View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.common.xmlobject.impl;
19  
20  import javax.xml.namespace.QName;
21  
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.signature.KeyInfo;
26  import org.opensaml.xml.util.XMLHelper;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  import org.w3c.dom.Attr;
30  
31  import edu.internet2.middleware.shibboleth.common.xmlobject.ShibbolethMetadataKeyAuthority;
32  
33  /**
34   * A thread-safe Unmarshaller for {@link ShibbolethMetadataKeyAuthority}.
35   */
36  public class ShibbolethMetadataKeyAuthorityUnmarshaller extends AbstractXMLObjectUnmarshaller {
37      
38      /** Logger. */
39      private final Logger log = LoggerFactory.getLogger(ShibbolethMetadataKeyAuthorityUnmarshaller.class);
40  
41      /** {@inheritDoc} */
42      protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
43          ShibbolethMetadataKeyAuthority authority = (ShibbolethMetadataKeyAuthority) xmlObject;
44          
45          if (attribute.getLocalName().equals(ShibbolethMetadataKeyAuthority.VERIFY_DEPTH_ATTRIB_NAME)) {
46              authority.setVerifyDepth(Integer.valueOf(attribute.getValue()));
47          } else {
48              QName attribQName = XMLHelper.getNodeQName(attribute);
49              if (attribute.isId()) {
50                 authority.getUnknownAttributes().registerID(attribQName);
51              }
52              authority.getUnknownAttributes().put(attribQName, attribute.getValue());
53          }
54  
55      }
56  
57      /** {@inheritDoc} */
58      protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject)
59              throws UnmarshallingException {
60          ShibbolethMetadataKeyAuthority authority = (ShibbolethMetadataKeyAuthority) parentXMLObject;
61          
62          if (childXMLObject instanceof KeyInfo) {
63              authority.getKeyInfos().add((KeyInfo) childXMLObject);
64          } else {
65              log.debug("Ignorning unknown child element {}", childXMLObject.getElementQName());
66          }
67  
68      }
69  
70      /** {@inheritDoc} */
71      protected void processElementContent(XMLObject xmlObject, String elementContent) {
72          log.debug("Ignorning unsupported element text content");
73      }
74  }