KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > soap > impl > PartReference


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.extensions.soap.impl;
20
21 import org.netbeans.modules.xml.wsdl.model.BindingInput;
22 import org.netbeans.modules.xml.wsdl.model.BindingOutput;
23 import org.netbeans.modules.xml.wsdl.model.Input;
24 import org.netbeans.modules.xml.wsdl.model.Message;
25 import org.netbeans.modules.xml.wsdl.model.Output;
26 import org.netbeans.modules.xml.wsdl.model.Part;
27 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody;
28 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPHeaderBase;
29 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
30 import org.netbeans.modules.xml.xam.AbstractReference;
31 import org.netbeans.modules.xml.xam.Reference;
32
33 /**
34  *
35  * @author Nam Nguyen
36  */

37 public class PartReference extends AbstractReference<Part> implements Reference<Part> {
38     
39     public PartReference(Part referenced, AbstractDocumentComponent parent) {
40         super(referenced, Part.class, parent);
41     }
42     
43     //used by resolve methods
44
public PartReference(AbstractDocumentComponent parent, String JavaDoc ref){
45         super(Part.class, parent, ref);
46     }
47     
48     public String JavaDoc getRefString() {
49         if (refString == null) {
50             refString = getReferenced().getName();
51         }
52         return refString;
53     }
54     
55     public SOAPBodyImpl getBodyParent() {
56         if (getParent() instanceof SOAPBodyImpl) {
57             return (SOAPBodyImpl) getParent();
58         } else {
59             return null;
60         }
61     }
62     
63     public SOAPHeaderBaseImpl getHeaderParent() {
64         if (getParent() instanceof SOAPHeaderBaseImpl) {
65             return (SOAPHeaderBaseImpl) getParent();
66         } else {
67             return null;
68         }
69     }
70     
71     public Part get() {
72         if (getReferenced() == null) {
73             Message m = null;
74             if (getBodyParent() != null) {
75                 SOAPBody p = getBodyParent();
76                 if (p.getParent() instanceof BindingInput) {
77                     BindingInput bi = (BindingInput)p.getParent();
78                     if (bi.getInput() != null) {
79                         Input in = bi.getInput().get();
80                         if (in != null) {
81                             m = in.getMessage().get();
82                         }
83                     }
84                 } else if (p.getParent() instanceof BindingOutput) {
85                     BindingOutput bo = (BindingOutput)p.getParent();
86                     if (bo.getOutput() != null) {
87                         Output out = bo.getOutput().get();
88                         if (out != null) {
89                             m = out.getMessage().get();
90                         }
91                     }
92                 }
93                 
94             } else if (getHeaderParent() != null) {
95                 SOAPHeaderBase header = getHeaderParent();
96                 if (header.getMessage() != null) {
97                     m = header.getMessage().get();
98                 }
99             }
100             if (m != null) {
101                 for (Part part : m.getParts()) {
102                     if (part.getName().equals(getRefString())) {
103                         setReferenced(part);
104                         break;
105                     }
106                 }
107             }
108         }
109         return getReferenced();
110     }
111 }
112
Popular Tags