1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 1999-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 * 20 */ 21 package com.sun.org.apache.xml.internal.security.transforms; 22 23 import java.io.IOException; 24 import java.io.OutputStream; 25 import javax.xml.parsers.ParserConfigurationException; 26 27 import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException; 28 import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException; 29 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; 30 import org.xml.sax.SAXException; 31 32 /** 33 * Base class which all Transform algorithms extend. The common methods that 34 * have to be overridden are the 35 * {@link #enginePerformTransform(XMLSignatureInput, Transform)} method. 36 * 37 * @author Christian Geuer-Pollmann 38 */ 39 public abstract class TransformSpi { 40 /** 41 * For API compatibility not thread safe. 42 * @deprecated 43 */ 44 @Deprecated 45 protected Transform _transformObject = null; 46 /** 47 * Set the transform object. 48 * Depeprecated For API compatibility. 49 * @param transform the Transform 50 * @deprecated 51 */ 52 @Deprecated 53 protected void setTransform(Transform transform) { 54 this._transformObject = transform; 55 } 56 /** 57 * The mega method which MUST be implemented by the Transformation Algorithm. 58 * 59 * @param input {@link XMLSignatureInput} as the input of transformation 60 * @param os where to output this transformation. 61 * @param _transformObject the Transform 62 * @return {@link XMLSignatureInput} as the result of transformation 63 * @throws CanonicalizationException 64 * @throws IOException 65 * @throws InvalidCanonicalizerException 66 * @throws ParserConfigurationException 67 * @throws SAXException 68 * @throws TransformationException 69 */ 70 protected XMLSignatureInput enginePerformTransform( 71 XMLSignatureInput input, OutputStream os, Transform _transformObject) 72 throws IOException, 73 CanonicalizationException, InvalidCanonicalizerException, 74 TransformationException, ParserConfigurationException, 75 SAXException { 76 return enginePerformTransform(input, _transformObject); 77 } 78 /** 79 * The mega method which MUST be implemented by the Transformation Algorithm. 80 * In order to be compatible with preexisting Transform implementations, 81 * by default this implementation invokes the deprecated, thread-unsafe 82 * methods. Subclasses should override this with a thread-safe 83 * implementation. 84 * 85 * @param input {@link XMLSignatureInput} as the input of transformation 86 * @param _transformObject the Transform 87 * @return {@link XMLSignatureInput} as the result of transformation 88 * @throws CanonicalizationException 89 * @throws IOException 90 * @throws InvalidCanonicalizerException 91 * @throws ParserConfigurationException 92 * @throws SAXException 93 * @throws TransformationException 94 */ 95 protected XMLSignatureInput enginePerformTransform( 96 XMLSignatureInput input, Transform _transformObject) 97 throws IOException, 98 CanonicalizationException, InvalidCanonicalizerException, 99 TransformationException, ParserConfigurationException, 100 SAXException { 101 //Default implementation overide with a much better 102 try { 103 TransformSpi tmp = (TransformSpi) getClass().newInstance(); 104 tmp.setTransform(_transformObject); 105 return tmp.enginePerformTransform(input); 106 } catch (InstantiationException e) { 107 throw new TransformationException("",e); 108 } catch (IllegalAccessException e) { 109 throw new TransformationException("",e); 110 } 111 } 112 113 /** 114 * The mega method which MUST be implemented by the Transformation Algorithm. 115 * @deprecated 116 * @param input {@link XMLSignatureInput} as the input of transformation 117 * @return {@link XMLSignatureInput} as the result of transformation 118 * @throws CanonicalizationException 119 * @throws IOException 120 * @throws InvalidCanonicalizerException 121 * @throws ParserConfigurationException 122 * @throws SAXException 123 * @throws TransformationException 124 */ 125 @Deprecated 126 protected XMLSignatureInput enginePerformTransform( 127 XMLSignatureInput input) 128 throws IOException, 129 CanonicalizationException, InvalidCanonicalizerException, 130 TransformationException, ParserConfigurationException, 131 SAXException { 132 throw new UnsupportedOperationException(); 133 } 134 /** 135 * Returns the URI representation of <code>Transformation algorithm</code> 136 * 137 * @return the URI representation of <code>Transformation algorithm</code> 138 */ 139 protected abstract String engineGetURI(); 140 } | 1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /** 6 * Licensed to the Apache Software Foundation (ASF) under one 7 * or more contributor license agreements. See the NOTICE file 8 * distributed with this work for additional information 9 * regarding copyright ownership. The ASF licenses this file 10 * to you under the Apache License, Version 2.0 (the 11 * "License"); you may not use this file except in compliance 12 * with the License. You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, 17 * software distributed under the License is distributed on an 18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 * KIND, either express or implied. See the License for the 20 * specific language governing permissions and limitations 21 * under the License. 22 */ 23 package com.sun.org.apache.xml.internal.security.transforms; 24 25 import java.io.IOException; 26 import java.io.OutputStream; 27 import javax.xml.parsers.ParserConfigurationException; 28 29 import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException; 30 import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException; 31 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; 32 import org.xml.sax.SAXException; 33 34 /** 35 * Base class which all Transform algorithms extend. The common methods that 36 * have to be overridden are the 37 * {@link #enginePerformTransform(XMLSignatureInput, Transform)} method. 38 * 39 * @author Christian Geuer-Pollmann 40 */ 41 public abstract class TransformSpi { 42 43 /** 44 * The mega method which MUST be implemented by the Transformation Algorithm. 45 * 46 * @param input {@link XMLSignatureInput} as the input of transformation 47 * @param os where to output this transformation. 48 * @param transformObject the Transform object 49 * @return {@link XMLSignatureInput} as the result of transformation 50 * @throws CanonicalizationException 51 * @throws IOException 52 * @throws InvalidCanonicalizerException 53 * @throws ParserConfigurationException 54 * @throws SAXException 55 * @throws TransformationException 56 */ 57 protected XMLSignatureInput enginePerformTransform( 58 XMLSignatureInput input, OutputStream os, Transform transformObject 59 ) throws IOException, CanonicalizationException, InvalidCanonicalizerException, 60 TransformationException, ParserConfigurationException, SAXException { 61 throw new UnsupportedOperationException(); 62 } 63 64 /** 65 * The mega method which MUST be implemented by the Transformation Algorithm. 66 * In order to be compatible with preexisting Transform implementations, 67 * by default this implementation invokes the deprecated, thread-unsafe 68 * methods. Subclasses should override this with a thread-safe 69 * implementation. 70 * 71 * @param input {@link XMLSignatureInput} as the input of transformation 72 * @param transformObject the Transform object 73 * @return {@link XMLSignatureInput} as the result of transformation 74 * @throws CanonicalizationException 75 * @throws IOException 76 * @throws InvalidCanonicalizerException 77 * @throws ParserConfigurationException 78 * @throws SAXException 79 * @throws TransformationException 80 */ 81 protected XMLSignatureInput enginePerformTransform( 82 XMLSignatureInput input, Transform transformObject 83 ) throws IOException, CanonicalizationException, InvalidCanonicalizerException, 84 TransformationException, ParserConfigurationException, SAXException { 85 return enginePerformTransform(input, null, transformObject); 86 } 87 88 /** 89 * The mega method which MUST be implemented by the Transformation Algorithm. 90 * @param input {@link XMLSignatureInput} as the input of transformation 91 * @return {@link XMLSignatureInput} as the result of transformation 92 * @throws CanonicalizationException 93 * @throws IOException 94 * @throws InvalidCanonicalizerException 95 * @throws ParserConfigurationException 96 * @throws SAXException 97 * @throws TransformationException 98 */ 99 protected XMLSignatureInput enginePerformTransform( 100 XMLSignatureInput input 101 ) throws IOException, CanonicalizationException, InvalidCanonicalizerException, 102 TransformationException, ParserConfigurationException, SAXException { 103 return enginePerformTransform(input, null); 104 } 105 106 /** 107 * Returns the URI representation of <code>Transformation algorithm</code> 108 * 109 * @return the URI representation of <code>Transformation algorithm</code> 110 */ 111 protected abstract String engineGetURI(); 112 } |