View Javadoc

1   /*
2    * Copyright [2006] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.xml.encryption.impl;
18  
19  import java.util.Map.Entry;
20  
21  import javax.xml.namespace.QName;
22  
23  import org.opensaml.xml.Configuration;
24  import org.opensaml.xml.XMLObject;
25  import org.opensaml.xml.encryption.EncryptionProperty;
26  import org.opensaml.xml.io.MarshallingException;
27  import org.opensaml.xml.util.XMLHelper;
28  import org.w3c.dom.Attr;
29  import org.w3c.dom.Element;
30  
31  /**
32   * A thread-safe Marshaller for {@link org.opensaml.xml.encryption.EncryptionProperty} objects.
33   */
34  public class EncryptionPropertyMarshaller extends AbstractXMLEncryptionMarshaller {
35  
36      /** {@inheritDoc} */
37      protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
38          EncryptionProperty ep = (EncryptionProperty) xmlObject;
39  
40          if (ep.getID() != null) {
41              domElement.setAttributeNS(null, EncryptionProperty.ID_ATTRIB_NAME, ep.getID());
42              domElement.setIdAttributeNS(null, EncryptionProperty.ID_ATTRIB_NAME, true);
43          }
44          if (ep.getTarget() != null) {
45              domElement.setAttributeNS(null, EncryptionProperty.TARGET_ATTRIB_NAME, ep.getTarget());
46          }
47  
48          Attr attribute;
49          for (Entry<QName, String> entry : ep.getUnknownAttributes().entrySet()) {
50              attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
51              attribute.setValue(entry.getValue());
52              domElement.setAttributeNodeNS(attribute);
53              if (Configuration.isIDAttribute(entry.getKey()) || ep.getUnknownAttributes().isIDAttribute(entry.getKey())) {
54                  attribute.getOwnerElement().setIdAttributeNode(attribute, true);
55              }
56          }
57      }
58  
59  }