Update ooo320-m1
[ooovba.git] / jurt / com / sun / star / comp / servicemanager / ServiceManager.java
blob42ba36a82d86faffbe43c9322727bf1c2f432240
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ServiceManager.java,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com.sun.star.comp.servicemanager;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XComponentContext;
36 import com.sun.star.container.XSet;
37 import com.sun.star.container.XContentEnumerationAccess;
38 import com.sun.star.container.XEnumeration;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XEventListener;
42 import com.sun.star.lang.XInitialization;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.lang.XServiceInfo;
45 import com.sun.star.lang.XSingleServiceFactory;
46 import com.sun.star.lang.XSingleComponentFactory;
47 import com.sun.star.lang.XMultiComponentFactory;
49 import com.sun.star.registry.XRegistryKey;
50 import com.sun.star.registry.XSimpleRegistry;
52 import com.sun.star.loader.XImplementationLoader;
54 import java.lang.reflect.InvocationTargetException;
56 /**
57 * The <code>ServiceManager</code> class is an implmentation of the <code>ServiceManager</code>the central class needed for
58 * implementing or using UNO components in Java.
59 * <p>
60 * The Methods <code>queryInterface</code> and <code>isSame</code> delegate
61 * calls to the implementing objects and are used instead of casts
62 * and identity comparisons.
63 * <p>
64 * @version $Revision: 1.10 $ $ $Date: 2008-04-11 11:11:46 $
65 * @author Markus Herzog
66 * @see com.sun.star.lang.XMultiServiceFactory
67 * @see com.sun.star.container.XSet
68 * @see com.sun.star.container.XContentEnumerationAccess
69 * @see com.sun.star.lang.XComponent
70 * @see com.sun.star.lang.XServiceInfo
71 * @see com.sun.star.lang.XInitialization
72 * @since UDK1.0
73 */
74 public class ServiceManager implements XMultiServiceFactory,
75 XMultiComponentFactory,
76 XSet,
77 XContentEnumerationAccess,
78 XComponent,
79 XServiceInfo,
80 XInitialization
82 private static final boolean DEBUG = false;
84 private static final void DEBUG (String dbg) {
85 if (DEBUG) System.err.println( dbg );
88 private static com.sun.star.uno.Type UNO_TYPE = null;
90 XImplementationLoader loader = null;
92 static String[] supportedServiceNames = {
93 "com.sun.star.lang.MultiServiceFactory",
94 "com.sun.star.lang.ServiceManager"
97 java.util.Vector eventListener;
98 java.util.Hashtable factoriesByImplNames;
99 java.util.Hashtable factoriesByServiceNames; // keys:
101 private com.sun.star.uno.XComponentContext m_xDefaultContext;
104 * Creates a new instance of the <code>ServiceManager</code>.
106 public ServiceManager() {
107 eventListener = new java.util.Vector();
108 factoriesByImplNames = new java.util.Hashtable();
109 factoriesByServiceNames = new java.util.Hashtable();
110 m_xDefaultContext = null;
113 * Creates a new instance of the <code>ServiceManager</code>.
115 public ServiceManager( XComponentContext xContext ) {
116 eventListener = new java.util.Vector();
117 factoriesByImplNames = new java.util.Hashtable();
118 factoriesByServiceNames = new java.util.Hashtable();
119 m_xDefaultContext = xContext;
123 * Returns the service factory for the <code>ServiceManager</code>. If the given implementation name
124 * does not equal to the <code>ServiceManagers</code> class name null will be returned.
125 * <p>
126 * @return the factory for the <code>ServiceManager</code>.
127 * @param implName the implementation name of the of the service.
128 * Must be equal to <code>com.sun.star.comp.servicemanager.ServicManager</code>
129 * @param multiFactory refernce of the <code>MultiServiceFactory</code>. This parameter will be ignored.
130 * @param regKey the root key of the registry. This parameter will be ignored.
132 public static XSingleServiceFactory getServiceFactory( String implName,
133 XMultiServiceFactory multiFactory,
134 XRegistryKey regKey)
136 if ( implName.equals(ServiceManager.class.getName()) )
137 return new ServiceManagerFactory();
139 return null;
144 * Supplies a Java component loader. The loader component must be enlisted at the <code>ServiceManager</code> before.
145 * <p>
146 * @return a new instance of the Java component loader
147 * @see com.sun.star.loader.Java
149 private XImplementationLoader getLoader()
150 throws com.sun.star.uno.Exception,
151 com.sun.star.uno.RuntimeException
153 Object[] param = { this };
154 DEBUG("make loader");
155 Object loaderObj = createInstanceWithArgumentsAndContext(
156 "com.sun.star.loader.Java", param, m_xDefaultContext );
158 if (loaderObj == null)
159 throw new com.sun.star.uno.Exception("Can get an instance of com.sun.star.loader.Java");
161 return UnoRuntime.queryInterface( XImplementationLoader.class, loaderObj );
165 * Registers a list of components given by their class names.
166 * <p>
167 * @param newImpls list of the components that should be registered, given by their class names.
168 * If any exception occured during the registration, the process will be canceled.
169 * @see com.sun.star.container.XSet
171 private void xaddFactories( String[] newImpls )
172 throws com.sun.star.uno.Exception
174 for (int i=0; i<newImpls.length; i++) {
175 DEBUG ("try to add " + newImpls[i] );
176 Object newFactory = null;
178 try {
179 if (loader == null)
180 loader = getLoader();
182 newFactory = loader.activate( newImpls[i], null, null, null );
184 catch (com.sun.star.uno.Exception e) {
186 //****************************** BEGIN DEPRECATED ******************************************
188 try {
189 // try to get the class of the implementation
190 Class clazz = Class.forName( newImpls[i] );
192 Class[] methodClassParam = { String.class, XMultiServiceFactory.class, XRegistryKey.class };
193 java.lang.reflect.Method getFactoryMeth = null;
194 try {
195 getFactoryMeth = clazz.getMethod("__getServiceFactory", methodClassParam);
197 catch (NoSuchMethodException noSuchMethodEx) {
198 getFactoryMeth = null;
200 catch (SecurityException securityExc) {
201 getFactoryMeth = null;
204 if (getFactoryMeth == null)
205 getFactoryMeth = clazz.getMethod("getServiceFactory", methodClassParam);
207 Object[] methodParams = { newImpls[i], this, null };
208 newFactory = getFactoryMeth.invoke( clazz, methodParams );
210 catch (NoSuchMethodException ex) {}
211 catch (SecurityException ex) {}
212 catch (ClassNotFoundException ex) {}
213 catch (IllegalAccessException ex) {}
214 catch (IllegalArgumentException ex) {}
215 catch (InvocationTargetException ex) {}
217 //****************************** END DEPRECATED ******************************************
220 if ( newFactory == null )
221 throw new com.sun.star.loader.CannotActivateFactoryException("Can not get factory for " + newImpls[i]);
223 insert( newFactory );
224 } // end of for ...
228 * The method is used to add components to the <code>ServiceManager</code>. The first argument indicates a <code>SimpleRegistry</code>.
229 * The components which should be added will be searched under the <i>Implementations</i> key in the registry.
230 * <p>
231 * @param args the first argument ( args[0] ) specifices the SimpleRegistry object
232 * @see com.sun.star.lang.XInitialization
233 * @see com.sun.star.lang.RegistryServiceManager
234 * @see com.sun.star.lang.XSimpleRegistry
236 public void initialize( Object args[] )
237 throws com.sun.star.uno.Exception,
238 com.sun.star.uno.RuntimeException {
239 XSimpleRegistry xSimpleRegistry = null;
240 try {
241 xSimpleRegistry = (XSimpleRegistry) args[0];
242 if (xSimpleRegistry != null)
244 XRegistryKey rootkey = xSimpleRegistry.getRootKey();
246 XRegistryKey implkey_xRegistryKey = rootkey.openKey("Implementations");
247 if(implkey_xRegistryKey != null) {
248 XRegistryKey xRegistryKeys[] = implkey_xRegistryKey.openKeys();
250 for(int i = 0; i < xRegistryKeys.length; ++ i) {
251 xaddFactories(new String[]{xRegistryKeys[i].getStringValue()});
256 if (args.length > 1)
258 m_xDefaultContext = (XComponentContext)args[ 1 ];
261 catch (ArrayIndexOutOfBoundsException e)
263 throw new com.sun.star.lang.IllegalArgumentException("Argument must not be null.");
268 * Creates a new instance of a specified service. Therefor the associated factory of the service is
269 * looked up and used to instanciate a new component.
270 * <p>
271 * @return newly created component
272 * @param serviceSpecifier indicates the service or component name
273 * @see com.sun.star.lang.XMultiServiceFactory
275 public java.lang.Object createInstance( String serviceSpecifier )
276 throws com.sun.star.uno.Exception,
277 com.sun.star.uno.RuntimeException
279 return createInstanceWithContext( serviceSpecifier, m_xDefaultContext );
283 * Creates a new instance of a specified service with the given parameters.
284 * Therefor the associated factory of the service is looked up and used to instanciate a new component.
285 * <p>
286 * @return newly created component
287 * @param serviceSpecifier indicates the service or component name
288 * @see com.sun.star.lang.XMultiServiceFactory
290 public java.lang.Object createInstanceWithArguments(
291 String serviceSpecifier, Object[] args )
292 throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException
294 if (DEBUG) {
295 System.err.println("createInstanceWithArguments:" );
297 for (int i=0; i<args.length; i++)
298 System.err.print(" "+ args[i]);
300 System.err.println();
303 return createInstanceWithArgumentsAndContext( serviceSpecifier, args, m_xDefaultContext );
307 * Look up the factory for a given service or implementation name.
308 * First the requested service name is search in the list of avaible services. If it can not be found
309 * the name is looked up in the the implementation list.
310 * <p>
311 * @return the factory of the service / implementation
312 * @param serviceSpecifier indicates the service or implementation name
313 * @see com.sun.star.lang.XMultiServiceFactory
315 private Object queryServiceFactory(String serviceName)
316 throws com.sun.star.uno.Exception,
317 com.sun.star.uno.RuntimeException
319 DEBUG("queryServiceFactory for name " + serviceName );
320 Object factory = null;
322 if ( factoriesByServiceNames.containsKey( serviceName ) ) {
323 java.util.Vector aviableFact = (java.util.Vector) factoriesByServiceNames.get( serviceName );
325 DEBUG("");
326 DEBUG("aviable factories for " + serviceName +" "+ aviableFact);
327 DEBUG("");
329 if ( !aviableFact.isEmpty() )
330 factory = aviableFact.lastElement();
332 } else // not found in list of services - now try the implementations
333 factory = factoriesByImplNames.get( serviceName ); // return null if none is aviable
335 if (DEBUG) {
336 if (factory == null) System.err.println("service not registered");
337 else
338 System.err.println("service found:" + factory + " " + UnoRuntime.queryInterface(XSingleServiceFactory.class, factory));
341 if (factory == null)
342 throw new com.sun.star.uno.Exception("Query for service factory for " + serviceName + " failed.");
344 return factory;
348 * Supplies a list of all avialable services names.
349 * <p>
350 * @return list of Strings of all service names
351 * @see com.sun.star.container.XContentEnumerationAccess
353 public String[] getAvailableServiceNames()
354 throws com.sun.star.uno.RuntimeException
356 int i = 0;
357 String[] availableServiceNames = new String[factoriesByServiceNames.size()];
359 java.util.Enumeration keys = factoriesByServiceNames.keys();
361 while (keys.hasMoreElements())
362 availableServiceNames[i++] = (String) keys.nextElement();
364 return availableServiceNames;
367 // XMultiComponentFactory implementation
369 /** Create a service instance with given context.
371 @param rServiceSpecifier service name
372 @param xContext context
373 @return service instance
375 public java.lang.Object createInstanceWithContext(
376 String rServiceSpecifier,
377 com.sun.star.uno.XComponentContext xContext )
378 throws com.sun.star.uno.Exception
380 Object fac = queryServiceFactory( rServiceSpecifier );
381 if (fac != null)
383 XSingleComponentFactory xCompFac = UnoRuntime.queryInterface(
384 XSingleComponentFactory.class, fac );
385 if (xCompFac != null)
387 return xCompFac.createInstanceWithContext( xContext );
389 else
391 XSingleServiceFactory xServiceFac = UnoRuntime.queryInterface(
392 XSingleServiceFactory.class, fac );
393 if (xServiceFac != null)
395 if (DEBUG)
396 System.err.println( "### ignoring context raising service \"" + rServiceSpecifier + "\"!" );
397 return xServiceFac.createInstance();
399 else
401 throw new com.sun.star.uno.Exception(
402 "retrieved service factory object for \"" + rServiceSpecifier +
403 "\" does not export XSingleComponentFactory nor XSingleServiceFactory!" );
407 return null;
409 /** Create a service instance with given context and arguments.
411 @param rServiceSpecifier service name
412 @param rArguments arguments
413 @param xContext context
414 @return service instance
416 public java.lang.Object createInstanceWithArgumentsAndContext(
417 String rServiceSpecifier,
418 java.lang.Object[] rArguments,
419 com.sun.star.uno.XComponentContext xContext )
420 throws com.sun.star.uno.Exception
422 Object fac = queryServiceFactory( rServiceSpecifier );
423 if (fac != null)
425 XSingleComponentFactory xCompFac = UnoRuntime.queryInterface(
426 XSingleComponentFactory.class, fac );
427 if (xCompFac != null)
429 return xCompFac.createInstanceWithArgumentsAndContext( rArguments, xContext );
431 else
433 XSingleServiceFactory xServiceFac = UnoRuntime.queryInterface(
434 XSingleServiceFactory.class, fac );
435 if (xServiceFac != null)
437 if (DEBUG)
438 System.err.println( "### ignoring context raising service \"" + rServiceSpecifier + "\"!" );
439 return xServiceFac.createInstanceWithArguments( rArguments );
441 else
443 throw new com.sun.star.uno.Exception(
444 "retrieved service factory object for \"" + rServiceSpecifier +
445 "\" does not export XSingleComponentFactory nor XSingleServiceFactory!" );
449 return null;
451 // public String[] getAvailableServiceNames();
454 * Removes all listeners from the <code>ServiceManager</code> and clears the list of the services.
455 * <p>
456 * @see com.sun.star.lang.XComponent
458 public void dispose()
459 throws com.sun.star.uno.RuntimeException
461 if (eventListener != null) {
462 java.util.Enumeration enumer = eventListener.elements();
464 while (enumer.hasMoreElements()) {
465 XEventListener listener = (XEventListener) enumer.nextElement();
466 listener.disposing(new com.sun.star.lang.EventObject(this));
470 eventListener.removeAllElements();
471 factoriesByServiceNames.clear();
472 factoriesByImplNames.clear();
476 * Adds a new <code>EventListener</code>. The listener is notified when a
477 * service is added (removed) to (from) the <code>ServiceManager</code>.
478 * If the listener is already registred a
479 * <code>com.sun.star.uno.RuntimeException</code> will be thrown.
480 * <p>
481 * @param xListener the new listener which should been added.
482 * @see com.sun.star.lang.XComponent
484 public void addEventListener( XEventListener xListener )
485 throws com.sun.star.uno.RuntimeException
487 if (xListener == null)
488 throw new com.sun.star.uno.RuntimeException("Listener must not be null");
490 if ( eventListener.contains(xListener) )
491 throw new com.sun.star.uno.RuntimeException("Listener already registred.");
493 eventListener.addElement(xListener);
497 * Removes a <code>EventListener</code> from the <code>ServiceManager</code>.
498 * If the listener is not registered a <code>com.sun.star.uno.RuntimeException</code>
499 * will be thrown.
500 * <p>
501 * @param xListener the new listener which should been removed.
502 * @see com.sun.star.lang.XComponent
504 public void removeEventListener( XEventListener xListener )
505 throws com.sun.star.uno.RuntimeException
507 if (xListener == null)
508 throw new com.sun.star.uno.RuntimeException("Listener must not be null");
510 if ( !eventListener.contains(xListener) )
511 throw new com.sun.star.uno.RuntimeException("Listener is not registered.");
513 eventListener.removeElement(xListener);
517 * Checks if a component is registered at the <code>ServiceManager</code>. The given object argument must
518 * provide a <code>XServiceInfo</code> interface.
519 * <p>
520 * @return true if the component is registred otherwise false.
521 * @param object object which provides a <code>XServiceInfo</code> interface.
522 * @see com.sun.star.container.XSet
523 * @see com.sun.star.lang.XServiceInfo
525 public boolean has( Object object )
526 throws com.sun.star.uno.RuntimeException
528 if (object == null)
529 throw new com.sun.star.uno.RuntimeException("The parameter must not been null");
531 XServiceInfo xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, object);
533 if (xServiceInfo != null) {
534 return UnoRuntime.areSame(factoriesByImplNames.get(xServiceInfo.getImplementationName()), object);
537 return false;
541 * Adds a <code>SingleServiceFactory</code> to the <code>ServiceManager</code>.
542 * <p>
543 * @param object factory which should be added.
544 * @see com.sun.star.container.XSet
545 * @see com.sun.star.lang.XSingleServiceFactory
547 public void insert( Object object )
548 throws com.sun.star.lang.IllegalArgumentException,
549 com.sun.star.container.ElementExistException,
550 com.sun.star.uno.RuntimeException
552 if (object == null) throw new com.sun.star.lang.IllegalArgumentException();
554 XServiceInfo xServiceInfo =
555 UnoRuntime.queryInterface(XServiceInfo.class, object);
557 if (xServiceInfo == null)
558 throw new com.sun.star.lang.IllegalArgumentException(
559 "The given object does not implement the XServiceInfo interface."
562 if ( factoriesByImplNames.containsKey( xServiceInfo.getImplementationName() ) ) {
563 throw new com.sun.star.container.ElementExistException(
564 xServiceInfo.getImplementationName() + " already registred"
568 DEBUG("add factory " + object.toString() + " for " + xServiceInfo.getImplementationName());
569 factoriesByImplNames.put( xServiceInfo.getImplementationName(), object );
572 String[] serviceNames = xServiceInfo.getSupportedServiceNames();
573 java.util.Vector vec = null;
575 for (int i=0; i<serviceNames.length; i++) {
576 if ( !factoriesByServiceNames.containsKey( serviceNames[i] ) ) {
577 DEBUG("> no registered services found under " + serviceNames[i] + ": adding..." );
578 factoriesByServiceNames.put(serviceNames[i], new java.util.Vector());
581 vec = (java.util.Vector) factoriesByServiceNames.get( serviceNames[i] );
583 if ( vec.contains( object ) )
584 System.err.println("The implementation " + xServiceInfo.getImplementationName() +
585 " already registered for the service " + serviceNames[i] + " - ignoring!");
586 else
587 vec.addElement(object);
592 * Removes a <code>SingleServiceFactory</code> from the <code>ServiceManager</code>.
593 * <p>
594 * @param object factory which should be removed.
595 * @see com.sun.star.container.XSet
596 * @see com.sun.star.lang.XSingleServiceFactory
598 public void remove( Object object )
599 throws com.sun.star.lang.IllegalArgumentException,
600 com.sun.star.container.NoSuchElementException,
601 com.sun.star.uno.RuntimeException
603 if (object == null)
604 throw new com.sun.star.lang.IllegalArgumentException(
605 "The given object must not be null."
608 XServiceInfo xServiceInfo =
609 UnoRuntime.queryInterface(XServiceInfo.class, object);
611 if (xServiceInfo == null)
612 throw new com.sun.star.lang.IllegalArgumentException(
613 "The given object does not implement the XServiceInfo interface."
616 XSingleServiceFactory xSingleServiceFactory =
617 UnoRuntime.queryInterface(XSingleServiceFactory.class, object);
619 if (xSingleServiceFactory == null)
620 throw new com.sun.star.lang.IllegalArgumentException(
621 "The given object does not implement the XSingleServiceFactory interface."
624 if ( factoriesByImplNames.remove( xServiceInfo.getImplementationName() ) == null )
625 throw new com.sun.star.container.NoSuchElementException(
626 xServiceInfo.getImplementationName() +
627 " is not registered as an implementation."
630 String[] serviceNames = xServiceInfo.getSupportedServiceNames();
632 for ( int i=0; i<serviceNames.length; i++ ) {
633 if ( factoriesByServiceNames.containsKey( serviceNames[i] ) ) {
634 java.util.Vector vec = (java.util.Vector) factoriesByServiceNames.get(serviceNames[i]);
636 if ( !vec.removeElement(object) )
637 System.err.println("The implementation " + xServiceInfo.getImplementationName() +
638 " is not registered for the service " + serviceNames[i] + " - ignoring!");
640 if ( vec.isEmpty() ) // remove the vector if no implementations aviable for the service
641 factoriesByServiceNames.remove( serviceNames[i] );
647 * Provides an enumeration of all registred services.
648 * <p>
649 * @return an enumeration of all avialable services.
650 * @see com.sun.star.conatiner.XEnumerationAccess
652 public XEnumeration createEnumeration()
653 throws com.sun.star.uno.RuntimeException
655 return new ServiceEnumerationImpl( factoriesByImplNames.elements() );
659 * Provides the UNO type of the <code>ServiceManager</code>
660 * <p>
661 * @return the UNO type of the <code>ServiceManager</code>.
662 * @see com.sun.star.container.XElementAccess
663 * @see com.sun.star.uno.TypeClass
665 public com.sun.star.uno.Type getElementType()
666 throws com.sun.star.uno.RuntimeException
668 if ( UNO_TYPE == null )
669 UNO_TYPE = new com.sun.star.uno.Type(ServiceManager.class);
671 return UNO_TYPE;
675 * Checks if the any componets are registered.
676 * <p>
677 * @return true - if the list of the registred components is not empty - otherwise false.
678 * @see com.sun.star.container.XElementAccess
680 public boolean hasElements() {
681 return ! factoriesByImplNames.isEmpty();
685 * Provides an enumeration of of all factorys for a specified service.
686 * <p>
687 * @return an enumeration for service name.
688 * @param serviceName name of the requested service
689 * @see com.sun.star.container.XContentEnumerationAccess
691 public XEnumeration createContentEnumeration( String serviceName )
692 throws com.sun.star.uno.RuntimeException
694 XEnumeration enumer = null;
696 java.util.Vector serviceList = (java.util.Vector) factoriesByServiceNames.get(serviceName);
698 if (serviceList != null)
699 enumer = new ServiceEnumerationImpl( serviceList.elements() );
700 else
701 enumer = new ServiceEnumerationImpl();
703 return enumer;
707 * Returns the implementation name of the <code>ServiceManager</code> component.
708 * <p>
709 * @return the class name of the <code>ServiceManager</code>.
710 * @see com.sun.star.lang.XServiceInfo
712 public String getImplementationName()
713 throws com.sun.star.uno.RuntimeException
715 return getClass().getName();
719 * Checks if the <code>ServiceManager</code> supports a service.
720 * <p>
721 * @return true if the service is supported - otherwise false.
722 * @param serviceName service name which should be checked.
723 * @see com.sun.star.lang.XServiceInfo
725 public boolean supportsService( String serviceName )
726 throws com.sun.star.uno.RuntimeException
728 for (int i=0; i<supportedServiceNames.length; i++)
729 if (supportedServiceNames[i].equals( serviceName )) return true;
731 if (getImplementationName().equals( serviceName )) return true;
733 return false;
737 * Supplies list of all supported services.
738 * <p>
739 * @return a list of all supported service names.
740 * @see com.sun.star.lang.XServiceInfo
742 public String[] getSupportedServiceNames()
743 throws com.sun.star.uno.RuntimeException
745 return supportedServiceNames;
749 * The <code>ServiceEnumerationImpl</code> class provides an
750 * implementation of the @see com.sun.star.container.XEnumeration interface.
751 * It is a inner wrapper for a java.util.Enumeration object.
752 * <p>
753 * @version $Revision: 1.10 $ $ $Date: 2008-04-11 11:11:46 $
754 * @author Markus Herzog
755 * @see com.sun.star.lang.XSingleServiceFactory
756 * @see com.sun.star.lang.XServiceInfo
757 * @since UDK1.0
759 class ServiceEnumerationImpl implements XEnumeration {
760 java.util.Enumeration enumeration = null;
763 * Constructs a new empty instance.
765 public ServiceEnumerationImpl() {
769 * Constructs a new instance with a given enumeration.
770 * <p>
771 * @param enumer is the enumeration which should been wrapped.
772 * @see com.sun.star.container.XEnumeration
774 public ServiceEnumerationImpl(java.util.Enumeration enumer) {
775 enumeration = enumer;
779 * Checks if the enumeration contains more elements.
780 * <p>
781 * @return true if more elements are available - otherwise false.
782 * @see com.sun.star.container.XEnumeration
784 public boolean hasMoreElements()
785 throws com.sun.star.uno.RuntimeException
787 if (enumeration != null)
788 return enumeration.hasMoreElements();
790 return false;
794 * Returns the next element of the enumeration. If no further elements
795 * available a com.sun.star.container.NoSuchElementException exception will be thrown.
796 * <p>
797 * @return the next element.
798 * @see com.sun.star.container.XEnumeration
800 public Object nextElement()
801 throws com.sun.star.container.NoSuchElementException,
802 com.sun.star.lang.WrappedTargetException,
803 com.sun.star.uno.RuntimeException
805 if (enumeration == null)
806 throw new com.sun.star.container.NoSuchElementException();
808 try {
809 return enumeration.nextElement();
810 } catch (java.util.NoSuchElementException e) {
811 com.sun.star.container.NoSuchElementException ex =
812 new com.sun.star.container.NoSuchElementException();
813 ex.fillInStackTrace();
815 throw ex;
821 * The <code>ServiceManagerFactory</code> is the factory class for the
822 * <code>ServiceManager</code>. As all factories it implments the
823 * com.sun.star.lang.XSingleServiceFactory and the com.sun.star.lang.XServiceInfo
824 * interfaces.
825 * <p>
826 * @version $Revision: 1.10 $ $ $Date: 2008-04-11 11:11:46 $
827 * @author Markus Herzog
828 * @see com.sun.star.lang.XSingleServiceFactory
829 * @see com.sun.star.lang.XServiceInfo
830 * @since UDK1.0
832 class ServiceManagerFactory implements XServiceInfo, XSingleComponentFactory, XSingleServiceFactory
835 * Creates a new instance of the <code>ServiceManagerFactory</code>.
837 public ServiceManagerFactory() {
841 * Supplies the implementation name of the <code>ServiceManager</code>.
842 * <p>
843 * @return <code>ServiceManager</code> class name.
844 * @see com.sun.star.lang.XServiceInfo
846 public String getImplementationName()
847 throws com.sun.star.uno.RuntimeException
849 return ServiceManager.class.getName();
853 * Checks wether or not a service is supported.
854 * <p>
855 * @return true - if the service is supported, otherwise false.
856 * @param serviceName the name of the service that should be checked.
857 * @see com.sun.star.lang.XServiceInfo
859 public boolean supportsService( String serviceName )
860 throws com.sun.star.uno.RuntimeException
862 for ( int i=0; i<ServiceManager.supportedServiceNames.length; i++ )
863 if ( ServiceManager.supportedServiceNames[i].equals(serviceName) ) return true;
865 if ( getImplementationName().equals(serviceName) ) return true;
867 return false;
871 * Returns all service names which are supported by <code>ServiceManager</code>.
872 * <p>
873 * @return a list aof all supported service names.
874 * @see com.sun.star.lang.XServiceInfo
876 public String[] getSupportedServiceNames()
877 throws com.sun.star.uno.RuntimeException
879 return ServiceManager.supportedServiceNames;
883 * Creates a new instance of the <code>ServiceManager</code>.
884 * <p>
885 * @return newly created <code>ServiceManager</code> object.
886 * @see com.sun.star.lang.XSingleServiceFactory
888 public java.lang.Object createInstance()
889 throws com.sun.star.uno.Exception,
890 com.sun.star.uno.RuntimeException
892 return new ServiceManager();
896 * Creates a new instance of the <code>ServiceManager</code> with arguments.
897 * At this time it always throws a com.sun.star.lang.NoSuchMethodException
898 * because there is no the <code>ServiceManager</code> has no constructor with
899 * arguments.
900 * <p>
901 * @return null - allways throws an exception
902 * @param aArguments arguments for new instance.
903 * @see com.sun.star.lang.XSingleServiceFactory
905 public java.lang.Object createInstanceWithArguments( java.lang.Object[] aArguments )
906 throws com.sun.star.uno.Exception,
907 com.sun.star.uno.RuntimeException
909 throw new com.sun.star.lang.NoSuchMethodException("Constructor with arguments is not supported.");
912 // XSingleComponentFactory impl
913 //______________________________________________________________________________________________
914 public Object createInstanceWithContext( XComponentContext xContext )
915 throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException
917 return new ServiceManager( xContext );
919 //______________________________________________________________________________________________
920 public Object createInstanceWithArgumentsAndContext(
921 Object aArguments [], XComponentContext xContext )
922 throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException
924 throw new com.sun.star.lang.NoSuchMethodException(
925 "ServiceManagerFactory.createInstanceWithArgumentsAndContext() not impl!" );