1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 // Template for an Office Calc add-in Java implementation file.
39 * information on the following web page:
40 * https://api.libreoffice.org/
42 import com
.sun
.star
.comp
.loader
.FactoryHelper
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.lang
.XSingleServiceFactory
;
45 import com
.sun
.star
.registry
.XRegistryKey
;
46 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
47 import com
.sun
.star
.lang
.XServiceInfo
;
48 import com
.sun
.star
.lang
.XServiceName
;
49 import com
.sun
.star
.sheet
.XAddIn
;
50 import com
.sun
.star
.lang
.Locale
;
51 import org
.openoffice
.sheet
.addin
.XCalcAddins
;
53 /** This outer class provides an inner class to implement the service
54 * description, a method to instantiate the
55 * component on demand (__getServiceFactory()), and a method to give
56 * information about the component (__writeRegistryServiceInfo()).
58 public class CalcAddins
{
60 /** This inner class provides the component as a concrete implementation
61 * of the service description. It implements the needed interfaces.
62 * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider
64 public static class _CalcAddins
extends WeakBase
implements
71 /** The component will be registered under this name.
73 private static final String __serviceName
= "org.openoffice.sheet.addin.CalcAddins";
75 private static final String ADDIN_SERVICE
= "com.sun.star.sheet.AddIn";
77 private Locale aFuncLoc
;
79 private static final String
[] stringFunctionName
= {
81 * You should replace these method names by the method names of your interface.
88 * For each of your methods you should make up a new constant with a different value.
90 private static final short shortGETMYFIRSTVALUE
= 0;
91 private static final short shortGETMYSECONDVALUE
= 1;
94 * This is where you implement all methods of your interface. The parameters have to
95 * be the same as in your IDL file and their types have to be the correct
96 * IDL-to-Java mappings of their types in the IDL file.
98 public int getMyFirstValue(
99 com
.sun
.star
.beans
.XPropertySet xOptions
104 public int getMySecondValue(
105 com
.sun
.star
.beans
.XPropertySet xOptions
,
111 // Implement method from interface XServiceName
112 public String
getServiceName() {
113 return __serviceName
;
116 // Implement methods from interface XServiceInfo
117 public boolean supportsService(String stringServiceName
) {
118 return( stringServiceName
.equals( ADDIN_SERVICE
) ||
119 stringServiceName
.equals( __serviceName
) );
122 public String
getImplementationName() {
123 return _CalcAddins
.class.getName();
126 public String
[] getSupportedServiceNames() {
127 String
[] stringSupportedServiceNames
= { ADDIN_SERVICE
, __serviceName
};
128 return stringSupportedServiceNames
;
131 // Implement methods from interface XAddIn
132 public String
getDisplayArgumentName(String stringProgrammaticFunctionName
,int intArgument
) {
133 String stringReturn
= "";
135 switch( this.getFunctionID( stringProgrammaticFunctionName
) ) {
137 * You should list all argument names for each of your methods, here.
139 case shortGETMYFIRSTVALUE
:
140 switch( intArgument
) {
142 stringReturn
= "(internal)";
146 case shortGETMYSECONDVALUE
:
147 switch( intArgument
) {
149 stringReturn
= "(internal)";
152 stringReturn
= "intDummy";
160 public String
getDisplayFunctionName(String stringProgrammaticName
) {
161 String stringReturn
= "";
163 switch( this.getFunctionID( stringProgrammaticName
) ) {
165 * Assign the name of each of your methods.
167 case shortGETMYFIRSTVALUE
:
168 stringReturn
= "getMyFirstValue";
170 case shortGETMYSECONDVALUE
:
171 stringReturn
= "getMySecondValue";
178 public String
getProgrammaticCategoryName(String p1
) {
182 public String
getDisplayCategoryName(String p1
) {
186 public String
getFunctionDescription(String stringProgrammaticName
) {
187 String stringReturn
= "";
189 switch( this.getFunctionID( stringProgrammaticName
) ) {
191 * Enter a description for each of your methods that office users will understand.
193 case shortGETMYFIRSTVALUE
:
194 stringReturn
= "This is your first method.";
196 case shortGETMYSECONDVALUE
:
197 stringReturn
= "This is your second method.";
204 public String
getArgumentDescription(String stringProgrammaticFunctionName
,int intArgument
) {
205 String stringReturn
= "";
207 switch( this.getFunctionID( stringProgrammaticFunctionName
) ) {
209 * Enter a description for every argument of every method. Make them so that office users will understand.
211 case shortGETMYFIRSTVALUE
:
212 switch( intArgument
) {
214 stringReturn
= "(internal)";
218 case shortGETMYSECONDVALUE
:
219 switch( intArgument
) {
221 stringReturn
= "(internal)";
224 stringReturn
= "You can add this value.";
232 public String
getProgrammaticFuntionName(String p1
) {
236 // Implement methods from interface XLocalizable
237 public Locale
getLocale() {
241 public void setLocale(Locale p1
) {
245 // Auxiliary functions
246 private short getFunctionID( String stringProgrammaticName
) {
247 for ( int i
= 0; i
< stringFunctionName
.length
; i
++ ) {
248 if ( stringProgrammaticName
.equals( stringFunctionName
[ i
] ) ) {
258 * Returns a factory for creating the service.
259 * This method is called by the <code>JavaLoader</code>
261 * @return returns a <code>XSingleServiceFactory</code> for creating the component
262 * @param implName the name of the implementation for which a service is desired
263 * @param multiFactory the service manager to be used if needed
264 * @param regKey the registryKey
265 * @see com.sun.star.comp.loader.JavaLoader
267 public static XSingleServiceFactory
__getServiceFactory(String implName
,
268 XMultiServiceFactory multiFactory
,
269 XRegistryKey regKey
) {
270 XSingleServiceFactory xSingleServiceFactory
= null;
272 if (implName
.equals(_CalcAddins
.class.getName()) )
273 xSingleServiceFactory
= FactoryHelper
.getServiceFactory(_CalcAddins
.class,
274 _CalcAddins
.__serviceName
,
278 return xSingleServiceFactory
;
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */