1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *************************************************************************/
35 import com
.sun
.star
.lib
.uno
.helper
.Factory
;
36 import com
.sun
.star
.lang
.XMultiComponentFactory
;
37 import com
.sun
.star
.lang
.XSingleComponentFactory
;
38 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
39 import com
.sun
.star
.uno
.XComponentContext
;
40 import com
.sun
.star
.lang
.XInitialization
;
41 import com
.sun
.star
.lang
.XServiceInfo
;
43 /** This class capsulates the class, that implements the minimal component, a
44 * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a
45 * method, that writes the information into the given registry key
46 * (<CODE>__writeRegistryServiceInfo</CODE>).
48 public class MinimalComponent
{
49 /** This class implements the component. At least the interfaces XServiceInfo,
50 * XTypeProvider, and XInitialization should be provided by the service.
52 public static class _MinimalComponent
extends WeakBase
53 implements XInitialization
, XServiceInfo
{
54 /** The service name, that must be used to get an instance of this service.
56 static private final String __serviceName
=
57 "org.openoffice.MinimalComponent";
59 /** The initial component contextr, that gives access to
60 * the service manager, supported singletons, ...
61 * It's often later used
63 private XComponentContext m_cmpCtx
;
65 /** The service manager, that gives access to all registered services.
66 * It's often later used
68 private XMultiComponentFactory m_xMCF
;
70 /** The constructor of the inner class has a XMultiServiceFactory parameter.
71 * @param xCompContext A special service factory
72 * could be introduced while initializing.
74 public _MinimalComponent(XComponentContext xCompContext
) {
76 m_cmpCtx
= xCompContext
;
77 m_xMCF
= m_cmpCtx
.getServiceManager();
79 catch( Exception e
) {
84 /** This method is a member of the interface for initializing an object
85 * directly after its creation.
86 * @param object This array of arbitrary objects will be passed to the
87 * component after its creation.
88 * @throws com.sun.star.uno.Exception Every exception will not be handled, but will be
89 * passed to the caller.
91 public void initialize( Object
[] object
)
92 throws com
.sun
.star
.uno
.Exception
{
93 /* The component describes what arguments its expected and in which
94 * order!At this point you can read the objects and can intialize
95 * your component using these objects.
99 /** This method returns an array of all supported service names.
100 * @return Array of supported service names.
102 public String
[] getSupportedServiceNames() {
103 return getServiceNames();
106 /** This method is a simple helper function to used in the
107 * static component initialisation functions as well as in
108 * getSupportedServiceNames.
110 private static String
[] getServiceNames() {
111 String
[] sSupportedServiceNames
= { __serviceName
};
112 return sSupportedServiceNames
;
115 /** This method returns true, if the given service will be
116 * supported by the component.
117 * @param sServiceName Service name.
118 * @return True, if the given service name will be supported.
120 public boolean supportsService( String sServiceName
) {
121 return sServiceName
.equals( __serviceName
);
124 /** Return the class name of the component.
125 * @return Class name of the component.
127 public String
getImplementationName() {
128 return _MinimalComponent
.class.getName();
134 * Gives a factory for creating the service.
135 * This method is called by the <code>JavaLoader</code>
137 * @return returns a <code>XSingleComponentFactory</code> for creating
139 * @param sImplName the name of the implementation for which a
141 * @see com.sun.star.comp.loader.JavaLoader
143 public static XSingleComponentFactory
__getComponentFactory(String sImplName
)
145 XSingleComponentFactory xFactory
= null;
147 if ( sImplName
.equals( _MinimalComponent
.class.getName() ) )
148 xFactory
= Factory
.createComponentFactory(_MinimalComponent
.class,
149 _MinimalComponent
.getServiceNames());