FileDocCategorySizeDatePackage
TypeMappingRegistryImpl.javaAPI DocApache Axis 1.416589Sat Apr 22 18:57:28 BST 2006org.apache.axis.encoding

TypeMappingRegistryImpl

public class TypeMappingRegistryImpl extends Object implements TypeMappingRegistry

The TypeMappingRegistry keeps track of the individual TypeMappings.

The TypeMappingRegistry for axis contains a default type mapping that is set for either SOAP 1.1 or SOAP 1.2 The default type mapping is a singleton used for the entire runtime and should not have anything new registered in it.

Instead the new TypeMappings for the deploy and service are made in a separate TypeMapping which is identified by the soap encoding. These new TypeMappings delegate back to the default type mapping when information is not found.

So logically we have:

TMR
| |
| +---------------> DefaultTM
| ^
| |
+----> TM --delegate---+
But in the implementation, the TMR references "delegate" TypeMappings (TM') which then reference the actual TM's

So the picture is really:

TMR
| |
| +-----------TM'------> DefaultTM
| ^
| |
+-TM'-> TM ----+
This extra indirection is necessary because the user may want to change the default type mapping. In such cases, the TMR just needs to adjust the TM' for the DefaultTM, and all of the other TMs will properly delegate to the new one. Here's the picture:
TMR
| |
| +-----------TM'--+ DefaultTM
| ^ |
| | +---> New User Defined Default TM
+-TM'-> TM ----+
The other reason that it is necessary is when a deploy has a TMR, and then TMR's are defined for the individual services in such cases the delegate() method is invoked on the service to delegate to the deploy TMR
Deploy TMR
| |
| +-----------TM'------> DefaultTM
| ^
| |
+-TM'-> TM ----+

Service TMR
| |
| +-----------TM'------> DefaultTM
| ^
| |
+-TM'-> TM ----+

ServiceTMR.delegate(DeployTMR)

Deploy TMR
| |
| +------------TM'------> DefaultTM
| ^ ^
| | |
+-TM'-> TM ----+ |
^ |
+-------+ |
| |
| Service TMR |
| | | |
| | +----------TM'-+
| |
| |
| +-TM'-> TM +
| |
+----------------+
So now the service uses the DefaultTM of the Deploy TMR, and the Service TM properly delegates to the deploy's TM. And if either the deploy defaultTM or TMs change, the links are not broken.

author
James Snell (jasnell@us.ibm.com)
author
Sam Ruby (rubys@us.ibm.com) Re-written for JAX-RPC Compliance by
author
Rich Scheuerle (scheu@us.ibm.com

Fields Summary
private HashMap
mapTM
private TypeMappingDelegate
defaultDelTM
private boolean
isDelegated
Constructors Summary
public TypeMappingRegistryImpl(TypeMappingImpl tm)
Construct TypeMappingRegistry

param
tm


              
       
        mapTM = new HashMap();
        defaultDelTM = new TypeMappingDelegate(tm);
//        TypeMappingDelegate del = new TypeMappingDelegate(new DefaultSOAPEncodingTypeMappingImpl());
//        register(Constants.URI_SOAP11_ENC, del);
    
public TypeMappingRegistryImpl()
Construct TypeMappingRegistry

        this(true);
    
public TypeMappingRegistryImpl(boolean registerDefaults)

        mapTM = new HashMap();
        if (registerDefaults) {
            defaultDelTM = DefaultTypeMappingImpl.getSingletonDelegate();
            TypeMappingDelegate del = new TypeMappingDelegate(new DefaultSOAPEncodingTypeMappingImpl());
            register(Constants.URI_SOAP11_ENC, del);
        } else {
            defaultDelTM = new TypeMappingDelegate(TypeMappingDelegate.placeholder);
        }
    
Methods Summary
public voidclear()
Removes all TypeMappings and namespaceURIs from this TypeMappingRegistry.

        mapTM.clear();
    
public javax.xml.rpc.encoding.TypeMappingcreateTypeMapping()
Creates a new empty TypeMapping object for the specified encoding style or XML schema namespace.

return
An empty generic TypeMapping object

        TypeMappingImpl impl = new TypeMappingImpl();
        TypeMappingDelegate del = new TypeMappingDelegate(impl);
        del.setNext(defaultDelTM);
        return del;
    
public voiddelegate(TypeMappingRegistry secondaryTMR)
delegate Changes the contained type mappings to delegate to their corresponding types in the secondary TMR.


        if (isDelegated || secondaryTMR == null || secondaryTMR == this) {
            return;
        }

        isDelegated = true;
        String[]  keys = secondaryTMR.getRegisteredEncodingStyleURIs();
        TypeMappingDelegate otherDefault =
                ((TypeMappingRegistryImpl)secondaryTMR).defaultDelTM;
        if (keys != null) {
            for (int i=0; i < keys.length; i++) {
                try {
                    String nsURI = keys[i];
                    TypeMappingDelegate tm = (TypeMappingDelegate) mapTM.get(nsURI);
                    if (tm == null) {
                        tm = (TypeMappingDelegate)createTypeMapping();
                        tm.setSupportedEncodings(new String[] { nsURI });
                        register(nsURI, tm);
                    }

                    if (tm != null) {
                        // Get the secondaryTMR's TM'
                        TypeMappingDelegate del = (TypeMappingDelegate)
                            ((TypeMappingRegistryImpl)secondaryTMR).mapTM.get(nsURI);

                        while (del.next != null) {
                            TypeMappingDelegate nu = new TypeMappingDelegate(del.delegate);
                            tm.setNext(nu);

                            if (del.next == otherDefault) {
                                nu.setNext(defaultDelTM);
                                break;
                            }
                            del = del.next;
                            tm = nu;
                        }
                    }

                } catch (Exception e) {
                }
            }
        }
        // Change our defaultDelTM to delegate to the one in 
        // the secondaryTMR
        if (defaultDelTM.delegate != TypeMappingDelegate.placeholder) {
            defaultDelTM.setNext(otherDefault);
        } else {
            defaultDelTM.delegate = otherDefault.delegate;
        }
        
    
public voiddoRegisterFromVersion(java.lang.String version)
Set up the default type mapping (and the SOAP encoding type mappings) as per the passed "version" option.

param
version

        if (version == null || version.equals("1.0") || version.equals("1.2")) {
            TypeMappingImpl.dotnet_soapenc_bugfix = false;
            // Do nothing, just register SOAPENC mapping
        } else if (version.equals("1.1")) {
            TypeMappingImpl.dotnet_soapenc_bugfix = true;
            // Do nothing, no SOAPENC mapping
            return;
        } else if (version.equals("1.3")) {
            // Reset the default TM to the JAXRPC version, then register SOAPENC
            defaultDelTM = new TypeMappingDelegate(
                    DefaultJAXRPC11TypeMappingImpl.getSingleton());
        } else {
            throw new RuntimeException(
                    Messages.getMessage("j2wBadTypeMapping00"));
        }
        registerSOAPENCDefault(
                new TypeMappingDelegate(DefaultSOAPEncodingTypeMappingImpl.
                                        getSingleton()));
    
public javax.xml.rpc.encoding.TypeMappinggetDefaultTypeMapping()
Return the default TypeMapping

return
TypeMapping or null

        return defaultDelTM;
    
public TypeMappinggetOrMakeTypeMapping(java.lang.String encodingStyle)
Obtain a type mapping for the given encodingStyle. If no specific mapping exists for this encodingStyle, we will create and register one before returning it.

param
encodingStyle
return
a registered TypeMapping for the given encodingStyle

        TypeMappingDelegate del = (TypeMappingDelegate) mapTM.get(encodingStyle);
        if (del == null || del.delegate instanceof DefaultTypeMappingImpl) {
            del = (TypeMappingDelegate)createTypeMapping();
            del.setSupportedEncodings(new String[] {encodingStyle});
            register(encodingStyle, del);
        }
        return del;
    
public java.lang.String[]getRegisteredEncodingStyleURIs()
Gets a list of namespace URIs registered with this TypeMappingRegistry.

return
String[] containing names of all registered namespace URIs

        java.util.Set s = mapTM.keySet(); 
        if (s != null) { 
            String[] rc = new String[s.size()];
            int i = 0;
            java.util.Iterator it = s.iterator();
            while(it.hasNext()) {
                rc[i++] = (String) it.next();
            }
            return rc;
        }
        return null;
    
public javax.xml.rpc.encoding.TypeMappinggetTypeMapping(java.lang.String namespaceURI)
Gets the TypeMapping for the namespace. If not found, the default TypeMapping is returned.

param
namespaceURI - The namespace URI of a Web Service
return
The registered TypeMapping (which may be the default TypeMapping) or null.

//        namespaceURI = "";
        TypeMapping del = (TypeMappingDelegate) mapTM.get(namespaceURI);
        if (del == null) {
            del = (TypeMapping)getDefaultTypeMapping();
        }
        return del;
    
public javax.xml.rpc.encoding.TypeMappingregister(java.lang.String namespaceURI, javax.xml.rpc.encoding.TypeMapping mapping)
The method register adds a TypeMapping instance for a specific namespace

param
namespaceURI
param
mapping - TypeMapping for specific namespaces
return
Previous TypeMapping associated with the specified namespaceURI, or null if there was no TypeMapping associated with the specified namespaceURI

//        namespaceURI = "";
        if (mapping == null || 
            !(mapping instanceof TypeMappingDelegate)) {
            throw new IllegalArgumentException(
                    Messages.getMessage("badTypeMapping"));
        } 
        if (namespaceURI == null) {
            throw new java.lang.IllegalArgumentException(
                    Messages.getMessage("nullNamespaceURI"));
        }

        TypeMappingDelegate del = (TypeMappingDelegate)mapping;
        TypeMappingDelegate old = (TypeMappingDelegate)mapTM.get(namespaceURI);
        if (old == null) {
            del.setNext(defaultDelTM);
        } else {
            del.setNext(old);
        }
        mapTM.put(namespaceURI, del);
        return old; // Needs works
    
public voidregisterDefault(javax.xml.rpc.encoding.TypeMapping mapping)
The method register adds a default TypeMapping instance. If a specific TypeMapping is not found, the default TypeMapping is used.

param
mapping - TypeMapping for specific type namespaces java.lang.IllegalArgumentException - if an invalid type mapping is specified or the delegate is already set

        if (mapping == null ||
            !(mapping instanceof TypeMappingDelegate)) {
            throw new IllegalArgumentException(
                    Messages.getMessage("badTypeMapping"));
        }

        /* Don't allow this call after the delegate() method since
         * the TMR's TypeMappings will be using the default type mapping
         * of the secondary TMR.
         */
        if (defaultDelTM.getNext() != null) {
            throw new IllegalArgumentException(
                    Messages.getMessage("defaultTypeMappingSet"));
        }

        defaultDelTM = (TypeMappingDelegate)mapping;
    
private voidregisterSOAPENCDefault(TypeMappingDelegate mapping)
Force registration of the given mapping as the SOAPENC default mapping

param
mapping

        // This get a bit ugly as we do not want to just overwrite
        // an existing type mapping for SOAP encodings.  This happens
        // when {client,server}-config.wsdd defines a type mapping for
        // instance.
        if (!mapTM.containsKey(Constants.URI_SOAP11_ENC)) {
            mapTM.put(Constants.URI_SOAP11_ENC, mapping);
        } else {
            // We have to make sure the default type mapping is
            // at the end of the chain.
            // This is important if the default is switched to
            // the JAX_RPC 1.1 default type mapping!
            TypeMappingDelegate del =
                    (TypeMappingDelegate) mapTM.get(Constants.URI_SOAP11_ENC);
            while (del.getNext() != null && ! (del.delegate instanceof DefaultTypeMappingImpl)) {
                del = del.getNext();
            }
            del.setNext(defaultDelTM);
        }

        if (!mapTM.containsKey(Constants.URI_SOAP12_ENC)) {
            mapTM.put(Constants.URI_SOAP12_ENC, mapping);
        } else {
            // We have to make sure the default type mapping is
            // at the end of the chain.
            // This is important if the default is switched to
            // the JAX_RPC 1.1 default type mapping!
            TypeMappingDelegate del =
                    (TypeMappingDelegate) mapTM.get(Constants.URI_SOAP12_ENC);
            while (del.getNext() != null && ! (del.delegate instanceof DefaultTypeMappingImpl)) {
                del = del.getNext();
            }
            del.setNext(defaultDelTM);
        }
        
        // Just do this unconditionally in case we used mapping.
        // This is important if the default is switched to
        // the JAX_RPC 1.1 default type mapping!
        mapping.setNext(defaultDelTM);
    
public booleanremoveTypeMapping(javax.xml.rpc.encoding.TypeMapping mapping)
Removes the TypeMapping for the namespace.

param
mapping The type mapping to remove
return
true if found and removed

        String[] ns = getRegisteredEncodingStyleURIs();
        boolean rc = false;
        for (int i=0; i < ns.length; i++) {
            if (getTypeMapping(ns[i]) == mapping) {
                rc = true;
                unregisterTypeMapping(ns[i]);
            }
        }
        return rc;
    
public javax.xml.rpc.encoding.TypeMappingunregisterTypeMapping(java.lang.String namespaceURI)
Unregisters the TypeMapping for the namespace.

param
namespaceURI - The namespace URI
return
The registered TypeMapping .

        return (TypeMappingDelegate)mapTM.remove(namespaceURI);