pressrv_plat/xdm_api/inc/XdmDocumentNode.h
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   XDM document node
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __XDMDOCUMENTNODE__
       
    22 #define __XDMDOCUMENTNODE__
       
    23 
       
    24 #include <e32base.h>
       
    25 #include "XdmNodeInterface.h"
       
    26 
       
    27 enum TXdmElementType
       
    28     {
       
    29     EXdmElementNode = 0,
       
    30     EXdmElementAttribute,
       
    31     EXdmElementUnspecified
       
    32     };
       
    33 
       
    34 class CXdmEngine;
       
    35 struct SXdmAttribute8;
       
    36 struct SXdmAttribute16;
       
    37 class MXdmNodeFactory;
       
    38 class CXdmNodeAttribute;
       
    39 class CXdmOperationFactory;
       
    40 
       
    41 //CLASS DECLARATION
       
    42 class CXdmDocumentNode : public CBase, public MXdmNodeInterface
       
    43     {
       
    44     public:  // Constructors and destructor
       
    45         
       
    46         /**
       
    47         * Create a new child element
       
    48         *
       
    49 		* @return CXdmDocumentNode* 
       
    50         */
       
    51         IMPORT_C CXdmDocumentNode* CreateChileNodeL();
       
    52         
       
    53         /**
       
    54         * Create a new child element
       
    55         *
       
    56         * @param TDesC8& Name of the new element
       
    57 		* @return CXdmDocumentNode* 
       
    58         */
       
    59         IMPORT_C CXdmDocumentNode* CreateChileNodeL( const TDesC& aChildName );
       
    60 
       
    61         /**
       
    62         * Create a new attribute
       
    63         *
       
    64         * @param TDesC8& Name of the new attribute
       
    65 		* @return CXdmNodeAttribute* 
       
    66         */
       
    67         IMPORT_C CXdmNodeAttribute* CreateAttributeL();
       
    68         
       
    69         /**
       
    70         * Create a new attribute
       
    71         *
       
    72         * @param TDesC8& Name of the new attribute
       
    73 		* @return CXdmNodeAttribute* 
       
    74         */
       
    75         IMPORT_C CXdmNodeAttribute* CreateAttributeL( const TDesC& aAttributeName );
       
    76 
       
    77         /**
       
    78         * Set the contents of a leaf node. Fails if this element
       
    79         * is not a leaf element.
       
    80         *
       
    81         * <leaf>leafnodecontent</leaf>
       
    82         *
       
    83         *
       
    84         * @param TDesC8& Content of the leaf element
       
    85 		* @return void 
       
    86         */
       
    87         IMPORT_C void SetLeafNodeContentL( const TDesC& aLeafContent );
       
    88         
       
    89         /**
       
    90         * Set the contents of a leaf node. Fails if this element
       
    91         * is not a leaf element.
       
    92         *
       
    93         * <leaf>leafnodecontent</leaf>
       
    94         *
       
    95         *
       
    96         * @param TDesC8& Content of the leaf element
       
    97 		* @return void 
       
    98         */
       
    99         IMPORT_C void SetLeafNodeContentL( const TDesC8& aLeafContent );
       
   100         
       
   101         /**
       
   102         * Define this node to be a leaf node. Default value is EFalse,
       
   103         * so this method only needs to be called when the client wants to
       
   104         * define a node a leaf node. The operation can, of course, be
       
   105         * reverted if needed.
       
   106         *
       
   107         * @param TBool Define/undefine this node to be a leaf node
       
   108 		* @return void 
       
   109         */
       
   110         IMPORT_C void SetLeafNode( TBool aIsLeafNode );
       
   111         
       
   112         /**
       
   113         * Define this node to be empty. Default value is EFalse,
       
   114         * so this method only needs to be called when the client wants
       
   115         * to indicate that a node does not/will not have children.
       
   116         * The operation can be reverted if needed.
       
   117         *
       
   118         * NOTE: An attempt to create children on an empty node will
       
   119         *       result in a panic being raised. Respectively, if a
       
   120         *       client application wants to revert the state of a 
       
   121         *       node from non-empty to empty, all children that may
       
   122         *       have been created will be removed.
       
   123         *
       
   124         * @param TBool Define/undefine this node to be empty
       
   125 		* @return void 
       
   126         */
       
   127         IMPORT_C void SetEmptyNode( TBool aIsEmptyNode );
       
   128         
       
   129         /**
       
   130         * Report whether or not this is a leaf element
       
   131 		* @return TBool Is this a leaf element
       
   132         */
       
   133         IMPORT_C TBool IsLeafNode() const;
       
   134         
       
   135         /**
       
   136         * Report whether or not this element is empty
       
   137 		* @return TBool Is this an empty element
       
   138         */
       
   139         IMPORT_C TBool IsEmptyNode() const;
       
   140         
       
   141         /**
       
   142         * Return the contents of a leaf element
       
   143 		* @return TPtrC8 Contents of the leaf element
       
   144         */
       
   145         IMPORT_C TPtrC8 LeafNodeContent() const;
       
   146         
       
   147         /**
       
   148         * Return the contents of a leaf element escape-coded, if needed
       
   149 		* @return TPtrC8 Contents of the leaf element
       
   150         */
       
   151         IMPORT_C HBufC8* EscapeLeafNodeContentLC() const;
       
   152 
       
   153         /**
       
   154         * Returns the contents of a single element without any brackets
       
   155         * and pushes the buffer onto the CleanupStack.
       
   156         *
       
   157         * For instance:
       
   158         *
       
   159         * 'element attribute1 = "value" attribute2 = "another value"'
       
   160         *
       
   161 		* @return HBufC8* 
       
   162         */
       
   163         IMPORT_C HBufC8* ElementDataLC() const;
       
   164         
       
   165         /**
       
   166         * Return the parent node of this element
       
   167         *
       
   168 		* @return CXdmDocumentNode* 
       
   169         */
       
   170         IMPORT_C CXdmDocumentNode* Parent() const;
       
   171         
       
   172         /**
       
   173         * Name of this element
       
   174 		* @return TPtrC8 Name of this element
       
   175         */
       
   176         IMPORT_C TPtrC NodeName() const;
       
   177 
       
   178         /**
       
   179         * Name of this element
       
   180 		* @return TPtrC8 Name of this element
       
   181         */
       
   182         IMPORT_C HBufC8* EightBitNodeNameLC() const;
       
   183         
       
   184         /**
       
   185         * (Re-)Set the name of this element
       
   186 		* @param TDesC& Name of this element
       
   187         * @return void
       
   188         */
       
   189         IMPORT_C void SetNameL( const TDesC& aNodeName );
       
   190         
       
   191         /**
       
   192         * (Re-)Set the name of this element
       
   193 		* @param TDesC& Name of this element
       
   194         * @return void
       
   195         */
       
   196         IMPORT_C void SetNameL( const TDesC8& aNodeName );
       
   197         
       
   198         /**
       
   199         * Returns the number of child & lealf elements
       
   200         *
       
   201         * @return TInt Number of descendants
       
   202         */
       
   203         IMPORT_C TInt NodeCount() const;
       
   204 
       
   205         /**
       
   206         * Returns the number of attributes of this element
       
   207         *
       
   208 		* @return TInt The number of attributes 
       
   209         */
       
   210         IMPORT_C TInt AttributeCount() const;
       
   211 
       
   212         /**
       
   213         * Returns a child node specified by its position among the
       
   214         * descendants of an element
       
   215         *
       
   216 		* @return CXdmDocument* 
       
   217         */
       
   218         IMPORT_C CXdmDocumentNode* ChileNode( TInt aPosition ) const;
       
   219 
       
   220         /**
       
   221         * Reference an attribute of this element specified by the position
       
   222         * of the attribute
       
   223         *
       
   224 		* @return CXdmDocument* 
       
   225         */
       
   226         IMPORT_C CXdmNodeAttribute* Attribute( TInt aPosition ) const;
       
   227         
       
   228         /**
       
   229         * Reference an attribute of this element specified by the position
       
   230         * of the attribute
       
   231         *
       
   232 		* @return CXdmDocument* 
       
   233         */
       
   234         IMPORT_C CXdmNodeAttribute* Attribute( const TDesC& aAttributeName ) const;
       
   235         
       
   236         /**
       
   237         * Search for nodes which match the specified name
       
   238         *
       
   239         * @param TDesC& The element name to search for
       
   240         * @param RPointerArray<CXdmDocumentNode> Results, if any
       
   241 		* @return TInt Error
       
   242         */
       
   243         IMPORT_C TInt Find( const TDesC& aNodeName,
       
   244                             RPointerArray<CXdmDocumentNode>& aResultArray ) const;
       
   245                    
       
   246         /**
       
   247         * Search for nodes which match the specified node
       
   248         *
       
   249         * @param CXdmDocumentNode& The node to compare to
       
   250 		* @return TInt KErrNotFound if no matching nodes are found
       
   251         */
       
   252         IMPORT_C TInt Find( const CXdmDocumentNode& aTargetNode,
       
   253                             RPointerArray<CXdmDocumentNode>& aResultArray ) const;
       
   254                    
       
   255         /**
       
   256         * Search for nodes which match the specified name & attributes
       
   257         *
       
   258         * @param TDesC& The element name to search for
       
   259         * @param RPointerArray<CXdmDocumentNode>& Results
       
   260         * @param RPointerArray<SXdmAttribute16>& Attributes to search for
       
   261 		* @return TInt KErrNotFound if no matching nodes are found
       
   262         */
       
   263         IMPORT_C TInt Find( const TDesC& aNodeName,
       
   264                             RPointerArray<CXdmDocumentNode>& aResultArray,
       
   265                             const RPointerArray<SXdmAttribute16>& aAttributeArray ) const;
       
   266 
       
   267 
       
   268         /**
       
   269         * The type of this element: an element or an attribute
       
   270 		* @return TXdmElementType* 
       
   271         */
       
   272         IMPORT_C TBool Match( const CXdmDocumentNode& aAnotherNode ) const;
       
   273                               
       
   274         /**
       
   275         * The type of this element: an element or an attribute
       
   276 		* @return TXdmElementType* 
       
   277         */
       
   278         IMPORT_C TBool Match( const TDesC& aNodeName,
       
   279                               const RPointerArray<SXdmAttribute8>& aAttributeArray ) const;
       
   280         
       
   281         /**
       
   282         * Comparison operator
       
   283         *
       
   284 		* @return TBool Are the contents of this object identical to
       
   285 		*               the ones in the parameter
       
   286         */
       
   287         IMPORT_C TBool operator==( const CXdmDocumentNode& aNode ) const;
       
   288         
       
   289         /**
       
   290         * The type of this element: an element or an attribute
       
   291 		* @return TXdmElementType* 
       
   292         */                    
       
   293         IMPORT_C TBool HasAttribute( const TDesC& aAttributeName ) const;
       
   294                               
       
   295         /**
       
   296         * The type of this element: an element or an attribute
       
   297 		* @return TXdmElementType* 
       
   298         */
       
   299         IMPORT_C virtual TXdmElementType ElementType() const;
       
   300         
       
   301         /**
       
   302         * Remove a child node
       
   303         * @param CXdmDocumentNode The element to be removed
       
   304 		* @return void 
       
   305         */
       
   306         IMPORT_C void RemoveChileNodeL( CXdmDocumentNode* aChileNode );
       
   307         
       
   308         /**
       
   309         * Append a child node
       
   310         * @param CXdmDocumentNode The element to be appended
       
   311 		* @return void 
       
   312         */
       
   313         IMPORT_C void AppendChileNodeL( CXdmDocumentNode* aChileNode );
       
   314         
       
   315         /**
       
   316         * Insert a child node to the given position
       
   317         * @param TInt The position of the new element
       
   318         * @param CXdmDocumentNode The element to be inserted
       
   319 		* @return void 
       
   320         */
       
   321         IMPORT_C void InsertChileNodeL( TInt aIndex, CXdmDocumentNode* aChileNode );
       
   322         
       
   323         /**
       
   324         * Replace a child node
       
   325         * @param CXdmDocumentNode The new node
       
   326         * @param CXdmDocumentNode The node to be replaced
       
   327 		* @return void 
       
   328         */
       
   329         IMPORT_C void ReplaceChileNodeL( CXdmDocumentNode* aNewNode,
       
   330                                          CXdmDocumentNode* aTargetNode );
       
   331                                             
       
   332         /**
       
   333         * Destructor.
       
   334         */
       
   335         IMPORT_C ~CXdmDocumentNode();
       
   336     
       
   337     public:
       
   338     
       
   339         /**
       
   340         * Print the contents of this node to the log file
       
   341         *
       
   342 		* @return void 
       
   343         */
       
   344         IMPORT_C void Print();
       
   345         
       
   346         /**
       
   347         * Return the next node in the list
       
   348 		* @return CXdmDocumentNode* 
       
   349         */
       
   350         IMPORT_C CXdmDocumentNode* NextNode() const;
       
   351         
       
   352         /**
       
   353         * Set the next node in the list
       
   354         * @param The next node in the list
       
   355 		* @return void 
       
   356         */
       
   357         IMPORT_C void SetNextNode( CXdmDocumentNode* aNextNode );
       
   358     
       
   359     public:
       
   360         
       
   361         /**
       
   362         * Check whether an element has the specified attribute
       
   363         *
       
   364         * @param CXdmNodeAttribute& The specified attribute
       
   365 		* @return TBool Does the element have the specified attribute
       
   366         */
       
   367         TBool HasAttribute( const CXdmNodeAttribute& aNode ) const;
       
   368         
       
   369         /**
       
   370         * Check whether an element has the specified attribute
       
   371         *
       
   372         * @param SXdmAttribute8& The specified attribute
       
   373 		* @return TBool Does the element have the specified attribute
       
   374         */
       
   375         TBool HasAttributeL( const SXdmAttribute8& aAttribute ) const;
       
   376         
       
   377         /**
       
   378         * Check whether an element has the specified attribute
       
   379         *
       
   380         * @param SXdmAttribute16& The specified attribute
       
   381 		* @return TBool Does the element have the specified attribute
       
   382         */
       
   383         TBool HasAttribute( const SXdmAttribute16& aAttribute ) const;
       
   384         
       
   385     protected: // New functions
       
   386         
       
   387         /**
       
   388         * Escape-code the specified string
       
   389         *
       
   390         * @param TDesC8& The descriptor to escape-code
       
   391 		* @return HBufC8* Escape-coded string
       
   392         */
       
   393         HBufC8* EscapeDescLC( const TDesC8& aDescriptor ) const;
       
   394 
       
   395     protected:
       
   396 		                           
       
   397         /**
       
   398         * C++ constructor, for derived classes
       
   399         *
       
   400         * @param CXdmEngine* Reference to the engine
       
   401         * @param MXdmNodeFactory* Reference to the node factory
       
   402         * @param CXdmDocumentNode* The parent node of this element
       
   403         */
       
   404 		IMPORT_C CXdmDocumentNode( CXdmEngine& aXdmEngine,
       
   405 		                           MXdmNodeFactory& aNodeFactory,
       
   406 		                           CXdmDocumentNode* aParentNode );
       
   407 		
       
   408 		/**
       
   409         * CC++ constructor, for derived classes
       
   410         *
       
   411         * @param CXdmEngine* Reference to the engine
       
   412         * @param MXdmNodeFactory* Reference to the node factory
       
   413         */
       
   414         IMPORT_C CXdmDocumentNode( CXdmEngine& aXdmEngine,
       
   415                                    MXdmNodeFactory& aNodeFactory );
       
   416 
       
   417         /**
       
   418         * C++ constructor, for derived classes
       
   419         *
       
   420         * @param CXdmEngine* Is this a leaf element
       
   421         * @param CXdmEngine* Reference to the engine
       
   422         * @param MXdmNodeFactory* Reference to the node factory
       
   423         * @param CXdmDocumentNode* The parent node of this element
       
   424         */
       
   425 		IMPORT_C CXdmDocumentNode( const TBool aLeafNode,
       
   426 		                           CXdmEngine& aXdmEngine,
       
   427 		                           MXdmNodeFactory& aNodeFactory,
       
   428                                    CXdmDocumentNode* aParentNode );
       
   429        
       
   430         /**
       
   431         * Symbian OS constructor for derived classes.
       
   432         *
       
   433         * @param TDesC8& Name of this element
       
   434         * @return void
       
   435         */
       
   436 		IMPORT_C void BaseConstructL( const TDesC& aNodeName );
       
   437 		
       
   438 		/**
       
   439         * Copy constructor
       
   440         *
       
   441         * @param CXdmDocumentNode& The element to copy
       
   442         * @param CXdmDocumentNode& The parent of this element
       
   443         * @return void
       
   444         */
       
   445 		IMPORT_C virtual void CopyConstructL( const CXdmDocumentNode& aAnotherNode,
       
   446 		                                      const CXdmDocumentNode& aParentNode );
       
   447     
       
   448     private:
       
   449         
       
   450         /**
       
   451         * Search for nodes which match the specified name
       
   452         *
       
   453         * @param TDesC& The element name to search for
       
   454         * @param RPointerArray<CXdmDocumentNode> Results, if any
       
   455 		* @return TInt KErrNotFound if no matches were found,
       
   456 		*         number of matching elements otherwise
       
   457         */
       
   458         TInt DoFind( const TDesC& aNodeName,
       
   459                      RPointerArray<CXdmDocumentNode>& aResultArray ) const;
       
   460         
       
   461         /**
       
   462         * Search for nodes which match the specified node
       
   463         *
       
   464         * @param CXdmDocumentNode& The node to compare to
       
   465 		* @return TInt KErrNotFound if no matching nodes are found
       
   466         */             
       
   467         TInt DoFind( const CXdmDocumentNode& aTargetNode,
       
   468                      RPointerArray<CXdmDocumentNode>& aResultArray ) const;
       
   469         
       
   470         /**
       
   471         * Search for nodes which match the specified name & attributes
       
   472         *
       
   473         * @param TDesC& The element name to search for
       
   474         * @param RPointerArray<CXdmDocumentNode>& Results
       
   475         * @param RPointerArray<SXdmAttribute16>& Attributes to search for
       
   476 		* @return TInt KErrNotFound if no matching nodes are found
       
   477         */              
       
   478         TInt DoFind( const TDesC& aNodeName,
       
   479                      RPointerArray<CXdmDocumentNode>& aResultArray,
       
   480                      const RPointerArray<SXdmAttribute16>& aAttributeArray );
       
   481                             
       
   482         /**
       
   483         * Copy the child nodes of another element.
       
   484         *
       
   485         * @param CXdmDocumentNode& The element the children of which should be copied
       
   486         * @return void
       
   487         */
       
   488         void ConstructChildrenL( const CXdmDocumentNode& aAnotherNode );
       
   489         
       
   490         /**
       
   491         * Copy the attributes of another element.
       
   492         *
       
   493         * @param CXdmDocumentNode& The element the attributes of which should be copied
       
   494         * @return void
       
   495         */
       
   496         void ConstructAttributesL( const CXdmDocumentNode& aAnotherNode );
       
   497         
       
   498         /**
       
   499         * Remove namespace attributes from this element. Namespaces must 
       
   500         * not be used when comparing two elements, which is why these 
       
   501         * attributes need to be removed before the comparison.
       
   502         *
       
   503         * @return void
       
   504         */
       
   505         void RemoveNamespaceAttributes();
       
   506     
       
   507     protected:
       
   508         
       
   509         TInt                                        iPosition;
       
   510         TBool                                       iLeafNode;
       
   511         TBool                                       iEmptyNode;
       
   512         HBufC*                                      iNodeName;
       
   513         HBufC8*                                     iLeafContent;
       
   514         CXdmEngine&                                 iXdmEngine;
       
   515         MXdmNodeFactory&                            iNodeFactory;
       
   516         friend class                                CXdmDocument;
       
   517         CXdmDocumentNode*                           iNextNode;
       
   518         CXdmDocumentNode*                           iParentNode;
       
   519         RPointerArray<CXdmDocumentNode>             iChildren;
       
   520         RPointerArray<CXdmNodeAttribute>            iAttributes;  
       
   521     };
       
   522 
       
   523 #endif      //__XDMDOCUMENTNODE__
       
   524             
       
   525 // End of File