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