Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.comp.servicemanager;
import java.util.ArrayList;
import java.util.Collections;
import com.sun.star.container.XContentEnumerationAccess;
import com.sun.star.container.XEnumeration;
import com.sun.star.container.XSet;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XEventListener;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.XSingleComponentFactory;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
/**
* The ServiceManager class is an implementation of the
* ServiceManagerthe central class needed for implementing or using
* UNO components in Java.
*
*
The Methods queryInterface and isSame delegate
* calls to the implementing objects and are used instead of casts and identity
* comparisons.
*
* @see com.sun.star.lang.XMultiServiceFactory
* @see com.sun.star.container.XSet
* @see com.sun.star.container.XContentEnumerationAccess
* @see com.sun.star.lang.XComponent
* @see com.sun.star.lang.XServiceInfo
* @since UDK1.0
*/
public class ServiceManager implements XMultiServiceFactory,
XMultiComponentFactory,
XSet,
XContentEnumerationAccess,
XComponent,
XServiceInfo
{
private static final boolean DEBUG = false;
private static final void DEBUG (String dbg) {
if (DEBUG) System.err.println( dbg );
}
private static com.sun.star.uno.Type UNO_TYPE = null;
static String[] supportedServiceNames = {
"com.sun.star.lang.MultiServiceFactory",
"com.sun.star.lang.ServiceManager"
};
ArrayList eventListener;
java.util.HashMap factoriesByImplNames;
java.util.HashMap> factoriesByServiceNames; // keys:
private com.sun.star.uno.XComponentContext m_xDefaultContext;
/**
* Creates a new instance of the ServiceManager.
*/
public ServiceManager() {
eventListener = new ArrayList();
factoriesByImplNames = new java.util.HashMap();
factoriesByServiceNames = new java.util.HashMap>();
m_xDefaultContext = null;
}
public void setDefaultContext(XComponentContext context) {
m_xDefaultContext = context;
}
/**
* Creates a new instance of a specified service.
*
*
Therefore the associated factory of the service is looked up and used
* to instantiate a new component.
*
* @param serviceSpecifier indicates the service or component name.
* @return newly created component.
*
* @see com.sun.star.lang.XMultiServiceFactory
*/
public java.lang.Object createInstance( String serviceSpecifier )
throws com.sun.star.uno.Exception,
com.sun.star.uno.RuntimeException
{
return createInstanceWithContext( serviceSpecifier, m_xDefaultContext );
}
/**
* Creates a new instance of a specified service with the given parameters.
*
*
Therefore the associated factory of the service is looked up and used
* to instantiate a new component.
*
* @return newly created component.
* @param serviceSpecifier indicates the service or component name.
* @see com.sun.star.lang.XMultiServiceFactory
*/
public java.lang.Object createInstanceWithArguments(
String serviceSpecifier, Object[] args )
throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException
{
if (DEBUG) {
System.err.println("createInstanceWithArguments:" );
for (Object arg : args) {
System.err.print(" " + arg);
}
System.err.println();
}
return createInstanceWithArgumentsAndContext( serviceSpecifier, args, m_xDefaultContext );
}
/**
* Look up the factory for a given service or implementation name.
*
*
First the requested service name is search in the list of available
* services. If it can not be found the name is looked up in the implementation
* list.
*
* @param serviceName indicates the service or implementation name.
* @return the factory of the service / implementation.
*
* @see com.sun.star.lang.XMultiServiceFactory
*/
private Object queryServiceFactory(String serviceName)
throws com.sun.star.uno.Exception,
com.sun.star.uno.RuntimeException
{
DEBUG("queryServiceFactory for name " + serviceName );
Object factory = null;
if ( factoriesByServiceNames.containsKey( serviceName ) ) {
ArrayList