1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <cppuhelper/factory.hxx>
25 
26 #include "MyProtocolHandler.h"
27 #include "MyListener.h"
28 
29 namespace css = ::com::sun::star;
30 
31 #if 0
32 static void writeInfo(const css::uno::Reference< css::registry::XRegistryKey >& xRegistryKey       ,
33                       const char*                                               pImplementationName,
34                       const char*                                               pServiceName       )
35 {
36     ::rtl::OUStringBuffer sKey(256);
37 	sKey.append     (::rtl::OUString::createFromAscii(pImplementationName));
38     sKey.appendAscii("/UNO/SERVICES/");
39     sKey.append     (::rtl::OUString::createFromAscii(pServiceName));
40 
41     xRegistryKey->createKey(sKey.makeStringAndClear());
42 }
43 #endif
44 
45 extern "C"
46 {
47 //==================================================================================================
48 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char**        ppEnvTypeName,
49                                                                                  uno_Environment** ppEnv        )
50 {
51 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
52 }
53 
54 #if 0
55 /**
56  * This method not longer necessary since OOo 3.4 where the component registration was
57  * was changed to passive component registration. For more details see
58  * http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
59  */
60 //==================================================================================================
61 SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void* pServiceManager,
62                                                             void* pRegistryKey   )
63 {
64     if (!pRegistryKey)
65         return sal_False;
66 
67     try
68     {
69         css::uno::Reference< css::registry::XRegistryKey > xKey(reinterpret_cast< css::registry::XRegistryKey* >(pRegistryKey), css::uno::UNO_QUERY);
70 
71         writeInfo( xKey, MYLISTENER_IMPLEMENTATIONNAME       , MYLISTENER_SERVICENAME        );
72         writeInfo( xKey, MYPROTOCOLHANDLER_IMPLEMENTATIONNAME, MYPROTOCOLHANDLER_SERVICENAME );
73 
74         return sal_True;
75     }
76     catch(const css::registry::InvalidRegistryException&)
77         { OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); }
78 
79     return sal_False;
80 }
81 #endif
82 
83 //==================================================================================================
84 SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* pImplName      ,
85                                                                 void*     pServiceManager,
86                                                                 void*     pRegistryKey   )
87 {
88     if ( !pServiceManager || !pImplName )
89         return 0;
90 
91     css::uno::Reference< css::lang::XSingleServiceFactory > xFactory  ;
92     css::uno::Reference< css::lang::XMultiServiceFactory >  xSMGR     (reinterpret_cast< css::lang::XMultiServiceFactory* >(pServiceManager), css::uno::UNO_QUERY);
93     ::rtl::OUString                                         sImplName = ::rtl::OUString::createFromAscii(pImplName);
94 
95     if (sImplName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MYLISTENER_IMPLEMENTATIONNAME ) ) )
96 	{
97         css::uno::Sequence< ::rtl::OUString > lNames(1);
98         lNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MYLISTENER_IMPLEMENTATIONNAME ) );
99 		xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyListener::st_createInstance, lNames);
100 	}
101     else
102     if (sImplName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MYPROTOCOLHANDLER_IMPLEMENTATIONNAME ) ) )
103 	{
104         css::uno::Sequence< ::rtl::OUString > lNames(1);
105         lNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MYPROTOCOLHANDLER_SERVICENAME ) );
106         xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyProtocolHandler_createInstance, lNames);
107 	}
108 
109     if (!xFactory.is())
110         return 0;
111 
112     xFactory->acquire();
113     return xFactory.get();
114 }
115 
116 } // extern C
117