KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > metadata > NamedNode


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.extractor.metadata;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 /**
30  * Base type for Extractor metadata.
31  */

32 // QUESTION : Why is XTreeNode not used ?
33
public abstract class NamedNode {
34
35     private static final String JavaDoc RCSRevision = "$Revision: 1.4 $";
36     private static final String JavaDoc RCSName = "$Name: $";
37
38     protected String JavaDoc _name;
39     protected List JavaDoc _children;
40     protected NamedNode _father;
41     protected String JavaDoc _alias;
42
43     public NamedNode() {}
44
45     /**
46      * @param name
47      */

48     public NamedNode(String JavaDoc name) {
49         setName(name);
50     }
51
52     /**
53     Access method for the _name property.
54     
55     @return the current value of the _name property
56      */

57     public String JavaDoc getName() {
58         return _name;
59     }
60
61     /**
62      * Sets the value of the _name property.
63      * @param aName the new value of the _name property
64      */

65     public void setName(String JavaDoc aName) {
66         _name = aName;
67     }
68
69     public String JavaDoc getAlias() {
70         return _alias;
71     }
72
73     public void setAlias(String JavaDoc alias) {
74         _alias = alias;
75     }
76
77     /**
78      * @param child
79      */

80     public void addChild(NamedNode child) {
81         if (null == _children)
82             _children = new ArrayList JavaDoc();
83         _children.add(child);
84         child.setFather(this);
85         return;
86     }
87
88     /**
89      * @param children
90      */

91     public void setChildren(List JavaDoc children) {
92         _children = children;
93         if (null != _children) {
94             for (int i = 0; i < _children.size(); i++) {
95                 ((NamedNode) _children.get(i)).setFather(this);
96             }
97         }
98     }
99
100     /**
101      * @param childName
102      * @return NamedNode
103      */

104     public NamedNode findChild(String JavaDoc childName) {
105         NamedNode retVal = null;
106
107         if (null != _children && null != childName) {
108             Iterator JavaDoc iter = _children.iterator();
109             NamedNode item;
110             while (iter.hasNext()) {
111                 item = (NamedNode) iter.next();
112                 if (childName.equalsIgnoreCase(item.getName())) {
113                     retVal = item;
114                     break;
115                 }
116             }
117         }
118         return retVal;
119     }
120
121     public NamedNode findChildByAlias(String JavaDoc childName) {
122         NamedNode retVal = null;
123
124         if (null != _children && null != childName) {
125             Iterator JavaDoc iter = _children.iterator();
126             NamedNode item;
127             while (iter.hasNext()) {
128                 item = (NamedNode) iter.next();
129                 if (childName.equals(item.getAlias())) {
130                     retVal = item;
131                     break;
132                 }
133             }
134         }
135         return retVal;
136     }
137
138     /**
139      * @return org.xquark.xqueryparser.xquery.List
140      */

141     public List JavaDoc getChildren() {
142         return _children;
143     }
144
145     public void setFather(NamedNode father) {
146         _father = father;
147     }
148
149     public NamedNode getFather() {
150         return _father;
151     }
152
153     public abstract String JavaDoc pprint();
154 }
155
Popular Tags