LCOV - code coverage report
Current view: top level - unodevtools/source/skeletonmaker - javacompskeleton.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 385 0.0 %
Date: 2012-08-25 Functions: 0 21 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10