19e0fc027SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
39e0fc027SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
49e0fc027SAndrew Rist * or more contributor license agreements. See the NOTICE file
59e0fc027SAndrew Rist * distributed with this work for additional information
69e0fc027SAndrew Rist * regarding copyright ownership. The ASF licenses this file
79e0fc027SAndrew Rist * to you under the Apache License, Version 2.0 (the
89e0fc027SAndrew Rist * "License"); you may not use this file except in compliance
99e0fc027SAndrew Rist * with the License. You may obtain a copy of the License at
109e0fc027SAndrew Rist *
119e0fc027SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
129e0fc027SAndrew Rist *
139e0fc027SAndrew Rist * Unless required by applicable law or agreed to in writing,
149e0fc027SAndrew Rist * software distributed under the License is distributed on an
159e0fc027SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169e0fc027SAndrew Rist * KIND, either express or implied. See the License for the
179e0fc027SAndrew Rist * specific language governing permissions and limitations
189e0fc027SAndrew Rist * under the License.
199e0fc027SAndrew Rist *
209e0fc027SAndrew Rist *************************************************************/
219e0fc027SAndrew Rist
229e0fc027SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_filter.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "frameloaderfactory.hxx"
28cdf0e10cSrcweir #include "macros.hxx"
29cdf0e10cSrcweir #include "constant.hxx"
30cdf0e10cSrcweir #include "versions.hxx"
31cdf0e10cSrcweir
32cdf0e10cSrcweir //_______________________________________________
33cdf0e10cSrcweir // includes
34cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
35cdf0e10cSrcweir #include <comphelper/enumhelper.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir //_______________________________________________
38cdf0e10cSrcweir // namespace
39cdf0e10cSrcweir
40cdf0e10cSrcweir namespace filter{
41cdf0e10cSrcweir namespace config{
42cdf0e10cSrcweir
43cdf0e10cSrcweir namespace css = ::com::sun::star;
44cdf0e10cSrcweir
45cdf0e10cSrcweir //_______________________________________________
46cdf0e10cSrcweir // definitions
47cdf0e10cSrcweir
48cdf0e10cSrcweir /*-----------------------------------------------
49cdf0e10cSrcweir 09.07.2003 07:43
50cdf0e10cSrcweir -----------------------------------------------*/
FrameLoaderFactory(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)51cdf0e10cSrcweir FrameLoaderFactory::FrameLoaderFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir BaseContainer::init(xSMGR ,
54cdf0e10cSrcweir FrameLoaderFactory::impl_getImplementationName() ,
55cdf0e10cSrcweir FrameLoaderFactory::impl_getSupportedServiceNames(),
56cdf0e10cSrcweir FilterCache::E_FRAMELOADER );
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
59cdf0e10cSrcweir /*-----------------------------------------------
60cdf0e10cSrcweir 09.07.2003 07:43
61cdf0e10cSrcweir -----------------------------------------------*/
~FrameLoaderFactory()62cdf0e10cSrcweir FrameLoaderFactory::~FrameLoaderFactory()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
66cdf0e10cSrcweir /*-----------------------------------------------
67cdf0e10cSrcweir 16.07.2003 13:37
68cdf0e10cSrcweir -----------------------------------------------*/
createInstance(const::rtl::OUString & sLoader)69cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstance(const ::rtl::OUString& sLoader)
70cdf0e10cSrcweir throw(css::uno::Exception ,
71cdf0e10cSrcweir css::uno::RuntimeException)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir return createInstanceWithArguments(sLoader, css::uno::Sequence< css::uno::Any >());
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir /*-----------------------------------------------
77cdf0e10cSrcweir 17.07.2003 09:00
78cdf0e10cSrcweir -----------------------------------------------*/
createInstanceWithArguments(const::rtl::OUString & sLoader,const css::uno::Sequence<css::uno::Any> & lArguments)79cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstanceWithArguments(const ::rtl::OUString& sLoader ,
80cdf0e10cSrcweir const css::uno::Sequence< css::uno::Any >& lArguments)
81cdf0e10cSrcweir throw(css::uno::Exception ,
82cdf0e10cSrcweir css::uno::RuntimeException)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir // SAFE ->
85cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
86cdf0e10cSrcweir
87cdf0e10cSrcweir ::rtl::OUString sRealLoader = sLoader;
88cdf0e10cSrcweir
89cdf0e10cSrcweir #ifdef _FILTER_CONFIG_MIGRATION_Q_
90cdf0e10cSrcweir
91cdf0e10cSrcweir /* -> TODO - HACK
92*07a3d7f1SPedro Giffuni check if the given loader name really exists ...
93cdf0e10cSrcweir Because our old implementation worked with an internal
94cdf0e10cSrcweir type name instead of a loader name. For a small migration time
95cdf0e10cSrcweir we must simulate this old feature :-( */
96cdf0e10cSrcweir
97cdf0e10cSrcweir if (!m_rCache->hasItem(FilterCache::E_FRAMELOADER, sLoader) && m_rCache->hasItem(FilterCache::E_TYPE, sLoader))
98cdf0e10cSrcweir {
99cdf0e10cSrcweir _FILTER_CONFIG_LOG_("FrameLoaderFactory::createInstanceWithArguments() ... simulate old type search functionality!\n");
100cdf0e10cSrcweir
101cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lTypes(1);
102cdf0e10cSrcweir lTypes[0] = sLoader;
103cdf0e10cSrcweir
104cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > lQuery(1);
105cdf0e10cSrcweir lQuery[0].Name = PROPNAME_TYPES;
106cdf0e10cSrcweir lQuery[0].Value <<= lTypes;
107cdf0e10cSrcweir
108cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > xSet = createSubSetEnumerationByProperties(lQuery);
109cdf0e10cSrcweir while(xSet->hasMoreElements())
110cdf0e10cSrcweir {
111cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lLoaderProps(xSet->nextElement());
112cdf0e10cSrcweir if (!(lLoaderProps[PROPNAME_NAME] >>= sRealLoader))
113cdf0e10cSrcweir continue;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir // prevent outside code against NoSuchElementException!
117cdf0e10cSrcweir // But dont implement such defensive strategy for our new create handling :-)
118cdf0e10cSrcweir if (!m_rCache->hasItem(FilterCache::E_FRAMELOADER, sRealLoader))
119cdf0e10cSrcweir return css::uno::Reference< css::uno::XInterface>();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
122cdf0e10cSrcweir /* <- HACK */
123cdf0e10cSrcweir
124cdf0e10cSrcweir #endif // _FILTER_CONFIG_MIGRATION_Q_
125cdf0e10cSrcweir
126cdf0e10cSrcweir // search loader on cache
127cdf0e10cSrcweir CacheItem aLoader = m_rCache->getItem(m_eType, sRealLoader);
128cdf0e10cSrcweir
129cdf0e10cSrcweir // create service instance
130cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xLoader = m_xSMGR->createInstance(sRealLoader);
131cdf0e10cSrcweir
132cdf0e10cSrcweir // initialize filter
133cdf0e10cSrcweir css::uno::Reference< css::lang::XInitialization > xInit(xLoader, css::uno::UNO_QUERY);
134cdf0e10cSrcweir if (xInit.is())
135cdf0e10cSrcweir {
136cdf0e10cSrcweir // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this loader
137cdf0e10cSrcweir // lInitData[1] = lArguments[0]
138cdf0e10cSrcweir // ...
139cdf0e10cSrcweir // lInitData[n] = lArguments[n-1]
140cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > lConfig;
141cdf0e10cSrcweir aLoader >> lConfig;
142cdf0e10cSrcweir
143cdf0e10cSrcweir ::comphelper::SequenceAsVector< css::uno::Any > stlArguments(lArguments);
144cdf0e10cSrcweir stlArguments.insert(stlArguments.begin(), css::uno::makeAny(lConfig));
145cdf0e10cSrcweir
146cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lInitData;
147cdf0e10cSrcweir stlArguments >> lInitData;
148cdf0e10cSrcweir
149cdf0e10cSrcweir xInit->initialize(lInitData);
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir return xLoader;
153cdf0e10cSrcweir // <- SAFE
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir /*-----------------------------------------------
157cdf0e10cSrcweir 09.07.2003 07:46
158cdf0e10cSrcweir -----------------------------------------------*/
getAvailableServiceNames()159cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL FrameLoaderFactory::getAvailableServiceNames()
160cdf0e10cSrcweir throw(css::uno::RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir // must be the same list as ((XNameAccess*)this)->getElementNames() return!
163cdf0e10cSrcweir return getElementNames();
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir /*-----------------------------------------------
167cdf0e10cSrcweir 09.07.2003 07:43
168cdf0e10cSrcweir -----------------------------------------------*/
impl_getImplementationName()169cdf0e10cSrcweir ::rtl::OUString FrameLoaderFactory::impl_getImplementationName()
170cdf0e10cSrcweir {
171cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.comp.filter.config.FrameLoaderFactory");
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir /*-----------------------------------------------
175cdf0e10cSrcweir 09.07.2003 07:43
176cdf0e10cSrcweir -----------------------------------------------*/
impl_getSupportedServiceNames()177cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > FrameLoaderFactory::impl_getSupportedServiceNames()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lServiceNames(1);
180cdf0e10cSrcweir lServiceNames[0] = ::rtl::OUString::createFromAscii("com.sun.star.frame.FrameLoaderFactory");
181cdf0e10cSrcweir return lServiceNames;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
184cdf0e10cSrcweir /*-----------------------------------------------
185cdf0e10cSrcweir 09.07.2003 07:43
186cdf0e10cSrcweir -----------------------------------------------*/
impl_createInstance(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)187cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir FrameLoaderFactory* pNew = new FrameLoaderFactory(xSMGR);
190cdf0e10cSrcweir return css::uno::Reference< css::uno::XInterface >(static_cast< css::lang::XMultiServiceFactory* >(pNew), css::uno::UNO_QUERY);
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir } // namespace config
194cdf0e10cSrcweir } // namespace filter
195