1 55 56 package org.jboss.axis.encoding; 57 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.utils.Messages; 60 61 import java.util.HashMap ; 62 63 167 public class TypeMappingRegistryImpl implements TypeMappingRegistry 168 { 169 170 private HashMap mapTM; private TypeMapping defaultDelTM; 173 174 177 public TypeMappingRegistryImpl() 178 { 179 mapTM = new HashMap (); 180 if (Constants.URI_DEFAULT_SOAP_ENC.equals(Constants.URI_SOAP11_ENC)) 181 { 182 defaultDelTM = 183 new TypeMappingImpl(DefaultTypeMappingImpl.getSingleton()); 184 } 185 else 186 { 187 defaultDelTM = 188 new TypeMappingImpl(DefaultSOAPEncodingTypeMappingImpl.create()); 189 } 190 } 191 192 198 public void delegate(TypeMappingRegistry secondaryTMR) 199 { 200 201 if (secondaryTMR == null || secondaryTMR == this) 202 { 203 return; 204 } 205 String [] keys = secondaryTMR.getRegisteredEncodingStyleURIs(); 206 if (keys != null) 208 { 209 for (int i = 0; i < keys.length; i++) 210 { 211 try 212 { 213 String nsURI = keys[i]; 214 TypeMapping tm = (TypeMapping)getTypeMapping(nsURI); 215 if (tm == null || tm == getDefaultTypeMapping()) 216 { 217 tm = (TypeMapping)createTypeMapping(); 218 tm.setSupportedEncodings(new String []{nsURI}); 219 register(nsURI, tm); 220 } 221 222 if (tm != null) 223 { 224 TypeMapping del = (TypeMapping) 226 ((TypeMappingRegistryImpl) 227 secondaryTMR).mapTM.get(nsURI); 228 tm.setDelegate(del); 229 } 230 231 } 232 catch (Exception e) 233 { 234 } 235 } 236 } 237 if (defaultDelTM != null) 240 { 241 defaultDelTM.setDelegate(((TypeMappingRegistryImpl)secondaryTMR).defaultDelTM); 242 } 243 244 } 245 246 247 248 249 250 261 public javax.xml.rpc.encoding.TypeMapping register(String namespaceURI, 262 javax.xml.rpc.encoding.TypeMapping mapping) 263 { 264 if (mapping == null || 266 !(mapping instanceof TypeMapping)) 267 { 268 throw new IllegalArgumentException (Messages.getMessage("badTypeMapping")); 269 } 270 if (namespaceURI == null) 271 { 272 throw new java.lang.IllegalArgumentException (Messages.getMessage("nullNamespaceURI")); 273 } 274 TypeMappingDelegate del = (TypeMappingDelegate) 277 mapTM.get(namespaceURI); 278 if (del == null) 279 { 280 del = new TypeMappingDelegate((TypeMapping)mapping); 281 mapTM.put(namespaceURI, del); 282 } 283 else 284 { 285 del.setDelegate((TypeMapping)mapping); 286 } 287 return null; } 289 290 299 public void registerDefault(javax.xml.rpc.encoding.TypeMapping mapping) 300 { 301 if (mapping == null || 302 !(mapping instanceof TypeMapping)) 303 { 304 throw new IllegalArgumentException (Messages.getMessage("badTypeMapping")); 305 } 306 307 311 if (defaultDelTM.getDelegate() instanceof TypeMappingDelegate) 312 { 313 throw new IllegalArgumentException (Messages.getMessage("defaultTypeMappingSet")); 314 } 315 316 defaultDelTM.setDelegate((TypeMapping)mapping); 317 } 318 319 327 public javax.xml.rpc.encoding.TypeMapping 328 getTypeMapping(String namespaceURI) 329 { 330 TypeMapping del = (TypeMapping)mapTM.get(namespaceURI); 332 TypeMapping tm = null; 333 if (del != null) 334 { 335 tm = del.getDelegate(); 336 } 337 if (tm == null) 338 { 339 tm = (TypeMapping)getDefaultTypeMapping(); 340 } 341 return tm; 342 } 343 344 352 public TypeMapping getOrMakeTypeMapping(String encodingStyle) 353 { 354 TypeMapping del = (TypeMapping)mapTM.get(encodingStyle); 355 TypeMapping tm = null; 356 if (del != null) 357 { 358 tm = del.getDelegate(); 359 } 360 if (tm == null) 361 { 362 tm = (TypeMapping)createTypeMapping(); 363 tm.setSupportedEncodings(new String []{encodingStyle}); 364 register(encodingStyle, tm); 365 } 366 return tm; 367 } 368 369 375 public javax.xml.rpc.encoding.TypeMapping 376 unregisterTypeMapping(String namespaceURI) 377 { 378 TypeMapping del = (TypeMapping)mapTM.get(namespaceURI); 379 TypeMapping tm = null; 380 if (del != null) 381 { 382 tm = del.getDelegate(); 383 del.setDelegate(null); 384 } 385 return tm; 386 } 387 388 394 public boolean removeTypeMapping(javax.xml.rpc.encoding.TypeMapping mapping) 395 { 396 String [] ns = getRegisteredEncodingStyleURIs(); 397 boolean rc = false; 398 for (int i = 0; i < ns.length; i++) 399 { 400 if (getTypeMapping(ns[i]) == mapping) 401 { 402 rc = true; 403 unregisterTypeMapping(ns[i]); 404 } 405 } 406 return rc; 407 } 408 409 415 public javax.xml.rpc.encoding.TypeMapping createTypeMapping() 416 { 417 return new TypeMappingImpl(defaultDelTM); 418 } 419 420 421 426 public String [] getRegisteredEncodingStyleURIs() 427 { 428 java.util.Set s = mapTM.keySet(); 429 if (s != null) 430 { 431 String [] rc = new String [s.size()]; 432 int i = 0; 433 java.util.Iterator it = s.iterator(); 434 while (it.hasNext()) 435 { 436 rc[i++] = (String )it.next(); 437 } 438 return rc; 439 } 440 return null; 441 } 442 443 444 447 public void clear() 448 { 449 mapTM.clear(); 450 } 451 452 457 public javax.xml.rpc.encoding.TypeMapping getDefaultTypeMapping() 458 { 459 TypeMapping defaultTM = defaultDelTM; 460 while (defaultTM != null && defaultTM instanceof TypeMappingDelegate) 461 { 462 defaultTM = defaultTM.getDelegate(); 463 } 464 return defaultTM; 465 } 466 467 } 468 | Popular Tags |