Update ooo320-m1
[ooovba.git] / configmgr / source / api2 / providerimpl.hxx
blob9e8e9e252daf5398827d7503da64035ad9d7c430
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: providerimpl.hxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_API_PROVIDERIMPL_HXX_
32 #define CONFIGMGR_API_PROVIDERIMPL_HXX_
34 #include "defaultprovider.hxx"
35 #include "requestoptions.hxx"
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <com/sun/star/script/XTypeConverter.hpp>
38 #include <com/sun/star/lang/XEventListener.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <cppuhelper/implbase1.hxx>
41 #include <osl/mutex.hxx>
43 namespace com { namespace sun { namespace star {
44 namespace uno
46 class Any;
47 class XInterface;
48 template <class> class Sequence;
49 template <class> class Reference;
51 namespace beans
53 struct PropertyValue;
55 } } }
57 namespace rtl
59 class OUString;
60 template <class RCType> class Reference;
63 namespace configmgr
65 namespace css = ::com::sun::star;
66 namespace uno = css::uno;
67 namespace script = css::script;
68 namespace lang = css::lang;
69 namespace beans = css::beans;
71 class ISubtree;
72 struct TreeChangeList;
73 class TreeManager;
74 class ContextReader;
75 class OProvider;
77 namespace configapi
79 class NodeElement;
80 class ApiProviderInstances;
81 class Factory;
83 namespace sharable { union Node; }
85 // -----------------------------------------------------------------------------
86 class OProviderImpl : public IDefaultableTreeManager
88 friend class OProvider;
89 public:
90 //==========================================================================
91 //= FactoryArguments
92 //==========================================================================
93 /** Helper class for evaluation of the arguments for creating a service instance.*/
94 struct FactoryArguments
96 /// possible arguments, given only in small letters.
97 enum Argument
99 ARG_NODEPATH, // requested node path
100 ARG_DEPTH, // depth of the tree
101 ARG_USER_DEPRECATED, // name of the entity to be manipulated - deprecated version
102 ARG_LOCALE, // desired locale
103 ARG_NOCACHE_OBSOLETE, // cache disabling - obsolete and nonfunctional
104 ARG_ASYNC_DEPRECATED, // lasy write data - deprecated version
105 ARG_ASYNC, // lazy write data
106 ARG_ENTITY, // name of the entity to be manipulated - only for admin
107 ARG_REFRESH, // force refresh of data into cache
109 _arg_count,
110 ARG_NOT_FOUND = _arg_count
112 static sal_Char const * const asciiArgumentNames[];
114 static Argument lookupArgument(rtl::OUString const& sArgumentName) SAL_THROW(());
115 public:
116 /** extracts arguments from the argument sequence into to the parameter variables
118 <p>unknown arguments are ignored</p>
120 @throws com::sun::star::lang::IllegalArgumentException
121 if an element of _rArgs had the wrong type or
122 if the value of a known argument has the wrong type or
123 if the value of a known argument is out of range (sometimes)
124 or if no non-empty node path argument could be extracted,
126 static void extractArgs( const uno::Sequence<uno::Any>& _rArgs,
127 rtl::OUString& /* [out] */ _rNodeAccessor,
128 sal_Int32& /* [out] */ _nLevels,
129 RequestOptions& /* [in/out] */ xOptions)
130 SAL_THROW((lang::IllegalArgumentException));
132 static bool extractOneArgument( rtl::OUString const& aName, uno::Any const& aValue,
133 rtl::OUString& /* [out] */ _rNodeAccessor,
134 sal_Int32& /* [out] */ _nLevels,
135 RequestOptions& /* [in/out] */ xOptions
136 ) SAL_THROW(());
140 private:
141 OProvider* m_pProvider; /// used for ref counting, uno representation
143 uno::Reference< script::XTypeConverter > m_xTypeConverter;
144 RequestOptions m_aDefaultOptions;
145 configapi::ApiProviderInstances* m_pNewProviders;
146 mutable osl::Mutex m_aTreeManagerMutex;
147 TreeManager* m_pTreeManager; /// the tree cache. Will hold a reference to us as long as it life
149 rtl::Reference< TreeManager > maybeGetTreeManager() const SAL_THROW(());
150 rtl::Reference< TreeManager > getTreeManager() const SAL_THROW((com::sun::star::uno::RuntimeException));
151 void setTreeManager(TreeManager * pTreeManager) SAL_THROW((com::sun::star::uno::RuntimeException));
152 void clearTreeManager() SAL_THROW(());
154 OProviderImpl(OProvider* _pProvider,
155 uno::Reference< uno::XComponentContext > const & xContext);
157 public:
158 virtual ~OProviderImpl();
160 /** request that the tree named by a path is added to the collection of managed trees
161 respecting certain options and requiring a specific loading depth.
162 Return a reference to that managed tree.
163 The reference must later be released by calling releaseSubtree with the same path and options.
165 sharable::Node * requestSubtree(configuration::AbsolutePath const& aSubtreePath, const RequestOptions& _aOptions) SAL_THROW((com::sun::star::uno::Exception));
167 /// update the managed data according to a changes list - update the changes list accordingly with old values
168 void updateTree(TreeChangeList& aChanges) SAL_THROW((com::sun::star::uno::Exception));
170 // bookkeeping support
171 void releaseSubtree( configuration::AbsolutePath const& aSubtreePath, const RequestOptions& _aOptions ) SAL_THROW(());
173 // notification
174 void saveAndNotifyUpdate(TreeChangeList const& aChanges) SAL_THROW((com::sun::star::uno::Exception));
176 /** request that the tree named by a path is added to the collection of managed trees
177 respecting certain options and requiring a specific loading depth.
179 void fetchSubtree(configuration::AbsolutePath const& aSubtreePath, const RequestOptions& _aOptions) SAL_THROW(());
181 //Refresh all components in the cache
182 void refreshAll() SAL_THROW((com::sun::star::uno::Exception));
184 //Flush all components in the cache
185 void flushAll() SAL_THROW(());
187 //Enable/Disable Asynchronous write-back to cache
188 void enableAsync(const sal_Bool& bEnableAsync) SAL_THROW(());
190 /// IDefaultableTreeManager
191 virtual sal_Bool fetchDefaultData(configuration::AbsolutePath const& aSubtreePath, const RequestOptions& _aOptions
192 ) SAL_THROW((com::sun::star::uno::Exception));
194 // DefaultProvider access
195 rtl::Reference< TreeManager > getDefaultProvider() const SAL_THROW((com::sun::star::uno::RuntimeException));
197 protected:
198 static rtl::OUString getErrorMessage(configuration::AbsolutePath const& _rAccessor, const RequestOptions& _aOptions);
200 void SAL_CALL dispose() throw();
201 public:
202 void setDefaultLocale( com::sun::star::lang::Locale const & aLocale );
204 RequestOptions const& getDefaultOptions() const {return m_aDefaultOptions;}
205 uno::Reference< script::XTypeConverter > getTypeConverter() const {return m_xTypeConverter;}
206 TreeManager * getNotifier() SAL_THROW(());
207 uno::XInterface* getProviderInstance();
209 // actual factory methods
210 // the returned object (if any) has to be acquired once)
211 configapi::NodeElement* buildReadAccess( rtl::OUString const& _rAccessor, const RequestOptions& _aOptions, sal_Int32 nMinLevels) SAL_THROW((com::sun::star::uno::Exception));
212 // the returned object (if any) has to be acquired once)
213 configapi::NodeElement* buildUpdateAccess(rtl::OUString const& _rAccessor, const RequestOptions& _aOptions, sal_Int32 nMinLevels) SAL_THROW((com::sun::star::uno::Exception));
214 // factory methods
215 uno::Reference<uno::XInterface> createReadAccess( uno::Sequence<uno::Any> const& aArgs) SAL_THROW((com::sun::star::uno::Exception));
216 uno::Reference<uno::XInterface> createUpdateAccess( uno::Sequence<uno::Any> const& aArgs) SAL_THROW((com::sun::star::uno::Exception));
218 private:
219 bool initSession(const ContextReader& _rSettings);
220 private:
221 void implInitFromSettings(const ContextReader& _rSettings, bool& rNeedProfile);
222 void implInitFromProfile(sharable::Node * aProfile);
224 void initFromSettings(const ContextReader& _rSettings, bool& rNeedProfile);
225 void initFromProfile(sharable::Node * aProfile);
227 } // namespace configmgr
229 #endif // CONFIGMGR_API_PROVIDERIMPL_HXX_