1 /*************************************************************************
3 * $RCSfile: CalcAddins.java,v $
7 * last change: $Author: rt $ $Date: 2005-01-31 17:14:48 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 // Template for an Office Calc add-in Java implementation file.
44 * information on the following web page:
45 * http://api.openoffice.org/common/ref/com/sun/star/index.html
47 import com
.sun
.star
.comp
.loader
.FactoryHelper
;
48 import com
.sun
.star
.lang
.XMultiServiceFactory
;
49 import com
.sun
.star
.lang
.XSingleServiceFactory
;
50 import com
.sun
.star
.registry
.XRegistryKey
;
51 import com
.sun
.star
.uno
.UnoRuntime
;
52 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
53 import com
.sun
.star
.lang
.XInitialization
;
54 import com
.sun
.star
.beans
.XPropertySet
;
55 import com
.sun
.star
.lang
.XServiceInfo
;
56 import com
.sun
.star
.lang
.XServiceName
;
57 import com
.sun
.star
.sheet
.XAddIn
;
58 import com
.sun
.star
.lang
.Locale
;
59 import com
.sun
.star
.lang
.XTypeProvider
;
60 import com
.sun
.star
.uno
.Type
;
62 import org
.openoffice
.sheet
.addin
.XCalcAddins
;
64 /** This outer class provides an inner class to implement the service
65 * description, a method to instantiate the
66 * component on demand (__getServiceFactory()), and a method to give
67 * information about the component (__writeRegistryServiceInfo()).
69 public class CalcAddins
{
71 /** This inner class provides the component as a concrete implementation
72 * of the service description. It implements the needed interfaces.
73 * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider
75 static public class _CalcAddins
extends WeakBase
implements
82 /** The component will be registered under this name.
84 static private final String __serviceName
= "org.openoffice.sheet.addin.CalcAddins";
86 static private final String ADDIN_SERVICE
= "com.sun.star.sheet.AddIn";
88 private Locale aFuncLoc
;
90 private static final String
[] stringFunctionName
= {
92 * You should replace these method names by the method names of your interface.
98 private static final short shortINVALID
= -1;
101 * For each of your methods you should make up a new constant with a different value.
103 private static final short shortGETMYFIRSTVALUE
= 0;
104 private static final short shortGETMYSECONDVALUE
= 1;
108 * This is where you implement all methods of your interface. The parameters have to
109 * be the same as in your IDL file and their types have to be the correct
110 * IDL-to-Java mappings of their types in the IDL file.
112 public int getMyFirstValue(
113 com
.sun
.star
.beans
.XPropertySet xOptions
118 public int getMySecondValue(
119 com
.sun
.star
.beans
.XPropertySet xOptions
,
122 return( (int) ( 2 + intDummy
) );
126 // Implement method from interface XServiceName
127 public String
getServiceName() {
128 return( __serviceName
);
131 // Implement methods from interface XServiceInfo
132 public boolean supportsService(String stringServiceName
) {
133 return( stringServiceName
.equals( ADDIN_SERVICE
) ||
134 stringServiceName
.equals( __serviceName
) );
137 public String
getImplementationName() {
138 return( _CalcAddins
.class.getName() );
141 public String
[] getSupportedServiceNames() {
142 String
[] stringSupportedServiceNames
= { ADDIN_SERVICE
, __serviceName
};
143 return( stringSupportedServiceNames
);
146 // Implement methods from interface XAddIn
147 public String
getDisplayArgumentName(String stringProgrammaticFunctionName
,int intArgument
) {
148 String stringReturn
= "";
150 switch( this.getFunctionID( stringProgrammaticFunctionName
) ) {
152 * You should list all argument names for each of your methods, here.
154 case shortGETMYFIRSTVALUE
:
155 switch( intArgument
) {
157 stringReturn
= "(internal)";
161 case shortGETMYSECONDVALUE
:
162 switch( intArgument
) {
164 stringReturn
= "(internal)";
167 stringReturn
= "intDummy";
172 return( stringReturn
);
175 public String
getDisplayFunctionName(String stringProgrammaticName
) {
176 String stringReturn
= "";
178 switch( this.getFunctionID( stringProgrammaticName
) ) {
180 * Assign the name of each of your methods.
182 case shortGETMYFIRSTVALUE
:
183 stringReturn
= "getMyFirstValue";
185 case shortGETMYSECONDVALUE
:
186 stringReturn
= "getMySecondValue";
190 return( stringReturn
);
193 public String
getProgrammaticCategoryName(String p1
) {
197 public String
getDisplayCategoryName(String p1
) {
201 public String
getFunctionDescription(String stringProgrammaticName
) {
202 String stringReturn
= "";
204 switch( this.getFunctionID( stringProgrammaticName
) ) {
206 * Enter a description for each of your methods that office users will understand.
208 case shortGETMYFIRSTVALUE
:
209 stringReturn
= "This is your first method.";
211 case shortGETMYSECONDVALUE
:
212 stringReturn
= "This is your second method.";
216 return( stringReturn
);
219 public String
getArgumentDescription(String stringProgrammaticFunctionName
,int intArgument
) {
220 String stringReturn
= "";
222 switch( this.getFunctionID( stringProgrammaticFunctionName
) ) {
224 * Enter a description for every argument of every method. Make them so that office users will understand.
226 case shortGETMYFIRSTVALUE
:
227 switch( intArgument
) {
229 stringReturn
= "(internal)";
233 case shortGETMYSECONDVALUE
:
234 switch( intArgument
) {
236 stringReturn
= "(internal)";
239 stringReturn
= "You can add this value.";
244 return( stringReturn
);
247 public String
getProgrammaticFuntionName(String p1
) {
251 // Implement methods from interface XLocalizable
252 public Locale
getLocale() {
256 public void setLocale(Locale p1
) {
260 // Auxiliary functions
261 private short getFunctionID( String stringProgrammaticName
) {
262 for ( int i
= 0; i
< stringFunctionName
.length
; i
++ ) {
263 if ( stringProgrammaticName
.equals( stringFunctionName
[ i
] ) ) {
264 return( ( short ) i
);
273 * Returns a factory for creating the service.
274 * This method is called by the <code>JavaLoader</code>
276 * @return returns a <code>XSingleServiceFactory</code> for creating the component
277 * @param implName the name of the implementation for which a service is desired
278 * @param multiFactory the service manager to be used if needed
279 * @param regKey the registryKey
280 * @see com.sun.star.comp.loader.JavaLoader
282 public static XSingleServiceFactory
__getServiceFactory(String implName
,
283 XMultiServiceFactory multiFactory
,
284 XRegistryKey regKey
) {
285 XSingleServiceFactory xSingleServiceFactory
= null;
287 if (implName
.equals(_CalcAddins
.class.getName()) )
288 xSingleServiceFactory
= FactoryHelper
.getServiceFactory(_CalcAddins
.class,
289 _CalcAddins
.__serviceName
,
293 return xSingleServiceFactory
;
297 * Writes the service information into the given registry key.
298 * This method is called by the <code>JavaLoader</code>
300 * @return returns true if the operation succeeded
301 * @param regKey the registryKey
302 * @see com.sun.star.comp.loader.JavaLoader
304 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey
) {
305 return FactoryHelper
.writeRegistryServiceInfo(_CalcAddins
.class.getName(),
306 _CalcAddins
.__serviceName
, regKey
)
307 && FactoryHelper
.writeRegistryServiceInfo(_CalcAddins
.class.getName(),
308 _CalcAddins
.ADDIN_SERVICE
, regKey
);