1 16 17 package org.apache.axis.encoding; 18 19 import org.apache.axis.Constants; 20 import org.apache.axis.utils.Messages; 21 22 import java.util.HashMap ; 23 24 128 public class TypeMappingRegistryImpl implements TypeMappingRegistry { 129 130 private HashMap mapTM; private TypeMappingDelegate defaultDelTM; private boolean isDelegated = false; 133 134 138 public TypeMappingRegistryImpl(TypeMappingImpl tm) { 139 mapTM = new HashMap (); 140 defaultDelTM = new TypeMappingDelegate(tm); 141 } 144 145 148 public TypeMappingRegistryImpl() { 149 this(true); 150 } 151 152 public TypeMappingRegistryImpl(boolean registerDefaults) { 153 mapTM = new HashMap (); 154 if (registerDefaults) { 155 defaultDelTM = DefaultTypeMappingImpl.getSingletonDelegate(); 156 TypeMappingDelegate del = new TypeMappingDelegate(new DefaultSOAPEncodingTypeMappingImpl()); 157 register(Constants.URI_SOAP11_ENC, del); 158 } else { 159 defaultDelTM = new TypeMappingDelegate(TypeMappingDelegate.placeholder); 160 } 161 } 162 163 169 public void delegate(TypeMappingRegistry secondaryTMR) { 170 171 if (isDelegated || secondaryTMR == null || secondaryTMR == this) { 172 return; 173 } 174 175 isDelegated = true; 176 String [] keys = secondaryTMR.getRegisteredEncodingStyleURIs(); 177 TypeMappingDelegate otherDefault = 178 ((TypeMappingRegistryImpl)secondaryTMR).defaultDelTM; 179 if (keys != null) { 180 for (int i=0; i < keys.length; i++) { 181 try { 182 String nsURI = keys[i]; 183 TypeMappingDelegate tm = (TypeMappingDelegate) mapTM.get(nsURI); 184 if (tm == null) { 185 tm = (TypeMappingDelegate)createTypeMapping(); 186 tm.setSupportedEncodings(new String [] { nsURI }); 187 register(nsURI, tm); 188 } 189 190 if (tm != null) { 191 TypeMappingDelegate del = (TypeMappingDelegate) 193 ((TypeMappingRegistryImpl)secondaryTMR).mapTM.get(nsURI); 194 195 while (del.next != null) { 196 TypeMappingDelegate nu = new TypeMappingDelegate(del.delegate); 197 tm.setNext(nu); 198 199 if (del.next == otherDefault) { 200 nu.setNext(defaultDelTM); 201 break; 202 } 203 del = del.next; 204 tm = nu; 205 } 206 } 207 208 } catch (Exception e) { 209 } 210 } 211 } 212 if (defaultDelTM.delegate != TypeMappingDelegate.placeholder) { 215 defaultDelTM.setNext(otherDefault); 216 } else { 217 defaultDelTM.delegate = otherDefault.delegate; 218 } 219 220 } 221 222 223 224 225 226 237 public javax.xml.rpc.encoding.TypeMapping register(String namespaceURI, 238 javax.xml.rpc.encoding.TypeMapping mapping) { 239 if (mapping == null || 241 !(mapping instanceof TypeMappingDelegate)) { 242 throw new IllegalArgumentException ( 243 Messages.getMessage("badTypeMapping")); 244 } 245 if (namespaceURI == null) { 246 throw new java.lang.IllegalArgumentException ( 247 Messages.getMessage("nullNamespaceURI")); 248 } 249 250 TypeMappingDelegate del = (TypeMappingDelegate)mapping; 251 TypeMappingDelegate old = (TypeMappingDelegate)mapTM.get(namespaceURI); 252 if (old == null) { 253 del.setNext(defaultDelTM); 254 } else { 255 del.setNext(old); 256 } 257 mapTM.put(namespaceURI, del); 258 return old; } 260 261 270 public void registerDefault(javax.xml.rpc.encoding.TypeMapping mapping) { 271 if (mapping == null || 272 !(mapping instanceof TypeMappingDelegate)) { 273 throw new IllegalArgumentException ( 274 Messages.getMessage("badTypeMapping")); 275 } 276 277 281 if (defaultDelTM.getNext() != null) { 282 throw new IllegalArgumentException ( 283 Messages.getMessage("defaultTypeMappingSet")); 284 } 285 286 defaultDelTM = (TypeMappingDelegate)mapping; 287 } 288 289 295 public void doRegisterFromVersion(String version) { 296 if (version == null || version.equals("1.0") || version.equals("1.2")) { 297 TypeMappingImpl.dotnet_soapenc_bugfix = false; 298 } else if (version.equals("1.1")) { 300 TypeMappingImpl.dotnet_soapenc_bugfix = true; 301 return; 303 } else if (version.equals("1.3")) { 304 defaultDelTM = new TypeMappingDelegate( 306 DefaultJAXRPC11TypeMappingImpl.getSingleton()); 307 } else { 308 throw new RuntimeException ( 309 Messages.getMessage("j2wBadTypeMapping00")); 310 } 311 registerSOAPENCDefault( 312 new TypeMappingDelegate(DefaultSOAPEncodingTypeMappingImpl. 313 getSingleton())); 314 } 315 319 private void registerSOAPENCDefault(TypeMappingDelegate mapping) { 320 if (!mapTM.containsKey(Constants.URI_SOAP11_ENC)) { 325 mapTM.put(Constants.URI_SOAP11_ENC, mapping); 326 } else { 327 TypeMappingDelegate del = 332 (TypeMappingDelegate) mapTM.get(Constants.URI_SOAP11_ENC); 333 while (del.getNext() != null && ! (del.delegate instanceof DefaultTypeMappingImpl)) { 334 del = del.getNext(); 335 } 336 del.setNext(defaultDelTM); 337 } 338 339 if (!mapTM.containsKey(Constants.URI_SOAP12_ENC)) { 340 mapTM.put(Constants.URI_SOAP12_ENC, mapping); 341 } else { 342 TypeMappingDelegate del = 347 (TypeMappingDelegate) mapTM.get(Constants.URI_SOAP12_ENC); 348 while (del.getNext() != null && ! (del.delegate instanceof DefaultTypeMappingImpl)) { 349 del = del.getNext(); 350 } 351 del.setNext(defaultDelTM); 352 } 353 354 mapping.setNext(defaultDelTM); 358 } 359 360 368 public javax.xml.rpc.encoding.TypeMapping 369 getTypeMapping(String namespaceURI) { 370 TypeMapping del = (TypeMappingDelegate) mapTM.get(namespaceURI); 372 if (del == null) { 373 del = (TypeMapping)getDefaultTypeMapping(); 374 } 375 return del; 376 } 377 378 386 public TypeMapping getOrMakeTypeMapping(String encodingStyle) { 387 TypeMappingDelegate del = (TypeMappingDelegate) mapTM.get(encodingStyle); 388 if (del == null || del.delegate instanceof DefaultTypeMappingImpl) { 389 del = (TypeMappingDelegate)createTypeMapping(); 390 del.setSupportedEncodings(new String [] {encodingStyle}); 391 register(encodingStyle, del); 392 } 393 return del; 394 } 395 396 402 public javax.xml.rpc.encoding.TypeMapping 403 unregisterTypeMapping(String namespaceURI) { 404 return (TypeMappingDelegate)mapTM.remove(namespaceURI); 405 } 406 407 413 public boolean removeTypeMapping( 414 javax.xml.rpc.encoding.TypeMapping mapping) { 415 String [] ns = getRegisteredEncodingStyleURIs(); 416 boolean rc = false; 417 for (int i=0; i < ns.length; i++) { 418 if (getTypeMapping(ns[i]) == mapping) { 419 rc = true; 420 unregisterTypeMapping(ns[i]); 421 } 422 } 423 return rc; 424 } 425 426 432 public javax.xml.rpc.encoding.TypeMapping createTypeMapping() { 433 TypeMappingImpl impl = new TypeMappingImpl(); 434 TypeMappingDelegate del = new TypeMappingDelegate(impl); 435 del.setNext(defaultDelTM); 436 return del; 437 } 438 439 440 445 public String [] getRegisteredEncodingStyleURIs() { 446 java.util.Set s = mapTM.keySet(); 447 if (s != null) { 448 String [] rc = new String [s.size()]; 449 int i = 0; 450 java.util.Iterator it = s.iterator(); 451 while(it.hasNext()) { 452 rc[i++] = (String ) it.next(); 453 } 454 return rc; 455 } 456 return null; 457 } 458 459 460 463 public void clear() { 464 mapTM.clear(); 465 } 466 467 471 public javax.xml.rpc.encoding.TypeMapping getDefaultTypeMapping() { 472 return defaultDelTM; 473 } 474 475 } 476 | Popular Tags |