KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > bpel > impl > PartnerLinkTypeImpl


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel.impl;
21
22 import java.util.Collection JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.modules.xml.wsdl.model.Definitions;
25 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
26 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
27 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
28 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.BPELExtensibilityComponent;
29 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.BPELQName;
30 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PartnerLinkType;
31 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Documentation;
32 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Role;
33 import org.netbeans.modules.xml.wsdl.model.spi.NamedExtensibilityElementBase;
34 import org.netbeans.modules.xml.xam.Component;
35 import org.netbeans.modules.xml.xam.ComponentUpdater;
36 import org.w3c.dom.Element JavaDoc;
37
38 /**
39  *
40  * @author Nam Nguyen
41  * changed by
42  * @author ads
43  */

44 public class PartnerLinkTypeImpl extends NamedExtensibilityElementBase
45         implements PartnerLinkType
46 {
47
48     PartnerLinkTypeImpl( WSDLModel model, Element e ) {
49         super(model, e);
50     }
51
52     public PartnerLinkTypeImpl( WSDLModel model ) {
53         this(model, createPrefixedElement(BPELQName.PARTNER_LINK_TYPE
54                 .getQName(), model));
55     }
56
57     protected String JavaDoc getNamespaceURI() {
58         return BPELQName.PLNK_NS;
59     }
60
61     List JavaDoc<Role> getRoles() {
62         return getChildren(Role.class);
63     }
64
65     void addRole( Role role ) {
66         appendChild(ROLE_PROPERTY, role);
67     }
68
69     void removeRole( Role role ) {
70         removeChild(ROLE_PROPERTY, role);
71     }
72
73     public ComponentUpdater getComponentUpdater() {
74         return new BPELComponentUpdater();
75     }
76
77     public void accept( BPELExtensibilityComponent.Visitor v ) {
78         v.visit(this);
79     }
80
81     public void setRole2( Role role ) {
82         List JavaDoc<Role> roles = getRoles();
83         if (roles.size() == 0) {
84             throw new IllegalStateException JavaDoc("Needs to set role 1 first");
85         }
86         else {
87             Role old = getRole2();
88             if (old != null) {
89                 removeRole(old);
90             }
91             if (role != null) {
92                 insertAtIndex(ROLE_PROPERTY, role, 1, Role.class);
93             }
94         }
95     }
96
97     public void setRole1( Role role ) {
98         List JavaDoc<Role> roles = getRoles();
99         if (roles.size() == 0) {
100             addRole(role);
101         }
102         else {
103             Role old = getRole1();
104             if (old != null) {
105                 removeRole(old);
106             }
107             if (role != null) {
108                 insertAtIndex(ROLE_PROPERTY, role, 0, Role.class);
109             }
110         }
111     }
112
113     public Role getRole2() {
114         List JavaDoc<Role> roles = getRoles();
115         if (roles.size() > 1) {
116             return roles.get(1);
117         }
118         return null;
119     }
120
121     public Role getRole1() {
122         List JavaDoc<Role> roles = getRoles();
123         if (roles.size() > 0) {
124             return roles.get(0);
125         }
126         return null;
127     }
128
129     @Override JavaDoc
130     public void addExtensibilityElement(ExtensibilityElement ee) {
131         if (ee instanceof Documentation) {
132             addPartnerLinkTypeDocumentation((Documentation) ee);
133         } else {
134             super.addExtensibilityElement(ee);
135         }
136     }
137
138     public void addPartnerLinkTypeDocumentation(Documentation doc) {
139         if (doc == null) return;
140         Collection JavaDoc<WSDLComponent> children = getChildren();
141         int i = 0;
142         if (children != null) {
143             for (WSDLComponent child : children) {
144                 //add just before the role element.
145
if (child instanceof Role) {
146                     break;
147                 }
148                 i++;
149             }
150         }
151         insertAtIndex(PARTNERLINKTYPE_DOCUMENTATION_PROPERTY, doc, i);
152     }
153     
154     public void insertPartnerLinkTypeDocumentationAt(Documentation doc, int index) {
155         if (doc == null) return;
156         insertAtIndex(PARTNERLINKTYPE_DOCUMENTATION_PROPERTY, doc, index);
157     }
158
159     public void removePartnerLinkTypeDocumentation(Documentation doc) {
160         removeChild(PARTNERLINKTYPE_DOCUMENTATION_PROPERTY, doc);
161     }
162
163     public Collection JavaDoc<Documentation> getPartnerLinkTypeDocumentations() {
164         return getChildren(Documentation.class);
165     }
166
167     @Override JavaDoc
168     public boolean canBeAddedTo(Component target) {
169         if (target instanceof Definitions) {
170             return true;
171         }
172         return false;
173     }
174
175 }
176
Popular Tags