01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.util;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.apache.ws.commons.schema.XmlSchema;
24: import org.apache.ws.commons.schema.XmlSchemaImport;
25: import org.apache.ws.commons.schema.XmlSchemaInclude;
26: import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
27:
28: import java.util.HashMap;
29: import java.util.Iterator;
30:
31: /**
32: *
33: */
34: public class SchemaUtil {
35: private static final Log log = LogFactory.getLog(SchemaUtil.class);
36:
37: public static XmlSchema[] getAllSchemas(XmlSchema schema) {
38: HashMap map = new HashMap();
39: traverseSchemas(schema, map);
40: return (XmlSchema[]) map.values().toArray(
41: new XmlSchema[map.values().size()]);
42: }
43:
44: private static void traverseSchemas(XmlSchema schema, HashMap map) {
45: String key = schema.getTargetNamespace() + ":"
46: + schema.getSourceURI();
47: if (map.containsKey(key)) {
48: return;
49: }
50: map.put(key, schema);
51:
52: XmlSchemaObjectCollection includes = schema.getIncludes();
53: if (includes != null) {
54: Iterator tempIterator = includes.getIterator();
55: while (tempIterator.hasNext()) {
56: Object o = tempIterator.next();
57: if (o instanceof XmlSchemaImport) {
58: XmlSchema schema1 = ((XmlSchemaImport) o)
59: .getSchema();
60: if (schema1 != null) {
61: traverseSchemas(schema1, map);
62: }
63: }
64: if (o instanceof XmlSchemaInclude) {
65: XmlSchema schema1 = ((XmlSchemaInclude) o)
66: .getSchema();
67: if (schema1 != null) {
68: traverseSchemas(schema1, map);
69: }
70: }
71: }
72: }
73: }
74: }
|