View Javadoc

1   /*
2    * Copyright 2008 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.xacml.ctx.impl;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.opensaml.xacml.ctx.ResourceContentType;
22  import org.opensaml.xml.XMLObject;
23  import org.opensaml.xml.io.AbstractXMLObjectUnmarshaller;
24  import org.opensaml.xml.io.UnmarshallingException;
25  import org.opensaml.xml.util.DatatypeHelper;
26  import org.opensaml.xml.util.XMLHelper;
27  import org.w3c.dom.Attr;
28  
29  /** Unmarshaller for {@link ResourceContentType} objects. */
30  public class ResourceContentTypeUnmarshaller extends AbstractXMLObjectUnmarshaller {
31  
32      /** Constructor. */
33      public ResourceContentTypeUnmarshaller() {
34          super();
35      }
36  
37      /**
38       * Constructor.
39       * 
40       * @param targetNamespaceURI the namespace URI of either the schema type QName or element QName of the elements this
41       *            unmarshaller operates on
42       * @param targetLocalName the local name of either the schema type QName or element QName of the elements this
43       *            unmarshaller operates on
44       */
45      protected ResourceContentTypeUnmarshaller(String targetNamespaceURI, String targetLocalName) {
46          super(targetNamespaceURI, targetLocalName);
47      }
48  
49      /** {@inheritDoc} */
50      protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
51          ResourceContentType resourceContent = (ResourceContentType) xmlObject;
52  
53          QName attribQName = XMLHelper.getNodeQName(attribute);
54          if (attribute.isId()) {
55              resourceContent.getUnknownAttributes().registerID(attribQName);
56          }
57          resourceContent.getUnknownAttributes().put(attribQName, attribute.getValue());
58      }
59  
60      /** {@inheritDoc} */
61      protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject)
62              throws UnmarshallingException {
63          ResourceContentType resourceContent = (ResourceContentType) parentXMLObject;
64          resourceContent.getUnknownXMLObjects().add(childXMLObject);
65      }
66  
67      /** {@inheritDoc} */
68      protected void processElementContent(XMLObject xmlObject, String elementContent) {
69          ResourceContentType resourceContent = (ResourceContentType) xmlObject;
70          resourceContent.setValue(DatatypeHelper.safeTrimOrNullString(elementContent));
71      }
72  }