1 17 package org.apache.ws.jaxme.xs.xml; 18 19 import java.util.StringTokenizer ; 20 21 49 public class XsDerivationSet { 50 boolean extensionAllowed, restrictionAllowed; 51 52 54 public boolean isExtensionAllowed() { 55 return extensionAllowed; 56 } 57 58 60 public void setExtensionAllowed(boolean pExtensionAllowed) { 61 extensionAllowed = pExtensionAllowed; 62 } 63 64 66 public boolean isRestrictionAllowed() { 67 return restrictionAllowed; 68 } 69 70 72 public void setRestrictionAllowed(boolean pRestrictionAllowed) { 73 restrictionAllowed = pRestrictionAllowed; 74 } 75 76 79 public static XsDerivationSet valueOf(String pValue) { 80 return new XsDerivationSet(pValue); 81 } 82 83 85 public XsDerivationSet(String pValue) { 86 if ("#all".equals(pValue)) { 87 setExtensionAllowed(true); 88 setRestrictionAllowed(true); 89 } else { 90 for (StringTokenizer st = new StringTokenizer (pValue, " "); st.hasMoreTokens(); ) { 91 String s = st.nextToken(); 92 if ("extension".equals(s)) { 93 setExtensionAllowed(true); 94 } else if ("restriction".equals(s)) { 95 setRestrictionAllowed(true); 96 } else { 97 throw new IllegalArgumentException ("Invalid derivation set value: " + pValue + "; the token " + s + " did not resolve to either of 'extension' or 'restriction'"); 98 } 99 } 100 } 101 } 102 103 public String toString() { 104 if (isExtensionAllowed()) { 105 if (isRestrictionAllowed()) { 106 return "extension restriction"; 107 } else { 108 return "extension"; 109 } 110 } else { 111 if (isRestrictionAllowed()) { 112 return "restriction"; 113 } else { 114 return ""; 115 } 116 } 117 } 118 119 public boolean equals(Object o) { 120 if (o == null || !(XsDerivationSet.class.equals(o.getClass()))) { 121 return false; 122 } 123 XsDerivationSet ds = (XsDerivationSet) o; 124 return ds.extensionAllowed == extensionAllowed && 125 ds.restrictionAllowed == restrictionAllowed; 126 } 127 128 public int hashCode() { 129 int result = 0; 130 if (extensionAllowed) { result += 1; } 131 if (restrictionAllowed) { result += 2; } 132 return result; 133 } 134 } 135 | Popular Tags |