001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.tools.internal.ws.wsdl.framework;
026:
027: /**
028: *
029: * Maintains wsdl:location context. This is used with
030: * ParserContext, where one each WSDL being imported its location is pushed, this will be used
031: * latter to resolve relative imports of schema in SchemaParser.
032: *
033: * @author WS Development Team
034: */
035: public class WSDLLocation {
036: WSDLLocation() {
037: reset();
038: }
039:
040: public void push() {
041: int max = contexts.length;
042: idPos++;
043: if (idPos >= max) {
044: LocationContext newContexts[] = new LocationContext[max * 2];
045: System.arraycopy(contexts, 0, newContexts, 0, max);
046: max *= 2;
047: contexts = newContexts;
048: }
049: currentContext = contexts[idPos];
050: if (currentContext == null) {
051: contexts[idPos] = currentContext = new LocationContext();
052: }
053: if (idPos > 0) {
054: currentContext.setParent(contexts[idPos - 1]);
055: }
056:
057: }
058:
059: public void pop() {
060: idPos--;
061: if (idPos >= 0) {
062: currentContext = contexts[idPos];
063: }
064: }
065:
066: public void reset() {
067: contexts = new LocationContext[32];
068: idPos = 0;
069: contexts[idPos] = currentContext = new LocationContext();
070: }
071:
072: public String getLocation() {
073: return currentContext.getLocation();
074: }
075:
076: public void setLocation(String loc) {
077: currentContext.setLocation(loc);
078: }
079:
080: private LocationContext[] contexts;
081: private int idPos;
082: private LocationContext currentContext;
083:
084: // LocationContext - inner class
085: private static class LocationContext {
086: void setLocation(String loc) {
087: location = loc;
088: }
089:
090: String getLocation() {
091: return location;
092: }
093:
094: void setParent(LocationContext parent) {
095: parentLocation = parent;
096: }
097:
098: private String location;
099: private LocationContext parentLocation;
100: }
101: }
|