View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.support.definition.support;
14  
15  import com.eviware.soapui.impl.support.AbstractInterface;
16  import com.eviware.soapui.impl.support.definition.DefinitionLoader;
17  import com.eviware.soapui.impl.wsdl.support.xsd.SchemaException;
18  import com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils;
19  import org.apache.xmlbeans.SchemaType;
20  import org.apache.xmlbeans.SchemaTypeLoader;
21  import org.apache.xmlbeans.SchemaTypeSystem;
22  import org.apache.xmlbeans.XmlBeans;
23  
24  import javax.xml.namespace.QName;
25  import java.util.Collection;
26  import java.util.HashSet;
27  import java.util.Set;
28  
29  public abstract class XmlSchemaBasedInterfaceDefinition<T extends AbstractInterface> extends AbstractInterfaceDefinition<T>
30  {
31     private SchemaTypeSystem schemaTypes;
32     private SchemaTypeLoader schemaTypeLoader;
33  
34     public XmlSchemaBasedInterfaceDefinition(T iface)
35     {
36        super(iface);
37     }
38  
39     public SchemaTypeLoader getSchemaTypeLoader()
40     {
41        return schemaTypeLoader;
42     }
43  
44     public SchemaTypeSystem getSchemaTypeSystem()
45     {
46        return schemaTypes;
47     }
48  
49     public boolean hasSchemaTypes()
50     {
51        return schemaTypes != null;
52     }
53  
54     public Collection<String> getDefinedNamespaces() throws Exception
55     {
56        Set<String> namespaces = new HashSet<String>();
57  
58        SchemaTypeSystem schemaTypes = getSchemaTypeSystem();
59        if (schemaTypes != null)
60        {
61           namespaces.addAll(SchemaUtils.extractNamespaces(getSchemaTypeSystem(), true));
62        }
63  
64        namespaces.add(getTargetNamespace());
65  
66        return namespaces;
67     }
68  
69     public SchemaType findType(QName typeName)
70     {
71        return getSchemaTypeLoader().findType(typeName);
72     }
73  
74     public void loadSchemaTypes(DefinitionLoader loader) throws SchemaException
75     {
76        schemaTypes = SchemaUtils.loadSchemaTypes(loader.getBaseURI(), loader);
77        schemaTypeLoader = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[]{schemaTypes, XmlBeans.getBuiltinTypeSystem()});
78     }
79  }