001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation;
042:
043: import java.util.Collections;
044: import java.util.Iterator;
045: import java.util.List;
046: import java.util.Set;
047: import org.netbeans.modules.xml.wsdl.model.Definitions;
048: import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
049: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
050: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.BPELExtensibilityComponent;
051:
052: import org.netbeans.modules.xml.xam.Model;
053: import org.netbeans.modules.xml.xam.spi.Validation;
054: import org.netbeans.modules.xml.xam.spi.ValidationResult;
055: import org.netbeans.modules.xml.xam.spi.Validator;
056: import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
057:
058: /**
059: *
060: * Generic abstract validator.
061: * @author radval
062: *
063: */
064: public abstract class AbstractValidator implements Validator {
065:
066: @SuppressWarnings("unchecked")
067: public static final ValidationResult EMPTY_RESULT = new ValidationResult(
068: Collections.EMPTY_SET, Collections.EMPTY_SET);
069:
070: /* (non-Javadoc)
071: * @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)
072: */
073: /** {@inheritDoc} */
074: @SuppressWarnings("unchecked")
075: public ValidationResult validate(Model model,
076: Validation validation, ValidationType validationType) {
077: if (!(model instanceof WSDLModel)) {
078: return EMPTY_RESULT;
079: }
080:
081: WSDLModel wsdlModel = (WSDLModel) model;
082:
083: if (wsdlModel.getState() == Model.State.NOT_WELL_FORMED) {
084: return EMPTY_RESULT;
085: }
086:
087: // Initialize our result object
088: Set<ResultItem> results;
089: Set<Model> models = Collections.singleton(model);
090:
091: ValidationVisitor visitor = getVisitor();
092: Definitions def = wsdlModel.getDefinitions();
093:
094: if (def != null) {
095: List<ExtensibilityElement> extensions = def
096: .getExtensibilityElements();
097: Iterator<ExtensibilityElement> it = extensions.iterator();
098: while (it.hasNext()) {
099: ExtensibilityElement exElement = it.next();
100: if (exElement instanceof BPELExtensibilityComponent) {
101: ((BPELExtensibilityComponent) exElement)
102: .accept(visitor);
103: }
104: }
105:
106: }
107:
108: results = visitor.getResultItems();
109: if (results == null) {
110: results = Collections.EMPTY_SET;
111: }
112: return new ValidationResult(results, models);
113: }
114:
115: protected abstract ValidationVisitor getVisitor();
116:
117: }
|