KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation;
20
21 import java.util.Collections JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25 import org.netbeans.modules.xml.wsdl.model.Definitions;
26 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
27 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
28 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.BPELExtensibilityComponent;
29
30 import org.netbeans.modules.xml.xam.Model;
31 import org.netbeans.modules.xml.xam.spi.Validation;
32 import org.netbeans.modules.xml.xam.spi.ValidationResult;
33 import org.netbeans.modules.xml.xam.spi.Validator;
34 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
35
36
37 /**
38  *
39  * Generic abstract validator.
40  * @author radval
41  *
42  */

43 public abstract class AbstractValidator implements Validator {
44     
45     @SuppressWarnings JavaDoc("unchecked")
46     public static final ValidationResult EMPTY_RESULT =
47                 new ValidationResult( Collections.EMPTY_SET,
48                         Collections.EMPTY_SET);
49
50     /* (non-Javadoc)
51      * @see org.netbeans.modules.xml.xam.spi.Validator#validate(org.netbeans.modules.xml.xam.Model, org.netbeans.modules.xml.xam.spi.Validation, org.netbeans.modules.xml.xam.spi.Validation.ValidationType)
52      */

53     /** {@inheritDoc} */
54     @SuppressWarnings JavaDoc("unchecked")
55     public ValidationResult validate( Model model, Validation validation,
56             ValidationType validationType)
57     {
58         if(!(model instanceof WSDLModel)) {
59             return EMPTY_RESULT;
60         }
61         
62         WSDLModel wsdlModel = (WSDLModel) model;
63         
64         if ( wsdlModel.getState() == Model.State.NOT_WELL_FORMED ){
65             return EMPTY_RESULT;
66         }
67         
68         // Initialize our result object
69
Set JavaDoc<ResultItem> results;
70         Set JavaDoc<Model> models = Collections.singleton( model );
71         
72         
73         ValidationVisitor visitor = getVisitor();
74         Definitions def = wsdlModel.getDefinitions();
75         
76         if( def != null ) {
77             List JavaDoc<ExtensibilityElement> extensions = def.getExtensibilityElements();
78             Iterator JavaDoc<ExtensibilityElement> it = extensions.iterator();
79             while(it.hasNext()) {
80                 ExtensibilityElement exElement = it.next();
81                 if(exElement instanceof BPELExtensibilityComponent) {
82                     ((BPELExtensibilityComponent)exElement).accept(visitor);
83                 }
84             }
85             
86         }
87         
88         results = visitor.getResultItems();
89         if ( results == null ){
90             results = Collections.EMPTY_SET;
91         }
92         return new ValidationResult(results, models);
93     }
94     
95     protected abstract ValidationVisitor getVisitor();
96
97 }
98
Popular Tags