1 19 20 package org.netbeans.modules.xml.wsdl.model.impl; 21 22 import java.io.IOException ; 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 ; 34 35 39 public class SyncReviewVisitor extends DefaultVisitor { 40 41 private SyncUnit unit; 42 43 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 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 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 (new IOException ("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 |