001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.tools.xjc.reader.dtd.bindinfo;
037:
038: import java.util.StringTokenizer;
039:
040: import org.w3c.dom.Element;
041: import org.xml.sax.Locator;
042:
043: /**
044: * <interface> declaration in the binding file.
045: */
046: public final class BIInterface {
047: BIInterface(Element e) {
048: this .dom = e;
049: name = DOMUtil.getAttribute(e, "name");
050: members = parseTokens(DOMUtil.getAttribute(e, "members"));
051:
052: if (DOMUtil.getAttribute(e, "properties") != null) {
053: fields = parseTokens(DOMUtil.getAttribute(e, "properties"));
054: throw new AssertionError(
055: "//interface/@properties is not supported");
056: } else
057: // no property was specified
058: fields = new String[0];
059: }
060:
061: /** <interface> element in the binding file. */
062: private final Element dom;
063:
064: /** Name of the generated Java interface. */
065: private final String name;
066:
067: /**
068: * Gets the name of this interface.
069: * This name should also used as the class name.
070: */
071: public String name() {
072: return name;
073: }
074:
075: private final String[] members;
076:
077: /**
078: * Gets the names of interfaces/classes that implement
079: * this interface.
080: */
081: public String[] members() {
082: return members;
083: }
084:
085: private final String[] fields;
086:
087: /** Gets the names of fields in this interface. */
088: public String[] fields() {
089: return fields;
090: }
091:
092: /** Gets the location where this declaration is declared. */
093: public Locator getSourceLocation() {
094: return DOMLocator.getLocationInfo(dom);
095: }
096:
097: /** splits a list into an array of strings. */
098: private static String[] parseTokens(String value) {
099: StringTokenizer tokens = new StringTokenizer(value);
100:
101: String[] r = new String[tokens.countTokens()];
102: int i = 0;
103: while (tokens.hasMoreTokens())
104: r[i++] = tokens.nextToken();
105:
106: return r;
107: }
108: }
|