cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From owu...@apache.org
Subject svn commit: r1435858 - /cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java
Date Sun, 20 Jan 2013 14:49:25 GMT
Author: owulff
Date: Sun Jan 20 14:49:25 2013
New Revision: 1435858

URL: http://svn.apache.org/viewvc?rev=1435858&view=rev
Log:
Factories defined as private static final

Modified:
    cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java

Modified: cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java?rev=1435858&r1=1435857&r2=1435858&view=diff
==============================================================================
--- cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java
(original)
+++ cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/metadata/MetadataWriter.java
Sun Jan 20 14:49:25 2013
@@ -78,16 +78,23 @@ import static org.apache.cxf.fediz.core.
 public class MetadataWriter {
     
     private static final Logger LOG = LoggerFactory.getLogger(MetadataWriter.class);
+    
+    private static final XMLOutputFactory XML_OUTPUT_FACTORY = XMLOutputFactory.newInstance();
+    private static final XMLSignatureFactory XML_SIGNATURE_FACTORY = XMLSignatureFactory.getInstance("DOM");
+    private static final DocumentBuilderFactory DOC_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
+    private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance();
+    
+    static {
+        DOC_BUILDER_FACTORY.setNamespaceAware(true);
+    }
 
     //CHECKSTYLE:OFF
     public Document getMetaData(FederationContext config) throws ProcessingException {
 
         try {
-            XMLOutputFactory factory = XMLOutputFactory.newInstance();
-
             ByteArrayOutputStream bout = new ByteArrayOutputStream(4096);
             Writer streamWriter = new OutputStreamWriter(bout);
-            XMLStreamWriter writer = factory.createXMLStreamWriter(streamWriter);
+            XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(streamWriter);
 
             Protocol protocol = config.getProtocol();
 
@@ -240,20 +247,16 @@ public class MetadataWriter {
         String keyAlias = keyManager.getKeyAlias();
         String keypass  = keyManager.getKeyPassword();  
         
-        // Create a DOM XMLSignatureFactory that will be used to
-        // generate the enveloped signature.
-        XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
-
         // Create a Reference to the enveloped document (in this case,
         // you are signing the whole document, so a URI of "" signifies
         // that, and also specify the SHA1 digest algorithm and
         // the ENVELOPED Transform.
-        Reference ref = fac.newReference("#" + referenceID, fac.newDigestMethod(DigestMethod.SHA1,
null), Collections
-            .singletonList(fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec)null)),
null, null);
+        Reference ref = XML_SIGNATURE_FACTORY.newReference("#" + referenceID, XML_SIGNATURE_FACTORY.newDigestMethod(DigestMethod.SHA1,
null), Collections
+            .singletonList(XML_SIGNATURE_FACTORY.newTransform(Transform.ENVELOPED, (TransformParameterSpec)null)),
null, null);
 
         // Create the SignedInfo.
-        SignedInfo si = fac.newSignedInfo(fac.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE,
-                                                                        (C14NMethodParameterSpec)null),
fac
+        SignedInfo si = XML_SIGNATURE_FACTORY.newSignedInfo(XML_SIGNATURE_FACTORY.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE,
+                                                                        (C14NMethodParameterSpec)null),
XML_SIGNATURE_FACTORY
             .newSignatureMethod(SignatureMethod.RSA_SHA1, null), Collections.singletonList(ref));
 
         // step 2
@@ -278,7 +281,7 @@ public class MetadataWriter {
         X509Certificate cert = issuerCerts[0];
         
         // Create the KeyInfo containing the X509Data.
-        KeyInfoFactory kif = fac.getKeyInfoFactory();
+        KeyInfoFactory kif = XML_SIGNATURE_FACTORY.getKeyInfoFactory();
         List<Object> x509Content = new ArrayList<Object>();
         x509Content.add(cert.getSubjectX500Principal().getName());
         x509Content.add(cert);
@@ -287,9 +290,7 @@ public class MetadataWriter {
 
         // step3
         // Instantiate the document to be signed.
-        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-        dbf.setNamespaceAware(true);
-        Document doc = dbf.newDocumentBuilder().parse(metaInfo);
+        Document doc = DOC_BUILDER_FACTORY.newDocumentBuilder().parse(metaInfo);
 
         // Create a DOMSignContext and specify the RSA PrivateKey and
         // location of the resulting XMLSignature's parent element.
@@ -299,7 +300,7 @@ public class MetadataWriter {
         dsc.setNextSibling(doc.getDocumentElement().getFirstChild());
 
         // Create the XMLSignature, but don't sign it yet.
-        XMLSignature signature = fac.newXMLSignature(si, ki);
+        XMLSignature signature = XML_SIGNATURE_FACTORY.newXMLSignature(si, ki);
 
         // Marshal, generate, and sign the enveloped signature.
         signature.sign(dsc);
@@ -308,8 +309,7 @@ public class MetadataWriter {
         // Output the resulting document.
 
         ByteArrayOutputStream os = new ByteArrayOutputStream(8192);
-        TransformerFactory tf = TransformerFactory.newInstance();
-        Transformer trans = tf.newTransformer();
+        Transformer trans = TRANSFORMER_FACTORY.newTransformer();
         trans.transform(new DOMSource(doc), new StreamResult(os));
         os.flush();
         return os;



Mime
View raw message