1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bootstrap.hxx,v $
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 // ---------------------------------------------------------------------------------------
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"
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 // ---------------------------------------------------------------------------------------
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
85 friend uno::Reference
<uno::XInterface
> SAL_CALL
86 instantiateBootstrapContext( uno::Reference
< uno::XComponentContext
> const& xContext
);
89 BootstrapContext(uno::Reference
< uno::XComponentContext
> const & _xContext
);
91 // two-phase construct
95 using ComponentContext::initialize
;
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.
110 The base context of this component context.
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.
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.
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
133 // gets the INI that should be used for bootstrap data by default
134 static rtl::OUString
getDefaultConfigurationBootstrapURL();
136 // interface implementations
139 /** Retrieves a value from this context.
142 The name of the value to retrieve.
143 A prefix of "com.sun.star.configuration.bootstrap." is stripped/ignored
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
);
156 static rtl::OUString
makeBootstrapName(rtl::OUString
const & _aLongName
);
157 uno::Any
makeBootstrapException();
159 // -----------------------------------------------------------------------------
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..
176 The context that is checked.
178 static bool testAdminService(uno::Reference
< uno::XComponentContext
> const & context
, bool bAdmin
);
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;
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;
210 uno::Reference
< uno::XComponentContext
> m_basecontext
;
211 uno::Reference
< uno::XComponentContext
> m_fullcontext
;
213 //------------------------------------------------------------------------
219 ArgumentHelper(uno::Reference
< uno::XComponentContext
> const & 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
);
230 bool extractArgument(beans::NamedValue
& rValue
, uno::Any
const & aArgument
);
232 static beans::NamedValue
makeAdminServiceOverride(sal_Bool bAdmin
);
234 uno::Reference
< uno::XComponentContext
> m_context
; // context used to strip identical arguments
235 bool m_bHasBackendArguments
;
237 // -----------------------------------------------------------------------------------
241 #endif // CONFIGMGR_BOOTSTRAP_HXX_