1 19 package org.netbeans.modules.xml.wsdl.model.impl; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.List ; 24 import org.netbeans.modules.xml.wsdl.model.Binding; 25 import org.netbeans.modules.xml.wsdl.model.BindingInput; 26 import org.netbeans.modules.xml.wsdl.model.BindingOperation; 27 import org.netbeans.modules.xml.wsdl.model.BindingOutput; 28 import org.netbeans.modules.xml.wsdl.model.Input; 29 import org.netbeans.modules.xml.wsdl.model.Operation; 30 import org.netbeans.modules.xml.wsdl.model.Output; 31 import org.netbeans.modules.xml.wsdl.model.PortType; 32 import org.netbeans.modules.xml.xam.AbstractComponent; 33 import org.netbeans.modules.xml.xam.AbstractReference; 34 import org.netbeans.modules.xml.xam.Reference; 35 36 40 public class OperationReference extends AbstractReference<Operation> implements Reference<Operation> { 41 42 43 public OperationReference(Operation referenced, AbstractComponent parent) { 44 super(referenced, Operation.class, parent); 45 } 46 47 public OperationReference(AbstractComponent parent, String ref){ 49 super(Operation.class, parent, ref); 50 } 51 52 public String getRefString() { 53 if (refString == null) { 54 refString = getReferenced().getName(); 55 } 56 return refString; 57 } 58 59 public Operation get() { 60 if (getReferenced() != null) return getReferenced(); 61 62 String operationName = getRefString(); 63 if (operationName == null) { 64 return null; 65 } 66 67 Binding p = (Binding) getParent().getParent(); 68 if (p == null || p.getType() == null) { 69 return null; 70 } 71 72 PortType pt = p.getType().get(); 73 if (pt == null || pt.getOperations() == null) { 74 return null; 75 } 76 77 Collection <Operation> operations = pt.getOperations(); 78 BindingOperation bindingOp = (BindingOperation) getParent(); 79 List <Operation> candidates = new ArrayList <Operation>(); 80 for (Operation op : operations) { 81 if (operationName.equals(op.getName())) { 82 candidates.add(op); 83 } 84 } 85 86 for (Operation op : candidates) { 88 BindingInput bi = bindingOp.getBindingInput(); 89 BindingOutput bo = bindingOp.getBindingOutput(); 90 Input in = op.getInput(); 91 Output out = op.getOutput(); 92 if (in == null && bi == null && out != null && bo != null && out.getName().equals(bo.getName()) || 93 out == null && bo == null && in != null && bi != null && in.getName().equals(bi.getName()) || 94 in != null && bi != null && out != null && bo != null && 95 in.getName().equals(bi.getName()) && out.getName().equals(bo.getName())) 96 { 97 setReferenced(op); 98 break; 99 } 100 } 101 102 if (getReferenced() == null && ! candidates.isEmpty()) { 103 setReferenced(candidates.get(0)); 104 } 105 return getReferenced(); 106 } 107 } 108 | Popular Tags |