1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
33 *************************************************************************/
35 // Template for an Office Calc add-in Java implementation file.
38 * information on the following web page:
39 * http://api.libreoffice.org/
41 import com
.sun
.star
.comp
.loader
.FactoryHelper
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.lang
.XSingleServiceFactory
;
44 import com
.sun
.star
.registry
.XRegistryKey
;
45 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
46 import com
.sun
.star
.lang
.XServiceInfo
;
47 import com
.sun
.star
.lang
.XServiceName
;
48 import com
.sun
.star
.sheet
.XAddIn
;
49 import com
.sun
.star
.lang
.Locale
;
50 import org
.openoffice
.sheet
.addin
.XCalcAddins
;
52 /** This outer class provides an inner class to implement the service
53 * description, a method to instantiate the
54 * component on demand (__getServiceFactory()), and a method to give
55 * information about the component (__writeRegistryServiceInfo()).
57 public class CalcAddins
{
59 /** This inner class provides the component as a concrete implementation
60 * of the service description. It implements the needed interfaces.
61 * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider
63 static public class _CalcAddins
extends WeakBase
implements
70 /** The component will be registered under this name.
72 static private final String __serviceName
= "org.openoffice.sheet.addin.CalcAddins";
74 static private final String ADDIN_SERVICE
= "com.sun.star.sheet.AddIn";
76 private Locale aFuncLoc
;
78 private static final String
[] stringFunctionName
= {
80 * You should replace these method names by the method names of your interface.
87 * For each of your methods you should make up a new constant with a different value.
89 private static final short shortGETMYFIRSTVALUE
= 0;
90 private static final short shortGETMYSECONDVALUE
= 1;
93 * This is where you implement all methods of your interface. The parameters have to
94 * be the same as in your IDL file and their types have to be the correct
95 * IDL-to-Java mappings of their types in the IDL file.
97 public int getMyFirstValue(
98 com
.sun
.star
.beans
.XPropertySet xOptions
103 public int getMySecondValue(
104 com
.sun
.star
.beans
.XPropertySet xOptions
,
110 // Implement method from interface XServiceName
111 public String
getServiceName() {
112 return __serviceName
;
115 // Implement methods from interface XServiceInfo
116 public boolean supportsService(String stringServiceName
) {
117 return( stringServiceName
.equals( ADDIN_SERVICE
) ||
118 stringServiceName
.equals( __serviceName
) );
121 public String
getImplementationName() {
122 return _CalcAddins
.class.getName();
125 public String
[] getSupportedServiceNames() {
126 String
[] stringSupportedServiceNames
= { ADDIN_SERVICE
, __serviceName
};
127 return stringSupportedServiceNames
;
130 // Implement methods from interface XAddIn
131 public String
getDisplayArgumentName(String stringProgrammaticFunctionName
,int intArgument
) {
132 String stringReturn
= "";
134 switch( this.getFunctionID( stringProgrammaticFunctionName
) ) {
136 * You should list all argument names for each of your methods, here.
138 case shortGETMYFIRSTVALUE
:
139 switch( intArgument
) {
141 stringReturn
= "(internal)";
145 case shortGETMYSECONDVALUE
:
146 switch( intArgument
) {
148 stringReturn
= "(internal)";
151 stringReturn
= "intDummy";
159 public String
getDisplayFunctionName(String stringProgrammaticName
) {
160 String stringReturn
= "";
162 switch( this.getFunctionID( stringProgrammaticName
) ) {
164 * Assign the name of each of your methods.
166 case shortGETMYFIRSTVALUE
:
167 stringReturn
= "getMyFirstValue";
169 case shortGETMYSECONDVALUE
:
170 stringReturn
= "getMySecondValue";
177 public String
getProgrammaticCategoryName(String p1
) {
181 public String
getDisplayCategoryName(String p1
) {
185 public String
getFunctionDescription(String stringProgrammaticName
) {
186 String stringReturn
= "";
188 switch( this.getFunctionID( stringProgrammaticName
) ) {
190 * Enter a description for each of your methods that office users will understand.
192 case shortGETMYFIRSTVALUE
:
193 stringReturn
= "This is your first method.";
195 case shortGETMYSECONDVALUE
:
196 stringReturn
= "This is your second method.";
203 public String
getArgumentDescription(String stringProgrammaticFunctionName
,int intArgument
) {
204 String stringReturn
= "";
206 switch( this.getFunctionID( stringProgrammaticFunctionName
) ) {
208 * Enter a description for every argument of every method. Make them so that office users will understand.
210 case shortGETMYFIRSTVALUE
:
211 switch( intArgument
) {
213 stringReturn
= "(internal)";
217 case shortGETMYSECONDVALUE
:
218 switch( intArgument
) {
220 stringReturn
= "(internal)";
223 stringReturn
= "You can add this value.";
231 public String
getProgrammaticFuntionName(String p1
) {
235 // Implement methods from interface XLocalizable
236 public Locale
getLocale() {
240 public void setLocale(Locale p1
) {
244 // Auxiliary functions
245 private short getFunctionID( String stringProgrammaticName
) {
246 for ( int i
= 0; i
< stringFunctionName
.length
; i
++ ) {
247 if ( stringProgrammaticName
.equals( stringFunctionName
[ i
] ) ) {
257 * Returns a factory for creating the service.
258 * This method is called by the <code>JavaLoader</code>
260 * @return returns a <code>XSingleServiceFactory</code> for creating the component
261 * @param implName the name of the implementation for which a service is desired
262 * @param multiFactory the service manager to be used if needed
263 * @param regKey the registryKey
264 * @see com.sun.star.comp.loader.JavaLoader
266 public static XSingleServiceFactory
__getServiceFactory(String implName
,
267 XMultiServiceFactory multiFactory
,
268 XRegistryKey regKey
) {
269 XSingleServiceFactory xSingleServiceFactory
= null;
271 if (implName
.equals(_CalcAddins
.class.getName()) )
272 xSingleServiceFactory
= FactoryHelper
.getServiceFactory(_CalcAddins
.class,
273 _CalcAddins
.__serviceName
,
277 return xSingleServiceFactory
;