001: /*
002: * Copyright (C) Chaperon. All rights reserved.
003: * -------------------------------------------------------------------------
004: * This software is published under the terms of the Apache Software License
005: * version 1.1, a copy of which has been included with this distribution in
006: * the LICENSE file.
007: */
008:
009: package net.sourceforge.chaperon.model.extended;
010:
011: import net.sourceforge.chaperon.model.Violations;
012:
013: /**
014: * This class represent a reference to an element.
015: *
016: * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
017: * @version CVS $Id: Element.java,v 1.5 2004/01/07 08:28:49 benedikta Exp $
018: */
019: public class Element extends Pattern {
020: private String symbol = null;
021: private String location = null;
022:
023: public Element() {
024: }
025:
026: /**
027: * Create a element symbol.
028: *
029: * @param name Name of the symbol.
030: */
031: public Element(String symbol) {
032: this .symbol = symbol;
033: }
034:
035: public void setSymbol(String symbol) {
036: this .symbol = symbol;
037: }
038:
039: public String getSymbol() {
040: return symbol;
041: }
042:
043: public boolean isNullable() {
044: return false;
045: }
046:
047: public PatternSet getFirstSet() {
048: PatternSet set = new PatternSet();
049: set.addPattern(this );
050: return set;
051: }
052:
053: public PatternSet getLastSet() {
054: PatternSet set = new PatternSet();
055: set.addPattern(this );
056: return set;
057: }
058:
059: public char[] getLimits() {
060: return new char[0];
061: }
062:
063: public boolean contains(char minimum, char maximum) {
064: return false;
065: }
066:
067: public boolean contains(char c) {
068: return false;
069: }
070:
071: /**
072: * Set the location from the input source.
073: *
074: * @param location Location in the input source.
075: */
076: public void setLocation(String location) {
077: this .location = location;
078: }
079:
080: /**
081: * Returns the location from the input source.
082: *
083: * @return Location in the input source.
084: */
085: public String getLocation() {
086: return location;
087: }
088:
089: /**
090: * Create a clone this pattern.
091: *
092: * @return Clone of this pattern.
093: *
094: * @throws CloneNotSupportedException If an exception occurs during the cloning.
095: */
096: public Object clone() {
097: Element clone = new Element(symbol);
098:
099: return clone;
100: }
101:
102: /**
103: * Validates this pattern.
104: *
105: * @return Return a list of violations, if this pattern isn't valid.
106: */
107: public Violations validate() {
108: Violations violations = new Violations();
109:
110: if (symbol == null)
111: violations.addViolation("No symbol defined for element",
112: location);
113:
114: return violations;
115: }
116:
117: public String toString() {
118: StringBuffer buffer = new StringBuffer();
119: buffer.append(symbol);
120: buffer.append("[");
121: buffer.append(index);
122: buffer.append("]");
123: return buffer.toString();
124: }
125: }
|