FileDocCategorySizeDatePackage
Transform.javaAPI DocJava SE 6 API14304Tue Jun 10 00:23:04 BST 2008com.sun.org.apache.xml.internal.security.transforms

Transform

public final class Transform extends SignatureElementProxy
Implements the behaviour of the ds:Transform element. This Transform(Factory) class role as the Factory and Proxy of implemanting class that have the functionality of a Transform algorithm. Implements the Factory and Proxy pattern for ds:Transform algorithms.
author
Christian Geuer-Pollmann
see
Transforms
see
TransformSpi

Fields Summary
static Logger
log
{@link java.util.logging} logging facility
static boolean
_alreadyInitialized
Field _alreadyInitialized
static HashMap
_transformHash
All available Transform classes are registered here
protected TransformSpi
transformSpi
Field transformSpi
Constructors Summary
public Transform(Document doc, String algorithmURI, NodeList contextNodes)
Constructs {@link Transform}

param
doc the {@link Document} in which Transform will be placed
param
algorithmURI URI representation of Transform algorithm will be specified as parameter of {@link #getInstance(Document, String)}, when generate.
param
contextNodes the child node list of Transform element
throws
InvalidTransformException


                                                     
         
             

      super(doc);

      try {
         this._constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM,
                                                algorithmURI);

         Class implementingClass =
            Transform.getImplementingClass(algorithmURI);
		 
         if(implementingClass == null) {
             Object exArgs[] = { algorithmURI };

             throw new InvalidTransformException(
                "signature.Transform.UnknownTransform", exArgs);
         }
         if (true) {
         	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
                   + implementingClass + "\"");
         	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "The NodeList is " + contextNodes);
         }

         // create the custom Transform object
         this.transformSpi =
            (TransformSpi) implementingClass.newInstance();

         this.transformSpi.setTransform(this);

         // give it to the current document
         if (contextNodes != null) {
            /*
            while (contextNodes.getLength() > 0) {
               this._constructionElement.appendChild(contextNodes.item(0));
            }
            */

            for (int i = 0; i < contextNodes.getLength(); i++) {
               this._constructionElement.appendChild(contextNodes.item(i).cloneNode(true));
            }

         }
      } catch (IllegalAccessException ex) {
         Object exArgs[] = { algorithmURI };

         throw new InvalidTransformException(
            "signature.Transform.UnknownTransform", exArgs, ex);
      } catch (InstantiationException ex) {
         Object exArgs[] = { algorithmURI };

         throw new InvalidTransformException(
            "signature.Transform.UnknownTransform", exArgs, ex);
      }
   
public Transform(Element element, String BaseURI)
This constructor can only be called from the {@link Transforms} object, so it's protected.

param
element ds:Transform element
param
BaseURI the URI of the resource where the XML instance was stored
throws
InvalidTransformException
throws
TransformationException
throws
XMLSecurityException


      super(element, BaseURI);

      // retrieve Algorithm Attribute from ds:Transform
      String AlgorithmURI = element.getAttributeNS(null, Constants._ATT_ALGORITHM);

      if ((AlgorithmURI == null) || (AlgorithmURI.length() == 0)) {
         Object exArgs[] = { Constants._ATT_ALGORITHM,
                             Constants._TAG_TRANSFORM };

         throw new TransformationException("xml.WrongContent", exArgs);
      }

      try {
         Class implementingClass = (Class) _transformHash.get(AlgorithmURI);		 
         this.transformSpi =
            (TransformSpi) implementingClass.newInstance();

         this.transformSpi.setTransform(this);
      } catch (IllegalAccessException e) {
         Object exArgs[] = { AlgorithmURI };

         throw new InvalidTransformException(
            "signature.Transform.UnknownTransform", exArgs);
      } catch (InstantiationException e) {
         Object exArgs[] = { AlgorithmURI };

         throw new InvalidTransformException(
            "signature.Transform.UnknownTransform", exArgs);
      } catch (NullPointerException e) {
		  Object exArgs[] = { AlgorithmURI };

	         throw new InvalidTransformException(
	            "signature.Transform.UnknownTransform", exArgs);
	}
   
Methods Summary
public java.lang.StringgetBaseLocalName()

inheritDoc

      return Constants._TAG_TRANSFORM;
   
private static java.lang.ClassgetImplementingClass(java.lang.String URI)
Method getImplementingClass

param
URI
return
The name of the class implementing the URI.

       return (Class)Transform._transformHash.get(URI);
   
public static final com.sun.org.apache.xml.internal.security.transforms.TransformgetInstance(org.w3c.dom.Document doc, java.lang.String algorithmURI)
Generates a Transform object that implements the specified Transform algorithm URI.

param
algorithmURI Transform algorithm URI representation, such as specified in Transform algorithm
param
doc the proxy {@link Document}
return
{@link Transform} object
throws
InvalidTransformException

      return Transform.getInstance(doc, algorithmURI, (NodeList) null);
   
