KickJava   Java API By Example, From Geeks To Geeks.

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


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 an universal character. This pattern matches against all characters.
15  *
16  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
17  * @version CVS $Id: UniversalCharacter.java,v 1.4 2003/12/09 19:55:53 benedikta Exp $
18  */

19 public class UniversalCharacter extends Pattern
20 {
21   /**
22    * Create a pattern for an universal character.
23    */

24   public UniversalCharacter() {}
25
26   /**
27    * Return a string representation of this pattern
28    *
29    * @return String representation of the pattern.
30    */

31   public String JavaDoc toString()
32   {
33     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
34
35     buffer.append(".");
36
37     if ((getMinOccurs()==1) && (getMaxOccurs()==1))
38     {
39       // nothing
40
}
41     else if ((getMinOccurs()==0) && (getMaxOccurs()==1))
42       buffer.append("?");
43     else if ((getMinOccurs()==0) && (getMaxOccurs()==Integer.MAX_VALUE))
44       buffer.append("*");
45     else if ((getMinOccurs()==1) && (getMaxOccurs()==Integer.MAX_VALUE))
46       buffer.append("+");
47     else
48     {
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 this pattern.
61    *
62    * @return Clone of this pattern.
63    *
64    * @throws CloneNotSupportedException If an exception occurs during the cloning.
65    */

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

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