1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * The Contents of this file are made available subject to the terms of 4*cdf0e10cSrcweir * the BSD license. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * All rights reserved. 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * Redistribution and use in source and binary forms, with or without 10*cdf0e10cSrcweir * modification, are permitted provided that the following conditions 11*cdf0e10cSrcweir * are met: 12*cdf0e10cSrcweir * 1. Redistributions of source code must retain the above copyright 13*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer. 14*cdf0e10cSrcweir * 2. Redistributions in binary form must reproduce the above copyright 15*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer in the 16*cdf0e10cSrcweir * documentation and/or other materials provided with the distribution. 17*cdf0e10cSrcweir * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18*cdf0e10cSrcweir * contributors may be used to endorse or promote products derived 19*cdf0e10cSrcweir * from this software without specific prior written permission. 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*cdf0e10cSrcweir * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*cdf0e10cSrcweir * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*cdf0e10cSrcweir * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*cdf0e10cSrcweir * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*cdf0e10cSrcweir * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*cdf0e10cSrcweir * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28*cdf0e10cSrcweir * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29*cdf0e10cSrcweir * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30*cdf0e10cSrcweir * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31*cdf0e10cSrcweir * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*cdf0e10cSrcweir * 33*cdf0e10cSrcweir *************************************************************************/ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir // Template for an Office Calc add-in Java implementation file. 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir /** You can find more 38*cdf0e10cSrcweir * information on the following web page: 39*cdf0e10cSrcweir * http://api.openoffice.org/common/ref/com/sun/star/index.html 40*cdf0e10cSrcweir */ 41*cdf0e10cSrcweir import com.sun.star.comp.loader.FactoryHelper; 42*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 43*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 44*cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey; 45*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 46*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase; 47*cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 48*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 49*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 50*cdf0e10cSrcweir import com.sun.star.lang.XServiceName; 51*cdf0e10cSrcweir import com.sun.star.sheet.XAddIn; 52*cdf0e10cSrcweir import com.sun.star.lang.Locale; 53*cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider; 54*cdf0e10cSrcweir import com.sun.star.uno.Type; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir import org.openoffice.sheet.addin.XCalcAddins; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir /** This outer class provides an inner class to implement the service 59*cdf0e10cSrcweir * description, a method to instantiate the 60*cdf0e10cSrcweir * component on demand (__getServiceFactory()), and a method to give 61*cdf0e10cSrcweir * information about the component (__writeRegistryServiceInfo()). 62*cdf0e10cSrcweir */ 63*cdf0e10cSrcweir public class CalcAddins { 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir /** This inner class provides the component as a concrete implementation 66*cdf0e10cSrcweir * of the service description. It implements the needed interfaces. 67*cdf0e10cSrcweir * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider 68*cdf0e10cSrcweir */ 69*cdf0e10cSrcweir static public class _CalcAddins extends WeakBase implements 70*cdf0e10cSrcweir XCalcAddins, 71*cdf0e10cSrcweir XAddIn, 72*cdf0e10cSrcweir XServiceName, 73*cdf0e10cSrcweir XServiceInfo 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir /** The component will be registered under this name. 77*cdf0e10cSrcweir */ 78*cdf0e10cSrcweir static private final String __serviceName = "org.openoffice.sheet.addin.CalcAddins"; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir static private final String ADDIN_SERVICE = "com.sun.star.sheet.AddIn"; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir private Locale aFuncLoc; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir private static final String[] stringFunctionName = { 85*cdf0e10cSrcweir /** TO DO: 86*cdf0e10cSrcweir * You should replace these method names by the method names of your interface. 87*cdf0e10cSrcweir */ 88*cdf0e10cSrcweir "getMyFirstValue", 89*cdf0e10cSrcweir "getMySecondValue" 90*cdf0e10cSrcweir }; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir private static final short shortINVALID = -1; 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir /** TO DO: 95*cdf0e10cSrcweir * For each of your methods you should make up a new constant with a different value. 96*cdf0e10cSrcweir */ 97*cdf0e10cSrcweir private static final short shortGETMYFIRSTVALUE = 0; 98*cdf0e10cSrcweir private static final short shortGETMYSECONDVALUE = 1; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir /** TO DO: 102*cdf0e10cSrcweir * This is where you implement all methods of your interface. The parameters have to 103*cdf0e10cSrcweir * be the same as in your IDL file and their types have to be the correct 104*cdf0e10cSrcweir * IDL-to-Java mappings of their types in the IDL file. 105*cdf0e10cSrcweir */ 106*cdf0e10cSrcweir public int getMyFirstValue( 107*cdf0e10cSrcweir com.sun.star.beans.XPropertySet xOptions 108*cdf0e10cSrcweir ) { 109*cdf0e10cSrcweir return (int) 1; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir public int getMySecondValue( 113*cdf0e10cSrcweir com.sun.star.beans.XPropertySet xOptions, 114*cdf0e10cSrcweir int intDummy 115*cdf0e10cSrcweir ) { 116*cdf0e10cSrcweir return( (int) ( 2 + intDummy ) ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // Implement method from interface XServiceName 121*cdf0e10cSrcweir public String getServiceName() { 122*cdf0e10cSrcweir return( __serviceName ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // Implement methods from interface XServiceInfo 126*cdf0e10cSrcweir public boolean supportsService(String stringServiceName) { 127*cdf0e10cSrcweir return( stringServiceName.equals( ADDIN_SERVICE ) || 128*cdf0e10cSrcweir stringServiceName.equals( __serviceName ) ); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir public String getImplementationName() { 132*cdf0e10cSrcweir return( _CalcAddins.class.getName() ); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir public String[] getSupportedServiceNames() { 136*cdf0e10cSrcweir String[] stringSupportedServiceNames = { ADDIN_SERVICE, __serviceName }; 137*cdf0e10cSrcweir return( stringSupportedServiceNames ); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // Implement methods from interface XAddIn 141*cdf0e10cSrcweir public String getDisplayArgumentName(String stringProgrammaticFunctionName,int intArgument) { 142*cdf0e10cSrcweir String stringReturn = ""; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir switch( this.getFunctionID( stringProgrammaticFunctionName ) ) { 145*cdf0e10cSrcweir /** TO DO: 146*cdf0e10cSrcweir * You should list all argument names for each of your methods, here. 147*cdf0e10cSrcweir */ 148*cdf0e10cSrcweir case shortGETMYFIRSTVALUE: 149*cdf0e10cSrcweir switch( intArgument ) { 150*cdf0e10cSrcweir case 0: 151*cdf0e10cSrcweir stringReturn = "(internal)"; 152*cdf0e10cSrcweir break; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir break; 155*cdf0e10cSrcweir case shortGETMYSECONDVALUE: 156*cdf0e10cSrcweir switch( intArgument ) { 157*cdf0e10cSrcweir case 0: 158*cdf0e10cSrcweir stringReturn = "(internal)"; 159*cdf0e10cSrcweir break; 160*cdf0e10cSrcweir case 1: 161*cdf0e10cSrcweir stringReturn = "intDummy"; 162*cdf0e10cSrcweir break; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir break; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir return( stringReturn ); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir public String getDisplayFunctionName(String stringProgrammaticName) { 170*cdf0e10cSrcweir String stringReturn = ""; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir switch( this.getFunctionID( stringProgrammaticName ) ) { 173*cdf0e10cSrcweir /** TO DO: 174*cdf0e10cSrcweir * Assign the name of each of your methods. 175*cdf0e10cSrcweir */ 176*cdf0e10cSrcweir case shortGETMYFIRSTVALUE: 177*cdf0e10cSrcweir stringReturn = "getMyFirstValue"; 178*cdf0e10cSrcweir break; 179*cdf0e10cSrcweir case shortGETMYSECONDVALUE: 180*cdf0e10cSrcweir stringReturn = "getMySecondValue"; 181*cdf0e10cSrcweir break; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir return( stringReturn ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir public String getProgrammaticCategoryName(String p1) { 188*cdf0e10cSrcweir return( "Add-In" ); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir public String getDisplayCategoryName(String p1) { 192*cdf0e10cSrcweir return( "Add-In" ); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir public String getFunctionDescription(String stringProgrammaticName) { 196*cdf0e10cSrcweir String stringReturn = ""; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir switch( this.getFunctionID( stringProgrammaticName ) ) { 199*cdf0e10cSrcweir /** TO DO: 200*cdf0e10cSrcweir * Enter a description for each of your methods that office users will understand. 201*cdf0e10cSrcweir */ 202*cdf0e10cSrcweir case shortGETMYFIRSTVALUE: 203*cdf0e10cSrcweir stringReturn = "This is your first method."; 204*cdf0e10cSrcweir break; 205*cdf0e10cSrcweir case shortGETMYSECONDVALUE: 206*cdf0e10cSrcweir stringReturn = "This is your second method."; 207*cdf0e10cSrcweir break; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir return( stringReturn ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir public String getArgumentDescription(String stringProgrammaticFunctionName,int intArgument) { 214*cdf0e10cSrcweir String stringReturn = ""; 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir switch( this.getFunctionID( stringProgrammaticFunctionName ) ) { 217*cdf0e10cSrcweir /** TO DO: 218*cdf0e10cSrcweir * Enter a description for every argument of every method. Make them so that office users will understand. 219*cdf0e10cSrcweir */ 220*cdf0e10cSrcweir case shortGETMYFIRSTVALUE: 221*cdf0e10cSrcweir switch( intArgument ) { 222*cdf0e10cSrcweir case 0: 223*cdf0e10cSrcweir stringReturn = "(internal)"; 224*cdf0e10cSrcweir break; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir break; 227*cdf0e10cSrcweir case shortGETMYSECONDVALUE: 228*cdf0e10cSrcweir switch( intArgument ) { 229*cdf0e10cSrcweir case 0: 230*cdf0e10cSrcweir stringReturn = "(internal)"; 231*cdf0e10cSrcweir break; 232*cdf0e10cSrcweir case 1: 233*cdf0e10cSrcweir stringReturn = "You can add this value."; 234*cdf0e10cSrcweir break; 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir break; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir return( stringReturn ); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir public String getProgrammaticFuntionName(String p1) { 242*cdf0e10cSrcweir return( "" ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir // Implement methods from interface XLocalizable 246*cdf0e10cSrcweir public Locale getLocale() { 247*cdf0e10cSrcweir return( aFuncLoc ); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir public void setLocale(Locale p1) { 251*cdf0e10cSrcweir aFuncLoc = p1; 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir // Auxiliary functions 255*cdf0e10cSrcweir private short getFunctionID( String stringProgrammaticName ) { 256*cdf0e10cSrcweir for ( int i = 0; i < stringFunctionName.length; i++ ) { 257*cdf0e10cSrcweir if ( stringProgrammaticName.equals( stringFunctionName[ i ] ) ) { 258*cdf0e10cSrcweir return( ( short ) i ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir return( -1 ); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir /** 267*cdf0e10cSrcweir * Returns a factory for creating the service. 268*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 269*cdf0e10cSrcweir * <p> 270*cdf0e10cSrcweir * @return returns a <code>XSingleServiceFactory</code> for creating the component 271*cdf0e10cSrcweir * @param implName the name of the implementation for which a service is desired 272*cdf0e10cSrcweir * @param multiFactory the service manager to be used if needed 273*cdf0e10cSrcweir * @param regKey the registryKey 274*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 275*cdf0e10cSrcweir */ 276*cdf0e10cSrcweir public static XSingleServiceFactory __getServiceFactory(String implName, 277*cdf0e10cSrcweir XMultiServiceFactory multiFactory, 278*cdf0e10cSrcweir XRegistryKey regKey) { 279*cdf0e10cSrcweir XSingleServiceFactory xSingleServiceFactory = null; 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir if (implName.equals(_CalcAddins.class.getName()) ) 282*cdf0e10cSrcweir xSingleServiceFactory = FactoryHelper.getServiceFactory(_CalcAddins.class, 283*cdf0e10cSrcweir _CalcAddins.__serviceName, 284*cdf0e10cSrcweir multiFactory, 285*cdf0e10cSrcweir regKey); 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir return xSingleServiceFactory; 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir /** 291*cdf0e10cSrcweir * Writes the service information into the given registry key. 292*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 293*cdf0e10cSrcweir * <p> 294*cdf0e10cSrcweir * @return returns true if the operation succeeded 295*cdf0e10cSrcweir * @param regKey the registryKey 296*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 297*cdf0e10cSrcweir */ 298*cdf0e10cSrcweir // This method not longer necessary since OOo 3.4 where the component registration 299*cdf0e10cSrcweir // was changed to passive component registration. For more details see 300*cdf0e10cSrcweir // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir // public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { 303*cdf0e10cSrcweir // return FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(), 304*cdf0e10cSrcweir // _CalcAddins.__serviceName, regKey) 305*cdf0e10cSrcweir // && FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(), 306*cdf0e10cSrcweir // _CalcAddins.ADDIN_SERVICE, regKey); 307*cdf0e10cSrcweir // } 308*cdf0e10cSrcweir } 309