KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.xml.wsdl.model.impl;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.List JavaDoc;
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 /**
37  *
38  * @author Nam Nguyen
39  */

40 public class OperationReference extends AbstractReference<Operation> implements Reference<Operation> {
41     
42     /** Creates a new instance of OperationReference */
43     public OperationReference(Operation referenced, AbstractComponent parent) {
44         super(referenced, Operation.class, parent);
45     }
46     
47     //used by resolve methods
48
public OperationReference(AbstractComponent parent, String JavaDoc ref){
49         super(Operation.class, parent, ref);
50     }
51     
52     public String JavaDoc 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 JavaDoc 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 JavaDoc<Operation> operations = pt.getOperations();
78         BindingOperation bindingOp = (BindingOperation) getParent();
79         List JavaDoc<Operation> candidates = new ArrayList JavaDoc<Operation>();
80         for (Operation op : operations) {
81             if (operationName.equals(op.getName())) {
82                 candidates.add(op);
83             }
84         }
85         
86         // find perfect matched
87
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