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