Package net.sourceforge.chaperon.model.extended

Source Code of net.sourceforge.chaperon.model.extended.Element

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

package net.sourceforge.chaperon.model.extended;

import net.sourceforge.chaperon.model.Violations;

/**
* This class represent a reference to an element.
*
* @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
* @version CVS $Id: Element.java,v 1.5 2004/01/07 08:28:49 benedikta Exp $
*/
public class Element extends Pattern
{
  private String symbol = null;
  private String location = null;

  public Element() {}

  /**
   * Create a element symbol.
   *
   * @param name Name of the symbol.
   */
  public Element(String symbol)
  {
    this.symbol = symbol;
  }

  public void setSymbol(String symbol)
  {
    this.symbol = symbol;
  }

  public String getSymbol()
  {
    return symbol;
  }

  public boolean isNullable()
  {
    return false;
  }

  public PatternSet getFirstSet()
  {
    PatternSet set = new PatternSet();
    set.addPattern(this);
    return set;
  }

  public PatternSet getLastSet()
  {
    PatternSet set = new PatternSet();
    set.addPattern(this);
    return set;
  }

  public char[] getLimits()
  {
    return new char[0];
  }

  public boolean contains(char minimum, char maximum)
  {
    return false;
  }

  public boolean contains(char c)
  {
    return false;
  }

  /**
   * Set the location from the input source.
   *
   * @param location Location in the input source.
   */
  public void setLocation(String location)
  {
    this.location = location;
  }

  /**
   * Returns the location from the input source.
   *
   * @return Location in the input source.
   */
  public String getLocation()
  {
    return location;
  }

  /**
   * Create a clone this pattern.
   *
   * @return Clone of this pattern.
   *
   * @throws CloneNotSupportedException If an exception occurs during the cloning.
   */
  public Object clone()
  {
    Element clone = new Element(symbol);

    return clone;
  }

  /**
   * Validates this pattern.
   *
   * @return Return a list of violations, if this pattern isn't valid.
   */
  public Violations validate()
  {
    Violations violations = new Violations();

    if (symbol==null)
      violations.addViolation("No symbol defined for element", location);

    return violations;
  }

  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(symbol);
    buffer.append("[");
    buffer.append(index);
    buffer.append("]");
    return buffer.toString();
  }
}
TOP

Related Classes of net.sourceforge.chaperon.model.extended.Element

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.