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