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