KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > model > pattern > BeginOfLine


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.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   /**
22    * Creates a pattern for the begin of a line.
23    */

24   public BeginOfLine() {}
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 JavaDoc toString()
34   {
35     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
36
37     buffer.append("^");
38
39     if ((getMinOccurs()==1) && (getMaxOccurs()==1))
40     {
41       // nothing
42
}
43     else if ((getMinOccurs()==0) && (getMaxOccurs()==1))
44       buffer.append("?");
45     else if ((getMinOccurs()==0) && (getMaxOccurs()==Integer.MAX_VALUE))
46       buffer.append("*");
47     else if ((getMinOccurs()==1) && (getMaxOccurs()==Integer.MAX_VALUE))
48       buffer.append("+");
49     else
50     {
51       buffer.append("{");
52       buffer.append(String.valueOf(getMinOccurs()));
53       buffer.append(",");
54       buffer.append(String.valueOf(getMaxOccurs()));
55       buffer.append("}");
56     }
57
58     return buffer.toString();
59   }
60
61   /**
62    * Create a clone of this pattern.
63    *
64    * @return Clone of this pattern.
65    *
66    * @throws CloneNotSupportedException If an exception occurs during the cloning.
67    */

68   public Object JavaDoc clone()
69   {
70     BeginOfLine clone = new BeginOfLine();
71
72     clone.setMinOccurs(getMinOccurs());
73     clone.setMaxOccurs(getMaxOccurs());
74
75     return clone;
76   }
77
78   /**
79    * Validates this pattern.
80    *
81    * @return Return a list of violations, if this pattern isn't valid.
82    */

83   public Violations validate()
84   {
85     return null;
86   }
87 }
88
Popular Tags