KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xpath > schema > SchemaNode


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.xpath.schema;
24
25 import org.xquark.schema.AttributeDeclaration;
26 import org.xquark.schema.Declaration;
27 import org.xquark.schema.ElementDeclaration;
28 import org.xquark.xpath.NodeKind;
29 import org.xquark.xpath.TypedXTreeNode;
30 import org.xquark.xpath.XTree;
31
32 /**
33  * Implementation of XTreeNode for XML schema access through XPath indexing.
34  */

35 public class SchemaNode extends TypedXTreeNode
36 {
37     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
38     private static final String JavaDoc RCSName = "$Name: $";
39     
40     Declaration declaration;
41
42     /**
43      * Constructor for element and attributes nodes using names.
44      * Calls its ancestor constructor for registrations. Retrieves and sets
45      * the node declaration from the parent's one.
46      * @param tree the owner tree
47      * @param parent the parent node
48      * @param namespace the namespace URI of the new node
49      * @param localName the local name of the new node
50      * @param the type of the new node
51      */

52     public SchemaNode(
53         XTree tree,
54         SchemaNode parent,
55         String JavaDoc namespace,
56         String JavaDoc localName,
57         byte type)
58     {
59         super(tree, parent, namespace, localName, type);
60         if ((type != NodeKind.NONE)
61             && (parent != null)
62             && (parent.getDeclaration() != null))
63         {
64             org.xquark.schema.Type parentType =
65                 parent.getDeclaration().getType();
66             switch (type)
67             {
68                 case NodeKind.ATTRIBUTE :
69                     declaration =
70                         parentType.getAttributeDeclaration(
71                             namespace,
72                             localName);
73                     break;
74                 case NodeKind.ELEMENT :
75                     declaration =
76                         parentType.getElementDeclaration(namespace, localName);
77                     break;
78             }
79         }
80     }
81
82     /**
83      * Constructor for element and attributes nodes using declaration.
84      * Calls its ancestor constructor for registrations. Sets name and type
85      * from the declaration passed as a parameter.
86      * @param tree the owner tree
87      * @param parent the parent node
88      * @param decl the node declaration defining the new node
89      */

90     public SchemaNode(XTree tree, SchemaNode parent, Declaration decl)
91     {
92         super(tree, parent, decl.getNamespace(), decl.getName(), NodeKind.NODE);
93         if (decl instanceof AttributeDeclaration)
94             XModelNode.set(NodeKind.ATTRIBUTE);
95         else if (decl instanceof ElementDeclaration)
96             XModelNode.set(NodeKind.ELEMENT);
97         declaration = decl;
98     }
99
100     /**
101      * Accessor to the node XML schema declaration.
102      * @return null if not available
103      */

104     public Declaration getDeclaration()
105     {
106         return declaration;
107     }
108
109     /**
110      * Builds a String representation of the node.
111      * @returna String representation of the node.
112      */

113     public String JavaDoc toString()
114     {
115         return super.toString() + "[Decl = " + declaration + "]";
116     }
117 }
118
Popular Tags