View Javadoc

1   /*
2    * Copyright [2005] [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.saml2.core.impl;
18  
19  import org.opensaml.common.impl.AbstractSAMLObjectMarshaller;
20  import org.opensaml.saml2.core.NameID;
21  import org.opensaml.saml2.core.NameIDType;
22  import org.opensaml.xml.XMLObject;
23  import org.opensaml.xml.io.MarshallingException;
24  import org.opensaml.xml.util.XMLHelper;
25  import org.w3c.dom.Element;
26  
27  /**
28   * A thread safe Marshaller for {@link org.opensaml.saml2.core.NameIDType} objects.
29   */
30  public abstract class AbstractNameIDTypeMarshaller extends AbstractSAMLObjectMarshaller {
31  
32      /** {@inheritDoc} */
33      protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
34          NameIDType nameID = (NameIDType) samlObject;
35  
36          if (nameID.getNameQualifier() != null) {
37              domElement.setAttributeNS(null, NameID.NAME_QUALIFIER_ATTRIB_NAME, nameID.getNameQualifier());
38          }
39  
40          if (nameID.getSPNameQualifier() != null) {
41              domElement.setAttributeNS(null, NameID.SP_NAME_QUALIFIER_ATTRIB_NAME, nameID.getSPNameQualifier());
42          }
43  
44          if (nameID.getFormat() != null) {
45              domElement.setAttributeNS(null, NameID.FORMAT_ATTRIB_NAME, nameID.getFormat());
46          }
47  
48          if (nameID.getSPProvidedID() != null) {
49              domElement.setAttributeNS(null, NameID.SPPROVIDED_ID_ATTRIB_NAME, nameID.getSPProvidedID());
50          }
51      }
52  
53      /** {@inheritDoc} */
54      protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException {
55          NameIDType nameID = (NameIDType) samlObject;
56          XMLHelper.appendTextContent(domElement, nameID.getValue());
57      }
58  }