cid#1607171 Data race condition
[LibreOffice.git] / odk / examples / java / Spreadsheet / CalcAddins.java
blob37785056e5c70f715546a2131a755f8195a037c2
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
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
38 /** You can find more
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
65 XCalcAddins,
66 XAddIn,
67 XServiceName,
68 XServiceInfo
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 = {
80 /** TO DO:
81 * You should replace these method names by the method names of your interface.
83 "getMyFirstValue",
84 "getMySecondValue"
87 /** TO DO:
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;
93 /** TO DO:
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
101 return 1;
104 public int getMySecondValue(
105 com.sun.star.beans.XPropertySet xOptions,
106 int intDummy
108 return 2 + intDummy;
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 ) ) {
136 /** TO DO:
137 * You should list all argument names for each of your methods, here.
139 case shortGETMYFIRSTVALUE:
140 switch( intArgument ) {
141 case 0:
142 stringReturn = "(internal)";
143 break;
145 break;
146 case shortGETMYSECONDVALUE:
147 switch( intArgument ) {
148 case 0:
149 stringReturn = "(internal)";
150 break;
151 case 1:
152 stringReturn = "intDummy";
153 break;
155 break;
157 return stringReturn;
160 public String getDisplayFunctionName(String stringProgrammaticName) {
161 String stringReturn = "";
163 switch( this.getFunctionID( stringProgrammaticName ) ) {
164 /** TO DO:
165 * Assign the name of each of your methods.
167 case shortGETMYFIRSTVALUE:
168 stringReturn = "getMyFirstValue";
169 break;
170 case shortGETMYSECONDVALUE:
171 stringReturn = "getMySecondValue";
172 break;
175 return stringReturn;
178 public String getProgrammaticCategoryName(String p1) {
179 return "Add-In";
182 public String getDisplayCategoryName(String p1) {
183 return "Add-In";
186 public String getFunctionDescription(String stringProgrammaticName) {
187 String stringReturn = "";
189 switch( this.getFunctionID( stringProgrammaticName ) ) {
190 /** TO DO:
191 * Enter a description for each of your methods that office users will understand.
193 case shortGETMYFIRSTVALUE:
194 stringReturn = "This is your first method.";
195 break;
196 case shortGETMYSECONDVALUE:
197 stringReturn = "This is your second method.";
198 break;
201 return stringReturn;
204 public String getArgumentDescription(String stringProgrammaticFunctionName,int intArgument) {
205 String stringReturn = "";
207 switch( this.getFunctionID( stringProgrammaticFunctionName ) ) {
208 /** TO DO:
209 * Enter a description for every argument of every method. Make them so that office users will understand.
211 case shortGETMYFIRSTVALUE:
212 switch( intArgument ) {
213 case 0:
214 stringReturn = "(internal)";
215 break;
217 break;
218 case shortGETMYSECONDVALUE:
219 switch( intArgument ) {
220 case 0:
221 stringReturn = "(internal)";
222 break;
223 case 1:
224 stringReturn = "You can add this value.";
225 break;
227 break;
229 return stringReturn;
232 public String getProgrammaticFuntionName(String p1) {
233 return "";
236 // Implement methods from interface XLocalizable
237 public Locale getLocale() {
238 return aFuncLoc;
241 public void setLocale(Locale p1) {
242 aFuncLoc = 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 ] ) ) {
249 return ( short ) i;
253 return -1;
258 * Returns a factory for creating the service.
259 * This method is called by the <code>JavaLoader</code>
260 * <p>
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,
275 multiFactory,
276 regKey);
278 return xSingleServiceFactory;
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */