merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / inc / bootstrap.hxx
blob8443003852f0bb6248d04671725f2156e75afcf5
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: bootstrap.hxx,v $
10 * $Revision: 1.29 $
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_BOOTSTRAP_HXX_
32 #define CONFIGMGR_BOOTSTRAP_HXX_
34 #include "bootstrapcontext.hxx"
36 // ---------------------------------------------------------------------------------------
37 #define BOOTSTRAP_ITEM_INIFILE "CFG_INIFILE"
38 // ---------------------------------------------------------------------------------------
39 // standard settings
40 #define SETTING_UNOSERVICE "BackendService"
41 #define SETTING_UNOWRAPPER "BackendWrapper"
42 #define SETTING_OFFLINE "Offline"
43 #define SETTING_LOCALE_NEW "Locale"
44 #define SETTING_ASYNC_NEW "EnableAsync"
45 #define SETTING_INIFILE "Inifile"
47 // Prefixes
48 #define CONTEXT_MODULE_PREFIX_ "/modules/com.sun.star.configuration/"
49 #define CONTEXT_SECTION_BOOTSTRAP_ "bootstrap/"
50 #define CONTEXT_ITEM_PREFIX_ CONTEXT_MODULE_PREFIX_ CONTEXT_SECTION_BOOTSTRAP_
51 #define BOOTSTRAP_ITEM_PREFIX_ "CFG_"
53 // special internal context values
54 #define CONTEXT_SECTION_INTERNAL_ "factory/"
55 #define CONTEXT_INTERNAL_PREFIX_ CONTEXT_MODULE_PREFIX_ CONTEXT_SECTION_INTERNAL_
56 #define CONTEXT_ITEM_ADMINFLAG CONTEXT_INTERNAL_PREFIX_"isAdminConfiguration"
57 #define CONTEXT_ITEM_BOOTSTRAP_ERROR CONTEXT_INTERNAL_PREFIX_"theBootstrapError"
59 #define CONTEXT_ITEM_IS_WRAPPER_CONTEXT CONTEXT_INTERNAL_PREFIX_"isWrapperContext"
60 #define CONTEXT_ITEM_IS_BOOTSTRAP_CONTEXT CONTEXT_INTERNAL_PREFIX_"isBootstrapContext"
62 // ---------------------------------------------------------------------------------------
63 #define A_DefaultProviderSingletonName "com.sun.star.configuration.theDefaultProvider"
64 #define K_DefaultBackendSingletonName "com.sun.star.configuration.backend.theDefaultBackend"
65 #define A_BootstrapContextSingletonName "com.sun.star.configuration.bootstrap.theBootstrapContext"
66 // -------------------------------------------------------------------------
67 #define A_DefaultProviderServiceAndImplName "com.sun.star.configuration.DefaultProvider"
68 #define K_DefaultBackendServiceAndImplName "com.sun.star.configuration.backend.DefaultBackend"
69 // ---------------------------------------------------------------------------------------
70 namespace configmgr
72 // -----------------------------------------------------------------------------------
74 namespace uno = ::com::sun::star::uno;
75 namespace lang = ::com::sun::star::lang;
76 namespace beans = ::com::sun::star::beans;
77 // -----------------------------------------------------------------------------------
79 /** Customized ComponentContext for configuration bootstrap data and runtime arguments
81 class BootstrapContext : public ComponentContext
83 // creation and destruction
84 private:
85 friend uno::Reference<uno::XInterface> SAL_CALL
86 instantiateBootstrapContext( uno::Reference< uno::XComponentContext > const& xContext );
88 // constructor
89 BootstrapContext(uno::Reference< uno::XComponentContext > const & _xContext);
91 // two-phase construct
92 void initialize();
94 protected:
95 using ComponentContext::initialize;
97 public:
98 // XServiceInfo
99 virtual rtl::OUString SAL_CALL getImplementationName()
100 throw (uno::RuntimeException) ;
101 virtual sal_Bool SAL_CALL supportsService(
102 const rtl::OUString& aServiceName)
103 throw (uno::RuntimeException) ;
104 virtual uno::Sequence<rtl::OUString> SAL_CALL
105 getSupportedServiceNames(void) throw (uno::RuntimeException) ;
108 /** Constructs a Context based on the given arguments and context.
109 @param _xContext
110 The base context of this component context.
112 @param _aArguments
113 The arguments used to create this component context.
115 static uno::Reference< uno::XComponentContext > createWrapper(uno::Reference< uno::XComponentContext > const & _xContext, uno::Sequence < beans::NamedValue > const & _aOverrides);
117 /** Checks, if the given context is a wrapper.
118 @param _xContext
119 The context that is checked.
121 static sal_Bool isWrapper(uno::Reference< uno::XComponentContext > const & _xContext);
123 /** Retrieves the BootstrapContext for the given non-bootstrap context.
124 @param _xContext
125 The context from which the bootstrap context should be retrieved.
128 static uno::Reference< uno::XComponentContext > get(uno::Reference< uno::XComponentContext > const & _xContext);
130 /// Destroys this BootstrapContext
131 ~BootstrapContext();
133 // gets the INI that should be used for bootstrap data by default
134 static rtl::OUString getDefaultConfigurationBootstrapURL();
136 // interface implementations
137 public:
138 // XComponentContext
139 /** Retrieves a value from this context.
141 @param name
142 The name of the value to retrieve.
143 A prefix of "com.sun.star.configuration.bootstrap." is stripped/ignored
145 @returns
146 The requested value, or <VOID/> if the value is not found.
148 virtual uno::Any SAL_CALL
149 getValueByName( const rtl::OUString& name )
150 throw (uno::RuntimeException);
152 public: // used by ArgumentHelper
153 static rtl::OUString makeContextName (rtl::OUString const & _aShortName);
155 private:
156 static rtl::OUString makeBootstrapName(rtl::OUString const & _aLongName);
157 uno::Any makeBootstrapException();
159 // -----------------------------------------------------------------------------
160 class ContextReader
162 public:
163 explicit
164 ContextReader(uno::Reference< uno::XComponentContext > const & context);
166 // the underlying contexts
167 sal_Bool hasBootstrapContext() const { return m_fullcontext.is(); }
168 uno::Reference< uno::XComponentContext > const & getBootstrapContext() const { return m_fullcontext; }
169 uno::Reference< uno::XComponentContext > const & getBaseContext() const { return m_basecontext; }
170 uno::Reference< uno::XComponentContext > const & getBestContext() const { return m_fullcontext.is() ? m_fullcontext : m_basecontext; }
172 uno::Reference< lang::XMultiComponentFactory > getServiceManager() const;
174 /** Checks, if the given context has the given 'admin' flag setting..
175 @param _xContext
176 The context that is checked.
178 static bool testAdminService(uno::Reference< uno::XComponentContext > const & context, bool bAdmin);
180 // general settings
181 sal_Bool isUnoBackend() const;
183 sal_Bool hasUnoBackendService() const;
184 sal_Bool hasUnoBackendWrapper() const;
186 sal_Bool hasLocale() const;
187 sal_Bool hasAsyncSetting() const;
188 sal_Bool hasOfflineSetting() const;
190 rtl::OUString getUnoBackendService() const;
191 rtl::OUString getUnoBackendWrapper() const;
193 rtl::OUString getLocale() const;
194 sal_Bool getAsyncSetting() const;
195 sal_Bool getOfflineSetting() const;
197 // internal settings - should only ever be in configmgr::BootstrapContext instances
198 // get a special setting
199 sal_Bool isAdminService() const;
201 // access to error diagnostics
202 sal_Bool isBootstrapValid() const;
203 uno::Any getBootstrapError() const;
204 private:
205 sal_Bool hasSetting(rtl::OUString const & _aSetting) const;
206 sal_Bool getBoolSetting(rtl::OUString const & _aSetting, sal_Bool bValue) const;
207 rtl::OUString getStringSetting(rtl::OUString const & _aSetting, rtl::OUString aValue) const;
208 uno::Any getSetting(rtl::OUString const & _aSetting) const;
209 private:
210 uno::Reference< uno::XComponentContext > m_basecontext;
211 uno::Reference< uno::XComponentContext > m_fullcontext;
213 //------------------------------------------------------------------------
215 class ArgumentHelper
217 public:
218 explicit
219 ArgumentHelper(uno::Reference< uno::XComponentContext > const & context)
220 : m_context(context)
221 , m_bHasBackendArguments(false)
224 bool hasBackendArguments() const { return m_bHasBackendArguments; }
225 bool checkBackendArgument(beans::NamedValue const & aAdjustedValue);
227 bool filterAndAdjustArgument(beans::NamedValue & rValue);
229 static
230 bool extractArgument(beans::NamedValue & rValue, uno::Any const & aArgument);
232 static beans::NamedValue makeAdminServiceOverride(sal_Bool bAdmin);
233 private:
234 uno::Reference< uno::XComponentContext > m_context; // context used to strip identical arguments
235 bool m_bHasBackendArguments;
237 // -----------------------------------------------------------------------------------
241 #endif // CONFIGMGR_BOOTSTRAP_HXX_