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 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: * Create a pattern for an universal character.
22: */
23: public UniversalCharacter() {
24: }
25:
26: /**
27: * Return a string representation of this pattern
28: *
29: * @return String representation of the pattern.
30: */
31: public String toString() {
32: StringBuffer buffer = new StringBuffer();
33:
34: buffer.append(".");
35:
36: if ((getMinOccurs() == 1) && (getMaxOccurs() == 1)) {
37: // nothing
38: } else if ((getMinOccurs() == 0) && (getMaxOccurs() == 1))
39: buffer.append("?");
40: else if ((getMinOccurs() == 0)
41: && (getMaxOccurs() == Integer.MAX_VALUE))
42: buffer.append("*");
43: else if ((getMinOccurs() == 1)
44: && (getMaxOccurs() == Integer.MAX_VALUE))
45: buffer.append("+");
46: else {
47: buffer.append("{");
48: buffer.append(String.valueOf(getMinOccurs()));
49: buffer.append(",");
50: buffer.append(String.valueOf(getMaxOccurs()));
51: buffer.append("}");
52: }
53:
54: return buffer.toString();
55: }
56:
57: /**
58: * Create a clone this pattern.
59: *
60: * @return Clone of this pattern.
61: *
62: * @throws CloneNotSupportedException If an exception occurs during the cloning.
63: */
64: public Object clone() {
65: UniversalCharacter clone = new UniversalCharacter();
66:
67: clone.setMinOccurs(getMinOccurs());
68: clone.setMaxOccurs(getMaxOccurs());
69:
70: return clone;
71: }
72:
73: /**
74: * Validates this pattern.
75: *
76: * @return Return a list of violations, if this pattern isn't valid.
77: */
78: public Violations validate() {
79: return null;
80: }
81: }
|