diff options
Diffstat (limited to 'rdbmaker/source/rdbmaker')
-rw-r--r-- | rdbmaker/source/rdbmaker/makefile.mk | 63 | ||||
-rw-r--r-- | rdbmaker/source/rdbmaker/rdbmaker.cxx | 508 | ||||
-rw-r--r-- | rdbmaker/source/rdbmaker/rdboptions.cxx | 381 | ||||
-rw-r--r-- | rdbmaker/source/rdbmaker/rdboptions.hxx | 57 | ||||
-rw-r--r-- | rdbmaker/source/rdbmaker/rdbtype.cxx | 195 | ||||
-rw-r--r-- | rdbmaker/source/rdbmaker/rdbtype.hxx | 52 | ||||
-rw-r--r-- | rdbmaker/source/rdbmaker/specialtypemanager.cxx | 101 | ||||
-rw-r--r-- | rdbmaker/source/rdbmaker/specialtypemanager.hxx | 71 | ||||
-rw-r--r-- | rdbmaker/source/rdbmaker/typeblop.cxx | 535 |
9 files changed, 1963 insertions, 0 deletions
diff --git a/rdbmaker/source/rdbmaker/makefile.mk b/rdbmaker/source/rdbmaker/makefile.mk new file mode 100644 index 000000000000..8b41a93b6e7f --- /dev/null +++ b/rdbmaker/source/rdbmaker/makefile.mk @@ -0,0 +1,63 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=codemaker +TARGET=rdbmaker +TARGETTYPE=CUI +LIBTARGET=NO + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- +.INCLUDE : settings.mk + +OBJFILES= $(OBJ)$/rdbmaker.obj \ + $(OBJ)$/rdboptions.obj \ + $(OBJ)$/typeblop.obj \ + $(OBJ)$/specialtypemanager.obj \ + $(OBJ)$/rdbtype.obj + + +APP1TARGET= $(TARGET) + +APP1OBJS= $(OBJFILES) + +APP1STDLIBS=\ + $(SALLIB) \ + $(SALHELPERLIB) \ + $(REGLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) + +APP1LIBS= \ + $(LB)$/codemaker.lib + +APP1RPATH= NONE + +.INCLUDE : target.mk diff --git a/rdbmaker/source/rdbmaker/rdbmaker.cxx b/rdbmaker/source/rdbmaker/rdbmaker.cxx new file mode 100644 index 000000000000..5a4bd498cca2 --- /dev/null +++ b/rdbmaker/source/rdbmaker/rdbmaker.cxx @@ -0,0 +1,508 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <stdio.h> +#include <osl/file.hxx> +#include <osl/process.h> +#include <codemaker/typemanager.hxx> +#include <codemaker/dependency.hxx> + +#ifndef _RTL_OSTRINGBUFFER_HXX_ +#include <rtl/strbuf.hxx> +#endif + +#if defined(SAL_W32) || defined(SAL_OS2) +#include <io.h> +#include <direct.h> +#include <errno.h> +#endif + +#ifdef UNX +#include <stdlib.h> +#include <sys/stat.h> +#include <errno.h> +#include <unistd.h> +#endif + +#include "specialtypemanager.hxx" +#include "rdboptions.hxx" +#include "rdbtype.hxx" + +#define PATH_DELEMITTER '/' + +using namespace rtl; +using namespace osl; + +FileStream listFile; +RegistryKey rootKey; +Registry regFile; +sal_Bool useSpecial; +TypeManager* pTypeMgr = NULL; +StringList dirEntries; +StringSet filterTypes; + +OString getFullNameOfApplicatRdb() +{ + OUString bootReg; + OUString uTmpStr; + if( osl_getExecutableFile(&uTmpStr.pData) == osl_Process_E_None ) + { + sal_uInt32 lastIndex = uTmpStr.lastIndexOf(PATH_DELEMITTER); + OUString tmpReg; + + if ( lastIndex > 0 ) + { + tmpReg =uTmpStr.copy(0, lastIndex + 1); + } + + tmpReg += OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb") ); + + FileBase::getSystemPathFromFileURL(tmpReg, bootReg); + } + + return OUStringToOString(bootReg, RTL_TEXTENCODING_ASCII_US); +} + +void initFilterTypes(RdbOptions* pOptions) +{ + if (pOptions->isValid("-FT")) + { + OString fOption(pOptions->getOption("-FT")); + sal_Int32 nIndex = 0; + do + { + filterTypes.insert( fOption.getToken( 0, ';', nIndex ).replace('.', '/') ); + } + while ( nIndex >= 0 ); + } + if (pOptions->isValid("-F")) + { + FILE *f = fopen(pOptions->getOption("-F").getStr(), "r"); + + if (f) + { + sal_Char buffer[1024+1]; + sal_Char *pBuf = fgets(buffer, 1024, f); + sal_Char *s = NULL; + sal_Char *p = NULL; + while ( pBuf && !feof(f)) + { + p = pBuf; + if (*p != '\n' && *p != '\r') + { + while (*p == ' ' && *p =='\t') + p++; + + s = p; + while (*p != '\n' && *p != '\r' && *p != ' ' && *p != '\t') + p++; + + *p = '\0'; + filterTypes.insert( OString(s).replace('.', '/') ); + } + + pBuf = fgets(buffer, 1024, f); + } + + fclose(f); + } + } +} + +sal_Bool checkFilterTypes(const OString& type) +{ + StringSet::iterator iter = filterTypes.begin(); + while ( iter != filterTypes.end() ) + { + if ( type.indexOf( *iter ) == 0 ) + { + return sal_True; + } + + iter++; + } + + return sal_False; +} + +void cleanUp( sal_Bool bError) +{ + if ( pTypeMgr ) + { + delete pTypeMgr; + } + if (useSpecial) + { + pTypeMgr = new SpecialTypeManager(); + }else + { + pTypeMgr = new RegistryTypeManager(); + } + + if ( rootKey.isValid() ) + { + rootKey.closeKey(); + } + if ( regFile.isValid() ) + { + if ( bError ) + { + regFile.destroy(OUString()); + } else + { + regFile.close(); + } + } + if ( listFile.isValid() ) + { + listFile.close(); + unlink(listFile.getName().getStr()); + } + + StringList::reverse_iterator iter = dirEntries.rbegin(); + while ( iter != dirEntries.rend() ) + { + if (rmdir((char*)(*iter).getStr()) == -1) + { + break; + } + + iter++; + } +} + +OString createFileName(const OString& path) +{ + OString fileName(path); + + sal_Char token; +#ifdef SAL_UNX + fileName = fileName.replace('\\', '/'); + token = '/'; +#else + fileName = fileName.replace('/', '\\'); + token = '\\'; +#endif + + OStringBuffer nameBuffer( path.getLength() ); + + sal_Int32 nIndex = 0; + do + { + nameBuffer.append(fileName.getToken( 0, token, nIndex ).getStr()); + if ( nIndex == -1 ) break; + + if (nameBuffer.getLength() == 0 || OString(".") == nameBuffer.getStr()) + { + nameBuffer.append(token); + continue; + } + +#if defined(SAL_UNX) || defined(SAL_OS2) + if (mkdir((char*)nameBuffer.getStr(), 0777) == -1) +#else + if (mkdir((char*)nameBuffer.getStr()) == -1) +#endif + { + if ( errno == ENOENT ) + return OString(); + } else + { + dirEntries.push_back(nameBuffer.getStr()); + } + + nameBuffer.append(token); + } + while ( nIndex >= 0 ); + + return fileName; +} + +sal_Bool produceAllTypes(const OString& typeName, + TypeManager& typeMgr, + TypeDependency& typeDependencies, + RdbOptions* pOptions, + sal_Bool bFullScope, + FileStream& o, + RegistryKey& regKey, + StringSet& filterTypes2) + throw( CannotDumpException ) +{ + if (!produceType(typeName, typeMgr, typeDependencies, pOptions, o, regKey, filterTypes2)) + { + fprintf(stderr, "%s ERROR: %s\n", + pOptions->getProgramName().getStr(), + OString("cannot dump Type '" + typeName + "'").getStr()); + cleanUp(sal_True); + exit(99); + } + + RegistryKey typeKey = typeMgr.getTypeKey(typeName); + RegistryKeyNames subKeys; + + if (typeKey.getKeyNames(OUString(), subKeys)) + return sal_False; + + OString tmpName; + for (sal_uInt32 i=0; i < subKeys.getLength(); i++) + { + tmpName = OUStringToOString(subKeys.getElement(i), RTL_TEXTENCODING_UTF8); + + if (pOptions->isValid("-B")) + tmpName = tmpName.copy(tmpName.indexOf('/', 1) + 1); + else + tmpName = tmpName.copy(1); + + if (bFullScope) + { + if (!produceAllTypes(tmpName, typeMgr, typeDependencies, pOptions, sal_True, + o, regKey, filterTypes2)) + return sal_False; + } else + { + if (!produceType(tmpName, typeMgr, typeDependencies, pOptions, o, regKey, filterTypes2)) + return sal_False; + } + } + + return sal_True; +} + + +#if (defined UNX) || (defined OS2) +int main( int argc, char * argv[] ) +#else +int _cdecl main( int argc, char * argv[] ) +#endif +{ + RdbOptions options; + + try + { + if (!options.initOptions(argc, argv)) + { + cleanUp(sal_True); + exit(1); + } + } + catch( IllegalArgument& e) + { + fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr()); + cleanUp(sal_True); + exit(99); + } + + TypeDependency typeDependencies; + + OString bootReg; + + if ( options.isValid("-R") ) + { + bootReg = options.getOption("-R"); + } else + { + if (options.getInputFiles().empty()) + { + bootReg = getFullNameOfApplicatRdb(); + } + } + + if ( bootReg.getLength() ) + { + pTypeMgr = new SpecialTypeManager(); + useSpecial = sal_True; + } else + { + pTypeMgr = new RegistryTypeManager(); + useSpecial = sal_False; + } + + TypeManager& typeMgr = *pTypeMgr; + + if ( useSpecial && !typeMgr.init( bootReg ) ) + { + fprintf(stderr, "%s : init typemanager failed, check your environment for bootstrapping uno.\n", options.getProgramName().getStr()); + cleanUp(sal_True); + exit(99); + } + if ( !useSpecial && !typeMgr.init(!options.isValid("-T"), options.getInputFiles())) + { + fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr()); + cleanUp(sal_True); + exit(99); + } + + initFilterTypes(&options); + + if (options.isValid("-B")) + { + typeMgr.setBase(options.getOption("-B")); + } + + if ( !options.isValid("-O") ) + { + fprintf(stderr, "%s ERROR: %s\n", + options.getProgramName().getStr(), + "no output file is specified."); + cleanUp(sal_True); + exit(99); + } + + if ( options.generateTypeList() ) + { + OString fileName = createFileName( options.getOption("-O") ); + listFile.open(fileName); + + if ( !listFile.isValid() ) + { + fprintf(stderr, "%s ERROR: %s\n", + options.getProgramName().getStr(), + "could not open output file."); + cleanUp(sal_True); + exit(99); + } + } else + { + OUString fileName( OStringToOUString(createFileName( options.getOption("-O") ), RTL_TEXTENCODING_UTF8) ); + if ( regFile.create(fileName) ) + { + fprintf(stderr, "%s ERROR: %s\n", + options.getProgramName().getStr(), + "could not create registry output file."); + cleanUp(sal_True); + exit(99); + } + + + if (options.isValid("-b")) + { + RegistryKey tmpKey; + regFile.openRootKey(tmpKey); + + tmpKey.createKey( OStringToOUString(options.getOption("-b"), RTL_TEXTENCODING_UTF8), rootKey); + } else + { + regFile.openRootKey(rootKey); + } + } + + try + { + if (options.isValid("-T")) + { + OString tOption(options.getOption("-T")); + OString typeName, tmpName; + sal_Bool ret = sal_False; + sal_Int32 nIndex = 0; + do + { + typeName = tOption.getToken( 0, ';', nIndex); + sal_Int32 lastIndex = typeName.lastIndexOf('.'); + tmpName = typeName.copy( lastIndex+1 ); + if (tmpName == "*") + { + if (bootReg.getLength()) + { + fprintf(stderr, "%s ERROR: %s\n", + options.getProgramName().getStr(), + "dumping all types of a scope is not possible if -R option is used."); + exit(99); + } + // produce this type and his scope, but the scope is not recursively generated. + if (typeName.equals("*")) + { + tmpName = "/"; + } else + { + tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/'); + if (tmpName.getLength() == 0) + tmpName = "/"; + else + tmpName.replace('.', '/'); + } + ret = produceAllTypes(tmpName, typeMgr, typeDependencies, &options, sal_False, + listFile, rootKey, filterTypes); + } else + { + // produce only this type + ret = produceType(typeName.replace('.', '/'), typeMgr, typeDependencies, + &options, listFile, rootKey, filterTypes); + } +/* + // produce only this type + ret = produceType(typeName.replace('.', '/'), typeMgr, typeDependencies, + &options, listFile, rootKey, filterTypes); +*/ + if (!ret) + { + fprintf(stderr, "%s ERROR: %s\n", + options.getProgramName().getStr(), + OString("cannot dump Type '" + typeName + "'").getStr()); + cleanUp(sal_True); + exit(99); + } + } + while ( nIndex >= 0 ); + } else + if (options.isValid("-X")) + { + } else + { + if (!bootReg.getLength()) + { + // produce all types + if (!produceAllTypes("/", typeMgr, typeDependencies, &options, sal_True, + listFile, rootKey, filterTypes)) + { + fprintf(stderr, "%s ERROR: %s\n", + options.getProgramName().getStr(), + "an error occurs while dumping all types."); + exit(99); + } + } else + { + fprintf(stderr, "%s ERROR: %s\n", + options.getProgramName().getStr(), + "dumping all types is not possible if -R option is used."); + exit(99); + } + } + } + catch( CannotDumpException& e) + { + fprintf(stderr, "%s ERROR: %s\n", + options.getProgramName().getStr(), + e.m_message.getStr()); + cleanUp(sal_True); + exit(99); + } + + cleanUp(sal_False); + return 0; +} + + diff --git a/rdbmaker/source/rdbmaker/rdboptions.cxx b/rdbmaker/source/rdbmaker/rdboptions.cxx new file mode 100644 index 000000000000..c70424bb7b25 --- /dev/null +++ b/rdbmaker/source/rdbmaker/rdboptions.cxx @@ -0,0 +1,381 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <stdio.h> +#include <string.h> + +#include "rdboptions.hxx" + +using namespace rtl; + +sal_Bool RdbOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile) + throw( IllegalArgument ) +{ + sal_Bool ret = sal_True; + sal_uInt16 i=0; + + if (!bCmdFile) + { + bCmdFile = sal_True; + + m_program = av[0]; + + if (ac < 2) + { + fprintf(stderr, "%s", prepareHelp().getStr()); + ret = sal_False; + } + + i = 1; + } else + { + i = 0; + } + + char *s=NULL; + for (; i < ac; i++) + { + if (av[i][0] == '-') + { + switch (av[i][1]) + { + case 'O': + if (av[i][2] == '\0') + { + if (i < ac - 1 && av[i+1][0] != '-') + { + i++; + s = av[i]; + } else + { + OString tmp("'-O', please check"); + if (i <= ac - 1) + { + tmp += " your input '" + OString(av[i+1]) + "'"; + } + + throw IllegalArgument(tmp); + } + } else + { + s = av[i] + 2; + } + + m_options["-O"] = OString(s); + break; + case 'X': + if (av[i][2] == '\0') + { + if (i < ac - 1 && av[i+1][0] != '-') + { + i++; + s = av[i]; + } else + { + OString tmp("'-X', please check"); + if (i <= ac - 1) + { + tmp += " your input '" + OString(av[i+1]) + "'"; + } + + throw IllegalArgument(tmp); + } + } else + { + s = av[i] + 2; + } + + m_options["-X"] = OString(s); + break; + case 'R': + if (av[i][2] == '\0') + { + if (i < ac - 1 && av[i+1][0] != '-') + { + i++; + s = av[i]; + } else + { + OString tmp("'-R', please check"); + if (i <= ac - 1) + { + tmp += " your input '" + OString(av[i+1]) + "'"; + } + + throw IllegalArgument(tmp); + } + } else + { + s = av[i] + 2; + } + + m_options["-R"] = OString(s); + break; + case 'B': + if (av[i][2] == '\0') + { + if (i < ac - 1 && av[i+1][0] != '-') + { + i++; + s = av[i]; + } else + { + OString tmp("'-B', please check"); + if (i <= ac - 1) + { + tmp += " your input '" + OString(av[i+1]) + "'"; + } + + throw IllegalArgument(tmp); + } + } else + { + s = av[i] + 2; + } + + m_options["-B"] = OString(s); + break; + case 'b': + if (av[i][2] == '\0') + { + if (i < ac - 1 && av[i+1][0] != '-') + { + i++; + s = av[i]; + } else + { + OString tmp("'-b', please check"); + if (i <= ac - 1) + { + tmp += " your input '" + OString(av[i+1]) + "'"; + } + + throw IllegalArgument(tmp); + } + } else + { + s = av[i] + 2; + } + + m_options["-b"] = OString(s); + break; + case 'T': + if (av[i][2] == '\0') + { + if (i < ac - 1 && av[i+1][0] != '-') + { + i++; + s = av[i]; + } else + { + OString tmp("'-T', please check"); + if (i <= ac - 1) + { + tmp += " your input '" + OString(av[i+1]) + "'"; + } + + throw IllegalArgument(tmp); + } + } else + { + s = av[i] + 2; + } + + if (m_options.count("-T") > 0) + { + OString tmp(m_options["-T"]); + tmp = tmp + ";" + s; + m_options["-T"] = tmp; + } else + { + m_options["-T"] = OString(s); + } + break; + case 'F': + if (av[i][2] == 'T') + { + if (av[i][3] == '\0') + { + if (i < ac - 1 && av[i+1][0] != '-') + { + i++; + s = av[i]; + } else + { + OString tmp("'-FT', please check"); + if (i <= ac - 1) + { + tmp += " your input '" + OString(av[i+1]) + "'"; + } + + throw IllegalArgument(tmp); + } + } else + { + s = av[i] + 3; + } + + if (m_options.count("-FT") > 0) + { + OString tmp(m_options["-FT"]); + tmp = tmp + ";" + s; + m_options["-FT"] = tmp; + } else + { + m_options["-FT"] = OString(s); + } + } else + { + if (av[i][2] == '\0') + { + if (i < ac - 1 && av[i+1][0] != '-') + { + i++; + s = av[i]; + } else + { + OString tmp("'-F', please check"); + if (i <= ac - 1) + { + tmp += " your input '" + OString(av[i+1]) + "'"; + } + + throw IllegalArgument(tmp); + } + } else + { + s = av[i] + 2; + } + + m_options["-F"] = OString(s); + } + break; + case 'L': + if (av[i][2] != '\0') + { + OString tmp("'-L', please check"); + if (i <= ac - 1) + { + tmp += " your input '" + OString(av[i+1]) + "'"; + } + + throw IllegalArgument(tmp); + } + + m_options["-L"] = OString(); + m_generateTypeList = sal_True; + break; + default: + throw IllegalArgument("the option is unknown" + OString(av[i])); + } + } else + { + if (av[i][0] == '@') + { + FILE* cmdFile = fopen(av[i]+1, "r"); + if( cmdFile == NULL ) + { + fprintf(stderr, "%s", prepareHelp().getStr()); + ret = sal_False; + } else + { + int rargc=0; + char* rargv[512]; + char buffer[512]; + + while ( fscanf(cmdFile, "%s", buffer) != EOF ) + { + rargv[rargc]= strdup(buffer); + rargc++; + } + fclose(cmdFile); + + ret = initOptions(rargc, rargv, bCmdFile); + + for (long j=0; j < rargc; j++) + { + free(rargv[j]); + } + } + } else + { + m_inputFiles.push_back(av[i]); + } + } + } + + return ret; +} + +OString RdbOptions::prepareHelp() +{ + OString help("\nusing: "); + help += m_program + " [-options] (-R<regname> | file_1 [... file_n])\n"; + help += "The rdbmaker supports 2 modes:\n"; + help += " 1. using the internal UNO type description manager -> use -R<regname>\n" + " where regname specifies the type library used by the UNO type description manager\n" + " after UNO is bootstrapped. This option disables the use of any other type libraries.\n" + " The tpye library must be a valid product type library which means that all types are\n" + " stored under the global base node UCR (Uno Core Reflection data).\n"; + help += " 2. using one or more type library files -> use file_1 ... file_n\n" + " file_1 .. file_n specifies one or more valid type library files which are used to\n" + " find the needed type information. The used type libraries have to support the same base\n" + " node (-B option).\n"; + help += "Options:\n"; + help += " -O<filename> = filename specifies the name of the generated registry\n"; + help += " or text file.\n"; + help += " -L = specifies that only a text file is generated with the\n"; + help += " names of the specified types and their dependencies.\n"; + help += " Default is that a registry file will be created\n"; +// help += " -X<xmlfile> = xmlfile specifies the name of an xml description where\n"; +// help += " all types are specified which will be generated.\n"; + help += " -T<name> = name specifies a type or a list of types. The output for\n"; + help += " [t1;...] this type is generated.\n"; + help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"; + help += " -FT<name> = name specifies a type or a list of types. For this types\n"; + help += " [t1;...] nothing will be generated.\n"; + help += " |F<file> = file specifies an text file. For the specified types in\n" ; + help += " this file nothing will be generated.\n"; + help += " -B<name> = name specifies the base node. All types are searched under\n"; + help += " this node. Default is the root '/' of the registry files.\n"; + help += " This option takes effect using run mode 2 only.\n"; + help += " -b<name> = name specifies the base node of the output registry. All\n"; + help += " types will be generated under this node. Default is the\n"; + help += " root '/' of the registry file.\n"; + help += prepareVersion(); + + return help; +} + +OString RdbOptions::prepareVersion() +{ + OString version("\nSun Microsystems (R) "); + version += m_program + " Version 2.0\n\n"; + + return version; +} + + diff --git a/rdbmaker/source/rdbmaker/rdboptions.hxx b/rdbmaker/source/rdbmaker/rdboptions.hxx new file mode 100644 index 000000000000..533dc6187197 --- /dev/null +++ b/rdbmaker/source/rdbmaker/rdboptions.hxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _RDBMAKER_RDBOPTIONS_HXX_ +#define _RDBMAKER_RDBOPTIONS_HXX_ + +#include <codemaker/options.hxx> + +class RdbOptions : public Options +{ +public: + RdbOptions() + : Options() + , m_generateTypeList(sal_False) + {} + + ~RdbOptions() {} + + sal_Bool initOptions(int ac, char* av[], sal_Bool bCmdFile=sal_False) + throw( IllegalArgument ); + + ::rtl::OString prepareHelp(); + + ::rtl::OString prepareVersion(); + + sal_Bool generateTypeList() + { return m_generateTypeList; } + +protected: + sal_Bool m_generateTypeList; +}; + +#endif // _RDBMAKER_RDBOPTIONS_HXX_ diff --git a/rdbmaker/source/rdbmaker/rdbtype.cxx b/rdbmaker/source/rdbmaker/rdbtype.cxx new file mode 100644 index 000000000000..5bfd27be21af --- /dev/null +++ b/rdbmaker/source/rdbmaker/rdbtype.cxx @@ -0,0 +1,195 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <stdio.h> +#include <rtl/alloc.h> +#include <rtl/ustring.hxx> +#include <rtl/strbuf.hxx> + +#include "rdbtype.hxx" +#include "rdboptions.hxx" + +using namespace rtl; + +sal_Bool isBaseType(const OString& type) +{ + if ( type.equals("long") || + type.equals("short") || + type.equals("hyper") || + type.equals("string") || + type.equals("boolean") || + type.equals("char") || + type.equals("byte") || + type.equals("any") || + type.equals("type") || + type.equals("float") || + type.equals("double") || + type.equals("octet") || + type.equals("void") || + type.equals("unsigned long") || + type.equals("unsigned short") || + type.equals("unsigned hyper") ) + return sal_True; + + return sal_False; +} + +sal_Bool produceDependedTypes(const OString& typeName, + TypeManager& typeMgr, + TypeDependency& typeDependencies, + RdbOptions* pOptions, + FileStream& o, + RegistryKey& regKey, + StringSet& filterTypes) + throw( CannotDumpException ) +{ + sal_Bool ret = sal_True; + + TypeUsingSet usingSet(typeDependencies.getDependencies(typeName)); + + TypeUsingSet::const_iterator iter = usingSet.begin(); + OString sTypeName; + sal_Int32 index = 0; + while (iter != usingSet.end()) + { + sTypeName = (*iter).m_type; + if ((index = sTypeName.lastIndexOf(']')) > 0) + sTypeName = sTypeName.copy(index + 1); + + if ( !isBaseType(sTypeName) ) + { + if (!produceType(sTypeName, + typeMgr, + typeDependencies, + pOptions, + o, regKey, + filterTypes, + sal_True)) + { + fprintf(stderr, "%s ERROR: %s\n", + pOptions->getProgramName().getStr(), + OString("cannot dump Type '" + sTypeName + "'").getStr()); + cleanUp(sal_True); + exit(99); + } + } + iter++; + } + + return ret; +} + +//************************************************************************* +// produceType +//************************************************************************* +sal_Bool produceType(const OString& typeName, + TypeManager& typeMgr, + TypeDependency& typeDependencies, + RdbOptions* pOptions, + FileStream& o, + RegistryKey& regKey, + StringSet& filterTypes, + sal_Bool bDepend) + throw( CannotDumpException ) +{ + if (typeDependencies.isGenerated(typeName) ) + return sal_True; +/* + RegistryKey typeKey = typeMgr.getTypeKey(typeName); + + if (!typeKey.isValid()) + return sal_False; +*/ + if( !checkTypeDependencies(typeMgr, typeDependencies, typeName, bDepend)) + return sal_False; + + if ( !checkFilterTypes(typeName) ) + { + if ( pOptions->generateTypeList() ) + { + o << typeName.getStr() << "\n"; + } else + { +/* + RegValueType valueType; + sal_uInt32 valueSize; + + if (typeKey.getValueInfo(OUString(), &valueType, &valueSize)) + { + if (typeName.equals("/")) + return sal_True; + else + return sal_False; + } + + sal_uInt8* pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize); + + if (typeKey.getValue(OUString(), pBuffer)) + { + rtl_freeMemory(pBuffer); + return sal_False; + } +*/ + TypeReader reader = typeMgr.getTypeReader(typeName); + + if (!reader.isValid()) + { + if (typeName.equals("/")) + { + return sal_True; + } else + { + return sal_False; + } + } + RegistryKey typeKey; + if ( regKey.createKey( OStringToOUString(typeName, RTL_TEXTENCODING_UTF8), typeKey) ) + { +// rtl_freeMemory(pBuffer); + return sal_False; + } + + if ( typeKey.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)reader.getBlop(), reader.getBlopSize()) ) +// if ( typeKey.setValue(OUString(), valueType, pBuffer, valueSize) ) + { +// rtl_freeMemory(pBuffer); + return sal_False; + } + +// rtl_freeMemory(pBuffer); + } + } + + typeDependencies.setGenerated(typeName); + sal_Bool ret = produceDependedTypes(typeName, typeMgr, typeDependencies, + pOptions, o, regKey, filterTypes); + + return ret; +} + + + diff --git a/rdbmaker/source/rdbmaker/rdbtype.hxx b/rdbmaker/source/rdbmaker/rdbtype.hxx new file mode 100644 index 000000000000..a6df2266257c --- /dev/null +++ b/rdbmaker/source/rdbmaker/rdbtype.hxx @@ -0,0 +1,52 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _RDBMAKER_RDBTYPE_HXX_ +#define _RDBMAKER_RDBTYPE_HXX_ + +#include <codemaker/typemanager.hxx> +#include <codemaker/dependency.hxx> + +sal_Bool checkFilterTypes(const ::rtl::OString& type); +void cleanUp(sal_Bool); + +class RdbOptions; +class FileStream; +class RegistryKey; + +sal_Bool produceType(const ::rtl::OString& typeName, + TypeManager& typeMgr, + TypeDependency& typeDependencies, + RdbOptions* pOptions, + FileStream& o, + RegistryKey& regKey, + StringSet& filterTypes, + sal_Bool bDepend = sal_False) + throw( CannotDumpException ); + +#endif // _RDBMAKER_RDBTYPE_HXX_ + diff --git a/rdbmaker/source/rdbmaker/specialtypemanager.cxx b/rdbmaker/source/rdbmaker/specialtypemanager.cxx new file mode 100644 index 000000000000..8089e1b8d68d --- /dev/null +++ b/rdbmaker/source/rdbmaker/specialtypemanager.cxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <rtl/alloc.h> + +#include "specialtypemanager.hxx" + +extern "C" +{ +sal_Bool SAL_CALL initTypeMapper( const sal_Char* pRegName ); +sal_uInt32 SAL_CALL getTypeBlop(const sal_Char* pTypeName, sal_uInt8** pBlop); +} + +using namespace rtl; + +SpecialTypeManager::SpecialTypeManager() +{ + m_pImpl = new SpecialTypeManagerImpl(); + acquire(); +} + +SpecialTypeManager::~SpecialTypeManager() +{ + release(); +} + +void SpecialTypeManager::acquire() +{ + TypeManager::acquire(); +} + +void SpecialTypeManager::release() +{ + if (0 == TypeManager::release()) + { + delete m_pImpl; + } +} + +sal_Bool SpecialTypeManager::init(const OString& registryName) +{ + return initTypeMapper( registryName.getStr() ); +} + +TypeReader SpecialTypeManager::getTypeReader(const OString& name) +{ + TypeReader reader; + + sal_uInt8* pBlop = NULL; + sal_uInt32 blopSize = 0; + + if ( (blopSize = getTypeBlop( name.getStr(), &pBlop)) > 0 ) + { + reader = TypeReader(pBlop, blopSize, sal_True); + } + + if ( pBlop ) + { + rtl_freeMemory(pBlop); + } + + return reader; +} + +RTTypeClass SpecialTypeManager::getTypeClass(const OString& name) +{ + if (m_pImpl->m_t2TypeClass.count(name) > 0) + { + return m_pImpl->m_t2TypeClass[name]; + } else + { + } + + return RT_TYPE_INVALID; +} + + diff --git a/rdbmaker/source/rdbmaker/specialtypemanager.hxx b/rdbmaker/source/rdbmaker/specialtypemanager.hxx new file mode 100644 index 000000000000..b363e875b042 --- /dev/null +++ b/rdbmaker/source/rdbmaker/specialtypemanager.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SPECIALTYPEMANAGER_HXX_ +#define _SPECIALTYPEMANAGER_HXX_ + +#include <codemaker/registry.hxx> +#include <codemaker/typemanager.hxx> + + +struct SpecialTypeManagerImpl +{ + T2TypeClassMap m_t2TypeClass; +}; + +class SpecialTypeManager : public TypeManager +{ +public: + SpecialTypeManager(); + ~SpecialTypeManager(); + + SpecialTypeManager( const SpecialTypeManager& value ) + : TypeManager(value) + , m_pImpl( value.m_pImpl ) + { + acquire(); + } + + using TypeManager::init; + sal_Bool init(const ::rtl::OString& registryName); + + sal_Bool isValidType(const ::rtl::OString&) + { return sal_True; } + TypeReader getTypeReader(const ::rtl::OString& name); + RTTypeClass getTypeClass(const ::rtl::OString& name); + + sal_Int32 getSize() { return m_pImpl->m_t2TypeClass.size(); } + +protected: + void acquire(); + void release(); + +protected: + SpecialTypeManagerImpl* m_pImpl; +}; + +#endif // _CODEMAKER_TYPEMANAGER_HXX_ diff --git a/rdbmaker/source/rdbmaker/typeblop.cxx b/rdbmaker/source/rdbmaker/typeblop.cxx new file mode 100644 index 000000000000..0300970567d4 --- /dev/null +++ b/rdbmaker/source/rdbmaker/typeblop.cxx @@ -0,0 +1,535 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <rtl/alloc.h> +#ifndef __REGISTRY_REFLWRIT_HXX__ +#include <registry/reflwrit.hxx> +#endif +#include <cppuhelper/servicefactory.hxx> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/reflection/XInterfaceTypeDescription.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/XInterfaceAttributeTypeDescription.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 <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <codemaker/global.hxx> + +using namespace com::sun::star; +using namespace com::sun::star::uno; +using namespace com::sun::star::reflection; +using namespace com::sun::star::lang; +using namespace com::sun::star::container; +using namespace cppu; +//using namespace osl; +using namespace rtl; + +static Reference< XHierarchicalNameAccess > xNameAccess; + +void writeConstantData( RegistryTypeWriter& 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; + default: + OSL_ASSERT(false); + break; + } + + rWriter.setFieldData(fieldIndex, uConstName, uConstTypeName, OUString(), + OUString(), RT_ACCESS_CONST, constValue); +} + +sal_uInt32 getInheritedMemberCount( Reference< XTypeDescription >& xType ) +{ + sal_uInt32 memberCount = 0; + if ( xType->getTypeClass() == TypeClass_INTERFACE ) + { + Reference< XInterfaceTypeDescription > xIFace(xType, UNO_QUERY); + + if ( !xIFace.is() ) + return memberCount; + + Reference< XTypeDescription > xSuperType = xIFace->getBaseType(); + + if ( xSuperType.is() ) + memberCount = getInheritedMemberCount( xSuperType ); + + memberCount += xIFace->getMembers().getLength(); + } +// } else +// if ( xType->getTypeClass() == TypeClass_Struct || xType->getTypeClass() == TypeClass_Exception ) +// { +// Reference< XCompoundTypeDescription > xComp(xType, UNO_QUERY); +// +// if ( xComp.is() ) +// return membercount; +// +// Reference< XTypeDescription > xSuperType = xComp->getBaseType(); +// +// if ( xSuperType.is() ) +// memberCount = getInheritedMemberCount( xSuperType ); +// +// memberCount += xComp->getMemberNames().getLength(); +// } + + return memberCount; +} + +void writeMethodData( RegistryTypeWriter& rWriter, sal_uInt32 calculatedMemberOffset, + const Reference< XInterfaceMemberTypeDescription >& xMember, + 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)(xMember->getPosition() - calculatedMemberOffset); + sal_uInt16 paramCount = (sal_uInt16)parameters.getLength(); + sal_uInt16 exceptionCount = (sal_uInt16)exceptions.getLength(); + + rWriter.setMethodData(methodIndex, xMember->getMemberName(), + xMethod->getReturnType()->getName().replace('.', '/'), + methodMode, paramCount, exceptionCount, OUString()); + + 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.setParamData(methodIndex, (sal_uInt16)xParam->getPosition(), xParam->getType()->getName().replace('.', '/'), + xParam->getName(), paramMode); + } + + for (i=0; i < exceptionCount; i++) + { + rWriter.setExcData(methodIndex, i, exceptions[i]->getName().replace('.', '/')); + } +} + +extern "C" +{ + +sal_Bool SAL_CALL initTypeMapper( const sal_Char* pRegName ) +{ + try + { + if (!pRegName) + return sal_False; + + Reference< XMultiServiceFactory > xSMgr( createRegistryServiceFactory( convertToFileUrl(pRegName) ) ); + + if ( !xSMgr.is() ) + return sal_False; + + Reference< XHierarchicalNameAccess > xNAccess; + + Reference< beans::XPropertySet > xProps( xSMgr, UNO_QUERY ); + if (xProps.is()) + { + try + { + Reference< XComponentContext > xContext; + if (xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext) + { + xContext->getValueByName( + OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theTypeDescriptionManager") ) ) >>= xNAccess; + } + } + catch (beans::UnknownPropertyException &) + { + } + } + + if ( !xNAccess.is() ) + return sal_False; + + xNameAccess = xNAccess; + } + catch( Exception& ) + { + return sal_False; + } + + return sal_True; +} + +sal_uInt32 SAL_CALL getTypeBlop(const sal_Char* pTypeName, sal_uInt8** pBlop) +{ + sal_uInt32 length = 0; + + if ( !pTypeName ) + return length; + + OUString uTypeName( OUString::createFromAscii(pTypeName).replace('/', '.') ); + try + { + Any aTypeAny( xNameAccess->getByHierarchicalName( uTypeName ) ); + + if ( !aTypeAny.hasValue() ) + return length; + + Reference< XTypeDescription > xType; + aTypeAny >>= xType; + + if ( !xType.is() ) + return length; + + switch (xType->getTypeClass()) + { + case TypeClass_CONSTANTS: + { + Reference< XConstantsTypeDescription > xCFace(xType, UNO_QUERY); + + if ( !xCFace.is() ) + return length; + + Sequence< Reference< XConstantTypeDescription > > constTypes( xCFace->getConstants()); + sal_uInt16 constCount = (sal_uInt16)constTypes.getLength(); + + RegistryTypeWriter writer(RT_TYPE_MODULE, uTypeName.replace('.', '/'), + OUString(), constCount, 0, 0); + + for (sal_uInt16 i=0; i < constCount; i++) + writeConstantData(writer, i, constTypes[i]); + + length = writer.getBlopSize(); + *pBlop = (sal_uInt8*)rtl_allocateMemory( length ); + rtl_copyMemory(*pBlop, writer.getBlop(), length); + } + break; + case TypeClass_MODULE: + { + Reference< XModuleTypeDescription > xMFace(xType, UNO_QUERY); + + if ( !xMFace.is() ) + return length; + + 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++; + } + + RegistryTypeWriter writer(RT_TYPE_MODULE, uTypeName.replace('.', '/'), + OUString(), 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); + } + } + } + + length = writer.getBlopSize(); + *pBlop = (sal_uInt8*)rtl_allocateMemory( length ); + rtl_copyMemory(*pBlop, writer.getBlop(), length); + } + break; + case TypeClass_INTERFACE: + { + Reference< XInterfaceTypeDescription > xIFace(xType, UNO_QUERY); + + if ( !xIFace.is() ) + return length; + + Reference< XInterfaceAttributeTypeDescription > xAttr; + Reference< XInterfaceMethodTypeDescription > xMethod; + Sequence< Reference< XInterfaceMemberTypeDescription > > memberTypes( xIFace->getMembers()); + sal_uInt16 memberCount = (sal_uInt16)memberTypes.getLength(); + sal_uInt16 attrCount = 0; + sal_uInt16 inheritedMemberCount = 0; + sal_Int32 i; + + for ( i=0; i < memberCount; i++) + { + xAttr = Reference< XInterfaceAttributeTypeDescription >(memberTypes[i], UNO_QUERY); + if ( xAttr.is() ) + { + attrCount++; + } + } + + OUString uSuperType; + Reference< XTypeDescription > xSuperType = xIFace->getBaseType(); + if ( xSuperType.is() ) + { + uSuperType = xSuperType->getName().replace('.','/'); + inheritedMemberCount = (sal_uInt16)getInheritedMemberCount( xSuperType ); + } + + RegistryTypeWriter writer(RT_TYPE_INTERFACE, uTypeName.replace('.', '/'), + uSuperType, attrCount, memberCount-attrCount, 0); + + Uik uik = xIFace->getUik(); + RTUik rtUik = { uik.m_Data1, uik.m_Data2, uik.m_Data3, uik.m_Data4, uik.m_Data5 }; + writer.setUik( rtUik ); + + RTFieldAccess attrAccess = RT_ACCESS_READWRITE; + // reset attrCount, used for method index calculation + attrCount = 0; + + for (i=0; i < memberCount; i++) + { + xAttr = Reference< XInterfaceAttributeTypeDescription >(memberTypes[i], UNO_QUERY); + if ( xAttr.is() ) + { + ++attrCount; + if (xAttr->isReadOnly()) + { + attrAccess = RT_ACCESS_READONLY; + } else + { + attrAccess = RT_ACCESS_READWRITE; + } + writer.setFieldData(sal::static_int_cast< sal_uInt16 >(memberTypes[i]->getPosition() - inheritedMemberCount), + memberTypes[i]->getMemberName(), + xAttr->getType()->getName().replace('.', '/'), + OUString(), OUString(), attrAccess); + continue; + } + + xMethod = Reference< XInterfaceMethodTypeDescription >(memberTypes[i], UNO_QUERY); + if ( xMethod.is() ) + { + writeMethodData( writer, attrCount+inheritedMemberCount, memberTypes[i], xMethod ); + } + } + + length = writer.getBlopSize(); + *pBlop = (sal_uInt8*)rtl_allocateMemory( length ); + rtl_copyMemory(*pBlop, writer.getBlop(), length); + } + break; + case TypeClass_STRUCT: + case TypeClass_EXCEPTION: + { + RTTypeClass rtTypeClass = RT_TYPE_STRUCT; + if (xType->getTypeClass() == TypeClass_EXCEPTION) + { + rtTypeClass = RT_TYPE_EXCEPTION; + } +#include <com/sun/star/reflection/XConstantsTypeDescription.hpp> + + Reference< XCompoundTypeDescription > xComp(xType, UNO_QUERY); + + if ( !xComp.is() ) + return length; + + Sequence< OUString > memberNames( xComp->getMemberNames()); + Sequence< Reference< XTypeDescription > > memberTypes( xComp->getMemberTypes()); + sal_uInt16 memberCount = (sal_uInt16)memberNames.getLength(); + + OUString uSuperType; + Reference< XTypeDescription > xSuperType = xComp->getBaseType(); + if ( xSuperType.is() ) + { + uSuperType = xSuperType->getName().replace('.','/'); + } + + RegistryTypeWriter writer(rtTypeClass, uTypeName.replace('.', '/'), + uSuperType, memberCount, 0, 0); + + for (sal_Int16 i=0; i < memberCount; i++) + { + writer.setFieldData(i , memberNames[i], memberTypes[i]->getName().replace('.', '/'), + OUString(), OUString(), RT_ACCESS_READWRITE); + } + + length = writer.getBlopSize(); + *pBlop = (sal_uInt8*)rtl_allocateMemory( length ); + rtl_copyMemory(*pBlop, writer.getBlop(), length); + } + break; + case TypeClass_ENUM: + { + Reference< XEnumTypeDescription > xEnum(xType, UNO_QUERY); + + if ( !xEnum.is() ) + return length; + + Sequence< OUString > enumNames( xEnum->getEnumNames()); + Sequence< sal_Int32 > enumValues( xEnum->getEnumValues()); + sal_uInt16 enumCount = (sal_uInt16)enumNames.getLength(); + + RegistryTypeWriter writer(RT_TYPE_ENUM, uTypeName.replace('.', '/'), + OUString(), 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, enumNames[i], OUString(), OUString(), OUString(), + RT_ACCESS_CONST, constValue); + } + + length = writer.getBlopSize(); + *pBlop = (sal_uInt8*)rtl_allocateMemory( length ); + rtl_copyMemory(*pBlop, writer.getBlop(), length); + } + break; + case TypeClass_TYPEDEF: + { + Reference< XIndirectTypeDescription > xTD(xType, UNO_QUERY); + + if ( !xTD.is() ) + return length; + + RegistryTypeWriter writer(RT_TYPE_TYPEDEF, uTypeName.replace('.', '/'), + xTD->getReferencedType()->getName().replace('.', '/'), + 0, 0, 0); + length = writer.getBlopSize(); + *pBlop = (sal_uInt8*)rtl_allocateMemory( length ); + rtl_copyMemory(*pBlop, writer.getBlop(), length); + } + break; + default: + OSL_ASSERT(false); + break; + } + + } + catch( Exception& ) + { + } + + return length; +} + +} // extern "C" + + + |