View Javadoc

1   package net.sf.tomp.xml.type;
2   
3   import java.util.*;
4   
5   /***
6    * DOCUMENT ME!
7    * 
8    * @author $author$
9    * @version $Revision$
10   */
11  public class TypeImpl implements Type {
12      /*** DOCUMENT ME! */
13      public static final boolean SHOW_PARENTS = false;
14  
15      /*** DOCUMENT ME! */
16      public static final Type UNKNOWN = new TypeImpl("UNKNOWN", "UNKNOWN");
17  
18      /*** DOCUMENT ME! */
19      protected String identification;
20  
21      /*** DOCUMENT ME! */
22      protected String type;
23  
24      /*** DOCUMENT ME! */
25      protected List parents = new ArrayList();
26  
27      /*** DOCUMENT ME! */
28      protected Map typesForContext = new HashMap();
29  
30      /***
31       * Creates a new TypeImpl object.
32       * 
33       * @param t DOCUMENT ME!
34       * @param i DOCUMENT ME!
35       */
36      public TypeImpl(String t, String i) {
37          type = t;
38          identification = i;
39      }
40  
41      public boolean equals(Object o) {
42          Type t = (Type) o;
43  
44          return getIdentification().equals(t.getIdentification())
45                  && getTypeType().equals(t.getTypeType());
46      }
47  
48      public int hashCode() {
49          return getIdentification().hashCode() ^ getTypeType().hashCode();
50      }
51  
52      /***
53       * DOCUMENT ME!
54       * 
55       * @return DOCUMENT ME!
56       */
57      public String getIdentification() {
58          return identification;
59      }
60  
61      /***
62       * DOCUMENT ME!
63       * 
64       * @return DOCUMENT ME!
65       */
66      public String getTypeType() {
67          return type;
68      }
69  
70      /***
71       * DOCUMENT ME!
72       * 
73       * @param p DOCUMENT ME!
74       */
75      public void addParent(Type p) {
76          parents.add(p);
77      }
78  
79      /***
80       * DOCUMENT ME!
81       * 
82       * @return DOCUMENT ME!
83       */
84      public Iterator parentIterator() {
85          return parents.iterator();
86      }
87  
88      /***
89       * DOCUMENT ME!
90       * 
91       * @return DOCUMENT ME!
92       */
93      public Iterator ancestorIterator() {
94          // FIXME: only parents, not further ancestors
95          return parents.iterator();
96      }
97  
98      /***
99       * DOCUMENT ME!
100      * 
101      * @param c DOCUMENT ME!
102      * @param t DOCUMENT ME!
103      */
104     public void addTypeForContext(TypeContext c, Type t) {
105         typesForContext.put(c, t);
106     }
107 
108     /***
109      * DOCUMENT ME!
110      * 
111      * @param c DOCUMENT ME!
112      * @return DOCUMENT ME!
113      */
114     public Type getTypeForContext(TypeContext c) {
115         return (Type) typesForContext.get(c);
116     }
117 
118     /***
119      * DOCUMENT ME!
120      * 
121      * @param t DOCUMENT ME!
122      * @return DOCUMENT ME!
123      */
124     public boolean isDescendantOf(Type t) {
125         for (Iterator i = parentIterator(); i.hasNext();) {
126             Type parent = (Type) i.next();
127 
128             if (parent.equals(t) || parent.isDescendantOf(t)) {
129                 return true;
130             }
131         }
132 
133         return false;
134     }
135 
136     /***
137      * DOCUMENT ME!
138      * 
139      * @return DOCUMENT ME!
140      */
141     public String toString() {
142         return "Type[" + identification
143                 + (SHOW_PARENTS ? (" parents=" + parents) : "") + "]";
144     }
145 }
146 
147 /*
148  * The contents of this file are subject to the Mozilla Public License Version
149  * 1.1 (the "License"); you may not use this file except in compliance with the
150  * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
151  * Software distributed under the License is distributed on an "AS IS" basis,
152  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
153  * the specific language governing rights and limitations under the License. The
154  * Original Code is: all this file. The Initial Developer of the Original Code
155  * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
156  */