KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > relaxng > program > ZeroOrMoreItem


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.relaxng.program;
30
31 import com.caucho.relaxng.RelaxException;
32 import com.caucho.util.L10N;
33 import com.caucho.xml.QName;
34
35 import java.util.HashSet JavaDoc;
36 import java.util.Iterator JavaDoc;
37
38 /**
39  * Generates programs from patterns.
40  */

41 public class ZeroOrMoreItem extends Item {
42   protected final static L10N L = new L10N(ZeroOrMoreItem.class);
43
44   private Item _item;
45
46   public ZeroOrMoreItem(Item item)
47   {
48     _item = item;
49   }
50
51   /**
52    * Returns the item.
53    */

54   public Item getItem()
55   {
56     return _item;
57   }
58
59   /**
60    * Returns the first set, the set of element names possible.
61    */

62   public void firstSet(HashSet JavaDoc<QName> set)
63   {
64     _item.firstSet(set);
65   }
66
67   /**
68    * Returns the first set, the set of element names possible.
69    */

70   public void requiredFirstSet(HashSet JavaDoc<QName> set)
71   {
72   }
73   
74   /**
75    * The element always allows
76    */

77   public boolean allowEmpty()
78   {
79     return true;
80   }
81   
82   /**
83    * Return all possible child items or null
84    */

85   public Iterator JavaDoc<Item> getItemsIterator()
86   {
87     return itemIterator( _item );
88   }
89
90   /**
91    * Returns the next item on the match.
92    *
93    * @param name the name of the element
94    * @param contItem the continuation item
95    */

96   public Item startElement(QName name)
97     throws RelaxException
98   {
99     Item next = _item.startElement(name);
100
101     if (next == null)
102       return null;
103     else
104       return next.groupContinuation(this);
105   }
106
107   /**
108    * Returns the first set, the set of attribute names possible.
109    */

110   public void attributeSet(HashSet JavaDoc<QName> set)
111   {
112     _item.attributeSet(set);
113   }
114   
115   /**
116    * Returns true if the attribute is allowed.
117    *
118    * @param name the name of the attribute
119    * @param value the value of the attribute
120    *
121    * @return true if the attribute is allowed
122    */

123   public boolean allowAttribute(QName name, String JavaDoc value)
124     throws RelaxException
125   {
126     return _item.allowAttribute(name, value);
127   }
128   
129   /**
130    * Returns true if the element is allowed somewhere in the item.
131    * allowsElement is used for error messages to give more information
132    * in cases of order dependency.
133    *
134    * @param name the name of the element
135    *
136    * @return true if the element is allowed somewhere
137    */

138   public boolean allowsElement(QName name)
139   {
140     return _item.allowsElement(name);
141   }
142
143   /**
144    * Returns the pretty printed syntax.
145    */

146   public String JavaDoc toSyntaxDescription(int depth)
147   {
148     return _item.toSyntaxDescription(depth) + "*";
149   }
150
151   /**
152    * Returns true for an element with simple syntax.
153    */

154   protected boolean isSimpleSyntax()
155   {
156     return _item.isSimpleSyntax();
157   }
158
159   /**
160    * Returns the hash code for the empty item.
161    */

162   public int hashCode()
163   {
164     return 17 + _item.hashCode();
165   }
166
167   /**
168    * Returns true if the object is an empty item.
169    */

170   public boolean equals(Object JavaDoc o)
171   {
172     if (this == o)
173       return true;
174     
175     if (! (o instanceof ZeroOrMoreItem))
176       return false;
177
178     ZeroOrMoreItem item = (ZeroOrMoreItem) o;
179
180     return _item.equals(item._item);
181   }
182
183   public String JavaDoc toString()
184   {
185     return "ZeroOrMoreItem[" + _item + "]";
186   }
187 }
188
189
Popular Tags