Commits

Juergen Schmidt  committed c680d9f

sdk350: i117257: adapt skeletonmaker for passive registration

  • Participants
  • Parent commits 564e24b

Comments (0)

Files changed (4)

File unodevtools/source/skeletonmaker/cppcompskeleton.cxx

     
 }
 
-void generateCompFunctions(std::ostream & o, const OString & nmspace)
+void generateCompFunctions(std::ostream & o, const OString & nmspace, bool activeregistration)
 {
     o << "static ::cppu::ImplementationEntry const entries[] = {\n"
       << "    { &" << nmspace << "::_create,\n      &"
       << "      &::cppu::createSingleComponentFactory, 0, 0 },\n"
       << "    { 0, 0, 0, 0, 0, 0 }\n};\n\n";
 
-    o << "extern \"C\" void SAL_CALL component_getImplementationEnvironment(\n"
+    o << "extern \"C\" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(\n"
       << "    const char ** envTypeName, uno_Environment **)\n{\n"
       << "    *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;\n}\n\n";
 
-    o << "extern \"C\" void * SAL_CALL component_getFactory(\n"
+    o << "extern \"C\" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(\n"
       << "    const char * 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";
+    if (activeregistration) {
+       o << "extern \"C\" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(\n"
+       	 << "    void * serviceManager, void * registryKey)\n{\n"
+      	 << "    return ::cppu::component_writeInfoHelper("
+      	 << "serviceManager, registryKey, entries);\n}\n";
+    }
 }
 
 void generateXPropertySetBodies(std::ostream& o,
     OString compFileName;
     OString tmpFileName;
     std::ostream* pofs = NULL;
-    bool standardout = getOutputStream(options, ".cxx",
-                                       &pofs, compFileName, tmpFileName);
+    bool standardout = false;
+
+    // generate components xml file if necessary
+    if (options.componentsxml) {
+        standardout = getOutputStream(options, ".components",
+				      &pofs, compFileName, tmpFileName);
+    
+	*pofs << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+	      << "<components xmlns=\"http://openoffice.org/2010/uno-components\">\n"
+	      << "  <component loader=\"com.sun.star.loader.SharedLibrary\" uri=\"%URI_TO_COMPONENT_LIB%\">\n";
+
+	*pofs << "    <implementation name=\"" << options.implname << "\">\n";
+	std::hash_set< OString, OStringHash >::const_iterator iter = services.begin();
+	while (iter != services.end())
+	{
+	    *pofs << "      <service name=\"" << (*iter).replace('/','.') << "\"/>\n";
+	    iter++;
+	} 
+
+	*pofs << "    </implementation>\n  </component>\n<components>\n";
+
+	if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) {
+	    ((std::ofstream*)pofs)->close();
+            delete pofs;
+            OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, sal_False));
+        }
+	return;
+    }
+
+    standardout = getOutputStream(options, ".cxx",
+				  &pofs, compFileName, tmpFileName);
 
     try {
         if (!standardout && options.license) {
         generateQueryInterface(*pofs, options, manager, interfaces, parentname,
                                classname, propertyhelper);
         
-		generateMethodBodies(*pofs, options, manager, interfaces, classname,
+	generateMethodBodies(*pofs, options, manager, interfaces, classname,
                              nmspace, propertyhelper);
 
         if (serviceobject) {
             
             generateCompHelperDefinition(*pofs, options.implname,
                                          classname, services);
-            generateCompFunctions(*pofs, nmspace);
+            generateCompFunctions(*pofs, nmspace, options.activeregistration);
         } else {
             // close namepsace
             for (short i=0; i < nm; i++)
         generateQueryInterface(*pofs, options, manager, interfaces, parentname,
                                classname, propertyhelper);
         
-		generateMethodBodies(*pofs, options, manager, interfaces, classname,
+	generateMethodBodies(*pofs, options, manager, interfaces, classname,
                              nmspace, propertyhelper);
         
         // close namepsace
         generateCompHelperDefinition(*pofs, options.implname, classname,
                                      services);
         
-        generateCompFunctions(*pofs, nmspace);
+        generateCompFunctions(*pofs, nmspace, options.activeregistration);
         
         if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) {
             ((std::ofstream*)pofs)->close();

File unodevtools/source/skeletonmaker/javacompskeleton.cxx

 //     }
 }
 
-void generateCompFunctions(std::ostream & o, const OString & classname)
+void generateCompFunctions(std::ostream & o, const OString & classname, bool activeregistration)
 {
     o << "    public static XSingleComponentFactory __getComponentFactory("
         " String sImplementationName ) {\n"
       << 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";   
+    if (activeregistration) {
+       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)
     }
 
     if (!services.empty())
-        generateCompFunctions(o, classname);
+        generateCompFunctions(o, classname, options.activeregistration);
     
     generateMethodBodies(o, options, manager, interfaces,
                          "    ", propertyhelper.getLength() > 1); 
     OString compFileName;
     OString tmpFileName;
     std::ostream* pofs = NULL;
-    bool standardout = getOutputStream(options, ".java",
-                                       &pofs, compFileName, tmpFileName);
+    bool standardout = false;
+
+    // generate components xml file if necessary
+    if (options.componentsxml) {
+        standardout = getOutputStream(options, ".components",
+				      &pofs, compFileName, tmpFileName);
+    
+	*pofs << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+	      << "<components xmlns=\"http://openoffice.org/2010/uno-components\">\n"
+	      << "  <component loader=\"com.sun.star.loader.Java2\" uri=\"%URI_TO_COMPONENT_JAR%\">\n";
+
+	*pofs << "    <implementation name=\"" << options.implname << "\">\n";
+	std::hash_set< OString, OStringHash >::const_iterator iter = services.begin();
+	while (iter != services.end())
+	{
+	    *pofs << "      <service name=\"" << (*iter).replace('/','.') << "\"/>\n";
+	    iter++;
+	} 
+
+	*pofs << "    </implementation>\n  </component>\n<components>\n";
+
+	if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) {
+	    ((std::ofstream*)pofs)->close();
+            delete pofs;
+            OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, sal_False));
+        }
+	return;
+    }
+
+    standardout = getOutputStream(options, ".java",
+				  &pofs, compFileName, tmpFileName);
 
     try {
         if (!standardout && options.license) {

File unodevtools/source/skeletonmaker/skeletoncommon.hxx

 struct ProgramOptions {
     ProgramOptions(): java5(true), all(false), dump(false), license(false),
                       shortnames(false), supportpropertysetmixin(false),
-                      backwardcompatible(false), language(1), componenttype(1) {}
+                      backwardcompatible(false), activeregistration(false),
+                      componentsxml(false), language(1), componenttype(1), implname("ComponentImpl") {}
 
     bool java5;
     bool all;
     bool shortnames;
     bool supportpropertysetmixin;
     bool backwardcompatible;
+    bool activeregistration;
+    bool componentsxml;
     // language specifier - is extendable
     // 1 = Java
     // 2 = C++

File unodevtools/source/skeletonmaker/skeletonmaker.cxx

 "                           add-in as well. Default is a minimal add-in component\n"
 "                           skeleton based on the configuration coming with the\n"
 "                           office since OO.org 2.0.4.\n"
+"    --active-registration  the generated skeleton implements the former used method\n"
+"                           component_writeInfo to support active component\n"
+"                           registration before OO.org 3.4.\n"
+"    --components-xml       a template components xml snippet is generated that can\n"
+"                           be used for the passive component registration (e.g. in\n"
+"                           an oxt package). Passive component registration is\n"
+"                           supported since OO.org 3.4.\n"
 "    -o <path>              path specifies an existing directory where the\n"
 "                           output files are generated to, only valid for\n"
 "                           sub-command 'component'. If path=stdout the generated\n"
 "                           (used as classname, filename and package|namespace\n"
 "                           name). In 'dump' mode it is used as classname (e.g.\n"
 "                           \"MyBase::\", C++ only) to generate method bodies not\n"
-"                           inline.\n"
+"                           inline. If not specified, the default is \"ComponentImpl\"\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"
 "                           command names, where the commands are a ',' separated list\n"
 "                           of unique commands. This option is only valid for add-ons.\n"
 "    -V, --version          print version number and exit\n"
-"    -h, --help             print this help and exit\n\n"
-" Sun Microsystems (R) ";
+  "    -h, --help             print this help and exit\n\n";
 
 void printUsageAndExit(const char* programname, const char* version)
 {
 
 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, /*argv*/)
 {
-    const char* version = "0.4";
+    const char* version = "0.5";
     const char* programname = "uno-skeletonmaker";
 
     if ( argc <= 1 ) {
 
     try {
         
-	sal_Int32 nPos = 0;
-    sal_Int32 nCount = (sal_Int32)rtl_getAppCommandArgCount();
-    OUString arg, sOption;
-    sal_Bool bOption=sal_False;
+		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;
+		    options.shortnames = true;
+		} else if ( arg.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("calc-add-in"))) ) {
+		    options.dump = false;
+		    options.shortnames = true;
+		    options.componenttype = 2;
+		} else if ( arg.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("add-on"))) ) {
+		    options.dump = false;
+		    options.shortnames = true;
+		    options.componenttype = 3;
+		} else if ( readOption( &bOption, "h", &nPos, arg) ||
+					readOption( &bOption, "help", &nPos, arg) ) {
+		    printUsageAndExit(programname, version);
+		    exit(EXIT_SUCCESS);
+		} else if ( readOption( &bOption, "V", &nPos, arg) ||
+					readOption( &bOption, "version", &nPos, arg) ) {
+		    std::cerr << "\n " << programname
+					  << " Version " << version << "\n\n";
+			exit(EXIT_SUCCESS);
+		} else {
+		    std::cerr << "ERROR: unexpected command \""
+					  << OUStringToOString(arg, RTL_TEXTENCODING_UTF8).getStr()
+					  << "\"!\n";
+			printUsageAndExit(programname, version);
+			exit(EXIT_FAILURE);
+		}
+	
+		// read up to arguments
+		while ( nPos < nCount )
+		{
+			rtl_getAppCommandArg(nPos, &arg.pData);
 
-    // 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;
-        options.shortnames = true;
-    } else if ( arg.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("calc-add-in"))) ) {
-        options.dump = false;
-        options.shortnames = true;
-        options.componenttype = 2;
-    } else if ( arg.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("add-on"))) ) {
-        options.dump = false;
-        options.shortnames = true;
-        options.componenttype = 3;
-	} else if ( readOption( &bOption, "h", &nPos, arg) ||
-                readOption( &bOption, "help", &nPos, arg) ) {
-		printUsageAndExit(programname, version);
-        exit(EXIT_SUCCESS);
-    } else if ( readOption( &bOption, "V", &nPos, arg) ||
-                readOption( &bOption, "version", &nPos, arg) ) {
-        std::cerr << "\n Sun Microsystems (R) " << programname
-                  << " Version " << version << "\n\n";
-        exit(EXIT_SUCCESS);
-    } else {
-        std::cerr
-            << "ERROR: unexpected command \""
-            << OUStringToOString(arg, RTL_TEXTENCODING_UTF8).getStr()
-            << "\"!\n";
-        printUsageAndExit(programname, version);
-        exit(EXIT_FAILURE);
-    }
+			if ( readOption( &bOption, "a", &nPos, arg) ||
+				 readOption( &bOption, "all", &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( &bOption, "sn", &nPos, arg) ||
+				 readOption( &bOption, "shortnames", &nPos, arg) ) {
+			    options.shortnames = true;
+				continue;
+			}        
+			if ( readOption( &bOption, "lh", &nPos, arg) ||
+				 readOption( &bOption, "licenseheader", &nPos, arg) ) {
+			    options.license = true;
+				continue;
+			}        
+			if ( readOption( &bOption, "bc", &nPos, arg) ||
+				 readOption( &bOption, "backward-compatible", &nPos, arg) ) {
+			    options.backwardcompatible = true;
+				continue;
+			}        
+			if ( readOption( &bOption, "active-registration", &nPos, arg) ) {
+			    options.activeregistration = true;
+				continue;
+			}
+			if ( readOption( &bOption, "components-xml", &nPos, arg) ) {
+			    options.componentsxml = true;
+				continue;
+			}
+			if ( readOption( &bOption, "propertysetmixin", &nPos, arg) ) {
+			    options.supportpropertysetmixin = true;
+				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;
+			}
+			if ( readOption( &sOption, "p", &nPos, arg) ) {
+			    OString sTmp(OUStringToOString(sOption, RTL_TEXTENCODING_UTF8));
+				sal_Int32 nIndex= sTmp.indexOf(':');
+				OString sPrt = sTmp.copy(0, nIndex+1);
+				OString sCmds = sTmp.copy(nIndex+1);
+			   
+				nIndex = 0;
+				std::vector< OString > vCmds;
+				do {
+				    OString sCmd = sCmds.getToken( 0, ',', nIndex );
+					vCmds.push_back(sCmd);
+				} while ( nIndex >= 0 );
+
+				options.protocolCmdMap.insert(ProtocolCmdMap::value_type(sPrt, vCmds));            
+				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() && options.componenttype != 3) {
+		    std::cerr
+			  << ("\nError: no type is specified, use the -T option at least once\n");
+			printUsageAndExit(programname, version);        
+			exit(EXIT_FAILURE);
+		}
     
-    // read up to arguments
-    while ( nPos < nCount )
-    {
-        rtl_getAppCommandArg(nPos, &arg.pData);
+		UnoTypeManager manager;
+		if ( !manager.init(registries) ) {
+		    std::cerr
+			  << ("\nError: Using the binary type libraries failed, check the -L"
+				  " options\n");
+			exit(EXIT_FAILURE);
+		}
 
-        if ( readOption( &bOption, "a", &nPos, arg) ||
-             readOption( &bOption, "all", &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( &bOption, "sn", &nPos, arg) ||
-             readOption( &bOption, "shortnames", &nPos, arg) ) {
-            options.shortnames = true;
-            continue;
-        }        
-        if ( readOption( &bOption, "lh", &nPos, arg) ||
-             readOption( &bOption, "licenseheader", &nPos, arg) ) {
-            options.license = true;
-            continue;
-        }        
-        if ( readOption( &bOption, "bc", &nPos, arg) ||
-             readOption( &bOption, "backward-compatible", &nPos, arg) ) {
-            options.backwardcompatible = true;
-            continue;
-        }        
-        if ( readOption( &bOption, "propertysetmixin", &nPos, arg) ) {
-            options.supportpropertysetmixin = true;
-            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;
-        }
-        if ( readOption( &sOption, "p", &nPos, arg) ) {
-            OString sTmp(OUStringToOString(sOption, RTL_TEXTENCODING_UTF8));
-            sal_Int32 nIndex= sTmp.indexOf(':');
-            OString sPrt = sTmp.copy(0, nIndex+1);
-            OString sCmds = sTmp.copy(nIndex+1);
-
-            nIndex = 0;
-            std::vector< OString > vCmds;
-            do {
-                OString sCmd = sCmds.getToken( 0, ',', nIndex );
-                vCmds.push_back(sCmd);
-            } while ( nIndex >= 0 );
-
-            options.protocolCmdMap.insert(ProtocolCmdMap::value_type(sPrt, vCmds));            
-            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() && options.componenttype != 3) {
-        std::cerr
-            << ("\nError: no type is specified, use the -T option at least once\n");
-        printUsageAndExit(programname, version);        
-        exit(EXIT_FAILURE);
-    }
-    
-    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< 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, delegate);
-                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;
-        }
-    }
+		if ( options.dump ) {
+		    std::vector< 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, delegate);
+			    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();