xref: /trunk/main/toolkit/source/layout/core/factory.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "factory.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
27cdf0e10cSrcweir #include <com/sun/star/registry/InvalidRegistryException.hpp>
28cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "root.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace ::com::sun::star;
33cdf0e10cSrcweir using namespace layoutimpl;
34cdf0e10cSrcweir 
comp_Layout_component_getFactory(const char * pImplName,void * pServiceManager,void *)35cdf0e10cSrcweir void * SAL_CALL comp_Layout_component_getFactory( const char * pImplName, void * pServiceManager, void * /*registryKey*/ )
36cdf0e10cSrcweir     {
37cdf0e10cSrcweir         void * pRet = 0;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir         ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) );
40cdf0e10cSrcweir         uno::Reference< lang::XSingleServiceFactory > xFactory;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir         if ( pServiceManager && aImplName.equals( LayoutFactory::impl_staticGetImplementationName() ) )
43cdf0e10cSrcweir             xFactory = ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
44cdf0e10cSrcweir                                                          LayoutFactory::impl_staticGetImplementationName(),
45cdf0e10cSrcweir                                                          LayoutFactory::impl_staticCreateSelfInstance,
46cdf0e10cSrcweir                                                          LayoutFactory::impl_staticGetSupportedServiceNames() );
47cdf0e10cSrcweir         if ( xFactory.is() )
48cdf0e10cSrcweir         {
49cdf0e10cSrcweir             xFactory->acquire();
50cdf0e10cSrcweir             pRet = xFactory.get();
51cdf0e10cSrcweir         }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         return pRet;
54cdf0e10cSrcweir     }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // Component registration
impl_staticGetImplementationName()57cdf0e10cSrcweir ::rtl::OUString SAL_CALL LayoutFactory::impl_staticGetImplementationName()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii( "com.sun.star.comp.awt.Layout" );
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
impl_staticGetSupportedServiceNames()62cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::impl_staticGetSupportedServiceNames()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aRet(2);
65cdf0e10cSrcweir     aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.awt.Layout");
66cdf0e10cSrcweir     aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.awt.Layout");
67cdf0e10cSrcweir     return aRet;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
impl_staticCreateSelfInstance(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)70cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::impl_staticCreateSelfInstance(
71cdf0e10cSrcweir     const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     return uno::Reference< uno::XInterface >( *new LayoutFactory( xServiceManager ) );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir // XServiceInfo
getImplementationName()77cdf0e10cSrcweir ::rtl::OUString SAL_CALL LayoutFactory::getImplementationName()
78cdf0e10cSrcweir     throw ( uno::RuntimeException )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     return impl_staticGetImplementationName();
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
getSupportedServiceNames()83cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::getSupportedServiceNames()
84cdf0e10cSrcweir     throw ( uno::RuntimeException )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     return impl_staticGetSupportedServiceNames();
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
supportsService(const::rtl::OUString & ServiceName)89cdf0e10cSrcweir sal_Bool SAL_CALL LayoutFactory::supportsService( const ::rtl::OUString& ServiceName )
90cdf0e10cSrcweir     throw ( uno::RuntimeException )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
93cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
94cdf0e10cSrcweir         if ( ServiceName.compareTo( aSeq[i] ) == 0 )
95cdf0e10cSrcweir             return sal_True;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     return sal_False;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // XSingleServiceFactory
createInstance()101cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstance()
102cdf0e10cSrcweir     throw ( uno::Exception,
103cdf0e10cSrcweir             uno::RuntimeException )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     return uno::Reference< uno::XInterface >(
106cdf0e10cSrcweir         static_cast< OWeakObject* >( new LayoutRoot( m_xFactory ) ),
107cdf0e10cSrcweir         uno::UNO_QUERY );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
createInstanceWithArguments(const uno::Sequence<uno::Any> & aArguments)110cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstanceWithArguments(
111cdf0e10cSrcweir     const uno::Sequence< uno::Any >& aArguments )
112cdf0e10cSrcweir     throw ( uno::Exception,
113cdf0e10cSrcweir             uno::RuntimeException )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     uno::Reference< uno::XInterface > layout = createInstance();
116cdf0e10cSrcweir     uno::Reference< lang::XInitialization > xInit( layout, uno::UNO_QUERY );
117cdf0e10cSrcweir     xInit->initialize( aArguments );
118cdf0e10cSrcweir     return layout;
119cdf0e10cSrcweir }
120