1 17 package org.apache.ws.jaxme.xs.xml; 18 19 import java.util.StringTokenizer ; 20 21 58 public class XsBlockSet { 59 boolean extensionAllowed, restrictionAllowed, substitutionAllowed; 60 61 63 public boolean isExtensionAllowed() { 64 return extensionAllowed; 65 } 66 67 69 public void setExtensionAllowed(boolean pExtensionAllowed) { 70 extensionAllowed = pExtensionAllowed; 71 } 72 73 75 public boolean isRestrictionAllowed() { 76 return restrictionAllowed; 77 } 78 79 81 public void setRestrictionAllowed(boolean pRestrictionAllowed) { 82 restrictionAllowed = pRestrictionAllowed; 83 } 84 85 87 public boolean isSubstitutionAllowed() { 88 return substitutionAllowed; 89 } 90 91 93 public void setSubstitutionAllowed(boolean pSubstitutionAllowed) { 94 substitutionAllowed = pSubstitutionAllowed; 95 } 96 97 100 public static XsBlockSet valueOf(String pValue) { 101 return new XsBlockSet(pValue); 102 } 103 104 106 public XsBlockSet(String pValue) { 107 if ("#all".equals(pValue)) { 108 setExtensionAllowed(true); 109 setRestrictionAllowed(true); 110 setSubstitutionAllowed(true); 111 } else { 112 for (StringTokenizer st = new StringTokenizer (pValue, " "); st.hasMoreTokens(); ) { 113 String s = st.nextToken(); 114 if ("extension".equals(s)) { 115 setExtensionAllowed(true); 116 } else if ("restriction".equals(s)) { 117 setRestrictionAllowed(true); 118 } else if ("substitution".equals(s)) { 119 setSubstitutionAllowed(true); 120 } else { 121 throw new IllegalArgumentException ("Invalid block set value: " + pValue + "; the token " + s + " did not resolve to either of 'extension', 'restriction', or 'substitution'."); 122 } 123 } 124 } 125 } 126 127 public String toString() { 128 StringBuffer sb = new StringBuffer (); 129 if (extensionAllowed) { 130 sb.append("extension"); 131 } 132 if (restrictionAllowed) { 133 if (sb.length() > 0) { 134 sb.append(" "); 135 } 136 sb.append("restriction"); 137 } 138 if (substitutionAllowed) { 139 if (sb.length() > 0) { 140 sb.append(" "); 141 } 142 sb.append("substitution"); 143 } 144 return sb.toString(); 145 } 146 147 public boolean equals(Object o) { 148 if (o == null || !(XsBlockSet.class.equals(o.getClass()))) { 149 return false; 150 } 151 XsBlockSet bs = (XsBlockSet) o; 152 return bs.extensionAllowed == extensionAllowed && 153 bs.restrictionAllowed == restrictionAllowed && 154 bs.substitutionAllowed == substitutionAllowed; 155 } 156 157 public int hashCode() { 158 int result = 0; 159 if (extensionAllowed) { result += 1; } 160 if (restrictionAllowed) { result += 2; } 161 if (substitutionAllowed) { result += 4; } 162 return result; 163 } 164 } 165 | Popular Tags |