View Javadoc

1   /*
2    * Copyright [2007] [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 edu.internet2.middleware.shibboleth.common.xmlobject.impl;
18  
19  import org.opensaml.xml.XMLObject;
20  import org.opensaml.xml.io.AbstractXMLObjectMarshaller;
21  import org.opensaml.xml.io.MarshallingException;
22  import org.opensaml.xml.util.XMLHelper;
23  import org.w3c.dom.Element;
24  
25  import edu.internet2.middleware.shibboleth.common.ShibbolethConstants;
26  import edu.internet2.middleware.shibboleth.common.xmlobject.ShibbolethMetadataScope;
27  
28  /**
29   * A thread-safe Marshaller for {@link ShibbolethMetadataScope}.
30   */
31  public class ShibbolethMetadataScopeMarshaller extends AbstractXMLObjectMarshaller {
32      
33      /** Constructor. */
34      public ShibbolethMetadataScopeMarshaller() {
35          super(ShibbolethConstants.SHIB_MDEXT10_NS, ShibbolethMetadataScope.DEFAULT_ELEMENT_LOCAL_NAME);
36      }
37  
38      /**
39       * Constructor.
40       * 
41       * @param namespaceURI the namespace URI
42       * @param elementLocalName the element local name
43       */
44      protected ShibbolethMetadataScopeMarshaller(String namespaceURI, String elementLocalName) {
45          super(namespaceURI, elementLocalName);
46      }
47  
48      /** {@inheritDoc} */
49      protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
50          ShibbolethMetadataScope scope = (ShibbolethMetadataScope) xmlObject;
51          
52          if (scope.getRegexpXSBoolean() != null) {
53              domElement.setAttributeNS(null, ShibbolethMetadataScope.REGEXP_ATTRIB_NAME,
54                      scope.getRegexpXSBoolean().toString());
55          }
56  
57      }
58  
59      /** {@inheritDoc} */
60      protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException {
61          ShibbolethMetadataScope shibMDScope = (ShibbolethMetadataScope) xmlObject;
62          
63          XMLHelper.appendTextContent(domElement, shibMDScope.getValue());
64      }
65  
66  }