Author: DartPeng
Date: 2009-05-18 22:48:33 -0400 (Mon, 18 May 2009)
New Revision: 15337
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/AbstractValidator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/DuplicatedBeanIDValidator.java
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/ClassFieldEditorValidator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SmooksModelValidator.java
Log:
JBIDE-4232
Extent validation extension point of the "WST validation platform" to validate
the smooks file
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2009-05-18
20:13:30 UTC (rev 15336)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2009-05-19
02:48:33 UTC (rev 15337)
@@ -18,7 +18,9 @@
org.eclipse.emf.edit,
org.eclipse.emf.edit.ui,
org.eclipse.jdt.core,
- org.eclipse.jdt.ui
+ org.eclipse.jdt.ui,
+ org.eclipse.wst.validation,
+ org.eclipse.wst.validation.ui;bundle-version="1.2.2"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: JBoss, a division of Red Hat
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml 2009-05-18 20:13:30 UTC (rev
15336)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml 2009-05-19 02:48:33 UTC (rev
15337)
@@ -88,5 +88,27 @@
name="uri">
</attribute>
</extension>
+ <extension
+ id="org.jboss.tools.smooks.configuration.validator"
+ name="Smooks File Validator"
+ point="org.eclipse.wst.validation.validatorV2">
+ <validator
+ build="true"
+
class="org.jboss.tools.smooks.configuration.validate.SmooksModelValidator"
+ manual="true"
+ version="1">
+ <include>
+ <rules>
+ <contentType
+ exactMatch="true"
+ id="org.jboss.tools.smooks.ui.smooks.contentType">
+ </contentType>
+ </rules>
+ </include>
+ <group
+ id="org.eclipse.wst.sse.core.structuredModelGroup">
+ </group>
+ </validator>
+ </extension>
</plugin>
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/AbstractValidator.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/AbstractValidator.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/AbstractValidator.java 2009-05-19
02:48:33 UTC (rev 15337)
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.smooks.configuration.validate;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+
+/**
+ * @author Dart (dpeng(a)redhat.com)
+ *
+ */
+public abstract class AbstractValidator implements ISmooksValidator {
+
+
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.smooks.configuration.validate.ISmooksValidator#validate(java.util.Collection,
org.eclipse.emf.edit.domain.EditingDomain)
+ */
+ public List<Diagnostic> validate(Collection<?> selectedObjects,
EditingDomain editingDomain) {
+ preStartValidation();
+ List<Diagnostic> list = new ArrayList<Diagnostic>();
+ for (Iterator<?> iterator = selectedObjects.iterator(); iterator.hasNext();) {
+ Object object = (Object) iterator.next();
+ Diagnostic d = validateModel(object, editingDomain);
+ if(d != null){
+ list.add(d);
+ }
+ if (object instanceof EObject) {
+ List<Diagnostic> dd = validate(((EObject) object).eContents(),editingDomain);
+ if (dd != null) {
+ list.addAll(dd);
+ }
+ }
+ }
+ return list;
+ }
+
+ protected void preStartValidation(){
+
+ }
+
+ protected Diagnostic newDiagnostic(int severity , String message , Object model,
EAttribute property){
+ return new BasicDiagnostic(severity, "org.jboss.tools", 0, message, new
Object[] {
+ model, property });
+ }
+
+ protected Diagnostic newWaringDiagnostic(String message , Object model, EAttribute
property){
+ return newDiagnostic(Diagnostic.WARNING, message, model, property);
+ }
+
+ protected Diagnostic newErrorDiagnostic(String message , Object model, EAttribute
property){
+ return newDiagnostic(Diagnostic.ERROR, message, model, property);
+ }
+
+ protected Diagnostic validateModel(Object model , EditingDomain editingDomain){
+ return null;
+ }
+
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/AbstractValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/ClassFieldEditorValidator.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/ClassFieldEditorValidator.java 2009-05-18
20:13:30 UTC (rev 15336)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/ClassFieldEditorValidator.java 2009-05-19
02:48:33 UTC (rev 15337)
@@ -16,7 +16,6 @@
import java.util.List;
import org.eclipse.core.resources.IResource;
-import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
@@ -31,7 +30,7 @@
* @author Dart (dpeng(a)redhat.com)
*
*/
-public class ClassFieldEditorValidator implements ISmooksValidator {
+public class ClassFieldEditorValidator extends AbstractValidator {
private ProjectClassLoader classLoader;
@@ -59,6 +58,12 @@
BindingsType bindings = (BindingsType) object;
classLoader = getClassLoader(bindings);
String clazz = bindings.getClass_();
+ if (clazz != null) {
+ clazz = clazz.trim();
+ if (clazz.endsWith("[]")) {
+ clazz = clazz.substring(0, clazz.length() - 2);
+ }
+ }
Class<?> clazz1 = null;
if (clazz != null && classLoader != null) {
try {
@@ -69,8 +74,7 @@
}
String message = "Can't find class : \"" + clazz +
"\"";
if (clazz1 == null) {
- list.add(new BasicDiagnostic(Diagnostic.WARNING, "org.jboss.tools", 0,
message, new Object[] {
- bindings, JavabeanPackage.Literals.BINDINGS_TYPE__CLASS }));
+ list.add(newWaringDiagnostic(message, bindings,
JavabeanPackage.Literals.BINDINGS_TYPE__CLASS));
}
}
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/DuplicatedBeanIDValidator.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/DuplicatedBeanIDValidator.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/DuplicatedBeanIDValidator.java 2009-05-19
02:48:33 UTC (rev 15337)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.smooks.configuration.validate;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.jboss.tools.smooks.model.javabean.BindingsType;
+import org.jboss.tools.smooks.model.javabean.JavabeanPackage;
+
+/**
+ * @author Dart (dpeng(a)redhat.com)
+ *
+ */
+public class DuplicatedBeanIDValidator extends AbstractValidator {
+
+ private List<String> beanIdList = new ArrayList<String>();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.smooks.configuration.validate.AbstractValidator#validate
+ * (java.util.Collection, org.eclipse.emf.edit.domain.EditingDomain)
+ */
+ @Override
+ public List<Diagnostic> validate(Collection<?> selectedObjects,
EditingDomain editingDomain) {
+ beanIdList.clear();
+ findDuplicatedBeanId(selectedObjects);
+ if(beanIdList.isEmpty()){
+ return null;
+ }
+ List<Diagnostic> list = new ArrayList<Diagnostic>();
+ validateModel(selectedObjects, list);//, editingDomain)
+ return list;
+ }
+
+ private boolean isDuplicateBeanId(String id){
+ if(id != null){
+ id = id.trim();
+ }
+ return beanIdList.contains(id);
+ }
+
+ protected void validateModel(Collection<?> selectedObjects ,
List<Diagnostic> list){
+ for (Iterator<?> iterator = selectedObjects.iterator(); iterator.hasNext();) {
+ Object object = (Object) iterator.next();
+ if (object instanceof BindingsType) {
+ String beanId = ((BindingsType) object).getBeanId();
+ if(isDuplicateBeanId(beanId)){
+ list.add(newWaringDiagnostic("Duplicated beanId : " + beanId, object,
+ JavabeanPackage.Literals.BINDINGS_TYPE__BEAN_ID));
+ }
+ continue;
+ }
+ if (object instanceof EObject) {
+ validateModel(((EObject) object).eContents() , list);
+ }
+ }
+ }
+
+ protected void findDuplicatedBeanId(Collection<?> selectedObjects) {
+ List<String> idlist = new ArrayList<String>();
+ for (Iterator<?> iterator = selectedObjects.iterator(); iterator.hasNext();) {
+ Object object = (Object) iterator.next();
+ if (object instanceof BindingsType) {
+ String beanId = ((BindingsType) object).getBeanId();
+ if (beanId != null) {
+ beanId = beanId.trim();
+ }
+ if (idlist.contains(beanId)) {
+ if (!beanIdList.contains(beanId)) {
+ beanIdList.add(beanId);
+ }
+ } else {
+ idlist.add(beanId);
+ }
+ continue;
+ }
+ if (object instanceof EObject) {
+ findDuplicatedBeanId(((EObject) object).eContents());
+ }
+ }
+ }
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/DuplicatedBeanIDValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SmooksModelValidator.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SmooksModelValidator.java 2009-05-18
20:13:30 UTC (rev 15336)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SmooksModelValidator.java 2009-05-19
02:48:33 UTC (rev 15337)
@@ -10,43 +10,79 @@
******************************************************************************/
package org.jboss.tools.smooks.configuration.validate;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
+import org.eclipse.wst.validation.internal.provisional.core.IValidator;
+import org.jboss.tools.smooks.model.calc.provider.CalcItemProviderAdapterFactory;
+import org.jboss.tools.smooks.model.common.provider.CommonItemProviderAdapterFactory;
+import org.jboss.tools.smooks.model.csv.provider.CsvItemProviderAdapterFactory;
+import
org.jboss.tools.smooks.model.datasource.provider.DatasourceItemProviderAdapterFactory;
+import
org.jboss.tools.smooks.model.dbrouting.provider.DbroutingItemProviderAdapterFactory;
+import org.jboss.tools.smooks.model.edi.provider.EdiItemProviderAdapterFactory;
+import
org.jboss.tools.smooks.model.fileRouting.provider.FileRoutingItemProviderAdapterFactory;
+import
org.jboss.tools.smooks.model.freemarker.provider.FreemarkerItemProviderAdapterFactory;
+import org.jboss.tools.smooks.model.groovy.provider.GroovyItemProviderAdapterFactory;
+import
org.jboss.tools.smooks.model.iorouting.provider.IoroutingItemProviderAdapterFactory;
+import
org.jboss.tools.smooks.model.javabean.provider.JavabeanItemProviderAdapterFactory;
+import
org.jboss.tools.smooks.model.jmsrouting.provider.JmsroutingItemProviderAdapterFactory;
+import org.jboss.tools.smooks.model.json.provider.JsonItemProviderAdapterFactory;
+import org.jboss.tools.smooks.model.medi.provider.MEdiItemProviderAdapterFactory;
+import org.jboss.tools.smooks.model.smooks.provider.SmooksItemProviderAdapterFactory;
+import org.jboss.tools.smooks.model.xsl.provider.XslItemProviderAdapterFactory;
+import org.jboss.tools.smooks10.model.smooks.util.SmooksResourceFactoryImpl;
/**
* @author Dart (dpeng(a)redhat.com)
* <p>
* Apr 14, 2009
*/
-public class SmooksModelValidator implements ISmooksValidator{
+public class SmooksModelValidator extends AbstractValidator implements IValidator,
ISmooksValidator {
Collection<?> selectedObjects;
EditingDomain domain;
private boolean starting = false;
private boolean waiting = false;
private Object lock = new Object();
-
+ private AdapterFactoryEditingDomain innerEditingDomain;
+
private long watingTime = 300;
private List<ISmooksModelValidateListener> listeners = new
ArrayList<ISmooksModelValidateListener>();
-
+
private List<ISmooksValidator> validatorList = new
ArrayList<ISmooksValidator>();
public SmooksModelValidator(Collection<?> selectedObjects, EditingDomain domain)
{
@@ -57,6 +93,8 @@
public SmooksModelValidator() {
validatorList.add(new ClassFieldEditorValidator());
+ validatorList.add(new DuplicatedBeanIDValidator());
+ innerEditingDomain = newEditingDomain();
}
public void addValidateListener(ISmooksModelValidateListener l) {
@@ -74,6 +112,13 @@
return validate(new NullProgressMonitor());
}
+ public List<Diagnostic> validate(Collection<?> selectedObjects,
EditingDomain editingDomain,
+ IProgressMonitor monitor) {
+ this.selectedObjects = selectedObjects;
+ domain = editingDomain;
+ return validate(monitor);
+ }
+
public List<Diagnostic> validate(final IProgressMonitor progressMonitor) {
EObject eObject = (EObject) selectedObjects.iterator().next();
int count = 0;
@@ -112,15 +157,17 @@
progressMonitor.setTaskName("Validating...");
Diagnostic diagnostic = diagnostician.validate(eObject);
-
+
List<Diagnostic> list = new ArrayList<Diagnostic>();
list.add(diagnostic);
for (Iterator<?> iterator = this.validatorList.iterator(); iterator.hasNext();)
{
ISmooksValidator validator = (ISmooksValidator) iterator.next();
List<Diagnostic> d = validator.validate(selectedObjects, domain);
- for (Iterator<?> iterator2 = d.iterator(); iterator2.hasNext();) {
- Diagnostic diagnostic2 = (Diagnostic) iterator2.next();
- ((BasicDiagnostic)diagnostic).add(diagnostic2);
+ if (d != null) {
+ for (Iterator<?> iterator2 = d.iterator(); iterator2.hasNext();) {
+ Diagnostic diagnostic2 = (Diagnostic) iterator2.next();
+ ((BasicDiagnostic) diagnostic).add(diagnostic2);
+ }
}
}
return list;
@@ -192,4 +239,102 @@
thread.setName("Validate Smooks model");
thread.start();
}
+
+ private AdapterFactoryEditingDomain newEditingDomain() {
+ ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
+ ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+
+ adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new XslItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new FreemarkerItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new JavabeanItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new CommonItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new SmooksItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new MEdiItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new EdiItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new IoroutingItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new JsonItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new JmsroutingItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new DbroutingItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new CsvItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new DatasourceItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new CalcItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new GroovyItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new FileRoutingItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
+ BasicCommandStack commandStack = new BasicCommandStack();
+ AdapterFactoryEditingDomain editingDomain = new
AdapterFactoryEditingDomain(adapterFactory, commandStack,
+ new HashMap<Resource, Boolean>());
+ return editingDomain;
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state,
IProgressMonitor monitor) {
+ System.out.println("validate file : " + resource.getFullPath().toOSString() +
", resource change type : "
+ + kind);
+
+ AdapterFactoryEditingDomain editingDomain = (AdapterFactoryEditingDomain) this.domain;
+ if (editingDomain == null) {
+ editingDomain = this.innerEditingDomain;
+ }
+ if (editingDomain == null)
+ return null;
+ Object smooksModel = null;
+ Resource smooksResource = new
SmooksResourceFactoryImpl().createResource(URI.createPlatformResourceURI(resource
+ .getFullPath().toPortableString(), false));
+ try {
+ smooksResource.load(Collections.emptyMap());
+ smooksModel = smooksResource.getContents().get(0);
+ } catch (IOException e) {
+ return null;
+ }
+ if (smooksModel == null) {
+ return null;
+ }
+ List<Object> list = new ArrayList<Object>();
+ list.add(smooksModel);
+ for (Iterator<?> iterator = listeners.iterator(); iterator.hasNext();) {
+ final ISmooksModelValidateListener l = (ISmooksModelValidateListener)
iterator.next();
+ Display.getDefault().syncExec(new Runnable() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ l.validateStart();
+ }
+
+ });
+
+ }
+
+ final List<Diagnostic> d = this.validate(list, editingDomain, monitor);
+ for (Iterator<?> iterator = listeners.iterator(); iterator.hasNext();) {
+ final ISmooksModelValidateListener l = (ISmooksModelValidateListener)
iterator.next();
+ Display.getDefault().syncExec(new Runnable() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ l.validateEnd(d);
+ }
+
+ });
+ }
+
+ return null;
+ }
+
+ public void cleanup(IReporter reporter) {
+
+ }
+
+ public void validate(IValidationContext helper, IReporter reporter) throws
ValidationException {
+
+ }
}