diff options
author | Juergen Schmidt <jsc@openoffice.org> | 2005-08-23 07:31:46 +0000 |
---|---|---|
committer | Juergen Schmidt <jsc@openoffice.org> | 2005-08-23 07:31:46 +0000 |
commit | 28193b418733023379f94f165121fdf8434619b4 (patch) | |
tree | 8c584e9997f63b8468c6e67e0ba74e73d2b55aad | |
parent | 55cf507765caeaf5f122bcfae7c77b218c7122af (diff) |
#52208# new
18 files changed, 5035 insertions, 0 deletions
diff --git a/unodevtools/inc/unodevtools/options.hxx b/unodevtools/inc/unodevtools/options.hxx new file mode 100644 index 000000000000..b2e4061c91ee --- /dev/null +++ b/unodevtools/inc/unodevtools/options.hxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * $RCSfile: options.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:23:10 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UNODEVTOOLS_OPTIONS_HXX_ +#define _UNODEVTOOLS_OPTIONS_HXX_ + +#include <rtl/ustrbuf.hxx> + +namespace com { namespace sun { namespace star { namespace uno { +class RuntimeException; +} } } } + +namespace unodevtools { + +//------------------------------------------------------------------------------- +sal_Bool readOption( rtl::OUString * pValue, const sal_Char * pOpt, + sal_Int32 * pnIndex, const rtl::OUString & aArg) + throw (com::sun::star::uno::RuntimeException); + +//------------------------------------------------------------------------------- +sal_Bool readOption( sal_Bool * pbOpt, const sal_Char * pOpt, + sal_Int32 * pnIndex, const rtl::OUString & aArg); + +} // end of namespace unodevtools + +#endif // _UNODEVTOOLS_OPTIONS_HXX_ diff --git a/unodevtools/inc/unodevtools/typemanager.hxx b/unodevtools/inc/unodevtools/typemanager.hxx new file mode 100644 index 000000000000..a56be9f28d51 --- /dev/null +++ b/unodevtools/inc/unodevtools/typemanager.hxx @@ -0,0 +1,133 @@ +/************************************************************************* + * + * $RCSfile: typemanager.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:23:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UNODEVTOOLS_TYPEMANAGER_HXX_ +#define _UNODEVTOOLS_TYPEMANAGER_HXX_ + +#include <registry/registry.hxx> +#include <codemaker/typemanager.hxx> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> + +#include <hash_map> +#include <vector> + +namespace typereg { class Reader; } + +#if defined( _MSC_VER ) && ( _MSC_VER < 1200 ) +typedef ::std::__hash_map__ +< + ::rtl::OString, // Typename + RTTypeClass, // TypeClass + HashString, + EqualString, + NewAlloc +> T2TypeClassMap; +#else +typedef ::std::hash_map +< + ::rtl::OString, // Typename + RTTypeClass, // TypeClass + HashString, + EqualString +> T2TypeClassMap; +#endif + +namespace unodevtools { + +struct UnoTypeManagerImpl +{ + UnoTypeManagerImpl() {} + + T2TypeClassMap m_t2TypeClass; + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XHierarchicalNameAccess> m_tdmgr; +}; + +class UnoTypeManager : public TypeManager +{ +public: + UnoTypeManager(); + ~UnoTypeManager(); + + UnoTypeManager( const UnoTypeManager& value ) + : TypeManager(value) + , m_pImpl( value.m_pImpl ) + {} + + sal_Bool init(const ::std::vector< ::rtl::OUString > registries); + + sal_Bool isValidType(const ::rtl::OString& name) const; + ::rtl::OString getTypeName(RegistryKey& rTypeKey) const; + typereg::Reader getTypeReader( + const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const; + typereg::Reader getTypeReader(RegistryKey& rTypeKey) const; + RTTypeClass getTypeClass(const ::rtl::OString& name) const; + RTTypeClass getTypeClass(RegistryKey& rTypeKey) const; + +protected: + void release(); + + UnoTypeManagerImpl* m_pImpl; +}; + +} + +#endif // _UNODEVTOOLS_TYPEMANAGER_HXX_ diff --git a/unodevtools/prj/build.lst b/unodevtools/prj/build.lst new file mode 100644 index 000000000000..4f99f7683846 --- /dev/null +++ b/unodevtools/prj/build.lst @@ -0,0 +1,8 @@ +udt unodevtools : codemaker NULL +udt unodevtools usr1 - all udt_mkout NULL +udt unodevtools\inc get - all udt_inc NULL +udt unodevtools\prj get - all udt_prj NULL +udt unodevtools\source\unodevtools nmake - all udt_unodevtools NULL +udt unodevtools\source\skeletonmaker nmake - all udt_skeletonmaker udt_unodevtools NULL + + diff --git a/unodevtools/prj/d.lst b/unodevtools/prj/d.lst new file mode 100644 index 000000000000..0060b6b9cc15 --- /dev/null +++ b/unodevtools/prj/d.lst @@ -0,0 +1,5 @@ +..\%__SRC%\bin\uno-skeletonmaker.exe %_DEST%\bin%_EXT%\uno-skeletonmaker.exe +..\%__SRC%\bin\uno-skeletonmaker.pdb %_DEST%\bin%_EXT%\uno-skeletonmaker.pdb + +..\%__SRC%\bin\uno-skeletonmaker %_DEST%\bin%_EXT%\uno-skeletonmaker + diff --git a/unodevtools/source/skeletonmaker/cppcompskeleton.cxx b/unodevtools/source/skeletonmaker/cppcompskeleton.cxx new file mode 100644 index 000000000000..78a29ad4aa37 --- /dev/null +++ b/unodevtools/source/skeletonmaker/cppcompskeleton.cxx @@ -0,0 +1,409 @@ +/************************************************************************* + * + * $RCSfile: cppcompskeleton.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:29:47 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "skeletoncpp.hxx" + +using namespace ::codemaker::cpp; + +namespace skeletonmaker { namespace cpp { + +void generateIncludes(std::ostream & o, + const std::hash_set< rtl::OString, rtl::OStringHash >& interfaces, + const StringPairHashMap& properties, + bool attributes, bool propertyhelper, bool serviceobject, + bool supportxcomponent) +{ + if (serviceobject) { + o << "#include <cppuhelper/factory.hxx>\n" + << "#include <cppuhelper/implementationentry.hxx>\n"; + } + if (supportxcomponent) { + o << "#include <cppuhelper/compbase" << interfaces.size() << ".hxx>\n"; + o << "#include <cppuhelper/basemutex.hxx>\n"; + } else + o << "#include <cppuhelper/implbase" << interfaces.size() << ".hxx>\n"; + + + if (attributes && propertyhelper) + o << "#include <cppuhelper/propertysetmixin.hxx>\n"; + + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = interfaces.begin(); + while (iter != interfaces.end()) { + o << "#include <" + << ((*iter).replace('.', '/').getStr()) + << ".hpp>\n"; + iter++; + } +} + +short generateNamespace(std::ostream & o, const rtl::OString & implname) +{ + short count=0; + sal_Int32 index = implname.lastIndexOf('.'); + if (index == -1) { + o << "namespace {\n\n"; + count=1; + } else { + sal_Int32 nPos=0; + do + { + o << "namespace " << implname.getToken(0, '.', nPos) << " { "; + count++; + } while( nPos <= index ); + o << "\n\n"; + } + return count; +} + +void generateServiceHelper(std::ostream & o, + const rtl::OString & implname, + const std::hash_set< rtl::OString, rtl::OStringHash >& services) +{ + o << "rtl::OUString SAL_CALL _getImplementationName() {\n" + << " return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(\n" + << " \"" << implname << "\"));\n}\n\n"; + + o << "css::uno::Sequence< rtl::OUString > SAL_CALL _getSupportedServiceNames()\n{\n" + << " css::uno::Sequence< rtl::OUString > s(" << services.size() << ");\n"; + + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = services.begin(); + short i=0; + while (iter != services.end()) { + o << " s[" << i++ << "] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(\n" + << " \"" << (*iter).replace('/','.') << "\"));\n"; + iter++; + } + o << " return s;\n}\n\n"; +} + +void generateCreateFunction(std::ostream & o, const rtl::OString & classname) +{ + o << "css::uno::Reference< css::uno::XInterface > SAL_CALL _create(\n" + << " css::uno::Reference< css::uno::XComponentContext > const & context)\n" + << " SAL_THROW((css::uno::Exception))\n{\n" + << " return static_cast< cppu::OWeakObject * >(new " + << classname << "(context));\n}\n\n"; +} + +void generateCompFunctions(std::ostream & o, const rtl::OString & nmspace) +{ + o << "static struct cppu::ImplementationEntry entries[] = {\n" + << " { &" << nmspace << "_create, &" + << nmspace << "_getImplementationName,\n &" + << nmspace << "_getSupportedServiceNames,\n" + << " &cppu::createSingleComponentFactory, 0, 0 },\n" + << " { 0, 0, 0, 0, 0, 0 }\n};\n\n"; + + o << "extern \"C\" void SAL_CALL component_getImplementationEnvironment(\n" + << " char const ** envTypeName, uno_Environment **)\n{\n" + << " *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;\n}\n\n"; + + o << "extern \"C\" void * SAL_CALL component_getFactory(\n" + << " char const * implName, void * serviceManager, void * registryKey)\n{\n" + << " return cppu::component_getFactoryHelper(\n" + << " implName, serviceManager, registryKey, entries);\n}\n\n"; + + o << "extern \"C\" sal_Bool SAL_CALL component_writeInfo(\n" + << " void * serviceManager, void * registryKey)\n{\n" + << " return cppu::component_writeInfoHelper(" + << "serviceManager, registryKey, entries);\n}\n"; +} + +void generateClassDefinition(std::ostream& o, + ProgramOptions const & options, + TypeManager const & manager, + const rtl::OString & classname, + const std::hash_set< rtl::OString, rtl::OStringHash >& interfaces, + const StringPairHashMap& properties, + const rtl::OString& propertyhelper, bool supportxcomponent) +{ + o << "class " << classname << ":\n"; + if (propertyhelper.getLength() > 0) + o << " public cppuhelper::PropertySetMixin< " + << scopedCppName(propertyhelper, false, true) << " >,\n"; + + if (!interfaces.empty()) { + if (supportxcomponent) + o << " private cppu::BaseMutex,\n" + << " public cppu::WeakComponentImplHelper" + << interfaces.size() << "<"; + else + o << " public cppu::WeakImplHelper" << interfaces.size() << "<"; + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = + interfaces.begin(); + while (iter != interfaces.end()) { + o << "\n " << scopedCppName(*iter, false, true); + iter++; + if (iter != interfaces.end()) + o << ","; + else + o << ">\n"; + } + } + o << "{\npublic:\n" + << " explicit " << classname << "(" + << "css::uno::Reference< css::uno::XComponentContext > const & context);\n\n"; + + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = + interfaces.begin(); + codemaker::GeneratedTypeSet generated; + while (iter != interfaces.end()) { + typereg::Reader reader(manager.getTypeReader((*iter).replace('.','/'))); + printMethods(o, options, manager, reader, generated, "", "", " ", + true, true); + o << "\n"; + iter++; + } + + o << "private:\n " + << classname << "(" << classname << " &); // not defined\n" + << " void operator =(" << classname << " &); // not defined\n\n" + << " virtual ~" << classname << "() {}\n\n"; + + // members + o << " css::uno::Reference< css::uno::XComponentContext > m_xContext;\n"; + + if (!properties.empty()) { + StringPairHashMap::const_iterator iter = properties.begin(); + while (iter != properties.end()) { + o << " "; + printType(o, options, manager, iter->second.first.replace('.','/'), + 1, false, false); + o << " m_" << iter->first << ";\n"; + iter++; + } + } + + o << "};\n\n"; + + + // generate constructor + o << classname << "::" << classname + << "(css::uno::Reference< css::uno::XComponentContext > const & context) :\n"; + if (supportxcomponent) { + o << " cppu::WeakComponentImplHelper" << interfaces.size() << "<"; + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = + interfaces.begin(); + while (iter != interfaces.end()) { + o << "\n " << scopedCppName(*iter, false, true); + iter++; + if (iter != interfaces.end()) + o << ","; + else + o << ">(m_mutex),\n"; + } + } + if (propertyhelper.getLength() > 0) + o << " cppuhelper::PropertySetMixin< " + << scopedCppName(propertyhelper, false, true) << " >(\n" + << " context, static_cast< Implements >(\n " + << "IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET " + << "| IMPLEMENTS_PROPERTY_ACCESS)),\n"; + + o << " m_xContext(context)\n{}\n\n"; +} + +void generateXServiceInfoBodies(std::ostream& o, + const rtl::OString & classname) +{ + o << "/* com.sun.star.uno.XServiceInfo */\n" + << "rtl::OUString SAL_CALL " << classname << "getImplementationName() " + << "throw (css::uno::RuntimeException)\n{\n " + << "return _getImplementationName();\n}\n\n"; + + o << "sal_Bool SAL_CALL " << classname + << "supportsService(rtl::OUString const & " + << "serviceName) throw (css::uno::RuntimeException)\n{\n " + << "css::uno::Sequence< rtl::OUString > serviceNames = " + << "_getSupportedServiceNames();\n " + << "for (sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {\n " + << " if (serviceNames[i] == serviceName)\n return true;\n" + << " }\n return false;\n}\n\n"; + + o << "css::uno::Sequence< rtl::OUString > SAL_CALL " << classname + << "getSupportedServiceNames() throw (css::uno::RuntimeException)\n{\n " + << "return _getSupportedServiceNames();\n}\n\n"; +} + + +void generateMethodBodies(std::ostream& o, + ProgramOptions const & options, + TypeManager const & manager, + const rtl::OString & classname, + const std::hash_set< rtl::OString, rtl::OStringHash >& interfaces) +{ + rtl::OString name(classname.concat("::")); + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = + interfaces.begin(); + codemaker::GeneratedTypeSet generated; + while (iter != interfaces.end()) { + if ( (*iter).equals("com.sun.star.lang.XServiceInfo") ) { + generateXServiceInfoBodies(o, name); + } else { + typereg::Reader reader(manager.getTypeReader((*iter).replace('.','/'))); + printMethods(o, options, manager, reader, generated, "_", + name, "", true, true); + } + iter++; + } +} + +void generateSkeleton(ProgramOptions const & options, + TypeManager const & manager, + std::vector< rtl::OString > const & types, + rtl::OString const & delegate) +{ + std::hash_set< rtl::OString, rtl::OStringHash > interfaces; + std::hash_set< rtl::OString, rtl::OStringHash > services; + StringPairHashMap properties; + bool attributes = false; + bool serviceobject = false; + bool supportxcomponent = false; + + std::vector< rtl::OString >::const_iterator iter = types.begin(); + while (iter != types.end()) { + checkType(manager, *iter, interfaces, services, properties, attributes); + iter++; + } + + rtl::OString propertyhelper = checkPropertyHelper(manager, services); + + checkDefaultInterfaces(interfaces, services, propertyhelper); + + if (interfaces.size() > 12) + std::cout << "ERROR: the skeletonmaker supports components with only 12 interfaces!\n"; + + // check if service object or simple UNO object + if (!services.empty()) + serviceobject = true; + + supportxcomponent = checkXComponentSupport(manager, interfaces); + + rtl::OString compFileName(createFileNameFromType( + options.outputpath, + options.implname.replace('.','/'), + ".cxx")); + + rtl::OString tmpDir = getTempDir(compFileName); + FileStream file; + file.createTempFile(tmpDir); + rtl::OString tmpFileName; + + if(!file.isValid()) + { + rtl::OString message("cannot open "); + message += compFileName + " for writing"; + throw CannotDumpException(message); + } else { + tmpFileName = file.getName(); + } + file.close(); + std::ofstream oFile(tmpFileName.getStr(), std::ios_base::binary); + + try { + generateIncludes(oFile, interfaces, properties, attributes, + false, serviceobject, supportxcomponent); + // namespace + oFile << "\n\nnamespace css = ::com::sun::star;\n\n"; + short nm = generateNamespace(oFile, options.implname); + sal_Int32 index = 0; + rtl::OString nmspace; + rtl::OString classname(options.implname); + if ((index = classname.lastIndexOf('.')) > 0) { + nmspace = scopedCppName(classname.copy(0, index)); + nmspace = nmspace.concat("::"); + classname = classname.copy(index+1); + } + + generateServiceHelper(oFile, options.implname, services); + + generateClassDefinition(oFile, options, manager, classname, + interfaces, properties, propertyhelper, + supportxcomponent); + + generateMethodBodies(oFile, options, manager, classname, interfaces); + + generateCreateFunction(oFile, classname); + + // close namepsace + for (short i=0; i < nm; i++) + oFile << "} "; + oFile << "// closing namespace\n\n"; + + generateCompFunctions(oFile, nmspace); + + oFile.close(); + OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, sal_False)); + } catch(CannotDumpException& e) { + + std::cout << "ERROR: " << e.m_message.getStr() << "\n"; + // remove existing type file if something goes wrong to ensure consistency + if (fileExists(compFileName)) + removeTypeFile(compFileName); + + // remove tmp file if something goes wrong + removeTypeFile(tmpFileName); + } +} + +} } + + diff --git a/unodevtools/source/skeletonmaker/cpptypemaker.cxx b/unodevtools/source/skeletonmaker/cpptypemaker.cxx new file mode 100644 index 000000000000..c7cd69441506 --- /dev/null +++ b/unodevtools/source/skeletonmaker/cpptypemaker.cxx @@ -0,0 +1,737 @@ +/************************************************************************* + * + * $RCSfile: cpptypemaker.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:29:58 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "skeletoncpp.hxx" + +using namespace ::codemaker::cpp; + +namespace skeletonmaker { namespace cpp { + +void printType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + codemaker::UnoType::Sort sort, RTTypeClass typeClass, + rtl::OString const & name, sal_Int32 rank, + std::vector< rtl::OString > const & arguments, short referenceType, + bool shortname, bool defaultvalue) +{ + if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) { + switch (sort) { + case codemaker::UnoType::SORT_BOOLEAN: + o << "sal_False"; + return; + case codemaker::UnoType::SORT_CHAR: + case codemaker::UnoType::SORT_BYTE: + case codemaker::UnoType::SORT_SHORT: + case codemaker::UnoType::SORT_UNSIGNED_SHORT: + case codemaker::UnoType::SORT_LONG: + case codemaker::UnoType::SORT_UNSIGNED_LONG: + case codemaker::UnoType::SORT_HYPER: + case codemaker::UnoType::SORT_UNSIGNED_HYPER: + case codemaker::UnoType::SORT_FLOAT: + case codemaker::UnoType::SORT_DOUBLE: + o << "0"; + return; + } + } + + bool bReference = false; + if ((sort > codemaker::UnoType::SORT_CHAR || + rank > 0) && referenceType != 8 ) + bReference = true; + + if (bReference && referenceType == 4) + o << "const "; + + for (sal_Int32 i = 0; i < rank; ++i) { + o << ((shortname) ? "css::uno::Sequence< " : + "::com::sun::star::uno::Sequence< "); + } + if (typeClass == RT_TYPE_INTERFACE && referenceType > 0) + o << ((shortname) ? "css::uno::Reference< " : + "::com::sun::star::uno::Reference< "); + o << scopedCppName(codemaker::cpp::translateUnoToCppType( + sort, typeClass, name), false, shortname); + if (typeClass == RT_TYPE_INTERFACE && referenceType > 0) + o << " >"; + for (sal_Int32 i = 0; i < rank; ++i) { + o << " >"; + } + + if (bReference && referenceType > 1) + o << " &"; + + if (referenceType == 8 && + (sort > codemaker::UnoType::SORT_CHAR)) + o << "()"; +} + +void printType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + rtl::OString const & type, short referenceType, bool shortname, + bool defaultvalue) +{ + RTTypeClass typeClass; + rtl::OString name; + sal_Int32 rank; + std::vector< rtl::OString > arguments; + codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve( + manager, type, true, true, true, &typeClass, &name, &rank, &arguments); + printType(o, + options, manager, sort, typeClass, name, rank, arguments, + referenceType, shortname, defaultvalue); +} + +bool printConstructorParameters(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, typereg::Reader const & outerReader, + std::vector< rtl::OString > const & arguments) +{ + bool previous = false; + if (reader.getSuperTypeCount() != 0) { + rtl::OString super( + codemaker::convertString(reader.getSuperTypeName(0))); + typereg::Reader superReader(manager.getTypeReader(super)); + if (!superReader.isValid()) { + throw CannotDumpException("Bad type library entity " + super); + } + previous = printConstructorParameters(o, + options, manager, superReader, outerReader, arguments); + } + for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) { + if (previous) { + o << ", "; + } + previous = true; + if ((reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) == 0) { + printType(o, + options, manager, + codemaker::convertString(reader.getFieldTypeName(i)), + 4); + } else if (arguments.empty()) { + o << "java.lang.Object"; + } else { + sal_uInt16 tparam = 0; + while (outerReader.getReferenceTypeName(tparam) + != reader.getFieldTypeName(i)) + { + ++tparam; + OSL_ASSERT(tparam < outerReader.getReferenceCount()); + } + // assume std::vector< rtl::OString >::size_type is at least as + // large as sal_uInt16: + printType(o, options, manager, arguments[tparam], 4); + } + o << ' ' + << (codemaker::cpp::translateUnoToCppIdentifier( + codemaker::convertString(reader.getFieldName(i)), + "param"). + getStr()); + } + return previous; +} + +void printConstructor(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, + std::vector< rtl::OString > const & arguments) +{ + rtl::OString type(codemaker::convertString(reader.getTypeName())); +// o << "public "; + o << type.copy(type.lastIndexOf('/') + 1) << '('; + printConstructorParameters(o, options, manager, reader, reader, arguments); + o << ");\n"; +} + +void printMethodParameters(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, sal_uInt16 method, bool previous, + bool withtype, bool shortname) +{ + short referenceType = 4; + for (sal_uInt16 i = 0; i < reader.getMethodParameterCount(method); ++i) { + if (previous) { + o << ", "; + } + previous = true; + + if (reader.getMethodParameterFlags(method, i) == RT_PARAM_OUT + || reader.getMethodParameterFlags(method, i) == RT_PARAM_INOUT) + referenceType = 2; + + if (withtype) + printType(o, options, manager, + codemaker::convertString( + reader.getMethodParameterTypeName(method, i)), + referenceType, shortname); +// if (reader.getMethodParameterFlags(method, i) == RT_PARAM_OUT +// || reader.getMethodParameterFlags(method, i) == RT_PARAM_INOUT) +// { +// o << "[]"; +// } else if ((reader.getMethodParameterFlags(method, i) & RT_PARAM_REST) +// != 0) +// { +// o << (options.java5 ? "..." : "[]"); +// } + o << ' ' + << (codemaker::cpp::translateUnoToCppIdentifier( + codemaker::convertString( + reader.getMethodParameterName(method, i)), + "param"). + getStr()); + } +} + +void printExceptionSpecification(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, sal_uInt16 method, bool shortname) +{ + o << ((shortname) ? " throw (css::uno::RuntimeException" : + " throw (::com::sun::star::uno::RuntimeException"); + if (reader.getMethodExceptionCount(method) > 0) { + for (sal_uInt16 i = 0; i < reader.getMethodExceptionCount(method); ++i) + { + o << ", "; + printType(o, + options, manager, + codemaker::convertString( + reader.getMethodExceptionTypeName(method, i)), + 0, shortname); + } + } + o << ")"; +} + +void printMethods(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, codemaker::GeneratedTypeSet & generated, + rtl::OString const & delegate, rtl::OString const & classname, + rtl::OString const & indentation, bool shortname, bool defaultvalue) +{ + rtl::OString type(codemaker::convertString(reader.getTypeName())); + if (generated.contains(type) || type.equals("com/sun/star/uno/XInterface") || + (defaultvalue && + ( type.equals("com/sun/star/lang/XComponent") || + type.equals("com/sun/star/lang/XTypeProvider") || + type.equals("com/sun/star/uno/XWeak")) ) ) { + return; + } + + static rtl::OString sd(RTL_CONSTASCII_STRINGPARAM("_")); + bool body = ((delegate.getLength() > 0) ? true : false); + bool defaultbody = ((delegate.equals(sd)) ? true : false); + + generated.add(type); + if (options.all || defaultvalue) { + for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) { + typereg::Reader super( + manager.getTypeReader( + codemaker::convertString( + reader.getSuperTypeName(i)))); + if (!super.isValid()) { + throw CannotDumpException( + "Bad type library entity " + + codemaker::convertString( + reader.getSuperTypeName(i))); + } + printMethods(o, options, manager, super, generated, delegate, + classname, indentation, shortname, defaultvalue); + } + if (reader.getFieldCount() > 0 || reader.getMethodCount() > 0) { + o << indentation << "/* "; + printType(o, options, manager, type, 0); + o << ": */\n"; + } + } + sal_uInt16 method = 0; + for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) { + o << indentation; + printType(o, + options, manager, + codemaker::convertString(reader.getFieldTypeName(i)), 1, shortname); + o << " SAL_CALL "; + if (classname.getLength() > 0) + o << classname; + o << "get" + << codemaker::convertString(reader.getFieldName(i)).getStr() + << "()"; + if (method < reader.getMethodCount() + && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_GET + && reader.getMethodName(method) == reader.getFieldName(i)) + { + printExceptionSpecification(o, options, manager, reader, + method++, shortname); + } + if (body) { + if (defaultbody) { + o << "\n{\n return "; + printType(o, + options, manager, + codemaker::convertString(reader.getFieldTypeName(i)), 8, + shortname, defaultvalue); + o << "\n}\n\n"; + } else { + o << "\n" << indentation << " { return " + << delegate.getStr() << "get" + << codemaker::convertString(reader.getFieldName(i)).getStr() + << "(); }"; + } + } else + o << ";\n"; + if ((reader.getFieldFlags(i) & RT_ACCESS_READONLY) == 0) { + o << indentation << "void SAL_CALL "; + if (classname.getLength() > 0) + o << classname; + o << "set" + << (codemaker::convertString(reader.getFieldName(i)).getStr()) + << '('; + printType(o, + options, manager, + codemaker::convertString(reader.getFieldTypeName(i)), + 4, shortname); + o << " the_value)"; + if (method < reader.getMethodCount() + && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_SET + && reader.getMethodName(method) == reader.getFieldName(i)) + { + printExceptionSpecification(o, options, manager, reader, + method++, shortname); + } + if (body) { + if (defaultbody) { + o << "\n{\n\n}\n\n"; + } else { + o << "\n" << indentation << " { " + << delegate.getStr() << "set" + << codemaker::convertString(reader.getFieldName(i)).getStr() + << "(the_value); }"; + } + } else + o << ";\n"; + } + } + for (; method < reader.getMethodCount(); ++method) { + o << indentation; + printType(o, + options, manager, + codemaker::convertString( + reader.getMethodReturnTypeName(method)), 1, shortname); + o << " SAL_CALL "; + if (classname.getLength() > 0) + o << classname; + o << (codemaker::convertString(reader.getMethodName(method)).getStr()) + << '('; + printMethodParameters(o, options, manager, reader, method, false, + true, shortname); + o << ')'; + printExceptionSpecification(o, options, manager, reader, + method, shortname); + if (body) { + static rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("void")); + if (defaultbody) { + o << "\n{\n"; + if (!reader.getMethodReturnTypeName(method).equals(s)) { + o << " return "; + printType(o, + options, manager, + codemaker::convertString( + reader.getMethodReturnTypeName(method)), 8, + shortname, defaultvalue); + o << ";"; + } + o << "\n}\n\n"; + } else { + o << "\n" << indentation << " { "; + if (!reader.getMethodReturnTypeName(method).equals(s)) + o << "return "; + o << delegate.getStr() + << (codemaker::convertString( + reader.getMethodName(method)).getStr()) + << '('; + printMethodParameters(o, options, manager, reader, method, + false, false, shortname); + o << "); }\n"; + } + } else + o << ";\n"; + } +} + +void printConstructionMethods(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader) +{ + for (sal_uInt16 i = 0; i < reader.getMethodCount(); ++i) { +// o << "public static "; + o << "static "; + printType(o, + options, manager, + codemaker::convertString(reader.getSuperTypeName(0)), 1); + o << ' '; + if (reader.getMethodName(i).getLength() == 0) { + o << "create"; + } else { + o << (codemaker::cpp::translateUnoToCppIdentifier( + codemaker::convertString(reader.getMethodName(i)), + "method"). + getStr()); + } + o << '('; + printMethodParameters(o, options, manager, reader, i, false, true); + o << ')'; + printExceptionSpecification(o, options, manager, reader, i); + o << ";\n"; + } +} + +void printServiceMembers(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, rtl::OString const & type, + rtl::OString const & delegate) +{ + for (sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i) { + rtl::OString referenceType( + codemaker::convertString( + reader.getReferenceTypeName(i)).replace('/', '.')); + + if ( reader.getReferenceSort(i) == RT_REF_SUPPORTS ) { + o << "\n// supported interface " << referenceType.getStr() << "\n"; + generateDocumentation(o, options, manager, referenceType, delegate); + } else if ( reader.getReferenceSort(i) == RT_REF_EXPORTS ) { + o << "\n// exported service " << referenceType.getStr() << "\n"; + generateDocumentation(o, options, manager, referenceType, delegate); + o << "\n// end of exported service " << referenceType.getStr() << "\n"; + } + } + + if (delegate.getLength() == 0) { + o << "\n// properties of service \""<< type.getStr() << "\"\n"; + for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) { + rtl::OString fieldName( + codemaker::convertString(reader.getFieldName(i))); + rtl::OString fieldType( + codemaker::convertString(reader.getFieldTypeName(i))); + + o << "// private "; + printType(o, options, manager, fieldType, 1); + o << " " + << codemaker::cpp::translateUnoToCppIdentifier( + fieldName, "property").getStr() + << ";\n"; + } + } +} + +void printMapsToCppType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + codemaker::UnoType::Sort sort, RTTypeClass typeClass, + rtl::OString const & name, sal_Int32 rank, + std::vector< rtl::OString > const & arguments, const char * cppTypeSort) +{ + o << "maps to C++ "; + if (cppTypeSort != 0) { + o << cppTypeSort << ' '; + } + o << "type \""; + if (rank == 0 && name == "com/sun/star/uno/XInterface") { + o << "Reference< com::sun::star::uno::XInterface >"; + } else { + printType(o, + options, manager, sort, typeClass, name, rank, arguments, 0); + } + o << '"'; +} + +void generateDocumentation(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + rtl::OString const & type, rtl::OString const & delegate) +{ + if (type.indexOf('/') >= 0) { + throw CannotDumpException("Illegal type name " + type); + } + rtl::OString binType(type.replace('.', '/')); + RTTypeClass typeClass; + rtl::OString name; + sal_Int32 rank; + std::vector< rtl::OString > arguments; + codemaker::UnoType::Sort sort = decomposeResolveAndCheck( + manager, binType, false, true, true, &typeClass, &name, &rank, + &arguments); + + bool comment=true; + if (delegate.getLength() > 0) { + if (typeClass != RT_TYPE_INTERFACE && + typeClass != RT_TYPE_SERVICE ) + return; + + comment=false; + } + + if (comment) { + o << "\n// UNO"; + if (rank > 0) { + o << " sequence type"; + } else if (sort != codemaker::UnoType::SORT_COMPLEX) { + o << " simple type"; + } else { + typereg::Reader reader(manager.getTypeReader(name)); + if (!reader.isValid()) { + throw CannotDumpException("Bad type library entity " + name); + } + switch (typeClass) { + case RT_TYPE_INTERFACE: + o << " interface type"; + break; + + case RT_TYPE_MODULE: + o << "IDL module"; + break; + + case RT_TYPE_STRUCT: + if (reader.getReferenceCount() == 0) { + o << " simple struct type"; + } else if (arguments.empty()) { + o << " polymorphic struct type template"; + } else { + o << " instantiated polymorphic struct type"; + } + break; + + case RT_TYPE_ENUM: + o << " enum type"; + break; + + case RT_TYPE_EXCEPTION: + o << " exception type"; + break; + + case RT_TYPE_TYPEDEF: + o << "IDL typedef"; + break; + + case RT_TYPE_SERVICE: + if (reader.getSuperTypeCount() > 0) { + o << " single-inheritance--based service"; + } else { + o << "IDL accumulation-based service"; + } + break; + + case RT_TYPE_SINGLETON: + if ((manager.getTypeReader( + codemaker::convertString( + reader.getSuperTypeName(0))). + getTypeClass()) + == RT_TYPE_INTERFACE) + { + o << " inheritance-based singleton"; + } else { + o << "IDL service-based singleton"; + } + break; + + case RT_TYPE_CONSTANTS: + o << "IDL constant group"; + break; + + default: + OSL_ASSERT(false); + break; + } + } + o << " \"" << type.getStr() << "\" "; + } + sort = codemaker::decomposeAndResolve( + manager, binType, true, true, true, &typeClass, &name, &rank, + &arguments); + if (rank > 0) { + if (comment) { + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, "array"); + o << '\n'; + } + } else if (sort != codemaker::UnoType::SORT_COMPLEX) { + if (comment) { + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, 0); + o << '\n'; + } + } else { + typereg::Reader reader(manager.getTypeReader(name)); + if (!reader.isValid()) { + throw CannotDumpException("Bad type library entity " + name); + } + switch (typeClass) { + case RT_TYPE_INTERFACE: + if (comment) + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, + "interface"); + if (name == "com/sun/star/uno/XInterface") { + if (comment) + o << '\n'; + } else { + if (comment) + o << "; " << (options.all ? "all" : "direct") + << " methods:\n"; + + codemaker::GeneratedTypeSet generated; + printMethods(o, options, manager, reader, generated, + delegate, options.implname); + } + break; + + case RT_TYPE_MODULE: + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, + "namespace"); + o << '\n'; + break; + + case RT_TYPE_STRUCT: + if (reader.getReferenceCount() == 0) { + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, + "class"); + } else if (arguments.empty()) { + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, + options.java5 ? "generic class" : "class"); + } else { + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, + options.java5 ? "generic class instantiation" : "class"); + } + o << "; full constructor:\n"; + printConstructor(o, options, manager, reader, arguments); + break; + + case RT_TYPE_ENUM: + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, + "enum"); + o << '\n'; + break; + + case RT_TYPE_CONSTANTS: + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, + "namespace"); + o << '\n'; + break; + + case RT_TYPE_EXCEPTION: + printMapsToCppType(o, + options, manager, sort, typeClass, name, rank, arguments, + "exception class"); + o << "; full constructor:\n"; + printConstructor(o, options, manager, reader, arguments); + break; + + case RT_TYPE_SERVICE: + if (reader.getSuperTypeCount() > 0) { + if (comment) { + printMapsToCppType(o, options, manager, sort, typeClass, + name, rank, arguments, "class"); + o << "; construction methods:\n"; + printConstructionMethods(o, options, manager, reader); + } + + rtl::OString super( + codemaker::convertString( + reader.getSuperTypeName(0)).replace('/', '.')); + generateDocumentation(o, options, manager, super, delegate); + } else { + if (comment) + o << ("does not map to C++\n" + "// the service members are generated instead\n"); + printServiceMembers(o, options, manager, reader, type, delegate); + } + break; + + case RT_TYPE_SINGLETON: + if (reader.getSuperTypeCount() > 0 && + ((manager.getTypeReader( + codemaker::convertString( + reader.getSuperTypeName(0))). + getTypeClass()) == RT_TYPE_INTERFACE) ) { + printMapsToCppType(o, options, manager, sort, typeClass, + name, rank, arguments, + "class"); +// o << "; get method:\npublic static "; + o << "; get method:\nstatic "; + printType(o, options, manager, + codemaker::convertString(reader.getSuperTypeName(0)), 1); + o << " get(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);\n"; + } else { + o << "does not map to C++\n"; + } + break; + + default: + OSL_ASSERT(false); + break; + } + } +} + +} } + + diff --git a/unodevtools/source/skeletonmaker/javacompskeleton.cxx b/unodevtools/source/skeletonmaker/javacompskeleton.cxx new file mode 100644 index 000000000000..f6d16a66d649 --- /dev/null +++ b/unodevtools/source/skeletonmaker/javacompskeleton.cxx @@ -0,0 +1,425 @@ +/************************************************************************* + * + * $RCSfile: javacompskeleton.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:30:10 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "skeletonjava.hxx" + +using namespace ::codemaker::java; + +namespace skeletonmaker { namespace java { + +void generatePackage(std::ostream & o, const rtl::OString & implname) +{ + short count=0; + sal_Int32 index = implname.lastIndexOf('.'); + if (index != -1) { + o << "package " << implname.copy(0, index) << ";\n\n"; + } +} + +void generateImports(std::ostream & o, + const std::hash_set< rtl::OString, rtl::OStringHash >& interfaces, + const rtl::OString & propertyhelper, + bool serviceobject, bool supportxcomponent) +{ + o << "import com.sun.star.uno.XComponentContext;\n"; + if (serviceobject) { + o << "import com.sun.star.lib.uno.helper.Factory;\n"; + o << "import com.sun.star.lang.XSingleComponentFactory;\n"; + o << "import com.sun.star.registry.XRegistryKey;\n"; + } + + if (!propertyhelper.equals("_")) { + if (supportxcomponent) + o << "import com.sun.star.lib.uno.helper.ComponentBase;\n"; + else + o << "import com.sun.star.lib.uno.helper.WeakBase;\n"; + } + if (propertyhelper.getLength() > 0) { + if (propertyhelper.equals("_")) { + o << "import com.sun.star.lib.uno.helper.PropertySet;\n"; + o << "import com.sun.star.beans.PropertyAttribute;\n"; + } else { + o << "import com.sun.star.uno.Type;\n"; + o << "import com.sun.star.lib.uno.helper.PropertySetMixin;\n"; + } + } + +// std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = interfaces.begin(); +// while (iter != interfaces.end()) { +// o << "import " << ((*iter).getStr()) << ";\n"; +// iter++; +// } +} + +void generateCompFunctions(std::ostream & o, const rtl::OString & classname) +{ + o << " public static XSingleComponentFactory __getComponentFactory(" + << "String sImplementationName ) {\n" + << " XSingleComponentFactory xFactory = null;\n\n" + << " if ( sImplementationName.equals( m_implementationName ) )\n" + << " xFactory = Factory.createComponentFactory(" + << classname << ".class, m_serviceNames);\n" + << " return xFactory;\n }\n\n"; + + o << " public static boolean __writeRegistryServiceInfo(" + << "XRegistryKey xRegistryKey ) {\n" + << " return Factory.writeRegistryServiceInfo(m_implementationName,\n" + << " m_serviceNames,\n" + << " xRegistryKey);\n" + << " }\n\n"; +} + +void generateXServiceInfoBodies(std::ostream& o) +{ + o << " /* com.sun.star.lang.XServiceInfo */\n"; + o << " public java.lang.String getImplementationName() {\n" + << " return m_implementationName;\n }\n\n"; + + o << " public boolean supportsService( java.lang.String sService ) {\n" + << " int len = m_serviceNames.length;\n\n" + << " for( int i=0; i < len; i++) {\n" + << " if (sService.equals(m_serviceNames[i]))\n" + << " return true;\n" + << " }\n return false;\n }\n\n"; + + o << " public java.lang.String[] getSupportedServiceNames() {\n" + << " return m_serviceNames;\n }\n\n"; +} + + +bool checkAttribute(rtl::OStringBuffer& attributeValue, sal_uInt16 attribute) { + bool cast = false; + sal_uInt16 attributes[9] = { + /* com::sun::star::beans::PropertyValue::MAYBEVOID */ 1, + /* com::sun::star::beans::PropertyValue::BOUND */ 2, + /* com::sun::star::beans::PropertyValue::CONSTRAINED */ 4, + /* com::sun::star::beans::PropertyValue::TRANSIENT */ 8, + /* com::sun::star::beans::PropertyValue::READONLY */ 16, + /* com::sun::star::beans::PropertyValue::MAYBEAMBIGIOUS */ 32, + /* com::sun::star::beans::PropertyValue::MAYBEDEFAULT */ 64, + /* com::sun::star::beans::PropertyValue::REMOVEABLE */ 128, + /* com::sun::star::beans::PropertyValue::OPTIONAL */ 256 }; + + for (sal_uInt16 i = 0; i < 9; i++) { + if (attribute & attributes[i]) { + if (attributeValue.getLength() > 0) { + cast |= true; + attributeValue.append("|"); + } + switch (attributes[i]) { + case 1: + attributeValue.append("PropertyAttribute.MAYBEVOID"); + break; + case 2: + attributeValue.append("PropertyAttribute.BOUND"); + break; + case 4: + attributeValue.append("PropertyAttribute.CONSTRAINED"); + break; + case 8: + attributeValue.append("PropertyAttribute.TRANSIENT"); + break; + case 16: + attributeValue.append("PropertyAttribute.READONLY"); + break; + case 32: + attributeValue.append("PropertyAttribute.MAYBEAMBIGIOUS"); + break; + case 64: + attributeValue.append("PropertyAttribute.MAYBEDEFAULT"); + break; + case 128: + attributeValue.append("PropertyAttribute.REMOVEABLE"); + break; + case 256: + attributeValue.append("PropertyAttribute.OPTIONAL"); + break; + } + } + } + if (cast) { + attributeValue.insert(0, '('); + attributeValue.append(')'); + } + + return cast; +} + +void registerProperties(std::ostream& o, + TypeManager const & manager, + const StringPairHashMap& properties, + const rtl::OString& indentation) +{ + if (!properties.empty()) { + StringPairHashMap::const_iterator iter = + properties.begin(); + bool cast = false; + rtl::OStringBuffer attributeValue; + while (iter != properties.end()) { + if (iter->second.second > 0) { + cast = checkAttribute(attributeValue, iter->second.second); + } else { + cast = true; + attributeValue.append('0'); + } + + o << indentation << "registerProperty(\"" << iter->first + << "\", \"m_" << iter->first << "\",\n" + << indentation << " "; + if (cast) + o << "(short)"; + + o << attributeValue.makeStringAndClear() << ");\n"; + iter++; + } + } +} + +void generateMethodBodies(std::ostream& o, + ProgramOptions const & options, + TypeManager const & manager, + const std::hash_set< rtl::OString, rtl::OStringHash >& interfaces, + const rtl::OString& indentation) +{ + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = + interfaces.begin(); + codemaker::GeneratedTypeSet generated; + while (iter != interfaces.end()) { + if ( (*iter).equals("com.sun.star.lang.XServiceInfo")) { + generateXServiceInfoBodies(o); + } else { + typereg::Reader reader(manager.getTypeReader((*iter).replace('.','/'))); + printMethods(o, options, manager, reader, generated, "_", + indentation, true); + } + iter++; + } +} + +void generateClassDefinition(std::ostream& o, + ProgramOptions const & options, + TypeManager const & manager, + const rtl::OString & classname, + const std::hash_set< rtl::OString, rtl::OStringHash >& services, + const std::hash_set< rtl::OString, rtl::OStringHash >& interfaces, + const StringPairHashMap& properties, + const rtl::OString& propertyhelper, bool supportxcomponent) +{ + o << "\n\npublic final class " << classname << " extends "; + + if (!interfaces.empty()) { + if (propertyhelper.equals("_")) { + o << "PropertySet\n"; + } else { + if (supportxcomponent) + o << "ComponentBase\n"; + else + o << "WeakBase\n"; + } + o << " implements "; + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = + interfaces.begin(); + while (iter != interfaces.end()) { + o << (*iter); + iter++; + if (iter != interfaces.end()) + o << ",\n "; + } + } + o << "\n{\n"; + + o << " private final XComponentContext m_context;\n"; + + // check property helper + if (propertyhelper.getLength() > 1) { + o << " private final PropertySetMixin m_prophlp;"; + } + + o << " private static final java.lang.String m_implementationName = " + << classname << ".class.getName();\n"; + + if (!services.empty()) { + o << " private static final java.lang.String[] m_serviceNames = {\n"; + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = + services.begin(); + while (iter != services.end()) { + o << " \"" << (*iter).replace('/','.') << "\""; + iter++; + if (iter != services.end()) + o << ",\n"; + else + o << " };\n"; + } + } + o << "\n public " << classname << "( XComponentContext context ) {\n" + << " m_context = context;\n"; + if (propertyhelper.equals("_")) { + registerProperties(o, manager, properties, " "); + } else { + if (propertyhelper.getLength() > 1) { + o << " m_prophlp = new PropertySetMixin(\n" + << " m_context, this, new Type(" << propertyhelper + << ".class));\n"; + } + } + o << " };\n\n"; + + if (!services.empty()) + generateCompFunctions(o, classname); + + generateMethodBodies(o, options, manager, interfaces, " "); + + if (!properties.empty()) { + StringPairHashMap::const_iterator iter = + properties.begin(); + while (iter != properties.end()) { + o << " protected "; + printType(o, options, manager, iter->second.first.replace('.','/'), + false, false); + o << " m_" << iter->first << ";\n"; + iter++; + } + } + + // end of class definition + o << "}\n"; +} + +void generateSkeleton(ProgramOptions const & options, + TypeManager const & manager, + std::vector< rtl::OString > const & types, + rtl::OString const & delegate) +{ + std::hash_set< rtl::OString, rtl::OStringHash > interfaces; + std::hash_set< rtl::OString, rtl::OStringHash > services; + StringPairHashMap properties; + bool attributes = false; + bool serviceobject = false; + bool supportxcomponent = false; + + std::vector< rtl::OString >::const_iterator iter = types.begin(); + while (iter != types.end()) { + checkType(manager, *iter, interfaces, services, properties, attributes); + iter++; + } + + // check if service object or simple UNO object + if (!services.empty()) + serviceobject = true; + + rtl::OString propertyhelper = checkPropertyHelper(manager, services); + checkDefaultInterfaces(interfaces, services, propertyhelper); + + supportxcomponent = checkXComponentSupport(manager, interfaces); + + rtl::OString compFileName(createFileNameFromType( + options.outputpath, + options.implname.replace('.','/'), + ".java")); + + rtl::OString tmpDir = getTempDir(compFileName); + FileStream file; + file.createTempFile(tmpDir); + rtl::OString tmpFileName; + + if(!file.isValid()) + { + rtl::OString message("cannot open "); + message += compFileName + " for writing"; + throw CannotDumpException(message); + } else { + tmpFileName = file.getName(); + } + file.close(); + std::ofstream oFile(tmpFileName.getStr(), std::ios_base::binary); + + try { + generatePackage(oFile, options.implname); + + generateImports(oFile, interfaces, propertyhelper, + serviceobject, supportxcomponent); + + rtl::OString classname(options.implname); + sal_Int32 index = 0; + if ((index = classname.lastIndexOf('.')) > 0) + classname = classname.copy(index+1); + + generateClassDefinition(oFile, options, manager, classname, services, + interfaces, properties, propertyhelper, + supportxcomponent); + + oFile.close(); + OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, sal_False)); + } catch(CannotDumpException& e) { + + std::cout << "ERROR: " << e.m_message.getStr() << "\n"; + // remove existing type file if something goes wrong to ensure consistency + if (fileExists(compFileName)) + removeTypeFile(compFileName); + + // remove tmp file if something goes wrong + removeTypeFile(tmpFileName); + } +} + +} } + + diff --git a/unodevtools/source/skeletonmaker/javatypemaker.cxx b/unodevtools/source/skeletonmaker/javatypemaker.cxx new file mode 100644 index 000000000000..5b8ed625741d --- /dev/null +++ b/unodevtools/source/skeletonmaker/javatypemaker.cxx @@ -0,0 +1,707 @@ +/************************************************************************* + * + * $RCSfile: javatypemaker.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:30:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "skeletonjava.hxx" + +namespace skeletonmaker { namespace java { + +void printType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + rtl::OString const & type, bool referenceType, + bool defaultvalue); + +void printType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + codemaker::UnoType::Sort sort, RTTypeClass typeClass, + rtl::OString const & name, sal_Int32 rank, + std::vector< rtl::OString > const & arguments, bool referenceType, + bool defaultvalue) +{ + if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) { + switch (sort) { + case codemaker::UnoType::SORT_BOOLEAN: + o << "false"; + return; + case codemaker::UnoType::SORT_CHAR: + case codemaker::UnoType::SORT_BYTE: + case codemaker::UnoType::SORT_SHORT: + case codemaker::UnoType::SORT_UNSIGNED_SHORT: + case codemaker::UnoType::SORT_LONG: + case codemaker::UnoType::SORT_UNSIGNED_LONG: + case codemaker::UnoType::SORT_HYPER: + case codemaker::UnoType::SORT_UNSIGNED_HYPER: + case codemaker::UnoType::SORT_FLOAT: + case codemaker::UnoType::SORT_DOUBLE: + o << "0"; + return; + } + } + + if (defaultvalue) { + if (sort == codemaker::UnoType::SORT_COMPLEX) { + o << "null"; + return; + } else + o << "new "; + } + + o << (codemaker::java::translateUnoToJavaType( + sort, typeClass, name, referenceType). + replace('/', '.').getStr()); + if (!arguments.empty() && options.java5) { + o << '<'; + for (std::vector< rtl::OString >::const_iterator i(arguments.begin()); + i != arguments.end(); ++i) + { + if (i != arguments.begin()) { + o << ", "; + } + printType(o, options, manager, *i, true, defaultvalue); + } + o << '>'; + } + for (sal_Int32 i = 0; i < rank; ++i) { + if (defaultvalue) + o << "[0]"; + else + o << "[]"; + } + + if (defaultvalue && sort > codemaker::UnoType::SORT_CHAR && rank == 0) + o << "()"; +} + +void printType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + rtl::OString const & type, bool referenceType, bool defaultvalue) +{ + RTTypeClass typeClass; + rtl::OString name; + sal_Int32 rank; + std::vector< rtl::OString > arguments; + codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve( + manager, type, true, true, true, &typeClass, &name, &rank, &arguments); + printType(o, + options, manager, sort, typeClass, name, rank, arguments, + referenceType, defaultvalue); +} + +bool printConstructorParameters(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, typereg::Reader const & outerReader, + std::vector< rtl::OString > const & arguments) +{ + bool previous = false; + if (reader.getSuperTypeCount() != 0) { + rtl::OString super( + codemaker::convertString(reader.getSuperTypeName(0))); + typereg::Reader superReader(manager.getTypeReader(super)); + if (!superReader.isValid()) { + throw CannotDumpException("Bad type library entity " + super); + } + previous = printConstructorParameters(o, + options, manager, superReader, outerReader, arguments); + } + for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) { + if (previous) { + o << ", "; + } + previous = true; + if ((reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) == 0) { + printType(o, + options, manager, + codemaker::convertString(reader.getFieldTypeName(i)), + false); + } else if (arguments.empty()) { + o << "java.lang.Object"; + } else { + sal_uInt16 tparam = 0; + while (outerReader.getReferenceTypeName(tparam) + != reader.getFieldTypeName(i)) + { + ++tparam; + OSL_ASSERT(tparam < outerReader.getReferenceCount()); + } + // assume std::vector< rtl::OString >::size_type is at least as + // large as sal_uInt16: + printType(o, options, manager, arguments[tparam], true); + } + o + << ' ' + << (codemaker::java::translateUnoToJavaIdentifier( + codemaker::convertString(reader.getFieldName(i)), + "param"). + getStr()); + } + return previous; +} + +void printConstructor(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, + std::vector< rtl::OString > const & arguments) +{ + rtl::OString type(codemaker::convertString(reader.getTypeName())); + o << "public " << type.copy(type.lastIndexOf('/') + 1) << '('; + printConstructorParameters(o, options, manager, reader, reader, arguments); + o << ");\n"; +} + +void printMethodParameters(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, sal_uInt16 method, bool previous, + bool withtype, bool shortname) +{ + for (sal_uInt16 i = 0; i < reader.getMethodParameterCount(method); ++i) { + if (previous) { + o << ", "; + } + previous = true; + if (withtype) { + printType(o, options, manager, + codemaker::convertString( + reader.getMethodParameterTypeName(method, i)), + false); + if (reader.getMethodParameterFlags(method, i) == RT_PARAM_OUT + || reader.getMethodParameterFlags(method, i) == RT_PARAM_INOUT) + { + o << "[]"; + } else if ((reader.getMethodParameterFlags(method, i) & RT_PARAM_REST) + != 0) + { + o << (options.java5 ? "..." : "[]"); + } + } + o << ' ' + << (codemaker::java::translateUnoToJavaIdentifier( + codemaker::convertString( + reader.getMethodParameterName(method, i)), + "param"). + getStr()); + } +} + +void printExceptionSpecification(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, sal_uInt16 method) +{ + if (reader.getMethodExceptionCount(method) > 0) { + o << " throws "; + for (sal_uInt16 i = 0; i < reader.getMethodExceptionCount(method); ++i) + { + if (i != 0) { + o << ", "; + } + printType(o, + options, manager, + codemaker::convertString( + reader.getMethodExceptionTypeName(method, i)), + false); + } + } +} + +void printMethods(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, codemaker::GeneratedTypeSet & generated, + rtl::OString const & delegate, rtl::OString const & indentation, + bool defaultvalue) +{ + rtl::OString type(codemaker::convertString(reader.getTypeName())); + if (generated.contains(type) || type == "com/sun/star/uno/XInterface" || + (defaultvalue && + ( type.equals("com/sun/star/lang/XComponent") || + type.equals("com/sun/star/lang/XTypeProvider") || + type.equals("com/sun/star/uno/XWeak")) ) ) { + return; + } + + static rtl::OString sd(RTL_CONSTASCII_STRINGPARAM("_")); + bool body = ((delegate.getLength() > 0) ? true : false); + bool defaultbody = ((delegate.equals(sd)) ? true : false); + + generated.add(type); + if (options.all || defaultvalue) { + for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) { + typereg::Reader super( + manager.getTypeReader( + codemaker::convertString( + reader.getSuperTypeName(i)))); + if (!super.isValid()) { + throw CannotDumpException( + "Bad type library entity " + + codemaker::convertString( + reader.getSuperTypeName(i))); + } + printMethods(o, options, manager, super, generated, delegate, + indentation, defaultvalue); + } + if (reader.getFieldCount() > 0 || reader.getMethodCount() > 0) { + o << indentation << "/* "; + printType(o, options, manager, type, false); + o << ": */\n"; + } + } + sal_uInt16 method = 0; + for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) { + o << indentation << "public "; + printType(o, + options, manager, + codemaker::convertString(reader.getFieldTypeName(i)), false); + o << " get" + << codemaker::convertString(reader.getFieldName(i)).getStr() + << "()"; + if (method < reader.getMethodCount() + && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_GET + && reader.getMethodName(method) == reader.getFieldName(i)) + { + printExceptionSpecification(o, options, manager, reader, method++); + } + if (body) { + if (defaultbody) { + o << "\n" << indentation << "{\n" << indentation << " return "; + printType(o, + options, manager, + codemaker::convertString(reader.getFieldTypeName(i)), + false, defaultvalue); + o << ";\n" << indentation << "}\n\n"; + } else { + o << "\n" << indentation << " { return " + << delegate.getStr() << "get" + << codemaker::convertString(reader.getFieldName(i)).getStr() + << "();\n" << indentation << "}\n\n"; + } + } else { + o << ";\n"; + } + + // REMOVE next line + rtl::OUString tmp = reader.getFieldName(i); + if ((reader.getFieldFlags(i) & RT_ACCESS_READONLY) == 0) { + o << indentation << "public void set" + << (codemaker::convertString(reader.getFieldName(i)). + getStr()) + << '('; + printType(o, + options, manager, + codemaker::convertString(reader.getFieldTypeName(i)), + false); + o << " the_value)"; + if (method < reader.getMethodCount() + && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_SET + && reader.getMethodName(method) == reader.getFieldName(i)) + { + printExceptionSpecification(o, options, manager, reader, method++); + } + if (body) { + if (defaultbody) { + o << "\n" << indentation << "{\n\n" << indentation << "}\n\n"; + } else { + o << "\n" << indentation << " { " + << delegate.getStr() << "set" + << codemaker::convertString(reader.getFieldName(i)).getStr() + << "(the_value);\n" << indentation << "}"; + } + } else { + o << ";\n"; + } + } + } + for (; method < reader.getMethodCount(); ++method) { + o << indentation << "public "; + printType(o, + options, manager, + codemaker::convertString( + reader.getMethodReturnTypeName(method)), + false); + o << ' ' + << (codemaker::convertString(reader.getMethodName(method)). + getStr()) + << '('; + printMethodParameters(o, options, manager, reader, method, false, true); + o << ')'; + printExceptionSpecification(o, options, manager, reader, method); + if (body) { + static rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("void")); + if (defaultbody) { + o << "\n" << indentation << "{\n"; + if (!reader.getMethodReturnTypeName(method).equals(s)) { + o << indentation << " return "; + printType(o, + options, manager, + codemaker::convertString( + reader.getMethodReturnTypeName(method)), + false, defaultvalue); + o << ";"; + } + o << "\n" << indentation << "}\n\n"; + } else { + o << "\n" << indentation << " { "; + if (!reader.getMethodReturnTypeName(method).equals(s)) + o << "return "; + o << delegate.getStr() + << (codemaker::convertString( + reader.getMethodName(method)).getStr()) + << '('; + printMethodParameters(o, options, manager, reader, method, + false, false); + o << ");\n" << indentation << "}\n"; + } + } else + o << ";\n"; + } +} + +void printConstructionMethods(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader) +{ + for (sal_uInt16 i = 0; i < reader.getMethodCount(); ++i) { + o << "public static "; + printType(o, + options, manager, + codemaker::convertString(reader.getSuperTypeName(0)), false); + o << ' '; + if (reader.getMethodName(i).getLength() == 0) { + o << "create"; + } else { + o + << (codemaker::java::translateUnoToJavaIdentifier( + codemaker::convertString(reader.getMethodName(i)), + "method"). + getStr()); + } + o << '('; + printMethodParameters(o, options, manager, reader, i, false, true); + o << ')'; + printExceptionSpecification(o, options, manager, reader, i); + o << ";\n"; + } +} + +void generateDocumentation(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + rtl::OString const & type); + +void printServiceMembers(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, rtl::OString const & type) +{ + for (sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i) { + rtl::OString referenceType( + codemaker::convertString( + reader.getReferenceTypeName(i)).replace('/', '.')); + + if ( reader.getReferenceSort(i) == RT_REF_SUPPORTS ) { + o << "\n// supported interface " << referenceType.getStr() << "\n"; + generateDocumentation(o, options, manager, referenceType); + } else if ( reader.getReferenceSort(i) == RT_REF_EXPORTS ) { + o << "\n// exported service " << referenceType.getStr() << "\n"; + generateDocumentation(o, options, manager, referenceType); + } + } + + o << "\n// properties of service \""<< type.getStr() << "\"\n"; + for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) { + rtl::OString fieldName( + codemaker::convertString(reader.getFieldName(i))); + rtl::OString fieldType( + codemaker::convertString(reader.getFieldTypeName(i))); + + o << "// private "; + printType(o, options, manager, fieldType, false); + o << " " + << codemaker::java::translateUnoToJavaIdentifier( + fieldName, "property").getStr() + << ";\n"; + } +} + +void printMapsToJavaType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + codemaker::UnoType::Sort sort, RTTypeClass typeClass, + rtl::OString const & name, sal_Int32 rank, + std::vector< rtl::OString > const & arguments, const char * javaTypeSort) +{ + o << "maps to Java " << (options.java5 ? "1.5" : "1.4") << " "; + if (javaTypeSort != 0) { + o << javaTypeSort << ' '; + } + o << "type \""; + if (rank == 0 && name == "com/sun/star/uno/XInterface") { + o << "com.sun.star.uno.XInterface"; + } else { + printType(o, + options, manager, sort, typeClass, name, rank, arguments, false); + } + o << '"'; +} + +void generateDocumentation(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + rtl::OString const & type) +{ + if (type.indexOf('/') >= 0) { + throw CannotDumpException("Illegal type name " + type); + } + rtl::OString binType(type.replace('.', '/')); + RTTypeClass typeClass; + rtl::OString name; + sal_Int32 rank; + std::vector< rtl::OString > arguments; + codemaker::UnoType::Sort sort = decomposeResolveAndCheck( + manager, binType, false, true, true, &typeClass, &name, &rank, + &arguments); + o << "\n// UNO"; + if (rank > 0) { + o << " sequence type"; + } else if (sort != codemaker::UnoType::SORT_COMPLEX) { + o << " simple type"; + } else { + typereg::Reader reader(manager.getTypeReader(name)); + if (!reader.isValid()) { + throw CannotDumpException("Bad type library entity " + name); + } + switch (typeClass) { + case RT_TYPE_INTERFACE: + o << " interface type"; + break; + + case RT_TYPE_MODULE: + o << "IDL module"; + break; + + case RT_TYPE_STRUCT: + if (reader.getReferenceCount() == 0) { + o << " simple struct type"; + } else if (arguments.empty()) { + o << " polymorphic struct type template"; + } else { + o << " instantiated polymorphic struct type"; + } + break; + + case RT_TYPE_ENUM: + o << " enum type"; + break; + + case RT_TYPE_EXCEPTION: + o << " exception type"; + break; + + case RT_TYPE_TYPEDEF: + o << "IDL typedef"; + break; + + case RT_TYPE_SERVICE: + if (reader.getSuperTypeCount() > 0) { + o << " single-inheritance--based service"; + } else { + o << "IDL accumulation-based service"; + } + break; + + case RT_TYPE_SINGLETON: + if ((manager.getTypeReader( + codemaker::convertString( + reader.getSuperTypeName(0))). + getTypeClass()) + == RT_TYPE_INTERFACE) + { + o << " inheritance-based singleton"; + } else { + o << "IDL service-based singleton"; + } + break; + + case RT_TYPE_CONSTANTS: + o << "IDL constant group"; + break; + + default: + OSL_ASSERT(false); + break; + } + } + o << " \"" << type.getStr() << "\" "; + sort = codemaker::decomposeAndResolve( + manager, binType, true, true, true, &typeClass, &name, &rank, + &arguments); + if (rank > 0) { + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, "array"); + o << '\n'; + } else if (sort != codemaker::UnoType::SORT_COMPLEX) { + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, 0); + o << '\n'; + } else { + typereg::Reader reader(manager.getTypeReader(name)); + if (!reader.isValid()) { + throw CannotDumpException("Bad type library entity " + name); + } + switch (typeClass) { + case RT_TYPE_INTERFACE: + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, + "interface"); + if (name == "com/sun/star/uno/XInterface") { + o << '\n'; + } else { + o + << "; " << (options.all ? "all" : "direct") + << " methods:\n"; + codemaker::GeneratedTypeSet generated; + printMethods(o, options, manager, reader, generated, + "", "", false); + } + break; + + case RT_TYPE_MODULE: + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, + "package"); + o << '\n'; + break; + + case RT_TYPE_STRUCT: + if (reader.getReferenceCount() == 0) { + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, + "class"); + } else if (arguments.empty()) { + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, + options.java5 ? "generic class" : "class"); + } else { + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, + options.java5 ? "generic class instantiation" : "class"); + } + o << "; full constructor:\n"; + printConstructor(o, options, manager, reader, arguments); + break; + + case RT_TYPE_ENUM: + case RT_TYPE_CONSTANTS: + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, + "class"); + o << '\n'; + break; + + case RT_TYPE_EXCEPTION: + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, + "exception class"); + o << "; full constructor:\n"; + printConstructor(o, options, manager, reader, arguments); + break; + + case RT_TYPE_SERVICE: + if (reader.getSuperTypeCount() > 0) { + printMapsToJavaType(o, + options, manager, sort, typeClass, name, rank, arguments, + "class"); + o << "; construction methods:\n"; + printConstructionMethods(o, options, manager, reader); + + rtl::OString super( + codemaker::convertString( + reader.getSuperTypeName(0)).replace('/', '.')); + + generateDocumentation(o, options, manager, super); + } else { + o << ("does not map to Java\n" + "// the service members are generated instead\n"); + printServiceMembers(o, options, manager, reader, type); + } + break; + + case RT_TYPE_SINGLETON: + if (reader.getSuperTypeCount() > 0 && + ((manager.getTypeReader( + codemaker::convertString( + reader.getSuperTypeName(0))). + getTypeClass()) == RT_TYPE_INTERFACE) ) { + printMapsToJavaType(o, options, manager, sort, typeClass, + name, rank, arguments, "class"); + o << "; get method:\npublic static "; + printType(o, options, manager, + codemaker::convertString(reader.getSuperTypeName(0)), + false); + o + << " get(com.sun.star.uno.XComponentContext context);\n"; + } else { + o << "does not map to Java\n"; + } + break; + + default: + OSL_ASSERT(false); + break; + } + } +} + +} } + + diff --git a/unodevtools/source/skeletonmaker/makefile.mk b/unodevtools/source/skeletonmaker/makefile.mk new file mode 100644 index 000000000000..8a4118dd2a9a --- /dev/null +++ b/unodevtools/source/skeletonmaker/makefile.mk @@ -0,0 +1,91 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: jsc $ $Date: 2005-08-23 08:30:33 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +#************************************************************************* + +PRJ := ..$/.. +PRJNAME := unodevtools + +TARGET := uno-skeletonmaker +TARGETTYPE := CUI +LIBTARGET := NO + +ENABLE_EXCEPTIONS := TRUE + +.INCLUDE: settings.mk + +APP1TARGET = $(TARGET) +APP1OBJS = $(OBJ)$/skeletonmaker.obj \ + $(OBJ)$/skeletoncommon.obj \ + $(OBJ)$/javatypemaker.obj \ + $(OBJ)$/cpptypemaker.obj \ + $(OBJ)$/javacompskeleton.obj \ + $(OBJ)$/cppcompskeleton.obj + + + +APP1STDLIBS = $(REGLIB) $(SALLIB) $(SALHELPERLIB) $(CPPULIB) $(CPPUHELPERLIB) +APP1LIBS = $(LB)$/unodevtools.lib \ + $(SOLARLIBDIR)$/codemaker.lib \ + $(SOLARLIBDIR)$/commonjava.lib \ + $(SOLARLIBDIR)$/commoncpp.lib + +OBJFILES = $(APP1OBJS) + +.INCLUDE: target.mk diff --git a/unodevtools/source/skeletonmaker/skeletoncommon.cxx b/unodevtools/source/skeletonmaker/skeletoncommon.cxx new file mode 100644 index 000000000000..526d0dba0a63 --- /dev/null +++ b/unodevtools/source/skeletonmaker/skeletoncommon.cxx @@ -0,0 +1,281 @@ +/************************************************************************* + * + * $RCSfile: skeletoncommon.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:30:44 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <osl/thread.hxx> +#include "skeletonmaker.hxx" +#include "skeletoncommon.hxx" + +using namespace ::codemaker::cpp; + +namespace skeletonmaker { + +codemaker::UnoType::Sort decomposeResolveAndCheck( + TypeManager const & manager, rtl::OString const & type, + bool resolveTypedefs, bool allowVoid, bool allowExtraEntities, + RTTypeClass * typeClass, rtl::OString * name, sal_Int32 * rank, + std::vector< rtl::OString > * arguments) +{ + codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve( + manager, type, resolveTypedefs, allowVoid, allowExtraEntities, + typeClass, name, rank, arguments); + for (std::vector< rtl::OString >::iterator i(arguments->begin()); + i != arguments->end(); ++i) + { + RTTypeClass typeClass2; + rtl::OString name2; + sal_Int32 rank2; + std::vector< rtl::OString > arguments2; + decomposeResolveAndCheck( + manager, *i, true, false, false, &typeClass2, &name2, &rank2, + &arguments2); + } + return sort; +} + +void checkType(TypeManager const & manager, + rtl::OString const & type, + std::hash_set< rtl::OString, rtl::OStringHash >& interfaceTypes, + std::hash_set< rtl::OString, rtl::OStringHash >& serviceTypes, + StringPairHashMap& properties, + bool& attributes) { + + rtl::OString binType(type.replace('.', '/')); + typereg::Reader reader(manager.getTypeReader(binType)); + if (!reader.isValid()) { + throw CannotDumpException("Bad type library entity " + binType); + } + + switch (reader.getTypeClass()) { + case RT_TYPE_INTERFACE: + { + // com/sun/star/lang/XComponent should also not in the list + // but it will be used for checking the impl helper and will be + // removed later if necessary. + if ( binType.equals("com/sun/star/lang/XTypeProvider") || + binType.equals("com/sun/star/uno/XWeak") ) + return; + if (interfaceTypes.find(type) == interfaceTypes.end()) { + interfaceTypes.insert(type); + if (reader.getFieldCount() > 0) + attributes |= true; + } + } + break; + case RT_TYPE_SERVICE: + if (serviceTypes.find(binType) == serviceTypes.end()) { + serviceTypes.insert(binType); + + if (reader.getSuperTypeCount() > 0) { + rtl::OString superType(codemaker::convertString( + reader.getSuperTypeName(0).replace('/', '.'))); + if (interfaceTypes.find(superType) == interfaceTypes.end()) + interfaceTypes.insert(superType); + } else { + for (sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i) { + rtl::OString referenceType( + codemaker::convertString( + reader.getReferenceTypeName(i)).replace('/', '.')); + + if ( reader.getReferenceSort(i) == RT_REF_SUPPORTS ) { + checkType(manager, referenceType, interfaceTypes, + serviceTypes, properties, attributes); + } else if ( reader.getReferenceSort(i) == RT_REF_EXPORTS ) { + checkType(manager, referenceType, interfaceTypes, + serviceTypes, properties, attributes); + } + } + + for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) { + rtl::OString fieldName( + codemaker::convertString(reader.getFieldName(i)). + replace('/', '.')); + rtl::OString fieldType( + codemaker::convertString(reader.getFieldTypeName(i)). + replace('/', '.')); + +// std::pair<rtl::OString, sal_Int16> prop( +// fieldType, reader.getFieldFlags(i)); + +// properties[fieldName] = std::pair<rtl::OString, sal_Int16>( +// fieldType, reader.getFieldFlags(i)); + properties.insert(StringPairHashMap::value_type(fieldName, + std::pair<rtl::OString, sal_Int16>( + fieldType, reader.getFieldFlags(i)))); + } + } + } + break; + default: + OSL_ASSERT(false); + break; + } +} + +void checkDefaultInterfaces( + std::hash_set< rtl::OString, rtl::OStringHash >& interfaces, + const std::hash_set< rtl::OString, rtl::OStringHash >& services, + const rtl::OString & propertyhelper) +{ + if (services.empty()) { + if (interfaces.find("com.sun.star.lang.XServiceInfo") != interfaces.end()) + interfaces.erase("com.sun.star.lang.XServiceInfo"); + } else { + if (interfaces.find("com.sun.star.lang.XServiceInfo") == interfaces.end()) + interfaces.insert("com.sun.star.lang.XServiceInfo"); + } + + if (propertyhelper.getLength() > 0) { + if (interfaces.find("com.sun.star.beans.XPropertySet") != interfaces.end()) + interfaces.erase("com.sun.star.beans.XPropertySet"); + if (interfaces.find("com.sun.star.beans.XFastPropertySet") != interfaces.end()) + interfaces.erase("com.sun.star.beans.XFastPropertySet"); + if (interfaces.find("com.sun.star.beans.XMultiPropertySet") != interfaces.end()) + interfaces.erase("com.sun.star.beans.XMultiPropertySet"); + } +} + +rtl::OString checkPropertyHelper(TypeManager const & manager, + const std::hash_set< rtl::OString, rtl::OStringHash >& services) +{ + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = + services.begin(); + bool oldStyleWithProperties = false; + while (iter != services.end()) { + typereg::Reader reader(manager.getTypeReader((*iter).replace('.', '/'))); + + if (reader.getSuperTypeCount() > 0) { + typereg::Reader super( + manager.getTypeReader( + codemaker::convertString( + reader.getSuperTypeName(0)))); + if (!super.isValid()) { + throw CannotDumpException( + "Bad type library entity " + + codemaker::convertString( + reader.getSuperTypeName(0))); + } + + if (super.getFieldCount() > 0) + return rtl::OUStringToOString(super.getTypeName().replace('/', '.'), + osl_getThreadTextEncoding()); + } else { + if (reader.getFieldCount() > 0) + oldStyleWithProperties = true; + } + iter++; + } + + return (oldStyleWithProperties ? "_" : ""); +} + + +bool checkXComponentSupport(TypeManager const & manager, + typereg::Reader const & reader) +{ + static rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("com/sun/star/lang/XComponent")); + if (reader.getTypeName().equals(s)) + return true; + + for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) { + typereg::Reader super( + manager.getTypeReader( + codemaker::convertString( + reader.getSuperTypeName(i)))); + if (!super.isValid()) { + throw CannotDumpException( + "Bad type library entity " + + codemaker::convertString( + reader.getSuperTypeName(i))); + } + if (checkXComponentSupport(manager, super)) + return true; + } + + return false; +} + + +// if XComponent is directly specified, return true and remove it from the +// supported interfaces list +bool checkXComponentSupport(TypeManager const & manager, + std::hash_set< rtl::OString, rtl::OStringHash >& interfaces) +{ + if (interfaces.empty()) + return false; + + std::hash_set< rtl::OString, rtl::OStringHash >::const_iterator iter = + interfaces.begin(); + while (iter != interfaces.end()) { + if ((*iter).equals("com.sun.star.lang.XComponent")) { + interfaces.erase("com.sun.star.lang.XComponent"); + return true; + } + typereg::Reader reader(manager.getTypeReader((*iter).replace('.', '/'))); + if (checkXComponentSupport(manager, reader)) + return true; + iter++; + } + + return false; +} + +} + diff --git a/unodevtools/source/skeletonmaker/skeletoncommon.hxx b/unodevtools/source/skeletonmaker/skeletoncommon.hxx new file mode 100644 index 000000000000..895fae0f001d --- /dev/null +++ b/unodevtools/source/skeletonmaker/skeletoncommon.hxx @@ -0,0 +1,99 @@ +/************************************************************************* + * + * $RCSfile: skeletoncommon.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:31:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_DEVTOOLS_SKELETONCOMMON_HXX_ +#define _UNO_DEVTOOLS_SKELETONCOMMON_HXX_ + +#include "skeletonmaker.hxx" + +namespace skeletonmaker { + +codemaker::UnoType::Sort decomposeResolveAndCheck( + TypeManager const & manager, rtl::OString const & type, + bool resolveTypedefs, bool allowVoid, bool allowExtraEntities, + RTTypeClass * typeClass, rtl::OString * name, sal_Int32 * rank, + std::vector< rtl::OString > * arguments); + +void checkType(TypeManager const & manager, + rtl::OString const & type, + std::hash_set< rtl::OString, rtl::OStringHash >& interfaceTypes, + std::hash_set< rtl::OString, rtl::OStringHash >& serviceTypes, + StringPairHashMap& properties, bool& attributes); + +void checkDefaultInterfaces( + std::hash_set< rtl::OString, rtl::OStringHash >& interfaces, + const std::hash_set< rtl::OString, rtl::OStringHash >& services, + const rtl::OString & propertyhelper); + +rtl::OString checkPropertyHelper(TypeManager const & manager, + const std::hash_set< rtl::OString, rtl::OStringHash >& services); + +bool checkXComponentSupport(TypeManager const & manager, + typereg::Reader const & reader); + +// if XComponent is directly specified, return true and remove it from the +// supported interfaces list +bool checkXComponentSupport(TypeManager const & manager, + std::hash_set< rtl::OString, rtl::OStringHash >& interfaces); + +} + +#endif // _UNO_DEVTOOLS_SKELETONCOMMON_HXX_ + diff --git a/unodevtools/source/skeletonmaker/skeletoncpp.hxx b/unodevtools/source/skeletonmaker/skeletoncpp.hxx new file mode 100644 index 000000000000..a74ad470da97 --- /dev/null +++ b/unodevtools/source/skeletonmaker/skeletoncpp.hxx @@ -0,0 +1,169 @@ +/************************************************************************* + * + * $RCSfile: skeletoncpp.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:31:11 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_DEVTOOLS_SKELETONCPP_HXX_ +#define _UNO_DEVTOOLS_SKELETONCPP_HXX_ + +#include "skeletoncommon.hxx" + +namespace skeletonmaker { namespace cpp { + +// referenceType +// 0 = no reference +// 1 = use of css::uno::Reference for interfaces +// 2 = reference (includes css::uno::Reference for interfaces) +// 4 = const reference (includes css::uno::Reference for interfaces) +// 8 = default construction for example for return types, means "return <type>();" +void printType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + codemaker::UnoType::Sort sort, RTTypeClass typeClass, + rtl::OString const & name, sal_Int32 rank, + std::vector< rtl::OString > const & arguments, + short referenceType, bool shortname=false, + bool defaultvalue=false); + +void printType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + rtl::OString const & type, short referenceType, + bool shortname=false, bool defaultvalue=false); + + +bool printConstructorParameters(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader, + typereg::Reader const & outerReader, + std::vector< rtl::OString > const & arguments); + + +void printConstructor(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader, + std::vector< rtl::OString > const & arguments); + + +void printMethodParameters(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader, + sal_uInt16 method, bool previous, + bool withtype, + bool shortname=false); + + +void printExceptionSpecification(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader, + sal_uInt16 method, + bool shortname=false); + + +void printMethods(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, + codemaker::GeneratedTypeSet & generated, + rtl::OString const & delegate, + rtl::OString const & classname=rtl::OString(), + rtl::OString const & indentation=rtl::OString(), + bool shortname=false, bool defaultvalue=false); + + +void printConstructionMethods(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader); + + +void printServiceMembers(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader, + rtl::OString const & type); + + +void printMapsToCppType(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + codemaker::UnoType::Sort sort, + RTTypeClass typeClass, + rtl::OString const & name, + sal_Int32 rank, + std::vector< rtl::OString > const & arguments, + const char * cppTypeSort); + + +void generateDocumentation(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + rtl::OString const & type, + rtl::OString const & delegate); + + +void generateSkeleton(ProgramOptions const & options, + TypeManager const & manager, + std::vector< rtl::OString > const & types, + rtl::OString const & delegate); + +} } + +#endif // _UNO_DEVTOOLS_SKELETONCPP_HXX_ + diff --git a/unodevtools/source/skeletonmaker/skeletonjava.hxx b/unodevtools/source/skeletonmaker/skeletonjava.hxx new file mode 100644 index 000000000000..84001d021618 --- /dev/null +++ b/unodevtools/source/skeletonmaker/skeletonjava.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: skeletonjava.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:31:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_DEVTOOLS_SKELETONJAVA_HXX_ +#define _UNO_DEVTOOLS_SKELETONJAVA_HXX_ + +#include "skeletoncommon.hxx" + +namespace skeletonmaker { namespace java { + +void printType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + codemaker::UnoType::Sort sort, RTTypeClass typeClass, + rtl::OString const & name, sal_Int32 rank, + std::vector< rtl::OString > const & arguments, + bool referenceType, bool defaultvalue=false); + +void printType(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + rtl::OString const & type, bool referenceType, + bool defaultvalue=false); + +bool printConstructorParameters(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader, + typereg::Reader const & outerReader, + std::vector< rtl::OString > const & arguments); + +void printConstructor(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, + std::vector< rtl::OString > const & arguments); + +void printMethodParameters(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader, + sal_uInt16 method, bool previous, + bool withtype, + bool shortname=false); + +void printExceptionSpecification(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader, + sal_uInt16 method); + +void printMethods(std::ostream & o, + ProgramOptions const & options, TypeManager const & manager, + typereg::Reader const & reader, + codemaker::GeneratedTypeSet & generated, + rtl::OString const & delegate, + rtl::OString const & indentation=rtl::OString(), + bool defaultvalue=false); + +void printConstructionMethods(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader); + +void printServiceMembers(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + typereg::Reader const & reader, + rtl::OString const & type); + +void printMapsToJavaType(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + codemaker::UnoType::Sort sort, + RTTypeClass typeClass, + rtl::OString const & name, sal_Int32 rank, + std::vector< rtl::OString > const & arguments, + const char * javaTypeSort); + +void generateDocumentation(std::ostream & o, + ProgramOptions const & options, + TypeManager const & manager, + rtl::OString const & type); + +void generateSkeleton(ProgramOptions const & options, TypeManager const & manager, std::vector< rtl::OString > const & types, rtl::OString const & delegate); + +} } + +#endif // _UNO_DEVTOOLS_SKELETONJAVA_HXX_ + diff --git a/unodevtools/source/skeletonmaker/skeletonmaker.cxx b/unodevtools/source/skeletonmaker/skeletonmaker.cxx new file mode 100644 index 000000000000..88f2707b0bbf --- /dev/null +++ b/unodevtools/source/skeletonmaker/skeletonmaker.cxx @@ -0,0 +1,289 @@ +/************************************************************************* + * + * $RCSfile: skeletonmaker.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:31:46 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "sal/main.h" +#include "rtl/process.h" +#include "rtl/ustrbuf.hxx" +#include "unodevtools/typemanager.hxx" +#include "unodevtools/options.hxx" +#include "skeletonjava.hxx" +#include "skeletoncpp.hxx" + +#include <com/sun/star/uno/Reference.hxx> + +using namespace ::rtl; +using namespace ::skeletonmaker; +using namespace ::unodevtools; +using namespace ::com::sun::star::uno; + +namespace { + +static const char usageText[] = +"\n sub-commands:\n" +" dump dump declarations on stdout (e.g. constructors, methods, type\n" +" mapping for properties)\n" +" or complete method bodies with method forwarding.\n" +" component generates language specific code skeleton files using the\n" +" implementation name as the file and class name\n" +"\n options:\n" +" -env:INIFILENAME=<url> url specifies a URL to an UNO ini|rc file of an\n" +" existing UNO environment (URE, office installation).\n" +" -env:UNO_TYPES=<url> url specifies a binary type library file. It can be\n" +" a space separated list of urls.\n" +" --a list all interface methods, not only the direct\n" +" ones\n" +" --(java4|java5|cpp) select the target language\n" +" --java4 generate output for Java 1.4 or earlier\n" +" --java5 generate output for Java 1.5 or later (is \n" +" currently the default)\n" +" --cpp generate output for C++\n" +" -o <path> path specifies an existing directory where the\n" +" output files are generated, only valid for\n" +" sub-command 'component'.\n" +" -l <file> specifies a binary type library (can be used more\n" +" than once). The type library is integrated as an\n" +" additional type provider in the bootstrapped type\n" +" system.\n" +" -n <name> specifies an implementation name for the component\n" +" (used as classname, filename and package|namespace\n" +" name). In 'dump' mode it is used as classname (e.g.\n" +" \"MyBase::\") to generate method bodies not inline.\n" +" -d <name> specifies a base classname or a delegator.\n" +" In 'dump' mode it is used as a delegator to forward\n" +" methods. It can be used as '<name>::' for base\n" +" forwarding, or '<name>->|.' for composition.\n" +" -t <name> specifies an UNOIDL type name, e.g.\n" +" com.sun.star.text.XText (can be used more than once)\n" +" --v print version number and exit\n" +" --h print this help and exit\n\n" +" Sun Microsystems (R) "; + +void printUsageAndExit(char* programname, char* version) { + std::cerr + << "\n using: " << programname + << " dump [<options>] (-env:INIFILENAME=<url> | \n" + << " -env:UNO_TYPES=<url>) -t <type> ...\n" + << " " << programname + << " component [<options>] (-env:INIFILENAME=<path>\n" + << " | -env:UNO_TYPES=<url>) -n <name> -t <type> ...\n" + << " " << programname << " --v\n" + << " " << programname << " --h\n" + << usageText + << programname << " Version " << version << "\n\n"; + exit(EXIT_FAILURE); +} + +} + +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) +{ + char* version = "0.1"; + char* programname = "uno-skeletonmaker"; + + if (argc <= 1) + printUsageAndExit(programname, version); + + ProgramOptions options; + std::vector< rtl::OUString > registries; + std::vector< rtl::OString > types; + rtl::OString delegate; + + try { + + sal_Int32 nPos = 0; + sal_Int32 nCount = (sal_Int32)rtl_getAppCommandArgCount(); + OUString arg, sOption; + sal_Bool bOption=sal_False; + + // check command + rtl_getAppCommandArg(nPos++, &arg.pData); + if (arg.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("dump")))) { + options.dump = true; + } else if (arg.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("component")))) { + options.dump = false; + } else if (readOption( &bOption, "h", &nPos, arg)) { + printUsageAndExit(programname, version); + } else if (readOption( &bOption, "v", &nPos, arg)) { + std::cerr << "\n Sun Microsystems (R) " << programname + << " Version " << version << "\n\n"; + exit(EXIT_FAILURE); + } else { + std::cerr + << "ERROR: unexpected command \"" + << OUStringToOString(arg, RTL_TEXTENCODING_UTF8).getStr() + << "\"!\n"; + printUsageAndExit(programname, version); + } + + // read up to arguments + while (nPos < nCount) + { + rtl_getAppCommandArg(nPos, &arg.pData); + + if (readOption( &bOption, "a", &nPos, arg)) { + options.all = true; + continue; + } + if (readOption( &bOption, "java4", &nPos, arg)) { + options.java5 = false; + options.language = 1; + continue; + } + if (readOption( &bOption, "java5", &nPos, arg)) { + options.java5 = true; + options.language = 1; + continue; + } + if (readOption( &bOption, "cpp", &nPos, arg)) { + options.java5 = false; + options.language = 2; + continue; + } + if (readOption( &sOption, "d", &nPos, arg)) { + delegate = OUStringToOString(sOption, RTL_TEXTENCODING_UTF8); + continue; + } + if (readOption( &sOption, "n", &nPos, arg)) { + options.implname = OUStringToOString(sOption, RTL_TEXTENCODING_UTF8); + continue; + } + if (readOption( &sOption, "o", &nPos, arg)) { + options.outputpath = OUStringToOString(sOption, RTL_TEXTENCODING_UTF8); + continue; + } + if (readOption( &sOption, "l", &nPos, arg)) { + registries.push_back(sOption); + continue; + } + if (readOption( &sOption, "t", &nPos, arg)) { + types.push_back(OUStringToOString(sOption, RTL_TEXTENCODING_UTF8)); + continue; + } + + // else illegal argument + OUStringBuffer buf( 64 ); + buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("unexpected parameter \"")); + buf.append(arg); + buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("\"!")); + throw RuntimeException(buf.makeStringAndClear(), + Reference< XInterface >()); + } + + if ( types.empty() ) { + std::cerr + << ("\nError: no type is specified, use the -T option at least once\n"); + printUsageAndExit(programname, version); + } + + UnoTypeManager manager; + if (!manager.init(registries)) { + std::cerr + << ("\nError: Using the binary type libraries failed, check the -L" + " options\n"); + exit(EXIT_FAILURE); + } + + if (options.dump) { + std::vector< rtl::OString >::const_iterator iter = types.begin(); + while (iter != types.end()) { + std::cout << "\n/********************************************************************************/\n"; + switch (options.language ) { + case 1: //Java + java::generateDocumentation(std::cout, options, manager, + *iter); + break; + case 2: //C++ + cpp::generateDocumentation(std::cout, options, manager, + *iter, delegate); + break; + default: + OSL_ASSERT(false); + break; + } + ++iter; + } + } else { + switch (options.language ) { + case 1: //Java + java::generateSkeleton(options, manager, types, delegate); + break; + case 2: //C++ + cpp::generateSkeleton(options, manager, types, delegate); + break; + default: + OSL_ASSERT(false); + break; + } + } + + } catch (CannotDumpException & e) { + std::cout.flush(); + std::cerr << "\nError: " << e.m_message << std::endl; + } catch(Exception& e) { + std::cout.flush(); + std::cerr + << "\nError: " + << OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr() + << std::endl; + } + + return 0; +} diff --git a/unodevtools/source/unodevtools/makefile.mk b/unodevtools/source/unodevtools/makefile.mk new file mode 100644 index 000000000000..ae5534ea1791 --- /dev/null +++ b/unodevtools/source/unodevtools/makefile.mk @@ -0,0 +1,85 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: jsc $ $Date: 2005-08-23 08:27:34 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=unodevtools +TARGET=unodevtools + + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# ------------------------------------------------------------------ + +OBJFILES= \ + $(OBJ)$/typemanager.obj \ + $(OBJ)$/typeblob.obj \ + $(OBJ)$/options.obj + +# ------------------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/unodevtools/source/unodevtools/options.cxx b/unodevtools/source/unodevtools/options.cxx new file mode 100644 index 000000000000..051a13ade233 --- /dev/null +++ b/unodevtools/source/unodevtools/options.cxx @@ -0,0 +1,166 @@ +/************************************************************************* + * + * $RCSfile: options.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:26:33 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> + +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/process.h> + +#include <com/sun/star/uno/RuntimeException.hpp> + +using namespace ::rtl; +using namespace ::com::sun::star::uno; + +namespace unodevtools { + +//------------------------------------------------------------------------------- +static void out( const sal_Char * pText ) +{ + fprintf( stderr, pText ); +} + +//------------------------------------------------------------------------------- +static void out( const OUString & rText ) +{ + OString aText( OUStringToOString( rText, RTL_TEXTENCODING_ASCII_US ) ); + fprintf( stderr, aText.getStr() ); +} + +//------------------------------------------------------------------------------- +sal_Bool readOption( OUString * pValue, const sal_Char * pOpt, + sal_Int32 * pnIndex, const OUString & aArg) + throw (RuntimeException) +{ + const OUString dash = OUString(RTL_CONSTASCII_USTRINGPARAM("-")); + if(aArg.indexOf(dash) != 0) + return sal_False; + + OUString aOpt = OUString::createFromAscii( pOpt ); + + if (aArg.getLength() < aOpt.getLength()) + return sal_False; + + if (aOpt.equalsIgnoreAsciiCase( aArg.copy(1) )) + { + // take next argument + ++(*pnIndex); + + rtl_getAppCommandArg(*pnIndex, &pValue->pData); + if (*pnIndex >= (sal_Int32)rtl_getAppCommandArgCount() || pValue->copy(1).equals(dash)) + { + OUStringBuffer buf( 32 ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("incomplete option \"-") ); + buf.appendAscii( pOpt ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" given!") ); + throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); + } + else + { +#if OSL_DEBUG_LEVEL > 1 + out( "\n> identified option -" ); + out( pOpt ); + out( " = " ); + OString tmp = OUStringToOString(*pValue, RTL_TEXTENCODING_ASCII_US); + out( tmp.getStr() ); +#endif + ++(*pnIndex); + return sal_True; + } + } + else if (aArg.indexOf(aOpt) == 1) + { + *pValue = aArg.copy(1 + aOpt.getLength()); +#if OSL_DEBUG_LEVEL > 1 + out( "\n> identified option -" ); + out( pOpt ); + out( " = " ); + OString tmp = OUStringToOString(aArg.copy(aOpt.getLength()), RTL_TEXTENCODING_ASCII_US); + out( tmp.getStr() ); +#endif + ++(*pnIndex); + + return sal_True; + } + return sal_False; +} + +//------------------------------------------------------------------------------- +sal_Bool readOption( sal_Bool * pbOpt, const sal_Char * pOpt, + sal_Int32 * pnIndex, const OUString & aArg) +{ + const OUString dashdash(RTL_CONSTASCII_USTRINGPARAM("--")); + OUString aOpt = OUString::createFromAscii(pOpt); + + if(aArg.indexOf(dashdash) == 0 && aOpt.equalsIgnoreAsciiCase(aArg.copy(2))) + { + ++(*pnIndex); + *pbOpt = sal_True; +#if OSL_DEBUG_LEVEL > 1 + out( "\n> identified option --" ); + out( pOpt ); +#endif + return sal_True; + } + return sal_False; +} + +} // end of namespace unodevtools diff --git a/unodevtools/source/unodevtools/typeblob.cxx b/unodevtools/source/unodevtools/typeblob.cxx new file mode 100644 index 000000000000..6c8df8b7c893 --- /dev/null +++ b/unodevtools/source/unodevtools/typeblob.cxx @@ -0,0 +1,804 @@ +/************************************************************************* + * + * $RCSfile: typeblob.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:26:55 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <rtl/alloc.h> +#include <registry/writer.hxx> + +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/reflection/XPublished.hpp> +#include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp> +#include <com/sun/star/reflection/XSingletonTypeDescription2.hpp> +#include <com/sun/star/reflection/XServiceTypeDescription2.hpp> +#include <com/sun/star/reflection/XStructTypeDescription.hpp> +#include <com/sun/star/reflection/XConstantsTypeDescription.hpp> +#include <com/sun/star/reflection/XConstantTypeDescription.hpp> +#include <com/sun/star/reflection/XModuleTypeDescription.hpp> +#include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp> +#include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp> +#include <com/sun/star/reflection/XMethodParameter.hpp> +#include <com/sun/star/reflection/XCompoundTypeDescription.hpp> +#include <com/sun/star/reflection/XIndirectTypeDescription.hpp> +#include <com/sun/star/reflection/XEnumTypeDescription.hpp> + +#include <codemaker/generatedtypeset.hxx> + +using namespace com::sun::star::uno; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace com::sun::star::reflection; +using namespace rtl; +using namespace codemaker; + +namespace unodevtools { + +void writeConstantData(typereg::Writer& rWriter, sal_uInt16 fieldIndex, + const Reference< XConstantTypeDescription >& xConstant) + +{ + RTConstValue constValue; + OUString uConstTypeName; + OUString uConstName = xConstant->getName(); + Any aConstantAny = xConstant->getConstantValue(); + + switch ( aConstantAny.getValueTypeClass() ) + { + case TypeClass_BOOLEAN: + { + uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("boolean")); + constValue.m_type = RT_TYPE_BOOL; + aConstantAny >>= constValue.m_value.aBool; + } + break; + case TypeClass_BYTE: + { + uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("byte")); + constValue.m_type = RT_TYPE_BYTE; + aConstantAny >>= constValue.m_value.aByte; + } + break; + case TypeClass_SHORT: + { + uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("short")); + constValue.m_type = RT_TYPE_INT16; + aConstantAny >>= constValue.m_value.aShort; + } + break; + case TypeClass_UNSIGNED_SHORT: + { + uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("unsigned short")); + constValue.m_type = RT_TYPE_UINT16; + aConstantAny >>= constValue.m_value.aUShort; + } + break; + case TypeClass_LONG: + { + uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("long")); + constValue.m_type = RT_TYPE_INT32; + aConstantAny >>= constValue.m_value.aLong; + } + break; + case TypeClass_UNSIGNED_LONG: + { + uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("unsigned long")); + constValue.m_type = RT_TYPE_UINT32; + aConstantAny >>= constValue.m_value.aULong; + } + break; + case TypeClass_FLOAT: + { + uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("float")); + constValue.m_type = RT_TYPE_FLOAT; + aConstantAny >>= constValue.m_value.aFloat; + } + break; + case TypeClass_DOUBLE: + { + uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("double")); + constValue.m_type = RT_TYPE_DOUBLE; + aConstantAny >>= constValue.m_value.aDouble; + } + break; + case TypeClass_STRING: + { + uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("string")); + constValue.m_type = RT_TYPE_STRING; + constValue.m_value.aString = ((OUString*)aConstantAny.getValue())->getStr(); + } + break; + } + + rWriter.setFieldData(fieldIndex, OUString(), OUString(), RT_ACCESS_CONST, + uConstName, uConstTypeName, constValue); +} + +sal_uInt32 getInheritedMemberCount( + GeneratedTypeSet& checkedTypes, + Sequence< Reference< XTypeDescription > >& superTypes) +{ + sal_uInt32 memberCount = 0; + + sal_uInt16 count = (sal_uInt16)superTypes.getLength(); + OString name; + for (sal_uInt16 i=0; i < count; i++) { + name = OString(OUStringToOString(superTypes[i]->getName(), + RTL_TEXTENCODING_UTF8)); + if (!checkedTypes.contains(name)) { + checkedTypes.add(name); + + Reference< XInterfaceTypeDescription2 > xIFace( + superTypes[i], UNO_QUERY); + + Sequence< Reference< XTypeDescription> > baseTypes = + xIFace->getBaseTypes(); + if ( baseTypes.getLength() > 0) + memberCount += getInheritedMemberCount(checkedTypes, + baseTypes); + + memberCount += xIFace->getMembers().getLength(); + } + } + + return memberCount; +} + +void writeMethodData( typereg::Writer& rWriter, sal_uInt32 calculatedMemberOffset, + const Reference< XInterfaceMethodTypeDescription >& xMethod ) +{ + RTMethodMode methodMode = RT_MODE_TWOWAY; + if ( xMethod->isOneway() ) + { + methodMode = RT_MODE_ONEWAY; + } + + Sequence< Reference< XMethodParameter > > parameters(xMethod->getParameters()); + Sequence< Reference< XTypeDescription > > exceptions(xMethod->getExceptions()); + sal_uInt16 methodIndex = (sal_uInt16)(xMethod->getPosition() + - calculatedMemberOffset); + sal_uInt16 paramCount = (sal_uInt16)parameters.getLength(); + sal_uInt16 exceptionCount = (sal_uInt16)exceptions.getLength(); + + rWriter.setMethodData(methodIndex, OUString(), methodMode, + xMethod->getMemberName(), + xMethod->getReturnType()->getName().replace('.', '/'), + paramCount, exceptionCount); + + RTParamMode paramMode = RT_PARAM_IN; + sal_uInt16 i; + + for ( i=0; i < paramCount; i++) + { + Reference< XMethodParameter > xParam = parameters[i]; + if ( xParam->isIn() && xParam->isOut()) + { + paramMode = RT_PARAM_INOUT; + } else + if ( xParam->isIn() ) + { + paramMode = RT_PARAM_IN; + } else + if ( xParam->isOut() ) + { + paramMode = RT_PARAM_OUT; + } + + rWriter.setMethodParameterData(methodIndex, + (sal_uInt16)xParam->getPosition(), + paramMode, xParam->getName(), + xParam->getType()-> + getName().replace('.', '/')); + } + + for (i=0; i < exceptionCount; i++) + { + rWriter.setMethodExceptionTypeName( + methodIndex, i, exceptions[i]->getName().replace('.', '/')); + } +} + +RTFieldAccess checkParameterizedTypeFlag(const Sequence< OUString >& typeParams, + const OUString & memberType) +{ + for (sal_uInt16 i=0; i < typeParams.getLength(); i++) { + if (typeParams[i].equals(memberType)) + return RT_ACCESS_PARAMETERIZED_TYPE; + } + + return RT_ACCESS_READWRITE; +} + +RTFieldAccess checkPropertyFlags(short flags) { + RTFieldAccess propertyFlags=RT_ACCESS_INVALID; + switch(flags) { + case PropertyAttribute::MAYBEVOID: + propertyFlags |= RT_ACCESS_MAYBEVOID; + case PropertyAttribute::BOUND: + propertyFlags |= RT_ACCESS_BOUND; + case PropertyAttribute::CONSTRAINED: + propertyFlags |= RT_ACCESS_CONSTRAINED; + case PropertyAttribute::TRANSIENT: + propertyFlags |= RT_ACCESS_TRANSIENT; + case PropertyAttribute::READONLY : + propertyFlags |= RT_ACCESS_READONLY; + case PropertyAttribute::MAYBEAMBIGUOUS: + propertyFlags |= RT_ACCESS_MAYBEAMBIGUOUS; + case PropertyAttribute::MAYBEDEFAULT: + propertyFlags |= RT_ACCESS_MAYBEDEFAULT; + case PropertyAttribute::REMOVEABLE: + propertyFlags |= RT_ACCESS_REMOVEABLE; + case PropertyAttribute::OPTIONAL: + propertyFlags |= RT_ACCESS_OPTIONAL; + } + return propertyFlags; +} + +void* getTypeBlob(Reference< XHierarchicalNameAccess > xTDmgr, + const OString& typeName, sal_uInt32* blobsize) +{ + if ( typeName.getLength() == 0 ) + return NULL; + + OUString uTypeName(OStringToOUString(typeName, RTL_TEXTENCODING_UTF8) + .replace('/', '.')); + + Any aTypeAny( xTDmgr->getByHierarchicalName( uTypeName ) ); + + if ( !aTypeAny.hasValue() ) + return NULL; + + Reference< XTypeDescription > xType; + aTypeAny >>= xType; + + if ( !xType.is() ) + return NULL; + + Reference< XPublished > xPublished(xType, UNO_QUERY); + void* pBlob = NULL; + switch (xType->getTypeClass()) + { + case TypeClass_CONSTANTS: + { + Reference< XConstantsTypeDescription > xCFace(xType, UNO_QUERY); + + if ( !xCFace.is() ) + return NULL; + + Sequence< Reference< XConstantTypeDescription > > constTypes( + xCFace->getConstants()); + sal_uInt16 constCount = (sal_uInt16)constTypes.getLength(); + + typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(), + RT_TYPE_CONSTANTS, xPublished->isPublished(), + uTypeName.replace('.', '/'), + 0, constCount, 0, 0); + + for (sal_uInt16 i=0; i < constCount; i++) + writeConstantData(writer, i, constTypes[i]); + + const void* p = writer.getBlob(blobsize); + pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize); + rtl_copyMemory(pBlob, p, *blobsize); + } + break; + case TypeClass_MODULE: + { + Reference< XModuleTypeDescription > xMFace(xType, UNO_QUERY); + + if ( !xMFace.is() ) + return NULL; + + Sequence< Reference< XTypeDescription > > memberTypes( + xMFace->getMembers()); + + sal_uInt16 memberCount = (sal_uInt16)memberTypes.getLength(); + sal_uInt16 constCount = 0; + sal_Int16 i; + + for ( i=0; i < memberCount; i++) + { + if ( TypeClass_CONSTANT == memberTypes[i]->getTypeClass() ) + constCount++; + } + + typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(), + RT_TYPE_MODULE, xPublished->isPublished(), + uTypeName.replace('.', '/'), + 0, constCount, 0, 0); + + if ( 0 < constCount ) + { + Reference< XConstantTypeDescription > xConst; + sal_uInt16 fieldIndex = 0; + for (i=0; i < memberCount; i++) + { + if ( TypeClass_CONSTANT == memberTypes[i]->getTypeClass() ) + { + xConst = Reference< XConstantTypeDescription >( + memberTypes[i], UNO_QUERY); + + writeConstantData(writer, ++fieldIndex, xConst); + } + } + } + + const void* p = writer.getBlob(blobsize); + pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize); + rtl_copyMemory(pBlob, p, *blobsize); + } + break; + case TypeClass_INTERFACE: + { + Reference< XInterfaceTypeDescription2 > xIFace(xType, UNO_QUERY); + + if ( !xIFace.is() ) + return NULL; + + Reference< XInterfaceAttributeTypeDescription2 > xAttr; + Reference< XInterfaceMethodTypeDescription > xMethod; + Sequence< Reference< XInterfaceMemberTypeDescription > > memberTypes( + xIFace->getMembers()); + Sequence< Reference< XTypeDescription > > baseTypes = + xIFace->getBaseTypes(); + Sequence< Reference< XTypeDescription > > optBaseTypes = + xIFace->getOptionalBaseTypes(); + + sal_uInt16 baseCount = (sal_uInt16)baseTypes.getLength(); + sal_uInt16 optBaseCount = (sal_uInt16)optBaseTypes.getLength(); + sal_uInt16 memberCount = (sal_uInt16)memberTypes.getLength(); + sal_uInt16 attrCount = 0; + sal_uInt16 inheritedMemberCount = 0; + sal_uInt16 i; + + for (i=0; i < memberCount; i++) + { + xAttr = Reference< XInterfaceAttributeTypeDescription2 >( + memberTypes[i], UNO_QUERY); + if ( xAttr.is() ) + attrCount++; + } + + // check inherited members count + if (baseCount > 0) + { + GeneratedTypeSet checkedTypes; + inheritedMemberCount = (sal_uInt16)getInheritedMemberCount( + checkedTypes, baseTypes ); + } + + typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(), + RT_TYPE_INTERFACE, xPublished->isPublished(), + uTypeName.replace('.', '/'), + baseCount, attrCount, memberCount-attrCount, + (sal_uInt16)optBaseTypes.getLength()); + + // set super types + for (i=0; i < baseCount; i++) { + writer.setSuperTypeName(i, baseTypes[i]-> + getName().replace('.', '/')); + } + + // set optional super types + RTReferenceType referenceType = RT_REF_SUPPORTS; + RTFieldAccess fieldAccess = RT_ACCESS_OPTIONAL; + for (i=0; i < optBaseCount; i++) { + writer.setReferenceData(i, OUString(), referenceType, + fieldAccess, optBaseTypes[i]-> + getName().replace('.', '/')); + } + + fieldAccess = RT_ACCESS_READWRITE; + // reset attrCount, used for method index calculation + attrCount = 0; + for (i=0; i < memberCount; i++) + { + xAttr = Reference< XInterfaceAttributeTypeDescription2 >( + memberTypes[i], UNO_QUERY); + if ( xAttr.is() ) + { + ++attrCount; + if (xAttr->isReadOnly()) + fieldAccess = RT_ACCESS_READONLY; + else + fieldAccess = RT_ACCESS_READWRITE; + + if (xAttr->isBound()) + fieldAccess |= RT_ACCESS_BOUND; + + + writer.setFieldData((sal_uInt16)memberTypes[i]->getPosition() + - inheritedMemberCount, + OUString(), OUString(), fieldAccess, + memberTypes[i]->getMemberName(), + xAttr->getType()->getName().replace('.','/'), + RTConstValue()); + continue; + } + + xMethod = Reference< XInterfaceMethodTypeDescription >( + memberTypes[i], UNO_QUERY); + if ( xMethod.is() ) + { + writeMethodData(writer, attrCount+inheritedMemberCount, + xMethod); + } + } + + const void* p = writer.getBlob(blobsize); + pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize); + rtl_copyMemory(pBlob, p, *blobsize); + } + break; + case TypeClass_STRUCT: + { + Reference< XStructTypeDescription > xStruct(xType, UNO_QUERY); + + if ( !xStruct.is() ) + return NULL; + + if ( xStruct->getTypeArguments().getLength() > 0) + return NULL; + + + Sequence< OUString > typeParams( xStruct->getTypeParameters()); + Sequence< OUString > memberNames( xStruct->getMemberNames()); + Sequence< Reference< XTypeDescription > > memberTypes( + xStruct->getMemberTypes()); + sal_uInt16 memberCount = (sal_uInt16)memberNames.getLength(); + + OUString uSuperType; + sal_uInt16 superCount=0; + if ( typeParams.getLength() == 0) { + Reference< XTypeDescription > xSuperType = xStruct->getBaseType(); + if ( xSuperType.is() ) + { + ++superCount; + uSuperType = xSuperType->getName().replace('.','/'); + } + } + typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(), + RT_TYPE_STRUCT, xPublished->isPublished(), + uTypeName.replace('.', '/'), + superCount, memberCount, 0, + (sal_uInt16)typeParams.getLength()); + + sal_uInt16 i=0; + for (i=0; i < memberCount; i++) + { + RTFieldAccess fieldAccess = RT_ACCESS_READWRITE; + if (typeParams.getLength() > 0) + fieldAccess |= checkParameterizedTypeFlag( + typeParams, memberTypes[i]->getName()); + + writer.setFieldData(i, OUString(), OUString(), fieldAccess, + memberNames[i], + memberTypes[i]->getName().replace('.', '/'), + RTConstValue()); + } + + for (i=0; i < typeParams.getLength(); i++) + { + writer.setReferenceData(i, OUString(), RT_REF_TYPE_PARAMETER, + RT_ACCESS_INVALID, typeParams[i]); + } + + const void* p = writer.getBlob(blobsize); + pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize); + rtl_copyMemory(pBlob, p, *blobsize); + } + break; + case TypeClass_EXCEPTION: + { + Reference< XCompoundTypeDescription > xComp(xType, UNO_QUERY); + + if ( !xComp.is() ) + return NULL; + + Sequence< OUString > memberNames( xComp->getMemberNames()); + Sequence< Reference< XTypeDescription > > memberTypes( + xComp->getMemberTypes()); + sal_uInt16 memberCount = (sal_uInt16)memberNames.getLength(); + + OUString uSuperType; + sal_uInt16 superCount=0; + Reference< XTypeDescription > xSuperType = xComp->getBaseType(); + if ( xSuperType.is() ) + { + ++superCount; + uSuperType = xSuperType->getName().replace('.','/'); + } + + typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(), + RT_TYPE_EXCEPTION, xPublished->isPublished(), + uTypeName.replace('.', '/'), + superCount, memberCount, 0, 0); + + for (sal_Int16 i=0; i < memberCount; i++) + { + writer.setFieldData(i, OUString(), OUString(), RT_ACCESS_READWRITE, + memberNames[i], + memberTypes[i]->getName().replace('.', '/'), + RTConstValue()); + } + + const void* p = writer.getBlob(blobsize); + pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize); + rtl_copyMemory(pBlob, p, *blobsize); + } + break; + case TypeClass_ENUM: + { + Reference< XEnumTypeDescription > xEnum(xType, UNO_QUERY); + + if ( !xEnum.is() ) + return NULL; + + Sequence< OUString > enumNames( xEnum->getEnumNames()); + Sequence< sal_Int32 > enumValues( xEnum->getEnumValues()); + sal_uInt16 enumCount = (sal_uInt16)enumNames.getLength(); + + typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(), + RT_TYPE_ENUM, xPublished->isPublished(), + uTypeName.replace('.', '/'), + 0, enumCount, 0, 0); + + RTConstValue constValue; + for (sal_Int16 i=0; i < enumCount; i++) + { + constValue.m_type = RT_TYPE_INT32; + constValue.m_value.aLong = enumValues[i]; + + writer.setFieldData(i, OUString(), OUString(), + RT_ACCESS_CONST, enumNames[i], + OUString(), constValue); + } + + const void* p = writer.getBlob(blobsize); + pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize); + rtl_copyMemory(pBlob, p, *blobsize); + } + break; + case TypeClass_TYPEDEF: + { + Reference< XIndirectTypeDescription > xTD(xType, UNO_QUERY); + + if ( !xTD.is() ) + return NULL; + + typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(), + RT_TYPE_TYPEDEF, xPublished->isPublished(), + uTypeName.replace('.', '/'), + 0, 0, 0, 0); + + writer.setSuperTypeName(0, xTD->getReferencedType() + ->getName().replace('.','/')); + + const void* p = writer.getBlob(blobsize); + pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize); + rtl_copyMemory(pBlob, p, *blobsize); + } + break; + case TypeClass_SERVICE: + { + Reference< XServiceTypeDescription2 > xService(xType, UNO_QUERY); + + if ( !xService.is() ) + return NULL; + + Sequence<Reference<XServiceConstructorDescription> > constructors( + xService->getConstructors()); + Sequence<Reference<XPropertyTypeDescription> > properties; + Sequence<Reference<XServiceTypeDescription> > mandatoryServices; + Sequence<Reference<XServiceTypeDescription> > optionalServices; + Sequence<Reference<XInterfaceTypeDescription> > mandatoryInterfaces; + Sequence<Reference<XInterfaceTypeDescription> > optionalInterfaces; + sal_uInt16 methodCount = (sal_uInt16)constructors.getLength(); + sal_uInt16 referenceCount = 0; + sal_uInt16 propertyCount = 0; + + if ( !xService->isSingleInterfaceBased() ) { + mandatoryServices = xService->getMandatoryServices(); + optionalServices = xService->getOptionalServices(); + mandatoryInterfaces = xService->getMandatoryInterfaces(); + optionalInterfaces = xService->getOptionalInterfaces(); + properties = xService->getProperties(); + referenceCount = (sal_uInt16)( + mandatoryServices.getLength()+ + optionalServices.getLength()+ + mandatoryInterfaces.getLength()+ + optionalInterfaces.getLength()); + propertyCount = (sal_uInt16)properties.getLength(); + } + + typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(), + RT_TYPE_SERVICE, xPublished->isPublished(), + uTypeName.replace('.', '/'), + (xService->isSingleInterfaceBased() ? 1 : 0), + propertyCount, methodCount, referenceCount); + + sal_uInt16 i=0; + if ( xService->isSingleInterfaceBased() ) { + writer.setSuperTypeName(0, xService->getInterface() + ->getName().replace('.','/')); + + sal_uInt16 j=0; + for (i=0; i<methodCount; i++) { + Reference<XServiceConstructorDescription> xConstructor( + constructors[i], UNO_QUERY); + Sequence<Reference<XParameter> > parameters; + Sequence<Reference<XCompoundTypeDescription> > exceptions; + sal_uInt16 parameterCount=0; + sal_uInt16 exceptionCount=0; + if (!xConstructor->isDefaultConstructor()) { + parameters = xConstructor->getParameters(); + parameterCount = (sal_uInt16)parameters.getLength(); + } + + writer.setMethodData(i, OUString(), RT_MODE_TWOWAY, + xConstructor->getName(), + OUString( + RTL_CONSTASCII_USTRINGPARAM("void")), + parameterCount, exceptionCount); + + if (!xConstructor->isDefaultConstructor()) { + for (j=0; j<parameterCount; j++) { + Reference<XParameter> xParam(parameters[j], UNO_QUERY); + RTParamMode paramMode = RT_PARAM_IN; + if (xParam->isRestParameter()) + paramMode = RT_PARAM_REST; + + writer.setMethodParameterData( + i, (sal_uInt16)xParam->getPosition(), + paramMode, xParam->getName(), + xParam->getType()->getName().replace('.', '/')); + } + + for (j=0; j<exceptionCount; j++) { + Reference<XCompoundTypeDescription> xExcp( + exceptions[j], UNO_QUERY); + + writer.setMethodExceptionTypeName( + i, j, xExcp->getName().replace('.', '/')); + } + } + } + } else { + for (i=0; i<propertyCount; i++) { + Reference<XPropertyTypeDescription> xProp( + properties[i], UNO_QUERY); + + RTFieldAccess propertyFlags = checkPropertyFlags( + xProp->getPropertyFlags()); + + writer.setFieldData(i, OUString(), OUString(), + propertyFlags, + xProp->getName().copy(xProp->getName().lastIndexOf('.')+1), + xProp->getPropertyTypeDescription() + ->getName().replace('.', '/'), + RTConstValue()); + } + + sal_uInt16 refIndex = 0; + sal_uInt16 length = (sal_uInt16)mandatoryServices.getLength(); + for (i=0; i < length; i++) { + writer.setReferenceData(refIndex++, OUString(), + RT_REF_EXPORTS, RT_ACCESS_INVALID, + mandatoryServices[i]->getName() + .replace('.', '/')); + } + length = (sal_uInt16)optionalServices.getLength(); + for (i=0; i < length; i++) { + writer.setReferenceData(refIndex++, OUString(), + RT_REF_EXPORTS, RT_ACCESS_OPTIONAL, + optionalServices[i]->getName() + .replace('.', '/')); + } + length = (sal_uInt16)mandatoryInterfaces.getLength(); + for (i=0; i < length; i++) { + writer.setReferenceData(refIndex++, OUString(), + RT_REF_SUPPORTS, RT_ACCESS_INVALID, + mandatoryInterfaces[i]->getName() + .replace('.', '/')); + } + length = (sal_uInt16)optionalInterfaces.getLength(); + for (i=0; i < length; i++) { + writer.setReferenceData(refIndex++, OUString(), + RT_REF_SUPPORTS, RT_ACCESS_OPTIONAL, + optionalInterfaces[i]->getName() + .replace('.', '/')); + } + } + + const void* p = writer.getBlob(blobsize); + pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize); + rtl_copyMemory(pBlob, p, *blobsize); + } + break; + case TypeClass_SINGLETON: + { + Reference<XSingletonTypeDescription2> xSingleton(xType, UNO_QUERY); + + if ( !xSingleton.is() ) + return NULL; + + typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(), + RT_TYPE_SINGLETON, xPublished->isPublished(), + uTypeName.replace('.', '/'), + 1, 0, 0, 0); + + if (xSingleton->isInterfaceBased()) { + writer.setSuperTypeName(0, xSingleton->getInterface() + ->getName().replace('.','/')); + } else { + writer.setSuperTypeName(0, xSingleton->getService() + ->getName().replace('.','/')); + } + + const void* p = writer.getBlob(blobsize); + pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize); + rtl_copyMemory(pBlob, p, *blobsize); + } + break; + } + + return pBlob; +} + +} // end of namespace unodevtools diff --git a/unodevtools/source/unodevtools/typemanager.cxx b/unodevtools/source/unodevtools/typemanager.cxx new file mode 100644 index 000000000000..b20fececb3d7 --- /dev/null +++ b/unodevtools/source/unodevtools/typemanager.cxx @@ -0,0 +1,399 @@ +/************************************************************************* + * + * $RCSfile: typemanager.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jsc $ $Date: 2005-08-23 08:26:44 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#include "unodevtools/typemanager.hxx" + +#include <rtl/alloc.h> +#include <registry/reader.hxx> +//#include <registry/version.h> +#include <cppuhelper/bootstrap.hxx> + +#include <com/sun/star/container/XSet.hpp> +#include <com/sun/star/reflection/XTypeDescription.hpp> + +using namespace ::rtl; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::reflection; + +namespace unodevtools { + +static RTTypeClass mapTypeClass(TypeClass typeclass) { + switch(typeclass) { + case TypeClass_ENUM: + return RT_TYPE_ENUM; + break; + case TypeClass_TYPEDEF: + return RT_TYPE_TYPEDEF; + break; + case TypeClass_STRUCT: + return RT_TYPE_STRUCT; + break; + case TypeClass_UNION: + return RT_TYPE_UNION; + break; + case TypeClass_EXCEPTION: + return RT_TYPE_EXCEPTION; + break; + case TypeClass_INTERFACE: + return RT_TYPE_INTERFACE; + break; + case TypeClass_SERVICE: + return RT_TYPE_SERVICE; + break; + case TypeClass_MODULE: + return RT_TYPE_MODULE; + break; + case TypeClass_CONSTANTS: + return RT_TYPE_CONSTANTS; + break; + case TypeClass_SINGLETON: + return RT_TYPE_SINGLETON; + break; + } + return RT_TYPE_INVALID; +} + + +// TypeManager::TypeManager() +// { +// m_pImpl = new TypeManagerImpl(); +// acquire(); +// } + +// TypeManager::~TypeManager() +// { +// release(); +// } + +// sal_Int32 TypeManager::acquire() +// { +// return osl_incrementInterlockedCount(&m_pImpl->m_refCount); +// } + +// sal_Int32 TypeManager::release() +// { +// sal_Int32 refCount = 0; +// if (0 == (refCount = osl_decrementInterlockedCount(&m_pImpl->m_refCount)) ) +// { +// delete m_pImpl; +// } +// return refCount;; +// } + +// sal_Bool TypeManager::isBaseType(const ::rtl::OString& name) +// { +// if ( name.equals(OString("short")) ) +// return sal_True; +// if ( name.equals(OString("unsigned short")) ) +// return sal_True; +// if ( name.equals(OString("long")) ) +// return sal_True; +// if ( name.equals(OString("unsigned long")) ) +// return sal_True; +// if ( name.equals(OString("hyper")) ) +// return sal_True; +// if ( name.equals(OString("unsigned hyper")) ) +// return sal_True; +// if ( name.equals(OString("string")) ) +// return sal_True; +// if ( name.equals(OString("boolean")) ) +// return sal_True; +// if ( name.equals(OString("char")) ) +// return sal_True; +// if ( name.equals(OString("byte")) ) +// return sal_True; +// if ( name.equals(OString("any")) ) +// return sal_True; +// if ( name.equals(OString("type")) ) +// return sal_True; +// if ( name.equals(OString("float")) ) +// return sal_True; +// if ( name.equals(OString("double")) ) +// return sal_True; +// if ( name.equals(OString("void")) ) +// return sal_True; + +// return sal_False; +// } + +UnoTypeManager::UnoTypeManager() +{ + m_pImpl = new UnoTypeManagerImpl(); + acquire(); +} + +UnoTypeManager::~UnoTypeManager() +{ + release(); +} + +void UnoTypeManager::release() +{ + if (0 == TypeManager::release()) + delete m_pImpl; +} + +sal_Bool UnoTypeManager::init( + const ::std::vector< ::rtl::OUString > registries) +{ + Reference< XComponentContext > xContext= + defaultBootstrap_InitialComponentContext(); + + if ( !xContext.is() ) { + OUString msg(RTL_CONSTASCII_USTRINGPARAM( + "internal UNO problem, can't create initial UNO component context")); + throw RuntimeException( msg, Reference< XInterface >()); + } + Any a = xContext->getValueByName( + OUString(RTL_CONSTASCII_USTRINGPARAM( + "/singletons/com.sun.star.reflection.theTypeDescriptionManager"))); + + a >>= m_pImpl->m_tdmgr; + + if ( !m_pImpl->m_tdmgr.is() ) { + OUString msg(RTL_CONSTASCII_USTRINGPARAM( + "internal UNO problem, can't get TypeDescriptionManager")); + throw RuntimeException( msg, Reference< XInterface >()); + } + + if ( !registries.empty() ) { + + Reference< XMultiComponentFactory > xServiceManager( + xContext->getServiceManager() ); + if ( !xServiceManager.is() ) { + OUString msg(RTL_CONSTASCII_USTRINGPARAM( + "internal UNO problem, can't get ServiceManager")); + throw RuntimeException( msg, Reference< XInterface >()); + } + + Sequence<Any> seqArgs(registries.size()); + + std::vector< OUString >::const_iterator iter = registries.begin(); + int i = 0; + while (iter != registries.end()) { + Reference< XSimpleRegistry > xReg( + xServiceManager->createInstanceWithContext( + OUString(RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.registry.SimpleRegistry")), + xContext), UNO_QUERY); + xReg->open(convertToFileUrl( + OUStringToOString(*iter, RTL_TEXTENCODING_UTF8)), + sal_True, sal_False); + + seqArgs[i++] = makeAny(xReg); + iter++; + } + + Reference< XHierarchicalNameAccess > xTDProvider( + xServiceManager->createInstanceWithArgumentsAndContext( + OUString(RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.reflection.TypeDescriptionProvider")), + seqArgs, xContext), + UNO_QUERY); + if ( !xTDProvider.is() ) { + OUString msg(RTL_CONSTASCII_USTRINGPARAM( + "internal UNO problem, can't create type local" + " type description provider")); + throw RuntimeException( msg, Reference< XInterface >()); + } + + a = makeAny(xTDProvider); + Reference< XSet > xSet(m_pImpl->m_tdmgr, UNO_QUERY); + xSet->insert(a); + } + + return sal_True; +} + +sal_Bool UnoTypeManager::isValidType(const ::rtl::OString& name) const +{ + return m_pImpl->m_tdmgr->hasByHierarchicalName( + OStringToOUString(name, RTL_TEXTENCODING_UTF8)); +} + +OString UnoTypeManager::getTypeName(RegistryKey& rTypeKey) const +{ + OString typeName = OUStringToOString(rTypeKey.getName(), RTL_TEXTENCODING_UTF8); + static OString sBase("/UCR"); + if (typeName.indexOf(sBase) == 0) + typeName = typeName.copy(typeName.indexOf('/', 1) + 1); + else + typeName = typeName.copy(1); + + return typeName; +} + +// extern +void* getTypeBlob(Reference< XHierarchicalNameAccess > xTDmgr, + const OString& typeName, sal_uInt32* pBlob); + +typereg::Reader UnoTypeManager::getTypeReader( + const OString& name, sal_Bool * pIsExtraType ) const +{ + typereg::Reader reader; + + void* pBlob = NULL; + sal_uInt32 blobsize = 0; + + if ( (pBlob = getTypeBlob(m_pImpl->m_tdmgr, name, &blobsize)) != NULL ) + { + reader = typereg::Reader(pBlob, blobsize, sal_True, TYPEREG_VERSION_1); + } + + if ( pBlob ) + { + rtl_freeMemory(pBlob); + } + + return reader; +} + +typereg::Reader UnoTypeManager::getTypeReader(RegistryKey& rTypeKey) const +{ + typereg::Reader reader; + + if (rTypeKey.isValid()) + { + RegValueType valueType; + sal_uInt32 valueSize; + + if (!rTypeKey.getValueInfo(OUString(), &valueType, &valueSize)) + { + sal_uInt8* pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize); + if (!rTypeKey.getValue(OUString(), pBuffer)) + { + reader = typereg::Reader( + pBuffer, valueSize, true, TYPEREG_VERSION_1); + } + rtl_freeMemory(pBuffer); + } + } + return reader; +} + + +RTTypeClass UnoTypeManager::getTypeClass(const OString& name) const +{ + if (m_pImpl->m_t2TypeClass.count(name) > 0) + { + return m_pImpl->m_t2TypeClass[name]; + } else + { + Reference< XTypeDescription > xTD; + Any a = m_pImpl->m_tdmgr->getByHierarchicalName( + OStringToOUString(name, RTL_TEXTENCODING_UTF8)); + a >>= xTD; + + if ( xTD.is()) + { + RTTypeClass tc = mapTypeClass(xTD->getTypeClass()); + if (tc != RT_TYPE_INVALID) + m_pImpl->m_t2TypeClass[name] = tc; + return tc; + } + } + + return RT_TYPE_INVALID; +} + +RTTypeClass UnoTypeManager::getTypeClass(RegistryKey& rTypeKey) const +{ + OString name = getTypeName(rTypeKey); + + if (m_pImpl->m_t2TypeClass.count(name) > 0) + { + return m_pImpl->m_t2TypeClass[name]; + } else + { + if (rTypeKey.isValid()) + { + RegValueType valueType; + sal_uInt32 valueSize; + + if (!rTypeKey.getValueInfo(OUString(), &valueType, &valueSize)) + { + sal_uInt8* pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize); + if (!rTypeKey.getValue(OUString(), pBuffer)) + { + typereg::Reader reader( + pBuffer, valueSize, false, TYPEREG_VERSION_1); + + RTTypeClass ret = reader.getTypeClass(); + + rtl_freeMemory(pBuffer); + + m_pImpl->m_t2TypeClass[name] = ret; + return ret; + } + rtl_freeMemory(pBuffer); + } + } + } + + return RT_TYPE_INVALID; +} + +} // end of namespace unodevtools |