diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 15:18:56 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 15:18:56 +0000 |
commit | c25ec0608a167bcf1d891043f02273761c351701 (patch) | |
tree | 32c3e19f0b663e37ad1910e8fddeac200ad3856d /configmgr/source |
initial import
Diffstat (limited to 'configmgr/source')
37 files changed, 8389 insertions, 0 deletions
diff --git a/configmgr/source/api/confeventhelpers.cxx b/configmgr/source/api/confeventhelpers.cxx new file mode 100644 index 000000000000..ef2ea4ee13a3 --- /dev/null +++ b/configmgr/source/api/confeventhelpers.cxx @@ -0,0 +1,484 @@ +/************************************************************************* + * + * $RCSfile: confeventhelpers.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> +#include "confeventhelpers.hxx" + +#ifndef CONFIGMGR_CONFNAME_HXX_ +#include "confname.hxx" +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +namespace configmgr +{ + namespace internal + { + + void throwDispatchIllegalSequenceException() + { + OSL_ENSHURE( 0, "Illegal Call to brodcaster while dispatching" ); + } + +//////////////////////////////////////////////////////////////////////// +/* template <class Listener> + class BroadcastImplHelper + { + public: + osl::Mutex m_aMutex; + + BroadcastImplHelper() {} + ~BroadcastImplHelper() {} + + typedef std::set<Listener*> Interfaces; + typedef Interfaces::const_iterator Iterator; + + void addInterface(Listener* aListener) { m_aInterfaces.insert(aListener); } + void removeInterface(Listener* aListener) { m_aInterfaces.erase(aListener); } + + void disposing(ConfigChangeBroadcaster* pSource); + + Iterator begin() const { return m_aInterfaces.begin(); } + Iterator end() const { return m_aInterfaces.end(); } + private: + Interfaces m_aInterfaces; + + // no implementation - not copyable + BroadcastImplHelper(BroadcastImplHelper&); + void operator=(BroadcastImplHelper&); + }; +*/ + +///////////////////////////////////////////////////////////////////////// +/* + struct NodeListenerInfo + { + INodeListener* m_pListener; + OUString m_path; + + // fake a pointer for generic clients + INodeListener* operator->() const { return m_pListener; } + INodeListener& operator*() const { return *m_pListener; } + + bool operator < (NodeListenerInfo const& aInfo) const; + }; +*/ +///////////////////////////////////////////////////////////////////////// + +/* + class ConfigChangesBroadcasterImpl + { + private: + typedef BroadcastImplHelper<NodeListenerInfo> Listeners; + Listeners m_aListeners; + std::map<OUString, Listeners::Iterator> m_aDispatchInfos; + }; +*/ +///////////////////////////////////////////////////////////////////////// +ConfigChangesBroadcasterImpl::ConfigChangesBroadcasterImpl() +{ +} + +///////////////////////////////////////////////////////////////////////// +ConfigChangesBroadcasterImpl::~ConfigChangesBroadcasterImpl() +{ + OSL_ENSURE(m_aListeners.begin() == m_aListeners.end(), "Remaining listeners found - forgot to dispose ?"); + OSL_ENSURE(m_aPathMap.empty(), "Spurious mappings found"); +} + +///////////////////////////////////////////////////////////////////////// +void ConfigChangesBroadcasterImpl::add(OUString const& aName, INodeListener* pListener) +{ + OSL_ASSERT( ! ConfigurationName(aName).isRelative() ); + + osl::MutexGuard aGuard(m_aListeners.mutex); + + InfoRef aAdded = m_aListeners.addListener(NodeListenerInfo(pListener)); + aAdded->addPath(aName); + m_aPathMap.insert(PathMap::value_type(aName,aAdded)); +} + +///////////////////////////////////////////////////////////////////////// +void ConfigChangesBroadcasterImpl::remove(INodeListener* pListener) +{ + osl::MutexGuard aGuard(m_aListeners.mutex); + + Listeners::Iterator const iter = m_aListeners.find(pListener); + if (iter != m_aListeners.end()) + { + typedef NodeListenerInfo::Pathes Pathes; + Pathes const& pathes = iter->pathList(); + + // first clear the Path Map + for(Pathes::iterator itPath = pathes.begin(); itPath != pathes.end(); ++itPath) + { + typedef PathMap::iterator PMIter; + typedef std::pair<PMIter, PMIter> PMRange; + + PMRange aRange = m_aPathMap.equal_range(*itPath); + while (aRange.first != aRange.second) + { + PMIter cur = aRange.first++; + if (cur->second == iter) + m_aPathMap.erase(cur); + } + } + + // the remove the broadcast helper entry + m_aListeners.removeListener(pListener); + } +} + +void ConfigChangesBroadcasterImpl::removed(OUString const& aBasePath, bool bRemovedFromModel, IConfigBroadcaster* pSource) +{ + OSL_ASSERT( ! ConfigurationName(aBasePath).isRelative() ); + + // Dispatch 'deleted' to descendants of the changed path + + for( PathMap::const_iterator it = m_aPathMap.lower_bound(aBasePath); + it != m_aPathMap.end() && 0 == aBasePath.compareTo(it->first, aBasePath.getLength()); + ) + { + OSL_ASSERT( m_aListeners.find(it->second->get()) != m_aListeners.end() ); + + OUString aDispatchPath = it->first; + OSL_ASSERT( ! ConfigurationName(aDispatchPath).isRelative() ); + + INodeListener* pTarget = it->second->get(); + ++it; + + // we allow a listener to remove itself from within the callback + // the simple increment above wont work, if the following listener is the same listener + // (which really shouldn't happen) + PathMap::const_iterator next = it; + while (next != m_aPathMap.end() && next->second->get() == pTarget) + ++next; + + pTarget->nodeDeleted(aBasePath, pSource); + + // if a listener removes itself from within the callback, it will be missing by now + // so we check whether our listener is still there and if necessary patch our position + if (m_aListeners.find(pTarget) == m_aListeners.end()) + it = next; + } +} + + +///////////////////////////////////////////////////////////////////////// +// This should actually be available from the TreeChangeList +///////////////////////////////////////////////////////////////////////// + +static Change const* resolvePath(Change const* pChange, ConfigurationName& aRelativePath, RemoveNode const*& pRemoveNode) +{ + OSL_ASSERT(aRelativePath.isRelative()); + OSL_ASSERT(pRemoveNode == 0); + pRemoveNode = 0; + + ConfigurationName::Iterator aIter(aRelativePath.begin()); + ConfigurationName::Iterator const aEnd(aRelativePath.end()); + + OSL_ASSERT(pChange); + OSL_ASSERT(aIter != aEnd); + + while (pChange) + { + if (pChange->ISA(RemoveNode)) + pRemoveNode = static_cast<RemoveNode const*>(pChange); + + OSL_ASSERT(*aIter == pChange->getNodeName()); + if (++aIter == aEnd) + break; // found it + + pChange = pChange->getSubChange(*aIter); + + OSL_ASSERT(pRemoveNode == NULL || pChange == NULL); + } + if (pRemoveNode) + { + aRelativePath = ConfigurationName(aRelativePath.begin(),aIter); + OSL_ASSERT( aRelativePath.localName() == pRemoveNode->getNodeName()); + } + else + OSL_ASSERT(pChange == 0 || aRelativePath == ConfigurationName(aRelativePath.begin(),aIter)); + + return pChange; +} + +///////////////////////////////////////////////////////////////////////// +void ConfigChangesBroadcasterImpl::dispatchInner +( + INodeListener* pTarget, + OUString const& sTargetPath, + Change const& rBaseChange, + OUString const& sChangeContext, + sal_Bool , //_bError, + IConfigBroadcaster* pSource +) +{ + ConfigurationName aContext(sChangeContext); + + OSL_ASSERT(pTarget); + OSL_ASSERT( ConfigurationName(sTargetPath).isNestedIn( aContext ) ); + + ConfigurationName aLocalPath = ConfigurationName(sTargetPath).relativeTo( aContext ); + RemoveNode const* pRemoved = 0; + Change const* pTargetChange = resolvePath(&rBaseChange, aLocalPath, pRemoved ); + + if (pRemoved) + { + pTarget->nodeDeleted(aContext.composeWith(aLocalPath).fullName(), pSource); + } + else if (pTargetChange) + { + OSL_ASSERT(aContext.composeWith(aLocalPath) == sTargetPath); + pTarget->nodeChanged(*pTargetChange, sTargetPath, pSource); + } +} + +///////////////////////////////////////////////////////////////////////// +void ConfigChangesBroadcasterImpl::dispatchOuter +( + INodeListener* pTarget, + OUString const& sTargetPath, + Change const& rBaseChange, + OUString const& sChangeContext, + sal_Bool , //_bError, + IConfigBroadcaster* pSource +) +{ + ConfigurationName sChangesRoot(sChangeContext,rBaseChange.getNodeName()); + + OSL_ASSERT(pTarget); + OSL_ASSERT( sChangesRoot.isNestedIn( sTargetPath ) ); + + pTarget->nodeChanged(rBaseChange, sChangesRoot.fullName(), pSource); +} + +///////////////////////////////////////////////////////////////////////// +void ConfigChangesBroadcasterImpl::dispatch(TreeChangeList const& rList_, sal_Bool _bError, IConfigBroadcaster* pSource) +{ + dispatch(rList_.root, rList_.pathToRoot,_bError, pSource); +} +void ConfigChangesBroadcasterImpl::dispatch +( + Change const& rBaseChange, + OUString const& sChangeContext, + sal_Bool _bError, + IConfigBroadcaster* pSource +) +{ + // listeners registered under multiple sub-pathes will be called multiple times ! + + osl::MutexGuard aGuard(m_aListeners.mutex); + + ConfigurationName aRootName(sChangeContext); + OSL_ASSERT(!aRootName.isRelative()); + + ConfigurationName aNodeName(aRootName, rBaseChange.getNodeName()); + OUString aBasePath( aNodeName.fullName() ); + OSL_ASSERT(!aNodeName.isRelative()); + + OSL_ASSERT(aNodeName.getParentName() == aRootName); + + // Dispatch listeners to ancestors of the change root + PathMap::const_iterator const endOuter = m_aPathMap.upper_bound(aRootName.fullName()); + + // TODO: Both loops are so similar - they should be a single function + for ( PathMap::const_iterator itOuter = m_aPathMap.lower_bound( ConfigurationName::rootname() += aRootName.moduleName() ); + itOuter != endOuter; + ) + { + OSL_ASSERT( m_aListeners.find(itOuter->second->get()) != m_aListeners.end() ); + + OUString aDispatchPath = itOuter->first; + OSL_ASSERT( ! ConfigurationName(aDispatchPath).isRelative() ); + + INodeListener* pTarget = itOuter->second->get(); + + // incrementing here usually is enough + ++itOuter; + + // check whether this should be dispatched at all + if (aBasePath == aDispatchPath || aNodeName.isNestedIn(aDispatchPath)) + { + // we allow a listener to remove itself from within the callback + // the simple increment above wont work, if the following listener is the same listener + // (which really shouldn't happen) + PathMap::const_iterator next = itOuter; + while (next != m_aPathMap.end() && next->second->get() == pTarget) + ++next; + + this->dispatchOuter(pTarget, aDispatchPath, rBaseChange, sChangeContext, _bError, pSource); + + // if a listener removes itself from within the callback, it will be missing by now + // so we check whether our listener is still there and if necessary patch our position + if (m_aListeners.find(pTarget) == m_aListeners.end()) + itOuter = next; + } + } + + + // Dispatch listeners to descendants of the change root + for( PathMap::const_iterator itInner = m_aPathMap.lower_bound(aBasePath); + itInner != m_aPathMap.end() && 0 == aBasePath.compareTo(itInner->first, aBasePath.getLength()); + ) + { + OSL_ASSERT( m_aListeners.find(itInner->second->get()) != m_aListeners.end() ); + + OUString aDispatchPath = itInner->first; + OSL_ASSERT( ! ConfigurationName(aDispatchPath).isRelative() ); + + INodeListener* pTarget = itInner->second->get(); + ++itInner; + + // check whether this should be dispatched at all + if (aBasePath == aDispatchPath || ConfigurationName(aDispatchPath).isNestedIn(aRootName)) + { + // we allow a listener to remove itself from within the callback + // the simple increment above wont work, if the following listener is the same listener + // (which really shouldn't happen) + PathMap::const_iterator next = itInner; + while (next != m_aPathMap.end() && next->second->get() == pTarget) + ++next; + + this->dispatchInner(pTarget, aDispatchPath, rBaseChange, sChangeContext, _bError, pSource); + + // if a listener removes itself from within the callback, it will be missing by now + // so we check whether our listener is still there and if necessary patch our position + if (m_aListeners.find(pTarget) == m_aListeners.end()) + itInner = next; + } + + } +} + +///////////////////////////////////////////////////////////////////////// +void ConfigChangesBroadcasterImpl::disposing(IConfigBroadcaster* pSource) +{ + osl::MutexGuard aGuard(m_aListeners.mutex); + + m_aPathMap.clear(); + m_aListeners.disposing(pSource); +} + +///////////////////////////////////////////////////////////////////////// +/* class ConfigMessageBroadcasterImpl + { + public: + private: + typedef BroadcastImplHelper<INodeListener*> Listeners; + Listeners m_aListeners; + }; +*/ +///////////////////////////////////////////////////////////////////////// +void ConfigMessageBroadcasterImpl::add(IMessageHandler* pListener) +{ + osl::MutexGuard aGuard(m_aListeners.mutex); + + m_aListeners.addListener(pListener); +} + +///////////////////////////////////////////////////////////////////////// +void ConfigMessageBroadcasterImpl::remove(IMessageHandler* pListener) +{ + osl::MutexGuard aGuard(m_aListeners.mutex); + + m_aListeners.removeListener(pListener); +} + +///////////////////////////////////////////////////////////////////////// +void ConfigMessageBroadcasterImpl::dispatch(OUString const& _rNotifyReason, sal_Int32 _nNotificationId, IConfigBroadcaster* pSource) +{ + osl::MutexGuard aGuard(m_aListeners.mutex); + + for (Listeners::Iterator it = m_aListeners.begin(); it != m_aListeners.end(); ) + { + // incrementing here allows a listener to remove itself from within the callback + + // it is illegal to cause removal of another listener from the callback + // if this occurs (dereferencing, incrementing or comparing 'it' fails) + // we need to explicitly guard against that (which is really too expensive) + + IMessageHandler* pHandler = *it; + ++it; + + if (pHandler) + pHandler->message(_rNotifyReason,_nNotificationId,pSource); + } + +} + +///////////////////////////////////////////////////////////////////////// +void ConfigMessageBroadcasterImpl::disposing(IConfigBroadcaster* pSource) +{ + osl::MutexGuard aGuard(m_aListeners.mutex); + + m_aListeners.disposing(pSource); +} + +///////////////////////////////////////////////////////////////////////// + } // namespace +} // namespace + + + diff --git a/configmgr/source/api/confeventhelpers.hxx b/configmgr/source/api/confeventhelpers.hxx new file mode 100644 index 000000000000..1b3b45898377 --- /dev/null +++ b/configmgr/source/api/confeventhelpers.hxx @@ -0,0 +1,248 @@ +/************************************************************************* + * + * $RCSfile: confeventhelpers.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef CONFIGMGR_API_EVENTHELPERS_HXX_ +#define CONFIGMGR_API_EVENTHELPERS_HXX_ + +#ifndef _COM_SUN_STAR_UNO_RUNTIMEEXCEPTION_HPP_ +#include <com/sun/star/uno/RuntimeException.hpp> +#endif + +#ifndef CONFIGMGR_API_EVENTS_HXX_ +#include "confevents.hxx" +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef __SGI_STL_MAP +#include <stl/map> +#endif +#ifndef __SGI_STL_SET +#include <stl/set> +#endif + +namespace configmgr +{ + namespace internal + { + + + //////////////////////////////////////////////////////////////////////// + template <class ListenerRef> + class BroadcastImplHelper + { + public: + osl::Mutex mutex; + + public: + BroadcastImplHelper() + {} + + ~BroadcastImplHelper() + { + OSL_ENSHURE(m_aInterfaces.empty(), "Configuration Broadcaster was not disposed properly"); + } + + public: + typedef std::set<ListenerRef> Interfaces; + typedef typename Interfaces::iterator FullIterator; + typedef typename Interfaces::const_iterator Iterator; + + public: + FullIterator addListener(ListenerRef aListener) + { + return m_aInterfaces.insert(aListener).first; + } + void removeListener(ListenerRef aListener) + { + m_aInterfaces.erase(aListener); + } + + void disposing(IConfigBroadcaster* pSource); + + public: + Iterator begin() const { return m_aInterfaces.begin(); } + Iterator end() const { return m_aInterfaces.end(); } + + Iterator find(ListenerRef aListener) const { return m_aInterfaces.find(aListener); } + FullIterator findFull(ListenerRef aListener) { return m_aInterfaces.find(aListener); } + private: + Interfaces m_aInterfaces; + + // no implementation - not copyable + BroadcastImplHelper(BroadcastImplHelper&); + void operator=(BroadcastImplHelper&); + }; + + //////////////////////////////////////////////////////////////////////// + template <class Listener> + void BroadcastImplHelper<Listener>::disposing(IConfigBroadcaster* pSource) + { + osl::MutexGuard aGuard(this->mutex); // ensure that no notifications are running + + for(FullIterator it = m_aInterfaces.begin(); it != m_aInterfaces.end(); ) + { + FullIterator cur = it++; + if (*cur) + (*cur)->disposing(pSource); + m_aInterfaces.erase(cur); + } + } + + + ///////////////////////////////////////////////////////////////////////// + + class NodeListenerInfo + { + public: + typedef std::set<OUString> Pathes; + + public: + NodeListenerInfo(INodeListener* pListener) + : m_pListener(pListener) + { + } + + // path handling + Pathes const& pathList() const { return m_aPathes; } + + void addPath(OUString const& sPath) const { m_aPathes.insert(sPath); } + void removePath(OUString const& sPath) const { m_aPathes.erase(sPath); } + //void removeChildPathes(OUString const& sPath); + + // behave as pointer for use as a 'reference' class + INodeListener* get() const { return m_pListener; } + INodeListener* operator->() const { return get(); } + INodeListener& operator*() const { return *get(); } + // needed to allow if (info) ... + struct HasListener; + operator HasListener const*() const { return reinterpret_cast<HasListener*>(m_pListener); } + + bool operator < (NodeListenerInfo const& aInfo) const + { return std::less<INodeListener*>()(m_pListener, aInfo.m_pListener); } + + bool operator == (NodeListenerInfo const& aInfo) const + { return m_pListener == aInfo.m_pListener; } + + bool operator > (NodeListenerInfo const& aInfo) const + { return aInfo.operator < (*this); } + bool operator >= (NodeListenerInfo const& aInfo) const + { return !operator<(aInfo); } + bool operator <= (NodeListenerInfo const& aInfo) const + { return !operator>(aInfo); } + + bool operator != (NodeListenerInfo const& aInfo) const + { return !operator==(aInfo); } + + private: + INodeListener* m_pListener; + mutable Pathes m_aPathes; // hack to be mutable as set element + }; + class ConfigChangesBroadcasterImpl + { + public: + ConfigChangesBroadcasterImpl(); + ~ConfigChangesBroadcasterImpl(); + + void add(OUString const& aName, INodeListener* pListener); + void remove(INodeListener* pListener); + + void removed(OUString const& aPath, bool bRemovedFromModel, IConfigBroadcaster* pSource); + + void dispatch(Change const& rBaseChange, OUString const& sChangeContext, sal_Bool _bError, IConfigBroadcaster* pSource); + void dispatch(TreeChangeList const& rList_, sal_Bool _bError, IConfigBroadcaster* pSource); + void disposing(IConfigBroadcaster* pSource); + private: + typedef BroadcastImplHelper<NodeListenerInfo> Listeners; + typedef Listeners::FullIterator InfoRef; + typedef std::multimap<OUString, InfoRef> PathMap; + Listeners m_aListeners; + PathMap m_aPathMap; + private: + void dispatchInner(INodeListener* pTarget, OUString const& sTargetPath, Change const& rBaseChange, OUString const& sChangeContext, sal_Bool _bError, IConfigBroadcaster* pSource); + void dispatchOuter(INodeListener* pTarget, OUString const& sTargetPath, Change const& rBaseChange, OUString const& sChangeContext, sal_Bool _bError, IConfigBroadcaster* pSource); + }; + + ///////////////////////////////////////////////////////////////////////// + class ConfigMessageBroadcasterImpl + { + public: + void add(IMessageHandler* pListener); + void remove(IMessageHandler* pListener); + + void dispatch(OUString const& _rNotifyReason, sal_Int32 _nNotificationId, IConfigBroadcaster* pSource); + void disposing(IConfigBroadcaster* pSource); + private: + typedef BroadcastImplHelper<IMessageHandler*> Listeners; + Listeners m_aListeners; + }; + + ///////////////////////////////////////////////////////////////////////// + } // namespace +} // namespace + +#endif // CONFIGMGR_API_EVENTHELPERS_HXX_ + + diff --git a/configmgr/source/api/confevents.cxx b/configmgr/source/api/confevents.cxx new file mode 100644 index 000000000000..19dd9d8e4a7c --- /dev/null +++ b/configmgr/source/api/confevents.cxx @@ -0,0 +1,410 @@ +/************************************************************************* + * + * $RCSfile: confevents.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> +#include "confevents.hxx" + +#ifndef CONFIGMGR_API_EVENTHELPERS_HXX_ +#include "confeventhelpers.hxx" +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +namespace configmgr +{ + // class is still abstract, ITreeListener methods are still unimplemented + TreeListenerImpl::TreeListenerImpl(ITreeNotifier* aSource) + : mySource(aSource) + { + if (mySource) mySource->setListener(this); + } + TreeListenerImpl::~TreeListenerImpl() + { + if (mySource) mySource->setListener(0); + } + + void TreeListenerImpl::disposing(ITreeNotifier* pSource) + { + OSL_ASSERT(pSource && pSource == mySource); + if (pSource == mySource) + mySource = 0; + } + + ITreeNotifier* TreeListenerImpl::rebind(ITreeNotifier* aSource) + { + ITreeNotifier* aOldSource = mySource; + if (aSource != aOldSource) + { + if (mySource) mySource->setListener(0); + mySource = aSource; + if (mySource) mySource->setListener(this); + } + return aOldSource; + } + + ///////////////////////////////////////////////////////////////////////// + using internal::ConfigChangesBroadcasterImpl; + using internal::ConfigMessageBroadcasterImpl; + + ///////////////////////////////////////////////////////////////////////// + class ConfigChangeBroadcaster::Impl + { + public: + Impl() : m_changes(), m_messages() {} + + ConfigChangesBroadcasterImpl m_changes; + ConfigMessageBroadcasterImpl m_messages; + }; + + ///////////////////////////////////////////////////////////////////////// + ConfigChangeBroadcaster::ConfigChangeBroadcaster(ITreeNotifier* aSource) + : TreeListenerImpl(aSource) + , pImpl(new Impl()) + { + } + + ConfigChangeBroadcaster::~ConfigChangeBroadcaster() + { + dispose(); + } + + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeBroadcaster::dispose() + { + unbind(); + + if (!pImpl) return; + pImpl->m_changes.disposing(this); + pImpl->m_messages.disposing(this); + delete pImpl, pImpl = 0; + } + + ///////////////////////////////////////////////////////////////////////// + // IConfigBroadcaster implementation + void ConfigChangeBroadcaster::addListener(OUString const& aName, INodeListener* pHandler) + { pImpl->m_changes.add(aName, pHandler); } + + void ConfigChangeBroadcaster::removeListener(INodeListener* pHandler) + { pImpl->m_changes.remove(pHandler); } + + void ConfigChangeBroadcaster::removeNode(OUString const& aPath, bool bRemovedFromModel) + { pImpl->m_changes.removed(aPath,bRemovedFromModel,this); } + + void ConfigChangeBroadcaster::addHandler(IMessageHandler* pHandler) + { pImpl->m_messages.add(pHandler); } + + void ConfigChangeBroadcaster::removeHandler(IMessageHandler* pHandler) + { pImpl->m_messages.remove(pHandler); } + + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeBroadcaster::broadcast(TreeChangeList const& anUpdate, sal_Bool bError) + { + pImpl->m_changes.dispatch(anUpdate, bError, this); + } + + ///////////////////////////////////////////////////////////////////////// + // ITreeListener implementation + void ConfigChangeBroadcaster::changes(TreeChangeList const& rList_, sal_Bool bError_) + { + broadcast(rList_, bError_);; + } + + void ConfigChangeBroadcaster::changes(sal_Int32 _nNotificationId,const OUString& _rNotifyReason) + { + pImpl->m_messages.dispatch(_rNotifyReason, _nNotificationId, this); + } + + ///////////////////////////////////////////////////////////////////////// + class ConfigChangeMultiplexer::Impl + { + public: + + Impl(OUString const& sBasePath_) : sBasePath(sBasePath_), m_changes(), m_messages() {} + + OUString const sBasePath; + ConfigChangesBroadcasterImpl m_changes; + ConfigMessageBroadcasterImpl m_messages; + }; + + ///////////////////////////////////////////////////////////////////////// + ConfigChangeMultiplexer::ConfigChangeMultiplexer(IConfigBroadcaster* pSource) + : m_pSource(pSource) + , pImpl(0) + { + if (m_pSource) m_pSource->addHandler(this); + } + + ConfigChangeMultiplexer::ConfigChangeMultiplexer(OUString const& aBasePath, IConfigBroadcaster* pSource) + : m_pSource(pSource) + , pImpl(0) + { + bind(aBasePath,pSource); + } + + ConfigChangeMultiplexer::~ConfigChangeMultiplexer() + { + dispose(); + } + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeMultiplexer::bind(OUString const& sNewPath, IConfigBroadcaster* pSource) + { + if (pImpl) + { + OSL_ASSERT(sNewPath == pImpl->sBasePath); + rebind(pSource); + } + else + { + pImpl = new Impl(sNewPath); + if (pSource) + m_pSource = pSource; + m_pSource->addListener(pImpl->sBasePath, this); + m_pSource->addHandler(this); + } + } + + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeMultiplexer::rebind(IConfigBroadcaster* pSource) + { + if (pSource != m_pSource) + { + unbind(); + m_pSource = pSource; + if (m_pSource) + { + if (pImpl) m_pSource->addListener(pImpl->sBasePath, this); + m_pSource->addHandler(this); + } + } + } + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeMultiplexer::unbind() + { + if (m_pSource) + { + if (pImpl) m_pSource->removeListener(this); + m_pSource->removeHandler(this); + } + m_pSource = 0; + } + + ///////////////////////////////////////////////////////////////////////// + bool ConfigChangeMultiplexer::normalizePath(OUString& aName) + { + if (!pImpl) return false; + + ConfigurationName aMyPath(pImpl->sBasePath); + ConfigurationName aPath(aName); + if (aPath.isRelative()) + { + aName = aMyPath.composeWith(aPath).fullName(); + return true; + } + else + { + bool ok = (aMyPath == aPath) || aPath.isNestedIn(aMyPath); + + return ok; + } + } + + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeMultiplexer::broadcast(Change const& anUpdate, OUString const& aRelativePath, sal_Bool bError) + { + OSL_ENSURE(pImpl!=0, "Trying to broadcast on disconnected Notification Multiplexer"); + + OUString aContext( aRelativePath ); + if (!normalizePath(aContext)) + OSL_TRACE("Invalid path. Multiplexer may not walk subtrees correctly\n\r"); + + if (pImpl) + { + pImpl->m_changes.dispatch(anUpdate, aContext, bError, this); + } + } + + void ConfigChangeMultiplexer::broadcast(Change const& anUpdate) + { + // do we need to append the local name ?? + if (pImpl) + pImpl->m_changes.dispatch(anUpdate, pImpl->sBasePath, false, this); + } + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeMultiplexer::dispose() + { + unbind(); + + if (!pImpl) return; + pImpl->m_changes.disposing(this); + pImpl->m_messages.disposing(this); + delete pImpl, pImpl = 0; + } + + // IConfigListener implementation + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeMultiplexer::disposing(IConfigBroadcaster* pSource) + { + OSL_ASSERT(pSource == m_pSource); + if (pSource == m_pSource) + unbind(); + } + + // INodeListener implementation + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeMultiplexer::nodeChanged(Change const& aChange, OUString const& aPath, IConfigBroadcaster* pSource) + { + OSL_ASSERT(pImpl != 0); + OSL_VERIFY(pSource == m_pSource); + broadcast(aChange, aPath); + } + void ConfigChangeMultiplexer::nodeDeleted(OUString const& aPath, IConfigBroadcaster* pSource) + { + OSL_ASSERT(pImpl != 0); + + if (pImpl) + { + OUString aContext( aPath ); + + // must be this base path or a child of it + OSL_ASSERT(!ConfigurationName(aPath).isRelative() || aPath.getLength() == 0); + OSL_ASSERT(aPath.getLength() == 0 || + pImpl->sBasePath == aPath || + ConfigurationName(pImpl->sBasePath).isNestedIn(aPath)); + pImpl->m_changes.removed(aContext,true,this); + } + } + + // IMessageHandler implementation + ///////////////////////////////////////////////////////////////////////// + void ConfigChangeMultiplexer::message(const OUString& rNotifyReason, sal_Int32 nNotificationId, IConfigBroadcaster* pSource) + { + OSL_VERIFY(pSource == m_pSource); + if (pImpl) + pImpl->m_messages.dispatch(rNotifyReason, nNotificationId, this); + } + + ///////////////////////////////////////////////////////////////////////// + // IConfigBroadcaster implementation + + void ConfigChangeMultiplexer::addListener(OUString const& aName, INodeListener* pHandler) + { pImpl->m_changes.add(aName, pHandler); } + + void ConfigChangeMultiplexer::removeListener(INodeListener* pHandler) + { pImpl->m_changes.remove(pHandler); } + + void ConfigChangeMultiplexer::removeNode(OUString const& aPath, bool bRemovedFromModel) + { pImpl->m_changes.removed(aPath,bRemovedFromModel,this); } + + void ConfigChangeMultiplexer::addHandler(IMessageHandler* pHandler) + { pImpl->m_messages.add(pHandler); } + + void ConfigChangeMultiplexer::removeHandler(IMessageHandler* pHandler) + { pImpl->m_messages.remove(pHandler); } + + ///////////////////////////////////////////////////////////////////////// + // ScreenedChangeMultiplexer + ScreenedChangeMultiplexer:: ScreenedChangeMultiplexer(IConfigBroadcaster* aSource) + : ConfigChangeMultiplexer() + , m_pScreeningChanges(0) + { + } + + ScreenedChangeMultiplexer:: ScreenedChangeMultiplexer(TreeChangeList& aScreeningTree, IConfigBroadcaster* aSource) + : ConfigChangeMultiplexer(aScreeningTree.pathToRoot, aSource) + , m_pScreeningChanges(&aScreeningTree.root) + { + } + + ScreenedChangeMultiplexer:: ScreenedChangeMultiplexer(ScreeningChange* aScreening, OUString const& aBasePath, IConfigBroadcaster* aSource) + : ConfigChangeMultiplexer(aBasePath, aSource) + , m_pScreeningChanges(aScreening) + { + } + + void ScreenedChangeMultiplexer:: bind(TreeChangeList& aScreeningTree, IConfigBroadcaster* aSource) + { + bind(&aScreeningTree.root, aScreeningTree.pathToRoot, aSource); + } + + void ScreenedChangeMultiplexer:: bind(ScreeningChange* aScreening, OUString const& aBasePath, IConfigBroadcaster* aSource) + { + unbind(); + m_pScreeningChanges = aScreening; + ConfigChangeMultiplexer::bind(aBasePath, aSource); + } + + void ScreenedChangeMultiplexer:: nodeChanged(Change const& aChange, OUString const& aPath, IConfigBroadcaster* pSource) + { + // To do: filter with local changes herehere + if (&aChange != m_pScreeningChanges) + ConfigChangeMultiplexer::nodeChanged(aChange,aPath,pSource); + } + + void ScreenedChangeMultiplexer:: nodeDeleted(OUString const& aPath, IConfigBroadcaster* pSource) + { + // To do: filter here + ConfigChangeMultiplexer::nodeDeleted(aPath,pSource); + } + +} // namespace + + + diff --git a/configmgr/source/api/confsvccomponent.cxx b/configmgr/source/api/confsvccomponent.cxx new file mode 100644 index 000000000000..1eba8c196734 --- /dev/null +++ b/configmgr/source/api/confsvccomponent.cxx @@ -0,0 +1,181 @@ +/************************************************************************* + * + * $RCSfile: confsvccomponent.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "confsvccomponent.hxx" + +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef __SGI_STL_MAP +#include <stl/map> +#endif + +namespace configmgr { + + + ServiceComponentImpl::ServiceComponentImpl(ServiceInfo const* aInfo) + : ServiceImplBase(m_aMutex) + , m_aMutex() + , m_info(aInfo) + { + } + + void ServiceComponentImpl::disposing() + { + ServiceImplBase::disposing(); + } + void ServiceComponentImpl::checkAlive() throw (uno::RuntimeException) + { + checkAlive("Object was disposed"); + } + void ServiceComponentImpl::checkAlive(OUString const& sMessage) throw (uno::RuntimeException) + { + if (rBHelper.bDisposed) + throw lang::DisposedException(sMessage, *this); + } + + sal_Int32 ServiceComponentImpl::countServices(ServiceInfo const* aInfo) + { + AsciiServiceName const* p= aInfo ? aInfo->serviceNames : 0; + if (p == 0) + return 0; + + sal_Int32 nCount = 0; + while (*p != 0) + { + ++nCount; + ++p; + } + + return nCount; + } + + // XTypeProvider + uno::Sequence<sal_Int8> ServiceComponentImpl::getStaticImplementationId(ServiceInfo const* pServiceInfo) + throw(uno::RuntimeException) + { + static osl::Mutex aMapMutex; + static std::map<ServiceInfo const*, ::cppu::OImplementationId> aIdMap; + + osl::MutexGuard aMapGuard(aMapMutex); + return aIdMap[pServiceInfo].getImplementationId(); + } + + uno::Sequence<sal_Int8> SAL_CALL ServiceComponentImpl::getImplementationId() + throw(uno::RuntimeException) + { + return getStaticImplementationId(m_info); + } + + // XServiceInfo + OUString SAL_CALL ServiceComponentImpl::getImplementationName( ) throw(uno::RuntimeException) + { + AsciiServiceName p= m_info ? m_info->implementationName : 0; + + return p ? OUString::createFromAscii(p) : OUString(); + } + + sal_Bool SAL_CALL ServiceComponentImpl::supportsService( const ::rtl::OUString& ServiceName ) throw(uno::RuntimeException) + { + AsciiServiceName const* p= m_info ? m_info->serviceNames : 0; + if (p == 0) + return false; + + while (*p != 0) + { + if (0 == ServiceName.compareToAscii(*p)) + return true; + ++p; + } + + return false; + } + + uno::Sequence< OUString > ServiceComponentImpl::getServiceNames(ServiceInfo const* pInfo ) throw(uno::RuntimeException) + { + sal_Int32 const nCount = countServices(pInfo); + + uno::Sequence< OUString > aServices( nCount ); + + for(sal_Int32 i= 0; i < nCount; ++i) + aServices[i] = OUString::createFromAscii(pInfo->serviceNames[i]); + + return aServices; + } + + uno::Sequence< OUString > SAL_CALL ServiceComponentImpl::getSupportedServiceNames( ) throw(uno::RuntimeException) + { + return getServiceNames( m_info ); + } + + //ServiceComponentImpl:: + +} // namespace configmgr + + diff --git a/configmgr/source/api/makefile.mk b/configmgr/source/api/makefile.mk new file mode 100644 index 000000000000..5703b6b3c4a9 --- /dev/null +++ b/configmgr/source/api/makefile.mk @@ -0,0 +1,102 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=$(PRJ)$/source$/inc +PRJNAME=configmgr +TARGET=api + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/encodename.obj \ + $(SLO)$/useradminimpl.obj \ + $(SLO)$/readaccessimpl.obj \ + $(SLO)$/confaccessfactory.obj \ + $(SLO)$/cfgupdatehelper.obj \ + $(SLO)$/nodepropset.obj \ + $(SLO)$/confreadaccess.obj \ + $(SLO)$/confgroupaccess.obj \ + $(SLO)$/confsetaccess.obj \ + $(SLO)$/confupdateimpl.obj \ + $(SLO)$/confupdateaccess.obj \ + $(SLO)$/confbaseelement.obj \ + $(SLO)$/confbaseaccess.obj \ + $(SLO)$/confaccess.obj \ + $(SLO)$/confsvccomponent.obj \ + $(SLO)$/confevents.obj \ + $(SLO)$/confeventhelpers.obj \ + $(SLO)$/confprovider.obj \ + $(SLO)$/confproviderimpl.obj \ + $(SLO)$/confchangesset.obj \ + $(SLO)$/changenotifier.obj \ + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/configmgr/source/cmdtools/makefile.mk b/configmgr/source/cmdtools/makefile.mk new file mode 100644 index 000000000000..cf830dbe237e --- /dev/null +++ b/configmgr/source/cmdtools/makefile.mk @@ -0,0 +1,121 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=$(PRJ)$/source + +PRJNAME=configmgr + +TARGET=configshutdown +TARGETTYPE=CUI +LIBTARGET=NO + +# --- Settings ----------------------------------------------------- +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- +CDEFS += -DDLL_VERSION=\"$(UPD)$(DLLPOSTFIX)\" + +APPSTDLIBS=\ + $(SALLIB) \ + $(VOSLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) + + +APP1STDLIBS = $(APPSTDLIBS) + +.IF "$(GUI)"=="UNX" +APP1TARGET= $(TARGET).bin +.ELSE +APP1TARGET= $(TARGET) +.ENDIF + +APP1OBJS= \ + $(SLO)$/configshutdown.obj + +.INCLUDE : target.mk + +#************************************************************************** +# history: +# $Log: not supported by cvs2svn $ +# Revision 1.4 2000/09/15 09:51:48 willem.vandorp +# OpenOffice header added +# +# Revision 1.3 2000/08/27 15:44:53 fs +# #78183# replaced cout/cerr with fprintf +# +# Revision 1.2 2000/08/25 13:22:39 fs +# #78116# on unx, build *.bin +# +# Revision 1.1 2000/08/25 13:02:07 fs +# common reg server related command line tools +# +# Revision 1.1 2000/06/23 08:47:33 fs +# socket related helpers/samples +# +# +# Revision 1.0 26.05.00 17:11:32 fs +#************************************************************************** + diff --git a/configmgr/source/inc/attributes.hxx b/configmgr/source/inc/attributes.hxx new file mode 100644 index 000000000000..ffd7835d81e4 --- /dev/null +++ b/configmgr/source/inc/attributes.hxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * $RCSfile: attributes.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_MISC_ATTRIBUTES_HXX_ +#define _CONFIGMGR_MISC_ATTRIBUTES_HXX_ + +#ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HPP_ +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#endif + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +/*---------------------------------------- +* +* Attributlist implementation +* +*----------------------------------------*/ + +//.......................................................................... +namespace configmgr +{ +//.......................................................................... + +struct AttributeListImpl_impl; +class AttributeListImpl : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XAttributeList > +{ +protected: + ~AttributeListImpl(); + +public: + AttributeListImpl(); + AttributeListImpl( const AttributeListImpl & ); + +public: + virtual sal_Int16 SAL_CALL getLength(void) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getNameByIndex(sal_Int16 i) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getTypeByIndex(sal_Int16 i) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getTypeByName(const ::rtl::OUString& aName) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getValueByIndex(sal_Int16 i) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getValueByName(const ::rtl::OUString& aName) throw (::com::sun::star::uno::RuntimeException); + +public: + void addAttribute( const ::rtl::OUString &sName , const ::rtl::OUString &sType , const ::rtl::OUString &sValue ); + void clear(); + +private: + struct AttributeListImpl_impl *m_pImpl; +}; + +//.......................................................................... +} // namespace configmgr +//.......................................................................... + +#endif // _CONFIGMGR_MISC_ATTRIBUTES_HXX_ + + diff --git a/configmgr/source/inc/bootstrap.hxx b/configmgr/source/inc/bootstrap.hxx new file mode 100644 index 000000000000..0273f79fd9a0 --- /dev/null +++ b/configmgr/source/inc/bootstrap.hxx @@ -0,0 +1,111 @@ +/************************************************************************* + * + * $RCSfile: bootstrap.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_BOOTSTRAP_HXX_ +#define CONFIGMGR_BOOTSTRAP_HXX_ + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif + +#ifndef _CONFIGMGR_COMMONTYPES_HXX_ +#include "commontypes.hxx" +#endif + +namespace com { namespace sun { namespace star { + + namespace uno { template <class> class Reference; } + namespace lang { class XMultiServiceFactory; } + +} } } + +#include <rtl/ustring.hxx> + +namespace configmgr +{ + namespace css = ::com::sun::star; + namespace uno = css::uno; + namespace lang = css::lang; + using ::rtl::OUString; + + class IConfigSession; + + class ConnectionSettings + { + OUString m_sSettingsFile; + public: + ConnectionSettings(); + explicit + ConnectionSettings(OUString const& aSettingsFile); + + + /** create a connection with the current settings. If the user name provided in _rSecurityOverride + is not empty, the security override will be used (if applicable), else it will be ignored + */ + IConfigSession* createConnection(uno::Reference<lang::XMultiServiceFactory> const& aServiceMgr, + const SettingsOverride& _rSettings) const; + }; + +} + +#endif // CONFIGMGR_BOOTSTRAP_HXX_ + + diff --git a/configmgr/source/inc/commontypes.hxx b/configmgr/source/inc/commontypes.hxx new file mode 100644 index 000000000000..ff89fc214c20 --- /dev/null +++ b/configmgr/source/inc/commontypes.hxx @@ -0,0 +1,129 @@ +/************************************************************************* + * + * $RCSfile: commontypes.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_COMMONTYPES_HXX_ +#define _CONFIGMGR_COMMONTYPES_HXX_ + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _UTL_STLTYPES_HXX_ +#include <unotools/stl_types.hxx> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_ +#include <com/sun/star/container/XNamed.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#include <com/sun/star/uno/Any.hxx> +#endif + +//.......................................................................... +namespace configmgr +{ +//.......................................................................... + +//========================================================================== +//= IInterface +//========================================================================== +/** abstract base class for objects which may be aquired by ORef's + (in opposite to the IReference, classes deriving from this IInterface can be + derived from XInterface, too) +*/ +class IInterface +{ +public: + virtual void SAL_CALL acquire( ) throw () = 0; + virtual void SAL_CALL release( ) throw () = 0; +}; + +//========================================================================== +//= SettingsOverride +//========================================================================== +DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Any, SettingsOverride ); + +typedef ::com::sun::star::uno::RuntimeException CantRenameException_Base; +class CantRenameException : CantRenameException_Base +{ +public: + ::rtl::OUString newName; + ::rtl::OUString oldName; + + static ::rtl::OUString message(::rtl::OUString const& sNewName, ::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed> xContext) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Object cannot be renamed") ); + } + + CantRenameException(::rtl::OUString const& sNewName, ::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed > xContext) + : CantRenameException_Base(message(sNewName,xContext), xContext) + , newName(sNewName) + , oldName(xContext->getName()) + { + } +}; + +//.......................................................................... +} // namespace configmgr +//.......................................................................... + +#endif // _CONFIGMGR_COMMONTYPES_HXX_ + + diff --git a/configmgr/source/inc/confapifactory.hxx b/configmgr/source/inc/confapifactory.hxx new file mode 100644 index 000000000000..067634cca328 --- /dev/null +++ b/configmgr/source/inc/confapifactory.hxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * $RCSfile: confapifactory.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_API_FACTORY_HXX_ +#define CONFIGMGR_API_FACTORY_HXX_ + +namespace com { namespace sun { namespace star { + namespace uno + { + class XInterface; + template <class> class Reference; + } + namespace lang + { + class XMultiServiceFactory; + } +} } } + +namespace configmgr +{ + namespace css = ::com::sun::star; + namespace uno = css::uno; + namespace lang = css::lang; + struct ServiceInfo; + + // instantiation + uno::Reference< uno::XInterface > SAL_CALL instantiateProvider(uno::Reference< lang::XMultiServiceFactory > const& rServiceManager ); + uno::Reference< uno::XInterface > SAL_CALL instantiateReadAccess(uno::Reference< lang::XMultiServiceFactory > const& rServiceManager ); + uno::Reference< uno::XInterface > SAL_CALL instantiateUpdateAccess(uno::Reference< lang::XMultiServiceFactory > const& rServiceManager ); + + uno::Reference< uno::XInterface > SAL_CALL instantiateConfigRegistry(uno::Reference< lang::XMultiServiceFactory > const& rServiceManager ); + + // Import / export + uno::Reference< uno::XInterface > SAL_CALL instantiateDataExport(uno::Reference< lang::XMultiServiceFactory > const& rServiceManager ); + const ServiceInfo* getDataExportServiceInfo(); + + uno::Reference< uno::XInterface > SAL_CALL instantiateDataImport(uno::Reference< lang::XMultiServiceFactory > const& rServiceManager ); + const ServiceInfo* getDataImportServiceInfo(); + + // service infos + const ServiceInfo* getConfigurationRegistryServiceInfo(); + +} // namespace configmgr + +#endif // CONFIGMGR_API_FACTORY_HXX_ + + diff --git a/configmgr/source/inc/confevents.hxx b/configmgr/source/inc/confevents.hxx new file mode 100644 index 000000000000..44deb33fd0b3 --- /dev/null +++ b/configmgr/source/inc/confevents.hxx @@ -0,0 +1,211 @@ +/************************************************************************* + * + * $RCSfile: confevents.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_API_EVENTS_HXX_ +#define CONFIGMGR_API_EVENTS_HXX_ + +#include "cmtreemodel.hxx" +namespace rtl { class OUString; } + +namespace configmgr +{ + using ::rtl::OUString; + + // class is still abstract, ITreeListener methods are still unimplemented + class TreeListenerImpl : private ITreeListener + { + ITreeNotifier* mySource; + public: + explicit TreeListenerImpl(ITreeNotifier* aSource = 0); + virtual ~TreeListenerImpl(); + + ITreeNotifier* rebind(ITreeNotifier* aSource); + ITreeNotifier* unbind() { return rebind(0); } + protected: + virtual void disposing(ITreeNotifier* pSource); + private: + TreeListenerImpl(TreeListenerImpl&); + void operator=(TreeListenerImpl&); + }; + + struct IConfigBroadcaster; + struct IConfigListener + { + virtual void disposing(IConfigBroadcaster* pSource) = 0; + }; + struct INodeListener : IConfigListener + { + virtual void nodeChanged(Change const& aChange, OUString const& aPath, IConfigBroadcaster* pSource) = 0; + virtual void nodeDeleted(OUString const& aPath, IConfigBroadcaster* pSource) = 0; + }; + struct IMessageHandler: IConfigListener + { + virtual void message(const OUString& rNotifyReason, sal_Int32 nNotificationId, IConfigBroadcaster* pSource) = 0; + }; + + struct IConfigBroadcaster + { + protected: + IConfigBroadcaster() {} + ~IConfigBroadcaster() {} + public: + virtual void addListener(OUString const& aName, INodeListener* pListener) = 0; + virtual void removeListener(INodeListener* pListener) = 0; + + virtual void removeNode(OUString const& aPath, bool bRemovedFromModel = false) = 0; + + virtual void addHandler(IMessageHandler* pHandler) = 0; + virtual void removeHandler(IMessageHandler* pHandler) = 0; + }; + + class ConfigChangeBroadcaster : public TreeListenerImpl, public IConfigBroadcaster + { + class Impl; + Impl* pImpl; + public: + ConfigChangeBroadcaster(ITreeNotifier* aSource = 0); + virtual ~ConfigChangeBroadcaster(); + + void rebind(ITreeNotifier* aSource); + + void broadcast(TreeChangeList const& anUpdate, sal_Bool bError = false); + + public: + // IConfigBroadcaster implementation + void addListener(OUString const& aName, INodeListener* ); + void removeListener(INodeListener*); + + void removeNode(OUString const& aPath, bool bRemovedFromModel = false); + + void addHandler(IMessageHandler* ); + void removeHandler(IMessageHandler* ); + + void dispose(); + protected: + // ITreeListener implementation + virtual void changes(TreeChangeList const& , sal_Bool _bError); + virtual void changes(sal_Int32 _nNotificationId,const ::rtl::OUString& _rNotifyReason); + }; + + class ConfigChangeMultiplexer : public IConfigBroadcaster, private INodeListener, private IMessageHandler + { + class Impl; + Impl* pImpl; + IConfigBroadcaster* m_pSource; + public: + ConfigChangeMultiplexer(IConfigBroadcaster* aSource = 0); + ConfigChangeMultiplexer(OUString const& aBasePath, IConfigBroadcaster* aSource); + virtual ~ConfigChangeMultiplexer(); + + void bind(OUString const& aBasePath, IConfigBroadcaster* aSource = 0); + void rebind(IConfigBroadcaster* aSource); + void unbind(); + + void broadcast(Change const& anUpdate, OUString const& aRelativePath, sal_Bool bError = false); + void broadcast(Change const& anUpdate); + + public: + // IConfigBroadcaster implementation + void addListener(OUString const& aName, INodeListener* ); + void removeListener(INodeListener*); + + void removeNode(OUString const& aPath, bool bRemovedFromModel = false); + + void addHandler(IMessageHandler* ); + void removeHandler(IMessageHandler* ); + + void dispose(); + protected: + bool normalizePath(OUString& aPath); + + // IConfigListener implementation + virtual void disposing(IConfigBroadcaster* pSource); + + // INodeListener implementation + virtual void nodeChanged(Change const& aChange, OUString const& aPath, IConfigBroadcaster* pSource); + virtual void nodeDeleted(OUString const& aPath, IConfigBroadcaster* pSource); + + // IMessageHandler implementation + virtual void message(const OUString& rNotifyReason, sal_Int32 nNotificationId, IConfigBroadcaster* pSource); + }; + + class ScreenedChangeMultiplexer : public ConfigChangeMultiplexer + { + typedef SubtreeChange ScreeningChange; + ScreeningChange* m_pScreeningChanges; + public: + ScreenedChangeMultiplexer(IConfigBroadcaster* aSource = 0); + ScreenedChangeMultiplexer(TreeChangeList& aScreeningTree, IConfigBroadcaster* aSource); + ScreenedChangeMultiplexer(ScreeningChange* aScreening, OUString const& aBasePath, IConfigBroadcaster* aSource); + + void bind(TreeChangeList& aScreeningTree, IConfigBroadcaster* aSource = 0); + void bind(ScreeningChange* aScreening, OUString const& aBasePath, IConfigBroadcaster* aSource = 0); + + protected: + virtual void nodeChanged(Change const& aChange, OUString const& aPath, IConfigBroadcaster* pSource); + virtual void nodeDeleted(OUString const& aPath, IConfigBroadcaster* pSource); + }; +} // namespace + +#endif // CONFIGMGR_API_EVENTS_HXX_ + + + diff --git a/configmgr/source/inc/confsvccomponent.hxx b/configmgr/source/inc/confsvccomponent.hxx new file mode 100644 index 000000000000..218ddb94c7f1 --- /dev/null +++ b/configmgr/source/inc/confsvccomponent.hxx @@ -0,0 +1,139 @@ +/************************************************************************* + * + * $RCSfile: confsvccomponent.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:40 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CONFIGMGR_API_SVCCOMPONENT_HXX_ +#define CONFIGMGR_API_SVCCOMPONENT_HXX_ + +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif + +#ifndef _CPPUHELPER_COMPBASE1_HXX_ +#include <cppuhelper/compbase1.hxx> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/Mutex.hxx> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +namespace configmgr { + + namespace css = ::com::sun::star; + namespace uno = css::uno; + namespace lang = css::lang; + using ::rtl::OUString; + + typedef sal_Char const * AsciiServiceName; + struct ServiceInfo + { + AsciiServiceName implementationName; + AsciiServiceName const * serviceNames; + }; + + typedef ::cppu::WeakComponentImplHelper1< lang::XServiceInfo > ServiceImplBase; + + class ServiceComponentImpl + : public ServiceImplBase + { + protected: + ::osl::Mutex m_aMutex; + ServiceInfo const* const m_info; + public: + ServiceComponentImpl(ServiceInfo const* aInfo); + + // XTypeProvider + virtual uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(uno::RuntimeException); + //virtual uno::Sequence<uno::Type> SAL_CALL getTypes( ) throw(uno::RuntimeException) = 0; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) throw(uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(uno::RuntimeException); + virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(uno::RuntimeException); + + // Component Helper - force override + virtual void SAL_CALL disposing() = 0; + // Component Helper - check object state + virtual void checkAlive() throw (uno::RuntimeException); + void checkAlive(char const* message) throw (uno::RuntimeException) + { checkAlive( OUString::createFromAscii(message) ); } + void checkAlive(OUString const& message) throw (uno::RuntimeException); + + // Extra helpers + static sal_Int32 countServices(ServiceInfo const* aInfo); + static uno::Sequence< OUString > getServiceNames(ServiceInfo const* aInfo) throw(uno::RuntimeException); + static uno::Sequence<sal_Int8> getStaticImplementationId(ServiceInfo const* pServiceInfo) throw(uno::RuntimeException); + + private: // no implementation + ServiceComponentImpl(ServiceComponentImpl&); + void operator=(ServiceComponentImpl&); + }; + +} // namespace configmgr + +#endif // CONFIGMGR_API_SVCCOMPONENT_HXX_ + + diff --git a/configmgr/source/inc/filehelper.hxx b/configmgr/source/inc/filehelper.hxx new file mode 100644 index 000000000000..fb9d6f3282a1 --- /dev/null +++ b/configmgr/source/inc/filehelper.hxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * $RCSfile: filehelper.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_FILEHELPER_HXX_ +#define _CONFIGMGR_FILEHELPER_HXX_ + +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif + +namespace configmgr +{ + class FileHelper + { + public: + + static sal_Int32 createBackupRemoveAndRename( + const rtl::OUString& _aFromURL, const rtl::OUString &_aToURL); + + static sal_Int32 tryToRemoveFile(const rtl::OUString& _aURL); + + static rtl::OUString createOSLErrorString(osl::FileBase::RC eError); + }; +} // namespace configmgr + +#endif diff --git a/configmgr/source/inc/oslstream.hxx b/configmgr/source/inc/oslstream.hxx new file mode 100644 index 000000000000..939227665245 --- /dev/null +++ b/configmgr/source/inc/oslstream.hxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * $RCSfile: oslstream.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_OSLSTREAM_HXX_ +#define _CONFIGMGR_OSLSTREAM_HXX_ + +#ifndef _OSL_MUTEX_HXX_ //autogen wg. ::osl::Mutex +#include <osl/mutex.hxx> +#endif + +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XOutputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#endif + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +#ifndef _UTL_UNO3_HXX_ +#include <unotools/uno3.hxx> +#endif + +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif + + +namespace configmgr +{ + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +//================================================================== +// FmUnoIOStream, +// stream zum schreiben un lesen von Daten, basieren auf File +//================================================================== + typedef ::cppu::WeakImplHelper1<stario::XInputStream> InputStreamWrapper_Base; + // needed for some compilers +class OSLInputStreamWrapper : public InputStreamWrapper_Base +{ + ::osl::Mutex m_aMutex; + ::osl::File* m_pFile; + sal_Bool m_bFileOwner : 1; + +public: + OSLInputStreamWrapper(::osl::File& _rStream); + OSLInputStreamWrapper(::osl::File* pStream, sal_Bool bOwner=sal_False); + virtual ~OSLInputStreamWrapper(); + +// UNO Anbindung + DECLARE_UNO3_AGG_DEFAULTS(OSLInputStreamWrapper, InputStreamWrapper_Base); + +// stario::XInputStream + virtual sal_Int32 SAL_CALL readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL available() throw(stario::NotConnectedException, staruno::RuntimeException); + virtual void SAL_CALL closeInput() throw(stario::NotConnectedException, staruno::RuntimeException); +}; + +//================================================================== +// FmUnoOutStream, +// Datensenke fuer Files +//================================================================== +typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamWrapper_Base; + // needed for some compilers +class OSLOutputStreamWrapper : public OutputStreamWrapper_Base +{ + ::osl::File& rFile; + +public: + OSLOutputStreamWrapper(::osl::File& _rFile) :rFile(_rFile) { } + +// UNO Anbindung + DECLARE_UNO3_AGG_DEFAULTS(OSLOutputStreamWrapper, OutputStreamWrapper_Base); + +// stario::XOutputStream + virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); +}; + +} // namespace configmgr + +#endif // _CONFIGMGR_OSLSTREAM_HXX_ + + + diff --git a/configmgr/source/inc/strdecl.hxx b/configmgr/source/inc/strdecl.hxx new file mode 100644 index 000000000000..154d11f631f3 --- /dev/null +++ b/configmgr/source/inc/strdecl.hxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * $RCSfile: strdecl.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONFIGMGR_STRDECL_HXX_ +#define _CONFIGMGR_STRDECL_HXX_ + +#ifndef _CONFIGMGR_STRINGS_HXX_ +#include "strings.hxx" +#endif + +//......................................................................... +namespace configmgr +{ +//......................................................................... + +// extern declaration for predefined strings, uncompleted + DECLARE_CONSTASCII_USTRING(TAG_VALUE); + DECLARE_CONSTASCII_USTRING(TAG_USERVALUE); + DECLARE_CONSTASCII_USTRING(TAG_VALUE_ITEM); + DECLARE_CONSTASCII_USTRING(TAG_DEFAULT_ITEM); + DECLARE_CONSTASCII_USTRING(TAG_NODEFAULT); + DECLARE_CONSTASCII_USTRING(TAG_DEFAULT); + DECLARE_CONSTASCII_USTRING(TAG_DEFAULTVALUE); + DECLARE_CONSTASCII_USTRING(TAG_DATA); + + DECLARE_CONSTASCII_USTRING(TYPE_BOOLEAN); + DECLARE_CONSTASCII_USTRING(TYPE_SHORT); + DECLARE_CONSTASCII_USTRING(TYPE_INT); + DECLARE_CONSTASCII_USTRING(TYPE_LONG); + DECLARE_CONSTASCII_USTRING(TYPE_DOUBLE); + DECLARE_CONSTASCII_USTRING(TYPE_STRING); + DECLARE_CONSTASCII_USTRING(TYPE_BINARY); + DECLARE_CONSTASCII_USTRING(TYPE_SET); + DECLARE_CONSTASCII_USTRING(TYPE_GROUP); + + DECLARE_CONSTASCII_USTRING(ATTR_ENCODING_HEX); + DECLARE_CONSTASCII_USTRING(ATTR_NAME); + DECLARE_CONSTASCII_USTRING(ATTR_TYPE); + DECLARE_CONSTASCII_USTRING(ATTR_GROUP); + DECLARE_CONSTASCII_USTRING(ATTR_DERIVED); + DECLARE_CONSTASCII_USTRING(ATTR_INSTANCE); + DECLARE_CONSTASCII_USTRING(ATTR_ENCODING); + DECLARE_CONSTASCII_USTRING(ATTR_MODE); + DECLARE_CONSTASCII_USTRING(ATTR_PATH); + DECLARE_CONSTASCII_USTRING(ATTR_DERIVED_LIST); + DECLARE_CONSTASCII_USTRING(ATTR_VALUE_ADD); + DECLARE_CONSTASCII_USTRING(ATTR_VALUE_REMOVE); + + DECLARE_CONSTASCII_USTRING(PARAM_OBJECT); + DECLARE_CONSTASCII_USTRING(PARAM_NAME); + DECLARE_CONSTASCII_USTRING(PARAM_ISNEWOBJECT); + + DECLARE_CONSTASCII_USTRING(XML_CDATA); +} // namespace configmgr +#endif + diff --git a/configmgr/source/inc/strings.hxx b/configmgr/source/inc/strings.hxx new file mode 100644 index 000000000000..9921b2efc597 --- /dev/null +++ b/configmgr/source/inc/strings.hxx @@ -0,0 +1,112 @@ +/************************************************************************* + * + * $RCSfile: strings.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_STRINGS_HXX_ +#define _CONFIGMGR_STRINGS_HXX_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + + +//......................................................................... +namespace configmgr +{ +//......................................................................... + +struct UStringDescription +{ + const sal_Char* m_pZeroTerminatedName; + sal_Int32 m_nLen; + rtl_TextEncoding m_encoding; + + UStringDescription(const sal_Char* _pName, sal_Int32 _nLen, rtl_TextEncoding _encoding) + { + m_pZeroTerminatedName = _pName; + m_nLen = _nLen; + m_encoding = _encoding; + m_aString = ::rtl::OUString(_pName, _nLen, _encoding); + } + operator ::rtl::OUString() const { + return m_aString; + } + +private: + rtl::OUString m_aString; + UStringDescription(); +}; + +#define DECLARE_CONSTASCII_USTRING(name) \ + extern ::configmgr::UStringDescription name + +#define IMPLEMENT_CONSTASCII_USTRING(name, asciivalue) \ + ::configmgr::UStringDescription name(RTL_CONSTASCII_USTRINGPARAM(asciivalue)) + +//......................................................................... +} // namespace frm +//......................................................................... + +#endif _CONFIGMGR_STRINGS_HXX_ + diff --git a/configmgr/source/inc/tracer.hxx b/configmgr/source/inc/tracer.hxx new file mode 100644 index 000000000000..27eba4317f86 --- /dev/null +++ b/configmgr/source/inc/tracer.hxx @@ -0,0 +1,180 @@ +/************************************************************************* + * + * $RCSfile: tracer.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_TRACER_HXX_ +#define _CONFIGMGR_TRACER_HXX_ + +#if defined(DEBUG) || defined(_DEBUG) +#define CFG_ENABLE_TRACING +#endif + +#ifdef CFG_ENABLE_TRACING + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#include <rtl/string.hxx> +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#include <stdarg.h> +#include <stdio.h> + +#define OUSTRING2ASCII(rtlOUString) ::rtl::OString((rtlOUString).getStr(), (rtlOUString).getLength(), RTL_TEXTENCODING_ASCII_US).getStr() + +#define CFG_TRACE_INFO OTraceIndent aIndent; OConfigTracer::traceInfo +#define CFG_TRACE_WARNING OTraceIndent aIndent; OConfigTracer::traceWarning +#define CFG_TRACE_ERROR OTraceIndent aIndent; OConfigTracer::traceError +#define CFG_TRACE_INFO_NI OConfigTracer::traceInfo +#define CFG_TRACE_WARNING_NI OConfigTracer::traceWarning +#define CFG_TRACE_ERROR_NI OConfigTracer::traceError + +#define CFG_TRACE_TO_DEVICE OConfigTracer::traceToVirtualDevice + +namespace configmgr +{ + +struct OTracerSetup; +class OConfigTracer +{ + friend class OTraceIndent; + +protected: + static ::osl::Mutex s_aMutex; + static OTracerSetup* s_pImpl; + +private: + OConfigTracer(); // never implemented, no instantiation of this class allowed, only static members + +public: + static void traceInfo(const sal_Char* _pFormat, ...); + static void traceWarning(const sal_Char* _pFormat, ...); + static void traceError(const sal_Char* _pFormat, ...); + + static void traceToVirtualDevice(const sal_Char* _pDeviceName, const sal_Char* _pFormat, ...); + + static ::rtl::OString getTimeStamp(); + +protected: + static void implTrace(const sal_Char* _pType, const sal_Char* _pFormat, va_list args); + + static void inc(); + static void dec(); + + static void indent(); + + static void ensureData(); + static void ensureInitalized(); +}; + +class OTraceIndent +{ +public: + OTraceIndent() { OConfigTracer::inc(); } + ~OTraceIndent() { OConfigTracer::dec(); } +}; + +} // namespace configmgr + +#else // !(defined(DEBUG) || defined(_DEBUG)) + +#include <stdio.h> + +#define OUSTRING2ASCII(rtlOUString) "nothing" + +#define CFG_TRACE_INFO 1 ? (0) : printf +#define CFG_TRACE_WARNING 1 ? (0) : printf +#define CFG_TRACE_ERROR 1 ? (0) : printf +#define CFG_TRACE_INFO_NI 1 ? (0) : printf +#define CFG_TRACE_WARNING_NI 1 ? (0) : printf +#define CFG_TRACE_ERROR_NI 1 ? (0) : printf +#define CFG_TRACE_TO_DEVICE 1 ? (0) : printf + +#endif // (defined(DEBUG) || defined(_DEBUG)) + +#endif // _CONFIGMGR_TRACER_HXX_ + +//************************************************************************** +// history: +// $Log: not supported by cvs2svn $ +// Revision 1.6 2000/09/15 09:51:50 willem.vandorp +// OpenOffice header added +// +// Revision 1.5 2000/08/30 10:00:40 fs +// getTimeStamp +// +// Revision 1.4 2000/08/20 12:52:14 fs +// #77860# introduced an impl class; introduces virtual trace devices +// +// Revision 1.3 2000/08/10 11:37:30 hjs +// filled defines with correct dummies +// +// Revision 1.2 2000/08/10 06:53:08 fs +// m_bInitialized +// +// Revision 1.1 2000/08/09 18:53:41 fs +// helper classes for tracing +// +// +// Revision 1.0 09.08.00 13:10:04 fs +//************************************************************************** + diff --git a/configmgr/source/inc/treeactions.hxx b/configmgr/source/inc/treeactions.hxx new file mode 100644 index 000000000000..70b21d21b23e --- /dev/null +++ b/configmgr/source/inc/treeactions.hxx @@ -0,0 +1,111 @@ +/************************************************************************* + * + * $RCSfile: treeactions.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_TREEACTIONS_HXX_ +#define _CONFIGMGR_TREEACTIONS_HXX_ + +#ifndef CONFIGMGR_CMTREEMODEL_HXX +#include "cmtreemodel.hxx" +#endif + +//.......................................................................... +namespace configmgr +{ +//.......................................................................... + +//========================================================================== +//= OChangeActionCounter +//========================================================================== +/** collects meta data about a changes tree +*/ +struct OChangeActionCounter : public ChangeTreeAction +{ + sal_Int32 nValues, nAdds, nAddUsers, nRemoves; + sal_Bool bDifferentSetActionLevels; + + OChangeActionCounter() :nValues(0), nAdds(0), nAddUsers(0), nRemoves(0), bDifferentSetActionLevels(sal_False) { } + + virtual void handle(ValueChange const& aValueNode) { ++nValues; } + virtual void handle(AddNode const& aAddNode); // moved to + virtual void handle(RemoveNode const& aRemoveNode) { ++nRemoves; } + virtual void handle(SubtreeChange const& aSubtree) + { + sal_Int32 nOldAdds(nAdds), nOldRemoves(nRemoves); + applyToChildren(aSubtree); + if ( ( nOldAdds + && (nAdds > nOldAdds) + ) + || ( nOldRemoves + && (nRemoves > nOldRemoves) + ) + ) + bDifferentSetActionLevels = sal_True; + } +}; + + +//.......................................................................... +} // namespace configmgr +//.......................................................................... + +#endif // _CONFIGMGR_TREEACTIONS_HXX_ + + diff --git a/configmgr/source/inc/typeconverter.hxx b/configmgr/source/inc/typeconverter.hxx new file mode 100644 index 000000000000..7c72df9c2587 --- /dev/null +++ b/configmgr/source/inc/typeconverter.hxx @@ -0,0 +1,112 @@ +/************************************************************************* + * + * $RCSfile: typeconverter.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef CONFIGMGR_TYPECONVERTER_HXX +#define CONFIGMGR_TYPECONVERTER_HXX + +#ifndef _COM_SUN_STAR_SCRIPT_XTYPECONVERTER_HPP_ +#include <com/sun/star/script/XTypeConverter.hpp> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + +namespace configmgr +{ + namespace staruno = ::com::sun::star::uno; + namespace starscript = ::com::sun::star::script; + + // UNO Type handling + staruno::Type getSequenceElementType(staruno::Type const& rSequenceType); + + staruno::Type getBasicType(staruno::Type const& rType, bool& bSequence); + inline + staruno::Type getBasicType(staruno::Type const& rType) + { bool dummy; return getBasicType(rType,dummy); } + + // Any Conversion + staruno::Any toAny(const staruno::Reference< starscript::XTypeConverter >& xTypeConverter, const ::rtl::OUString& _rValue,const staruno::TypeClass& _rTypeClass) throw( starscript::CannotConvertException ); + rtl::OUString toString(const staruno::Reference< starscript::XTypeConverter >& xTypeConverter, const staruno::Any& rValue) throw( starscript::CannotConvertException ); + + // Type conversion + staruno::TypeClass toTypeClass(const ::rtl::OUString& _rType); + ::rtl::OUString toTypeName(const staruno::TypeClass& _rTypeClass); + + staruno::Type toType(const ::rtl::OUString& _rsType); + staruno::Type toListType(const ::rtl::OUString& _rsElementType); + ::rtl::OUString toTypeName(const staruno::Type& _rType); + + inline + staruno::Type toType(const ::rtl::OUString& _rsSimpleType, bool isList) + { + return isList ? toListType(_rsSimpleType) : toType(_rsSimpleType); + } + + inline staruno::Type getBinaryType() { return ::getCppuType(static_cast<staruno::Sequence<sal_Int8> const*>(0)); } + + +} // namespace configmgr + +#endif /* CONFIGMGR_TYPECONVERTER_HXX */ diff --git a/configmgr/source/misc/configunoreg.cxx b/configmgr/source/misc/configunoreg.cxx new file mode 100644 index 000000000000..ad01d187abd9 --- /dev/null +++ b/configmgr/source/misc/configunoreg.cxx @@ -0,0 +1,490 @@ +/************************************************************************* + * + * $RCSfile: configunoreg.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif +#ifndef _UNO_LBNAMES_H_ +#include <uno/lbnames.h> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#ifndef CONFIGMGR_API_FACTORY_HXX_ +#include "confapifactory.hxx" +#endif + +#ifndef CONFIGMGR_API_SVCCOMPONENT_HXX_ +#include "confsvccomponent.hxx" +#endif +#ifndef CONFIGMGR_API_PROVIDER_HXX_ +#include "confprovider.hxx" +#endif + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ +#include <cppuhelper/implbase2.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#ifndef _UTL_STLTYPES_HXX_ +#include <unotools/stl_types.hxx> +#endif + +/********************************************************************************************/ + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::registry::XRegistryKey; +using ::com::sun::star::lang::XSingleServiceFactory; +using ::com::sun::star::lang::XMultiServiceFactory; +using configmgr::ServiceInfo; +using configmgr::AsciiServiceName; + +#define THISREF() static_cast< ::cppu::OWeakObject* >(this) + + +typedef Reference< XSingleServiceFactory > (SAL_CALL * createFactoryFunc) + ( + const Reference< XMultiServiceFactory > & rServiceManager, + const OUString & rComponentName, + ::cppu::ComponentInstantiation pCreateFunction, + const Sequence< OUString > & rServiceNames + ); + +// *************************************************************************************** + +namespace configmgr +{ + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + using namespace ::cppu; + using namespace ::osl; + +//======================================================================================= +//= OProviderFactory +//======================================================================================= + typedef ::cppu::WeakImplHelper1< ::com::sun::star::lang::XSingleServiceFactory > OProviderFactory_Base; + /** a special factory for the configuration provider, which implements some kind of + "shared multiple instances" factory. + */ + class OProviderFactory : public OProviderFactory_Base + { + protected: + ::osl::Mutex m_aMutex; + ::cppu::ComponentInstantiation m_pObjectCreator; + Reference< XMultiServiceFactory > m_xORB; + Reference< XInterface > m_xDefaultProvider; + + typedef ::com::sun::star::uno::WeakReference< XInterface > ProviderReference; + DECLARE_STL_USTRINGACCESS_MAP(ProviderReference, UserSpecificProvider); + UserSpecificProvider m_aUserProvider; + + public: + OProviderFactory( + const Reference< XMultiServiceFactory >& _rxORB, + ::cppu::ComponentInstantiation _pObjectCreator); + + virtual Reference< XInterface > SAL_CALL createInstance( ) throw(Exception, RuntimeException); + virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException); + + Reference< XInterface > createProvider(); + Reference< XInterface > createProviderWithArguments(const Sequence< Any >& _rArguments); + + protected: + void ensureDefaultProvider(); + }; + + //======================================================================================= + //= OProviderFactory + //======================================================================================= + //--------------------------------------------------------------------------------------- + OProviderFactory::OProviderFactory(const Reference< XMultiServiceFactory >& _rxORB, ::cppu::ComponentInstantiation _pObjectCreator) + :m_pObjectCreator(_pObjectCreator) + ,m_xORB(_rxORB) + { + } + + //--------------------------------------------------------------------------------------- + void OProviderFactory::ensureDefaultProvider() + { + MutexGuard aGuard(m_aMutex); + if (m_xDefaultProvider.is()) + return; + m_xDefaultProvider = (*m_pObjectCreator)(m_xORB); + + // initialize it with an empty sequence, thus we ensure the provider establishes it's connection + Reference< XInitialization > xProvInit(m_xDefaultProvider, UNO_QUERY); + if (xProvInit.is()) + xProvInit->initialize(Sequence< Any >()); + + // TODO : we need direct access to the provider implementation. This way we won't need the XInitialization + // interface, and we don't need this weird behaviour of initializing with an empty argument sequence + } + + //--------------------------------------------------------------------------------------- + Reference< XInterface > OProviderFactory::createProvider() + { + MutexGuard aGuard(m_aMutex); + ensureDefaultProvider(); + return m_xDefaultProvider; + } + + //--------------------------------------------------------------------------------------- + Reference< XInterface > OProviderFactory::createProviderWithArguments(const Sequence< Any >& _rArguments) + { + MutexGuard aGuard(m_aMutex); + ::rtl::OUString sUser; + // #78409 + // if a provider is queried with a password, we always create a new instance for him, + // as don't wan't to the passwords for the user. + ::rtl::OUString sPassword; + bool bPasswordUsed = false; + + const Any* pArguments = _rArguments.getConstArray(); + PropertyValue aCurrentArg; + for (sal_Int32 i=0; i<_rArguments.getLength(); ++i, ++pArguments) + { + if (!((*pArguments) >>= aCurrentArg)) + throw IllegalArgumentException(::rtl::OUString::createFromAscii("Arguments have to be com.sun.star.beans.PropertyValue's."), NULL, i); + if (0 == aCurrentArg.Name.compareToAscii("user")) + { + if (!(aCurrentArg.Value >>= sUser) || !sUser.getLength()) + throw IllegalArgumentException(::rtl::OUString::createFromAscii("The user name specified is invalid."), NULL, i); + } + + // sesions which query for a password are always one instance + if (0 == aCurrentArg.Name.compareToAscii("password")) + { + bPasswordUsed = true; + if (!(aCurrentArg.Value >>= sPassword)) + throw IllegalArgumentException(::rtl::OUString::createFromAscii("The password specified is invalid."), NULL, i); + } + } + + Reference< XInterface > xThisUsersProvider; + if (!bPasswordUsed) + { + UserSpecificProviderIterator aExistentProvider = m_aUserProvider.find(sUser); + if (m_aUserProvider.end() != aExistentProvider) + xThisUsersProvider = aExistentProvider->second; + } + + if (!xThisUsersProvider.is()) + { + xThisUsersProvider = (*m_pObjectCreator)(m_xORB); + if (!bPasswordUsed) + m_aUserProvider[sUser] = xThisUsersProvider; + + // initialize it + Reference< XInitialization > xProvInit(xThisUsersProvider, UNO_QUERY); + if (xProvInit.is()) + xProvInit->initialize(_rArguments); + } + + return xThisUsersProvider; + } + + //--------------------------------------------------------------------------------------- + Reference< XInterface > SAL_CALL OProviderFactory::createInstance( ) throw(Exception, RuntimeException) + { + // default provider + return createProvider(); + } + + //--------------------------------------------------------------------------------------- + Reference< XInterface > SAL_CALL OProviderFactory::createInstanceWithArguments( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException) + { + return createProviderWithArguments(_rArguments); + } + + //======================================================================================= + Reference< XSingleServiceFactory > SAL_CALL createProviderFactory( + const Reference< XMultiServiceFactory > & rServiceManager, + const OUString & rComponentName, + ::cppu::ComponentInstantiation pCreateFunction, + const Sequence< OUString > & rServiceNames + ) + { + OSL_ENSHURE(0 == rComponentName.compareToAscii(ConfigurationProvider::staticServiceInfo.implementationName), + "configmgr::createProviderFactory : invalid argument !"); + return new OProviderFactory(rServiceManager, pCreateFunction); + } + +} // namespace configmgr + +// *************************************************************************************** +// +// Die vorgeschriebene C-Api muss erfuellt werden! +// Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen. +// + +//--------------------------------------------------------------------------------------- +void REGISTER_PROVIDER( + const OUString& aServiceImplName, + const Sequence<OUString>& Services, + const Reference< XRegistryKey > & xKey) +{ + OUString aMainKeyName(OUString(RTL_CONSTASCII_USTRINGPARAM("/"))); + aMainKeyName += aServiceImplName; + aMainKeyName += OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES")); + + Reference< XRegistryKey > xNewKey( xKey->createKey(aMainKeyName) ); + OSL_ENSHURE(xNewKey.is(), "CONFMGR::component_writeInfo : could not create a registry key !"); + + for (sal_uInt32 i=0; i<Services.getLength(); ++i) + xNewKey->createKey(Services[i]); +} + + +//--------------------------------------------------------------------------------------- +void RegisterService( + const ServiceInfo* pInfo, + const Reference< XRegistryKey > & xKey) +{ + if (pInfo == 0 || pInfo->serviceNames==0 || pInfo->implementationName==0) + return; + + OUString aMainKeyName(OUString(RTL_CONSTASCII_USTRINGPARAM("/"))); + aMainKeyName += OUString::createFromAscii(pInfo->implementationName); + aMainKeyName += OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES")); + + Reference< XRegistryKey > xNewKey( xKey->createKey(aMainKeyName) ); + OSL_ENSHURE(xNewKey.is(), "CONFMGR::component_writeInfo : could not create a registry key !"); + + AsciiServiceName const* p = pInfo->serviceNames; + if (p != 0) + for( ; *p; ++p) + { + xNewKey->createKey(OUString::createFromAscii(*p)); + } +} + +//--------------------------------------------------------------------------------------- +struct ProviderRequest +{ + Reference< XSingleServiceFactory > xRet; + Reference< XMultiServiceFactory > const xServiceManager; + OUString const sImplementationName; + + ProviderRequest( + void* pServiceManager, + sal_Char const* pImplementationName + ) + : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager)) + , sImplementationName(OUString::createFromAscii(pImplementationName)) + { + } + + inline + sal_Bool CREATE_PROVIDER( + const OUString& Implname, + const Sequence< OUString > & Services, + ::cppu::ComponentInstantiation Factory, + createFactoryFunc creator + ) + { + if (!xRet.is() && (Implname == sImplementationName)) + try + { + OSL_ENSHURE(!xRet.is(), "CREATE_PROVIDER : invalid : already have a return value !"); + if (xRet.is()) + xRet->release(); + + xRet = creator( xServiceManager, sImplementationName,Factory, Services); + OSL_ENSHURE(xRet.is(), "CREATE_PROVIDER : invalid return value !"); + + if (xRet.is()) + xRet->acquire(); + // we want to transport the interface pointer as flat C void pointer, so this prevents deletion + } + catch(...) + { + } + return xRet.is(); + } + + inline + sal_Bool CreateProvider( + const ServiceInfo* pInfo, + ::cppu::ComponentInstantiation Factory, + createFactoryFunc creator + ) + { + OSL_ENSHURE(!xRet.is(), "CreateProvider : invalid : we already have a return value !"); + if (xRet.is()) + return true; //xRet->release(); + + if (!xRet.is() && pInfo!=0 && (0 == sImplementationName.compareToAscii(pInfo->implementationName))) + try + { + const Sequence< OUString > Services= configmgr::ServiceComponentImpl::getServiceNames(pInfo); + + xRet = creator( xServiceManager, OUString::createFromAscii(pInfo->implementationName),Factory, Services); + OSL_ENSHURE(xRet.is(), "CreateProvider : WHERE IS THE return value !"); + + if (xRet.is()) + xRet->acquire(); + // we want to transport the interface pointer as flat C void pointer, so this prevents deletion + } + catch(...) + { + } + return xRet.is(); + } + + void* getProvider() const { return xRet.get(); } +}; + +//--------------------------------------------------------------------------------------- + +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment **ppEnv + ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//--------------------------------------------------------------------------------------- +extern "C" sal_Bool SAL_CALL component_writeInfo( + void* pServiceManager, + void* pRegistryKey + ) +{ + if (pRegistryKey) + try + { + Reference< XRegistryKey > xKey(reinterpret_cast<XRegistryKey*>(pRegistryKey)); + + RegisterService(&configmgr::ConfigurationProvider::staticServiceInfo, xKey); + + RegisterService(configmgr::getConfigurationRegistryServiceInfo(), xKey); + + // im/export + RegisterService(configmgr::getDataExportServiceInfo(), xKey); + RegisterService(configmgr::getDataImportServiceInfo(), xKey); + + return sal_True; + } + catch (::com::sun::star::registry::InvalidRegistryException& ) + { + OSL_ENSHURE(sal_False, "SBA::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !"); + } + + return sal_False; +} + +//--------------------------------------------------------------------------------------- +extern "C" void* SAL_CALL component_getFactory( + const sal_Char* pImplementationName, + void* pServiceManager, + void* pRegistryKey) +{ + void* pRet = 0; + if (pServiceManager) + { + ProviderRequest aReq(pServiceManager,pImplementationName); + + aReq.CreateProvider( + &configmgr::ConfigurationProvider::staticServiceInfo, + &configmgr::instantiateProvider, + ::configmgr::createProviderFactory) + || + aReq.CreateProvider( + configmgr::getConfigurationRegistryServiceInfo(), + &configmgr::instantiateConfigRegistry, + ::cppu::createSingleFactory) + || + /* Export */ + aReq.CreateProvider( + configmgr::getDataExportServiceInfo(), + &configmgr::instantiateDataExport, + ::cppu::createSingleFactory) + || + /* Import */ + aReq.CreateProvider( + configmgr::getDataImportServiceInfo(), + &configmgr::instantiateDataImport, + ::cppu::createSingleFactory) + || + false; + + pRet = aReq.getProvider(); + } + + return pRet; +}; +//--------------------------------------------------------------------------------------- + diff --git a/configmgr/source/misc/filehelper.cxx b/configmgr/source/misc/filehelper.cxx new file mode 100644 index 000000000000..f7bb7ec7138e --- /dev/null +++ b/configmgr/source/misc/filehelper.cxx @@ -0,0 +1,320 @@ +/************************************************************************* + * + * $RCSfile: filehelper.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _RTL_USTRING_H_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif + +#ifndef _CONFIGMGR_FILEHELPER_HXX_ +#include "filehelper.hxx" +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + + +namespace configmgr +{ +using namespace ::osl; + +#define ASCII(x) rtl::OUString::createFromAscii(x) +// ---------------------------- tryToRemoveFile ---------------------------- + sal_Int32 FileHelper::tryToRemoveFile(const rtl::OUString& _aURL) + { + { + File aFile(_aURL); + FileBase::RC eError = aFile.open(OpenFlag_Read); + if (eError != osl_File_E_None) + { + // IF not exists + return 0; + } + aFile.close(); + } + FileBase::RC eError = File::remove(_aURL); + if (eError != osl_File_E_None) + { + rtl::OUString sError = ASCII("tryToRemoveFile: "); + sError += FileHelper::createOSLErrorString(eError); + sError += ASCII("\n with URL: "); + sError += _aURL; + rtl::OString aStr = rtl::OUStringToOString(sError,RTL_TEXTENCODING_ASCII_US); + OSL_ENSHURE(0, aStr.getStr()); + return 1; + } + return 0; + } + +// ----------------------------------------------------------------------------- + sal_Int32 FileHelper::createBackupRemoveAndRename( + const rtl::OUString& _aFromURL, const rtl::OUString &_aToURL) + { + // remove FromURL + // rename ToURL to FromURL + if (FileHelper::tryToRemoveFile(_aFromURL) != 0) + return 1; + + FileBase::RC eError = File::move(_aToURL, _aFromURL); + if (eError != osl_File_E_None) + { + rtl::OUString sError = ASCII("createBackupAndRemove: ") + FileHelper::createOSLErrorString(eError) + ASCII("\n with URL: ") + _aFromURL; + rtl::OString aStr = rtl::OUStringToOString(sError,RTL_TEXTENCODING_ASCII_US); + OSL_ENSHURE(0, aStr.getStr()); + return 2; + } + return 0; + } +// ------------------ Create a string from FileBase::RC Error ------------------ + rtl::OUString FileHelper::createOSLErrorString(FileBase::RC eError) + { + rtl::OUString aRet; + switch(eError) + { + case osl_File_E_None: + aRet = ASCII(""); + break; + + case osl_File_E_PERM: + aRet = ASCII("Operation not permitted"); + break; + + case osl_File_E_NOENT: + aRet = ASCII("No such file or directory"); + break; + + case osl_File_E_SRCH: + aRet = ASCII("unknown error: osl_File_E_SRCH"); + break; + + case osl_File_E_INTR: + aRet = ASCII("function call was interrupted"); + break; + + case osl_File_E_IO: + aRet = ASCII("I/O error"); + break; + + case osl_File_E_NXIO: + aRet = ASCII("No such device or address"); + break; + + case osl_File_E_2BIG: + aRet = ASCII("unknown error: osl_File_E_2BIG"); + break; + + case osl_File_E_NOEXEC: + aRet = ASCII("unknown error: osl_File_E_NOEXEC"); + break; + + case osl_File_E_BADF: + aRet = ASCII("Bad file"); + break; + + case osl_File_E_CHILD: + aRet = ASCII("unknown error: osl_File_E_CHILD"); + break; + + case osl_File_E_AGAIN: + aRet = ASCII("Operation would block"); + break; + + case osl_File_E_NOMEM: + aRet = ASCII("not enough memory for allocating structures"); + break; + + case osl_File_E_ACCES: + aRet = ASCII("Permission denied"); + break; + + case osl_File_E_FAULT: + aRet = ASCII("Bad address"); + break; + + case osl_File_E_BUSY: + aRet = ASCII("Text file busy"); + break; + + case osl_File_E_EXIST: + aRet = ASCII("File exists"); + break; + + case osl_File_E_XDEV: + aRet = ASCII("unknown error: osl_File_E_XDEV"); + break; + + case osl_File_E_NODEV: + aRet = ASCII("No such device"); + break; + + case osl_File_E_NOTDIR: + aRet = ASCII("Not a directory"); + break; + + case osl_File_E_ISDIR: + aRet = ASCII("Is a director"); + break; + + case osl_File_E_INVAL: + aRet = ASCII("the format of the parameters was not valid"); + break; + + case osl_File_E_NFILE: + aRet = ASCII("too many open files in the system"); + break; + + case osl_File_E_MFILE: + aRet = ASCII("too many open files used by the process"); + break; + + case osl_File_E_NOTTY: + aRet = ASCII("unknown error: osl_File_E_NOTTY"); + break; + + case osl_File_E_FBIG: + aRet = ASCII("File too large"); + break; + + case osl_File_E_NOSPC: + aRet = ASCII("No space left on device"); + break; + + case osl_File_E_SPIPE: + aRet = ASCII("unknown error: osl_File_E_SPIPE"); + break; + + case osl_File_E_ROFS: + aRet = ASCII("Read-only file system"); + break; + + case osl_File_E_MLINK: + aRet = ASCII("Too many links"); + break; + + case osl_File_E_PIPE: + aRet = ASCII("unknown error: osl_File_E_PIPE"); + break; + + case osl_File_E_DOM: + aRet = ASCII("unknown error: osl_File_E_DOM"); + break; + + case osl_File_E_RANGE: + aRet = ASCII("unknown error: osl_File_E_RANGE"); + break; + + case osl_File_E_DEADLK: + aRet = ASCII("unknown error: osl_File_E_DEADLK"); + break; + + case osl_File_E_NAMETOOLONG: + aRet = ASCII("File name too long"); + break; + + case osl_File_E_NOLCK: + aRet = ASCII("No record locks available"); + break; + + case osl_File_E_NOSYS: + aRet = ASCII("Function not implemente"); + break; + + case osl_File_E_NOTEMPTY: + aRet = ASCII("Directory not empt"); + break; + + case osl_File_E_LOOP: + aRet = ASCII("Too many symbolic links encountered"); + break; + + case osl_File_E_ILSEQ: + aRet = ASCII("unknown error: osl_File_E_ILSEQ"); + break; + + case osl_File_E_NOLINK: + aRet = ASCII("Link has been severed"); + break; + + case osl_File_E_MULTIHOP: + aRet = ASCII("Multihop attempted"); + break; + + case osl_File_E_USERS: + aRet = ASCII("unknown error: osl_File_E_USERS"); + break; + + case osl_File_E_OVERFLOW: + aRet = ASCII("Value too large for defined data type"); + break; + + /* unmapped error: always last entry in enum! */ + case osl_File_E_invalidError: + aRet = ASCII("unmapped Error"); + break; + } + return aRet; + } +} // namespace configmgr diff --git a/configmgr/source/misc/makefile.mk b/configmgr/source/misc/makefile.mk new file mode 100644 index 000000000000..38808828d11e --- /dev/null +++ b/configmgr/source/misc/makefile.mk @@ -0,0 +1,100 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=$(PRJ)$/source +PRJNAME=configmgr +TARGET=misc + +#ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +EXCEPTIONSFILES = \ + $(SLO)$/saxtools.obj \ + $(SLO)$/oslstream.obj \ + $(SLO)$/attributes.obj \ + $(SLO)$/confname.obj \ + $(SLO)$/configmodule.obj \ + $(SLO)$/configunoreg.obj \ + +SLOFILES= \ + $(SLO)$/tracer.obj \ + $(SLO)$/saxtools.obj \ + $(SLO)$/oslstream.obj \ + $(SLO)$/attributes.obj \ + $(SLO)$/confname.obj \ + $(SLO)$/configmodule.obj \ + $(SLO)$/configunoreg.obj \ + $(SLO)$/synchronize.obj \ + $(SLO)$/filehelper.obj \ + $(SLO)$/strimpl.obj \ + $(SLO)$/strconverter.obj \ + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/configmgr/source/misc/oslstream.cxx b/configmgr/source/misc/oslstream.cxx new file mode 100644 index 000000000000..1fe03b22ec7e --- /dev/null +++ b/configmgr/source/misc/oslstream.cxx @@ -0,0 +1,239 @@ +/************************************************************************* + * + * $RCSfile: oslstream.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_OSLSTREAM_HXX_ +#include "oslstream.hxx" +#endif + +//#ifndef _STREAM_HXX //autogen +//#include <tools/stream.hxx> +//#endif +//#ifndef _TOOLS_DEBUG_HXX +//#include <tools/debug.hxx> +//#endif + +namespace configmgr +{ + using namespace osl; + +//------------------------------------------------------------------ +OSLInputStreamWrapper::OSLInputStreamWrapper( File& _rFile ) + :m_pFile(&_rFile) + ,m_bFileOwner(sal_False) +{ +} + +//------------------------------------------------------------------ +OSLInputStreamWrapper::OSLInputStreamWrapper( File* pStream, sal_Bool bOwner ) + :m_pFile( pStream ) + ,m_bFileOwner( bOwner ) +{ +} + +//------------------------------------------------------------------ +OSLInputStreamWrapper::~OSLInputStreamWrapper() +{ + if( m_bFileOwner ) + delete m_pFile; +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OSLInputStreamWrapper::readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) + throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + if (nBytesToRead < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + ::osl::MutexGuard aGuard( m_aMutex ); + + aData.realloc(nBytesToRead); + + sal_uInt64 nRead = 0; + FileBase::RC eError = m_pFile->read((void*)aData.getArray(), nBytesToRead, nRead); + if (eError != osl_File_E_None) + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + // Wenn gelesene Zeichen < MaxLength, staruno::Sequence anpassen + if (nRead < (sal_uInt32)nBytesToRead) + aData.realloc( nRead ); + + return nRead; +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OSLInputStreamWrapper::readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + if (nMaxBytesToRead < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + /* + if (m_pFile->IsEof()) + { + aData.realloc(0); + return 0; + } + else + */ + return readBytes(aData, nMaxBytesToRead); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OSLInputStreamWrapper::skipBytes(sal_Int32 nBytesToSkip) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + sal_uInt64 nCurrentPos; + m_pFile->getPos(nCurrentPos); + + sal_uInt64 nNewPos = nCurrentPos + nBytesToSkip; + FileBase::RC eError = m_pFile->setPos(osl_Pos_Absolut, nNewPos); + if (eError != osl_File_E_None) + { + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + } + +#ifdef DBG_UTIL + m_pFile->getPos(nCurrentPos); + volatile int dummy = 0; // to take a look at last changes ;-) +#endif +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OSLInputStreamWrapper::available() throw( stario::NotConnectedException, staruno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + sal_uInt64 nPos; + FileBase::RC eError = m_pFile->getPos(nPos); + if (eError != osl_File_E_None) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + sal_uInt64 nDummy = 0; + eError = m_pFile->setPos(Pos_End, nDummy); + if (eError != osl_File_E_None) + throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + sal_uInt64 nAvailable; + eError = m_pFile->getPos(nAvailable); + if (eError != osl_File_E_None) + throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + nAvailable = nAvailable - nPos; + eError = m_pFile->setPos(Pos_Absolut, nPos); + if (eError != osl_File_E_None) + throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + return nAvailable; +} + +//------------------------------------------------------------------------------ +void SAL_CALL OSLInputStreamWrapper::closeInput() throw( stario::NotConnectedException, staruno::RuntimeException ) +{ + if (!m_pFile) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + m_pFile->close(); + if (m_bFileOwner) + delete m_pFile; + + m_pFile = NULL; +} + +/*************************************************************************/ +// stario::XOutputStream +//------------------------------------------------------------------------------ +void SAL_CALL OSLOutputStreamWrapper::writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + sal_uInt64 nWritten; + if (aData.getLength() != 0) + { + FileBase::RC eError = rFile.write(aData.getConstArray(),aData.getLength(), nWritten); + if (eError != osl_File_E_None || nWritten != aData.getLength()) + { + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + } + } +} + + +//------------------------------------------------------------------ +void SAL_CALL OSLOutputStreamWrapper::flush() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ +} + +//------------------------------------------------------------------ +void SAL_CALL OSLOutputStreamWrapper::closeOutput() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + rFile.close(); +} + +} // namespace configmgr + + diff --git a/configmgr/source/misc/strimpl.cxx b/configmgr/source/misc/strimpl.cxx new file mode 100644 index 000000000000..bf872dd58c3c --- /dev/null +++ b/configmgr/source/misc/strimpl.cxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * $RCSfile: strimpl.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_STRINGS_HXX_ +#include "strings.hxx" +#endif + +namespace configmgr +{ + // tag names + // <name>...</name> + IMPLEMENT_CONSTASCII_USTRING(TAG_VALUE, "cfg:value"); + IMPLEMENT_CONSTASCII_USTRING(TAG_USERVALUE, "uservalue"); + IMPLEMENT_CONSTASCII_USTRING(TAG_VALUE_ITEM, "value_item"); + IMPLEMENT_CONSTASCII_USTRING(TAG_DEFAULT_ITEM, "default_item"); + IMPLEMENT_CONSTASCII_USTRING(TAG_NODEFAULT, "nodefault"); + IMPLEMENT_CONSTASCII_USTRING(TAG_DEFAULT, "default"); + IMPLEMENT_CONSTASCII_USTRING(TAG_DEFAULTVALUE, "defaultvalue"); + IMPLEMENT_CONSTASCII_USTRING(TAG_DATA, "data"); + + // simple types Attribut params + IMPLEMENT_CONSTASCII_USTRING(TYPE_BOOLEAN, "boolean"); + IMPLEMENT_CONSTASCII_USTRING(TYPE_SHORT, "short"); + IMPLEMENT_CONSTASCII_USTRING(TYPE_INT, "int"); + IMPLEMENT_CONSTASCII_USTRING(TYPE_LONG, "long"); + IMPLEMENT_CONSTASCII_USTRING(TYPE_DOUBLE, "double"); + IMPLEMENT_CONSTASCII_USTRING(TYPE_STRING, "string"); + + // Type: Sequence<bytes> + IMPLEMENT_CONSTASCII_USTRING(TYPE_BINARY, "binary"); + + // special types + IMPLEMENT_CONSTASCII_USTRING(TYPE_SET, "set"); + IMPLEMENT_CONSTASCII_USTRING(TYPE_GROUP, "group"); + + + // Attributes name="..." + IMPLEMENT_CONSTASCII_USTRING(ATTR_ENCODING_HEX, "hex"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_NAME, "name"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_TYPE, "cfg:type"); + + IMPLEMENT_CONSTASCII_USTRING(ATTR_GROUP, "group"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_DERIVED, "derived"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_INSTANCE, "cfg:element-type"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_ENCODING, "encoding"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_MODE, "mode"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_PATH, "path"); + + // some Attribute params + IMPLEMENT_CONSTASCII_USTRING(ATTR_DERIVED_LIST, "list"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUE_ADD, "add"); + IMPLEMENT_CONSTASCII_USTRING(ATTR_VALUE_REMOVE, "remove"); + + // Parameter + IMPLEMENT_CONSTASCII_USTRING(PARAM_OBJECT, "Object"); + IMPLEMENT_CONSTASCII_USTRING(PARAM_NAME, "Name"); + IMPLEMENT_CONSTASCII_USTRING(PARAM_ISNEWOBJECT, "IsNewObject"); + + IMPLEMENT_CONSTASCII_USTRING(XML_CDATA, "CDATA"); + +// emacs: +// create the declare from the implement +// (fset 'create-declare-from-implement +// [home M-right ?\C- ?\C-s ?, left right left ?\M-w f12 return up tab ?D ?E ?C ?L ?A ?R ?E ?\C-y ?) ?; home down f12 home down]) + +} // namespace configmgr diff --git a/configmgr/source/misc/tracer.cxx b/configmgr/source/misc/tracer.cxx new file mode 100644 index 000000000000..64dbf87e5d1a --- /dev/null +++ b/configmgr/source/misc/tracer.cxx @@ -0,0 +1,396 @@ +/************************************************************************* + * + * $RCSfile: tracer.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// SUNPRO5 does not like the following to be done after including stdio.h, that's why it's here at the very +// beginning of the file +#undef _TIME_T_DEFINED +#include <time.h> +#include <rtl/string.hxx> +#include <map> + +namespace configmgr +{ + typedef ::std::map< ::rtl::OString, void*, ::std::less< ::rtl::OString > > VirtualDevices; +} + +#ifndef _CONFIGMGR_TRACER_HXX_ +#include "tracer.hxx" +#endif + +#ifdef CFG_ENABLE_TRACING + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#define INFO 1 +#define WARNING 2 +#define ERROR 4 + +namespace configmgr +{ + +struct OTracerSetup +{ + sal_Int32 s_nTraceMask; + sal_Int32 s_nIndentDepth; + FILE* s_pOutputMedium; + sal_Bool s_bInitialized; + + VirtualDevices s_aDevices; + + OTracerSetup() + :s_nTraceMask(INFO | WARNING | ERROR) + ,s_nIndentDepth(0) + ,s_pOutputMedium(NULL) + ,s_bInitialized(sal_False) + { + } +}; + +//========================================================================== +//= OConfigTracer +//========================================================================== +::osl::Mutex OConfigTracer::s_aMutex; +OTracerSetup* OConfigTracer::s_pImpl = NULL; + +//-------------------------------------------------------------------------- +void OConfigTracer::ensureData() +{ + if (s_pImpl) + return; + s_pImpl = new OTracerSetup; +} + +//-------------------------------------------------------------------------- +void OConfigTracer::inc() +{ + ::osl::MutexGuard aGuard(s_aMutex); + ensureData(); + ++s_pImpl->s_nIndentDepth; +} + +//-------------------------------------------------------------------------- +void OConfigTracer::dec() +{ + ::osl::MutexGuard aGuard(s_aMutex); + ensureData(); + --s_pImpl->s_nIndentDepth; +} + +//-------------------------------------------------------------------------- +void OConfigTracer::traceInfo(const sal_Char* _pFormat, ...) +{ + ::osl::MutexGuard aGuard(s_aMutex); + ensureData(); + if (s_pImpl->s_nTraceMask & INFO) + { + va_list args; + va_start(args, _pFormat); + implTrace("info : ", _pFormat, args); + va_end(args); + } +} + +//-------------------------------------------------------------------------- +void OConfigTracer::traceWarning(const sal_Char* _pFormat, ...) +{ + ::osl::MutexGuard aGuard(s_aMutex); + ensureData(); + if (s_pImpl->s_nTraceMask & WARNING) + { + va_list args; + va_start(args, _pFormat); + implTrace("warning : ", _pFormat, args); + va_end(args); + } +} + +//-------------------------------------------------------------------------- +void OConfigTracer::traceError(const sal_Char* _pFormat, ...) +{ + ::osl::MutexGuard aGuard(s_aMutex); + ensureData(); + if (s_pImpl->s_nTraceMask & ERROR) + { + va_list args; + va_start(args, _pFormat); + implTrace("error : ", _pFormat, args); + va_end(args); + } +} + +//-------------------------------------------------------------------------- +void OConfigTracer::indent() +{ + for (sal_Int32 i=0; i<s_pImpl->s_nIndentDepth; ++i) + fprintf(s_pImpl->s_pOutputMedium, " "); +} + +//-------------------------------------------------------------------------- +FILE* disambiguate(const ::rtl::OString& _rFileName) +{ + FILE* pExistenceCheck = NULL; + sal_Int32 i = 1; + ::rtl::OString sLoop; + while (i <= 256) + { + sLoop = _rFileName; + sLoop += "."; + sLoop += ::rtl::OString::valueOf(i); + + pExistenceCheck = fopen(sLoop.getStr(), "r"); + if (!pExistenceCheck) + // does not exist + return fopen(sLoop.getStr(), "w+"); + + // already exists, try the next name + fclose(pExistenceCheck); + ++i; + } + + // could not open such a file + return NULL; +} + +//-------------------------------------------------------------------------- +void OConfigTracer::ensureInitalized() +{ + if (s_pImpl->s_bInitialized) + return; + + s_pImpl->s_bInitialized = sal_True; + + char* pSettings = getenv("ENVCFGFLAGS"); + if (!pSettings) + return; + + /* currently recognized structure : + + switches have to be separated by whitespaces + + valid switches are: + -m[e|o|f<file>] - output to stderr (e), stdout (o) or a file (f). In the latter case the whole rest + of the param ('til the next one, means 'til the next whitespace) is the filename + -t{i,w,e}* - type of output : i includes infos, w includes warnings, e includes errors + */ + + s_pImpl->s_pOutputMedium = stderr; + s_pImpl->s_nTraceMask = 0; + + char* pParamLoop = pSettings; + while (*pParamLoop) + { + while (!isspace(*pParamLoop) && *pParamLoop) + ++pParamLoop; + + sal_Int32 nLen = pParamLoop - pSettings; + if ((nLen > 1) && (*pSettings == '-')) + { + ++pSettings; + switch (*pSettings) + { + case 'm': + case 'w': + if (nLen > 2) + { + ++pSettings; + switch (*pSettings) + { + case 'e': + s_pImpl->s_pOutputMedium = stderr; + break; + case 'o': + s_pImpl->s_pOutputMedium = stdout; + break; + case 'f': + { + ++pSettings; + // copy the filename into an own buffer + ::rtl::OString sFileName(pSettings, pParamLoop - pSettings); + + // open the file + s_pImpl->s_pOutputMedium = disambiguate(sFileName); + + break; + } + } + } + break; + case 'd': + { // assign a virtual device + // copy the device assingment description + ::rtl::OString sDescription(pSettings + 1, pParamLoop - pSettings - 1); + sal_Int32 nSep = sDescription.indexOf(':'); + if (-1 == nSep) + break; // invalid format + + ::rtl::OString sVirtualDeviceName, sFileName; + sVirtualDeviceName = sDescription.copy(0, nSep); + sFileName = sDescription.copy(nSep + 1); + + FILE* pVirtualDevice = disambiguate(sFileName); + if (pVirtualDevice) + s_pImpl->s_aDevices[sVirtualDeviceName] = pVirtualDevice; + } + case 't': + { + ++pSettings; + while (pSettings != pParamLoop) + { + switch (*pSettings) + { + case 'i': s_pImpl->s_nTraceMask |= INFO; break; + case 'w': s_pImpl->s_nTraceMask |= WARNING; break; + case 'e': s_pImpl->s_nTraceMask |= ERROR; break; + } + ++pSettings; + } + } + } + } + + if (!*pParamLoop) + break; + + ++pParamLoop; + pSettings = pParamLoop; + } +} +//-------------------------------------------------------------------------- +void OConfigTracer::traceToVirtualDevice(const sal_Char* _pDeviceName, const sal_Char* _pFormat, ...) +{ + ::osl::MutexGuard aGuard(s_aMutex); + ensureData(); + ensureInitalized(); + + VirtualDevices::const_iterator aDeviceMediumPos = s_pImpl->s_aDevices.find(::rtl::OString(_pDeviceName)); + if (aDeviceMediumPos != s_pImpl->s_aDevices.end()) + { + FILE* pDeviceMedium = (FILE*)aDeviceMediumPos->second; + + va_list args; + va_start(args, _pFormat); + vfprintf(pDeviceMedium, _pFormat, args); + fflush(pDeviceMedium); + va_end(args); + } +} + +//-------------------------------------------------------------------------- +::rtl::OString OConfigTracer::getTimeStamp() +{ + time_t aTime = time(NULL); + tm* pStructuredTime = gmtime(&aTime); + ::rtl::OString sTimeStamp(asctime(pStructuredTime)); + // cut the trainling linefeed (asctime is defined to contain such a line feed) + sal_Int32 nStampLen = sTimeStamp.getLength(); + if ((0 != nStampLen) && ('\n' == sTimeStamp.getStr()[nStampLen - 1])) + sTimeStamp = sTimeStamp.copy(0, nStampLen - 1); + + return sTimeStamp; +} + +//-------------------------------------------------------------------------- +void OConfigTracer::implTrace(const sal_Char* _pType, const sal_Char* _pFormat, va_list args) +{ + ensureInitalized(); + if (!s_pImpl->s_pOutputMedium) + // no tracing enabled + return; + + fprintf(s_pImpl->s_pOutputMedium, "%s", _pType); + indent(); + vfprintf(s_pImpl->s_pOutputMedium, _pFormat, args); + fprintf(s_pImpl->s_pOutputMedium,"\n"); + fflush(s_pImpl->s_pOutputMedium); +} + +} // namespace configmgr + +#endif // defined(DEBUG) || defined(_DEBUG) + +//************************************************************************** +// history: +// $Log: not supported by cvs2svn $ +// Revision 1.7 2000/09/15 09:51:51 willem.vandorp +// OpenOffice header added +// +// Revision 1.6 2000/08/31 10:00:21 fs +// time_t unknown +// +// Revision 1.5 2000/08/30 14:34:09 fs +// getTimeStamp +// +// Revision 1.4 2000/08/20 12:55:42 fs +// #77860# introduced an impl class; introduces virtual trace devices +// +// Revision 1.3 2000/08/17 07:18:02 lla +// im/export +// +// Revision 1.2 2000/08/10 06:53:45 fs +// read settings from the ENVCFGFLAGS environment variable +// +// Revision 1.1 2000/08/09 18:52:46 fs +// helper classes for tracing +// +// +// Revision 1.0 09.08.00 13:10:05 fs +//************************************************************************** + diff --git a/configmgr/source/registry/cfgregistrykey.cxx b/configmgr/source/registry/cfgregistrykey.cxx new file mode 100644 index 000000000000..259df2542b98 --- /dev/null +++ b/configmgr/source/registry/cfgregistrykey.cxx @@ -0,0 +1,783 @@ +/************************************************************************* + * + * $RCSfile: cfgregistrykey.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_REGISTRY_CFGREGISTRYKEY_HXX_ +#include "cfgregistrykey.hxx" +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _CPPUHELPER_EXTRACT_HXX_ +#include <cppuhelper/extract.hxx> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ +#include <com/sun/star/container/XNameContainer.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif +#ifndef _TYPELIB_TYPEDESCRIPTION_HXX_ +#include <typelib/typedescription.hxx> +#endif + +#define THISREF() static_cast< ::cppu::OWeakObject* >(this) +#define UNISTRING(c) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(c) ) + +//.......................................................................... +namespace configmgr +{ +//.......................................................................... + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::container; +using namespace ::osl; +using namespace ::cppu; + +//========================================================================== +//= OConfigurationRegistryKey +//========================================================================== + +//-------------------------------------------------------------------------- +OConfigurationRegistryKey::OConfigurationRegistryKey + (const Reference< XNameAccess >& _rxContainerNode + ,sal_Bool _bWriteable + ,SubtreeRoot + ) + :m_xNodeAccess(_rxContainerNode) + ,m_bReadOnly(!_bWriteable) + ,m_xNodeDeepAccess(_rxContainerNode, UNO_QUERY) +{ + OSL_ENSHURE(m_xNodeAccess.is(), "OConfigurationRegistryKey::OConfigurationRegistryKey : invalid config node param !"); +} + +//-------------------------------------------------------------------------- +OConfigurationRegistryKey::OConfigurationRegistryKey( + const Reference< XNameAccess >& _rxContainerNode, + const ::rtl::OUString& _rLocalName, + sal_Bool _bWriteable) + :m_xNodeAccess(_rxContainerNode) + ,m_bReadOnly(!_bWriteable) + ,m_xNodeDeepAccess(_rxContainerNode, UNO_QUERY) + ,m_sLocalName(_rLocalName) +{ + OSL_ENSHURE(m_xNodeAccess.is(), "OConfigurationRegistryKey::OConfigurationRegistryKey : invalid config node param !"); + OSL_ENSHURE(m_sLocalName.getLength(), "OConfigurationRegistryKey::OConfigurationRegistryKey : invalid relative name !"); +} + +//-------------------------------------------------------------------------- +OConfigurationRegistryKey::OConfigurationRegistryKey( + Any _rCurrentValue, + const Reference< XNameAccess >& _rxParentNode, + const ::rtl::OUString& _rRelativeName, + sal_Bool _bWriteable) + :m_aLeafElement(_rCurrentValue) + ,m_xLeafParent(_rxParentNode) + ,m_sLocalName(_rRelativeName) + ,m_bReadOnly(!_bWriteable) +{ + OSL_ENSHURE(_rxParentNode.is() && _rCurrentValue.hasValue(), + "OConfigurationRegistryKey::OConfigurationRegistryKey : invalid value and/or parent !"); + OSL_ENSHURE(m_bReadOnly || Reference< XNameReplace >(_rxParentNode, UNO_QUERY).is(), + "OConfigurationRegistryKey::OConfigurationRegistryKey : invalid parent (no value write access) !"); + OSL_ENSHURE(m_sLocalName.getLength(), "OConfigurationRegistryKey::OConfigurationRegistryKey : invalid relative name !"); +} + +//-------------------------------------------------------------------------- +void OConfigurationRegistryKey::checkValid(KEY_ACCESS_TYPE _eIntentedAccess) throw (InvalidRegistryException) +{ + if (!isValid()) + throw InvalidRegistryException(UNISTRING("The registry is not bound to a configuration node anymore."), THISREF()); + // "anymore", because at the moment the ctor was called it probably was bound .... + switch (_eIntentedAccess) + { + case KAT_VALUE_WRITE: + if (m_bReadOnly) + throw InvalidRegistryException(UNISTRING("This configuration node is not writeable."), THISREF()); + // !!! NO !!! BREAK !!! + case KAT_VALUE: + if (!m_aLeafElement.hasValue()) + throw InvalidRegistryException(UNISTRING("This configuration node does not have a value, it is a container."), THISREF()); + if (!m_xLeafParent.is()) + throw InvalidRegistryException(UNISTRING("This configuration nodes parent is invalid."), THISREF()); + break; + case KAT_CHILD: + if (!m_xNodeAccess.is()) + throw InvalidRegistryException(UNISTRING("This configuration node does not have children, it is a value node."), THISREF()); + break; + } +} + +//-------------------------------------------------------------------------- +Any OConfigurationRegistryKey::getDescendant(const ::rtl::OUString& _rDescendantName) throw(InvalidRegistryException) +{ + Any aElementReturn; + + try + { + if (-1 != _rDescendantName.indexOf('/')) + { + if (m_xNodeDeepAccess.is()) + aElementReturn = m_xNodeDeepAccess->getByHierarchicalName(_rDescendantName); + else + throw InvalidRegistryException(UNISTRING("Nested element access not supported by this node."), THISREF()); + } + else + { + if (m_xNodeAccess.is()) + aElementReturn = m_xNodeAccess->getByName(_rDescendantName); + else + { + OSL_ENSHURE(sal_False, "OConfigurationRegistryKey::getDescendant : invalid call !"); + // this method should not be called if the object does not represent a container node ... + throw InvalidRegistryException(UNISTRING("invalid object."), THISREF()); + } + } + } + catch(NoSuchElementException&) + { // not allowed to leave the method, wrap it + ::rtl::OUString sMessage(UNISTRING("There is no element named ")); + sMessage += _rDescendantName; + sMessage += UNISTRING("."); + throw InvalidRegistryException(sMessage, THISREF()); + } + catch(WrappedTargetException&) + { // allowed to be thrown by XNameAccess::getByName, but not allowed to leave this method + ::rtl::OUString sMessage(UNISTRING("The configuration node could not provide an element for ")); + sMessage += _rDescendantName; + sMessage += UNISTRING("."); + throw InvalidRegistryException(sMessage, THISREF()); + } + + if (!aElementReturn.hasValue()) + { // suspicious .... either there is an element, or there is none, but in the latter case an exception should + // have been thrown. + ::rtl::OUString sMessage(UNISTRING("There is no element named ")); + sMessage += _rDescendantName; + sMessage += UNISTRING("."); + throw InvalidRegistryException(sMessage, THISREF()); + } + + return aElementReturn; +} + +//-------------------------------------------------------------------------- +void OConfigurationRegistryKey::writeValueNode(const Any& _rValue) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_VALUE_WRITE); + + Reference< XNameReplace > xParentValueAccess(m_xLeafParent, UNO_QUERY); + if (!xParentValueAccess.is()) + throw InvalidRegistryException(UNISTRING("The parent configuration node does not allow write access to it's children."), THISREF()); + + try + { + xParentValueAccess->replaceByName(m_sLocalName, _rValue); + } + catch(IllegalArgumentException&) + { + throw InvalidRegistryException(UNISTRING("Unable to replace the old value. The configuration node threw an IllegalArgumentException."), THISREF()); + } + catch(NoSuchElementException&) + { + OSL_ENSHURE(sal_False, "OConfigurationRegistryKey::writeValueNode : a NoSuchElementException should be impossible !"); + throw InvalidRegistryException(UNISTRING("Unable to replace the old value. The configuration node threw an NoSuchElementException."), THISREF()); + } + catch(WrappedTargetException&) + { + throw InvalidRegistryException(UNISTRING("Unable to replace the old value. The configuration node threw an WrappedTargetException."), THISREF()); + } +} + +//-------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConfigurationRegistryKey::getKeyName() throw(RuntimeException) +{ + return m_sLocalName; +} + +//-------------------------------------------------------------------------- +sal_Bool SAL_CALL OConfigurationRegistryKey::isReadOnly( ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_META); + return m_bReadOnly; +} + +//-------------------------------------------------------------------------- +sal_Bool SAL_CALL OConfigurationRegistryKey::isValid( ) throw(RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + // TODO : perhaps if the registry we're a part of is closed .... + return m_xNodeAccess.is() || m_aLeafElement.hasValue(); +} + +//-------------------------------------------------------------------------- +RegistryKeyType SAL_CALL OConfigurationRegistryKey::getKeyType( const ::rtl::OUString& _rKeyName ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_CHILD); + + // no further checks are made (for performance reasons) ... + return RegistryKeyType_KEY; +} + +//-------------------------------------------------------------------------- +namespace { + inline + Type getBinaryDataType() { + Sequence<sal_Int8> const * const p= 0; + return ::getCppuType(p); + } +} +//-------------------------------------------------------------------------- +typedef typelib_TypeDescriptionReference ElementTypeDesc; + +RegistryValueType SAL_CALL OConfigurationRegistryKey::getValueType( ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_VALUE); + + switch (m_aLeafElement.getValueType().getTypeClass()) + { + case TypeClass_STRING: + return RegistryValueType_STRING; + case TypeClass_SHORT: + case TypeClass_UNSIGNED_SHORT: + case TypeClass_BYTE: + case TypeClass_LONG: + case TypeClass_UNSIGNED_LONG: + case TypeClass_BOOLEAN: + return RegistryValueType_LONG; + case TypeClass_SEQUENCE: + if (m_aLeafElement.getValueType() == getBinaryDataType()) + return RegistryValueType_BINARY; + else + { + TypeDescription aType( m_aLeafElement.getValueType() ); + typelib_IndirectTypeDescription* pSequenceType + = reinterpret_cast< typelib_IndirectTypeDescription* >(aType.get()); + ElementTypeDesc* pElementType = pSequenceType->pType; + + switch (pElementType->eTypeClass) + { + case TypeClass_SHORT: + case TypeClass_UNSIGNED_SHORT: + case TypeClass_BYTE: + case TypeClass_LONG: + case TypeClass_UNSIGNED_LONG: + case TypeClass_BOOLEAN: + return RegistryValueType_LONGLIST; + case TypeClass_STRING: + return RegistryValueType_STRINGLIST; + case TypeClass_DOUBLE: + OSL_ENSHURE(sal_False, "OConfigurationRegistryKey::getValueType : registry does not support lists of floating point numebrs !"); + default: + if (Type(pElementType) == getBinaryDataType()) + OSL_ENSHURE(sal_False,"OConfigurationRegistryKey::getValueType : Registry cannot support LIST of BINARY"); + else + OSL_ENSHURE(sal_False, "OConfigurationRegistryKey::getValueType : unknown sequence element type !"); + return RegistryValueType_NOT_DEFINED; + } + } + case TypeClass_DOUBLE: + OSL_ENSHURE(sal_False, "OConfigurationRegistryKey::getValueType : registry does not support floating point numebrs !"); + return RegistryValueType_NOT_DEFINED; + default: + OSL_ENSHURE(sal_False, "OConfigurationRegistryKey::getValueType : unknown entry type !"); + return RegistryValueType_NOT_DEFINED; + } +} + +//-------------------------------------------------------------------------- +sal_Int32 SAL_CALL OConfigurationRegistryKey::getLongValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_VALUE); + +#define EXTRACT(tcname, type) \ + case TypeClass_##tcname : { type nNativeValue; m_aLeafElement >>= nNativeValue; nLongValue = nNativeValue; } + + sal_Int32 nLongValue(0); + switch (m_aLeafElement.getValueTypeClass()) + { + case TypeClass_SHORT : { sal_Int16 nNativeValue; m_aLeafElement >>= nNativeValue; nLongValue = nNativeValue; } break; + case TypeClass_UNSIGNED_SHORT : { sal_uInt16 nNativeValue; m_aLeafElement >>= nNativeValue; nLongValue = nNativeValue; } break; + case TypeClass_BYTE : { sal_Int8 nNativeValue; m_aLeafElement >>= nNativeValue; nLongValue = nNativeValue; } break; + case TypeClass_LONG : { sal_Int32 nNativeValue; m_aLeafElement >>= nNativeValue; nLongValue = nNativeValue; } break; + case TypeClass_UNSIGNED_LONG : { sal_uInt32 nNativeValue; m_aLeafElement >>= nNativeValue; nLongValue = nNativeValue; } break; + case TypeClass_BOOLEAN : { sal_Bool nNativeValue; m_aLeafElement >>= nNativeValue; nLongValue = nNativeValue; } break; + default: + throw InvalidValueException(UNISTRING("This node does not contain a long (or a compatible) value."), THISREF()); + } + return nLongValue; +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::setLongValue( sal_Int32 _nValue ) throw(InvalidRegistryException, RuntimeException) +{ + writeValueNode(makeAny(_nValue)); +} + +//-------------------------------------------------------------------------- +Sequence< sal_Int32 > SAL_CALL OConfigurationRegistryKey::getLongListValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_VALUE); + + Sequence< sal_Int32 > aReturn; + if (m_aLeafElement >>= aReturn) + return aReturn; + + // TODO : maybe it's a sequence of sal_Int8 or anything like that which we're able to convert .... + + throw InvalidValueException(UNISTRING("This configuration node does not contain a list of longs !"), THISREF()); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::setLongListValue( const Sequence< sal_Int32 >& _seqValue ) throw(InvalidRegistryException, RuntimeException) +{ + writeValueNode(makeAny(_seqValue)); +} + +//-------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConfigurationRegistryKey::getAsciiValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException) +{ + ::rtl::OUString sReturn = getStringValue(); + // TODO : check if it's really ascii ... + return sReturn; +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::setAsciiValue( const ::rtl::OUString& _rValue ) throw(InvalidRegistryException, RuntimeException) +{ + setStringValue(_rValue); +} + +//-------------------------------------------------------------------------- +Sequence< ::rtl::OUString > SAL_CALL OConfigurationRegistryKey::getAsciiListValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException) +{ + return getStringListValue(); + // TODO : it's not really an "ascii list" .... perhaps we should throw an exception here ... +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::setAsciiListValue( const Sequence< ::rtl::OUString >& _seqValue ) throw(InvalidRegistryException, RuntimeException) +{ + setStringListValue(_seqValue); +} + +//-------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConfigurationRegistryKey::getStringValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_VALUE); + + ::rtl::OUString sReturn; + if (!(m_aLeafElement >>= sReturn)) + throw InvalidValueException(UNISTRING("This node does not contain a string value."), THISREF()); + return sReturn; +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::setStringValue( const ::rtl::OUString& _rValue ) throw(InvalidRegistryException, RuntimeException) +{ + writeValueNode(makeAny(_rValue)); +} + +//-------------------------------------------------------------------------- +Sequence< ::rtl::OUString > SAL_CALL OConfigurationRegistryKey::getStringListValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_VALUE); + + Sequence< ::rtl::OUString > aReturn; + if (m_aLeafElement >>= aReturn) + return aReturn; + + throw InvalidValueException(UNISTRING("This configuration node does not contain a list of strings !"), THISREF()); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::setStringListValue( const Sequence< ::rtl::OUString >& _seqValue ) throw(InvalidRegistryException, RuntimeException) +{ + writeValueNode(makeAny(_seqValue)); +} + +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > SAL_CALL OConfigurationRegistryKey::getBinaryValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_VALUE); + + Sequence< sal_Int8 > aReturn; + if (m_aLeafElement >>= aReturn) + return aReturn; + + throw InvalidValueException(UNISTRING("This configuration node does not contain a list of strings !"), THISREF()); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::setBinaryValue( const Sequence< sal_Int8 >& _rValue ) throw(InvalidRegistryException, RuntimeException) +{ + writeValueNode(makeAny(_rValue)); +} + +//-------------------------------------------------------------------------- +Reference< XRegistryKey > OConfigurationRegistryKey::implGetKey( const ::rtl::OUString& _rKeyName ) + throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException) +{ + ::rtl::OUString sDescRelativeName(_rKeyName); + // will be the name of the new key relative to it's parent + sal_Bool bDeepAccess = sal_False; + sal_Int32 nSeparatorPos = _rKeyName.lastIndexOf('/'); + if ((nSeparatorPos >= 0) && (nSeparatorPos == (_rKeyName.getLength() - 1))) + // recognize a trailing slashs + nSeparatorPos = _rKeyName.lastIndexOf('/', nSeparatorPos - 1); + if (nSeparatorPos >= 1) + { + sDescRelativeName = _rKeyName.copy(nSeparatorPos + 1); + bDeepAccess = sal_True; + } + + Any aDescendant = getDescendant(_rKeyName); + if (aDescendant.getValueType().getTypeClass() == TypeClass_INTERFACE) + { + Reference< XNameAccess > xContainerNode; + ::cppu::extractInterface(xContainerNode, aDescendant); + if (!xContainerNode.is()) + throw InvalidRegistryException(UNISTRING("invalid descendant node."), THISREF()); + return new OConfigurationRegistryKey(xContainerNode, sDescRelativeName, !m_bReadOnly); + } + else + { + Reference< XNameAccess > xDescParent(m_xNodeAccess); // the parent config node of the descandent + + OSL_ENSHURE(aDescendant.hasValue(), "OConfigurationRegistryKey::openKey : invalid return from getDescendant."); +#ifdef DEBUG + switch (aDescendant.getValueType().getTypeClass()) + { + case TypeClass_STRING: + case TypeClass_SHORT: + case TypeClass_UNSIGNED_SHORT: + case TypeClass_BYTE: + case TypeClass_LONG: + case TypeClass_UNSIGNED_LONG: + case TypeClass_BOOLEAN: + case TypeClass_SEQUENCE: + break; + default: + OSL_ENSHURE(sal_False, "OConfigurationRegistryKey::openKey : unknown or invalid descendant value type !"); + } +#endif + if (bDeepAccess) + { + Any aDescParent = getDescendant(_rKeyName.copy(0, nSeparatorPos)); + ::cppu::extractInterface(xDescParent, aDescParent); + if (!xDescParent.is()) + throw InvalidRegistryException(UNISTRING("The internal registry structure seems to be corrupt."), THISREF()); + } + + return new OConfigurationRegistryKey(aDescendant, xDescParent, sDescRelativeName, !m_bReadOnly); + } +} + +//-------------------------------------------------------------------------- +Reference< XRegistryKey > SAL_CALL OConfigurationRegistryKey::openKey( const ::rtl::OUString& _rKeyName ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_CHILD); + + return implGetKey(_rKeyName); +} + +//-------------------------------------------------------------------------- +void OConfigurationRegistryKey::checkRelativeKeyName(::rtl::OUString& _rKeyName) throw(InvalidRegistryException, RuntimeException) +{ + // no empty names allowed + if (!_rKeyName.getLength()) + throw InvalidRegistryException(UNISTRING("The key name is invalid."), THISREF()); + + // no absolute names ("/...") allowed + if (_rKeyName.getStr()[0] == '/') + throw InvalidRegistryException(UNISTRING("The key name is invalid. It must be a relative, not an absolute name."), THISREF()); + + // cut trailing slashes + while (_rKeyName.getLength() && (_rKeyName.getStr()[_rKeyName.getLength() - 1] == '/')) + _rKeyName = _rKeyName.copy(0, _rKeyName.getLength() - 1); + + if (!_rKeyName.getLength()) + // the original name consists of slashes only + throw InvalidRegistryException(UNISTRING("The key name is invalid."), THISREF()); +} + +//-------------------------------------------------------------------------- +Reference< XRegistryKey > SAL_CALL OConfigurationRegistryKey::createKey( const ::rtl::OUString& _rKeyName ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_CHILD); + + if (m_bReadOnly) + throw InvalidRegistryException(UNISTRING("The key is read only."), THISREF()); + + ::rtl::OUString sKeyName(_rKeyName); + checkRelativeKeyName(sKeyName); + + sal_Int32 nSeparatorPos = sKeyName.lastIndexOf('/'); + if (-1 != nSeparatorPos) + { + // deep access. delegate it to a registry key which is one level above the to-be-created one + ::rtl::OUString sSetNodeName = sKeyName.copy(0, nSeparatorPos); + sKeyName = sKeyName.copy(nSeparatorPos + 1); + + Reference< XRegistryKey > xSetNode = implGetKey(sSetNodeName); + if (!xSetNode.is()) + { + OSL_ENSHURE(sal_False, "OConfigurationRegistryKey::createKey : somebody changed the implGetKey behaviour !"); + throw InvalidRegistryException(UNISTRING("An internal error occured."), THISREF()); + } + return xSetNode->createKey(sKeyName); + } + + // The requested new key is one level below ourself. Can't delegate the creation. + Reference< XNameContainer > xContainer(m_xNodeAccess, UNO_QUERY); + Reference< XSingleServiceFactory > xChildFactory(xContainer, UNO_QUERY); + if (!xChildFactory.is()) + throw InvalidRegistryException(UNISTRING("The configuration node represented by this key is not a container node, you can't insert keys."), THISREF()); + + // In the configuration API, the creation of a new child is two-stage process : first you create a child which + // is "floating", i.e. does not belong to the configuration tree, yet. After filling it with values, you insert + // it into the container node which was used for the creation. + // We can't map this behaviour with the registry API, so we have to combine both steps + + // create a new floating child for the container node + Reference< XInterface > xFloatingChild; + try + { + xFloatingChild = xChildFactory->createInstance(); + } + catch (RuntimeException&) + { // allowed to leave this method + throw; + } + catch (Exception& e) + { // not allowed to leave this method + throw InvalidRegistryException(UNISTRING("Unable to create a new child for the configuration node. Original error message as provided by the configuration API : ") += e.Message, + THISREF()); + } + + // and immediately insert it into the container + try + { + xContainer->insertByName(sKeyName, makeAny(xFloatingChild)); + } + catch (IllegalArgumentException& e) + { + throw InvalidRegistryException(UNISTRING("illegal argument : ") += e.Message, THISREF()); + } + catch (ElementExistException& e) + { + if (e.Message.getLength()) + throw InvalidRegistryException(e.Message, THISREF()); + else + throw InvalidRegistryException((UNISTRING("There already is an element named ") += sKeyName) += UNISTRING("."), THISREF()); + } + catch (WrappedTargetException& e) + { + throw InvalidRegistryException(UNISTRING("Caught an WrappedTargetException. Original error message : ") += e.Message, THISREF()); + } + + Reference< XNameAccess > xInsertedChild(xFloatingChild, UNO_QUERY); + if (!xInsertedChild.is()) + throw InvalidRegistryException(UNISTRING("An internal error occured. The objects provided by the configuration API are invalid."), THISREF()); + + return new OConfigurationRegistryKey(xInsertedChild, sKeyName, !m_bReadOnly); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::closeKey( ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + + m_xNodeAccess = NULL; + m_xNodeDeepAccess = NULL; + m_aLeafElement.clear(); + m_xLeafParent = NULL; + m_sLocalName = ::rtl::OUString(); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::deleteKey( const ::rtl::OUString& _rKeyName ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + + checkValid(KAT_CHILD); + if (m_bReadOnly) + throw InvalidRegistryException(UNISTRING("The key is read only."), THISREF()); + + ::rtl::OUString sKeyName(_rKeyName); + checkRelativeKeyName(sKeyName); + + sal_Int32 nSeparatorPos = sKeyName.lastIndexOf('/'); + if (-1 != nSeparatorPos) + { + // deep access. delegate it to a registry key which is one level above the to-be-created one + ::rtl::OUString sSetNodeName = sKeyName.copy(0, nSeparatorPos); + sKeyName = sKeyName.copy(nSeparatorPos + 1); + + Reference< XRegistryKey > xSetNode = implGetKey(sSetNodeName); + if (!xSetNode.is()) + { + OSL_ENSHURE(sal_False, "OConfigurationRegistryKey::createKey : somebody changed the implGetKey behaviour !"); + throw InvalidRegistryException(UNISTRING("An internal error occured."), THISREF()); + } + xSetNode->deleteKey(sKeyName); + return; + } + + // The requested new key is one level below ourself. Can't delegate the creation. + Reference< XNameContainer > xContainer(m_xNodeAccess, UNO_QUERY); + if (!xContainer.is()) + throw InvalidRegistryException(UNISTRING("The configuration node represented by this key is not a container node, you can't remove keys."), THISREF()); + + // and immediately insert it into the container + try + { + xContainer->removeByName(sKeyName); + } + catch (NoSuchElementException& e) + { + if (e.Message.getLength()) + throw InvalidRegistryException(e.Message, THISREF()); + else + throw InvalidRegistryException((UNISTRING("There is no element named ") += sKeyName) += UNISTRING("."), THISREF()); + } + catch (WrappedTargetException& e) + { + throw InvalidRegistryException(UNISTRING("Caught an WrappedTargetException. Original error message : ") += e.Message, THISREF()); + } +} + +//-------------------------------------------------------------------------- +Sequence< Reference< XRegistryKey > > SAL_CALL OConfigurationRegistryKey::openKeys( ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_CHILD); + + Sequence< ::rtl::OUString > aNames(m_xNodeAccess->getElementNames()); + const ::rtl::OUString* pNames = aNames.getConstArray(); + Sequence< Reference< XRegistryKey > > aReturn(aNames.getLength()); + Reference< XRegistryKey >* pReturn = aReturn.getArray(); + for (sal_Int32 i=0; i<aNames.getLength(); ++i, ++pNames, ++pReturn) + *pReturn = implGetKey(*pNames); + + return aReturn; +} + +//-------------------------------------------------------------------------- +Sequence< ::rtl::OUString > SAL_CALL OConfigurationRegistryKey::getKeyNames( ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkValid(KAT_CHILD); + return m_xNodeAccess->getElementNames(); +} + +//-------------------------------------------------------------------------- +sal_Bool SAL_CALL OConfigurationRegistryKey::createLink( const ::rtl::OUString& aLinkName, const ::rtl::OUString& aLinkTarget ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + throw InvalidRegistryException(UNISTRING("This registry, which is base on a configuration tree, does not support links."), THISREF()); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistryKey::deleteLink( const ::rtl::OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + throw InvalidRegistryException(UNISTRING("This registry, which is base on a configuration tree, does not support links."), THISREF()); +} + +//-------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConfigurationRegistryKey::getLinkTarget( const ::rtl::OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + throw InvalidRegistryException(UNISTRING("This registry, which is base on a configuration tree, does not support links."), THISREF()); +} + +//-------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConfigurationRegistryKey::getResolvedName( const ::rtl::OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + throw InvalidRegistryException(UNISTRING("This registry, which is base on a configuration tree, does not support links."), THISREF()); +} + +//-------------------------------------------------------------------------- +//.......................................................................... +} // namespace configmgr +//.......................................................................... + + diff --git a/configmgr/source/registry/cfgregistrykey.hxx b/configmgr/source/registry/cfgregistrykey.hxx new file mode 100644 index 000000000000..edf9c7d25fea --- /dev/null +++ b/configmgr/source/registry/cfgregistrykey.hxx @@ -0,0 +1,256 @@ +/************************************************************************* + * + * $RCSfile: cfgregistrykey.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_REGISTRY_CFGREGISTRYKEY_HXX_ +#define _CONFIGMGR_REGISTRY_CFGREGISTRYKEY_HXX_ + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_ +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/Mutex.hxx> +#endif + +//.......................................................................... +namespace configmgr +{ +//.......................................................................... + +//========================================================================== +//= OConfigurationRegistryKey +//========================================================================== +typedef ::cppu::WeakImplHelper1 < ::com::sun::star::registry::XRegistryKey + > OConfigurationRegistryKey_Base; + +/** wraps the registry-like access to a single node of a configuration sub tree +*/ +class OConfigurationRegistryKey + :public OConfigurationRegistryKey_Base +{ + ::osl::Mutex m_aMutex; /// access safety + sal_Bool m_bReadOnly; /// is the key readonly ? + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + m_xNodeAccess; /// the config node object, if it describes a container + ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess > + m_xNodeDeepAccess; /// for accessing elements which are grandchildren + + ::com::sun::star::uno::Any + m_aLeafElement; /// if the key represents a leaf, this is the value + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > + m_xLeafParent; /// if the key represents a leaf, this is it's parent. used for write access + + ::rtl::OUString m_sLocalName; /** the name of the element relative to the parent, which would be + m_xLeafParent in case the key represents a value node + */ + + // TODO : the current concept does not recognize any changes in the config tree, i.e. the values stored + // in a configuration key wrapper are not changed if the value in the corresponding config node changes. + // Possible solutions: + // 1. on each value (or even on each sub key) access, the node is read from the configuration hierarchy, again. + // sounds very expensive. + // 2. each registry key is a listener on the node it represents. + // sounds expensive, too. + // + // At the moment we ignore this restriction, but perhaps we can't do that forever .... + +public: + /// when used as ctor parameter, this indicates that the key wraps a config tree subtree root + struct SubtreeRoot { }; + + /** builds an registry key which wraps the root of a configuration node + */ + OConfigurationRegistryKey( + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxContainerNode + ,sal_Bool _bWriteable + ,SubtreeRoot + ); + + /** builds an registry key for a configuration container node + @param _rxContainerNode the container the key should represent + @param _rLocalName the name of the node local to it's parent. Must be empty only if + the key represents the root node of a navigatable sub tree. + @param _bWriteable should the key be writeable ? + */ + OConfigurationRegistryKey( + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxContainerNode + ,const ::rtl::OUString& _rLocalName + ,sal_Bool _bWriteable + ); + + /** builds an registry key for a configuration value container node. + @param _rCurrentValue the current value of the node. Must be the same as _rxParentNode->getByName(_rRelativeName) would provide + @param _rxParentNode the parent of the value node. Used for update access and for obtaining the initial value. + @param _rRelativeName te relative name within the parent + @param _bWriteable should the key be writeable ? + */ + OConfigurationRegistryKey( + ::com::sun::star::uno::Any _rCurrentValue + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxParentNode + ,const ::rtl::OUString& _rRelativeName + ,sal_Bool _bWriteable + ); + + // XRegistryKey + virtual ::rtl::OUString SAL_CALL getKeyName() throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isReadOnly( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isValid( ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::registry::RegistryKeyType SAL_CALL getKeyType( const ::rtl::OUString& rKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::registry::RegistryValueType SAL_CALL getValueType( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getLongValue( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setLongValue( sal_Int32 value ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL getLongListValue( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setLongListValue( const ::com::sun::star::uno::Sequence< sal_Int32 >& seqValue ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getAsciiValue( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setAsciiValue( const ::rtl::OUString& value ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAsciiListValue( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setAsciiListValue( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& seqValue ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getStringValue( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setStringValue( const ::rtl::OUString& value ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getStringListValue( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setStringListValue( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& seqValue ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setBinaryValue( const ::com::sun::star::uno::Sequence< sal_Int8 >& value ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > SAL_CALL openKey( const ::rtl::OUString& aKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > SAL_CALL createKey( const ::rtl::OUString& aKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL closeKey( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL deleteKey( const ::rtl::OUString& rKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > > SAL_CALL openKeys( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getKeyNames( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL createLink( const ::rtl::OUString& aLinkName, const ::rtl::OUString& aLinkTarget ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL deleteLink( const ::rtl::OUString& rLinkName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getLinkTarget( const ::rtl::OUString& rLinkName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getResolvedName( const ::rtl::OUString& aKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + +protected: + /** specifies the kind of access to the key. + */ + enum KEY_ACCESS_TYPE + { + KAT_META, /// access on a meta level, e.g. asking for the read-onyl flag + KAT_VALUE, /// read access to the value the node represents + KAT_VALUE_WRITE, /// write access to the value the node represents + KAT_CHILD /// access to one of the (grand-)children of the node + }; + + /** check if the registry key is valid + @param _eIntentedAccess type of access which the caller wants to perform on the object + @throws <type scope="com.sun.star.registry">InvalidRegistryException</type> if the key is invalid + */ + void checkValid(KEY_ACCESS_TYPE _eIntentedAccess) throw (::com::sun::star::registry::InvalidRegistryException); + + /** return an child element. + @param _rDescendantName the name of the descendant to open. May have a depth of more than 1, if + the node container support XHierarchicalNameAccess + @return the requested element. The caller can assume that the returned + <type scope="com.sun.star.uno">Any</type> always contains an object, all other cases are + handled with exceptions + @throws <type scope="com.sun.star.registry">InvalidRegistryException</type> if the key is invalid, + the element refered by _rName does not exist, the configuration node threw an exception, or + the name has a depth of more than one and the config node does not support this. + */ + ::com::sun::star::uno::Any getDescendant(const ::rtl::OUString& _rDescendantName) throw(::com::sun::star::registry::InvalidRegistryException); + + /** write the given value into the configuration node the object represents. + @throws <type scope="com.sun.star.registry">InvalidRegistryException</type> if the key is invalid, + not opened for write access or the configurations parent is not able to provide a value access + @throws <type scope="com.sun.star.uno">RuntimeException</type> if a fatal runtime error occurs + */ + void writeValueNode(const ::com::sun::star::uno::Any& _rValue) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + + /** open the sub key (depth 1 or more) determined by the given name + @param _rKeyName the name of the descendant node + @return a XRegistryKey wrapper for the requested configuration node + @throws <type scope="com.sun.star.registry">InvalidRegistryException</type> if the key is invalid, + the element refered by _rName does not exist, the configuration node threw an exception, or + the name has a depth of more than one and the config node does not support this. + */ + ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > OConfigurationRegistryKey::implGetKey( const ::rtl::OUString& _rKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + + /** check the given (relative) key name syntactically. In particular, this means that no checks are made if a node + with the given name exists or something like that ... + <BR> + In addition, the given name will be normalized. Basically, this means that it does not contain trailing slashes. + @throws InvalidRegistryException if the name is not relative (i.e. if it starts with an slash) + @throws InvalidRegistryException if the name is empty or consists of slashes only + */ + void checkRelativeKeyName(::rtl::OUString& _rKeyName) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); +}; + + +//.......................................................................... +} // namespace configmgr +//.......................................................................... + +#endif // _CONFIGMGR_REGISTRY_CFGREGISTRYKEY_HXX_ + + diff --git a/configmgr/source/registry/configregistry.cxx b/configmgr/source/registry/configregistry.cxx new file mode 100644 index 000000000000..82d9eba7a743 --- /dev/null +++ b/configmgr/source/registry/configregistry.cxx @@ -0,0 +1,344 @@ +/************************************************************************* + * + * $RCSfile: configregistry.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _CONFIGMGR_REGISTRY_CONFIGREGISTRY_HXX_ +#include "configregistry.hxx" +#endif +#ifndef _CONFIGMGR_REGISTRY_CFGREGISTRYKEY_HXX_ +#include "cfgregistrykey.hxx" +#endif + +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _COM_SUN_STAR_LANG_SERVICENOTREGISTEREDEXCEPTION_HPP_ +#include <com/sun/star/lang/ServiceNotRegisteredException.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif + +#define THISREF() static_cast< ::cppu::OWeakObject* >(this) +#define UNISTRING(c) ::rtl::OUString::createFromAscii(c) + +//.......................................................................... +namespace configmgr +{ +//.......................................................................... + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::util; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::container; +using namespace ::osl; +using namespace ::cppu; + +//========================================================================== +//= OConfigurationRegistry +//========================================================================== + + static const AsciiServiceName aConfigRegistryServices[] = + { + "com.sun.star.registry.SimpleRegistry", + "com.sun.star.configuration.ConfigurationRegistry", + NULL + }; + const ServiceInfo OConfigurationRegistry::s_aServiceInfo = + { + "com.sun.star.configuration.configmgr.OConfigurationRegistry", + aConfigRegistryServices + }; + + Reference< XInterface > SAL_CALL instantiateConfigRegistry(Reference< XMultiServiceFactory > const& _rServiceManager ) + { + return static_cast< ::cppu::OWeakObject* >(new OConfigurationRegistry(_rServiceManager)); + } + + const ServiceInfo* getConfigurationRegistryServiceInfo() + { + return &OConfigurationRegistry::s_aServiceInfo; + } + +//-------------------------------------------------------------------------- +OConfigurationRegistry::OConfigurationRegistry(const Reference< XMultiServiceFactory >& _rORB) throw(Exception, RuntimeException) + :ServiceComponentImpl(&s_aServiceInfo) + ,m_xORB(_rORB) + ,m_aFlushListeners(m_aMutex) +{ + // create the configuration provider used for accessing the configuration + OSL_ENSHURE(m_xORB.is(), "OConfigurationRegistry::OConfigurationRegistry : invalid service factory !"); + if (m_xORB.is()) + m_xConfigurationProvider = + Reference< XMultiServiceFactory > ( + m_xORB->createInstance(UNISTRING("com.sun.star.configuration.ConfigurationProvider")), + UNO_QUERY + ); + + if (!m_xConfigurationProvider.is()) + // it's heavily needed ... + throw ServiceNotRegisteredException(UNISTRING("Failed to instantiate the mandatory service com.sun.star.configuration.ConfigurationProvider."), + THISREF()); +} + +//-------------------------------------------------------------------------- +Any SAL_CALL OConfigurationRegistry::queryInterface( const Type& _rType ) throw(RuntimeException) +{ + Any aReturn = ServiceComponentImpl::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = OConfigurationRegistry_Base::queryInterface(_rType); + return aReturn; +} + +//-------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OConfigurationRegistry::getTypes( ) throw(RuntimeException) +{ + return ::utl::concatSequences( + ServiceComponentImpl::getTypes(), + OConfigurationRegistry_Base::getTypes()); +} + +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > SAL_CALL OConfigurationRegistry::getImplementationId( ) throw(RuntimeException) +{ + static OImplementationId aId; + return aId.getImplementationId(); +} + +//-------------------------------------------------------------------------- +::rtl::OUString OConfigurationRegistry::getNodePathFromURL(const ::rtl::OUString& _rURL) +{ + // TODO + return _rURL; +} + +//-------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConfigurationRegistry::getURL() throw(RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + return m_sLocation; +} + +//-------------------------------------------------------------------------- +void OConfigurationRegistry::checkOpen() throw(InvalidRegistryException, RuntimeException) +{ + if (!isOpen()) + throw InvalidRegistryException(UNISTRING("The registry is not bound to a configuration node."), THISREF()); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistry::open( const ::rtl::OUString& _rURL, sal_Bool _bReadOnly, sal_Bool _bCreate ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + if (isOpen()) + close(); + + ::rtl::OUString sNodePath = getNodePathFromURL(_rURL); + + if (!m_xConfigurationProvider.is()) + throw RuntimeException(UNISTRING("invalid object. configuration provider is already disposed."), THISREF()); + + Reference< XInterface > xNodeAccess; + try + { + // the one and only parameter for creating the config access : the node path + Sequence< Any > aArguments(1); + aArguments[0] <<= sNodePath; + + if (_bReadOnly) + xNodeAccess = m_xConfigurationProvider->createInstanceWithArguments(UNISTRING("com.sun.star.configuration.ConfigurationAccess"), aArguments); + else + xNodeAccess = m_xConfigurationProvider->createInstanceWithArguments(UNISTRING("com.sun.star.configuration.ConfigurationUpdateAccess"), aArguments); + } + catch (RuntimeException&) + { // allowed to leave this method + throw; + } + catch (Exception& e) + { // not allowed to leave this method + ::rtl::OUString sMessage = UNISTRING("The configuration provider does not supply a registry access for the requested Node."); + sMessage += UNISTRING(" original error message of the provider : "); + sMessage += e.Message; + throw InvalidRegistryException(sMessage, THISREF()); + } + + Reference< XNameAccess > xReadRoot(xNodeAccess, UNO_QUERY); + if (!_bReadOnly) + m_xUpdateRoot = m_xUpdateRoot.query(xNodeAccess); + + if (!xReadRoot.is() || (!_bReadOnly && !m_xUpdateRoot.is())) + throw InvalidRegistryException(UNISTRING("The object supplied the by configuration provider is invalid."), THISREF()); + + m_xRootKey = new OConfigurationRegistryKey(xReadRoot, !_bReadOnly, OConfigurationRegistryKey::SubtreeRoot()); + m_xSubtreeRoot = xNodeAccess; +} + +//-------------------------------------------------------------------------- +sal_Bool SAL_CALL OConfigurationRegistry::isValid( ) throw(RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + return m_xRootKey.is(); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistry::close( ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + + if (m_xRootKey.is()) + m_xRootKey->closeKey(); + m_xRootKey = NULL; + + Reference< XComponent > xRootComponent(m_xSubtreeRoot, UNO_QUERY); + if (xRootComponent.is()) + xRootComponent->dispose(); + m_xSubtreeRoot = NULL; + m_xUpdateRoot = NULL; + + m_sLocation = ::rtl::OUString(); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistry::destroy( ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + throw InvalidRegistryException(UNISTRING("This registry is a wrapper for a configuration access. It can not be destroyed."), THISREF()); +} + +//-------------------------------------------------------------------------- +Reference< XRegistryKey > SAL_CALL OConfigurationRegistry::getRootKey( ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkOpen(); + + return m_xRootKey; +} + +//-------------------------------------------------------------------------- +sal_Bool SAL_CALL OConfigurationRegistry::isReadOnly( ) throw(InvalidRegistryException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + checkOpen(); + + return !m_xUpdateRoot.is(); + // if we don't have the update root, we're readonly +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistry::mergeKey( const ::rtl::OUString& aKeyName, const ::rtl::OUString& aUrl ) throw(InvalidRegistryException, MergeConflictException, RuntimeException) +{ + MutexGuard aGuard(m_aMutex); + // not supported. but we can't throw an NoSupportException here ... + throw InvalidRegistryException(UNISTRING("You can't merge into this registry. It's just a wrapper for a configuration node, which has a fixed structure which can not be modified"), THISREF()); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistry::flush( ) throw(RuntimeException) +{ + { + MutexGuard aGuard(m_aMutex); + + try + { + m_xUpdateRoot->commitChanges(); + } + catch (WrappedTargetException& e) + { // not allowed to leave this method + // TODO : the specification of XFlushable has to be changed !!!!! + OSL_ENSHURE(sal_False, "OConfigurationRegistry::flush : caught an exception, could not flush the data !"); + return; +// ::rtl::OUString sMessage; +// sMessage = UNISTRING("The changes made could not be committed. Orginal exception message : "); +// sMessage += e.Message; +// throw RuntimeException(sMessage, THISREF()); + } + } + + EventObject aFlushed(THISREF()); + ::cppu::OInterfaceIteratorHelper aIter(m_aFlushListeners); + while (aIter.hasMoreElements()) + static_cast< XFlushListener* >(aIter.next())->flushed(aFlushed); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistry::addFlushListener( const Reference< XFlushListener >& _rxListener ) throw(RuntimeException) +{ + m_aFlushListeners.addInterface(_rxListener); +} + +//-------------------------------------------------------------------------- +void SAL_CALL OConfigurationRegistry::removeFlushListener( const Reference< XFlushListener >& _rxListener ) throw(RuntimeException) +{ + m_aFlushListeners.removeInterface(_rxListener); +} + +//.......................................................................... +} // namespace configmgr +//.......................................................................... + + diff --git a/configmgr/source/registry/configregistry.hxx b/configmgr/source/registry/configregistry.hxx new file mode 100644 index 000000000000..661aa6b2bb32 --- /dev/null +++ b/configmgr/source/registry/configregistry.hxx @@ -0,0 +1,175 @@ +/************************************************************************* + * + * $RCSfile: configregistry.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONFIGMGR_REGISTRY_CONFIGREGISTRY_HXX_ +#define _CONFIGMGR_REGISTRY_CONFIGREGISTRY_HXX_ + +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ +#include <cppuhelper/implbase2.hxx> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef CONFIGMGR_API_SVCCOMPONENT_HXX_ +#include "confsvccomponent.hxx" +#endif + +#ifndef _COM_SUN_STAR_REGISTRY_XSIMPLEREGISTRY_HPP_ +#include <com/sun/star/registry/XSimpleRegistry.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XFLUSHABLE_HPP_ +#include <com/sun/star/util/XFlushable.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XCHANGESBATCH_HPP_ +#include <com/sun/star/util/XChangesBatch.hpp> +#endif + +//.......................................................................... +namespace configmgr +{ +//.......................................................................... + +//========================================================================== +//= OConfigurationRegistry +//========================================================================== +typedef ::cppu::ImplHelper2 < ::com::sun::star::registry::XSimpleRegistry + , ::com::sun::star::util::XFlushable + > OConfigurationRegistry_Base; + +/** an object implmenting the <service scope="com.sun.star.configuration">ConfigurationRegistry</service> + service. +*/ +class OConfigurationRegistry + :public ServiceComponentImpl + ,public OConfigurationRegistry_Base +{ +public: + static const ServiceInfo s_aServiceInfo; + +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + m_xORB; /// the service provider used for creating the instance + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + m_xConfigurationProvider; /// the configuration provider used for creating configuration accesses + + ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > + m_xRootKey; /// the root key for the registry-like configuration access + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + m_xSubtreeRoot; /// the root of the sub tree the object wraps + ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch > + m_xUpdateRoot; /// the update access to the root of the sub tree, valid if opened for writing + ::rtl::OUString m_sLocation; /// URL of the configuration node we're representing, if any + + ::cppu::OInterfaceContainerHelper + m_aFlushListeners; + + +public: + OConfigurationRegistry( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rORB) + throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XInterface + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL acquire( ) throw() { ServiceComponentImpl::acquire(); } + virtual void SAL_CALL release( ) throw() { ServiceComponentImpl::release(); } + + // XTypeProvider + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw(::com::sun::star::uno::RuntimeException); + + // XSimpleRegistry + virtual ::rtl::OUString SAL_CALL getURL() throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL open( const ::rtl::OUString& rURL, sal_Bool bReadOnly, sal_Bool bCreate ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isValid( ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL close( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL destroy( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > SAL_CALL getRootKey( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isReadOnly( ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL mergeKey( const ::rtl::OUString& aKeyName, const ::rtl::OUString& aUrl ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::MergeConflictException, ::com::sun::star::uno::RuntimeException); + + // XFlushable + virtual void SAL_CALL flush( ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw(::com::sun::star::uno::RuntimeException); + +protected: + virtual void SAL_CALL disposing() { ServiceComponentImpl::disposing(); } + /// translates the given URL into a nodepath which may be used with the configuration provider + ::rtl::OUString getNodePathFromURL(const ::rtl::OUString& _rURL); + + void checkOpen() throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException); + + sal_Bool isOpen() { return isValid(); } +}; + + +//.......................................................................... +} // namespace configmgr +//.......................................................................... + +#endif // _CONFIGMGR_REGISTRY_CONFIGREGISTRY_HXX_ + + diff --git a/configmgr/source/registry/makefile.mk b/configmgr/source/registry/makefile.mk new file mode 100644 index 000000000000..70653bc4fe59 --- /dev/null +++ b/configmgr/source/registry/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:13:42 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=$(PRJ)$/source$/inc +PRJNAME=configmgr +TARGET=registry + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/configregistry.obj \ + $(SLO)$/cfgregistrykey.obj \ + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/configmgr/source/tree/changes.cxx b/configmgr/source/tree/changes.cxx new file mode 100644 index 000000000000..0181578b88fe --- /dev/null +++ b/configmgr/source/tree/changes.cxx @@ -0,0 +1,194 @@ +/************************************************************************* + * + * $RCSfile: changes.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#include <stdio.h> +#include "cmtreemodel.hxx" +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +using namespace configmgr; + +//========================================================================== +//= ValueChange +//========================================================================== +// ------------------------------------------------------------------------- +ValueChange::ValueChange(OUString const& _rName,Any aNewValue, Mode aMode, Any aOldValue) + : Change(_rName) + ,m_aValue(aNewValue) + ,m_aOldValue(aOldValue) + ,m_eMode(aMode) +{ +} +// ------------------------------------------------------------------------- +ValueChange::ValueChange(Any aNewValue, ValueNode const& aOldValue) + : Change(aOldValue.getName()) + ,m_aValue(aNewValue) + ,m_aOldValue(aOldValue.getValue()) +{ + m_eMode = aOldValue.isDefault() ? wasDefault : changeValue; +} +// ------------------------------------------------------------------------- +ValueChange::ValueChange(SetToDefault, ValueNode const& aOldValue) + : Change(aOldValue.getName()) + ,m_aValue(aOldValue.getDefault()) + ,m_aOldValue(aOldValue.getValue()) + ,m_eMode(setToDefault) +{ +} + +// ------------------------------------------------------------------------- +namespace tree_changes_internal { + inline void doAdjust(uno::Any& aActual, uno::Any const& aTarget) + { + // If set - it should already match + OSL_ASSERT(!aActual.hasValue() || aTarget == aActual); + aActual = aTarget; + } +} +using namespace tree_changes_internal; + +// ------------------------------------------------------------------------- +void ValueChange::applyTo(ValueNode& aValue) +{ + switch (getMode()) + { + case wasDefault: + OSL_ASSERT(aValue.isDefault()); + case changeValue: + doAdjust( m_aOldValue, aValue.getValue()); + aValue.setValue(getNewValue()); + break; + + case setToDefault: + doAdjust( m_aOldValue, aValue.getValue()); + doAdjust( m_aValue, aValue.getDefault()); + aValue.setDefault(); + break; + + case changeDefault: + doAdjust( m_aOldValue, aValue.getDefault()); + aValue.changeDefault(getNewValue()); + break; + + default: + OSL_ENSHURE(0, "Unknown mode found for ValueChange"); + break; + } +} + +// ------------------------------------------------------------------------- +::rtl::OUString ValueChange::getModeAsString() const +{ + ::rtl::OUString aRet; + switch(m_eMode) + { + case wasDefault: + aRet = ::rtl::OUString::createFromAscii("wasDefault"); + break; + case changeValue: + aRet = ::rtl::OUString::createFromAscii("changeValue"); + break; + case setToDefault: + aRet = ::rtl::OUString::createFromAscii("setToDefault"); + break; + case changeDefault: + aRet = ::rtl::OUString::createFromAscii("changeDefault"); + break; + default: + OSL_ENSHURE(0,"getModeAsString: Wrong mode!"); + } + + return aRet; +} +// ------------------------------------------------------------------------- +void ValueChange::setModeAsString(const ::rtl::OUString& _rMode) +{ + if(_rMode == ::rtl::OUString::createFromAscii("wasDefault")) m_eMode = wasDefault; + else if(_rMode == ::rtl::OUString::createFromAscii("changeValue")) m_eMode = changeValue; + else if(_rMode == ::rtl::OUString::createFromAscii("setToDefault")) m_eMode = setToDefault; + else if(_rMode == ::rtl::OUString::createFromAscii("changeDefault"))m_eMode = changeDefault; + else + { + OSL_ENSHURE(0,"setModeAsString: Wrong mode!"); + } +} + +//========================================================================== +//= AddNode +//========================================================================== +//-------------------------------------------------------------------------- +AddNode::AddNode(std::auto_ptr<INode> aNewNode_, OUString const& _rName) + :Change(_rName) + ,m_aOwnNewNode(aNewNode_) +{ + m_pNewNode = m_aOwnNewNode.get(); +} + +//-------------------------------------------------------------------------- +AddNode::~AddNode() +{ +} + +//-------------------------------------------------------------------------- + + diff --git a/configmgr/source/tree/cmtree.cxx b/configmgr/source/tree/cmtree.cxx new file mode 100644 index 000000000000..ea565365f3e8 --- /dev/null +++ b/configmgr/source/tree/cmtree.cxx @@ -0,0 +1,719 @@ +/************************************************************************* + * + * $RCSfile: cmtree.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/* PLEASE DON'T DELETE ANY COMMENT LINES, ALSO IT'S UNNECESSARY. */ + +#include <stl/deque> +#include <stl/vector> +#include <iostream> +#include <exception> +#include <sal/types.h> +#include <stl/set> +#include <rtl/string.hxx> +#include <rtl/ustring.hxx> +#include <osl/diagnose.h> + +#include "cmtree.hxx" +#include "confname.hxx" // Iterator for PathName scans +#include "cmtreemodel.hxx" + +#include <com/sun/star/uno/Any.hxx> + +#ifndef _CONFIGMGR_TREEACCESS_HXX_ +#include "treeaccess.hxx" +#endif + +// WISDOM +// !!Never write same code twice!! + +using namespace std; +using namespace rtl; +using namespace com::sun::star::uno; + +namespace configmgr +{ + +// ------------------------ ChildListSet implementations ------------------------ + ChildListSet::ChildListSet(ChildListSet const& aSet) + { + for(ChildList::iterator it = aSet.GetSet().begin(); + it != aSet.GetSet().end(); + ++it) + m_aChildList.insert(m_aChildList.end(), (*it)->clone()); + } + ChildListSet::~ChildListSet() + { + for(ChildList::iterator it = m_aChildList.begin(); + it != m_aChildList.end(); + ++it) + delete *it; + } + + +// ---------------------------- Node implementation ---------------------------- + + INode::INode(){} + INode::INode(OUString const& aName) + :m_aName(aName){} + // CopyCTor will be create automatically + + INode::~INode() {} + + // Node* Node::clone() {} + + OUString INode::getName() const {return m_aName;} + NodeAttributes INode::getAttributes() const {return m_aNodeAttribute;} + + ISubtree* INode::asISubtree(){return NULL;} + ISubtree const* INode::asISubtree() const {return NULL;} + ValueNode* INode::asValueNode() {return NULL;} + ValueNode const* INode::asValueNode() const {return NULL;} + + +// ------------------------- SearchNode implementation ------------------------- + SearchNode::SearchNode(){} + SearchNode::SearchNode(OUString const& aName) + :INode(aName){} + + INode* SearchNode::clone() const {return new SearchNode(*this);} + + OUString SearchNode::getName() const {return getName();} + SearchNode::~SearchNode(){} + + +// -------------------------- ISubtree implementation -------------------------- + ISubtree* ISubtree::asISubtree() {return this;} + ISubtree const* ISubtree::asISubtree() const {return this;} + +// --------------------------- Subtree implementation --------------------------- + + Subtree::Subtree(OUString const& aName) + :ISubtree(aName) + ,m_nLevel(0) + ,m_bComplete(sal_False) + { + } + Subtree::Subtree() + :m_nLevel(0) + ,m_bComplete(sal_False) + { + } + Subtree::~Subtree() {} + +// #pragma message("__FILE__(__LINE__) Subtree::clone() has empty implementation") + INode* Subtree::clone() const {return new Subtree(*this);} + +// #define MAX_NODE_NAME_LENGTH 256 + +// RECURSIVE: Node* Subtree::createChild(OUString const& aPath) +// RECURSIVE: { +// RECURSIVE: //? configmgr::Node searchObj(aName); +// RECURSIVE: //? ChildList::iterator it = m_aNode->GetSet().find(&searchObj); +// RECURSIVE: //? if (it == m_aNode->GetSet().end()) +// RECURSIVE: //? return NULL; +// RECURSIVE: //? else +// RECURSIVE: //? return *it; +// RECURSIVE: sal_Unicode aName[MAX_NODE_NAME_LENGTH]; +// RECURSIVE: int nStartPos = 0; +// RECURSIVE: int nPos = 0; +// RECURSIVE: +// RECURSIVE: if (aPath[0] == '/') +// RECURSIVE: { +// RECURSIVE: nStartPos++; +// RECURSIVE: } +// RECURSIVE: if (aPath[nStartPos] == '\0') +// RECURSIVE: { +// RECURSIVE: return this; +// RECURSIVE: } +// RECURSIVE: +// RECURSIVE: int nEndPos = nStartPos; +// RECURSIVE: while ((aPath[nEndPos] != '\0') && (aPath[nEndPos] != '/')) { +// RECURSIVE: aName[nPos++] = aPath[nEndPos++]; +// RECURSIVE: } +// RECURSIVE: aName[nPos] = '\0'; +// RECURSIVE: +// RECURSIVE: #ifdef DEBUG +// RECURSIVE: // list(cout << " searching for [" << aName << "] in\n"); +// RECURSIVE: #endif +// RECURSIVE: +// RECURSIVE: // search Node +// RECURSIVE: SearchNode searchObj(aName); +// RECURSIVE: ChildList::iterator it = m_aChildren->GetSet().find(&searchObj); +// RECURSIVE: if (it == m_aChildren->GetSet().end()) +// RECURSIVE: { +// RECURSIVE: // create new Child +// RECURSIVE: auto_ptr<Node> pSubtree( new Subtree(aName)); +// RECURSIVE: Node *pN = addChild(pSubtree); +// RECURSIVE: Subtree *pS = (Subtree*)pN; +// RECURSIVE: return pS->createChild(aPath + nEndPos); +// RECURSIVE: } +// RECURSIVE: else { +// RECURSIVE: // call recursive the inner child +// RECURSIVE: Node *pN = *it; +// RECURSIVE: Subtree *pP = (Subtree*)pN; +// RECURSIVE: return pP->createChild(aPath + nEndPos); +// RECURSIVE: } +// RECURSIVE: } + + INode* Subtree::createChild(OUString const& aName) + { + // POST: create Subtree if not found + + // search Node + SearchNode searchObj(aName); + ChildList::iterator it = m_aChildren.GetSet().find(&searchObj); + if (it == m_aChildren.GetSet().end()) + { + // create new Child + auto_ptr<INode> pSubtree( new Subtree(aName)); + return addChild(pSubtree); + } + return *it; + } + + INode* Subtree::doGetChild(OUString const& aName) const + { + SearchNode searchObj(aName); + ChildList::iterator it = m_aChildren.GetSet().find(&searchObj); + if (it == m_aChildren.GetSet().end()) + return NULL; + else + return *it; + } + + INode* Subtree::addChild(std::auto_ptr<INode> aNode) // takes ownership + { + OUString aName = aNode->getName(); + std::pair<ChildList::iterator, bool> aInserted = + m_aChildren.GetSet().insert(aNode.get()); + if (aInserted.second) + aNode.release(); + return *aInserted.first; + } + + ::std::auto_ptr<INode> Subtree::removeChild(OUString const& aName) + { + SearchNode searchObj(aName); + ChildList::const_iterator it = m_aChildren.GetSet().find(&searchObj); + + ::std::auto_ptr<INode> aReturn; + if (m_aChildren.GetSet().end() != it) + { + aReturn = ::std::auto_ptr<INode>(*it); + m_aChildren.GetSet().erase(it); + } + return aReturn; + } + + struct OPropagateLevels : public NodeModification + { + protected: + sal_Int32 nChildLevel; + public: + OPropagateLevels(sal_Int32 _nParentLevel) + { + nChildLevel = (ITreeProvider::ALL_LEVELS == _nParentLevel) ? ITreeProvider::ALL_LEVELS : _nParentLevel - 1; + } + virtual void handle(ValueNode&) { /* not interested in value nodes */ } + virtual void handle(ISubtree& _rSubtree) + { + if ((ITreeProvider::ALL_LEVELS == nChildLevel) || (nChildLevel > 0)) + { + OPropagateLevels aDeeperInto(nChildLevel); + aDeeperInto.applyToChildren(_rSubtree); + } + } + }; + + void Subtree::setLevel(sal_Int16 _nLevel) + { + m_nLevel = _nLevel; + if (0 == _nLevel) + // nothing more to do, this means "nothing known about any children" + return; + + // forward the level number to any child subtrees we have + OPropagateLevels aDeeperInto(_nLevel); + aDeeperInto.applyToChildren(*this); + } + + void Subtree::forEachChild(NodeAction& anAction) const { + for(ChildList::const_iterator it = m_aChildren.GetSet().begin(); + it != m_aChildren.GetSet().end(); + ++it) + (**it).dispatch(anAction); + } + + void Subtree::forEachChild(NodeModification& anAction) { + for(ChildList::iterator it = m_aChildren.GetSet().begin(); + it != m_aChildren.GetSet().end(); + ++it) + (**it).dispatch(anAction); + } + +// -------------------------- ValueNode implementation -------------------------- + void ValueNode::check_init() // may throw in the future + { + if (m_aValue.hasValue()) + { + OSL_ASSERT(m_aType != ::getVoidCppuType()); + OSL_ASSERT(m_aType == m_aValue.getValueType()); + } + else OSL_ASSERT(getVoidCppuType() == m_aValue.getValueType()); + + if (m_aDefaultValue.hasValue()) + { + OSL_ASSERT(m_aType != ::getVoidCppuType()); + OSL_ASSERT(m_aType == m_aDefaultValue.getValueType()); + } + else OSL_ASSERT(getVoidCppuType() == m_aDefaultValue.getValueType()); + } + + void ValueNode::init() + { + OSL_ASSERT(m_aType == ::getVoidCppuType()); + + if (m_aDefaultValue.hasValue()) + { + m_aType = m_aDefaultValue.getValueType(); + OSL_ASSERT(m_aType != ::getVoidCppuType()); + } + else if (m_aValue.hasValue()) + { + m_aType = m_aValue.getValueType(); + OSL_ASSERT(m_aType != ::getVoidCppuType()); + } + } + + bool ValueNode::isDefault() const + { + // POST: true, if only m_aDefaultValue is set. + return !m_aValue.hasValue() && hasDefault(); + } + + bool ValueNode::hasDefault() const + { + // POST: true, if only m_aDefaultValue is set. + return getAttributes().optional || m_aDefaultValue.hasValue(); + } + + bool ValueNode::isNull() const + { + // POST: true, if neither Any is set. + return !m_aValue.hasValue() && !m_aDefaultValue.hasValue(); + } + + + Type ValueNode::getValueType() const + { + // POST: return Type of Any + return m_aType; + } + + Any ValueNode::getValue() const + { + // POST: getValue, if not set, get DefaultValue + if (isDefault()) + return m_aDefaultValue; + return m_aValue; + } + + Any ValueNode::getDefault() const + { + return m_aDefaultValue; + } + + + void ValueNode::setValue(Any aValue) + { + m_aValue = aValue; + } + + void ValueNode::changeDefault(Any aValue) + { + m_aDefaultValue = aValue; + } + + void ValueNode::setDefault() + { + // PRE: ???? + // POST: isDefault() == true + m_aValue = Any(); + } + + INode* ValueNode::clone() const + { + return new ValueNode(*this); + } + + ValueNode* ValueNode::asValueNode() {return this;} + ValueNode const* ValueNode::asValueNode() const {return this;} + +// ---------------------------- Tree implementation ---------------------------- + + Tree::Tree() + : m_pRoot(NULL), m_pLock(NULL) + { + m_pRoot = new Subtree(); + m_pLock = new OTreeAccessor; + } + + Tree::~Tree() + { + delete m_pLock; + } + + void Tree::acquireReadAccess() const + { + m_pLock->acquireReadAccess(); + } + + void Tree::releaseReadAccess() const + { + m_pLock->releaseReadAccess(); + } + + void Tree::acquireWriteAccess() + { + m_pLock->acquireWriteAccess(); + } + + void Tree::releaseWriteAccess() + { + m_pLock->releaseWriteAccess(); + } + +// ----------------------------------------------------------------------------- + ISubtree* Tree::requestSubtree( OUString const& aComponentName, sal_Int16 nLevel ) + { + // OLD: + // INode* pResult = m_pRoot->getChild(aComponentName); + // return pResult->asISubtree(); + + // Build SearchName + OSL_ENSHURE(m_pRoot, "Tree::requestSubtree : m_pRoot MUST NOT BE ZERO"); + // hey, don't cry that loud .... + + ISubtree* pSubtree = m_pRoot; + ConfigurationName aConfigName(aComponentName,ConfigurationName::Absolute() ); + for(ConfigurationName::Iterator it = aConfigName.begin(); + it != aConfigName.end(); + ++it) + { + if (pSubtree) + { + INode* pNode = pSubtree->getChild(*it); + if (!pNode) + return NULL; + + pSubtree = pNode->asISubtree(); + } + else + break; + } + + if (pSubtree && (ALL_LEVELS != pSubtree->getLevel()) && (nLevel > pSubtree->getLevel())) + pSubtree = NULL; + return pSubtree; + } + +// ----------------------------------------------------------------------------- + const INode* Tree::getNode(const OUString& _rPath) + { + OSL_ENSHURE(m_pRoot, "Tree::getNode : invalid root !"); + + ConfigurationName aPath(_rPath, ConfigurationName::Absolute() ); + + INode* pNodeLoop = m_pRoot; + for ( ConfigurationName::Iterator aSearch = aPath.begin(); + (aSearch != aPath.end()) && pNodeLoop; + ++aSearch) + { + ISubtree* pNodeContainer = pNodeLoop->asISubtree(); + if (pNodeContainer) + pNodeLoop = pNodeContainer->getChild(*aSearch); + else + return NULL; + } + + return pNodeLoop; + } + +// ----------------------------------------------------------------------------- + ISubtree const* Tree::getSubtree( OUString const& aComponentName ) const + { + // Build SearchName + OSL_ENSHURE(m_pRoot, "m_pRoot MUST NOT BE ZERO"); + + ISubtree const* pSubtree = m_pRoot; + ConfigurationName aConfigName(aComponentName,ConfigurationName::Absolute() ); + for(ConfigurationName::Iterator it = aConfigName.begin(); + it != aConfigName.end(); + ++it) + { + if (pSubtree) + { + const INode* pNode = pSubtree->getChild(*it); + if (!pNode) + return NULL; + + pSubtree = pNode->asISubtree(); + } + else + break; + } + return pSubtree; + /* + sal_Unicode aName[MAX_NODE_NAME_LENGTH]; + int nStartPos = 0; + int nPos = 0; + + if (aPath[0] == '/') + { + nStartPos++; + } + if (aPath[nStartPos] == '\0') + { + return this; + } + + int nEndPos = nStartPos; + while ((aPath[nEndPos] != '\0') && (aPath[nEndPos] != '/')) { + aName[nPos++] = aPath[nEndPos++]; + } + aName[nPos] = '\0'; + + ISubtree const* pSubtree = m_pRoot->getChild(aName)->asISubtree(); + + + if (pSubtree) + { + // call recursive the inner child + return pSubtree->getSubtree(aPath + nEndPos); + } + return NULL; + */ + } + + Subtree * Tree::addSubtree(const ConfigurationName& _rLocation, std::auto_ptr<Subtree> _pSubtree, sal_Int16 nLevels) + { + OSL_ENSHURE(nLevels != 0, "Tree::addSubtree : invalid level count !"); + // there was a time where 0 meant "all levels", but we changed the according enum in ITReeProvider + // so that it is -1 now. Since this time, 0 isn't valid as level depth anymore ! + + auto_ptr<INode> pNode; + + // look for the place where to insert the given node + ConfigurationName::Iterator aGoDown = _rLocation.begin(); + ConfigurationName::Iterator aStopAt = _rLocation.end(); + Subtree* pInsertInto = m_pRoot; + while (aGoDown != aStopAt) + { + OUString sCurrentName = *aGoDown; + ++aGoDown; + + Subtree* pExistentSubtree = static_cast<Subtree*>(pInsertInto->getChild(sCurrentName)); + if (!pExistentSubtree) + { + Subtree* pNewChild = NULL; + if (aGoDown != aStopAt) + { // we already incremented aGoDown, so this means we still have (at least) one level to go + // -> we need a new temporary node + pNewChild = new Subtree(sCurrentName); + pNewChild = static_cast<Subtree*>(pInsertInto->addChild(::std::auto_ptr<INode>(pNewChild))); + pNewChild->setLevel(0); // which means "we know nothing about any children" + } + else + { // at this last level, we don't need an intermediate node, instead we have to insert _pSubtree here + break; + } + pExistentSubtree = pNewChild; + } + + // one level down + pInsertInto = pExistentSubtree; + } + + Subtree* pNewSubtree = static_cast<Subtree*>(pInsertInto->addChild(::std::auto_ptr<INode>(_pSubtree.release()))); + pNewSubtree->setLevel(nLevels); + return pNewSubtree; + } + + + // --------------------------------- updateTree --------------------------------- + class TreeUpdate : public ChangeTreeModification + { + ISubtree* m_pCurrentSubtree; + std::vector<OString> aLog; + + public: + TreeUpdate(ISubtree* pSubtree):m_pCurrentSubtree(pSubtree){} + + void handle(ValueChange& aValueNode); + void handle(AddNode& aAddNode); + void handle(RemoveNode& aRemoveNode); + void handle(SubtreeChange& aSubtree); + }; + + void TreeUpdate::handle(ValueChange& aValueNode) + { + // Change a Value + OSL_ENSURE(m_pCurrentSubtree,"Cannot apply ValueChange without subtree"); + + INode* pBaseNode = m_pCurrentSubtree ? m_pCurrentSubtree->getChild(aValueNode.getNodeName()) : 0; + OSL_ENSURE(pBaseNode,"Cannot apply Change: No node to change"); + + ValueNode* pValue = pBaseNode ? pBaseNode->asValueNode() : 0; + OSL_ENSURE(pValue,"Cannot apply ValueChange: Node is not a value"); + + if (pValue) + aValueNode.applyTo(*pValue); +#ifdef DBUG + else + { + ::rtl::OString aStr("TreeUpdate: Can't find value with name:="); + aStr += rtl::OUStringToOString(aValueNode.getNodeName(),RTL_TEXTENCODING_ASCII_US); + OSL_ENSHURE(pValue, aStr.getStr()); + aLog.push_back(aStr); + } +#endif + } + + void TreeUpdate::handle(AddNode& aAddNode) + { + // Add a new Value + if (m_pCurrentSubtree) + m_pCurrentSubtree->addChild(aAddNode.releaseAddedNode()); +#ifdef DBUG + else + aLog.push_back(OString("TreeUpdate: no CurrentSubtree for AddNode")); +#endif + + } + + void TreeUpdate::handle(RemoveNode& aRemoveNode) + { + // remove a Value + if (m_pCurrentSubtree) + { + sal_Bool bOk = (NULL != m_pCurrentSubtree->removeChild(aRemoveNode.getNodeName()).get()); + +#ifdef DBUG + ::rtl::OString aStr("TreeUpdate: Can't remove child with name:="); + aStr += rtl::OUStringToOString(aRemoveNode.getNodeName(),RTL_TEXTENCODING_ASCII_US); + OSL_ENSHURE(bOk, aStr.getStr()); + if (!bOk) + aLog.push_back(aStr); +#endif + } + } + + + void TreeUpdate::handle(SubtreeChange& aSubtree) + { + // handle traversion + ISubtree *pOldSubtree = m_pCurrentSubtree; + OSL_ENSHURE(m_pCurrentSubtree->getChild(aSubtree.getNodeName()), "TreeUpdate::handle : invalid subtree change ... this will crash !"); + m_pCurrentSubtree = m_pCurrentSubtree->getChild(aSubtree.getNodeName())->asISubtree(); + +#if DEBUG + ::rtl::OString aStr("TreeUpdate: there is no Subtree for name:="); + aStr += rtl::OUStringToOString(aSubtree.getNodeName(),RTL_TEXTENCODING_ASCII_US); + OSL_ENSHURE(m_pCurrentSubtree, aStr.getStr()); + if (!m_pCurrentSubtree) + aLog.push_back(aStr); +#endif + + aSubtree.forEachChange(*this); + m_pCurrentSubtree = pOldSubtree; + } + + + void Tree::updateTree( TreeChangeList& aTree) throw (starlang::WrappedTargetException, uno::RuntimeException) + { + ConfigurationName aSubtreeName(aTree.pathToRoot, aTree.root.getNodeName()); + ISubtree *pSubtree = requestSubtree(aSubtreeName.fullName(), ITreeProvider::ALL_LEVELS); + +#ifdef DEBUG + ::rtl::OString aStr("Tree: there is no Subtree for name:="); + aStr += rtl::OUStringToOString(aSubtreeName.fullName(),RTL_TEXTENCODING_ASCII_US); + OSL_ENSHURE(pSubtree, aStr.getStr()); +#endif + + if (pSubtree) + { + TreeUpdate aTreeUpdate(pSubtree); + aTree.root.forEachChange(aTreeUpdate); + } + // Better: + // ISubtree *pCloneTree = m_pRoot->clone(); + // ISubtree *pSubtree = pCloneTree->requestSubtree(aTree.pathToRoot, ITreeProvider::ALL_LEVELS); + // TreeUpdate aTreeUpdate(pSubtree); + // aTreeUpdate.handle(aTree.root); + // if (aTreeUpdate.isOk()) + // { + // delete m_pRoot; + // m_pRoot = pSubtree; + // } + } +} // namespace configmgr + + diff --git a/configmgr/source/tree/cmtreemodel.cxx b/configmgr/source/tree/cmtreemodel.cxx new file mode 100644 index 000000000000..2ef5f6e846aa --- /dev/null +++ b/configmgr/source/tree/cmtreemodel.cxx @@ -0,0 +1,323 @@ +/************************************************************************* + * + * $RCSfile: cmtreemodel.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> +#ifndef CONFIGMGR_CMTREEMODEL_HXX +#include "cmtreemodel.hxx" +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +//.......................................................................... +namespace configmgr +{ +//.......................................................................... + +//========================================================================== +//= SubtreeChange +//========================================================================== +//-------------------------------------------------------------------------- +SubtreeChange::SubtreeChange(OUString const& _rName) + :Change(_rName) +{ +} + +//-------------------------------------------------------------------------- +SubtreeChange::~SubtreeChange() +{ + for(Children::iterator aIter = m_mChanges.begin(); + aIter != m_mChanges.end(); + ++aIter) + { + // Change* pChange = aIter->second; + delete aIter->second; + } +} + +//-------------------------------------------------------------------------- +void SubtreeChange::addChange(std::auto_ptr<Change> aChange) +{ + OUString aNodeName(aChange->getNodeName()); + OSL_ENSHURE(m_mChanges.end() == m_mChanges.find(aNodeName), + "SubtreeChange::addChange : overwriting an existent change !"); + delete m_mChanges[aNodeName]; + m_mChanges[aNodeName] = aChange.release(); +} + +//-------------------------------------------------------------------------- +::std::auto_ptr<Change> SubtreeChange::removeChange(OUString const& _rName) +{ + Children::iterator aIter = m_mChanges.find(_rName); + + ::std::auto_ptr<Change> aReturn; + if (m_mChanges.end() != aIter) + { + aReturn = ::std::auto_ptr<Change>(aIter->second); + m_mChanges.erase(aIter); + } + return aReturn; +} + +//-------------------------------------------------------------------------- +Change* SubtreeChange::getChange(OUString const& _rName) +{ + return doGetChild(_rName); +} + +//-------------------------------------------------------------------------- +Change const* SubtreeChange::getChange(OUString const& _rName) const +{ + return doGetChild(_rName); +} + +//-------------------------------------------------------------------------- +void SubtreeChange::dispatch(ChangeTreeAction& _anAction) const +{ + _anAction.handle(*this); +} + +//-------------------------------------------------------------------------- +void SubtreeChange::dispatch(ChangeTreeModification& _anAction) +{ + _anAction.handle(*this); +} + +//-------------------------------------------------------------------------- +void SubtreeChange::forEachChange(ChangeTreeAction& _anAction) const +{ + ::std::map< ::rtl::OUString,Change* >::const_iterator aIter = m_mChanges.begin(); + for(;aIter != m_mChanges.end();) + { + ::std::map< ::rtl::OUString,Change* >::const_iterator aNextIter = aIter; + ++aNextIter; + aIter->second->dispatch(_anAction); + aIter = aNextIter; + } +} + +//-------------------------------------------------------------------------- +void SubtreeChange::forEachChange(ChangeTreeModification& _anAction) +{ + ::std::map< ::rtl::OUString,Change* >::const_iterator aIter = m_mChanges.begin(); + for(;aIter != m_mChanges.end();++aIter) + aIter->second->dispatch(_anAction); +} + +//-------------------------------------------------------------------------- +Change* SubtreeChange::doGetChild(OUString const& _rName) const +{ + Children::const_iterator aIter = m_mChanges.find(_rName); + return (aIter != m_mChanges.end()) ? aIter->second : NULL; +} + +//-------------------------------------------------------------------------- +uno::Sequence< OUString > SubtreeChange::elementNames() const +{ + uno::Sequence< OUString > aReturn(size()); + OUString* pReturn = aReturn.getArray(); + + for ( Children::const_iterator aCollector = m_mChanges.begin(); + aCollector != m_mChanges.end(); + ++aCollector, ++pReturn + ) + { + *pReturn = aCollector->first; + } + + return aReturn; +} + +//-------------------------------------------------------------------------- +SubtreeChange::ChildIterator SubtreeChange::begin() const throw() +{ + return ChildIterator(this); +} + +//-------------------------------------------------------------------------- +SubtreeChange::ChildIterator SubtreeChange::end() const throw() +{ + return ChildIterator(this, ChildIterator::EndPos()); +} + +//-------------------------------------------------------------------------- +SubtreeChange::ChildIterator::ChildIterator(const SubtreeChange* _pTree) + :m_pTree(_pTree) + ,m_aNames(_pTree->elementNames()) + ,m_nPos(0) +{ +} + +//-------------------------------------------------------------------------- +SubtreeChange::ChildIterator::ChildIterator(const SubtreeChange* _pTree, struct EndPos) + :m_pTree(_pTree) + ,m_aNames(_pTree->elementNames()) + ,m_nPos(_pTree->size()) +{ +} + +//-------------------------------------------------------------------------- +Change const * SubtreeChange::ChildIterator::operator*() const +{ + if (isValid()) + return m_pTree->getChange(m_aNames[m_nPos]); + OSL_ENSHURE(sal_False, "SubtreeChange::ChildIterator::operator* : invalid iterator !"); + return NULL; +} + +//-------------------------------------------------------------------------- +Change const * SubtreeChange::ChildIterator::operator->() const +{ + if (isValid()) + return m_pTree->getChange(m_aNames[m_nPos]); + OSL_ENSHURE(sal_False, "SubtreeChange::ChildIterator::operator-> : invalid iterator !"); + return NULL; +} + +//-------------------------------------------------------------------------- +SubtreeChange::ChildIterator& SubtreeChange::ChildIterator::operator++() +{ + OSL_ENSHURE(m_nPos < m_aNames.getLength(), "SubtreeChange::ChildIterator : can't increment the end iterator !"); + if (m_nPos < m_aNames.getLength()) + ++m_nPos; + return *this; +} + +//-------------------------------------------------------------------------- +SubtreeChange::ChildIterator& SubtreeChange::ChildIterator::operator--() +{ + OSL_ENSHURE(m_nPos > 0, "SubtreeChange::ChildIterator : can't decrement the begin iterator !"); + if (m_nPos > 0) + --m_nPos; + return *this; +} + +//-------------------------------------------------------------------------- +bool operator==(SubtreeChange::ChildIterator const& lhs, SubtreeChange::ChildIterator const& rhs) +{ + return (lhs.m_pTree == rhs.m_pTree) && (lhs.m_nPos == rhs.m_nPos); +} + +//========================================================================== +//= SubtreeChangeReferrer +//========================================================================== +//-------------------------------------------------------------------------- +SubtreeChangeReferrer::SubtreeChangeReferrer(const SubtreeChange& _rSource) + :SubtreeChange(_rSource.getNodeName()) +{ + ChildIterator aSourceChildren = _rSource.begin(); + while (aSourceChildren != _rSource.end()) + { + const Change* pChange = *aSourceChildren; + OSL_ENSHURE(pChange, "SubtreeChangeReferrer::SubtreeChangeReferrer : invalid change !"); + if ( pChange->isA(ValueChange::getStaticType()) + || pChange->isA(RemoveNode::getStaticType()) + || pChange->isA(AddNode::getStaticType()) + ) + SubtreeChange::addChange(::std::auto_ptr<Change>(const_cast<Change*>(pChange))); + else if ( pChange->isA(SubtreeChange::getStaticType()) + || pChange->isA(SubtreeChangeReferrer::getStaticType()) + ) + { + SubtreeChange::addChange(::std::auto_ptr<Change>(new SubtreeChangeReferrer(*static_cast<const SubtreeChange*>(pChange)))); + } + else + OSL_ENSHURE(sal_False, "SubtreeChangeReferrer::SubtreeChangeReferrer : unknown changes type !"); + + ++aSourceChildren; + } +} + +//-------------------------------------------------------------------------- +SubtreeChangeReferrer::~SubtreeChangeReferrer() +{ + for ( Children::iterator aChildren = m_mChanges.begin(); + aChildren != m_mChanges.end(); + ++aChildren + ) + { + const Change* pChange = aChildren->second; + if ( pChange->isA(ValueChange::getStaticType()) + || pChange->isA(RemoveNode::getStaticType()) + || pChange->isA(AddNode::getStaticType()) + ) + { + // we just hold references to the non-SubtreeChange-objects, so don't delete them + m_mChanges.erase(aChildren); + } + else if ( pChange->isA(SubtreeChange::getStaticType()) + || pChange->isA(SubtreeChangeReferrer::getStaticType()) + ) + { + // nothing to do + } + else + OSL_ENSHURE(sal_False, "SubtreeChangeReferrer::~SubtreeChangeReferrer : unknown changes type !"); + } + + // the base class will remove the remaining SubtreeChanges, which are SubtreeChangeReferrer's in real +} + +//.......................................................................... +} // namespace configmgr +//.......................................................................... + + diff --git a/configmgr/source/tree/makefile.mk b/configmgr/source/tree/makefile.mk new file mode 100644 index 000000000000..6d0cead70b93 --- /dev/null +++ b/configmgr/source/tree/makefile.mk @@ -0,0 +1,89 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:13:42 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=$(PRJ)$/source + +PRJNAME=configmgr +TARGET=cm +ENABLE_EXCEPTIONS=TRUE + + +# --- Settings --- +.IF "$(DBGUTIL_OJ)"!="" +ENVCFLAGS+=/FR$(SLO)$/ +.ENDIF + +.INCLUDE : settings.mk + +# --- Files --- + +SLOFILES=\ + $(SLO)$/changes.obj \ + $(SLO)$/cmtreemodel.obj \ + $(SLO)$/cmtree.obj + +# --- Targets --- + +.INCLUDE : target.mk +.INCLUDE : $(PRJ)$/util$/target.pmk + diff --git a/configmgr/source/treecache/makefile.mk b/configmgr/source/treecache/makefile.mk new file mode 100644 index 000000000000..5a211c6a2238 --- /dev/null +++ b/configmgr/source/treecache/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:13:42 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=$(PRJ)$/source +PRJNAME=configmgr +TARGET=treecache + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/treecache.obj \ + + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/configmgr/source/xml/makefile.mk b/configmgr/source/xml/makefile.mk new file mode 100644 index 000000000000..7dbbe2583a70 --- /dev/null +++ b/configmgr/source/xml/makefile.mk @@ -0,0 +1,92 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:13:42 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJINC=$(PRJ)$/source +PRJNAME=configmgr +TARGET=xml +ENABLE_EXCEPTIONS=TRUE + +# --- Settings --- + +.INCLUDE : settings.mk + +# --- Files --- + + +SLOFILES=\ + $(SLO)$/typeconverter.obj \ + $(SLO)$/xmltreebuilder.obj \ + $(SLO)$/xmlformater.obj \ + $(SLO)$/localsession.obj \ + $(SLO)$/mergeupdates.obj \ + $(SLO)$/dataexport.obj \ + $(SLO)$/dataimport.obj \ + $(SLO)$/updatedom.obj \ + + +# --- Targets --- + +.INCLUDE : target.mk +.INCLUDE : $(PRJ)$/util$/target.pmk + diff --git a/configmgr/source/xml/typeconverter.cxx b/configmgr/source/xml/typeconverter.cxx new file mode 100644 index 000000000000..db302e3c6a29 --- /dev/null +++ b/configmgr/source/xml/typeconverter.cxx @@ -0,0 +1,362 @@ +/************************************************************************* + * + * $RCSfile: typeconverter.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:13:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include "typeconverter.hxx" + +#ifndef _COM_SUN_STAR_SCRIPT_XTYPECONVERTER_HPP_ +#include <com/sun/star/script/XTypeConverter.hpp> +#endif +#ifndef _COM_SUN_STAR_SCRIPT_FAILREASON_HPP_ +#include <com/sun/star/script/FailReason.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ +#include <com/sun/star/uno/Type.hxx> +#endif + +#ifndef _TYPELIB_TYPEDESCRIPTION_HXX_ +#include <typelib/typedescription.hxx> +#endif + + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +//#include <stdio.h> + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +namespace staruno = ::com::sun::star::uno; +namespace starscript = ::com::sun::star::script; +namespace starlang = ::com::sun::star::lang; + +namespace configmgr +{ + +//-------------------------------------------------------------------------------------------------- + rtl::OUString toString(const staruno::Reference< starscript::XTypeConverter >& xTypeConverter, const staruno::Any& rValue) throw( starscript::CannotConvertException ) + { + rtl::OUString aRes; + ::staruno::TypeClass aDestinationClass = rValue.getValueType().getTypeClass(); + + switch (aDestinationClass) + { + case ::staruno::TypeClass_BOOLEAN: + case ::staruno::TypeClass_CHAR: + case ::staruno::TypeClass_BYTE: + case ::staruno::TypeClass_SHORT: + case ::staruno::TypeClass_LONG: + case ::staruno::TypeClass_FLOAT: + case ::staruno::TypeClass_DOUBLE: + if (!xTypeConverter.is()) + { + throw( starscript::CannotConvertException( ::rtl::OUString::createFromAscii("stardiv.script.Converter!"), ::staruno::Reference< ::staruno::XInterface > (), + aDestinationClass, starscript::FailReason::UNKNOWN, 0 ) ); + } + xTypeConverter->convertToSimpleType(rValue, ::staruno::TypeClass_STRING) >>= aRes; + break; + case ::staruno::TypeClass_STRING: + rValue >>= aRes; + break; + default: + throw( starscript::CannotConvertException( ::rtl::OUString::createFromAscii("TYPE is not supported!"), staruno::Reference< ::staruno::XInterface > (), + aDestinationClass, starscript::FailReason::TYPE_NOT_SUPPORTED, 0 ) ); + + } + return aRes; + } + + staruno::Any toAny(const staruno::Reference< starscript::XTypeConverter >& xTypeConverter, const ::rtl::OUString& _rValue,const staruno::TypeClass& _rTypeClass) throw( starscript::CannotConvertException ) + { + staruno::Any aRes; + try + { + xTypeConverter->convertToSimpleType(staruno::makeAny(_rValue), _rTypeClass) >>= aRes; + } + catch (starscript::CannotConvertException&) + { + OSL_ENSHURE(sal_False, "toAny : could not convert !"); + } + catch (starlang::IllegalArgumentException&) + { + OSL_ENSHURE(sal_False, "toAny : could not convert !"); + } + return aRes; + } + + ::rtl::OUString toTypeName(const staruno::TypeClass& _rTypeClass) + { + ::rtl::OUString aRet; + switch(_rTypeClass) + { + case staruno::TypeClass_BOOLEAN: aRet = ::rtl::OUString::createFromAscii("boolean"); break; + case staruno::TypeClass_SHORT: aRet = ::rtl::OUString::createFromAscii("short"); break; + case staruno::TypeClass_LONG: aRet = ::rtl::OUString::createFromAscii("integer"); break; + case staruno::TypeClass_HYPER: aRet = ::rtl::OUString::createFromAscii("long"); break; + case staruno::TypeClass_DOUBLE: aRet = ::rtl::OUString::createFromAscii("double"); break; + case staruno::TypeClass_STRING: aRet = ::rtl::OUString::createFromAscii("string"); break; + case staruno::TypeClass_SEQUENCE: aRet = ::rtl::OUString::createFromAscii("binary"); break; + default: + { + ::rtl::OString aStr("Wrong typeclass! "); + aStr += ::rtl::OString::valueOf((sal_Int32)_rTypeClass); + OSL_ENSHURE(0,aStr.getStr()); + } + } + return aRet; + } + + staruno::TypeClass toTypeClass(const ::rtl::OUString& _rType) + { + staruno::TypeClass aRet = staruno::TypeClass_VOID; + + if (_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("boolean"))) aRet = staruno::TypeClass_BOOLEAN; + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("short"))) aRet = staruno::TypeClass_SHORT; + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("int"))) aRet = staruno::TypeClass_LONG; + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("integer"))) aRet = staruno::TypeClass_LONG; + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("long"))) aRet = staruno::TypeClass_HYPER; + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double"))) aRet = staruno::TypeClass_DOUBLE; + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string"))) aRet = staruno::TypeClass_STRING; + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary"))) aRet = staruno::TypeClass_SEQUENCE; + else + { + ::rtl::OString aStr("Wrong typeclass! "); + aStr += rtl::OUStringToOString(_rType,RTL_TEXTENCODING_ASCII_US); + OSL_ENSHURE(0,aStr.getStr()); + } + + return aRet; + } + +// ************************************************************************* + + namespace + { + + inline staruno::Type getBooleanType() { return ::getBooleanCppuType(); } + + inline staruno::Type getShortType() { return ::getCppuType(static_cast<sal_Int16 const*>(0)); } + inline staruno::Type getIntType() { return ::getCppuType(static_cast<sal_Int32 const*>(0)); } + inline staruno::Type getLongType() { return ::getCppuType(static_cast<sal_Int64 const*>(0)); } + + inline staruno::Type getDoubleType() { return ::getCppuType(static_cast<double const*>(0)); } + + inline staruno::Type getStringType() { return ::getCppuType(static_cast<rtl::OUString const*>(0)); } + +// ************************************************************************* +/* + ::rtl::OUString findXMLTypeName(const staruno::Type& _rType) + { + ::rtl::OUString aRet; + switch(_rType.getTypeClass()) + { + case staruno::TypeClass_BOOLEAN: + OSL_ASSERT( _rType == getBooleanType() ); + aRet = ::rtl::OUString::createFromAscii("boolean"); + break; + + case staruno::TypeClass_SHORT: + OSL_ASSERT( _rType == getShortType() ); + aRet = ::rtl::OUString::createFromAscii("short"); + break; + + case staruno::TypeClass_LONG: + OSL_ASSERT( _rType == getIntType() ); + aRet = ::rtl::OUString::createFromAscii("int"); + break; + + case staruno::TypeClass_HYPER: + OSL_ASSERT( _rType == getLongType() ); + Ret = ::rtl::OUString::createFromAscii("long"); + break; + + case staruno::TypeClass_DOUBLE: + OSL_ASSERT( _rType == getDoubleType() ); + aRet = ::rtl::OUString::createFromAscii("double"); + break; + + case staruno::TypeClass_STRING: + OSL_ASSERT( _rType == getStringType() ); + aRet = ::rtl::OUString::createFromAscii("string"); + break; + + case staruno::TypeClass_SEQUENCE: + if ( _rType == getStringType() ); + aRet = ::rtl::OUString::createFromAscii("sequence"); + break; + + default: + { + ::rtl::OString aStr("Wrong typeclass! "); + aStr += ::rtl::OString::valueOf((sal_Int32)_rTypeClass); + OSL_ENSHURE(0,aStr.getStr()); + } + } + return aRet; + } + */ + } // unamed namespace +// ************************************************************************* + + staruno::Type toType(const ::rtl::OUString& _rType) + { + staruno::Type aRet; + + if (_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("boolean"))) aRet = getBooleanType(); + + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("short"))) aRet = getShortType(); + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("int"))) aRet = getIntType(); + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("integer"))) aRet = getIntType(); + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("long"))) aRet = getLongType(); + + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double"))) aRet = getDoubleType(); + + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string"))) aRet = getStringType(); + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary"))) aRet = getBinaryType(); +// else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("sequence"))) aRet = staruno::TypeClass_SEQUENCE; + else + { + ::rtl::OString aStr("Unknown type! "); + aStr += rtl::OUStringToOString(_rType,RTL_TEXTENCODING_ASCII_US); + OSL_ENSHURE(0,aStr.getStr()); + } + + return aRet; + } + staruno::Type toListType(const ::rtl::OUString& _rsElementType) + { + staruno::Type aRet; + + if (_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("boolean"))) + aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Bool> const*>(0)); + + else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("short"))) + aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int16> const*>(0)); + + else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("int"))) + aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int32> const*>(0)); + else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("integer"))) + aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int32> const*>(0)); + + else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("long"))) + aRet = ::getCppuType(static_cast<staruno::Sequence<sal_Int64> const*>(0)); + + else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double"))) + aRet = ::getCppuType(static_cast<staruno::Sequence<double> const*>(0)); + + else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string"))) + aRet = ::getCppuType(static_cast<staruno::Sequence<rtl::OUString> const*>(0)); + + else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary"))) + aRet = ::getCppuType(static_cast<staruno::Sequence<staruno::Sequence<sal_Int8> > const*>(0)); + +// else if(_rsElementType.equalsIgnoreCase(::rtl::OUString::createFromAscii("sequence"))) aRet = staruno::TypeClass_SEQUENCE; + else + { + ::rtl::OString aStr("Unknown type! "); + aStr += rtl::OUStringToOString(_rsElementType,RTL_TEXTENCODING_ASCII_US); + OSL_ENSHURE(0,aStr.getStr()); + } + + return aRet; + } + + staruno::Type getSequenceElementType(staruno::Type const& rSequenceType) + { + OSL_ENSHURE(rSequenceType.getTypeClass() == staruno::TypeClass_SEQUENCE, + "getSequenceElementType() must be called with a sequence type"); + + if (!(rSequenceType.getTypeClass() == staruno::TypeClass_SEQUENCE)) + return staruno::Type(); + + staruno::TypeDescription aTD(rSequenceType); + typelib_IndirectTypeDescription* pSequenceTD = + reinterpret_cast< typelib_IndirectTypeDescription* >(aTD.get()); + + OSL_ASSERT(pSequenceTD); + OSL_ASSERT(pSequenceTD->pType); + + if (pSequenceTD && pSequenceTD->pType) + { + #if (SUPD >= 0x601) + return staruno::Type(pSequenceTD->pType); + #else + OSL_ASSERT(pSequenceTD->pType); + return staruno::Type(pSequenceTD->pType->pWeakRef); + #endif + } + + return staruno::Type(); + } + staruno::Type getBasicType(staruno::Type const& rType, bool& bSequence) + { + bSequence = rType.getTypeClass() == staruno::TypeClass_SEQUENCE && + rType != getBinaryType(); + + if (!bSequence) + return rType; + + return getSequenceElementType(rType); + } + + +} // namespace configmgr |