1 8 9 package net.sourceforge.chaperon.model.pattern; 10 11 import net.sourceforge.chaperon.common.Decoder; 12 import net.sourceforge.chaperon.model.Violations; 13 14 20 public class CharacterString extends Pattern 21 { 22 private String string = ""; 23 24 27 public CharacterString() {} 28 29 34 public CharacterString(String string) 35 { 36 setString(string); 37 } 38 39 44 public void setString(String string) 45 { 46 this.string = string; 47 } 48 49 54 public String getString() 55 { 56 return string; 57 } 58 59 64 public String toString() 65 { 66 StringBuffer buffer = new StringBuffer (); 67 68 buffer.append(Decoder.decode(string, Decoder.REGEX)); 69 70 if ((getMinOccurs()==1) && (getMaxOccurs()==1)) 71 { 72 } 74 else if ((getMinOccurs()==0) && (getMaxOccurs()==1)) 75 buffer.append("?"); 76 else if ((getMinOccurs()==0) && (getMaxOccurs()==Integer.MAX_VALUE)) 77 buffer.append("*"); 78 else if ((getMinOccurs()==1) && (getMaxOccurs()==Integer.MAX_VALUE)) 79 buffer.append("+"); 80 else 81 { 82 buffer.append("{"); 83 buffer.append(String.valueOf(getMinOccurs())); 84 buffer.append(","); 85 buffer.append(String.valueOf(getMaxOccurs())); 86 buffer.append("}"); 87 } 88 89 return buffer.toString(); 90 } 91 92 99 public Object clone() 100 { 101 CharacterString clone = new CharacterString(); 102 103 clone.setMinOccurs(getMinOccurs()); 104 clone.setMaxOccurs(getMaxOccurs()); 105 106 clone.setString(getString()); 107 108 return clone; 109 } 110 111 116 public Violations validate() 117 { 118 Violations violations = new Violations(); 119 120 if ((string==null) || (string.length()<=0)) 121 violations.addViolation("Character string contains no characters", getLocation()); 122 123 return violations; 124 } 125 } 126 | Popular Tags |