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.ws.processor.model;
037:
038: import java.util.Iterator;
039:
040: /**
041: *
042: * A model visitor incorporating all the logic required to walk through the model.
043: *
044: * @author WS Development Team
045: */
046: public class ExtendedModelVisitor {
047:
048: public ExtendedModelVisitor() {
049: }
050:
051: public void visit(Model model) throws Exception {
052: preVisit(model);
053: for (Service service : model.getServices()) {
054: preVisit(service);
055: for (Port port : service.getPorts()) {
056: preVisit(port);
057: if (shouldVisit(port)) {
058: for (Operation operation : port.getOperations()) {
059: preVisit(operation);
060: Request request = operation.getRequest();
061: if (request != null) {
062: preVisit(request);
063: for (Iterator iter4 = request
064: .getHeaderBlocks(); iter4.hasNext();) {
065:
066: Block block = (Block) iter4.next();
067: visitHeaderBlock(block);
068: }
069: for (Iterator iter4 = request
070: .getBodyBlocks(); iter4.hasNext();) {
071:
072: Block block = (Block) iter4.next();
073: visitBodyBlock(block);
074: }
075: for (Iterator iter4 = request
076: .getParameters(); iter4.hasNext();) {
077:
078: Parameter parameter = (Parameter) iter4
079: .next();
080: visit(parameter);
081: }
082: postVisit(request);
083: }
084:
085: Response response = operation.getResponse();
086: if (response != null) {
087: preVisit(response);
088: for (Iterator iter4 = response
089: .getHeaderBlocks(); iter4.hasNext();) {
090:
091: Block block = (Block) iter4.next();
092: visitHeaderBlock(block);
093: }
094: for (Iterator iter4 = response
095: .getBodyBlocks(); iter4.hasNext();) {
096:
097: Block block = (Block) iter4.next();
098: visitBodyBlock(block);
099: }
100: for (Iterator iter4 = response
101: .getParameters(); iter4.hasNext();) {
102:
103: Parameter parameter = (Parameter) iter4
104: .next();
105: visit(parameter);
106: }
107: postVisit(response);
108: }
109:
110: for (Iterator iter4 = operation.getFaults(); iter4
111: .hasNext();) {
112:
113: Fault fault = (Fault) iter4.next();
114: preVisit(fault);
115: visitFaultBlock(fault.getBlock());
116: postVisit(fault);
117: }
118: postVisit(operation);
119: }
120: }
121: postVisit(port);
122: }
123: postVisit(service);
124: }
125: postVisit(model);
126: }
127:
128: protected boolean shouldVisit(Port port) {
129: return true;
130: }
131:
132: // these methods are intended for subclasses
133: protected void preVisit(Model model) throws Exception {
134: }
135:
136: protected void postVisit(Model model) throws Exception {
137: }
138:
139: protected void preVisit(Service service) throws Exception {
140: }
141:
142: protected void postVisit(Service service) throws Exception {
143: }
144:
145: protected void preVisit(Port port) throws Exception {
146: }
147:
148: protected void postVisit(Port port) throws Exception {
149: }
150:
151: protected void preVisit(Operation operation) throws Exception {
152: }
153:
154: protected void postVisit(Operation operation) throws Exception {
155: }
156:
157: protected void preVisit(Request request) throws Exception {
158: }
159:
160: protected void postVisit(Request request) throws Exception {
161: }
162:
163: protected void preVisit(Response response) throws Exception {
164: }
165:
166: protected void postVisit(Response response) throws Exception {
167: }
168:
169: protected void preVisit(Fault fault) throws Exception {
170: }
171:
172: protected void postVisit(Fault fault) throws Exception {
173: }
174:
175: protected void visitBodyBlock(Block block) throws Exception {
176: }
177:
178: protected void visitHeaderBlock(Block block) throws Exception {
179: }
180:
181: protected void visitFaultBlock(Block block) throws Exception {
182: }
183:
184: protected void visit(Parameter parameter) throws Exception {
185: }
186: }
|