1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "codemaker/commonjava.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "skeletoncommon.hxx" 31*cdf0e10cSrcweir #include "skeletonjava.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <iostream> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir using namespace ::rtl; 36*cdf0e10cSrcweir using namespace ::codemaker::java; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir namespace skeletonmaker { namespace java { 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir void generatePackage(std::ostream & o, const OString & implname) 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir sal_Int32 index = implname.lastIndexOf('.'); 43*cdf0e10cSrcweir if (index != -1) 44*cdf0e10cSrcweir o << "package " << implname.copy(0, index) << ";\n\n"; 45*cdf0e10cSrcweir } 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir void generateImports(std::ostream & o, ProgramOptions const & options, 48*cdf0e10cSrcweir const std::hash_set< OString, OStringHash >& /*interfaces*/, 49*cdf0e10cSrcweir const OString & propertyhelper, 50*cdf0e10cSrcweir bool serviceobject, bool supportxcomponent) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir if (options.componenttype == 3) 53*cdf0e10cSrcweir o << "import com.sun.star.uno.UnoRuntime;\n"; 54*cdf0e10cSrcweir o << "import com.sun.star.uno.XComponentContext;\n"; 55*cdf0e10cSrcweir if (serviceobject) { 56*cdf0e10cSrcweir o << "import com.sun.star.lib.uno.helper.Factory;\n"; 57*cdf0e10cSrcweir o << "import com.sun.star.lang.XSingleComponentFactory;\n"; 58*cdf0e10cSrcweir o << "import com.sun.star.registry.XRegistryKey;\n"; 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir if (!propertyhelper.equals("_")) { 62*cdf0e10cSrcweir if (supportxcomponent) 63*cdf0e10cSrcweir o << "import com.sun.star.lib.uno.helper.ComponentBase;\n"; 64*cdf0e10cSrcweir else 65*cdf0e10cSrcweir o << "import com.sun.star.lib.uno.helper.WeakBase;\n"; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir if (propertyhelper.getLength() > 0) { 68*cdf0e10cSrcweir if (propertyhelper.equals("_")) { 69*cdf0e10cSrcweir o << "import com.sun.star.lib.uno.helper.PropertySet;\n"; 70*cdf0e10cSrcweir o << "import com.sun.star.beans.PropertyAttribute;\n"; 71*cdf0e10cSrcweir } else { 72*cdf0e10cSrcweir o << "import com.sun.star.uno.Type;\n"; 73*cdf0e10cSrcweir o << "import com.sun.star.uno.Any;\n"; 74*cdf0e10cSrcweir o << "import com.sun.star.beans.Ambiguous;\n"; 75*cdf0e10cSrcweir o << "import com.sun.star.beans.Defaulted;\n"; 76*cdf0e10cSrcweir o << "import com.sun.star.beans.Optional;\n"; 77*cdf0e10cSrcweir o << "import com.sun.star.lib.uno.helper.PropertySetMixin;\n"; 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // std::hash_set< OString, OStringHash >::const_iterator iter = 83*cdf0e10cSrcweir // interfaces.begin(); 84*cdf0e10cSrcweir // while (iter != interfaces.end()) 85*cdf0e10cSrcweir // { 86*cdf0e10cSrcweir // o << "import " << ((*iter).getStr()) << ";\n"; 87*cdf0e10cSrcweir // iter++; 88*cdf0e10cSrcweir // } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir void generateCompFunctions(std::ostream & o, const OString & classname) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir o << " public static XSingleComponentFactory __getComponentFactory(" 94*cdf0e10cSrcweir " String sImplementationName ) {\n" 95*cdf0e10cSrcweir " XSingleComponentFactory xFactory = null;\n\n" 96*cdf0e10cSrcweir " if ( sImplementationName.equals( m_implementationName ) )\n" 97*cdf0e10cSrcweir " xFactory = Factory.createComponentFactory(" 98*cdf0e10cSrcweir << classname << ".class, m_serviceNames);\n" 99*cdf0e10cSrcweir " return xFactory;\n }\n\n"; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir o << " public static boolean __writeRegistryServiceInfo(" 102*cdf0e10cSrcweir " XRegistryKey xRegistryKey ) {\n" 103*cdf0e10cSrcweir " return Factory.writeRegistryServiceInfo(m_implementationName,\n" 104*cdf0e10cSrcweir " m_serviceNames,\n" 105*cdf0e10cSrcweir " xRegistryKey);\n" 106*cdf0e10cSrcweir " }\n\n"; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir void generateXServiceInfoBodies(std::ostream& o) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir o << " // com.sun.star.lang.XServiceInfo:\n"; 112*cdf0e10cSrcweir o << " public String getImplementationName() {\n" 113*cdf0e10cSrcweir << " return m_implementationName;\n }\n\n"; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir o << " public boolean supportsService( String sService ) {\n" 116*cdf0e10cSrcweir << " int len = m_serviceNames.length;\n\n" 117*cdf0e10cSrcweir << " for( int i=0; i < len; i++) {\n" 118*cdf0e10cSrcweir << " if (sService.equals(m_serviceNames[i]))\n" 119*cdf0e10cSrcweir << " return true;\n" 120*cdf0e10cSrcweir << " }\n return false;\n }\n\n"; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir o << " public String[] getSupportedServiceNames() {\n" 123*cdf0e10cSrcweir << " return m_serviceNames;\n }\n\n"; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir void generateXPropertySetBodies(std::ostream& o) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir o << " // com.sun.star.beans.XPropertySet:\n"; 129*cdf0e10cSrcweir o << " public com.sun.star.beans.XPropertySetInfo getPropertySetInfo()\n" 130*cdf0e10cSrcweir " {\n return m_prophlp.getPropertySetInfo();\n }\n\n"; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir o << " public void setPropertyValue(String aPropertyName, " 133*cdf0e10cSrcweir "Object aValue) throws " 134*cdf0e10cSrcweir "com.sun.star.beans.UnknownPropertyException, " 135*cdf0e10cSrcweir "com.sun.star.beans.PropertyVetoException, " 136*cdf0e10cSrcweir "com.sun.star.lang.IllegalArgumentException," 137*cdf0e10cSrcweir "com.sun.star.lang.WrappedTargetException\n {\n " 138*cdf0e10cSrcweir "m_prophlp.setPropertyValue(aPropertyName, aValue);\n }\n\n"; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir o << " public Object getPropertyValue(String " 141*cdf0e10cSrcweir "aPropertyName) throws com.sun.star.beans.UnknownPropertyException, " 142*cdf0e10cSrcweir "com.sun.star.lang.WrappedTargetException\n {\n return " 143*cdf0e10cSrcweir "m_prophlp.getPropertyValue(aPropertyName);\n }\n\n"; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir o << " public void addPropertyChangeListener(String aPropertyName" 146*cdf0e10cSrcweir ", com.sun.star.beans.XPropertyChangeListener xListener) throws " 147*cdf0e10cSrcweir "com.sun.star.beans.UnknownPropertyException, " 148*cdf0e10cSrcweir "com.sun.star.lang.WrappedTargetException\n {\n " 149*cdf0e10cSrcweir "m_prophlp.addPropertyChangeListener(aPropertyName, xListener);\n }\n\n"; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir o << " public void removePropertyChangeListener(String " 152*cdf0e10cSrcweir "aPropertyName, com.sun.star.beans.XPropertyChangeListener xListener) " 153*cdf0e10cSrcweir "throws com.sun.star.beans.UnknownPropertyException, " 154*cdf0e10cSrcweir "com.sun.star.lang.WrappedTargetException\n {\n " 155*cdf0e10cSrcweir "m_prophlp.removePropertyChangeListener(aPropertyName, xListener);\n" 156*cdf0e10cSrcweir " }\n\n"; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir o << " public void addVetoableChangeListener(String aPropertyName" 159*cdf0e10cSrcweir ", com.sun.star.beans.XVetoableChangeListener xListener) throws " 160*cdf0e10cSrcweir "com.sun.star.beans.UnknownPropertyException, " 161*cdf0e10cSrcweir "com.sun.star.lang.WrappedTargetException\n {\n " 162*cdf0e10cSrcweir "m_prophlp.addVetoableChangeListener(aPropertyName, xListener);\n }\n\n"; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir o << " public void removeVetoableChangeListener(String " 165*cdf0e10cSrcweir "aPropertyName, com.sun.star.beans.XVetoableChangeListener xListener) " 166*cdf0e10cSrcweir "throws com.sun.star.beans.UnknownPropertyException, " 167*cdf0e10cSrcweir "com.sun.star.lang.WrappedTargetException\n {\n " 168*cdf0e10cSrcweir "m_prophlp.removeVetoableChangeListener(aPropertyName, xListener);\n }\n\n"; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir void generateXFastPropertySetBodies(std::ostream& o) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir o << " // com.sun.star.beans.XFastPropertySet:\n"; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir o << " public void setFastPropertyValue(int nHandle, Object " 176*cdf0e10cSrcweir "aValue) throws com.sun.star.beans.UnknownPropertyException, " 177*cdf0e10cSrcweir "com.sun.star.beans.PropertyVetoException, " 178*cdf0e10cSrcweir "com.sun.star.lang.IllegalArgumentException, " 179*cdf0e10cSrcweir "com.sun.star.lang.WrappedTargetException\n {\n " 180*cdf0e10cSrcweir "m_prophlp.setFastPropertyValue(nHandle, aValue);\n }\n\n"; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir o << " public Object getFastPropertyValue(int nHandle) throws " 183*cdf0e10cSrcweir "com.sun.star.beans.UnknownPropertyException, " 184*cdf0e10cSrcweir "com.sun.star.lang.WrappedTargetException\n {\n return " 185*cdf0e10cSrcweir "m_prophlp.getFastPropertyValue(nHandle);\n }\n\n"; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir void generateXPropertyAccessBodies(std::ostream& o) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir o << " // com.sun.star.beans.XPropertyAccess:\n"; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir o << " public com.sun.star.beans.PropertyValue[] getPropertyValues()\n" 193*cdf0e10cSrcweir " {\n return m_prophlp.getPropertyValues();\n }\n\n"; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir o << " public void setPropertyValues(com.sun.star.beans.PropertyValue[] " 196*cdf0e10cSrcweir "aProps) throws com.sun.star.beans.UnknownPropertyException, " 197*cdf0e10cSrcweir "com.sun.star.beans.PropertyVetoException, " 198*cdf0e10cSrcweir "com.sun.star.lang.IllegalArgumentException, " 199*cdf0e10cSrcweir "com.sun.star.lang.WrappedTargetException\n {\n " 200*cdf0e10cSrcweir "m_prophlp.setPropertyValues(aProps);\n }\n\n"; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir bool checkAttribute(OStringBuffer& attributeValue, sal_uInt16 attribute) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir bool cast = false; 207*cdf0e10cSrcweir sal_uInt16 attributes[9] = { 208*cdf0e10cSrcweir /* com::sun::star::beans::PropertyValue::MAYBEVOID */ 1, 209*cdf0e10cSrcweir /* com::sun::star::beans::PropertyValue::BOUND */ 2, 210*cdf0e10cSrcweir /* com::sun::star::beans::PropertyValue::CONSTRAINED */ 4, 211*cdf0e10cSrcweir /* com::sun::star::beans::PropertyValue::TRANSIENT */ 8, 212*cdf0e10cSrcweir /* com::sun::star::beans::PropertyValue::READONLY */ 16, 213*cdf0e10cSrcweir /* com::sun::star::beans::PropertyValue::MAYBEAMBIGIOUS */ 32, 214*cdf0e10cSrcweir /* com::sun::star::beans::PropertyValue::MAYBEDEFAULT */ 64, 215*cdf0e10cSrcweir /* com::sun::star::beans::PropertyValue::REMOVEABLE */ 128, 216*cdf0e10cSrcweir /* com::sun::star::beans::PropertyValue::OPTIONAL */ 256 }; 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir for (sal_uInt16 i = 0; i < 9; i++) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir if (attribute & attributes[i]) { 221*cdf0e10cSrcweir if (attributeValue.getLength() > 0) { 222*cdf0e10cSrcweir cast |= true; 223*cdf0e10cSrcweir attributeValue.append("|"); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir switch (attributes[i]) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir case 1: 228*cdf0e10cSrcweir attributeValue.append("PropertyAttribute.MAYBEVOID"); 229*cdf0e10cSrcweir break; 230*cdf0e10cSrcweir case 2: 231*cdf0e10cSrcweir attributeValue.append("PropertyAttribute.BOUND"); 232*cdf0e10cSrcweir break; 233*cdf0e10cSrcweir case 4: 234*cdf0e10cSrcweir attributeValue.append("PropertyAttribute.CONSTRAINED"); 235*cdf0e10cSrcweir break; 236*cdf0e10cSrcweir case 8: 237*cdf0e10cSrcweir attributeValue.append("PropertyAttribute.TRANSIENT"); 238*cdf0e10cSrcweir break; 239*cdf0e10cSrcweir case 16: 240*cdf0e10cSrcweir attributeValue.append("PropertyAttribute.READONLY"); 241*cdf0e10cSrcweir break; 242*cdf0e10cSrcweir case 32: 243*cdf0e10cSrcweir attributeValue.append("PropertyAttribute.MAYBEAMBIGIOUS"); 244*cdf0e10cSrcweir break; 245*cdf0e10cSrcweir case 64: 246*cdf0e10cSrcweir attributeValue.append("PropertyAttribute.MAYBEDEFAULT"); 247*cdf0e10cSrcweir break; 248*cdf0e10cSrcweir case 128: 249*cdf0e10cSrcweir attributeValue.append("PropertyAttribute.REMOVEABLE"); 250*cdf0e10cSrcweir break; 251*cdf0e10cSrcweir case 256: 252*cdf0e10cSrcweir attributeValue.append("PropertyAttribute.OPTIONAL"); 253*cdf0e10cSrcweir break; 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir if (cast) { 258*cdf0e10cSrcweir attributeValue.insert(0, '('); 259*cdf0e10cSrcweir attributeValue.append(')'); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir return cast; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir void registerProperties(std::ostream& o, 266*cdf0e10cSrcweir TypeManager const & /*manager*/, 267*cdf0e10cSrcweir const AttributeInfo& properties, 268*cdf0e10cSrcweir const OString& indentation) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir if (!properties.empty()) { 271*cdf0e10cSrcweir bool cast = false; 272*cdf0e10cSrcweir OStringBuffer attributeValue; 273*cdf0e10cSrcweir for (AttributeInfo::const_iterator i(properties.begin()); 274*cdf0e10cSrcweir i != properties.end(); ++i) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir if (i->second.second > 0) { 277*cdf0e10cSrcweir cast = checkAttribute(attributeValue, i->second.second); 278*cdf0e10cSrcweir } else { 279*cdf0e10cSrcweir cast = true; 280*cdf0e10cSrcweir attributeValue.append('0'); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir o << indentation << "registerProperty(\"" << i->first 284*cdf0e10cSrcweir << "\", \"m_" << i->first << "\",\n" 285*cdf0e10cSrcweir << indentation << " "; 286*cdf0e10cSrcweir if (cast) 287*cdf0e10cSrcweir o << "(short)"; 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir o << attributeValue.makeStringAndClear() << ");\n"; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir void generateXLocalizableBodies(std::ostream& o) { 295*cdf0e10cSrcweir // com.sun.star.lang.XLocalizable: 296*cdf0e10cSrcweir // setLocale 297*cdf0e10cSrcweir o << " // com.sun.star.lang.XLocalizable:\n" 298*cdf0e10cSrcweir " public void setLocale(com.sun.star.lang.Locale eLocale)\n {\n" 299*cdf0e10cSrcweir " m_locale = eLocale;\n }\n\n"; 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir // getLocale 302*cdf0e10cSrcweir o << " public com.sun.star.lang.Locale getLocale()\n {\n" 303*cdf0e10cSrcweir " return m_locale;\n }\n\n"; 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir void generateXAddInBodies(std::ostream& o, ProgramOptions const & options) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir // com.sun.star.sheet.XAddIn: 309*cdf0e10cSrcweir // getProgrammaticFuntionName 310*cdf0e10cSrcweir o << " // com.sun.star.sheet.XAddIn:\n" 311*cdf0e10cSrcweir " public String getProgrammaticFuntionName(String " 312*cdf0e10cSrcweir "aDisplayName)\n {\n" 313*cdf0e10cSrcweir " try {\n" 314*cdf0e10cSrcweir " com.sun.star.container.XNameAccess xNAccess =\n" 315*cdf0e10cSrcweir " (com.sun.star.container.XNameAccess)UnoRuntime." 316*cdf0e10cSrcweir "queryInterface(\n" 317*cdf0e10cSrcweir " com.sun.star.container.XNameAccess.class, m_xHAccess);" 318*cdf0e10cSrcweir "\n String functions[] = xNAccess.getElementNames();\n" 319*cdf0e10cSrcweir " String sDisplayName = \"\";\n" 320*cdf0e10cSrcweir " int len = functions.length;\n" 321*cdf0e10cSrcweir " for (int i=0; i < len; ++i) {\n" 322*cdf0e10cSrcweir " sDisplayName = com.sun.star.uno.AnyConverter.toString(\n" 323*cdf0e10cSrcweir " getAddinProperty(functions[i], \"\", sDISPLAYNAME));\n" 324*cdf0e10cSrcweir " if (sDisplayName.equals(aDisplayName))\n" 325*cdf0e10cSrcweir " return functions[i];\n }\n" 326*cdf0e10cSrcweir " }\n catch ( com.sun.star.uno.RuntimeException e ) {\n" 327*cdf0e10cSrcweir " throw e;\n }\n" 328*cdf0e10cSrcweir " catch ( com.sun.star.uno.Exception e ) {\n }\n\n" 329*cdf0e10cSrcweir " return \"\";\n }\n\n"; 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir // getDisplayFunctionName 332*cdf0e10cSrcweir o << " public String getDisplayFunctionName(String " 333*cdf0e10cSrcweir "aProgrammaticName)\n {\n" 334*cdf0e10cSrcweir " return getAddinProperty(aProgrammaticName, \"\", sDISPLAYNAME);\n" 335*cdf0e10cSrcweir " }\n\n"; 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir // getFunctionDescription 338*cdf0e10cSrcweir o << " public String getFunctionDescription(String " 339*cdf0e10cSrcweir "aProgrammaticName)\n {\n" 340*cdf0e10cSrcweir " return getAddinProperty(aProgrammaticName, \"\", sDESCRIPTION);\n" 341*cdf0e10cSrcweir " }\n\n"; 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir // getDisplayArgumentName 344*cdf0e10cSrcweir o << " public String getDisplayArgumentName(String " 345*cdf0e10cSrcweir "aProgrammaticFunctionName, int nArgument)\n {\n"; 346*cdf0e10cSrcweir if (options.java5) { 347*cdf0e10cSrcweir o << " return getAddinProperty(aProgrammaticFunctionName,\n" 348*cdf0e10cSrcweir " m_functionMap.get(\n" 349*cdf0e10cSrcweir " aProgrammaticFunctionName).get(" 350*cdf0e10cSrcweir "nArgument),\n" 351*cdf0e10cSrcweir " sDISPLAYNAME);\n }\n\n"; 352*cdf0e10cSrcweir } else { 353*cdf0e10cSrcweir o << " return getAddinProperty(aProgrammaticFunctionName, (String)\n" 354*cdf0e10cSrcweir " ((java.util.Hashtable)m_functionMap." 355*cdf0e10cSrcweir "get(\n aProgrammaticFunctionName))." 356*cdf0e10cSrcweir "get(\n new Integer(nArgument))" 357*cdf0e10cSrcweir ", sDISPLAYNAME);\n }\n\n"; 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir // getArgumentDescription 361*cdf0e10cSrcweir o << " public String getArgumentDescription(String " 362*cdf0e10cSrcweir "aProgrammaticFunctionName, int nArgument)\n {\n"; 363*cdf0e10cSrcweir if (options.java5) { 364*cdf0e10cSrcweir o << " return getAddinProperty(aProgrammaticFunctionName,\n" 365*cdf0e10cSrcweir " m_functionMap.get(\n" 366*cdf0e10cSrcweir " aProgrammaticFunctionName).get(" 367*cdf0e10cSrcweir "nArgument),\n" 368*cdf0e10cSrcweir " sDESCRIPTION);\n }\n\n"; 369*cdf0e10cSrcweir } else { 370*cdf0e10cSrcweir o << " return getAddinProperty(aProgrammaticFunctionName, (String)\n" 371*cdf0e10cSrcweir " ((java.util.Hashtable)m_functionMap." 372*cdf0e10cSrcweir "get(\n aProgrammaticFunctionName))." 373*cdf0e10cSrcweir "get(\n new Integer(nArgument))" 374*cdf0e10cSrcweir ", sDESCRIPTION);\n }\n\n"; 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir // getProgrammaticCategoryName 377*cdf0e10cSrcweir o << " public String getProgrammaticCategoryName(String " 378*cdf0e10cSrcweir "aProgrammaticFunctionName)\n {\n" 379*cdf0e10cSrcweir " return getAddinProperty(aProgrammaticFunctionName, \"\", " 380*cdf0e10cSrcweir "sCATEGORY);\n }\n\n"; 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir // getDisplayCategoryName 383*cdf0e10cSrcweir o << " public String getDisplayCategoryName(String " 384*cdf0e10cSrcweir "aProgrammaticFunctionName)\n {\n" 385*cdf0e10cSrcweir " return getAddinProperty(aProgrammaticFunctionName, \"\", " 386*cdf0e10cSrcweir "sCATEGORYDISPLAYNAME);\n }\n\n"; 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir void generateXCompatibilityNamesBodies(std::ostream& o) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir o << " // com.sun.star.sheet.XCompatibilityNames:\n" 392*cdf0e10cSrcweir " public com.sun.star.sheet.LocalizedName[] getCompatibilityNames(" 393*cdf0e10cSrcweir "String aProgrammaticName)\n {\n" 394*cdf0e10cSrcweir " com.sun.star.sheet.LocalizedName[] seqLocalizedNames =\n" 395*cdf0e10cSrcweir " new com.sun.star.sheet.LocalizedName[0];\n\n try {\n"; 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir o << " StringBuffer path = new StringBuffer(aProgrammaticName);\n" 398*cdf0e10cSrcweir " path.append(\"/CompatibilityName\");\n" 399*cdf0e10cSrcweir " String hname = path.toString();\n\n"; 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir o << " if ( m_xCompAccess.hasByHierarchicalName(hname) ) {\n" 402*cdf0e10cSrcweir " com.sun.star.container.XNameAccess xNameAccess =\n" 403*cdf0e10cSrcweir " (com.sun.star.container.XNameAccess)UnoRuntime." 404*cdf0e10cSrcweir "queryInterface(\n" 405*cdf0e10cSrcweir " com.sun.star.container.XNameAccess.class,\n" 406*cdf0e10cSrcweir " m_xCompAccess.getByHierarchicalName(hname));\n\n" 407*cdf0e10cSrcweir " String elems[] = xNameAccess.getElementNames();\n" 408*cdf0e10cSrcweir " int len = elems.length;\n" 409*cdf0e10cSrcweir " seqLocalizedNames = new com.sun.star.sheet.LocalizedName" 410*cdf0e10cSrcweir "[len];\n String sCompatibilityName = \"\";\n\n"; 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir o << " for (int i=0; i < len; ++i) {\n" 413*cdf0e10cSrcweir " String sLocale = elems[i];\n" 414*cdf0e10cSrcweir " sCompatibilityName = com.sun.star.uno.AnyConverter." 415*cdf0e10cSrcweir "toString(\n xNameAccess.getByName(sLocale));\n\n" 416*cdf0e10cSrcweir " com.sun.star.lang.Locale aLocale = \n" 417*cdf0e10cSrcweir " new com.sun.star.lang.Locale();\n\n" 418*cdf0e10cSrcweir " String tokens[] = sLocale.split(\"-\");\n" 419*cdf0e10cSrcweir " int nToken = tokens.length;\n" 420*cdf0e10cSrcweir " if (nToken >= 1) aLocale.Language = tokens[0];\n" 421*cdf0e10cSrcweir " if (nToken >= 2) aLocale.Country = tokens[1];\n" 422*cdf0e10cSrcweir " if (nToken >= 3) {\n" 423*cdf0e10cSrcweir " StringBuffer buf = \n" 424*cdf0e10cSrcweir " new StringBuffer(tokens[2]);\n" 425*cdf0e10cSrcweir " for (int t=3; t < nToken; ++t)\n" 426*cdf0e10cSrcweir " buf.append(tokens[t]);\n\n" 427*cdf0e10cSrcweir " aLocale.Variant = buf.toString();\n" 428*cdf0e10cSrcweir " }\n\n" 429*cdf0e10cSrcweir " seqLocalizedNames[i].Locale = aLocale;\n" 430*cdf0e10cSrcweir " seqLocalizedNames[i].Name = sCompatibilityName;\n" 431*cdf0e10cSrcweir " }\n }\n }\n" 432*cdf0e10cSrcweir " catch ( com.sun.star.uno.RuntimeException e ) {\n" 433*cdf0e10cSrcweir " throw e;\n }\n" 434*cdf0e10cSrcweir " catch ( com.sun.star.uno.Exception e ) {\n }\n\n" 435*cdf0e10cSrcweir " return seqLocalizedNames;\n }\n\n"; 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir void generateXInitializationBodies(std::ostream& o) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir o << " // com.sun.star.lang.XInitialization:\n" 441*cdf0e10cSrcweir " public void initialize( Object[] object )\n" 442*cdf0e10cSrcweir " throws com.sun.star.uno.Exception\n {\n" 443*cdf0e10cSrcweir " if ( object.length > 0 )\n {\n" 444*cdf0e10cSrcweir " m_xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(\n" 445*cdf0e10cSrcweir " com.sun.star.frame.XFrame.class, object[0]);\n }\n }\n\n"; 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir void generateXDispatchBodies(std::ostream& o, ProgramOptions const & options) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir // com.sun.star.frame.XDispatch 451*cdf0e10cSrcweir // dispatch 452*cdf0e10cSrcweir o << " // com.sun.star.frame.XDispatch:\n" 453*cdf0e10cSrcweir " public void dispatch( com.sun.star.util.URL aURL,\n" 454*cdf0e10cSrcweir " com.sun.star.beans.PropertyValue[] aArguments )\n {\n"; 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir ProtocolCmdMap::const_iterator iter = options.protocolCmdMap.begin(); 457*cdf0e10cSrcweir while (iter != options.protocolCmdMap.end()) { 458*cdf0e10cSrcweir o << " if ( aURL.Protocol.compareTo(\"" << (*iter).first 459*cdf0e10cSrcweir << "\") == 0 )\n {\n"; 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir for (std::vector< OString >::const_iterator i = (*iter).second.begin(); 462*cdf0e10cSrcweir i != (*iter).second.end(); ++i) { 463*cdf0e10cSrcweir o << " if ( aURL.Path.compareTo(\"" << (*i) << "\") == 0 )\n" 464*cdf0e10cSrcweir " {\n // add your own code here\n" 465*cdf0e10cSrcweir " return;\n }\n"; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir o << " }\n"; 469*cdf0e10cSrcweir iter++; 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir o << " }\n\n"; 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir // addStatusListener 474*cdf0e10cSrcweir o << " public void addStatusListener( com.sun.star.frame.XStatusListener xControl,\n" 475*cdf0e10cSrcweir " com.sun.star.util.URL aURL )\n {\n" 476*cdf0e10cSrcweir " // add your own code here\n }\n\n"; 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir // com.sun.star.frame.XDispatch 479*cdf0e10cSrcweir o << " public void removeStatusListener( com.sun.star.frame.XStatusListener xControl,\n" 480*cdf0e10cSrcweir " com.sun.star.util.URL aURL )\n {\n" 481*cdf0e10cSrcweir " // add your own code here\n }\n\n"; 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir void generateXDispatchProviderBodies(std::ostream& o, ProgramOptions const & options) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir // com.sun.star.frame.XDispatchProvider 487*cdf0e10cSrcweir // queryDispatch 488*cdf0e10cSrcweir o << " // com.sun.star.frame.XDispatchProvider:\n" 489*cdf0e10cSrcweir " public com.sun.star.frame.XDispatch queryDispatch( com.sun.star.util.URL aURL,\n" 490*cdf0e10cSrcweir " String sTargetFrameName,\n" 491*cdf0e10cSrcweir " int iSearchFlags )\n {\n"; 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir ProtocolCmdMap::const_iterator iter = options.protocolCmdMap.begin(); 494*cdf0e10cSrcweir while (iter != options.protocolCmdMap.end()) { 495*cdf0e10cSrcweir o << " if ( aURL.Protocol.compareTo(\"" << (*iter).first 496*cdf0e10cSrcweir << "\") == 0 )\n {\n"; 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir for (std::vector< OString >::const_iterator i = (*iter).second.begin(); 499*cdf0e10cSrcweir i != (*iter).second.end(); ++i) { 500*cdf0e10cSrcweir o << " if ( aURL.Path.compareTo(\"" << (*i) << "\") == 0 )\n" 501*cdf0e10cSrcweir " return this;\n"; 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir o << " }\n"; 505*cdf0e10cSrcweir iter++; 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir o << " return null;\n }\n\n"; 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir // queryDispatches 510*cdf0e10cSrcweir o << " // com.sun.star.frame.XDispatchProvider:\n" 511*cdf0e10cSrcweir " public com.sun.star.frame.XDispatch[] queryDispatches(\n" 512*cdf0e10cSrcweir " com.sun.star.frame.DispatchDescriptor[] seqDescriptors )\n {\n" 513*cdf0e10cSrcweir " int nCount = seqDescriptors.length;\n" 514*cdf0e10cSrcweir " com.sun.star.frame.XDispatch[] seqDispatcher =\n" 515*cdf0e10cSrcweir " new com.sun.star.frame.XDispatch[seqDescriptors.length];\n\n" 516*cdf0e10cSrcweir " for( int i=0; i < nCount; ++i )\n {\n" 517*cdf0e10cSrcweir " seqDispatcher[i] = queryDispatch(seqDescriptors[i].FeatureURL,\n" 518*cdf0e10cSrcweir " seqDescriptors[i].FrameName,\n" 519*cdf0e10cSrcweir " seqDescriptors[i].SearchFlags );\n" 520*cdf0e10cSrcweir " }\n return seqDispatcher;\n }\n\n"; 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir void generateMethodBodies(std::ostream& o, 524*cdf0e10cSrcweir ProgramOptions const & options, 525*cdf0e10cSrcweir TypeManager const & manager, 526*cdf0e10cSrcweir const std::hash_set< OString, OStringHash >& interfaces, 527*cdf0e10cSrcweir const OString& indentation, bool usepropertymixin) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir std::hash_set< OString, OStringHash >::const_iterator iter = 530*cdf0e10cSrcweir interfaces.begin(); 531*cdf0e10cSrcweir codemaker::GeneratedTypeSet generated; 532*cdf0e10cSrcweir while (iter != interfaces.end()) { 533*cdf0e10cSrcweir OString type(*iter); 534*cdf0e10cSrcweir iter++; 535*cdf0e10cSrcweir if (type.equals("com.sun.star.lang.XServiceInfo")) { 536*cdf0e10cSrcweir generateXServiceInfoBodies(o); 537*cdf0e10cSrcweir generated.add(type); 538*cdf0e10cSrcweir } else { 539*cdf0e10cSrcweir if (options.componenttype == 2) { 540*cdf0e10cSrcweir if (type.equals("com.sun.star.lang.XServiceName")) { 541*cdf0e10cSrcweir o << " // com.sun.star.lang.XServiceName:\n" 542*cdf0e10cSrcweir " public String getServiceName() {\n" 543*cdf0e10cSrcweir " return sADDIN_SERVICENAME;\n }\n"; 544*cdf0e10cSrcweir generated.add(type); 545*cdf0e10cSrcweir continue; 546*cdf0e10cSrcweir } else if (type.equals("com.sun.star.sheet.XAddIn")) { 547*cdf0e10cSrcweir generateXAddInBodies(o, options); 548*cdf0e10cSrcweir generated.add(type); 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir // special handling of XLocalizable -> parent of XAddIn 551*cdf0e10cSrcweir if (!generated.contains("com.sun.star.lang.XLocalizable")) { 552*cdf0e10cSrcweir generateXLocalizableBodies(o); 553*cdf0e10cSrcweir generated.add("com.sun.star.lang.XLocalizable"); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir continue; 556*cdf0e10cSrcweir } else if (type.equals("com.sun.star.lang.XLocalizable")) { 557*cdf0e10cSrcweir generateXLocalizableBodies(o); 558*cdf0e10cSrcweir generated.add(type); 559*cdf0e10cSrcweir continue; 560*cdf0e10cSrcweir } else if (type.equals("com.sun.star.sheet.XCompatibilityNames")) { 561*cdf0e10cSrcweir generateXCompatibilityNamesBodies(o); 562*cdf0e10cSrcweir generated.add(type); 563*cdf0e10cSrcweir continue; 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir if (options.componenttype == 3) { 567*cdf0e10cSrcweir if (type.equals("com.sun.star.lang.XInitialization")) { 568*cdf0e10cSrcweir generateXInitializationBodies(o); 569*cdf0e10cSrcweir generated.add(type); 570*cdf0e10cSrcweir continue; 571*cdf0e10cSrcweir } else if (type.equals("com.sun.star.frame.XDispatch")) { 572*cdf0e10cSrcweir generateXDispatchBodies(o, options); 573*cdf0e10cSrcweir generated.add(type); 574*cdf0e10cSrcweir continue; 575*cdf0e10cSrcweir } else if (type.equals("com.sun.star.frame.XDispatchProvider")) { 576*cdf0e10cSrcweir generateXDispatchProviderBodies(o, options); 577*cdf0e10cSrcweir generated.add(type); 578*cdf0e10cSrcweir continue; 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir typereg::Reader reader(manager.getTypeReader(type.replace('.','/'))); 582*cdf0e10cSrcweir printMethods(o, options, manager, reader, generated, "_", 583*cdf0e10cSrcweir indentation, true, usepropertymixin); 584*cdf0e10cSrcweir } 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir static const char* propcomment= 589*cdf0e10cSrcweir " // use the last parameter of the PropertySetMixin constructor\n" 590*cdf0e10cSrcweir " // for your optional attributes if necessary. See the documentation\n" 591*cdf0e10cSrcweir " // of the PropertySetMixin helper for further information.\n" 592*cdf0e10cSrcweir " // Ensure that your attributes are initialized correctly!\n"; 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir void generateAddinConstructorAndHelper(std::ostream& o, 596*cdf0e10cSrcweir ProgramOptions const & options, 597*cdf0e10cSrcweir TypeManager const & manager, const OString & classname, 598*cdf0e10cSrcweir const std::hash_set< OString, OStringHash >& services, 599*cdf0e10cSrcweir const std::hash_set< OString, OStringHash >& interfaces) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir o << " private com.sun.star.lang.Locale m_locale = " 602*cdf0e10cSrcweir "new com.sun.star.lang.Locale();\n"; 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir if (!options.backwardcompatible) { 605*cdf0e10cSrcweir // Constructor 606*cdf0e10cSrcweir o << "\n public " << classname << "( XComponentContext context )\n" 607*cdf0e10cSrcweir " {\n m_xContext = context;\n }\n\n"; 608*cdf0e10cSrcweir return; 609*cdf0e10cSrcweir } 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir // get the one and only add-in service for later use 613*cdf0e10cSrcweir std::hash_set< OString, OStringHash >::const_iterator iter = services.begin(); 614*cdf0e10cSrcweir OString sAddinService = (*iter).replace('/', '.'); 615*cdf0e10cSrcweir if (sAddinService.equals("com.sun.star.sheet.AddIn")) { 616*cdf0e10cSrcweir sAddinService = (*(++iter)).replace('/', '.'); 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir // add-in specific fields 621*cdf0e10cSrcweir o << "\n private static final String sADDIN_SERVICENAME = \"" 622*cdf0e10cSrcweir << sAddinService << "\";\n\n"; 623*cdf0e10cSrcweir o << " private static final String sDISPLAYNAME = " 624*cdf0e10cSrcweir "\"DisplayName\";\n" 625*cdf0e10cSrcweir " private static final String sDESCRIPTION = " 626*cdf0e10cSrcweir "\"Description\";\n" 627*cdf0e10cSrcweir " private static final String sCATEGORY = \"Category\";\n" 628*cdf0e10cSrcweir " private static final String sCATEGORYDISPLAYNAME = " 629*cdf0e10cSrcweir "\"CategoryDisplayName\";\n\n"; 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir o << " private com.sun.star.container.XHierarchicalNameAccess " 632*cdf0e10cSrcweir "m_xHAccess = null;\n" 633*cdf0e10cSrcweir " private com.sun.star.container.XHierarchicalNameAccess " 634*cdf0e10cSrcweir "m_xCompAccess = null;\n"; 635*cdf0e10cSrcweir if (options.java5) { 636*cdf0e10cSrcweir o << " private java.util.Hashtable<\n String, " 637*cdf0e10cSrcweir "java.util.Hashtable< Integer, String> > m_functionMap = null;\n\n"; 638*cdf0e10cSrcweir } else { 639*cdf0e10cSrcweir o << " private java.util.Hashtable m_functionMap = null;\n\n"; 640*cdf0e10cSrcweir } 641*cdf0e10cSrcweir // Constructor 642*cdf0e10cSrcweir o << "\n public " << classname << "( XComponentContext context )\n {\n" 643*cdf0e10cSrcweir " m_xContext = context;\n\n" 644*cdf0e10cSrcweir " try {\n"; 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir if (options.java5) { 647*cdf0e10cSrcweir o << " m_functionMap = new java.util.Hashtable<\n" 648*cdf0e10cSrcweir " String, java.util.Hashtable< Integer, " 649*cdf0e10cSrcweir "String > >();\n\n"; 650*cdf0e10cSrcweir } else { 651*cdf0e10cSrcweir o << " m_functionMap = new java.util.Hashtable();\n\n"; 652*cdf0e10cSrcweir } 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir generateFunctionParameterMap(o, options, manager, interfaces); 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir o << " com.sun.star.lang.XMultiServiceFactory xProvider = \n" 657*cdf0e10cSrcweir " (com.sun.star.lang.XMultiServiceFactory)UnoRuntime." 658*cdf0e10cSrcweir "queryInterface(\n" 659*cdf0e10cSrcweir " com.sun.star.lang.XMultiServiceFactory.class,\n" 660*cdf0e10cSrcweir " m_xContext.getServiceManager().createInstanceWithContext(" 661*cdf0e10cSrcweir "\n \"com.sun.star.configuration.ConfigurationProvider\"" 662*cdf0e10cSrcweir ",\n m_xContext));\n\n"; 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir o << " String sReadOnlyView = " 665*cdf0e10cSrcweir "\"com.sun.star.configuration.ConfigurationAccess\";\n\n"; 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir o << " StringBuffer sPath = new StringBuffer(\n" 668*cdf0e10cSrcweir " \"/org.openoffice.Office.CalcAddIns/AddInInfo/\");\n" 669*cdf0e10cSrcweir " sPath.append(sADDIN_SERVICENAME);\n" 670*cdf0e10cSrcweir " sPath.append(\"/AddInFunctions\");\n\n"; 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir o << " // create arguments: nodepath\n" 673*cdf0e10cSrcweir " com.sun.star.beans.PropertyValue aArgument = \n" 674*cdf0e10cSrcweir " new com.sun.star.beans.PropertyValue();\n" 675*cdf0e10cSrcweir " aArgument.Name = \"nodepath\";\n" 676*cdf0e10cSrcweir " aArgument.Value = new com.sun.star.uno.Any(\n" 677*cdf0e10cSrcweir " com.sun.star.uno.Type.STRING, sPath.toString());\n\n"; 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir o << " Object aArguments[] = new Object[1];\n" 680*cdf0e10cSrcweir " aArguments[0] = new com.sun.star.uno.Any(" 681*cdf0e10cSrcweir " new com.sun.star.uno.Type(\n" 682*cdf0e10cSrcweir " com.sun.star.beans.PropertyValue.class), aArgument);\n\n"; 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir o << " // create the default view using default UI locale\n" 685*cdf0e10cSrcweir " Object xIface = \n" 686*cdf0e10cSrcweir " xProvider.createInstanceWithArguments(sReadOnlyView, " 687*cdf0e10cSrcweir "aArguments);\n\n"; 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir o << " m_xHAccess = (com.sun.star.container.XHierarchicalNameAccess)\n" 690*cdf0e10cSrcweir " UnoRuntime.queryInterface(\n" 691*cdf0e10cSrcweir " com.sun.star.container.XHierarchicalNameAccess.class, " 692*cdf0e10cSrcweir "xIface);\n\n"; 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir o << " // extends arguments to create a view for all locales to get " 695*cdf0e10cSrcweir "simple\n // access to the compatibilityname property\n" 696*cdf0e10cSrcweir " aArguments = new Object[2];\n" 697*cdf0e10cSrcweir " aArguments[0] = new com.sun.star.uno.Any( " 698*cdf0e10cSrcweir "new com.sun.star.uno.Type(\n" 699*cdf0e10cSrcweir " com.sun.star.beans.PropertyValue.class), aArgument);\n" 700*cdf0e10cSrcweir " aArgument.Name = \"locale\";\n" 701*cdf0e10cSrcweir " aArgument.Value = new com.sun.star.uno.Any(\n" 702*cdf0e10cSrcweir " com.sun.star.uno.Type.STRING, \"*\");\n" 703*cdf0e10cSrcweir " aArguments[1] = new com.sun.star.uno.Any( " 704*cdf0e10cSrcweir " new com.sun.star.uno.Type(\n" 705*cdf0e10cSrcweir " com.sun.star.beans.PropertyValue.class), aArgument);\n\n"; 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir o << " // create view for all locales\n" 708*cdf0e10cSrcweir " xIface = xProvider.createInstanceWithArguments(sReadOnlyView, " 709*cdf0e10cSrcweir "aArguments);\n\n" 710*cdf0e10cSrcweir " m_xCompAccess = (com.sun.star.container.XHierarchicalNameAccess)\n" 711*cdf0e10cSrcweir " UnoRuntime.queryInterface(\n" 712*cdf0e10cSrcweir " com.sun.star.container.XHierarchicalNameAccess.class, " 713*cdf0e10cSrcweir "xIface);\n }\n" 714*cdf0e10cSrcweir " catch ( com.sun.star.uno.Exception e ) {\n }\n }\n\n"; 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir // add-in helper function 717*cdf0e10cSrcweir o << " // addin configuration property helper function:\n" 718*cdf0e10cSrcweir " String getAddinProperty(String funcName, " 719*cdf0e10cSrcweir "String paramName, String propName)\n {\n" 720*cdf0e10cSrcweir " try {\n StringBuffer buf = " 721*cdf0e10cSrcweir "new StringBuffer(funcName);\n\n" 722*cdf0e10cSrcweir " if (paramName.length() > 0) {\n" 723*cdf0e10cSrcweir " buf.append(\"/Parameters/\");\n" 724*cdf0e10cSrcweir " buf.append(paramName);\n }\n\n"; 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir o << " com.sun.star.beans.XPropertySet xPropSet =\n" 727*cdf0e10cSrcweir " (com.sun.star.beans.XPropertySet)UnoRuntime." 728*cdf0e10cSrcweir "queryInterface(\n" 729*cdf0e10cSrcweir " com.sun.star.beans.XPropertySet.class,\n" 730*cdf0e10cSrcweir " m_xHAccess.getByHierarchicalName(buf.toString()));\n\n" 731*cdf0e10cSrcweir " return com.sun.star.uno.AnyConverter.toString(\n" 732*cdf0e10cSrcweir " xPropSet.getPropertyValue(propName));\n }\n" 733*cdf0e10cSrcweir " catch ( com.sun.star.uno.RuntimeException e ) {\n" 734*cdf0e10cSrcweir " throw e;\n }\n" 735*cdf0e10cSrcweir " catch ( com.sun.star.uno.Exception e ) {\n }\n" 736*cdf0e10cSrcweir " return \"\";\n }\n\n"; 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir 740*cdf0e10cSrcweir void generateClassDefinition(std::ostream& o, 741*cdf0e10cSrcweir ProgramOptions const & options, 742*cdf0e10cSrcweir TypeManager const & manager, 743*cdf0e10cSrcweir const OString & classname, 744*cdf0e10cSrcweir const std::hash_set< OString, OStringHash >& services, 745*cdf0e10cSrcweir const std::hash_set< OString, OStringHash >& interfaces, 746*cdf0e10cSrcweir const AttributeInfo& properties, 747*cdf0e10cSrcweir const AttributeInfo& attributes, 748*cdf0e10cSrcweir const OString& propertyhelper, bool supportxcomponent) 749*cdf0e10cSrcweir { 750*cdf0e10cSrcweir o << "\n\npublic final class " << classname << " extends "; 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir if (!interfaces.empty()) { 753*cdf0e10cSrcweir if (propertyhelper.equals("_")) { 754*cdf0e10cSrcweir o << "PropertySet\n"; 755*cdf0e10cSrcweir } else { 756*cdf0e10cSrcweir if (supportxcomponent) 757*cdf0e10cSrcweir o << "ComponentBase\n"; 758*cdf0e10cSrcweir else 759*cdf0e10cSrcweir o << "WeakBase\n"; 760*cdf0e10cSrcweir } 761*cdf0e10cSrcweir o << " implements "; 762*cdf0e10cSrcweir std::hash_set< OString, OStringHash >::const_iterator iter = 763*cdf0e10cSrcweir interfaces.begin(); 764*cdf0e10cSrcweir while (iter != interfaces.end()) { 765*cdf0e10cSrcweir o << (*iter); 766*cdf0e10cSrcweir iter++; 767*cdf0e10cSrcweir if (iter != interfaces.end()) 768*cdf0e10cSrcweir o << ",\n "; 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir } 771*cdf0e10cSrcweir o << "\n{\n"; 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir o << " private final XComponentContext m_xContext;\n"; 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir // additional member for add-ons 776*cdf0e10cSrcweir if (options.componenttype == 3) { 777*cdf0e10cSrcweir o << " private com.sun.star.frame.XFrame m_xFrame;\n"; 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir // check property helper 781*cdf0e10cSrcweir if (propertyhelper.getLength() > 1) 782*cdf0e10cSrcweir o << " private final PropertySetMixin m_prophlp;\n"; 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir o << " private static final String m_implementationName = " 785*cdf0e10cSrcweir << classname << ".class.getName();\n"; 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir if (!services.empty()) { 788*cdf0e10cSrcweir o << " private static final String[] m_serviceNames = {\n"; 789*cdf0e10cSrcweir std::hash_set< OString, OStringHash >::const_iterator iter = 790*cdf0e10cSrcweir services.begin(); 791*cdf0e10cSrcweir while (iter != services.end()) { 792*cdf0e10cSrcweir o << " \"" << (*iter).replace('/','.') << "\""; 793*cdf0e10cSrcweir iter++; 794*cdf0e10cSrcweir if (iter != services.end()) 795*cdf0e10cSrcweir o << ",\n"; 796*cdf0e10cSrcweir else 797*cdf0e10cSrcweir o << " };\n\n"; 798*cdf0e10cSrcweir } 799*cdf0e10cSrcweir } 800*cdf0e10cSrcweir 801*cdf0e10cSrcweir // attribute/property members 802*cdf0e10cSrcweir if (!properties.empty()) { 803*cdf0e10cSrcweir AttributeInfo::const_iterator iter = 804*cdf0e10cSrcweir properties.begin(); 805*cdf0e10cSrcweir o << " // properties\n"; 806*cdf0e10cSrcweir while (iter != properties.end()) { 807*cdf0e10cSrcweir o << " protected "; 808*cdf0e10cSrcweir printType(o, options, manager, iter->second.first.replace('.','/'), 809*cdf0e10cSrcweir false, false); 810*cdf0e10cSrcweir o << " m_" << iter->first << ";\n"; 811*cdf0e10cSrcweir iter++; 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir } else if (!attributes.empty()) { 814*cdf0e10cSrcweir AttributeInfo::const_iterator iter = 815*cdf0e10cSrcweir attributes.begin(); 816*cdf0e10cSrcweir o << " // attributes\n"; 817*cdf0e10cSrcweir while (iter != attributes.end()) { 818*cdf0e10cSrcweir o << " private "; 819*cdf0e10cSrcweir printType(o, options, manager, iter->second.first.replace('.','/'), 820*cdf0e10cSrcweir false, false); 821*cdf0e10cSrcweir o << " m_" << iter->first << " = "; 822*cdf0e10cSrcweir printType(o, options, manager, iter->second.first.replace('.','/'), 823*cdf0e10cSrcweir false, true); 824*cdf0e10cSrcweir o <<";\n"; 825*cdf0e10cSrcweir iter++; 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir // special handling of calc add-ins 830*cdf0e10cSrcweir if (options.componenttype == 2) 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir generateAddinConstructorAndHelper(o, options, manager, classname, 833*cdf0e10cSrcweir services, interfaces); 834*cdf0e10cSrcweir } else { 835*cdf0e10cSrcweir o << "\n public " << classname << "( XComponentContext context )\n" 836*cdf0e10cSrcweir " {\n m_xContext = context;\n"; 837*cdf0e10cSrcweir if (propertyhelper.equals("_")) { 838*cdf0e10cSrcweir registerProperties(o, manager, properties, " "); 839*cdf0e10cSrcweir } else { 840*cdf0e10cSrcweir if (propertyhelper.getLength() > 1) { 841*cdf0e10cSrcweir o << propcomment 842*cdf0e10cSrcweir << " m_prophlp = new PropertySetMixin(m_xContext, this,\n" 843*cdf0e10cSrcweir << " new Type(" << propertyhelper 844*cdf0e10cSrcweir << ".class), null);\n"; 845*cdf0e10cSrcweir } 846*cdf0e10cSrcweir } 847*cdf0e10cSrcweir o << " };\n\n"; 848*cdf0e10cSrcweir 849*cdf0e10cSrcweir } 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir if (!services.empty()) 852*cdf0e10cSrcweir generateCompFunctions(o, classname); 853*cdf0e10cSrcweir 854*cdf0e10cSrcweir generateMethodBodies(o, options, manager, interfaces, 855*cdf0e10cSrcweir " ", propertyhelper.getLength() > 1); 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir // end of class definition 858*cdf0e10cSrcweir o << "}\n"; 859*cdf0e10cSrcweir } 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir void generateSkeleton(ProgramOptions const & options, 862*cdf0e10cSrcweir TypeManager const & manager, 863*cdf0e10cSrcweir std::vector< OString > const & types, 864*cdf0e10cSrcweir OString const & /*delegate*/) 865*cdf0e10cSrcweir { 866*cdf0e10cSrcweir std::hash_set< OString, OStringHash > interfaces; 867*cdf0e10cSrcweir std::hash_set< OString, OStringHash > services; 868*cdf0e10cSrcweir AttributeInfo properties; 869*cdf0e10cSrcweir AttributeInfo attributes; 870*cdf0e10cSrcweir std::hash_set< OString, OStringHash > propinterfaces; 871*cdf0e10cSrcweir bool serviceobject = false; 872*cdf0e10cSrcweir bool supportxcomponent = false; 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir std::vector< OString >::const_iterator iter = types.begin(); 875*cdf0e10cSrcweir while (iter != types.end()) { 876*cdf0e10cSrcweir checkType(manager, *iter, interfaces, services, properties); 877*cdf0e10cSrcweir iter++; 878*cdf0e10cSrcweir } 879*cdf0e10cSrcweir 880*cdf0e10cSrcweir if (options.componenttype == 3) { 881*cdf0e10cSrcweir // the Protocolhandler service is mandatory for an protocol handler add-on, 882*cdf0e10cSrcweir // so it is defaulted. The XDispatchProvider provides Dispatch objects for 883*cdf0e10cSrcweir // certain functions and the generated impl object implements XDispatch 884*cdf0e10cSrcweir // directly for simplicity reasons. 885*cdf0e10cSrcweir checkType(manager, "com.sun.star.frame.ProtocolHandler", 886*cdf0e10cSrcweir interfaces, services, properties); 887*cdf0e10cSrcweir checkType(manager, "com.sun.star.frame.XDispatch", 888*cdf0e10cSrcweir interfaces, services, properties); 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir 891*cdf0e10cSrcweir // ProtocolCmdMap::const_iterator iter2 = options.protocolCmdMap.begin(); 892*cdf0e10cSrcweir // while (iter2 != options.protocolCmdMap.end()) { 893*cdf0e10cSrcweir // fprintf(stdout, "prt=%s\n", (*iter2).first.getStr()); 894*cdf0e10cSrcweir 895*cdf0e10cSrcweir // for (std::vector< OString >::const_iterator i = (*iter2).second.begin(); 896*cdf0e10cSrcweir // i != (*iter2).second.end(); ++i) { 897*cdf0e10cSrcweir // fprintf(stdout, "cmd=%s\n", (*i).getStr()); 898*cdf0e10cSrcweir // } 899*cdf0e10cSrcweir // iter2++; 900*cdf0e10cSrcweir // } 901*cdf0e10cSrcweir // return; 902*cdf0e10cSrcweir } 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir if (options.componenttype == 2) { 905*cdf0e10cSrcweir if (services.size() != 1) { 906*cdf0e10cSrcweir throw CannotDumpException( 907*cdf0e10cSrcweir "for calc add-in components one and only one service type is " 908*cdf0e10cSrcweir "necessary! Please reference a valid type with the '-t' option."); 909*cdf0e10cSrcweir } 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir // if backwardcompatible==true the AddIn service needs to be added to the 912*cdf0e10cSrcweir // suported service list, the necessary intefaces are mapped to the add-in 913*cdf0e10cSrcweir // configuration. Since OO.org 2.0.4 this is obsolete and the add-in is 914*cdf0e10cSrcweir // take form the configuration from Calc directly, this simplifies the 915*cdf0e10cSrcweir // add-in code 916*cdf0e10cSrcweir if (options.backwardcompatible) { 917*cdf0e10cSrcweir checkType(manager, "com.sun.star.sheet.AddIn", 918*cdf0e10cSrcweir interfaces, services, properties); 919*cdf0e10cSrcweir } else { 920*cdf0e10cSrcweir // special case for the optional XLocalization interface. It should be 921*cdf0e10cSrcweir // implemented always. But it is parent of the XAddIn and we need it only 922*cdf0e10cSrcweir // if backwardcompatible is false. 923*cdf0e10cSrcweir if (interfaces.find("com.sun.star.lang.XLocalizable") == interfaces.end()) { 924*cdf0e10cSrcweir interfaces.insert("com.sun.star.lang.XLocalizable"); 925*cdf0e10cSrcweir } 926*cdf0e10cSrcweir } 927*cdf0e10cSrcweir } 928*cdf0e10cSrcweir 929*cdf0e10cSrcweir 930*cdf0e10cSrcweir // check if service object or simple UNO object 931*cdf0e10cSrcweir if (!services.empty()) 932*cdf0e10cSrcweir serviceobject = true; 933*cdf0e10cSrcweir 934*cdf0e10cSrcweir OString propertyhelper = checkPropertyHelper( 935*cdf0e10cSrcweir options, manager, services, interfaces, attributes, propinterfaces); 936*cdf0e10cSrcweir checkDefaultInterfaces(interfaces, services, propertyhelper); 937*cdf0e10cSrcweir 938*cdf0e10cSrcweir if (options.componenttype == 2) { 939*cdf0e10cSrcweir if (propertyhelper.getLength() > 0) 940*cdf0e10cSrcweir std::cerr << "WARNING: interfaces specifying calc add-in functions " 941*cdf0e10cSrcweir "shouldn't support attributes!\n"; 942*cdf0e10cSrcweir } 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir supportxcomponent = checkXComponentSupport(manager, interfaces); 945*cdf0e10cSrcweir 946*cdf0e10cSrcweir OString compFileName; 947*cdf0e10cSrcweir OString tmpFileName; 948*cdf0e10cSrcweir std::ostream* pofs = NULL; 949*cdf0e10cSrcweir bool standardout = getOutputStream(options, ".java", 950*cdf0e10cSrcweir &pofs, compFileName, tmpFileName); 951*cdf0e10cSrcweir 952*cdf0e10cSrcweir try { 953*cdf0e10cSrcweir if (!standardout && options.license) { 954*cdf0e10cSrcweir printLicenseHeader(*pofs, compFileName); 955*cdf0e10cSrcweir } 956*cdf0e10cSrcweir 957*cdf0e10cSrcweir generatePackage(*pofs, options.implname); 958*cdf0e10cSrcweir 959*cdf0e10cSrcweir generateImports(*pofs, options, interfaces, propertyhelper, 960*cdf0e10cSrcweir serviceobject, supportxcomponent); 961*cdf0e10cSrcweir 962*cdf0e10cSrcweir OString classname(options.implname); 963*cdf0e10cSrcweir sal_Int32 index = 0; 964*cdf0e10cSrcweir if ((index = classname.lastIndexOf('.')) > 0) 965*cdf0e10cSrcweir classname = classname.copy(index+1); 966*cdf0e10cSrcweir 967*cdf0e10cSrcweir generateClassDefinition(*pofs, options, manager, classname, services, 968*cdf0e10cSrcweir interfaces, properties, attributes, propertyhelper, 969*cdf0e10cSrcweir supportxcomponent); 970*cdf0e10cSrcweir 971*cdf0e10cSrcweir if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) { 972*cdf0e10cSrcweir ((std::ofstream*)pofs)->close(); 973*cdf0e10cSrcweir delete pofs; 974*cdf0e10cSrcweir OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, sal_False)); 975*cdf0e10cSrcweir } 976*cdf0e10cSrcweir } catch(CannotDumpException& e) { 977*cdf0e10cSrcweir 978*cdf0e10cSrcweir std::cerr << "ERROR: " << e.m_message.getStr() << "\n"; 979*cdf0e10cSrcweir if ( !standardout ) { 980*cdf0e10cSrcweir if (pofs && ((std::ofstream*)pofs)->is_open()) { 981*cdf0e10cSrcweir ((std::ofstream*)pofs)->close(); 982*cdf0e10cSrcweir delete pofs; 983*cdf0e10cSrcweir } 984*cdf0e10cSrcweir // remove existing type file if something goes wrong to ensure 985*cdf0e10cSrcweir // consistency 986*cdf0e10cSrcweir if (fileExists(compFileName)) 987*cdf0e10cSrcweir removeTypeFile(compFileName); 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir // remove tmp file if something goes wrong 990*cdf0e10cSrcweir removeTypeFile(tmpFileName); 991*cdf0e10cSrcweir } 992*cdf0e10cSrcweir } 993*cdf0e10cSrcweir } 994*cdf0e10cSrcweir 995*cdf0e10cSrcweir } } 996*cdf0e10cSrcweir 997*cdf0e10cSrcweir 998