KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.xml.wsdl.model.extensions.bpel.BPELExtensibilityComponent;
23 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.CorrelationProperty;
24 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Documentation;
25 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PartnerLinkType;
26 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PropertyAlias;
27 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Role;
28 import org.netbeans.modules.xml.xam.Component;
29 import org.netbeans.modules.xml.xam.ComponentUpdater;
30 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
31
32 /**
33  * @author Nam Nguyen
34  *
35  * changed by
36  * @author ads
37  */

38 public class BPELComponentUpdater implements
39         BPELExtensibilityComponent.Visitor,
40         ComponentUpdater<BPELExtensibilityComponent>,
41         ComponentUpdater.Query<BPELExtensibilityComponent>
42 {
43
44     private BPELExtensibilityComponent parent;
45
46     private ComponentUpdater.Operation operation;
47     
48     private int index;
49     
50     private boolean canAdd;
51
52     /** Creates a new instance of BPELComponentUpdater */
53     public BPELComponentUpdater() {
54     }
55
56     public boolean canAdd(BPELExtensibilityComponent target, Component child) {
57         if (!(child instanceof BPELExtensibilityComponent)) {
58             return false;
59         }
60         update(target, (BPELExtensibilityComponent) child, null);
61         return canAdd;
62     }
63
64     public void update( BPELExtensibilityComponent target,
65             BPELExtensibilityComponent child,
66             ComponentUpdater.Operation operation )
67     {
68         update(target, child, -1, operation);
69     }
70
71     public void update( BPELExtensibilityComponent target,
72             BPELExtensibilityComponent child, int index,
73             ComponentUpdater.Operation operation )
74     {
75         parent = target;
76         this.operation = operation;
77         this.index = index;
78         child.accept(this);
79     }
80
81     public void visit( PropertyAlias c ) {
82         // never
83
}
84
85     public void visit( CorrelationProperty c ) {
86         // never
87
}
88
89     public void visit( Role child ) {
90         if (parent instanceof PartnerLinkTypeImpl) {
91
92             // Have to use sub-api level calls, not role1/role2 calls.
93
// Note: this might cause role2 become role1 after sync if source
94
// view
95
// has lines of role2 revoved. There supposed to be no role2 if
96
// there is
97
// no role1 and source editing is not main supported usage, so this
98
// is fine.
99

100             PartnerLinkTypeImpl target = (PartnerLinkTypeImpl) parent;
101             if (operation == ComponentUpdater.Operation.ADD) {
102                 target.addRole(child);
103             }
104             else if (operation == ComponentUpdater.Operation.REMOVE) {
105                 target.removeRole(child);
106             } else {
107                 canAdd = true;
108             }
109         }
110     }
111
112     public void visit( PartnerLinkType c ) {
113         // never
114
}
115
116     public void visit( org.netbeans.modules.xml.wsdl.model.extensions.bpel.Query c ) {
117         if ( parent instanceof PropertyAliasImpl ){
118             PropertyAliasImpl propertyAlias = ( PropertyAliasImpl )parent;
119             if (operation == ComponentUpdater.Operation.ADD) {
120                 /* TODO : this is actually wrong. There could be incorrectly added
121                  * second query element via editor. In this case we need
122                  * to distinguish position that was used for addition
123                  * and either insert element or add to the end......
124                  */

125                 propertyAlias.setQuery( c );
126             } else if (operation == ComponentUpdater.Operation.REMOVE) {
127                 propertyAlias.removeQuery( c );
128             } else {
129                 canAdd = true;
130             }
131         }
132         
133     }
134
135     public void visit(Documentation c) {
136         if ( parent instanceof PartnerLinkTypeImpl ){
137             PartnerLinkTypeImpl partnerLinkType = ( PartnerLinkTypeImpl )parent;
138             if (operation == ComponentUpdater.Operation.ADD) {
139                 //index is greater than -1, then insert with that index
140
if (index > -1)
141                     partnerLinkType.insertPartnerLinkTypeDocumentationAt( c, index);
142                 else
143                     partnerLinkType.addPartnerLinkTypeDocumentation(c);
144             }
145             else if (operation == ComponentUpdater.Operation.REMOVE) {
146                 partnerLinkType.removePartnerLinkTypeDocumentation( c );
147             } else {
148                 canAdd = true;
149             }
150         } else if ( parent instanceof RoleImpl ){
151             RoleImpl role = ( RoleImpl )parent;
152             if (operation == ComponentUpdater.Operation.ADD) {
153                 //index is greater than -1, then insert with that index
154
if (index > -1) {
155                     ((AbstractDocumentComponent)role).insertAtIndex(Role.ROLE_DOCUMENTATION_PROPERTY,
156                             c, index);
157                 } else {
158                     role.addRoleDocumentation( c );
159                 }
160             }
161             else if (operation == ComponentUpdater.Operation.REMOVE) {
162                 role.removeRoleDocumentation( c );
163             } else {
164                 canAdd = true;
165             }
166         }
167         
168     }
169
170 }
171
Popular Tags