public static final com.sun.org.apache.xml.internal.security.transforms.TransformgetInstance(org.w3c.dom.Document doc, java.lang.String algorithmURI, org.w3c.dom.Element contextChild)
Generates a Transform object that implements the specified Transform algorithm URI.

param
algorithmURI Transform algorithm URI representation, such as specified in Transform algorithm
param
contextChild the child element of Transform element
param
doc the proxy {@link Document}
return
{@link Transform} object
throws
InvalidTransformException


      HelperNodeList contextNodes = new HelperNodeList();

      contextNodes.appendChild(doc.createTextNode("\n"));
      contextNodes.appendChild(contextChild);
      contextNodes.appendChild(doc.createTextNode("\n"));

      return Transform.getInstance(doc, algorithmURI, contextNodes);
   
public static final com.sun.org.apache.xml.internal.security.transforms.TransformgetInstance(org.w3c.dom.Document doc, java.lang.String algorithmURI, org.w3c.dom.NodeList contextNodes)
Generates a Transform object that implements the specified Transform algorithm URI.

param
algorithmURI Transform algorithm URI form, such as specified in Transform algorithm
param
contextNodes the child node list of Transform element
param
doc the proxy {@link Document}
return
{@link Transform} object
throws
InvalidTransformException

      return new Transform(doc, algorithmURI, contextNodes);
   
public final java.lang.StringgetURI()
Returns the URI representation of Transformation algorithm

return
the URI representation of Transformation algorithm

      return this._constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
   
public static voidinit()
Initalizes for this {@link Transform}


      if (!_alreadyInitialized) {
         _transformHash = new HashMap(10);
         _alreadyInitialized = true;
      }
   
public com.sun.org.apache.xml.internal.security.signature.XMLSignatureInputperformTransform(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput input, java.io.OutputStream os)
Transforms the input, and generats {@link XMLSignatureInput} as output.

param
input input {@link XMLSignatureInput} which can supplied Octect Stream and NodeSet as Input of Transformation
param
os where to output the result of the last transformation
return
the {@link XMLSignatureInput} class as the result of transformation
throws
CanonicalizationException
throws
IOException
throws
InvalidCanonicalizerException
throws
TransformationException


   	    XMLSignatureInput result = null;

   	    try {
   	    	result = transformSpi.enginePerformTransform(input,os);
   	    } catch (ParserConfigurationException ex) {
   	    	Object exArgs[] = { this.getURI(), "ParserConfigurationException" };

   	    	throw new CanonicalizationException(
   	    			"signature.Transform.ErrorDuringTransform", exArgs, ex);
   	    } catch (SAXException ex) {
   	    	Object exArgs[] = { this.getURI(), "SAXException" };

   	    	throw new CanonicalizationException(
   	    			"signature.Transform.ErrorDuringTransform", exArgs, ex);
   	    }

   	    return result;
   
public com.sun.org.apache.xml.internal.security.signature.XMLSignatureInputperformTransform(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput input)
Transforms the input, and generats {@link XMLSignatureInput} as output.

param
input input {@link XMLSignatureInput} which can supplied Octect Stream and NodeSet as Input of Transformation
return
the {@link XMLSignatureInput} class as the result of transformation
throws
CanonicalizationException
throws
IOException
throws
InvalidCanonicalizerException
throws
TransformationException


      XMLSignatureInput result = null;

      try {
         result = transformSpi.enginePerformTransform(input);
      } catch (ParserConfigurationException ex) {
         Object exArgs[] = { this.getURI(), "ParserConfigurationException" };

         throw new CanonicalizationException(
            "signature.Transform.ErrorDuringTransform", exArgs, ex);
      } catch (SAXException ex) {
         Object exArgs[] = { this.getURI(), "SAXException" };

         throw new CanonicalizationException(
            "signature.Transform.ErrorDuringTransform", exArgs, ex);
      }

      return result;
   
public static voidregister(java.lang.String algorithmURI, java.lang.String implementingClass)
Registers implementing class of the Transform algorithm with algorithmURI

param
algorithmURI algorithmURI URI representation of Transform algorithm will be specified as parameter of {@link #getInstance(Document, String)}, when generate.
param
implementingClass implementingClass the implementing class of {@link TransformSpi}
throws
AlgorithmAlreadyRegisteredException if specified algorithmURI is already registered


      {

         // are we already registered?
         Class registeredClass = Transform.getImplementingClass(algorithmURI);

         if ((registeredClass != null) ) {
            Object exArgs[] = { algorithmURI, registeredClass };

            throw new AlgorithmAlreadyRegisteredException(
               "algorithm.alreadyRegistered", exArgs);
         }

	 ClassLoader cl = (ClassLoader) AccessController.doPrivileged(
             new PrivilegedAction() {
                 public Object run() {
                     return Thread.currentThread().getContextClassLoader();
                 }
             });

         try {
	     Transform._transformHash.put 
                 (algorithmURI, Class.forName(implementingClass, true, cl)); 
	 } catch (ClassNotFoundException e) {
	     // TODO Auto-generated catch block
	     e.printStackTrace();
	 }
      }