001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.wsif.schema;
059:
060: import java.io.Serializable;
061: import java.util.ArrayList;
062: import java.util.List;
063:
064: import org.w3c.dom.Element;
065: import org.w3c.dom.Node;
066: import org.w3c.dom.NodeList;
067:
068: /**
069: * A class to represent the tpo level <schema> element of a schema
070: *
071: * @author Owen Burroughs <owenb@apache.org>
072: */
073: public class Schema implements Serializable {
074:
075: static final long serialVersionUID = 1L;
076:
077: private String targetNamespace = "";
078: private ArrayList types = new ArrayList();
079: private ArrayList iai = new ArrayList();
080:
081: /**
082: * Constructor
083: * @param el The dom element for this schema
084: */
085: Schema(Element el) {
086: targetNamespace = el.getAttribute("targetNamespace");
087: NodeList children = el.getChildNodes();
088: for (int i = 0; i < children.getLength(); i++) {
089: Node child = children.item(i);
090: if (child.getNodeType() == Node.ELEMENT_NODE) {
091: Element subEl = (Element) child;
092: String elType = subEl.getLocalName();
093: if (elType.equals("complexType")) {
094: types.add(new ComplexType(subEl, targetNamespace));
095: } else if (elType.equals("simpleType")) {
096: types.add(new SimpleType(subEl, targetNamespace));
097: } else if (elType.equals("element")) {
098: types.add(new ElementType(subEl, targetNamespace));
099: } else if (elType.equals("import")
100: || elType.equals("include")) {
101: // If either an import or an include is defined, we need to get
102: // the referenced file so store its location (if appropriate)
103: String loc = subEl.getAttribute("schemaLocation");
104: if (loc != null && !loc.equals("")) {
105: iai.add(loc);
106: }
107: } else {
108: //ignore all other types
109: }
110: }
111: }
112: }
113:
114: /**
115: * Get a list of all the types within this schema
116: * @return A list of SchemaType objects
117: */
118: List getTypes() {
119: return types;
120: }
121:
122: /**
123: * Get the "targetNamespace" attribute for this schema
124: * @return The "targetNamespace" attribute
125: */
126: String getTargetNamespace() {
127: return targetNamespace;
128: }
129:
130: /**
131: * Get all the locations of imported/included schemas so that they can also be retrieved
132: * @return An array of all the import/include schemaLocations
133: */
134: String[] getImportsAndIncludes() {
135: return (String[]) iai.toArray(new String[iai.size()]);
136: }
137: }
|