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;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.opensaml.xml.util.XMLHelper;
22  import org.w3c.dom.Element;
23  
24  /**
25   * Base implementation for XMLObject builders.
26   * 
27   * <strong>Note:</strong> This class only works with {@link org.opensaml.xml.AbstractXMLObject}s
28   * 
29   * @param <XMLObjectType> the XMLObject type that this builder produces
30   */
31  public abstract class AbstractXMLObjectBuilder<XMLObjectType extends XMLObject> implements
32          XMLObjectBuilder<XMLObjectType> {
33  
34      /** {@inheritDoc} */
35      public XMLObjectType buildObject(QName objectName){
36          return buildObject(objectName.getNamespaceURI(), objectName.getLocalPart(), objectName.getPrefix());
37      }
38      
39      /** {@inheritDoc} */
40      public XMLObjectType buildObject(QName objectName, QName schemaType){
41          return buildObject(objectName.getNamespaceURI(), objectName.getLocalPart(), objectName.getPrefix(), schemaType);
42      }
43      
44      /** {@inheritDoc} */
45      public abstract XMLObjectType buildObject(String namespaceURI, String localName, String namespacePrefix);
46  
47      /** {@inheritDoc} */
48      public XMLObjectType buildObject(String namespaceURI, String localName, String namespacePrefix, QName schemaType) {
49          XMLObjectType xmlObject;
50  
51          xmlObject = buildObject(namespaceURI, localName, namespacePrefix);
52          ((AbstractXMLObject) xmlObject).setSchemaType(schemaType);
53  
54          return xmlObject;
55      }
56  
57      /** {@inheritDoc} */
58      public XMLObjectType buildObject(Element element) {
59          XMLObjectType xmlObject;
60  
61          String localName = element.getLocalName();
62          String nsURI = element.getNamespaceURI();
63          String nsPrefix = element.getPrefix();
64          QName schemaType = XMLHelper.getXSIType(element);
65  
66          xmlObject = buildObject(nsURI, localName, nsPrefix, schemaType);
67  
68          return xmlObject;
69      }
70  }