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 : #include <comphelper/sequence.hxx>
30 :
31 :
32 : namespace filter{
33 : namespace config{
34 :
35 26365 : FrameLoaderFactory::FrameLoaderFactory(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
36 26365 : : m_xContext(rxContext)
37 : {
38 : BaseContainer::init(rxContext ,
39 : FrameLoaderFactory::impl_getImplementationName() ,
40 : FrameLoaderFactory::impl_getSupportedServiceNames(),
41 26365 : FilterCache::E_FRAMELOADER );
42 26365 : }
43 :
44 :
45 :
46 52730 : FrameLoaderFactory::~FrameLoaderFactory()
47 : {
48 52730 : }
49 :
50 :
51 :
52 3213 : css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstance(const OUString& sLoader)
53 : throw(css::uno::Exception ,
54 : css::uno::RuntimeException, std::exception)
55 : {
56 3213 : return createInstanceWithArguments(sLoader, css::uno::Sequence< css::uno::Any >());
57 : }
58 :
59 :
60 :
61 3213 : css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createInstanceWithArguments(const OUString& sLoader ,
62 : const css::uno::Sequence< css::uno::Any >& lArguments)
63 : throw(css::uno::Exception ,
64 : css::uno::RuntimeException, std::exception)
65 : {
66 : // SAFE ->
67 3213 : ::osl::ResettableMutexGuard aLock(m_aLock);
68 :
69 6426 : OUString sRealLoader = sLoader;
70 :
71 : #ifdef _FILTER_CONFIG_MIGRATION_Q_
72 :
73 : /* -> TODO - HACK
74 : check if the given loader name really exist ...
75 : Because our old implementation worked with an internal
76 : type name instead of a loader name. For a small migration time
77 : we must simulate this old feature :-( */
78 :
79 3213 : if (!m_rCache->hasItem(FilterCache::E_FRAMELOADER, sLoader) && m_rCache->hasItem(FilterCache::E_TYPE, sLoader))
80 : {
81 : _FILTER_CONFIG_LOG_("FrameLoaderFactory::createInstanceWithArguments() ... simulate old type search functionality!\n");
82 :
83 0 : css::uno::Sequence< OUString > lTypes(1);
84 0 : lTypes[0] = sLoader;
85 :
86 0 : css::uno::Sequence< css::beans::NamedValue > lQuery(1);
87 0 : lQuery[0].Name = PROPNAME_TYPES;
88 0 : lQuery[0].Value <<= lTypes;
89 :
90 0 : css::uno::Reference< css::container::XEnumeration > xSet = BaseContainer::createSubSetEnumerationByProperties(lQuery);
91 0 : while(xSet->hasMoreElements())
92 : {
93 0 : ::comphelper::SequenceAsHashMap lLoaderProps(xSet->nextElement());
94 0 : if (!(lLoaderProps[PROPNAME_NAME] >>= sRealLoader))
95 0 : continue;
96 0 : }
97 :
98 : // prevent outside code against NoSuchElementException!
99 : // But dont implement such defensive strategy for our new create handling :-)
100 0 : if (!m_rCache->hasItem(FilterCache::E_FRAMELOADER, sRealLoader))
101 0 : return css::uno::Reference< css::uno::XInterface>();
102 : }
103 :
104 : /* <- HACK */
105 :
106 : #endif // _FILTER_CONFIG_MIGRATION_Q_
107 :
108 : // search loader on cache
109 6426 : CacheItem aLoader = m_rCache->getItem(m_eType, sRealLoader);
110 :
111 : // create service instance
112 6426 : css::uno::Reference< css::uno::XInterface > xLoader = m_xContext->getServiceManager()->createInstanceWithContext(sRealLoader, m_xContext);
113 :
114 : // initialize filter
115 6426 : css::uno::Reference< css::lang::XInitialization > xInit(xLoader, css::uno::UNO_QUERY);
116 3213 : if (xInit.is())
117 : {
118 : // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this loader
119 : // lInitData[1] = lArguments[0]
120 : // ...
121 : // lInitData[n] = lArguments[n-1]
122 0 : css::uno::Sequence< css::beans::PropertyValue > lConfig;
123 0 : aLoader >> lConfig;
124 :
125 0 : ::std::vector< css::uno::Any > stlArguments(comphelper::sequenceToContainer< ::std::vector<css::uno::Any> >(lArguments));
126 0 : stlArguments.insert(stlArguments.begin(), css::uno::makeAny(lConfig));
127 :
128 0 : xInit->initialize(comphelper::containerToSequence(stlArguments));
129 : }
130 :
131 6426 : return xLoader;
132 : // <- SAFE
133 : }
134 :
135 :
136 :
137 1 : css::uno::Sequence< OUString > SAL_CALL FrameLoaderFactory::getAvailableServiceNames()
138 : throw(css::uno::RuntimeException, std::exception)
139 : {
140 : // must be the same list as ((XNameAccess*)this)->getElementNames() return!
141 1 : return BaseContainer::getElementNames();
142 : }
143 :
144 :
145 :
146 26971 : OUString FrameLoaderFactory::impl_getImplementationName()
147 : {
148 26971 : return OUString( "com.sun.star.comp.filter.config.FrameLoaderFactory" );
149 : }
150 :
151 :
152 :
153 26474 : css::uno::Sequence< OUString > FrameLoaderFactory::impl_getSupportedServiceNames()
154 : {
155 26474 : css::uno::Sequence< OUString > lServiceNames(1);
156 26474 : lServiceNames[0] = "com.sun.star.frame.FrameLoaderFactory";
157 26474 : return lServiceNames;
158 : }
159 :
160 :
161 :
162 26365 : css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
163 : {
164 26365 : FrameLoaderFactory* pNew = new FrameLoaderFactory( comphelper::getComponentContext(xSMGR) );
165 26365 : return css::uno::Reference< css::uno::XInterface >(static_cast< css::lang::XMultiServiceFactory* >(pNew), css::uno::UNO_QUERY);
166 : }
167 :
168 : } // namespace config
169 : } // namespace filter
170 :
171 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|