KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > model > extended > Element


1 /*
2  * Copyright (C) Chaperon. All rights reserved.
3  * -------------------------------------------------------------------------
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8
9 package net.sourceforge.chaperon.model.extended;
10
11 import net.sourceforge.chaperon.model.Violations;
12
13 /**
14  * This class represent a reference to an element.
15  *
16  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
17  * @version CVS $Id: Element.java,v 1.5 2004/01/07 08:28:49 benedikta Exp $
18  */

19 public class Element extends Pattern
20 {
21   private String JavaDoc symbol = null;
22   private String JavaDoc location = null;
23
24   public Element() {}
25
26   /**
27    * Create a element symbol.
28    *
29    * @param name Name of the symbol.
30    */

31   public Element(String JavaDoc symbol)
32   {
33     this.symbol = symbol;
34   }
35
36   public void setSymbol(String JavaDoc symbol)
37   {
38     this.symbol = symbol;
39   }
40
41   public String JavaDoc getSymbol()
42   {
43     return symbol;
44   }
45
46   public boolean isNullable()
47   {
48     return false;
49   }
50
51   public PatternSet getFirstSet()
52   {
53     PatternSet set = new PatternSet();
54     set.addPattern(this);
55     return set;
56   }
57
58   public PatternSet getLastSet()
59   {
60     PatternSet set = new PatternSet();
61     set.addPattern(this);
62     return set;
63   }
64
65   public char[] getLimits()
66   {
67     return new char[0];
68   }
69
70   public boolean contains(char minimum, char maximum)
71   {
72     return false;
73   }
74
75   public boolean contains(char c)
76   {
77     return false;
78   }
79
80   /**
81    * Set the location from the input source.
82    *
83    * @param location Location in the input source.
84    */

85   public void setLocation(String JavaDoc location)
86   {
87     this.location = location;
88   }
89
90   /**
91    * Returns the location from the input source.
92    *
93    * @return Location in the input source.
94    */

95   public String JavaDoc getLocation()
96   {
97     return location;
98   }
99
100   /**
101    * Create a clone this pattern.
102    *
103    * @return Clone of this pattern.
104    *
105    * @throws CloneNotSupportedException If an exception occurs during the cloning.
106    */

107   public Object JavaDoc clone()
108   {
109     Element clone = new Element(symbol);
110
111     return clone;
112   }
113
114   /**
115    * Validates this pattern.
116    *
117    * @return Return a list of violations, if this pattern isn't valid.
118    */

119   public Violations validate()
120   {
121     Violations violations = new Violations();
122
123     if (symbol==null)
124       violations.addViolation("No symbol defined for element", location);
125
126     return violations;
127   }
128
129   public String JavaDoc toString()
130   {
131     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
132     buffer.append(symbol);
133     buffer.append("[");
134     buffer.append(index);
135     buffer.append("]");
136     return buffer.toString();
137   }
138 }
139
Popular Tags