KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > bpel > validation > semantic > BPELExtensionSemanticVisitor


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

44 public class BPELExtensionSemanticVisitor extends ValidationVisitor {
45     
46     public static final String JavaDoc VAL_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE = "VAL_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE"; //NOT I18N
47
public static final String JavaDoc FIX_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE = "FIX_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE"; //NOT I18N
48

49     public static final String JavaDoc VAL_INVALID_PROPERTY_ALIAS_ELEMENT = "VAL_INVALID_PROPERTY_ALIAS_ELEMENT"; //NOT I18N
50
public static final String JavaDoc FIX_INVALID_PROPERTY_ALIAS_ELEMENT = "FIX_INVALID_PROPERTY_ALIAS_ELEMENT"; //NOT I18N
51

52     public static final String JavaDoc VAL_INVALID_PROPERTY_ALIAS_TYPE = "VAL_INVALID_PROPERTY_ALIAS_TYPE"; //NOT I18N
53
public static final String JavaDoc FIX_INVALID_PROPERTY_ALIAS_TYPE = "FIX_INVALID_PROPERTY_ALIAS_TYPE"; //NOT I18N
54

55     public static final String JavaDoc VAL_INVALID_PORT_TYPE = "VAL_INVALID_PORT_TYPE"; //NOT I18N
56
public static final String JavaDoc FIX_INVALID_PORT_TYPE = "FIX_INVALID_PORT_TYPE"; //NOT I18N
57

58     public static final String JavaDoc VAL_INVALID_PARTNERLINK_TYPE = "VAL_INVALID_PARTNERLINK_TYPE"; //NOT I18N
59
public static final String JavaDoc FIX_INVALID_PARTNERLINK_TYPE = "FIX_INVALID_PARTNERLINK_TYPE"; //NOT I18N
60

61     public static final String JavaDoc VAL_INVALID_PROPERTY_NAME = "VAL_INVALID_PROPERTY_NAME";
62     public static final String JavaDoc FIX_INVALID_PROPERTY_NAME = "FIX_INVALID_PROPERTY_NAME";
63     
64             
65     private Validator mValidator;
66
67     public BPELExtensionSemanticVisitor(Validator validator) {
68         this.mValidator = validator;
69         init();
70     }
71
72     public void visit(PartnerLinkType c) {
73         Role role1 = c.getRole1();
74         if(role1 != null) {
75             visit(role1);
76         }
77         
78         Role role2 = c.getRole2();
79         if(role2 != null) {
80             visit(role2);
81         }
82         
83         //make sure there only two roles specified
84
if(c.getChildren(Role.class).size() > 2) {
85             addNewResultItem(Validator.ResultType.ERROR,
86                             c,
87                             NbBundle.getMessage(getClass(), VAL_INVALID_PARTNERLINK_TYPE),
88                             NbBundle.getMessage(getClass(), FIX_INVALID_PARTNERLINK_TYPE));
89         }
90     }
91
92     public void visit(Role c) {
93         //make sure role's portType if specified in accessible
94
NamedComponentReference<PortType> portTypeRef = c.getPortType();
95         String JavaDoc portType = c.getAttribute(new StringAttribute(Role.PORT_TYPE_PROPERTY));
96         if((portTypeRef== null || portTypeRef.get() == null) && portType != null) {
97             
98             addNewResultItem(Validator.ResultType.ERROR,
99                             c,
100                             NbBundle.getMessage(getClass(), VAL_INVALID_PORT_TYPE, portType),
101                             NbBundle.getMessage(getClass(), FIX_INVALID_PORT_TYPE, portType));
102         }
103     }
104
105
106     public void visit(PropertyAlias c) {
107        
108         //make sure propery if specified exists
109
NamedComponentReference<CorrelationProperty> propertyRef = c.getPropertyName();
110         String JavaDoc property = c.getAttribute(new StringAttribute(PropertyAlias.PROPERTY_NAME_PROPERTY));
111         if((propertyRef == null || propertyRef.get() == null) && property != null) {
112             addNewResultItem(Validator.ResultType.ERROR,
113                             c,
114                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_NAME, property),
115                             NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY_NAME, property));
116         
117         }
118         
119         //make sure messageType if specified is accessible
120
NamedComponentReference<Message> msgRef = c.getMessageType();
121         String JavaDoc messageType = c.getAttribute(new StringAttribute(PropertyAlias.MESSAGE_TYPE_PROPERTY));
122         if((msgRef== null || msgRef.get() == null) && messageType != null) {
123             
124             addNewResultItem(Validator.ResultType.ERROR,
125                             c,
126                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE, messageType),
127                             NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY_ALIAS_MESSAGE_TYPE, messageType));
128         }
129         
130         //make sure element if specified is accessible
131
NamedComponentReference<GlobalElement> geRef = c.getElement();
132         String JavaDoc element = c.getAttribute(new StringAttribute(PropertyAlias.ELEMENT_PROPERTY));
133         if((geRef == null || geRef.get() == null) && element != null) {
134             
135             addNewResultItem(Validator.ResultType.ERROR,
136                             c,
137                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_ELEMENT, element),
138                             NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY_ALIAS_ELEMENT, element));
139         }
140         
141         //make sure type if specified is accessible
142
NamedComponentReference<GlobalType> gtRef = c.getType();
143         String JavaDoc type = c.getAttribute(new StringAttribute(PropertyAlias.TYPE_PROPERTY));
144         if((gtRef == null || gtRef.get() == null) && type != null) {
145             
146             addNewResultItem(Validator.ResultType.ERROR,
147                             c,
148                             NbBundle.getMessage(getClass(), VAL_INVALID_PROPERTY_ALIAS_TYPE, type),
149                             NbBundle.getMessage(getClass(), FIX_INVALID_PROPERTY_ALIAS_TYPE, type));
150         }
151         
152        
153         
154     }
155     
156     
157     /**
158      * Fires to-do events to listeners.
159      *
160      * @param toDoEvent
161      * To-do event to fire.
162      * @return <code>true</code> if more events can be accepted by the
163      * listener; <code>false</code> otherwise.
164      */

165     void addNewResultItem( Validator.ResultType type,
166                            Component component,
167                            String JavaDoc desc,
168                            String JavaDoc correction )
169     {
170         ResultItem item = new Validator.ResultItem(mValidator,
171                                                    type,
172                                                    component,
173                                                    desc + correction);
174         getResultItems().add(item);
175     }
176     
177
178     
179 }
180
Popular Tags