1 17 package org.apache.ws.jaxme.xs.xml; 18 19 import java.util.Arrays ; 20 import java.util.Comparator ; 21 import java.util.HashSet ; 22 import java.util.Set ; 23 import java.util.StringTokenizer ; 24 25 26 62 public abstract class XsNamespaceList { 63 65 public static final XsNamespaceList ANY = new XsNamespaceList(){ 66 68 public boolean isAny() { return true; } 69 71 public boolean isOther() { return false; } 72 74 public XsAnyURI[] getUris() { return null; } 75 77 public String toString() { return "##any"; } 78 }; 79 80 83 public static class Other extends XsNamespaceList { 84 private final XsAnyURI[] uris; 85 protected Other(XsAnyURI pTargetNamespace) { 86 if (pTargetNamespace == null) { 87 pTargetNamespace = new XsAnyURI(""); 88 } 89 uris = new XsAnyURI[]{pTargetNamespace}; 90 } 91 93 public boolean isAny() { return false; } 94 96 public boolean isOther() { return true; } 97 99 public XsAnyURI[] getUris() { return uris; } 100 102 public String toString() { return "##other"; } 103 105 public int hashCode() { return getUris()[0].hashCode(); } 106 109 public boolean equals(Object pOther) { 110 return pOther != null 111 && (pOther instanceof Other) 112 && getUris()[0].equals(((Other) pOther).getUris()[0]); 113 } 114 } 115 116 public static class Basic extends XsNamespaceList { 117 private final XsAnyURI targetNamespace; 118 private final XsAnyURI[] uris; 119 private final String toStr; 120 protected Basic(String pValue, XsAnyURI pTargetNamespace) { 121 targetNamespace = pTargetNamespace; 122 toStr = pValue; 123 Set set = new HashSet (); 124 if (pTargetNamespace == null) { 125 pTargetNamespace = new XsAnyURI(""); 126 } 127 for (StringTokenizer st = new StringTokenizer (pValue); st.hasMoreTokens(); ) { 128 String s = st.nextToken(); 129 if ("##targetNamespace".equals(s)) { 130 set.add(pTargetNamespace); 131 } else if ("##local".equals(pTargetNamespace)) { 132 set.add(new XsAnyURI("")); 133 } else { 134 set.add(new XsAnyURI(s)); 135 } 136 } 137 uris = (XsAnyURI[]) set.toArray(new XsAnyURI[set.size()]); 138 } 139 141 public boolean isAny() { return false; } 142 144 public boolean isOther() { return false; } 145 148 public XsAnyURI[] getUris() { return uris; } 149 151 public String toString() { return toStr; } 152 156 public int hashCode() { 157 XsAnyURI[] uris = getUris(); 158 int hash = uris.length; 159 for (int i = 0; i < uris.length; i++) { 160 hash += uris[i].hashCode(); 161 } 162 return hash; 163 } 164 167 public boolean equals(Object pOther) { 168 return pOther != null 169 && pOther instanceof Basic 170 && Arrays.equals(getUris(), ((Basic) pOther).getUris()); 171 } 172 } 173 174 178 public static XsNamespaceList valueOf(String pValue, XsAnyURI pTargetNamespace) { 179 if ("##any".equals(pValue)) { 180 return ANY; 181 } else if ("##other".equals(pValue)) { 182 return new Other(pTargetNamespace); 183 } else { 184 return new Basic(pValue, pTargetNamespace); 185 } 186 } 187 188 192 public abstract boolean isAny(); 193 194 198 public abstract boolean isOther(); 199 200 206 public abstract XsAnyURI[] getUris(); 207 } 208 | Popular Tags |