KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > impl > SyncReviewVisitor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.model.impl;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.modules.xml.wsdl.model.NotificationOperation;
24 import org.netbeans.modules.xml.wsdl.model.OneWayOperation;
25 import org.netbeans.modules.xml.wsdl.model.Operation;
26 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation;
27 import org.netbeans.modules.xml.wsdl.model.SolicitResponseOperation;
28 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
29 import org.netbeans.modules.xml.wsdl.model.spi.ElementFactory;
30 import org.netbeans.modules.xml.wsdl.model.visitor.DefaultVisitor;
31 import org.netbeans.modules.xml.xam.dom.ChangeInfo;
32 import org.netbeans.modules.xml.xam.dom.SyncUnit;
33 import org.w3c.dom.Element JavaDoc;
34
35 /**
36  *
37  * @author Nam Nguyen
38  */

39 public class SyncReviewVisitor extends DefaultVisitor {
40     
41     private SyncUnit unit;
42     
43     /** Creates a new instance of SyncUnitReviewVisistor */
44     public SyncReviewVisitor() {
45     }
46  
47     SyncUnit review(SyncUnit toReview) {
48         this.unit = toReview;
49         if (unit.getTarget() instanceof WSDLComponent) {
50             ((WSDLComponent)unit.getTarget()).accept(this);
51         }
52         return unit;
53     }
54
55     private void reviewOperation(Operation target) {
56         if (unit.getToAddList().size() > 0 || unit.getToRemoveList().size() > 0) {
57             SyncUnit reviewed = new SyncUnit(target.getParent());
58             ChangeInfo change = unit.getLastChange();
59             Element JavaDoc peer = change.getParent();
60             change.markParentAsChanged();
61             change.setParentComponent(target.getParent());
62             reviewed.addChange(change);
63             reviewed.addToRemoveList(target);
64             reviewed.addToAddList(createOperation(target.getParent(), peer));
65             unit = reviewed;
66         }
67     }
68     
69     private Operation createOperation(WSDLComponent parent, Element JavaDoc e) {
70         ElementFactory factory = ElementFactoryRegistry.getDefault().get(WSDLQNames.OPERATION.getQName());
71         WSDLComponent component = factory.create(parent, e);
72         if (component == null) {
73             throw new IllegalArgumentException JavaDoc(new IOException JavaDoc("Cannot create operation."));
74         }
75         return (Operation) component;
76     }
77     
78     public void visit(OneWayOperation target) {
79         reviewOperation(target);
80     }
81
82     public void visit(SolicitResponseOperation target) {
83         reviewOperation(target);
84     }
85
86     public void visit(RequestResponseOperation target) {
87         reviewOperation(target);
88     }
89
90     public void visit(NotificationOperation target) {
91         reviewOperation(target);
92     }
93 }
94
Popular Tags