1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
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.
20  *
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.
32  *
33  *************************************************************************/
34 
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.UnoRuntime;
40 import com.sun.star.uno.XComponentContext;
41 import com.sun.star.registry.XRegistryKey;
42 import com.sun.star.lang.XInitialization;
43 import com.sun.star.lang.XTypeProvider;
44 import com.sun.star.lang.XServiceInfo;
45 import com.sun.star.uno.Type;
46 
47 /** This class capsulates the class, that implements the minimal component, a
48  * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a
49  * method, that writes the information into the given registry key
50  * (<CODE>__writeRegistryServiceInfo</CODE>).
51  */
52 public class LicenseTest {
53     /** This class implements the component. At least the interfaces XServiceInfo,
54      * XTypeProvider, and XInitialization should be provided by the service.
55      */
56     public static class _LicenseTest extends WeakBase
57         implements XServiceInfo {
58         /** The service name, that must be used to get an instance of this service.
59          */
60         static private final String __serviceName =
61         "org.openoffice.LicenseTest";
62 
63         /** The initial component contextr, that gives access to
64          * the service manager, supported singletons, ...
65          * It's often later used
66          */
67         private XComponentContext m_cmpCtx;
68 
69         /** The service manager, that gives access to all registered services.
70          * It's often later used
71          */
72         private XMultiComponentFactory m_xMCF;
73 
74         /** The constructor of the inner class has a XMultiServiceFactory parameter.
75          * @param xmultiservicefactoryInitialization A special service factory
76          * could be introduced while initializing.
77          */
78         public _LicenseTest(XComponentContext xCompContext) {
79             try {
80                 m_cmpCtx = xCompContext;
81                 m_xMCF = m_cmpCtx.getServiceManager();
82             }
83             catch( Exception e ) {
84                 e.printStackTrace();
85             }
86         }
87 
88         /** This method returns an array of all supported service names.
89          * @return Array of supported service names.
90          */
91         public String[] getSupportedServiceNames() {
92             return getServiceNames();
93         }
94 
95         /** This method is a simple helper function to used in the
96          * static component initialisation functions as well as in
97          * getSupportedServiceNames.
98          */
99         public static String[] getServiceNames() {
100             String[] sSupportedServiceNames = { __serviceName };
101             return sSupportedServiceNames;
102         }
103 
104         /** This method returns true, if the given service will be
105          * supported by the component.
106          * @param sServiceName Service name.
107          * @return True, if the given service name will be supported.
108          */
109         public boolean supportsService( String sServiceName ) {
110             return sServiceName.equals( __serviceName );
111         }
112 
113         /** Return the class name of the component.
114          * @return Class name of the component.
115          */
116         public String getImplementationName() {
117             return  _LicenseTest.class.getName();
118         }
119     }
120 
121 
122     /**
123      * Gives a factory for creating the service.
124      * This method is called by the <code>JavaLoader</code>
125      * <p>
126      * @return  returns a <code>XSingleComponentFactory</code> for creating
127      *          the component
128      * @param   sImplName the name of the implementation for which a
129      *          service is desired
130      * @see     com.sun.star.comp.loader.JavaLoader
131      */
132     public static XSingleComponentFactory __getComponentFactory(String sImplName)
133     {
134         XSingleComponentFactory xFactory = null;
135 
136         if ( sImplName.equals( _LicenseTest.class.getName() ) )
137             xFactory = Factory.createComponentFactory(_LicenseTest.class,
138                                              _LicenseTest.getServiceNames());
139 
140         return xFactory;
141     }
142 
143     /**
144      * Writes the service information into the given registry key.
145      * This method is called by the <code>JavaLoader</code>
146      * <p>
147      * @return  returns true if the operation succeeded
148      * @param   regKey the registryKey
149      * @see     com.sun.star.comp.loader.JavaLoader
150      */
151     // This method not longer necessary since OOo 3.4 where the component registration
152     // was changed to passive component registration. For more details see
153     // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
154 
155 //     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
156 //         return Factory.writeRegistryServiceInfo(_LicenseTest.class.getName(),
157 //                                                 _LicenseTest.getServiceNames(),
158 //                                                 regKey);
159 //     }
160         /** This method is a member of the interface for initializing an object
161          * directly after its creation.
162          * @param object This array of arbitrary objects will be passed to the
163          * component after its creation.
164          * @throws Exception Every exception will not be handled, but will be
165          * passed to the caller.
166          */
167         public void initialize( Object[] object )
168             throws com.sun.star.uno.Exception {
169             /* The component describes what arguments its expected and in which
170              * order!At this point you can read the objects and can intialize
171              * your component using these objects.
172              */
173         }
174 
175 }
176