1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 import com.sun.star.lib.uno.helper.Factory;
25 import com.sun.star.lang.XMultiComponentFactory;
26 import com.sun.star.lang.XSingleComponentFactory;
27 import com.sun.star.lib.uno.helper.WeakBase;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.XComponentContext;
30 import com.sun.star.registry.XRegistryKey;
31 import com.sun.star.lang.XInitialization;
32 import com.sun.star.lang.XTypeProvider;
33 import com.sun.star.lang.XServiceInfo;
34 import com.sun.star.uno.Type;
35 
36 /** This class capsulates the class, that implements the minimal component, a
37  * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a
38  * method, that writes the information into the given registry key
39  * (<CODE>__writeRegistryServiceInfo</CODE>).
40  */
41 public class LicenseTest {
42     /** This class implements the component. At least the interfaces XServiceInfo,
43      * XTypeProvider, and XInitialization should be provided by the service.
44      */
45     public static class _LicenseTest extends WeakBase
46         implements XServiceInfo {
47         /** The service name, that must be used to get an instance of this service.
48          */
49         static private final String __serviceName =
50         "org.openoffice.LicenseTest";
51 
52         /** The initial component contextr, that gives access to
53          * the service manager, supported singletons, ...
54          * It's often later used
55          */
56         private XComponentContext m_cmpCtx;
57 
58         /** The service manager, that gives access to all registered services.
59          * It's often later used
60          */
61         private XMultiComponentFactory m_xMCF;
62 
63         /** The constructor of the inner class has a XMultiServiceFactory parameter.
64          * @param xmultiservicefactoryInitialization A special service factory
65          * could be introduced while initializing.
66          */
_LicenseTest(XComponentContext xCompContext)67         public _LicenseTest(XComponentContext xCompContext) {
68             try {
69                 m_cmpCtx = xCompContext;
70                 m_xMCF = m_cmpCtx.getServiceManager();
71             }
72             catch( Exception e ) {
73                 e.printStackTrace();
74             }
75         }
76 
77         /** This method returns an array of all supported service names.
78          * @return Array of supported service names.
79          */
getSupportedServiceNames()80         public String[] getSupportedServiceNames() {
81             return getServiceNames();
82         }
83 
84         /** This method is a simple helper function to used in the
85          * static component initialisation functions as well as in
86          * getSupportedServiceNames.
87          */
getServiceNames()88         public static String[] getServiceNames() {
89             String[] sSupportedServiceNames = { __serviceName };
90             return sSupportedServiceNames;
91         }
92 
93         /** This method returns true, if the given service will be
94          * supported by the component.
95          * @param sServiceName Service name.
96          * @return True, if the given service name will be supported.
97          */
supportsService( String sServiceName )98         public boolean supportsService( String sServiceName ) {
99             return sServiceName.equals( __serviceName );
100         }
101 
102         /** Return the class name of the component.
103          * @return Class name of the component.
104          */
getImplementationName()105         public String getImplementationName() {
106             return  _LicenseTest.class.getName();
107         }
108     }
109 
110 
111     /**
112      * Gives a factory for creating the service.
113      * This method is called by the <code>JavaLoader</code>
114      * <p>
115      * @return  returns a <code>XSingleComponentFactory</code> for creating
116      *          the component
117      * @param   sImplName the name of the implementation for which a
118      *          service is desired
119      * @see     com.sun.star.comp.loader.JavaLoader
120      */
__getComponentFactory(String sImplName)121     public static XSingleComponentFactory __getComponentFactory(String sImplName)
122     {
123         XSingleComponentFactory xFactory = null;
124 
125         if ( sImplName.equals( _LicenseTest.class.getName() ) )
126             xFactory = Factory.createComponentFactory(_LicenseTest.class,
127                                              _LicenseTest.getServiceNames());
128 
129         return xFactory;
130     }
131 
132     /**
133      * Writes the service information into the given registry key.
134      * This method is called by the <code>JavaLoader</code>
135      * <p>
136      * @return  returns true if the operation succeeded
137      * @param   regKey the registryKey
138      * @see     com.sun.star.comp.loader.JavaLoader
139      */
140     // This method not longer necessary since OOo 3.4 where the component registration
141     // was changed to passive component registration. For more details see
142     // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
143 
144 //     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
145 //         return Factory.writeRegistryServiceInfo(_LicenseTest.class.getName(),
146 //                                                 _LicenseTest.getServiceNames(),
147 //                                                 regKey);
148 //     }
149         /** This method is a member of the interface for initializing an object
150          * directly after its creation.
151          * @param object This array of arbitrary objects will be passed to the
152          * component after its creation.
153          * @throws Exception Every exception will not be handled, but will be
154          * passed to the caller.
155          */
initialize( Object[] object )156         public void initialize( Object[] object )
157             throws com.sun.star.uno.Exception {
158             /* The component describes what arguments its expected and in which
159              * order!At this point you can read the objects and can intialize
160              * your component using these objects.
161              */
162         }
163 
164 }
165