1 17 package org.apache.ws.jaxme.xs.xml; 18 19 import java.util.StringTokenizer ; 20 21 52 public class XsSimpleDerivationSet { 53 final boolean listAllowed, unionAllowed, restrictionAllowed; 54 55 57 public boolean isListAllowed() { 58 return listAllowed; 59 } 60 61 63 public boolean isUnionAllowed() { 64 return unionAllowed; 65 } 66 67 69 public boolean isRestrictionAllowed() { 70 return restrictionAllowed; 71 } 72 73 76 public static XsSimpleDerivationSet valueOf(String pValue) { 77 return new XsSimpleDerivationSet(pValue); 78 } 79 80 82 public XsSimpleDerivationSet(String pValue) { 83 if ("#all".equals(pValue)) { 84 listAllowed = true; 85 unionAllowed = true; 86 restrictionAllowed = true; 87 } else { 88 boolean acceptList = false; 89 boolean acceptUnion = false; 90 boolean acceptRestriction = false; 91 for (StringTokenizer st = new StringTokenizer (pValue, " "); st.hasMoreTokens(); ) { 92 String s = st.nextToken(); 93 if ("list".equals(s)) { 94 acceptList = true; 95 } else if ("union".equals(s)) { 96 acceptUnion = true; 97 } else if ("restriction".equals(s)) { 98 acceptRestriction = true; 99 } else { 100 throw new IllegalArgumentException ("Invalid derivation set value: " + pValue + "; the token " + s + " did not resolve to either of 'extension' or 'restriction'"); 101 } 102 } 103 listAllowed = acceptList; 104 unionAllowed = acceptUnion; 105 restrictionAllowed = acceptRestriction; 106 } 107 } 108 109 public String toString() { 110 final StringBuffer sb = new StringBuffer (); 111 if (listAllowed) { 112 sb.append("list"); 113 } 114 if (unionAllowed) { 115 if (sb.length() > 0) { 116 sb.append(" "); 117 } 118 sb.append("union"); 119 } 120 if (restrictionAllowed) { 121 if (sb.length() > 0) { 122 sb.append(" "); 123 } 124 sb.append("restriction"); 125 } 126 return sb.toString(); 127 } 128 129 public boolean equals(Object o) { 130 if (o == null || !(XsSimpleDerivationSet.class.equals(o.getClass()))) { 131 return false; 132 } 133 XsSimpleDerivationSet ds = (XsSimpleDerivationSet) o; 134 return ds.listAllowed == listAllowed && 135 ds.unionAllowed == unionAllowed && 136 ds.restrictionAllowed == restrictionAllowed; 137 } 138 139 public int hashCode() { 140 int result = 0; 141 if (listAllowed) { result += 1; } 142 if (unionAllowed) { result += 2; } 143 if (restrictionAllowed) { result += 4; } 144 return result; 145 } 146 } 147 | Popular Tags |