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 // Template for an Office Calc add-in Java implementation file.
25cdf0e10cSrcweir 
26cdf0e10cSrcweir /** You can find more
27cdf0e10cSrcweir  * information on the following web page:
28cdf0e10cSrcweir  * http://api.openoffice.org/common/ref/com/sun/star/index.html
29cdf0e10cSrcweir  */
30cdf0e10cSrcweir import com.sun.star.comp.loader.FactoryHelper;
31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
32cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
33cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
34cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
35cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
36cdf0e10cSrcweir import com.sun.star.lang.XInitialization;
37cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
38cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
39cdf0e10cSrcweir import com.sun.star.lang.XServiceName;
40cdf0e10cSrcweir import com.sun.star.sheet.XAddIn;
41cdf0e10cSrcweir import com.sun.star.lang.Locale;
42cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider;
43cdf0e10cSrcweir import com.sun.star.uno.Type;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir import org.openoffice.sheet.addin.XCalcAddins;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir /** This outer class provides an inner class to implement the service
48cdf0e10cSrcweir  * description, a method to instantiate the
49cdf0e10cSrcweir  * component on demand (__getServiceFactory()), and a method to give
50cdf0e10cSrcweir  * information about the component (__writeRegistryServiceInfo()).
51cdf0e10cSrcweir  */
52cdf0e10cSrcweir public class CalcAddins {
53*5f946091Smseidel 
54cdf0e10cSrcweir /** This inner class provides the component as a concrete implementation
55cdf0e10cSrcweir  * of the service description. It implements the needed interfaces.
56cdf0e10cSrcweir  * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider
57cdf0e10cSrcweir  */
58cdf0e10cSrcweir     static public class _CalcAddins extends WeakBase implements
59cdf0e10cSrcweir                                             XCalcAddins,
60cdf0e10cSrcweir                                             XAddIn,
61cdf0e10cSrcweir                                             XServiceName,
62cdf0e10cSrcweir                                             XServiceInfo
63cdf0e10cSrcweir     {
64*5f946091Smseidel 
65cdf0e10cSrcweir /** The component will be registered under this name.
66cdf0e10cSrcweir  */
67cdf0e10cSrcweir         static private final String __serviceName = "org.openoffice.sheet.addin.CalcAddins";
68*5f946091Smseidel 
69cdf0e10cSrcweir         static private final String ADDIN_SERVICE = "com.sun.star.sheet.AddIn";
70*5f946091Smseidel 
71cdf0e10cSrcweir         private Locale aFuncLoc;
72*5f946091Smseidel 
73cdf0e10cSrcweir         private static final String[] stringFunctionName = {
74cdf0e10cSrcweir /** TO DO:
75cdf0e10cSrcweir  * You should replace these method names by the method names of your interface.
76cdf0e10cSrcweir  */
77cdf0e10cSrcweir             "getMyFirstValue",
78cdf0e10cSrcweir             "getMySecondValue"
79cdf0e10cSrcweir         };
80*5f946091Smseidel 
81cdf0e10cSrcweir         private static final short shortINVALID = -1;
82*5f946091Smseidel 
83cdf0e10cSrcweir /** TO DO:
84cdf0e10cSrcweir  * For each of your methods you should make up a new constant with a different value.
85cdf0e10cSrcweir  */
86cdf0e10cSrcweir         private static final short shortGETMYFIRSTVALUE = 0;
87cdf0e10cSrcweir         private static final short shortGETMYSECONDVALUE = 1;
88*5f946091Smseidel 
89*5f946091Smseidel 
90cdf0e10cSrcweir /** TO DO:
91cdf0e10cSrcweir  * This is where you implement all methods of your interface. The parameters have to
92*5f946091Smseidel  * be the same as in your IDL file and their types have to be the correct
93cdf0e10cSrcweir  * IDL-to-Java mappings of their types in the IDL file.
94cdf0e10cSrcweir  */
getMyFirstValue( com.sun.star.beans.XPropertySet xOptions )95cdf0e10cSrcweir         public int getMyFirstValue(
96cdf0e10cSrcweir             com.sun.star.beans.XPropertySet xOptions
97cdf0e10cSrcweir         ) {
98cdf0e10cSrcweir             return (int) 1;
99cdf0e10cSrcweir         }
100*5f946091Smseidel 
getMySecondValue( com.sun.star.beans.XPropertySet xOptions, int intDummy )101cdf0e10cSrcweir         public int getMySecondValue(
102cdf0e10cSrcweir             com.sun.star.beans.XPropertySet xOptions,
103cdf0e10cSrcweir             int intDummy
104cdf0e10cSrcweir         ) {
105cdf0e10cSrcweir             return( (int) ( 2 + intDummy ) );
106cdf0e10cSrcweir         }
107*5f946091Smseidel 
108*5f946091Smseidel 
109cdf0e10cSrcweir         // Implement method from interface XServiceName
getServiceName()110cdf0e10cSrcweir         public String getServiceName() {
111cdf0e10cSrcweir             return( __serviceName );
112cdf0e10cSrcweir         }
113*5f946091Smseidel 
114cdf0e10cSrcweir         // Implement methods from interface XServiceInfo
supportsService(String stringServiceName)115cdf0e10cSrcweir         public boolean supportsService(String stringServiceName) {
116cdf0e10cSrcweir             return( stringServiceName.equals( ADDIN_SERVICE ) ||
117cdf0e10cSrcweir                     stringServiceName.equals( __serviceName ) );
118cdf0e10cSrcweir         }
119*5f946091Smseidel 
getImplementationName()120cdf0e10cSrcweir         public String getImplementationName() {
121cdf0e10cSrcweir             return( _CalcAddins.class.getName() );
122cdf0e10cSrcweir         }
123*5f946091Smseidel 
getSupportedServiceNames()124cdf0e10cSrcweir         public String[] getSupportedServiceNames() {
125cdf0e10cSrcweir             String[] stringSupportedServiceNames = { ADDIN_SERVICE, __serviceName };
126cdf0e10cSrcweir             return( stringSupportedServiceNames );
127cdf0e10cSrcweir         }
128*5f946091Smseidel 
129cdf0e10cSrcweir         // Implement methods from interface XAddIn
getDisplayArgumentName(String stringProgrammaticFunctionName,int intArgument)130cdf0e10cSrcweir         public String getDisplayArgumentName(String stringProgrammaticFunctionName,int intArgument) {
131cdf0e10cSrcweir             String stringReturn = "";
132*5f946091Smseidel 
133cdf0e10cSrcweir             switch( this.getFunctionID( stringProgrammaticFunctionName ) ) {
134cdf0e10cSrcweir /** TO DO:
135cdf0e10cSrcweir  * You should list all argument names for each of your methods, here.
136cdf0e10cSrcweir  */
137cdf0e10cSrcweir                 case shortGETMYFIRSTVALUE:
138cdf0e10cSrcweir                     switch( intArgument ) {
139cdf0e10cSrcweir                         case 0:
140cdf0e10cSrcweir                             stringReturn = "(internal)";
141cdf0e10cSrcweir                             break;
142cdf0e10cSrcweir                     }
143cdf0e10cSrcweir                     break;
144cdf0e10cSrcweir                 case shortGETMYSECONDVALUE:
145cdf0e10cSrcweir                     switch( intArgument ) {
146cdf0e10cSrcweir                         case 0:
147cdf0e10cSrcweir                             stringReturn = "(internal)";
148cdf0e10cSrcweir                             break;
149cdf0e10cSrcweir                         case 1:
150cdf0e10cSrcweir                             stringReturn = "intDummy";
151cdf0e10cSrcweir                             break;
152cdf0e10cSrcweir                     }
153cdf0e10cSrcweir                     break;
154cdf0e10cSrcweir             }
155cdf0e10cSrcweir             return( stringReturn );
156cdf0e10cSrcweir         }
157*5f946091Smseidel 
getDisplayFunctionName(String stringProgrammaticName)158cdf0e10cSrcweir         public String getDisplayFunctionName(String stringProgrammaticName) {
159cdf0e10cSrcweir             String stringReturn = "";
160*5f946091Smseidel 
161cdf0e10cSrcweir             switch( this.getFunctionID( stringProgrammaticName ) ) {
162cdf0e10cSrcweir /** TO DO:
163cdf0e10cSrcweir  * Assign the name of each of your methods.
164cdf0e10cSrcweir  */
165cdf0e10cSrcweir                 case shortGETMYFIRSTVALUE:
166cdf0e10cSrcweir                     stringReturn = "getMyFirstValue";
167cdf0e10cSrcweir                     break;
168cdf0e10cSrcweir                 case shortGETMYSECONDVALUE:
169cdf0e10cSrcweir                     stringReturn = "getMySecondValue";
170cdf0e10cSrcweir                     break;
171cdf0e10cSrcweir             }
172*5f946091Smseidel 
173cdf0e10cSrcweir             return( stringReturn );
174cdf0e10cSrcweir         }
175*5f946091Smseidel 
getProgrammaticCategoryName(String p1)176cdf0e10cSrcweir         public String getProgrammaticCategoryName(String p1) {
177cdf0e10cSrcweir             return( "Add-In" );
178cdf0e10cSrcweir         }
179*5f946091Smseidel 
getDisplayCategoryName(String p1)180cdf0e10cSrcweir         public String getDisplayCategoryName(String p1) {
181cdf0e10cSrcweir             return( "Add-In" );
182cdf0e10cSrcweir         }
183*5f946091Smseidel 
getFunctionDescription(String stringProgrammaticName)184cdf0e10cSrcweir         public String getFunctionDescription(String stringProgrammaticName) {
185cdf0e10cSrcweir             String stringReturn = "";
186*5f946091Smseidel 
187cdf0e10cSrcweir             switch( this.getFunctionID( stringProgrammaticName ) ) {
188cdf0e10cSrcweir /** TO DO:
189cdf0e10cSrcweir  * Enter a description for each of your methods that office users will understand.
190cdf0e10cSrcweir  */
191cdf0e10cSrcweir                 case shortGETMYFIRSTVALUE:
192cdf0e10cSrcweir                     stringReturn = "This is your first method.";
193cdf0e10cSrcweir                     break;
194cdf0e10cSrcweir                 case shortGETMYSECONDVALUE:
195cdf0e10cSrcweir                     stringReturn = "This is your second method.";
196cdf0e10cSrcweir                     break;
197cdf0e10cSrcweir             }
198*5f946091Smseidel 
199cdf0e10cSrcweir             return( stringReturn );
200cdf0e10cSrcweir         }
201*5f946091Smseidel 
getArgumentDescription(String stringProgrammaticFunctionName,int intArgument)202cdf0e10cSrcweir         public String getArgumentDescription(String stringProgrammaticFunctionName,int intArgument) {
203cdf0e10cSrcweir             String stringReturn = "";
204*5f946091Smseidel 
205cdf0e10cSrcweir             switch( this.getFunctionID( stringProgrammaticFunctionName ) ) {
206cdf0e10cSrcweir /** TO DO:
207cdf0e10cSrcweir  * Enter a description for every argument of every method. Make them so that office users will understand.
208cdf0e10cSrcweir  */
209cdf0e10cSrcweir                 case shortGETMYFIRSTVALUE:
210cdf0e10cSrcweir                     switch( intArgument ) {
211cdf0e10cSrcweir                         case 0:
212cdf0e10cSrcweir                             stringReturn = "(internal)";
213cdf0e10cSrcweir                             break;
214cdf0e10cSrcweir                     }
215cdf0e10cSrcweir                     break;
216cdf0e10cSrcweir                 case shortGETMYSECONDVALUE:
217cdf0e10cSrcweir                     switch( intArgument ) {
218cdf0e10cSrcweir                         case 0:
219cdf0e10cSrcweir                             stringReturn = "(internal)";
220cdf0e10cSrcweir                             break;
221cdf0e10cSrcweir                         case 1:
222cdf0e10cSrcweir                             stringReturn = "You can add this value.";
223cdf0e10cSrcweir                             break;
224cdf0e10cSrcweir                     }
225cdf0e10cSrcweir                     break;
226cdf0e10cSrcweir             }
227cdf0e10cSrcweir             return( stringReturn );
228cdf0e10cSrcweir         }
229*5f946091Smseidel 
getProgrammaticFuntionName(String p1)230cdf0e10cSrcweir         public String getProgrammaticFuntionName(String p1) {
231cdf0e10cSrcweir             return( "" );
232cdf0e10cSrcweir         }
233*5f946091Smseidel 
234cdf0e10cSrcweir         // Implement methods from interface XLocalizable
getLocale()235cdf0e10cSrcweir         public Locale getLocale() {
236cdf0e10cSrcweir             return( aFuncLoc );
237cdf0e10cSrcweir         }
238*5f946091Smseidel 
setLocale(Locale p1)239cdf0e10cSrcweir         public void setLocale(Locale p1) {
240cdf0e10cSrcweir             aFuncLoc = p1;
241cdf0e10cSrcweir         }
242*5f946091Smseidel 
243cdf0e10cSrcweir         // Auxiliary functions
getFunctionID( String stringProgrammaticName )244cdf0e10cSrcweir         private short getFunctionID( String stringProgrammaticName ) {
245cdf0e10cSrcweir             for ( int i = 0; i < stringFunctionName.length; i++ ) {
246cdf0e10cSrcweir                 if ( stringProgrammaticName.equals( stringFunctionName[ i ] ) ) {
247cdf0e10cSrcweir                     return( ( short ) i );
248cdf0e10cSrcweir                 }
249cdf0e10cSrcweir             }
250*5f946091Smseidel 
251cdf0e10cSrcweir             return( -1 );
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir     }
254*5f946091Smseidel 
255cdf0e10cSrcweir     /**
256cdf0e10cSrcweir      * Returns a factory for creating the service.
257cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
258cdf0e10cSrcweir      * <p>
259cdf0e10cSrcweir      * @return  returns a <code>XSingleServiceFactory</code> for creating the component
260cdf0e10cSrcweir      * @param   implName     the name of the implementation for which a service is desired
261cdf0e10cSrcweir      * @param   multiFactory the service manager to be used if needed
262cdf0e10cSrcweir      * @param   regKey       the registryKey
263cdf0e10cSrcweir      * @see                  com.sun.star.comp.loader.JavaLoader
264cdf0e10cSrcweir      */
__getServiceFactory(String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)265cdf0e10cSrcweir     public static XSingleServiceFactory __getServiceFactory(String implName,
266cdf0e10cSrcweir     XMultiServiceFactory multiFactory,
267cdf0e10cSrcweir     XRegistryKey regKey) {
268cdf0e10cSrcweir         XSingleServiceFactory xSingleServiceFactory = null;
269*5f946091Smseidel 
270cdf0e10cSrcweir         if (implName.equals(_CalcAddins.class.getName()) )
271cdf0e10cSrcweir             xSingleServiceFactory = FactoryHelper.getServiceFactory(_CalcAddins.class,
272cdf0e10cSrcweir             _CalcAddins.__serviceName,
273cdf0e10cSrcweir             multiFactory,
274cdf0e10cSrcweir             regKey);
275*5f946091Smseidel 
276cdf0e10cSrcweir         return xSingleServiceFactory;
277cdf0e10cSrcweir     }
278*5f946091Smseidel 
279cdf0e10cSrcweir     /**
280cdf0e10cSrcweir      * Writes the service information into the given registry key.
281cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
282cdf0e10cSrcweir      * <p>
283cdf0e10cSrcweir      * @return  returns true if the operation succeeded
284cdf0e10cSrcweir      * @param   regKey       the registryKey
285cdf0e10cSrcweir      * @see                  com.sun.star.comp.loader.JavaLoader
286cdf0e10cSrcweir      */
287cdf0e10cSrcweir     // This method not longer necessary since OOo 3.4 where the component registration
288cdf0e10cSrcweir     // was changed to passive component registration. For more details see
289*5f946091Smseidel     // https://wiki.openoffice.org/wiki/Passive_Component_Registration
290cdf0e10cSrcweir 
291cdf0e10cSrcweir //     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
292cdf0e10cSrcweir //         return FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(),
293cdf0e10cSrcweir //         _CalcAddins.__serviceName, regKey)
294cdf0e10cSrcweir //         && FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(),
295cdf0e10cSrcweir //         _CalcAddins.ADDIN_SERVICE, regKey);
296cdf0e10cSrcweir //     }
297cdf0e10cSrcweir }
298*5f946091Smseidel 
299