src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/keys/content/KeyValue.java
changeset 50614 3810c9a2efa1
parent 47216 71c04702a3d5
child 54731 81de17a33575
--- a/src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/keys/content/KeyValue.java	Mon Jun 18 15:24:48 2018 -0700
+++ b/src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/keys/content/KeyValue.java	Tue Jun 19 08:06:35 2018 +0800
@@ -41,7 +41,6 @@
  * keys values represented as PCDATA or element types from an external
  * namespace.
  *
- * @author $Author: coheigea $
  */
 public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
 
@@ -54,9 +53,9 @@
     public KeyValue(Document doc, DSAKeyValue dsaKeyValue) {
         super(doc);
 
-        XMLUtils.addReturnToElement(this.constructionElement);
-        this.constructionElement.appendChild(dsaKeyValue.getElement());
-        XMLUtils.addReturnToElement(this.constructionElement);
+        addReturnToSelf();
+        appendSelf(dsaKeyValue);
+        addReturnToSelf();
     }
 
     /**
@@ -68,9 +67,9 @@
     public KeyValue(Document doc, RSAKeyValue rsaKeyValue) {
         super(doc);
 
-        XMLUtils.addReturnToElement(this.constructionElement);
-        this.constructionElement.appendChild(rsaKeyValue.getElement());
-        XMLUtils.addReturnToElement(this.constructionElement);
+        addReturnToSelf();
+        appendSelf(rsaKeyValue);
+        addReturnToSelf();
     }
 
     /**
@@ -82,9 +81,9 @@
     public KeyValue(Document doc, Element unknownKeyValue) {
         super(doc);
 
-        XMLUtils.addReturnToElement(this.constructionElement);
-        this.constructionElement.appendChild(unknownKeyValue);
-        XMLUtils.addReturnToElement(this.constructionElement);
+        addReturnToSelf();
+        appendSelf(unknownKeyValue);
+        addReturnToSelf();
     }
 
     /**
@@ -96,18 +95,22 @@
     public KeyValue(Document doc, PublicKey pk) {
         super(doc);
 
-        XMLUtils.addReturnToElement(this.constructionElement);
+        addReturnToSelf();
 
         if (pk instanceof java.security.interfaces.DSAPublicKey) {
-            DSAKeyValue dsa = new DSAKeyValue(this.doc, pk);
+            DSAKeyValue dsa = new DSAKeyValue(getDocument(), pk);
 
-            this.constructionElement.appendChild(dsa.getElement());
-            XMLUtils.addReturnToElement(this.constructionElement);
+            appendSelf(dsa);
+            addReturnToSelf();
         } else if (pk instanceof java.security.interfaces.RSAPublicKey) {
-            RSAKeyValue rsa = new RSAKeyValue(this.doc, pk);
+            RSAKeyValue rsa = new RSAKeyValue(getDocument(), pk);
 
-            this.constructionElement.appendChild(rsa.getElement());
-            XMLUtils.addReturnToElement(this.constructionElement);
+            appendSelf(rsa);
+            addReturnToSelf();
+        } else {
+            String error = "The given PublicKey type " + pk + " is not supported. Only DSAPublicKey and "
+                + "RSAPublicKey types are currently supported";
+            throw new IllegalArgumentException(error);
         }
     }
 
@@ -115,11 +118,11 @@
      * Constructor KeyValue
      *
      * @param element
-     * @param BaseURI
+     * @param baseURI
      * @throws XMLSecurityException
      */
-    public KeyValue(Element element, String BaseURI) throws XMLSecurityException {
-        super(element, BaseURI);
+    public KeyValue(Element element, String baseURI) throws XMLSecurityException {
+        super(element, baseURI);
     }
 
     /**
@@ -131,7 +134,7 @@
     public PublicKey getPublicKey() throws XMLSecurityException {
         Element rsa =
             XMLUtils.selectDsNode(
-                this.constructionElement.getFirstChild(), Constants._TAG_RSAKEYVALUE, 0);
+                getFirstChild(), Constants._TAG_RSAKEYVALUE, 0);
 
         if (rsa != null) {
             RSAKeyValue kv = new RSAKeyValue(rsa, this.baseURI);
@@ -140,7 +143,7 @@
 
         Element dsa =
             XMLUtils.selectDsNode(
-                this.constructionElement.getFirstChild(), Constants._TAG_DSAKEYVALUE, 0);
+                getFirstChild(), Constants._TAG_DSAKEYVALUE, 0);
 
         if (dsa != null) {
             DSAKeyValue kv = new DSAKeyValue(dsa, this.baseURI);
@@ -150,7 +153,7 @@
         return null;
     }
 
-    /** @inheritDoc */
+    /** {@inheritDoc} */
     public String getBaseLocalName() {
         return Constants._TAG_KEYVALUE;
     }