KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > wsm > wsdl > Schema


1 /*
2  *
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  *
19  */

20 package org.apache.beehive.wsm.wsdl;
21
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24
25 import javax.xml.namespace.QName JavaDoc;
26
27 import org.xmlsoap.schemas.wsdl.TTypes;
28
29 import org.apache.xmlbeans.XmlException;
30 import org.apache.xmlbeans.XmlObject;
31
32 import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
33 import org.apache.xmlbeans.impl.xb.xsdschema.TopLevelComplexType;
34 import org.apache.xmlbeans.impl.xb.xsdschema.TopLevelElement;
35 import org.apache.xmlbeans.impl.xb.xsdschema.TopLevelSimpleType;
36
37
38
39 public class Schema {
40     SchemaDocument.Schema[] schemas;
41
42     /**
43      * @param tt
44      * @throws NoSuchFieldException
45      * @throws IllegalAccessException
46      */

47     public Schema(TTypes tt) throws IllegalAccessException JavaDoc, NoSuchFieldException JavaDoc {
48         
49         schemas = Utilities.selectChildren(tt, SchemaDocument.Schema.class);
50     }
51     
52     /**
53      * @param stream
54      * @throws IOException
55      * @throws XmlException
56      */

57     public Schema(InputStream JavaDoc stream) throws XmlException, IOException JavaDoc {
58         SchemaDocument schemaDoc = SchemaDocument.Factory.parse(stream);
59         schemas = new SchemaDocument.Schema[1];
60         schemas[0] = schemaDoc.getSchema();
61        }
62
63     public XmlObject getTypeNode(QName JavaDoc q) {
64         // first find the schema with matching namespace
65
SchemaDocument.Schema schema = null;
66         for (SchemaDocument.Schema nxtSchema : schemas) {
67             if (nxtSchema.getTargetNamespace() != null
68                     && nxtSchema.getTargetNamespace().equals(
69                             q.getNamespaceURI())) {
70                 schema = nxtSchema;
71                 break;
72             }
73         }
74         if (null == schema)
75             return null; // namespace is not found in this schema.
76

77         
78         // look in complex types
79
TopLevelComplexType[] tlComplexTypes = schema.getComplexTypeArray();
80         for( TopLevelComplexType nxtComplexType : tlComplexTypes) {
81             if( nxtComplexType.getName().equals(q.getLocalPart())) {
82                 return nxtComplexType;
83             }
84         }
85
86         // look in simple types
87
TopLevelSimpleType[] tlSimpleTypes = schema.getSimpleTypeArray();
88         for( TopLevelSimpleType nxtSimpleType : tlSimpleTypes) {
89             if( nxtSimpleType.getName().equals(q.getLocalPart())) {
90                 return nxtSimpleType;
91             }
92         }
93         
94         // look in element types
95
TopLevelElement[] tlElementTypes = schema.getElementArray();
96         for( TopLevelElement nxtElement : tlElementTypes) {
97             if( nxtElement.getName().equals(q.getLocalPart())) {
98                 return nxtElement;
99             }
100         }
101          
102         return null; // it is not in comlex or simple types!
103
}
104
105 }
106
Popular Tags