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:
042: package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.deprecation;
043:
044: import java.util.Collections;
045: import java.util.HashSet;
046: import java.util.Map;
047: import java.util.Set;
048:
049: import org.netbeans.modules.xml.wsdl.model.Definitions;
050: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
051: import org.netbeans.modules.xml.wsdl.model.extensions.bpel.BPELQName;
052: import org.netbeans.modules.xml.wsdl.model.spi.GenericExtensibilityElement;
053: import org.netbeans.modules.xml.xam.Model;
054: import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
055: import org.netbeans.modules.xml.xam.spi.Validation;
056: import org.netbeans.modules.xml.xam.spi.ValidationResult;
057: import org.netbeans.modules.xml.xam.spi.Validator;
058: import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
059: import org.openide.util.NbBundle;
060:
061: /**
062: *
063: * @author radval
064: */
065: public class BPELExtensionDeprecationValidator implements Validator {
066:
067: public static final String VAL_DEPRECATED_PLINK_NAMESPACE_IN_DEFINITION = "VAL_DEPRECATED_PLINK_NAMESPACE_IN_DEFINITION";
068: public static final String FIX_DEPRECATED_PLINK_NAMESPACE_IN_DEFINITION = "FIX_DEPRECATED_PLINK_NAMESPACE_IN_DEFINITION";
069: public static final String VAL_DEPRECATED_PROPERTY_NAMESPACE_IN_DEFINITION = "VAL_DEPRECATED_PROPERTY_NAMESPACE_IN_DEFINITION";
070: public static final String FIX_DEPRECATED_PROPERTY_NAMESPACE_IN_DEFINITION = "FIX_DEPRECATED_PROPERTY_NAMESPACE_IN_DEFINITION";
071:
072: public static final String DEPRECATED_PLINK_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/03/partner-link/";
073: public static final String DEPRECATED_PROPERTY_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/03/business-process/";
074:
075: /**
076: * Returns name of this validation service.
077: */
078: public String getName() {
079: return getClass().getName();
080: }
081:
082: @SuppressWarnings("unchecked")
083: public static final ValidationResult EMPTY_RESULT = new ValidationResult(
084: Collections.EMPTY_SET, Collections.EMPTY_SET);
085:
086: /* (non-Javadoc)
087: * @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)
088: */
089: /** {@inheritDoc} */
090: @SuppressWarnings("unchecked")
091: public ValidationResult validate(Model model,
092: Validation validation, ValidationType validationType) {
093: if (!(model instanceof WSDLModel)) {
094: return EMPTY_RESULT;
095: }
096:
097: WSDLModel wsdlModel = (WSDLModel) model;
098:
099: if (wsdlModel.getState() == Model.State.NOT_WELL_FORMED) {
100: return EMPTY_RESULT;
101: }
102:
103: // Initialize our result object
104: Set<ResultItem> results = null;
105: Set<Model> models = Collections.singleton(model);
106:
107: Definitions def = wsdlModel.getDefinitions();
108: boolean foundDeprecatedElements = false;
109:
110: for (GenericExtensibilityElement element : def
111: .getExtensibilityElements(GenericExtensibilityElement.class)) {
112: if (element.getQName() != null) {
113: String namespaceURI = element.getQName()
114: .getNamespaceURI();
115: if (namespaceURI != null
116: && namespaceURI
117: .equals(DEPRECATED_PLINK_NAMESPACE)
118: || namespaceURI
119: .equals(DEPRECATED_PROPERTY_NAMESPACE)) {
120: foundDeprecatedElements = true;
121: break;
122: }
123: }
124: }
125:
126: if (foundDeprecatedElements) {
127: Map<String, String> prefixMap = ((AbstractDocumentComponent) def)
128: .getPrefixes();
129: results = new HashSet<ResultItem>();
130: if (prefixMap.containsValue(DEPRECATED_PLINK_NAMESPACE)) {
131: results
132: .add(new ResultItem(
133: this ,
134: Validator.ResultType.WARNING,
135: def,
136: NbBundle
137: .getMessage(
138: getClass(),
139: VAL_DEPRECATED_PLINK_NAMESPACE_IN_DEFINITION,
140: DEPRECATED_PLINK_NAMESPACE)
141: + " : "
142: + NbBundle
143: .getMessage(
144: getClass(),
145: FIX_DEPRECATED_PLINK_NAMESPACE_IN_DEFINITION,
146: DEPRECATED_PLINK_NAMESPACE,
147: BPELQName.PLNK_NS)));
148: }
149:
150: if (prefixMap.containsValue(DEPRECATED_PROPERTY_NAMESPACE)) {
151: results
152: .add(new ResultItem(
153: this ,
154: Validator.ResultType.WARNING,
155: def,
156: NbBundle
157: .getMessage(
158: getClass(),
159: VAL_DEPRECATED_PROPERTY_NAMESPACE_IN_DEFINITION,
160: DEPRECATED_PROPERTY_NAMESPACE)
161: + " : "
162: + NbBundle
163: .getMessage(
164: getClass(),
165: FIX_DEPRECATED_PROPERTY_NAMESPACE_IN_DEFINITION,
166: DEPRECATED_PROPERTY_NAMESPACE,
167: BPELQName.VARPROP_NS)));
168: }
169: }
170:
171: if (results == null) {
172: return EMPTY_RESULT;
173: }
174:
175: return new ValidationResult(results, models);
176: }
177:
178: }
|