KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > relaxng > pattern > Pattern


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.pattern;
30
31 import com.caucho.relaxng.RelaxException;
32 import com.caucho.relaxng.program.Item;
33 import com.caucho.relaxng.program.NameClassItem;
34 import com.caucho.util.L10N;
35
36 /**
37  * Relax pattern
38  */

39 abstract public class Pattern {
40   protected static final L10N L = new L10N(Pattern.class);
41   
42   private Pattern _parent;
43   private String JavaDoc _elementName;
44
45   private String JavaDoc _location;
46
47   /**
48    * Returns the relax config name.
49    */

50   public String JavaDoc getTagName()
51   {
52     return getClass().getName();
53   }
54
55   /**
56    * Sets the pattern source location.
57    */

58   public void setLocation(String JavaDoc location)
59   {
60     _location = location;
61   }
62
63   /**
64    * Gets the location.
65    */

66   public String JavaDoc getLocation()
67   {
68     if (_location != null)
69       return _location;
70     else if (_parent != null)
71       return _parent.getLocation();
72     else
73       return null;
74   }
75   
76   /**
77    * Returns the element-name.
78    */

79   public String JavaDoc getElementName()
80   {
81     return _elementName;
82   }
83   
84   /**
85    * Sets the element-name.
86    */

87   public void setElementName(String JavaDoc elementName)
88   {
89     _elementName = elementName;
90   }
91   
92   /**
93    * Sets the parent.
94    */

95   public void setParent(Pattern parent)
96     throws RelaxException
97   {
98     _parent = parent;
99   }
100
101   /**
102    * Gets the parent.
103    */

104   public Pattern getParent()
105   {
106     return _parent;
107   }
108
109   /**
110    * Returns true if it contains a data element.
111    */

112   public boolean hasData()
113   {
114     return false;
115   }
116
117   /**
118    * Returns true if it contains an element.
119    */

120   public boolean hasElement()
121   {
122     return false;
123   }
124
125   /**
126    * Adds a name child.
127    */

128   public void addNameChild(NameClassPattern child)
129     throws RelaxException
130   {
131     throw new RelaxException(L.l("<{0}> is not an allowed child for <{1}>.",
132                                  child.getTagName(), getTagName()));
133   }
134
135   /**
136    * Adds an element child.
137    */

138   public void addChild(Pattern child)
139     throws RelaxException
140   {
141     throw new RelaxException(L.l("<{0}> is not an allowed child for <{1}>.",
142                                  child.getTagName(), getTagName()));
143   }
144
145   /**
146    * Ends the element.
147    */

148   public void endElement()
149     throws RelaxException
150   {
151   }
152
153   /**
154    * Creates the current state
155    */

156   public Item createItem(GrammarPattern grammar)
157     throws RelaxException
158   {
159     throw new RelaxException(L.l("item isn't allowed in `{0}'.",
160                                  getClass().getName()));
161   }
162
163   /**
164    * Creates the name program
165    */

166   public NameClassItem createNameItem()
167     throws RelaxException
168   {
169     throw new RelaxException(L.l("name-item isn't allowed in `{0}'.",
170                                  getClass().getName()));
171   }
172
173   abstract public boolean equals(Object JavaDoc o);
174
175   /**
176    * Returns a string for the production.
177    */

178   public String JavaDoc toProduction()
179   {
180     return "unknown";
181   }
182   
183   /**
184    * creates an error.
185    */

186   public RelaxException error(String JavaDoc msg)
187   {
188     String JavaDoc location = getLocation();
189
190     if (location != null)
191       return new RelaxException(location + ": " + msg);
192     else
193       return new RelaxException(msg);
194   }
195 }
196
Popular Tags