1 /* 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.tools.internal.ws.wsdl.framework; 27 28 /** 29 * 30 * Maintains wsdl:location context. This is used with 31 * TWSDLParserContextImpl, where one each WSDL being imported its location is pushed. 32 * 33 * @author WS Development Team 34 */ 35 public class WSDLLocation { 36 WSDLLocation() { 37 reset(); 38 } 39 40 public void push() { 41 int max = contexts.length; 42 idPos++; 43 if (idPos >= max) { 44 LocationContext newContexts[] = new LocationContext[max * 2]; 45 System.arraycopy(contexts, 0, newContexts, 0, max); 46 max *= 2; 47 contexts = newContexts; 48 } 49 currentContext = contexts[idPos]; 50 if (currentContext == null) { 51 contexts[idPos] = currentContext = new LocationContext(); 52 } 53 if (idPos > 0) { 54 currentContext.setParent(contexts[idPos - 1]); 55 } 56 57 } 58 59 public void pop() { 60 idPos--; 61 if (idPos >= 0) { 62 currentContext = contexts[idPos]; 63 } 64 } 65 66 public void reset() { 67 contexts = new LocationContext[32]; 68 idPos = 0; 69 contexts[idPos] = currentContext = new LocationContext(); 70 } 71 72 public String getLocation() { 73 return currentContext.getLocation(); 74 } 75 76 public void setLocation(String loc) { 77 currentContext.setLocation(loc); 78 } 79 80 private LocationContext[] contexts; 81 private int idPos; 82 private LocationContext currentContext; 83 84 // LocationContext - inner class 85 private static class LocationContext { 86 void setLocation(String loc) { 87 location = loc; 88 } 89 90 String getLocation() { 91 return location; 92 } 93 94 void setParent(LocationContext parent) { 95 parentLocation = parent; 96 } 97 98 private String location; 99 private LocationContext parentLocation; 100 } 101 }