KickJava   Java API By Example, From Geeks To Geeks.

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


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  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

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

41 public class AttributeItem extends Item {
42   protected final static L10N L = new L10N(AttributeItem.class);
43
44   private final NameClassItem _name;
45
46   public AttributeItem(NameClassItem name)
47   {
48     _name = name;
49   }
50
51   public NameClassItem getNameClassItem()
52   {
53     return _name;
54   }
55
56   /**
57    * Returns the first set, the set of element names possible.
58    */

59   public void firstSet(HashSet JavaDoc<QName> set)
60   {
61   }
62   
63   /**
64    * The attribute does not allow the empty match.
65    */

66   public boolean allowEmpty()
67   {
68     return false;
69   }
70
71   /**
72    * Returns the attribute set, the set of attribute names possible.
73    */

74   public void attributeSet(HashSet JavaDoc<QName> set)
75   {
76     _name.firstSet(set);
77   }
78   
79   /**
80    * Returns true if the attribute is allowed.
81    *
82    * @param name the name of the attribute
83    */

84   public boolean allowAttribute(QName name, String JavaDoc value)
85     throws RelaxException
86   {
87     return _name.matches(name);
88   }
89   
90   /**
91    * Returns the next item on the match.
92    *
93    * @param name the name of the attribute
94    * @param value the value of the attribute
95    */

96   public Item setAttribute(QName name, String JavaDoc value)
97     throws RelaxException
98   {
99     if (_name.matches(name))
100       return null;
101     else
102       return this;
103   }
104
105   /**
106    * Returns the item after the attribute ends. In this case,
107    * return null since this attribute is still required.
108    */

109   public Item attributeEnd()
110   {
111     return null;
112   }
113
114   /**
115    * Returns the pretty printed syntax.
116    */

117   public String JavaDoc toSyntaxDescription(int depth)
118   {
119     return _name.toSyntaxDescription("@");
120   }
121
122   /**
123    * Returns true for an element with simple syntax.
124    */

125   protected boolean isSimpleSyntax()
126   {
127     return true;
128   }
129
130   /**
131    * Returns the hash code for the empty item.
132    */

133   public int hashCode()
134   {
135     return 27 + _name.hashCode();
136   }
137
138   /**
139    * Returns true if the object is an empty item.
140    */

141   public boolean equals(Object JavaDoc o)
142   {
143     if (this == o)
144       return true;
145     
146     if (! (o instanceof AttributeItem))
147       return false;
148
149     AttributeItem attr = (AttributeItem) o;
150
151     return _name.equals(attr._name);
152   }
153
154   public String JavaDoc toString()
155   {
156     return "AttributeItem[" + _name + "]";
157   }
158 }
159
160
Popular Tags