1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accessimpl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
35 #include "accessimpl.hxx"
36 #include "apinodeaccess.hxx"
37 #include "valueref.hxx"
38 #include "anynoderef.hxx"
39 #include "noderef.hxx"
40 #include "configset.hxx"
41 #include "confignotifier.hxx"
42 #include "propertyinfohelper.hxx"
43 #include "treeiterators.hxx"
44 #include "attributes.hxx"
45 #include "apitypes.hxx"
46 #include <com/sun/star/lang/DisposedException.hpp>
47 #include <com/sun/star/lang/WrappedTargetException.hpp>
48 #include <com/sun/star/beans/PropertyVetoException.hpp>
49 #include <osl/diagnose.h>
50 #include <rtl/logfile.hxx>
52 #define RTL_LOGFILE_OU2A(rtlOUString) (::rtl::OString((rtlOUString).getStr(), (rtlOUString).getLength(), RTL_TEXTENCODING_ASCII_US).getStr())
58 //-----------------------------------------------------------------------------------
59 namespace lang
= css::lang
;
60 namespace util
= css::util
;
62 //-----------------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------------
71 //------------------------------------------------------------------------------------------------------------------
72 rtl::OUString
implGetHierarchicalName( NodeAccess
& rNode
) throw(uno::RuntimeException
)
74 // RTL_LOGFILE_CONTEXT(aLog, "Configmgr::API::implGetHierarchicalName()");
79 GuardedNodeData
<NodeAccess
> lock( rNode
);
81 rtl::Reference
< configuration::Tree
> aTree( lock
.getTree());
83 configuration::AbsolutePath
const aFullPath
= aTree
->getAbsolutePath(lock
.getNode());
84 sRet
= aFullPath
.toString();
86 catch (configuration::Exception
& ex
)
88 ExceptionMapper
e(ex
);
89 e
.setContext( rNode
.getUnoInstance() );
96 //------------------------------------------------------------------------------------------------------------------
97 rtl::OUString
implComposeHierarchicalName(NodeGroupInfoAccess
& rNode
, const rtl::OUString
& sRelativeName
)
98 throw(css::lang::IllegalArgumentException
, lang::NoSupportException
, uno::RuntimeException
)
103 GuardedNodeData
<NodeAccess
> lock( rNode
);
104 configuration::NodeRef
aNode( lock
.getNode() );
105 rtl::Reference
< configuration::Tree
> aTree( lock
.getTree() );
107 configuration::RelativePath
const aAddedPath
= configuration::validateRelativePath(sRelativeName
, aTree
, aNode
);
109 // TODO: add (relative) name validation based on node type - may then need provider lock
110 configuration::AbsolutePath
const aFullPath
= aTree
->getAbsolutePath(aNode
).compose(aAddedPath
);
112 sRet
= aFullPath
.toString();
114 catch (configuration::InvalidName
& ex
)
116 ExceptionMapper
e(ex
);
117 e
.setContext( rNode
.getUnoInstance() );
118 e
.illegalArgument(1);
120 catch (configuration::Exception
& ex
)
122 ExceptionMapper
e(ex
);
123 e
.setContext( rNode
.getUnoInstance() );
131 //------------------------------------------------------------------------------------------------------------------
132 rtl::OUString
implComposeHierarchicalName(NodeSetInfoAccess
& rNode
, const rtl::OUString
& sElementName
)
133 throw(css::lang::IllegalArgumentException
, lang::NoSupportException
, uno::RuntimeException
)
138 GuardedNodeData
<NodeAccess
> lock( rNode
);
139 configuration::NodeRef
aNode( lock
.getNode() );
140 rtl::Reference
< configuration::Tree
> aTree( lock
.getTree() );
142 configuration::Path::Component
const aAddedName
= configuration::validateElementPathComponent(sElementName
, aTree
, aNode
);
144 // TODO: add (relative) name validation based on node type - may then need provider lock
145 configuration::AbsolutePath
const aFullPath
= aTree
->getAbsolutePath(aNode
).compose(aAddedName
);
147 sRet
= aFullPath
.toString();
149 catch (configuration::InvalidName
& ex
)
151 ExceptionMapper
e(ex
);
152 e
.setContext( rNode
.getUnoInstance() );
153 e
.illegalArgument(1);
155 catch (configuration::Exception
& ex
)
157 ExceptionMapper
e(ex
);
158 e
.setContext( rNode
.getUnoInstance() );
166 //------------------------------------------------------------------------------------------------------------------
168 // XElementAccess, base class of XNameAccess (and XHierarchicalNameAccess ? )
169 //-----------------------------------------------------------------------------------
172 //-----------------------------------------------------------------------------------
174 uno::Type
implGetElementType(NodeGroupInfoAccess
& rNode
) throw(uno::RuntimeException
)
177 // group nodes have a mix of types
178 // TODO(?): Discover single common type
179 return ::getCppuType( static_cast< uno::Any
const*>(0) );
183 uno::Type
implGetElementType(NodeSetInfoAccess
& rNode
) throw(uno::RuntimeException
)
188 GuardedNodeData
<NodeSetInfoAccess
> lock( rNode
);
190 aRet
= rNode
.getElementInfo()->getInstanceType();
192 catch (configuration::Exception
& ex
)
194 ExceptionMapper
e(ex
);
195 e
.setContext( rNode
.getUnoInstance() );
201 //-----------------------------------------------------------------------------------
203 sal_Bool
implHasElements(NodeGroupInfoAccess
& rNode
) throw(uno::RuntimeException
)
205 // rNode.checkAlive();
206 // return true; // group nodes always have children
208 // Better: cater for the case where we are reaching the depth limit
211 GuardedNodeData
<NodeAccess
> lock( rNode
); // no provider lock needed
213 rtl::Reference
< configuration::Tree
> aThisTree( lock
.getTree() );
214 configuration::NodeRef
aThisNode( lock
.getNode() );
215 OSL_ASSERT( !aThisTree
->hasElements(aThisNode
) );
216 return aThisTree
->hasChildren(aThisNode
);
218 catch (configuration::Exception
& ex
)
220 ExceptionMapper
e(ex
);
221 e
.setContext( rNode
.getUnoInstance() );
224 // unreachable, but still there to make compiler happy
225 OSL_ASSERT(!"Unreachable code");
230 sal_Bool
implHasElements(NodeSetInfoAccess
& rNode
) throw(uno::RuntimeException
)
234 GuardedNodeData
<NodeAccess
> lock( rNode
); // provider lock needed
236 rtl::Reference
< configuration::Tree
> aThisTree( lock
.getTree() );
237 configuration::NodeRef
aThisNode( lock
.getNode() );
238 OSL_ASSERT( !aThisTree
->hasChildren(aThisNode
) );
239 return aThisTree
->hasElements(aThisNode
);
241 catch (configuration::Exception
& ex
)
243 ExceptionMapper
e(ex
);
244 e
.setContext( rNode
.getUnoInstance() );
247 // unreachable, but still there to make compiler happy
248 OSL_ASSERT(!"Unreachable code");
253 //-----------------------------------------------------------------------------------
256 //------------------------------------------------------------------------------------------------------------------
259 struct SearchExactName
: private configuration::NodeVisitor
262 // warning: order dependency
263 configuration::RelativePath aSearchPath
;
264 std::vector
<configuration::Path::Component
>::reverse_iterator pSearchComponent
;
267 SearchExactName(const configuration::RelativePath
& aLookFor
)
268 : aSearchPath(aLookFor
)
269 , pSearchComponent(aSearchPath
.begin_mutate())
272 bool complete() { return aSearchPath
.end_mutate() == pSearchComponent
; }
274 bool search(configuration::NodeRef
const& aNode
, rtl::Reference
< configuration::Tree
> const& aTree
);
276 configuration::RelativePath
const& getBestMatch() const { return aSearchPath
; }
279 bool findMatch(configuration::NodeRef
& aNode
, rtl::Reference
< configuration::Tree
> & aTree
);
280 virtual Result
handle(rtl::Reference
< configuration::Tree
> const& aTree
, configuration::NodeRef
const&); // NodeVisitor
281 virtual Result
handle(rtl::Reference
< configuration::Tree
> const& aTree
, configuration::ValueRef
const&); // NodeVisitor
283 //..................................................................................................................
284 bool SearchExactName::findMatch(configuration::NodeRef
& aNode
, rtl::Reference
< configuration::Tree
> & aTree
)
286 OSL_ASSERT( !complete() );
288 if ( !aNode
.isValid() ) return false;
291 if (!configuration::hasChildOrElement(aTree
,aNode
,*pSearchComponent
))
293 if (aTree
->dispatchToChildren(aNode
,*this) == CONTINUE
) // not found there
296 OSL_ASSERT(configuration::hasChildOrElement(aTree
,aNode
,*pSearchComponent
));
298 if (! configuration::findInnerChildOrAvailableElement(aTree
,aNode
,pSearchComponent
->getName()) )
299 aNode
= configuration::NodeRef(); // will stop recursion (value or unloaded element found)
304 //..................................................................................................................
306 static configuration::Path::Component
getExtendedNodeName(rtl::Reference
< configuration::Tree
> const& aTree
, configuration::NodeRef
const& aNode
, rtl::OUString
const& aSimpleNodeName
)
308 OSL_PRECOND( !configuration::isEmpty(aTree
.get()), "ERROR: Configuration: Tree operation requires valid tree" );
309 OSL_PRECOND( !aNode
.isValid() || aTree
->isValidNode(aNode
.getOffset()), "ERROR: Configuration: NodeRef does not match tree" );
311 if (aTree
->isRootNode(aNode
))
312 return aTree
->getExtendedRootName();
315 return configuration::Path::wrapSimpleName(aSimpleNodeName
);
317 //..................................................................................................................
318 configuration::NodeVisitor::Result
SearchExactName::handle(rtl::Reference
< configuration::Tree
> const& aTree
, configuration::NodeRef
const& aNode
)
320 OSL_ASSERT( aNode
.isValid() );
321 OSL_ASSERT( !complete() );
323 // find inexact match (the first one, but the order is unspecified)
324 // TODO: Add support for node-type-specific element names
325 rtl::OUString aNodeName
= aTree
->getSimpleNodeName(aNode
.getOffset());
326 rtl::OUString aSearchName
= pSearchComponent
->getName();
327 if (aNodeName
.equalsIgnoreAsciiCase(aSearchName
))
329 *pSearchComponent
= getExtendedNodeName(aTree
,aNode
,aNodeName
);
330 return DONE
; // for this level
335 //..................................................................................................................
336 configuration::NodeVisitor::Result
SearchExactName::handle(rtl::Reference
< configuration::Tree
> const&, configuration::ValueRef
const& aNode
)
338 OSL_ASSERT( aNode
.isValid() );
339 OSL_ASSERT( !complete() );
341 // find inexact match (the first one, but the order is unspecified)
342 // TODO: Add support for node-type-specific element names
343 rtl::OUString aNodeName
= aNode
.m_sNodeName
;
344 OSL_ASSERT( configuration::isSimpleName(aNodeName
) );
346 // value refs are group members and thus have to have simple names
347 if (aNodeName
.equalsIgnoreAsciiCase(pSearchComponent
->getName()))
349 *pSearchComponent
= configuration::Path::wrapSimpleName(aNodeName
);
350 return DONE
; // for this level
355 //..................................................................................................................
356 bool SearchExactName::search(configuration::NodeRef
const & aNode
, rtl::Reference
< configuration::Tree
> const & aTree
)
358 if (!aNode
.isValid()) return false;
360 rtl::Reference
< configuration::Tree
> aSearchTree(aTree
);
361 configuration::NodeRef
aSearchNode(aNode
);
364 if (! findMatch(aSearchNode
, aSearchTree
))
370 } // namespace internal
372 //..................................................................................................................
373 rtl::OUString
implGetExactName(NodeGroupInfoAccess
& rNode
, const rtl::OUString
& rApproximateName
) throw(uno::RuntimeException
)
375 // here we try to support both tree-fragment-local pathes and simple names (the latter ones are just an instance of the first)
378 GuardedNodeData
<NodeAccess
> lock( rNode
);
380 rtl::Reference
< configuration::Tree
> aTree(lock
.getTree());
381 configuration::NodeRef
aNode(lock
.getNode());
383 configuration::RelativePath aApproximatePath
= configuration::validateRelativePath(rApproximateName
,aTree
,aNode
);
385 internal::SearchExactName
aSearch(aApproximatePath
);
387 aSearch
.search(aNode
, aTree
);
389 OSL_ENSURE( aSearch
.getBestMatch().getDepth() == aApproximatePath
.getDepth(),
390 "Search for exact names changed number of path components !?");
392 return aSearch
.getBestMatch().toString();
394 catch (configuration::InvalidName
& )
396 OSL_TRACE("WARNING: Configuration::getExactName: query uses locally invalid Path");
397 return rApproximateName
;
399 catch (configuration::Exception
& ex
)
401 ExceptionMapper
e(ex
);
402 e
.setContext( rNode
.getUnoInstance() );
405 // unreachable, but still there to make compiler happy
406 OSL_ASSERT(!"Unreachable code");
407 return rApproximateName
;
410 //..................................................................................................................
411 rtl::OUString
implGetExactName(NodeSetInfoAccess
& rNode
, const rtl::OUString
& rApproximateName
) throw(uno::RuntimeException
)
414 // here we can support only local names
417 GuardedNodeData
<NodeAccess
> lock( rNode
);
419 rtl::Reference
< configuration::Tree
> aTree(lock
.getTree());
420 configuration::NodeRef
aNode(lock
.getNode());
422 configuration::Path::Component aApproximateName
= configuration::validateElementPathComponent(rApproximateName
,aTree
,aNode
);
424 internal::SearchExactName
aSearch(aApproximateName
);
426 aSearch
.search(aNode
, aTree
);
428 OSL_ENSURE( aSearch
.getBestMatch().getDepth() == 1,
429 "Search for exact names changed number of path components !?");
431 return aSearch
.getBestMatch().getLocalName().getName();
433 catch (configuration::InvalidName
& )
435 OSL_TRACE("WARNING: Configuration::getExactName: query uses locally invalid Path");
436 return rApproximateName
;
438 catch (configuration::Exception
& ex
)
440 ExceptionMapper
e(ex
);
441 e
.setContext( rNode
.getUnoInstance() );
444 // unreachable, but still there to make compiler happy
445 OSL_ASSERT(!"Unreachable code");
446 return rApproximateName
;
450 //-----------------------------------------------------------------------------------
452 //-----------------------------------------------------------------------------------
453 beans::Property
implGetAsProperty(NodeAccess
& rNode
)
454 throw(uno::RuntimeException
)
458 GuardedNodeData
<NodeAccess
> lock( rNode
);
460 rtl::Reference
< configuration::Tree
> aTree( lock
.getTree());
461 configuration::NodeRef
aNode( lock
.getNode());
463 rtl::OUString aName
= aTree
->getSimpleNodeName(aNode
.getOffset());
464 node::Attributes aAttributes
= aTree
->getAttributes(aNode
);
465 uno::Type aApiType
= getUnoInterfaceType();
467 return helperMakeProperty( aName
,aAttributes
,aApiType
, aTree
->hasNodeDefault(aNode
) );
469 catch (configuration::Exception
& ex
)
471 ExceptionMapper
e(ex
);
472 e
.setContext( rNode
.getUnoInstance() );
476 // unreachable, but still there to make some compilers happy
477 OSL_ASSERT(!"Unreachable code");
478 return beans::Property();
481 //-----------------------------------------------------------------------------------
483 //-----------------------------------------------------------------------------------
484 uno::Sequence
< css::beans::Property
> implGetProperties( NodeAccess
& rNode
) throw (uno::RuntimeException
)
486 CollectPropertyInfo aCollect
;
490 GuardedNodeData
<NodeAccess
> lock( rNode
);
492 lock
.getTree()->dispatchToChildren(lock
.getNode(), aCollect
);
494 catch (configuration::Exception
& ex
)
496 ExceptionMapper
e(ex
);
497 e
.setContext( rNode
.getUnoInstance() );
501 return makeSequence( aCollect
.list() );
504 //-----------------------------------------------------------------------------------
505 css::beans::Property
implGetPropertyByName( NodeAccess
& rNode
, const rtl::OUString
& aName
)
506 throw (css::beans::UnknownPropertyException
, uno::RuntimeException
)
510 GuardedNodeData
<NodeAccess
> lock( rNode
);
512 rtl::Reference
< configuration::Tree
> aTree( lock
.getTree() );
513 configuration::NodeRef
const aNode( lock
.getNode() );
515 rtl::OUString aChildName
= configuration::validateChildOrElementName(aName
,aTree
,aNode
);
517 configuration::AnyNodeRef aChildNode
= configuration::getChildOrElement(aTree
,aNode
, aChildName
);
519 if (!aChildNode
.isValid())
521 OSL_ENSURE(!configuration::hasChildOrElement(aTree
,aNode
,aChildName
),"ERROR: Configuration: Existing Property not found by implementation");
523 rtl::OUString
sMessage( RTL_CONSTASCII_USTRINGPARAM("Configuration - Cannot get Property. Property '") );
525 sMessage
+= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("' could not be found in ") );
526 sMessage
+= aTree
->getAbsolutePath(aNode
).toString();
528 uno::Reference
<uno::XInterface
> xContext( rNode
.getUnoInstance() );
529 throw css::beans::UnknownPropertyException( sMessage
, xContext
);
532 node::Attributes aChildAttributes
= aTree
->getAttributes(aChildNode
);
533 uno::Type aApiType
= aChildNode
.isNode() ? getUnoInterfaceType() : aTree
->getUnoType(aChildNode
.toValue());
535 return helperMakeProperty( aChildName
,aChildAttributes
,aApiType
, aTree
->hasNodeDefault(aChildNode
) );
537 catch (configuration::InvalidName
& ex
)
539 ExceptionMapper
e(ex
);
540 uno::Reference
<uno::XInterface
> xContext( rNode
.getUnoInstance() );
541 throw css::beans::UnknownPropertyException( e
.message(), xContext
);
543 catch (configuration::Exception
& ex
)
545 ExceptionMapper
e(ex
);
546 e
.setContext( rNode
.getUnoInstance() );
550 // unreachable, but still there to make some compilers happy
551 OSL_ASSERT(!"Unreachable code");
552 return css::beans::Property();
556 //-----------------------------------------------------------------------------------
557 sal_Bool
implHasPropertyByName( NodeAccess
& rNode
, const rtl::OUString
& name
) throw (uno::RuntimeException
)
559 return implHasByName(rNode
, name
);
563 //-----------------------------------------------------------------------------------
565 //-----------------------------------------------------------------------------------
566 // TODO: optimization - cache the node found (for subsequent getByName)
567 // TODO: optimization - less locking for group nodes
568 //-----------------------------------------------------------------------------------
569 sal_Bool
implHasByName(NodeAccess
& rNode
, const rtl::OUString
& sName
) throw(uno::RuntimeException
)
573 GuardedNodeData
<NodeAccess
> lock( rNode
);
575 rtl::OUString
aChildName(sName
);
577 return configuration::hasChildOrElement(lock
.getTree(), lock
.getNode(), aChildName
);
579 #if OSL_DEBUG_LEVEL > 0
580 catch (configuration::InvalidName
& ex
)
582 ExceptionMapper
e(ex
);
583 OSL_ENSURE(false,"configmgr: BasicAccess::hasByName: Unexpected exception <InvalidName>");
584 e
.setContext( rNode
.getUnoInstance() );
588 catch (configuration::Exception
& ex
)
590 ExceptionMapper
e(ex
);
591 e
.setContext( rNode
.getUnoInstance() );
594 // unreachable, but still there to make compiler happy
595 OSL_ASSERT(!"Unreachable code");
599 //-----------------------------------------------------------------------------------
600 uno::Any
implGetByName(NodeAccess
& rNode
, const rtl::OUString
& sName
)
601 throw(css::container::NoSuchElementException
, css::lang::WrappedTargetException
, uno::RuntimeException
)
605 GuardedNodeData
<NodeAccess
> lock( rNode
);
607 rtl::Reference
< configuration::Tree
> aTree( lock
.getTree() );
608 configuration::NodeRef
aNode( lock
.getNode() );
610 rtl::OUString aChildName
= configuration::validateChildOrElementName(sName
,aTree
,aNode
);
612 configuration::AnyNodeRef aChildNode
= configuration::getChildOrElement(aTree
,aNode
, aChildName
);
613 if (!aChildNode
.isValid())
615 rtl::OUString
sMessage( RTL_CONSTASCII_USTRINGPARAM("Configuration - Child Element '") );
617 sMessage
+= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("' not found in ") );
618 sMessage
+= aTree
->getAbsolutePath(aNode
).toString();
620 uno::Reference
<uno::XInterface
> xContext( rNode
.getUnoInstance() );
621 throw com::sun::star::container::NoSuchElementException( sMessage
, xContext
);
623 OSL_ASSERT(aNode
.isValid());
625 return configapi::makeElement( rNode
.getFactory(), aTree
, aChildNode
);
627 catch (configuration::InvalidName
& ex
)
629 ExceptionMapper
e(ex
);
630 uno::Reference
<uno::XInterface
> xContext( rNode
.getUnoInstance() );
631 throw com::sun::star::container::NoSuchElementException( e
.message(), xContext
);
633 catch (configuration::Exception
& ex
)
635 ExceptionMapper
e(ex
);
636 e
.setContext( rNode
.getUnoInstance() );
640 // unreachable, but still there to make some compilers happy
641 OSL_ASSERT(!"Unreachable code");
645 //-----------------------------------------------------------------------------------
646 // TODO: optimization - less locking for group nodes
647 //-----------------------------------------------------------------------------------
648 uno::Sequence
< rtl::OUString
> implGetElementNames( NodeAccess
& rNode
) throw( uno::RuntimeException
)
650 CollectNodeNames aCollect
;
654 GuardedNodeData
<NodeAccess
> lock( rNode
);
656 lock
.getTree()->dispatchToChildren(lock
.getNode(), aCollect
);
658 catch (configuration::Exception
& ex
)
660 ExceptionMapper
e(ex
);
661 e
.setContext( rNode
.getUnoInstance() );
665 return makeSequence( aCollect
.list() );
668 // XHierarchicalNameAccess
669 //-----------------------------------------------------------------------------------
671 //-----------------------------------------------------------------------------------
672 // TO DO: optimization - cache the node found for subsequent getByHierarchicalName()
673 //-----------------------------------------------------------------------------------
674 sal_Bool
implHasByHierarchicalName(NodeAccess
& rNode
, const rtl::OUString
& sHierarchicalName
) throw(uno::RuntimeException
)
678 GuardedNodeData
<NodeAccess
> lock( rNode
);
680 rtl::Reference
< configuration::Tree
> aTree( lock
.getTree() );
681 configuration::NodeRef
aNode( lock
.getNode() );
683 configuration::RelativePath aRelPath
= configuration::validateAndReducePath( sHierarchicalName
, aTree
, aNode
);
685 return configuration::getDeepDescendant(aTree
, aNode
, aRelPath
).isValid();
687 catch (configuration::InvalidName
& )
689 OSL_TRACE("WARNING: Configuration::hasByHierarchicalName: query uses locally invalid Path");
692 catch (configuration::Exception
& ex
)
694 ExceptionMapper
e(ex
);
695 e
.setContext( rNode
.getUnoInstance() );
698 // unreachable, but still there to make some compilers happy
699 OSL_ASSERT(!"Unreachable code");
703 //-----------------------------------------------------------------------------------
704 uno::Any
implGetByHierarchicalName(NodeAccess
& rNode
, const rtl::OUString
& sHierarchicalName
)
705 throw(css::container::NoSuchElementException
, uno::RuntimeException
)
707 // rtl::OUString aTmpStr(implGetHierarchicalName(rNode));
708 // RTL_LOGFILE_CONTEXT_TRACE2(aLog, "Node: %s HierachicalName: %s",RTL_LOGFILE_OU2A(aTmpStr), RTL_LOGFILE_OU2A(sHierarchicalName));
712 GuardedNodeData
<NodeAccess
> lock( rNode
);
714 rtl::Reference
< configuration::Tree
> aTree( lock
.getTree() );
715 configuration::NodeRef
aNode( lock
.getNode() );
717 configuration::RelativePath aRelPath
= configuration::validateAndReducePath( sHierarchicalName
, aTree
, aNode
);
719 configuration::AnyNodeRef aNestedNode
= configuration::getDeepDescendant( aTree
, aNode
, aRelPath
);
720 if (!aNestedNode
.isValid())
722 rtl::OUString
sMessage( RTL_CONSTASCII_USTRINGPARAM("Configuration - Descendant Element '") );
723 sMessage
+= aRelPath
.toString();
724 sMessage
+= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("' not found in Node ") );
725 sMessage
+= aTree
->getAbsolutePath(aNode
).toString();
727 uno::Reference
<uno::XInterface
> xContext( rNode
.getUnoInstance() );
728 throw com::sun::star::container::NoSuchElementException( sMessage
, xContext
);
731 OSL_ASSERT(aNode
.isValid());
732 return configapi::makeElement( rNode
.getFactory(), aTree
, aNestedNode
);
734 catch (configuration::InvalidName
& ex
)
736 ExceptionMapper
e(ex
);
737 uno::Reference
<uno::XInterface
> xContext( rNode
.getUnoInstance() );
738 throw com::sun::star::container::NoSuchElementException( e
.message(), xContext
);
740 catch (configuration::Exception
& ex
)
742 ExceptionMapper
e(ex
);
743 e
.setContext( rNode
.getUnoInstance() );
747 // unreachable, but still there to make some compilers happy
748 OSL_ASSERT(!"Unreachable code");
752 // XPropertyWithState
753 //---------------------------------------------------------------------
754 css::beans::PropertyState
implGetStateAsProperty(NodeAccess
& rNode
)
755 throw (uno::RuntimeException
)
757 css::beans::PropertyState aRet
= css::beans::PropertyState_AMBIGUOUS_VALUE
;
760 GuardedNodeData
<NodeAccess
> lock( rNode
);
762 if ( lock
.getTree()->isNodeDefault( lock
.getNode() ) )
763 aRet
= css::beans::PropertyState_DEFAULT_VALUE
;
765 catch (configuration::Exception
& ex
)
767 ExceptionMapper
e(ex
);
768 e
.setContext( rNode
.getUnoInstance() );
774 uno::Reference
< uno::XInterface
> implGetDefaultAsProperty(NodeAccess
& )
775 throw (css::lang::WrappedTargetException
, uno::RuntimeException
)
777 // not really supported
779 /* possible, but nor really useful:
780 GuardedNodeAccess lock( rNode );
781 if (implGetStateAsProperty(rNode) == PropertyState_DEFAULT_VALUE)
782 return rNode.getUnoInstance();
785 return uno::Reference
< uno::XInterface
>();
789 // set-specific Interfaces
790 //-----------------------------------------------------------------------------------
793 // XTemplateContainer
794 //-----------------------------------------------------------------------------------
795 rtl::OUString SAL_CALL
implGetElementTemplateName(NodeSetInfoAccess
& rNode
)
796 throw(uno::RuntimeException
)
798 GuardedNodeData
<NodeSetInfoAccess
> lock(rNode
);
799 return rNode
.getElementInfo()->getPathString();
802 //-----------------------------------------------------------------------------------
803 } // namespace configapi
805 } // namespace configmgr