01: /*
02: * Copyright (C) Chaperon. All rights reserved.
03: * -------------------------------------------------------------------------
04: * This software is published under the terms of the Apache Software License
05: * version 1.1, a copy of which has been included with this distribution in
06: * the LICENSE file.
07: */
08:
09: package net.sourceforge.chaperon.model.pattern;
10:
11: import net.sourceforge.chaperon.model.Violations;
12:
13: /**
14: * This class describes a pattern for the begin of a line.
15: *
16: * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
17: * @version CVS $Id: BeginOfLine.java,v 1.5 2003/12/09 19:55:52 benedikta Exp $
18: */
19: public class BeginOfLine extends Pattern {
20: /**
21: * Creates a pattern for the begin of a line.
22: */
23: public BeginOfLine() {
24: }
25:
26: /**
27: * Create a clone of this pattern.
28: *
29: * @return Clone of this pattern.
30: *
31: * @throws CloneNotSupportedException If an exception occurs during the cloning.
32: */
33: public String toString() {
34: StringBuffer buffer = new StringBuffer();
35:
36: buffer.append("^");
37:
38: if ((getMinOccurs() == 1) && (getMaxOccurs() == 1)) {
39: // nothing
40: } else if ((getMinOccurs() == 0) && (getMaxOccurs() == 1))
41: buffer.append("?");
42: else if ((getMinOccurs() == 0)
43: && (getMaxOccurs() == Integer.MAX_VALUE))
44: buffer.append("*");
45: else if ((getMinOccurs() == 1)
46: && (getMaxOccurs() == Integer.MAX_VALUE))
47: buffer.append("+");
48: else {
49: buffer.append("{");
50: buffer.append(String.valueOf(getMinOccurs()));
51: buffer.append(",");
52: buffer.append(String.valueOf(getMaxOccurs()));
53: buffer.append("}");
54: }
55:
56: return buffer.toString();
57: }
58:
59: /**
60: * Create a clone of this pattern.
61: *
62: * @return Clone of this pattern.
63: *
64: * @throws CloneNotSupportedException If an exception occurs during the cloning.
65: */
66: public Object clone() {
67: BeginOfLine clone = new BeginOfLine();
68:
69: clone.setMinOccurs(getMinOccurs());
70: clone.setMaxOccurs(getMaxOccurs());
71:
72: return clone;
73: }
74:
75: /**
76: * Validates this pattern.
77: *
78: * @return Return a list of violations, if this pattern isn't valid.
79: */
80: public Violations validate() {
81: return null;
82: }
83: }
|