KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > bpel > validation > staticanalysis > BPELExtensionStaticAnalysisVisitor


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.validation.staticanalysis;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import org.netbeans.modules.xml.schema.model.GlobalElement;
27 import org.netbeans.modules.xml.schema.model.GlobalType;
28 import org.netbeans.modules.xml.wsdl.model.Message;
29 import org.netbeans.modules.xml.wsdl.model.Part;
30 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.CorrelationProperty;
31 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PartnerLinkType;
32 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PropertyAlias;
33 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Role;
34 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.StringAttribute;
35 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.ValidationVisitor;
36 import org.netbeans.modules.xml.xam.Component;
37 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
38 import org.netbeans.modules.xml.xam.spi.Validator;
39 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
40 import org.openide.util.NbBundle;
41
42 /**
43  *
44  * @author radval
45  */

46 public class BPELExtensionStaticAnalysisVisitor extends ValidationVisitor {
47     
48     public static final String JavaDoc VAL_INVALID_PROPERTY_ALIAS = "VAL_INVALID_PROPERTY_ALIAS"; //NOT I18N
49
public static final String JavaDoc FIX_INVALID_PROPERTY_ALIAS = "VAL_INVALID_PROPERTY_ALIAS"; //NOT 118N
50

51     public static final String JavaDoc VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_ONE_OF_MESSAGETYPE_OR_ELEMENT_OR_TYPE =
52                             "VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_ONE_OF_MESSAGETYPE_OR_ELEMENT_OR_TYPE";
53
54     public static final String JavaDoc VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE =
55                         "VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE";
56     
57     public static final String JavaDoc VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART =
58                             "VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART";
59             
60     
61     public static final String JavaDoc VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE =
62                         "VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE";
63     public static final String JavaDoc FIX_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE =
64                         "FIX_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE";
65     
66     public static final String JavaDoc VAL_INVALID_PROPERTY = "VAL_INVALID_PROPERTY"; //NOT I18N
67
public static final String JavaDoc FIX_INVALID_PROPERTY = "VAL_INVALID_PROPERTY"; //NOT 118N
68

69     public static final String JavaDoc VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE =
70                         "VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE";
71
72     
73             
74     private Validator mValidator;
75
76     public BPELExtensionStaticAnalysisVisitor(Validator validator) {
77         this.mValidator = validator;
78         init();
79     }
80
81     public void visit(PartnerLinkType c) {
82         
83     }
84
85     public void visit(Role c) {
86     }
87
88     public void visit(CorrelationProperty c) {
89         NamedComponentReference<GlobalElement> geRef = c.getElement();
90         String JavaDoc element = c.getAttribute(new StringAttribute(CorrelationProperty.ELEMENT_PROPERTY));
91     
92         NamedComponentReference<GlobalType> gtRef = c.getType();
93         String JavaDoc type = c.getAttribute(new StringAttribute(CorrelationProperty.TYPE_PROPERTY));
94         
95         // only one of element/type attribute should be specified
96
if (element != null && type != null)
97         {
98             addNewResultItem(Validator.ResultType.ERROR,
99                             c,
100                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY),
101                             NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY));
102             
103         }
104         
105         if(element == null && type == null) {
106             addNewResultItem(Validator.ResultType.ERROR,
107                             c,
108                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_MUST_SPECIFY_ONE_OF_ELEMENT_OR_TYPE),
109                             "");
110         }
111     }
112
113
114
115     public void visit(PropertyAlias c) {
116         NamedComponentReference<Message> msgRef = c.getMessageType();
117         String JavaDoc messageType = c.getAttribute(new StringAttribute(PropertyAlias.MESSAGE_TYPE_PROPERTY));
118         
119         String JavaDoc part = c.getPart();
120         
121         NamedComponentReference<GlobalElement> geRef = c.getElement();
122         String JavaDoc element = c.getAttribute(new StringAttribute(PropertyAlias.ELEMENT_PROPERTY));
123         
124         NamedComponentReference<GlobalType> gtRef = c.getType();
125         String JavaDoc type = c.getAttribute(new StringAttribute(PropertyAlias.TYPE_PROPERTY));
126         
127         // only one of messageType & part/element/type attribute should be specified
128
if ((messageType != null && element != null)
129                 || (messageType != null && type != null)
130                 || (element != null && type != null))
131         {
132             addNewResultItem(Validator.ResultType.ERROR,
133                             c,
134                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS),
135                             NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY_ALIAS));
136             
137         }
138         
139         //at least one of messageType & part/element/type attribute should be specified
140
if(messageType == null && part == null && element == null && type == null) {
141             addNewResultItem(Validator.ResultType.ERROR,
142                             c,
143                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_ONE_OF_MESSAGETYPE_OR_ELEMENT_OR_TYPE),
144                             "");
145             
146         }
147         
148         
149         if(messageType == null && part != null) {
150             addNewResultItem(Validator.ResultType.ERROR,
151                             c,
152                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE),
153                             "");
154             
155         } else if (messageType != null && part == null) {
156             addNewResultItem(Validator.ResultType.ERROR,
157                             c,
158                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_MUST_SPECIFY_MESSAGE_PART),
159                             "");
160             
161         }
162         
163         if(messageType != null && part != null) {
164             Message msg = msgRef.get();
165             if(msg != null) {
166                 boolean foundPart = false;
167                 
168                 Collection JavaDoc<Part> parts = msg.getParts();
169                 Iterator JavaDoc<Part> it = parts.iterator();
170                 while(it.hasNext()) {
171                     Part p = it.next();
172                     if(p.getName() != null && p.getName().equals(part)) {
173                         foundPart = true;
174                         break;
175                     }
176                 }
177                 
178                 if(!foundPart) {
179                     addNewResultItem(Validator.ResultType.ERROR,
180                             c,
181                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE, part, messageType),
182                             NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY_ALIAS_MESSAGE_PART_IS_NOT_FROM_MESSAGE, messageType));
183                 }
184             }
185         }
186     }
187     
188     
189     /**
190      * Fires to-do events to listeners.
191      *
192      * @param toDoEvent
193      * To-do event to fire.
194      * @return <code>true</code> if more events can be accepted by the
195      * listener; <code>false</code> otherwise.
196      */

197     void addNewResultItem( Validator.ResultType type,
198                            Component component,
199                            String JavaDoc desc,
200                            String JavaDoc correction )
201     {
202         ResultItem item = new Validator.ResultItem(mValidator,
203                                                    type,
204                                                    component,
205                                                    desc + correction);
206         getResultItems().add(item);
207     }
208     
209
210     
211 }
212
Popular Tags