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