LCOV - code coverage report
Current view: top level - unodevtools/source/skeletonmaker - javacompskeleton.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 365 0.0 %
Date: 2014-11-03 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10