1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "factory.hxx"
34 #include <com/sun/star/registry/XRegistryKey.hpp>
35 #include <com/sun/star/registry/InvalidRegistryException.hpp>
36 #include <cppuhelper/factory.hxx>
40 using namespace ::com::sun::star
;
41 using namespace layoutimpl
;
43 void * SAL_CALL
comp_Layout_component_getFactory( const char * pImplName
, void * pServiceManager
, void * /*registryKey*/ )
47 ::rtl::OUString
aImplName( ::rtl::OUString::createFromAscii( pImplName
) );
48 uno::Reference
< lang::XSingleServiceFactory
> xFactory
;
50 if ( pServiceManager
&& aImplName
.equals( LayoutFactory::impl_staticGetImplementationName() ) )
51 xFactory
= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory
*>( pServiceManager
),
52 LayoutFactory::impl_staticGetImplementationName(),
53 LayoutFactory::impl_staticCreateSelfInstance
,
54 LayoutFactory::impl_staticGetSupportedServiceNames() );
58 pRet
= xFactory
.get();
64 sal_Bool SAL_CALL
comp_Layout_component_writeInfo( void * /*serviceManager*/, void * pRegistryKey
)
70 uno::Reference
< registry::XRegistryKey
> xKey( reinterpret_cast< registry::XRegistryKey
* >( pRegistryKey
) );
71 uno::Reference
< registry::XRegistryKey
> xNewKey
;
73 xNewKey
= xKey
->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
74 LayoutFactory::impl_staticGetImplementationName() +
75 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") ) );
77 const uno::Sequence
< ::rtl::OUString
> aServices
= LayoutFactory::impl_staticGetSupportedServiceNames();
78 for ( sal_Int32 i
= 0; i
< aServices
.getLength(); i
++ )
79 xNewKey
->createKey( aServices
.getConstArray()[i
] );
83 catch (registry::InvalidRegistryException
&)
85 OSL_ENSURE( sal_False
, "### InvalidRegistryException!" );
91 // Component registration
92 ::rtl::OUString SAL_CALL
LayoutFactory::impl_staticGetImplementationName()
94 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.awt.Layout" );
97 uno::Sequence
< ::rtl::OUString
> SAL_CALL
LayoutFactory::impl_staticGetSupportedServiceNames()
99 uno::Sequence
< ::rtl::OUString
> aRet(2);
100 aRet
[0] = ::rtl::OUString::createFromAscii("com.sun.star.awt.Layout");
101 aRet
[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.awt.Layout");
105 uno::Reference
< uno::XInterface
> SAL_CALL
LayoutFactory::impl_staticCreateSelfInstance(
106 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
108 return uno::Reference
< uno::XInterface
>( *new LayoutFactory( xServiceManager
) );
112 ::rtl::OUString SAL_CALL
LayoutFactory::getImplementationName()
113 throw ( uno::RuntimeException
)
115 return impl_staticGetImplementationName();
118 uno::Sequence
< ::rtl::OUString
> SAL_CALL
LayoutFactory::getSupportedServiceNames()
119 throw ( uno::RuntimeException
)
121 return impl_staticGetSupportedServiceNames();
124 sal_Bool SAL_CALL
LayoutFactory::supportsService( const ::rtl::OUString
& ServiceName
)
125 throw ( uno::RuntimeException
)
127 uno::Sequence
< ::rtl::OUString
> aSeq
= impl_staticGetSupportedServiceNames();
128 for ( sal_Int32 i
= 0; i
< aSeq
.getLength(); i
++ )
129 if ( ServiceName
.compareTo( aSeq
[i
] ) == 0 )
135 // XSingleServiceFactory
136 uno::Reference
< uno::XInterface
> SAL_CALL
LayoutFactory::createInstance()
137 throw ( uno::Exception
,
138 uno::RuntimeException
)
140 return uno::Reference
< uno::XInterface
>(
141 static_cast< OWeakObject
* >( new LayoutRoot( m_xFactory
) ),
145 uno::Reference
< uno::XInterface
> SAL_CALL
LayoutFactory::createInstanceWithArguments(
146 const uno::Sequence
< uno::Any
>& aArguments
)
147 throw ( uno::Exception
,
148 uno::RuntimeException
)
150 uno::Reference
< uno::XInterface
> layout
= createInstance();
151 uno::Reference
< lang::XInitialization
> xInit( layout
, uno::UNO_QUERY
);
152 xInit
->initialize( aArguments
);