Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "frameloaderfactory.hxx"
22 : #include "macros.hxx"
23 : #include "constant.hxx"
24 : #include "versions.hxx"
25 :
26 : #include <com/sun/star/lang/XInitialization.hpp>
27 : #include <comphelper/enumhelper.hxx>
28 : #include <comphelper/processfactory.hxx>
29 :
30 :
31 : namespace filter{
32 : namespace config{
33 :
34 16530 : FrameLoaderFactory::FrameLoaderFactory(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
35 16530 : : m_xContext(rxContext)
36 : {
37 : BaseContainer::init(rxContext ,
38 : FrameLoaderFactory::impl_getImplementationName() ,
39 : FrameLoaderFactory::impl_getSupportedServiceNames(),
40 16530 : FilterCache::E_FRAMELOADER );
41 16530 : }
42 :
43 :
44 :
45 33060 : FrameLoaderFactory::~FrameLoaderFactory()
46 : {
47 33060 : }
48 :
49 :
50 :
51 2069 : css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstance(const OUString& sLoader)
52 : throw(css::uno::Exception ,
53 : css::uno::RuntimeException, std::exception)
54 : {
55 2069 : return createInstanceWithArguments(sLoader, css::uno::Sequence< css::uno::Any >());
56 : }
57 :
58 :
59 :
60 2069 : css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstanceWithArguments(const OUString& sLoader ,
61 : const css::uno::Sequence< css::uno::Any >& lArguments)
62 : throw(css::uno::Exception ,
63 : css::uno::RuntimeException, std::exception)
64 : {
65 : // SAFE ->
66 2069 : ::osl::ResettableMutexGuard aLock(m_aLock);
67 :
68 4138 : OUString sRealLoader = sLoader;
69 :
70 : #ifdef _FILTER_CONFIG_MIGRATION_Q_
71 :
72 : /* -> TODO - HACK
73 : check if the given loader name really exist ...
74 : Because our old implementation worked with an internal
75 : type name instead of a loader name. For a small migration time
76 : we must simulate this old feature :-( */
77 :
78 2069 : if (!m_rCache->hasItem(FilterCache::E_FRAMELOADER, sLoader) && m_rCache->hasItem(FilterCache::E_TYPE, sLoader))
79 : {
80 : _FILTER_CONFIG_LOG_("FrameLoaderFactory::createInstanceWithArguments() ... simulate old type search functionality!\n");
81 :
82 0 : css::uno::Sequence< OUString > lTypes(1);
83 0 : lTypes[0] = sLoader;
84 :
85 0 : css::uno::Sequence< css::beans::NamedValue > lQuery(1);
86 0 : lQuery[0].Name = PROPNAME_TYPES;
87 0 : lQuery[0].Value <<= lTypes;
88 :
89 0 : css::uno::Reference< css::container::XEnumeration > xSet = BaseContainer::createSubSetEnumerationByProperties(lQuery);
90 0 : while(xSet->hasMoreElements())
91 : {
92 0 : ::comphelper::SequenceAsHashMap lLoaderProps(xSet->nextElement());
93 0 : if (!(lLoaderProps[PROPNAME_NAME] >>= sRealLoader))
94 0 : continue;
95 0 : }
96 :
97 : // prevent outside code against NoSuchElementException!
98 : // But dont implement such defensive strategy for our new create handling :-)
99 0 : if (!m_rCache->hasItem(FilterCache::E_FRAMELOADER, sRealLoader))
100 0 : return css::uno::Reference< css::uno::XInterface>();
101 : }
102 :
103 : /* <- HACK */
104 :
105 : #endif // _FILTER_CONFIG_MIGRATION_Q_
106 :
107 : // search loader on cache
108 4138 : CacheItem aLoader = m_rCache->getItem(m_eType, sRealLoader);
109 :
110 : // create service instance
111 4138 : css::uno::Reference< css::uno::XInterface > xLoader = m_xContext->getServiceManager()->createInstanceWithContext(sRealLoader, m_xContext);
112 :
113 : // initialize filter
114 4138 : css::uno::Reference< css::lang::XInitialization > xInit(xLoader, css::uno::UNO_QUERY);
115 2069 : if (xInit.is())
116 : {
117 : // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this loader
118 : // lInitData[1] = lArguments[0]
119 : // ...
120 : // lInitData[n] = lArguments[n-1]
121 0 : css::uno::Sequence< css::beans::PropertyValue > lConfig;
122 0 : aLoader >> lConfig;
123 :
124 0 : ::comphelper::SequenceAsVector< css::uno::Any > stlArguments(lArguments);
125 0 : stlArguments.insert(stlArguments.begin(), css::uno::makeAny(lConfig));
126 :
127 0 : css::uno::Sequence< css::uno::Any > lInitData;
128 0 : stlArguments >> lInitData;
129 :
130 0 : xInit->initialize(lInitData);
131 : }
132 :
133 4138 : return xLoader;
134 : // <- SAFE
135 : }
136 :
137 :
138 :
139 1 : css::uno::Sequence< OUString > SAL_CALL FrameLoaderFactory::getAvailableServiceNames()
140 : throw(css::uno::RuntimeException, std::exception)
141 : {
142 : // must be the same list as ((XNameAccess*)this)->getElementNames() return!
143 1 : return BaseContainer::getElementNames();
144 : }
145 :
146 :
147 :
148 16911 : OUString FrameLoaderFactory::impl_getImplementationName()
149 : {
150 16911 : return OUString( "com.sun.star.comp.filter.config.FrameLoaderFactory" );
151 : }
152 :
153 :
154 :
155 16599 : css::uno::Sequence< OUString > FrameLoaderFactory::impl_getSupportedServiceNames()
156 : {
157 16599 : css::uno::Sequence< OUString > lServiceNames(1);
158 16599 : lServiceNames[0] = "com.sun.star.frame.FrameLoaderFactory";
159 16599 : return lServiceNames;
160 : }
161 :
162 :
163 :
164 16530 : css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
165 : {
166 16530 : FrameLoaderFactory* pNew = new FrameLoaderFactory( comphelper::getComponentContext(xSMGR) );
167 16530 : return css::uno::Reference< css::uno::XInterface >(static_cast< css::lang::XMultiServiceFactory* >(pNew), css::uno::UNO_QUERY);
168 : }
169 :
170 : } // namespace config
171 : } // namespace filter
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|