[jbosstools-commits] JBoss Tools SVN: r24542 - in trunk: cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl and 5 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Sun Aug 29 08:49:13 EDT 2010


Author: akazakov
Date: 2010-08-29 08:49:11 -0400 (Sun, 29 Aug 2010)
New Revision: 24542

Added:
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidationDelegate.java
Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/projects/tck/WebContent/WEB-INF/beans.xml
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java
   trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidationErrorManager.java
   trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java
Log:
https://jira.jboss.org/browse/JBIDE-6523 beans.xml validation

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java	2010-08-28 19:28:10 UTC (rev 24541)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java	2010-08-29 12:49:11 UTC (rev 24542)
@@ -192,6 +192,14 @@
 	IStereotype getStereotype(IPath path);
 
 	/**
+	 * Returns the stereotype which is declared in the given IType.
+	 * 
+	 * @param type
+	 * @return the stereotype which is declared in the given IType
+	 */
+	IStereotype getStereotype(IType type);
+
+	/**
 	 * Returns all the available intercepter binding types.
 	 * 
 	 * @return all the available intercepter binding types

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2010-08-28 19:28:10 UTC (rev 24541)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2010-08-29 12:49:11 UTC (rev 24542)
@@ -28,7 +28,6 @@
 import org.eclipse.jdt.core.IMemberValuePair;
 import org.eclipse.jdt.core.IMethod;
 import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.ITypeParameter;
 import org.eclipse.jdt.core.JavaModelException;
 import org.jboss.tools.cdi.core.CDIConstants;
 import org.jboss.tools.cdi.core.CDICoreNature;
@@ -866,14 +865,35 @@
 		return n.getProject().getFullPath();
 	}
 
+	/*
+	 * (non-Javadoc)
+	 * @see org.jboss.tools.cdi.core.IBeanManager#getStereotype(java.lang.String)
+	 */
 	public StereotypeElement getStereotype(String qualifiedName) {
 		return stereotypes.get(qualifiedName);
 	}
 
+	/*
+	 * (non-Javadoc)
+	 * @see org.jboss.tools.cdi.core.IBeanManager#getStereotype(org.eclipse.core.runtime.IPath)
+	 */
 	public StereotypeElement getStereotype(IPath path) {
 		return stereotypesByPath.get(path);
 	}
 
+	/*
+	 * (non-Javadoc)
+	 * @see org.jboss.tools.cdi.core.IBeanManager#getStereotype(org.eclipse.jdt.core.IType)
+	 */
+	public StereotypeElement getStereotype(IType type) {
+		IPath path = type.getPath();
+		return stereotypesByPath.get(path);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.jboss.tools.cdi.core.IBeanManager#getInterceptorBindings()
+	 */
 	public IInterceptorBinding[] getInterceptorBindings() {
 		IInterceptorBinding[] result = new IInterceptorBinding[interceptorBindings.size()];
 		synchronized (interceptorBindings) {
@@ -886,6 +906,10 @@
 	
 	}
 
+	/*
+	 * (non-Javadoc)
+	 * @see org.jboss.tools.cdi.core.IBeanManager#getInterceptorBinding(java.lang.String)
+	 */
 	public InterceptorBindingElement getInterceptorBinding(String qualifiedName) {
 		return interceptorBindings.get(qualifiedName);
 	}

Added: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java	                        (rev 0)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java	2010-08-29 12:49:11 UTC (rev 24542)
@@ -0,0 +1,188 @@
+/******************************************************************************* 
+ * Copyright (c) 2010 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.cdi.internal.core.validation;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.IMemberValuePair;
+import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.CDIUtil;
+import org.jboss.tools.cdi.core.IAnnotationDeclaration;
+import org.jboss.tools.cdi.core.ICDIAnnotation;
+import org.jboss.tools.cdi.core.IQualifier;
+import org.jboss.tools.cdi.core.IScope;
+import org.jboss.tools.cdi.core.IStereotype;
+import org.jboss.tools.cdi.core.preferences.CDIPreferences;
+
+/**
+ * CDI annotation validator.
+ * 
+ * @author Alexey Kazakov
+ */
+public class AnnotationValidationDelegate extends CDICoreValidationDelegate {
+
+	public AnnotationValidationDelegate(CDICoreValidator validator) {
+		super(validator);
+	}
+
+	public void validateStereotypeAnnotationTypeAnnotations(IStereotype stereotype, IResource resource) throws JavaModelException {
+		/*
+		 * Stereotype annotation type should be annotated with @Target with correct targets [JSR-299 §2.7.1]
+		 * Stereotype annotation type should be annotated with @Retention(RUNTIME)
+		 */
+		String[][] variants = {{TARGET_METHOD, TARGET_FIELD, TARGET_TYPE}, 
+					           {TARGET_METHOD, TARGET_FIELD},
+					           {TARGET_TYPE}, {TARGET_METHOD}, {TARGET_FIELD}};
+		validateTargetAnnotation(stereotype, variants, CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE, resource);
+
+		/*
+		 * Stereotype annotation type should be annotated with @Retention(RUNTIME)
+		 */
+		validateRetentionAnnotation(stereotype, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE, resource);
+	}
+
+	/**
+	 * Validates a scope type.
+	 * 
+	 * @param qualifier
+	 */
+	public void validateScopeType(IScope scope) {
+		if(scope == null) {
+			return;
+		}
+		IResource resource = scope.getResource();
+		if (resource == null || !resource.getName().toLowerCase().endsWith(".java")) {
+			// validate sources only
+			return;
+		}
+
+		try {
+			validateScopeAnnotationTypeAnnotations(scope, resource);
+		} catch (JavaModelException e) {
+			CDICorePlugin.getDefault().logError(e);
+		}
+	}
+
+	private void validateScopeAnnotationTypeAnnotations(IScope scope, IResource resource) throws JavaModelException {
+		/*
+		 * Scope annotation type should be annotated with @Target({TYPE, METHOD, FIELD})
+		 */
+		String[][] variants = {{TARGET_TYPE, TARGET_METHOD, TARGET_FIELD}};
+		validateTargetAnnotation(scope, variants, CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE, resource);
+		
+		/*
+		 * Scope annotation type should be annotated with @Retention(RUNTIME)
+		 */
+		validateRetentionAnnotation(scope, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_SCOPE_TYPE, resource);
+	}
+
+	void validateRetentionAnnotation(ICDIAnnotation type, String message, IResource resource) throws JavaModelException {
+		IAnnotationDeclaration retention = type.getAnnotationDeclaration(CDIConstants.RETENTION_ANNOTATION_TYPE_NAME);
+		if(retention == null) {
+			validator.addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, CDIUtil.convertToSourceReference(type.getSourceType().getNameRange()), resource);
+		} else {
+			IMemberValuePair[] ps = retention.getDeclaration().getMemberValuePairs();
+			boolean ok = false;
+			for (IMemberValuePair p: ps) {
+				if(!"value".equals(p.getMemberName())) continue;
+				Object o = p.getValue();
+				if(o != null) {
+					ok = true;
+					String s = o.toString();
+					int i = s.lastIndexOf('.');
+					if(i >= 0) s = s.substring(i + 1);
+					if(!"RUNTIME".equals(s)) ok = false;
+				}
+			}
+			if(!ok) {
+				validator.addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, retention, resource);
+			}
+		}
+	}
+
+	Set<String> getTargetAnnotationValues(IAnnotationDeclaration target) throws JavaModelException {
+		Set<String> result = new HashSet<String>();
+		IMemberValuePair[] ps = target.getDeclaration().getMemberValuePairs();
+		for (IMemberValuePair p: ps) {
+			if(!"value".equals(p.getMemberName())) continue;
+			Object o = p.getValue();
+			if(o instanceof Object[]) {
+				Object[] os = (Object[])o;
+				for (Object q: os) {
+					String s = q.toString();
+					int i = s.lastIndexOf('.');
+					if(i >= 0) s = s.substring(i + 1);
+					result.add(s);
+				}
+			} else if(o != null) {
+				String s = o.toString();
+				int i = s.lastIndexOf('.');
+				if(i >= 0) s = s.substring(i + 1);
+				result.add(s);
+			}
+		}
+		return result;
+	}
+
+	static String TARGET_METHOD = "METHOD";
+	static String TARGET_FIELD = "FIELD";
+	static String TARGET_PARAMETER = "PARAMETER";
+	static String TARGET_TYPE = "TYPE";
+
+	public void validateQualifierAnnotationTypeAnnotations(IQualifier qualifier, IResource resource) throws JavaModelException {
+		/*
+		 * Qualifier annotation type should be annotated with @Target({METHOD, FIELD, PARAMETER, TYPE}) or  @Target({"FIELD", "PARAMETER"})
+		 * Qualifier annotation type should be annotated with @Retention(RUNTIME)
+		 */
+		String[][] variants = {{TARGET_METHOD, TARGET_FIELD, TARGET_PARAMETER, TARGET_TYPE}, 
+				               {TARGET_FIELD, TARGET_PARAMETER}};
+		validateTargetAnnotation(qualifier, variants, CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, resource);
+
+		/*
+		 * Qualifier annotation type should be annotated with @Retention(RUNTIME)
+		 */
+		validateRetentionAnnotation(qualifier, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE, resource);
+	}
+
+	private void validateTargetAnnotation(ICDIAnnotation annotationType, String[][] variants, String message, IResource resource) throws JavaModelException {
+		IAnnotationDeclaration target = annotationType.getAnnotationDeclaration(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
+		if(target == null) {
+			validator.addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, CDIUtil.convertToSourceReference(annotationType.getSourceType().getNameRange()), resource);
+		} else {
+			Set<String> vs = getTargetAnnotationValues(target);
+			boolean ok = false;
+			for (int i = 0; i < variants.length; i++) {
+				if(vs.size() == variants[i].length) {
+					boolean ok2 = true;
+					String[] values = variants[i];
+					for (String s: values) {
+						if(!vs.contains(s)) {
+							ok2 = false;
+							break;
+						}
+					}
+					if(ok2) {
+						ok = true;
+						break;
+					}
+				}
+			}
+			if(!ok) {
+				validator.addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, target, resource);
+			}
+		}
+	}
+}
\ No newline at end of file


Property changes on: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java	                        (rev 0)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java	2010-08-29 12:49:11 UTC (rev 24542)
@@ -0,0 +1,531 @@
+/******************************************************************************* 
+ * Copyright (c) 2010 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.cdi.internal.core.validation;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.ICDIProject;
+import org.jboss.tools.cdi.core.IClassBean;
+import org.jboss.tools.cdi.core.IDecorator;
+import org.jboss.tools.cdi.core.IInterceptor;
+import org.jboss.tools.cdi.core.IStereotype;
+import org.jboss.tools.cdi.core.preferences.CDIPreferences;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * beans.xml validator
+ * 
+ * @author Alexey Kazakov
+ */
+public class BeansXmlValidationDelegate extends CDICoreValidationDelegate {
+
+	private AlternativeClassValidator alternativeClassValidator;
+	private AlternativeStereotypeValidator alternativeStereotypeValidator;
+	private DecoratorTypeValidator decoratorTypeValidator;
+	private InterceptorTypeValidator interceptorTypeValidator;
+
+	public BeansXmlValidationDelegate(CDICoreValidator validator) {
+		super(validator);
+	}
+
+	private AlternativeClassValidator getAlternativeClassValidator() {
+		if(alternativeClassValidator==null) {
+			alternativeClassValidator = new AlternativeClassValidator(validator.cdiProject);
+		}
+		return alternativeClassValidator;
+	}
+
+	private AlternativeStereotypeValidator getAlternativeStereotypeValidator() {
+		if(alternativeStereotypeValidator==null) {
+			alternativeStereotypeValidator = new AlternativeStereotypeValidator(validator.cdiProject);
+		}
+		return alternativeStereotypeValidator;
+	}
+
+	private DecoratorTypeValidator getDecoratorTypeValidator() {
+		if(decoratorTypeValidator==null) {
+			decoratorTypeValidator = new DecoratorTypeValidator(validator.cdiProject);
+		}
+		return decoratorTypeValidator;
+	}
+
+	private InterceptorTypeValidator getInterceptorTypeValidator() {
+		if(interceptorTypeValidator==null) {
+			interceptorTypeValidator = new InterceptorTypeValidator(validator.cdiProject);
+		}
+		return interceptorTypeValidator;
+	}
+
+	public void validateBeansXml(IFile beansXml) {
+		IModelManager manager = StructuredModelManager.getModelManager();
+		if(manager == null) {
+			// this may happen if plug-in org.eclipse.wst.sse.core 
+			// is stopping or un-installed, that is Eclipse is shutting down.
+			// there is no need to report it, just stop validation.
+			return;
+		}
+
+		IStructuredModel model = null;
+		try {
+			model = manager.getModelForRead(beansXml);
+			if (model instanceof IDOMModel) {
+				IDOMModel domModel = (IDOMModel) model;
+				IDOMDocument document = domModel.getDocument();
+
+				/*
+				 * 5.1.1. Declaring selected alternatives for a bean archive
+				 *  - Each child <class> element must specify the name of an alternative bean class. If there is no class with the specified
+				 *    name, or if the class with the specified name is not an alternative bean class, the container automatically detects the problem
+				 *    and treats it as a deployment problem.
+				 *  - If the same type is listed twice under the <alternatives> element, the container automatically detects the problem and
+				 *    treats it as a deployment problem.
+				 */
+				validateTypeBeanForBeansXml(
+						getAlternativeClassValidator(),
+						document,
+						beansXml);
+
+				/*
+				 * 5.1.1. Declaring selected alternatives for a bean archive
+				 *  - Each child <stereotype> element must specify the name of an @Alternative stereotype annotation. If there is no annotation
+				 *    with the specified name, or the annotation is not an @Alternative stereotype, the container automatically detects the
+				 *    problem and treats it as a deployment problem.
+				 *  - If the same type is listed twice under the <alternatives> element, the container automatically detects the problem and
+				 *    treats it as a deployment problem. 
+				 */
+				validateTypeBeanForBeansXml(
+						getAlternativeStereotypeValidator(),
+						document,
+						beansXml);
+
+				/*
+				 * 8.2. Decorator enablement and ordering
+				 *  - Each child <class> element must specify the name of a decorator bean class. If there is no class with the specified name,
+				 *    or if the class with the specified name is not a decorator bean class, the container automatically detects the problem and
+				 *    treats it as a deployment problem.
+				 *  - If the same class is listed twice under the <decorators> element, the container automatically detects the problem and
+				 *    treats it as a deployment problem.
+				 */
+				validateTypeBeanForBeansXml(
+						getDecoratorTypeValidator(),
+						document,
+						beansXml);
+
+				/*
+				 * 9.4. Interceptor enablement and ordering
+				 * 	- Each child <class> element must specify the name of an interceptor class. If there is no class with the specified name, or if
+				 * 	  the class with the specified name is not an interceptor class, the container automatically detects the problem and treats it as
+				 * 	  a deployment problem.
+				 *  - If the same class is listed twice under the <interceptors> element, the container automatically detects the problem and treats it as
+				 *    a deployment problem.
+				 */
+				validateTypeBeanForBeansXml(
+						getInterceptorTypeValidator(),
+						document,
+						beansXml);
+			}
+		} catch (CoreException e) {
+			CDICorePlugin.getDefault().logError(e);
+        } catch (IOException e) {
+        	CDICorePlugin.getDefault().logError(e);
+		} finally {
+			if (model != null) {
+				model.releaseFromRead();
+			}
+		}
+	}
+
+	private void validateTypeBeanForBeansXml(TypeValidator typeValidator, IDOMDocument document, IFile beansXml) {
+		try {
+			NodeList parentNodeList = document.getElementsByTagName(typeValidator.getParrentElementname());
+			for (int i = 0; i < parentNodeList.getLength(); i++) {
+				Node parentNode = parentNodeList.item(i);
+				if(parentNode instanceof Element) {
+					List<TypeNode> typeNodes = getTypeElements((Element)parentNode, typeValidator.getTypeElementName());
+					Map<String, TypeNode> uniqueTypes = new HashMap<String, TypeNode>();
+					for (TypeNode typeNode : typeNodes) {
+						IType type = getType(beansXml, typeNode, typeValidator.getUnknownTypeErrorMessage());
+						if(type!=null) {
+							if(!type.isBinary()) {
+								validator.getValidationContext().addLinkedCoreResource(beansXml.getFullPath().toOSString(), type.getPath(), false);
+							}
+							if(!typeValidator.validateKindOfType(type)) {
+								validator.addError(typeValidator.getIllegalTypeErrorMessage(), CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
+										new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml);
+							} else if(type.isBinary()) {
+								if(!typeValidator.validateBinaryType(type)) {
+									validator.addError(typeValidator.getIllegalTypeErrorMessage(), CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
+											new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml);
+								}
+								continue;
+							} else {
+								if(!typeValidator.validateSourceType(type)) {
+									validator.addError(typeValidator.getIllegalTypeErrorMessage(), CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
+											new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml);
+								}
+							}
+							TypeNode node = uniqueTypes.get(typeNode.getTypeName());
+							if(node!=null) {
+								if(!node.isMarkedAsDuplicated()) {
+									validator.addError(typeValidator.getDuplicateTypeErrorMessage(), CDIPreferences.DUPLICATE_TYPE_IN_BEANS_XML,
+											new String[]{}, node.getLength(), node.getStartOffset(), beansXml);
+								}
+								node.setMarkedAsDuplicated(true);
+								validator.addError(typeValidator.getDuplicateTypeErrorMessage(), CDIPreferences.DUPLICATE_TYPE_IN_BEANS_XML,
+										new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml);
+							}
+							uniqueTypes.put(typeNode.getTypeName(), typeNode);
+						}
+					}
+				}
+			}
+		} catch (JavaModelException e) {
+			CDICorePlugin.getDefault().logError(e);
+        }
+	}
+
+	private IType getType(IFile beansXml, TypeNode node, String errorMessage) {
+		IType type = null;
+		if(node.getTypeName()!=null) {
+			try {
+				type = EclipseJavaUtil.findType(validator.javaProject, node.getTypeName());
+			} catch (JavaModelException e) {
+				CDICorePlugin.getDefault().logError(e);
+				return null;
+			}
+		}
+		if(type==null) {
+			addLinkedResourcesForUnknownType(beansXml, node.getTypeName());
+			validator.addError(errorMessage, CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
+					new String[]{}, node.getLength(), node.getStartOffset(), beansXml);
+		}
+		return type;
+	}
+
+	private void addLinkedResourcesForUnknownType(IFile beansXml, String typeName) {
+		if(typeName!=null && typeName.trim().length()>0) {
+			IStatus status = JavaConventions.validateJavaTypeName(typeName, CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7);
+			if(status.getSeverity()!=IStatus.ERROR) {
+				String packagePath = typeName.replace('.', '/');
+				Set<IFolder> sources = validator.getSourceFolders();
+				for (IFolder source : sources) {
+					IPath path = source.getFullPath().append(packagePath + ".java"); //$NON-NLS-1$
+					validator.getValidationContext().addLinkedCoreResource(beansXml.getFullPath().toOSString(), path, false);
+				}
+			}
+		}
+	}
+
+	private List<TypeNode> getTypeElements(Element parentElement, String typeElementName) {
+		List<TypeNode> result = new ArrayList<TypeNode>();
+		NodeList list = parentElement.getElementsByTagName(typeElementName);
+		for (int i = 0; i < list.getLength(); i++) {
+			Node classNode = list.item(i);
+			NodeList children = classNode.getChildNodes();
+
+			boolean empty = true;
+			for (int j = 0; j < children.getLength(); j++) {
+				Node node = children.item(j);
+				if(node.getNodeType() == Node.TEXT_NODE) {
+					String value = node.getNodeValue();
+					if(value!=null) {
+						String className = value.trim();
+						if(className.length()==0) {
+							continue;
+						}
+						empty = false;
+						if(node instanceof IndexedRegion) {
+							int start = ((IndexedRegion)node).getStartOffset() + value.indexOf(className);
+							int length = className.length();
+							result.add(new TypeNode(start, length, className));
+							break;
+						}
+					}
+				}
+			}
+
+			if(empty && classNode instanceof IndexedRegion) {
+				int start = ((IndexedRegion)classNode).getStartOffset();
+				int end = ((IndexedRegion)classNode).getEndOffset();
+				int length = end - start;
+				result.add(new TypeNode(start, length, null));
+			}
+		}
+		return result;
+	}
+
+	private static class TypeNode {
+		private int startOffset;
+		private int length;
+		private String typeName;
+		private boolean markedAsDuplicated;
+
+		public TypeNode(int startOffset, int length, String typeName) {
+			this.startOffset = startOffset;
+			this.length = length;
+			this.typeName = typeName;
+		}
+
+		public int getStartOffset() {
+			return startOffset;
+		}
+
+		public void setStartOffset(int startOffset) {
+			this.startOffset = startOffset;
+		}
+
+		public int getLength() {
+			return length;
+		}
+
+		public void setLength(int length) {
+			this.length = length;
+		}
+
+		public String getTypeName() {
+			return typeName;
+		}
+
+		public void setTypeName(String typeName) {
+			this.typeName = typeName;
+		}
+
+		public boolean isMarkedAsDuplicated() {
+			return markedAsDuplicated;
+		}
+
+		public void setMarkedAsDuplicated(boolean markedAsDuplicated) {
+			this.markedAsDuplicated = markedAsDuplicated;
+		}
+	}
+
+	private static interface TypeValidator {
+
+		boolean validateSourceType(IType type);
+
+		boolean validateBinaryType(IType type) throws JavaModelException;
+
+		/**
+		 * Validates if the type represens class/annotation/...
+		 * @param type
+		 * @return
+		 * @throws JavaModelException 
+		 */
+		boolean validateKindOfType(IType type) throws JavaModelException;
+
+		String getTypeElementName();
+
+		String getParrentElementname();
+
+		String getUnknownTypeErrorMessage();
+
+		String getIllegalTypeErrorMessage();
+
+		String getDuplicateTypeErrorMessage();
+	}
+
+	private static abstract class AbstractTypeValidator implements TypeValidator {
+		ICDIProject cdiProject;
+
+		public AbstractTypeValidator(ICDIProject cdiProject) {
+			this.cdiProject = cdiProject;
+		}
+
+		public String getTypeElementName() {
+			return "class"; //$NON-NLS-1$
+		}
+
+		public boolean validateKindOfType(IType type) throws JavaModelException {
+			return type.isClass();
+		}
+
+		public boolean validateBinaryType(IType type) throws JavaModelException {
+			IAnnotation[] annotations = type.getAnnotations();
+			for (IAnnotation annotation : annotations) {
+				if(annotation.getElementName().equals(getAnnotationName())) {
+					return true;
+				}
+			}
+			return false;
+		}
+
+		protected abstract String getAnnotationName();
+	}
+
+	private static class AlternativeClassValidator extends AbstractTypeValidator {
+
+		public AlternativeClassValidator(ICDIProject cdiProject) {
+			super(cdiProject);
+		}
+
+		public boolean validateSourceType(IType type) {
+			IClassBean classBean = cdiProject.getBeanClass(type);
+			return classBean!=null && classBean.isAlternative();
+		}
+
+		public String getParrentElementname() {
+			return "alternatives"; //$NON-NLS-1$
+		}
+
+		public String getUnknownTypeErrorMessage() {
+			return CDIValidationMessages.UNKNOWN_ALTERNATIVE_BEAN_CLASS_NAME;
+		}
+
+		public String getIllegalTypeErrorMessage() {
+			return CDIValidationMessages.ILLEGAL_ALTERNATIVE_BEAN_CLASS;
+		}
+
+		public String getDuplicateTypeErrorMessage() {
+			return CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE;
+		}
+
+		@Override
+		protected String getAnnotationName() {
+			return CDIConstants.ALTERNATIVE_ANNOTATION_TYPE_NAME;
+		}
+	}
+
+	private static class AlternativeStereotypeValidator extends AbstractTypeValidator {
+
+		public AlternativeStereotypeValidator(ICDIProject cdiProject) {
+			super(cdiProject);
+		}
+
+		public boolean validateSourceType(IType type) {
+			IStereotype stereotype = cdiProject.getStereotype(type);
+			return stereotype!=null && stereotype.isAlternative();
+		}
+
+		@Override
+		public boolean validateKindOfType(IType type) throws JavaModelException {
+			return type.isAnnotation();
+		}
+
+		@Override
+		public String getTypeElementName() {
+			return "stereotype"; //$NON-NLS-1$
+		}
+
+		public String getParrentElementname() {
+			return "alternatives"; //$NON-NLS-1$
+		}
+
+		public String getUnknownTypeErrorMessage() {
+			return CDIValidationMessages.UNKNOWN_ALTERNATIVE_ANNOTATION_NAME;
+		}
+
+		public String getIllegalTypeErrorMessage() {
+			return CDIValidationMessages.ILLEGAL_ALTERNATIVE_ANNOTATION;
+		}
+
+		public String getDuplicateTypeErrorMessage() {
+			return CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE;
+		}
+
+		@Override
+		protected String getAnnotationName() {
+			return CDIConstants.ALTERNATIVE_ANNOTATION_TYPE_NAME;
+		}
+	}
+
+	private static class DecoratorTypeValidator extends AbstractTypeValidator {
+
+		public DecoratorTypeValidator(ICDIProject cdiProject) {
+			super(cdiProject);
+		}
+
+		public boolean validateSourceType(IType type) {
+			IClassBean classBean = cdiProject.getBeanClass(type);
+			return classBean instanceof IDecorator;
+		}
+
+		public String getParrentElementname() {
+			return "decorators"; //$NON-NLS-1$
+		}
+
+		public String getUnknownTypeErrorMessage() {
+			return CDIValidationMessages.UNKNOWN_DECORATOR_BEAN_CLASS_NAME;
+		}
+
+		public String getIllegalTypeErrorMessage() {
+			return CDIValidationMessages.ILLEGAL_DECORATOR_BEAN_CLASS;
+		}
+
+		public String getDuplicateTypeErrorMessage() {
+			return CDIValidationMessages.DUPLICATE_DECORATOR_CLASS;
+		}
+
+		@Override
+		protected String getAnnotationName() {
+			return CDIConstants.DECORATOR_STEREOTYPE_TYPE_NAME;
+		}
+	}
+
+	private static class InterceptorTypeValidator extends AbstractTypeValidator {
+
+		public InterceptorTypeValidator(ICDIProject cdiProject) {
+			super(cdiProject);
+		}
+
+		public boolean validateSourceType(IType type) {
+			IClassBean classBean = cdiProject.getBeanClass(type);
+			return classBean instanceof IInterceptor;
+		}
+
+		public String getParrentElementname() {
+			return "interceptors"; //$NON-NLS-1$
+		}
+
+		public String getUnknownTypeErrorMessage() {
+			return CDIValidationMessages.UNKNOWN_INTERCEPTOR_CLASS_NAME;
+		}
+
+		public String getIllegalTypeErrorMessage() {
+			return CDIValidationMessages.ILLEGAL_INTERCEPTOR_CLASS;
+		}
+
+		public String getDuplicateTypeErrorMessage() {
+			return CDIValidationMessages.DUPLICATE_INTERCEPTOR_CLASS;
+		}
+
+		@Override
+		protected String getAnnotationName() {
+			return CDIConstants.INTERCEPTOR_ANNOTATION_TYPE_NAME;
+		}
+	}
+}
\ No newline at end of file


Property changes on: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidationDelegate.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidationDelegate.java	                        (rev 0)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidationDelegate.java	2010-08-29 12:49:11 UTC (rev 24542)
@@ -0,0 +1,32 @@
+/******************************************************************************* 
+ * Copyright (c) 2010 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.cdi.internal.core.validation;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class CDICoreValidationDelegate {
+
+	protected CDICoreValidator validator;
+
+	public CDICoreValidationDelegate(CDICoreValidator validator) {
+		this.validator = validator;
+	}
+
+	public CDICoreValidator getValidator() {
+		return validator;
+	}
+
+	public void setValidator(CDICoreValidator validator) {
+		this.validator = validator;
+	}
+}
\ No newline at end of file


Property changes on: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidationDelegate.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java	2010-08-28 19:28:10 UTC (rev 24541)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java	2010-08-29 12:49:11 UTC (rev 24542)
@@ -10,7 +10,6 @@
  ******************************************************************************/
 package org.jboss.tools.cdi.internal.core.validation;
 
-import java.io.IOException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -46,14 +45,8 @@
 import org.eclipse.wst.common.componentcore.ComponentCore;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
 import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
 import org.eclipse.wst.validation.internal.core.ValidationException;
 import org.eclipse.wst.validation.internal.provisional.core.IReporter;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
 import org.jboss.tools.cdi.core.CDIConstants;
 import org.jboss.tools.cdi.core.CDICoreNature;
 import org.jboss.tools.cdi.core.CDICorePlugin;
@@ -101,9 +94,6 @@
 import org.jboss.tools.jst.web.kb.validation.IValidationContext;
 import org.jboss.tools.jst.web.kb.validation.IValidator;
 import org.jboss.tools.jst.web.kb.validation.ValidationUtil;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 /**
  * @author Alexey Kazakov
@@ -115,6 +105,9 @@
 	String projectName;
 	IJavaProject javaProject;
 
+	private BeansXmlValidationDelegate beansXmlValidator = new BeansXmlValidationDelegate(this);
+	private AnnotationValidationDelegate annptationValidator = new AnnotationValidationDelegate(this);
+
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -232,7 +225,7 @@
 
 				// Get all the paths of related resources for given file. These
 				// links were saved in previous validation process.
-				Set<String> oldReletedResources = validationContext.getVariableNamesByCoreResource(currentFile.getFullPath(), false);
+				Set<String> oldReletedResources = getValidationContext().getVariableNamesByCoreResource(currentFile.getFullPath(), false);
 				if (oldReletedResources != null) {
 					for (String resourcePath : oldReletedResources) {
 						resources.add(Path.fromOSString(resourcePath));
@@ -243,14 +236,16 @@
 		// Validate all collected linked resources.
 		// Remove all links between collected resources because they will be
 		// linked again during validation.
-		validationContext.removeLinkedCoreResources(resources);
+		getValidationContext().removeLinkedCoreResources(resources);
 
 		IFile[] filesToValidate = new IFile[resources.size()];
 		int i = 0;
 		// We have to remove markers from all collected source files first
 		for (IPath linkedResource : resources) {
 			filesToValidate[i] = root.getFile(linkedResource);
-			removeAllMessagesFromResource(filesToValidate[i++]);
+			if(filesToValidate[i].isAccessible()) {
+				removeAllMessagesFromResource(filesToValidate[i++]);
+			}
 		}
 		i = 0;
 		// Then we can validate them
@@ -301,12 +296,12 @@
 		
 		Set<String> scopes = cdiProject.getScopeNames();
 		for (String scope: scopes) {
-			validateScopeType(cdiProject.getScope(scope));
+			annptationValidator.validateScopeType(cdiProject.getScope(scope));
 		}
 
 		List<IFile> beansXmls = getAllBeansXmls();
 		for (IFile beansXml : beansXmls) {
-			validateBeansXml(beansXml);
+			beansXmlValidator.validateBeansXml(beansXml);
 		}
 
 		return OK_STATUS;
@@ -325,7 +320,7 @@
 
 		if("beans.xml".equalsIgnoreCase(file.getName()) && CDIPreferences.shouldValidateBeansXml(file.getProject())) {
 			// TODO should we check the path of the beans.xml? Or it's better to check the every beans.xml even if it is not in META-INF or WEB-INF.
-			validateBeansXml(file);
+			beansXmlValidator.validateBeansXml(file);
 		} else {
 			Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
 			for (IBean bean : beans) {
@@ -338,13 +333,37 @@
 			validateQualifier(qualifier);
 			
 			IScope scope = cdiProject.getScope(file.getFullPath());
-			validateScopeType(scope);
+			annptationValidator.validateScopeType(scope);
 	
 			IInterceptorBinding binding = cdiProject.getInterceptorBinding(file.getFullPath());
 			validateInterceptorBinding(binding);
 		}
 	}
 
+	Set<IFolder> sourceFolders = null;
+
+	Set<IFolder> getSourceFolders() {
+		if(sourceFolders==null) {
+			sourceFolders = new HashSet<IFolder>();
+			IPackageFragmentRoot[] roots;
+			try {
+				// From source folders
+				roots = javaProject.getPackageFragmentRoots();
+				for (int i = 0; i < roots.length; i++) {
+					if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) {
+						IResource source = roots[i].getCorrespondingResource();
+						if(source instanceof IFolder) {
+							sourceFolders.add((IFolder)source);
+						}
+					}
+				}
+			} catch (JavaModelException e) {
+				CDICorePlugin.getDefault().logError(e);
+			}
+		}
+		return sourceFolders;
+	}
+
 	/**
 	 * Returns all the beans.xml from META-INF and WEB-INF folders
 	 * 
@@ -352,31 +371,21 @@
 	 */
 	private List<IFile> getAllBeansXmls() {
 		List<IFile> beansXmls = new ArrayList<IFile>();
-		IPackageFragmentRoot[] roots;
-		try {
-			// From source folders
-			roots = javaProject.getPackageFragmentRoots();
-			for (int i = 0; i < roots.length; i++) {
-				if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) {
-					IResource source = roots[i].getCorrespondingResource();
-					if(source instanceof IFolder) {
-						IResource beansXml = ((IFolder)source).findMember(new Path("/META-INF/beans.xml")); //$NON-NLS-1$
-						if(beansXml!=null && beansXml instanceof IFile) {
-							beansXmls.add((IFile)beansXml);
-						}
-					}
-				}
+		// From source folders
+		Set<IFolder> sourceFolders = getSourceFolders();
+		for (IFolder source : sourceFolders) {
+			IResource beansXml = source.findMember(new Path("/META-INF/beans.xml")); //$NON-NLS-1$
+			if(beansXml!=null && beansXml instanceof IFile) {
+				beansXmls.add((IFile)beansXml);
 			}
-			// From WEB-INF folder
-			IVirtualComponent com = ComponentCore.createComponent(rootProject);
-			if(com!=null) {
-				IVirtualFile beansXml = com.getRootFolder().getFile(new Path("/WEB-INF/beans.xml")); //$NON-NLS-1$
-				if(beansXml!=null && beansXml.getUnderlyingFile().isAccessible()) {
-					beansXmls.add(beansXml.getUnderlyingFile());
-				}
+		}
+		// From WEB-INF folder
+		IVirtualComponent com = ComponentCore.createComponent(rootProject);
+		if(com!=null) {
+			IVirtualFile beansXml = com.getRootFolder().getFile(new Path("/WEB-INF/beans.xml")); //$NON-NLS-1$
+			if(beansXml!=null && beansXml.getUnderlyingFile().isAccessible()) {
+				beansXmls.add(beansXml.getUnderlyingFile());
 			}
-		} catch (JavaModelException e) {
-			CDICorePlugin.getDefault().logError(e);
 		}
 		return beansXmls;
 	}
@@ -396,14 +405,14 @@
 		// Collect all relations between the bean and other CDI elements.
 		String name = bean.getName();
 		if (name != null) {
-			validationContext.addVariableNameForELValidation(name);
+			getValidationContext().addVariableNameForELValidation(name);
 		}
 		String beanPath = bean.getResource().getFullPath().toOSString();
 		Set<IScopeDeclaration> scopeDeclarations = bean.getScopeDeclarations();
 		for (IScopeDeclaration scopeDeclaration : scopeDeclarations) {
 			IScope scope = scopeDeclaration.getScope();
 			if (!scope.getSourceType().isReadOnly()) {
-				validationContext.addLinkedCoreResource(beanPath, scope.getResource().getFullPath(), false);
+				getValidationContext().addLinkedCoreResource(beanPath, scope.getResource().getFullPath(), false);
 			}
 		}
 		addLinkedStereotypes(beanPath, bean);
@@ -411,7 +420,7 @@
 		for (IQualifierDeclaration qualifierDeclaration : qualifierDeclarations) {
 			IQualifier qualifier = qualifierDeclaration.getQualifier();
 			if (!qualifier.getSourceType().isReadOnly()) {
-				validationContext.addLinkedCoreResource(beanPath, qualifier.getResource().getFullPath(), false);
+				getValidationContext().addLinkedCoreResource(beanPath, qualifier.getResource().getFullPath(), false);
 			}
 		}
 
@@ -455,7 +464,7 @@
 		for (IStereotypeDeclaration stereotypeDeclaration : stereotypeDeclarations) {
 			IStereotype stereotype = stereotypeDeclaration.getStereotype();
 			if (!stereotype.getSourceType().isReadOnly()) {
-				validationContext.addLinkedCoreResource(beanPath, stereotype.getResource().getFullPath(), false);
+				getValidationContext().addLinkedCoreResource(beanPath, stereotype.getResource().getFullPath(), false);
 			}
 		}
 	}
@@ -465,7 +474,7 @@
 		for (IInterceptorBindingDeclaration bindingDeclaration : bindingDeclarations) {
 			IInterceptorBinding binding = bindingDeclaration.getInterceptorBinding();
 			if (!binding.getSourceType().isReadOnly()) {
-				validationContext.addLinkedCoreResource(beanPath, binding.getResource().getFullPath(), false);
+				getValidationContext().addLinkedCoreResource(beanPath, binding.getResource().getFullPath(), false);
 			}
 		}
 	}
@@ -554,7 +563,7 @@
 			return;
 		}
 		if(!specializingBean.getBeanClass().isReadOnly()) {
-			validationContext.addLinkedCoreResource(bean.getSourcePath().toOSString(), specializingBean.getResource().getFullPath(), false);
+			getValidationContext().addLinkedCoreResource(bean.getSourcePath().toOSString(), specializingBean.getResource().getFullPath(), false);
 		}
 
 		String beanClassName = bean.getBeanClass().getElementName();
@@ -862,7 +871,7 @@
 					addError(errorMessageKey, preferencesKey, declaration, bean.getResource());
 				}
 			} else {
-				validationContext.addLinkedCoreResource(bean.getSourcePath().toOSString(), iMethod.getResource().getFullPath(), false);
+				getValidationContext().addLinkedCoreResource(bean.getSourcePath().toOSString(), iMethod.getResource().getFullPath(), false);
 			}
 		}
 	}
@@ -1050,7 +1059,7 @@
 						addError(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, producer.getProducesAnnotation(), producer.getResource());
 						saveAllSuperTypesAsLinkedResources(classBean);
 					} else {
-						validationContext.addLinkedCoreResource(classBean.getSourcePath().toOSString(), method.getResource().getFullPath(), false);
+						getValidationContext().addLinkedCoreResource(classBean.getSourcePath().toOSString(), method.getResource().getFullPath(), false);
 					}
 				}
 
@@ -1107,7 +1116,7 @@
 		for (IParametedType type : types) {
 			IType superType = type.getType();
 			if(superType!=null && !superType.isBinary() && superType.getResource()!=null && superType!=bean.getBeanClass()) {
-				validationContext.addLinkedCoreResource(bean.getSourcePath().toOSString(), superType.getResource().getFullPath(), false);
+				getValidationContext().addLinkedCoreResource(bean.getSourcePath().toOSString(), superType.getResource().getFullPath(), false);
 			}
 		}
 	}
@@ -1635,7 +1644,7 @@
 						Set<IParametedType> decoratedParametedTypes = decorator.getDecoratedTypes();
 						List<String> supers = null;
 						if(!delegateType.isReadOnly()) {
-							validationContext.addLinkedCoreResource(decorator.getResource().getFullPath().toOSString(), delegateType.getResource().getFullPath(), false);
+							getValidationContext().addLinkedCoreResource(decorator.getResource().getFullPath().toOSString(), delegateType.getResource().getFullPath(), false);
 						}
 						for (IParametedType decoratedParametedType : decoratedParametedTypes) {
 							IType decoratedType = decoratedParametedType.getType();
@@ -1643,7 +1652,7 @@
 								continue;
 							}
 							if(!decoratedType.isReadOnly()) {
-								validationContext.addLinkedCoreResource(decorator.getResource().getFullPath().toOSString(), decoratedType.getResource().getFullPath(), false);
+								getValidationContext().addLinkedCoreResource(decorator.getResource().getFullPath().toOSString(), decoratedType.getResource().getFullPath(), false);
 							}
 							String decoratedTypeName = decoratedType.getFullyQualifiedName();
 							// Ignore the type of the decorator class bean
@@ -1873,111 +1882,28 @@
 		}
 
 		try {
-			validateStereotypeAnnotationTypeAnnotations(stereotype, resource);
+			annptationValidator.validateStereotypeAnnotationTypeAnnotations(stereotype, resource);
 		} catch (JavaModelException e) {
 			CDICorePlugin.getDefault().logError(e);
 		}
 	}
 
-	private void validateStereotypeAnnotationTypeAnnotations(IStereotype stereotype, IResource resource) throws JavaModelException {
-		/*
-		 * Stereotype annotation type should be annotated with @Target with correct targets [JSR-299 §2.7.1]
-		 * Stereotype annotation type should be annotated with @Retention(RUNTIME)
-		 */
-		String[][] variants = {{TARGET_METHOD, TARGET_FIELD, TARGET_TYPE}, 
-					           {TARGET_METHOD, TARGET_FIELD},
-					           {TARGET_TYPE}, {TARGET_METHOD}, {TARGET_FIELD}};
-		validateTargetAnnotation(stereotype, variants, CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE, resource);
-
-		/*
-		 * Stereotype annotation type should be annotated with @Retention(RUNTIME)
-		 */
-		validateRetentionAnnotation(stereotype, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE, resource);
-	}
-
-	/**
-	 * Validates a qualifier.
-	 * 
-	 * @param qualifier
-	 */
-	private void validateScopeType(IScope scope) {
-		if(scope == null) {
+	private void validateInterceptorBinding(IInterceptorBinding binding) {
+		if(binding==null) {
 			return;
 		}
-		IResource resource = scope.getResource();
+		IResource resource = binding.getResource();
 		if (resource == null || !resource.getName().toLowerCase().endsWith(".java")) {
 			// validate sources only
 			return;
 		}
-
-		try {
-			validateScopeAnnotationTypeAnnotations(scope, resource);
-		} catch (JavaModelException e) {
-			CDICorePlugin.getDefault().logError(e);
-		}
-	}
-
-	private void validateScopeAnnotationTypeAnnotations(IScope scope, IResource resource) throws JavaModelException {
 		/*
-		 * Scope annotation type should be annotated with @Target({TYPE, METHOD, FIELD})
+		 * 9.5.2. Interceptor binding types with members
+		 *  array-valued or annotation-valued member of an interceptor binding type is not annotated @Nonbinding (Non-Portable behavior)
 		 */
-		String[][] variants = {{TARGET_TYPE, TARGET_METHOD, TARGET_FIELD}};
-		validateTargetAnnotation(scope, variants, CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE, resource);
-		
-		/*
-		 * Scope annotation type should be annotated with @Retention(RUNTIME)
-		 */
-		validateRetentionAnnotation(scope, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_SCOPE_TYPE, resource);
+		validateAnnotationMembers(binding, CDIValidationMessages.MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER, CDIValidationMessages.MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER, CDIPreferences.MISSING_NONBINDING_IN_INTERCEPTOR_BINDING_TYPE_MEMBER);
 	}
 
-	void validateRetentionAnnotation(ICDIAnnotation type, String message, IResource resource) throws JavaModelException {
-		IAnnotationDeclaration retention = type.getAnnotationDeclaration(CDIConstants.RETENTION_ANNOTATION_TYPE_NAME);
-		if(retention == null) {
-			addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, CDIUtil.convertToSourceReference(type.getSourceType().getNameRange()), resource);
-		} else {
-			IMemberValuePair[] ps = retention.getDeclaration().getMemberValuePairs();
-			boolean ok = false;
-			for (IMemberValuePair p: ps) {
-				if(!"value".equals(p.getMemberName())) continue;
-				Object o = p.getValue();
-				if(o != null) {
-					ok = true;
-					String s = o.toString();
-					int i = s.lastIndexOf('.');
-					if(i >= 0) s = s.substring(i + 1);
-					if(!"RUNTIME".equals(s)) ok = false;
-				}
-			}
-			if(!ok) {
-				addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, retention, resource);
-			}
-		}
-	}
-
-	Set<String> getTargetAnnotationValues(IAnnotationDeclaration target) throws JavaModelException {
-		Set<String> result = new HashSet<String>();
-		IMemberValuePair[] ps = target.getDeclaration().getMemberValuePairs();
-		for (IMemberValuePair p: ps) {
-			if(!"value".equals(p.getMemberName())) continue;
-			Object o = p.getValue();
-			if(o instanceof Object[]) {
-				Object[] os = (Object[])o;
-				for (Object q: os) {
-					String s = q.toString();
-					int i = s.lastIndexOf('.');
-					if(i >= 0) s = s.substring(i + 1);
-					result.add(s);
-				}
-			} else if(o != null) {
-				String s = o.toString();
-				int i = s.lastIndexOf('.');
-				if(i >= 0) s = s.substring(i + 1);
-				result.add(s);
-			}
-		}
-		return result;
-	}
-
 	/**
 	 * Validates a qualifier.
 	 * 
@@ -2002,78 +1928,13 @@
 		 * Qualifier annotation type should be annotated with @Target({METHOD, FIELD, PARAMETER, TYPE})
 		 */
 		try {
-			validateQualifierAnnotationTypeAnnotations(qualifier, resource);
+			annptationValidator.validateQualifierAnnotationTypeAnnotations(qualifier, resource);
 		} catch (JavaModelException e) {
 			CDICorePlugin.getDefault().logError(e);
 		}
 	}
 
-	static String TARGET_METHOD = "METHOD";
-	static String TARGET_FIELD = "FIELD";
-	static String TARGET_PARAMETER = "PARAMETER";
-	static String TARGET_TYPE = "TYPE";
-
-	private void validateQualifierAnnotationTypeAnnotations(IQualifier qualifier, IResource resource) throws JavaModelException {
-		/*
-		 * Qualifier annotation type should be annotated with @Target({METHOD, FIELD, PARAMETER, TYPE}) or  @Target({"FIELD", "PARAMETER"})
-		 * Qualifier annotation type should be annotated with @Retention(RUNTIME)
-		 */
-		String[][] variants = {{TARGET_METHOD, TARGET_FIELD, TARGET_PARAMETER, TARGET_TYPE}, 
-				               {TARGET_FIELD, TARGET_PARAMETER}};
-		validateTargetAnnotation(qualifier, variants, CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, resource);
-
-		/*
-		 * Qualifier annotation type should be annotated with @Retention(RUNTIME)
-		 */
-		validateRetentionAnnotation(qualifier, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE, resource);
-	}
-
-	private void validateTargetAnnotation(ICDIAnnotation annotationType, String[][] variants, String message, IResource resource) throws JavaModelException {
-		IAnnotationDeclaration target = annotationType.getAnnotationDeclaration(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
-		if(target == null) {
-			addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, CDIUtil.convertToSourceReference(annotationType.getSourceType().getNameRange()), resource);
-		} else {
-			Set<String> vs = getTargetAnnotationValues(target);
-			boolean ok = false;
-			for (int i = 0; i < variants.length; i++) {
-				if(vs.size() == variants[i].length) {
-					boolean ok2 = true;
-					String[] values = variants[i];
-					for (String s: values) {
-						if(!vs.contains(s)) {
-							ok2 = false;
-							break;
-						}
-					}
-					if(ok2) {
-						ok = true;
-						break;
-					}
-				}
-			}
-			if(!ok) {
-				addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, target, resource);
-			}
-		}
-	}
-
-	private void validateInterceptorBinding(IInterceptorBinding binding) {
-		if(binding==null) {
-			return;
-		}
-		IResource resource = binding.getResource();
-		if (resource == null || !resource.getName().toLowerCase().endsWith(".java")) {
-			// validate sources only
-			return;
-		}
-		/*
-		 * 9.5.2. Interceptor binding types with members
-		 *  array-valued or annotation-valued member of an interceptor binding type is not annotated @Nonbinding (Non-Portable behavior)
-		 */
-		validateAnnotationMembers(binding, CDIValidationMessages.MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER, CDIValidationMessages.MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER, CDIPreferences.MISSING_NONBINDING_IN_INTERCEPTOR_BINDING_TYPE_MEMBER);
-	}
-
-	private void validateAnnotationMembers(ICDIAnnotation annotation, String arrayMessageErrorKey, String annotationValueErrorKey, String preferencesKey) {
+	void validateAnnotationMembers(ICDIAnnotation annotation, String arrayMessageErrorKey, String annotationValueErrorKey, String preferencesKey) {
 		IType type = annotation.getSourceType();
 		try {
 			IMethod[] methods = type.getMethods();
@@ -2108,241 +1969,4 @@
 			CDICorePlugin.getDefault().logError(e);
 		}
 	}
-
-	private void validateBeansXml(IFile beansXml) {
-		IModelManager manager = StructuredModelManager.getModelManager();
-		if(manager == null) {
-			// this may happen if plug-in org.eclipse.wst.sse.core 
-			// is stopping or un-installed, that is Eclipse is shutting down.
-			// there is no need to report it, just stop validation.
-			return;
-		}
-
-		IStructuredModel model = null;
-		try {
-			model = manager.getModelForRead(beansXml);
-			if (model instanceof IDOMModel) {
-				IDOMModel domModel = (IDOMModel) model;
-				IDOMDocument document = domModel.getDocument();
-
-				/*
-				 * 5.1.1. Declaring selected alternatives for a bean archive
-				 *  - Each child <class> element must specify the name of an alternative bean class. If there is no class with the specified
-				 *    name, or if the class with the specified name is not an alternative bean class, the container automatically detects the problem
-				 *    and treats it as a deployment problem.
-				 *  - If the same type is listed twice under the <alternatives> element, the container automatically detects the problem and
-				 *    treats it as a deployment problem.
-				 */
-				validateTypeBeanForBeansXml(document, beansXml, "class", false, "alternatives", CDIValidationMessages.UNKNOWN_ALTERNATIVE_BEAN_CLASS_NAME, CDIValidationMessages.ILLEGAL_ALTERNATIVE_BEAN_CLASS, CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE, CDIConstants.ALTERNATIVE_ANNOTATION_TYPE_NAME); //$NON-NLS-1$
-
-				/*
-				 * 5.1.1. Declaring selected alternatives for a bean archive
-				 *  - Each child <stereotype> element must specify the name of an @Alternative stereotype annotation. If there is no annotation
-				 *    with the specified name, or the annotation is not an @Alternative stereotype, the container automatically detects the
-				 *    problem and treats it as a deployment problem.
-				 *  - If the same type is listed twice under the <alternatives> element, the container automatically detects the problem and
-				 *    treats it as a deployment problem. 
-				 */
-				validateTypeBeanForBeansXml(document, beansXml, "stereotype", true, "alternatives", CDIValidationMessages.UNKNOWN_ALTERNATIVE_ANNOTATION_NAME, CDIValidationMessages.ILLEGAL_ALTERNATIVE_ANNOTATION, CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE, CDIConstants.ALTERNATIVE_ANNOTATION_TYPE_NAME); //$NON-NLS-1$
-
-				/*
-				 * 8.2. Decorator enablement and ordering
-				 *  - Each child <class> element must specify the name of a decorator bean class. If there is no class with the specified name,
-				 *    or if the class with the specified name is not a decorator bean class, the container automatically detects the problem and
-				 *    treats it as a deployment problem.
-				 *  - If the same class is listed twice under the <decorators> element, the container automatically detects the problem and
-				 *    treats it as a deployment problem.
-				 */
-				validateTypeBeanForBeansXml(document, beansXml, "class", false, "decorators", CDIValidationMessages.UNKNOWN_DECORATOR_BEAN_CLASS_NAME, CDIValidationMessages.ILLEGAL_DECORATOR_BEAN_CLASS, CDIValidationMessages.DUPLICATE_DECORATOR_CLASS, CDIConstants.DECORATOR_STEREOTYPE_TYPE_NAME); //$NON-NLS-1$
-
-				/*
-				 * 9.4. Interceptor enablement and ordering
-				 * 	- Each child <class> element must specify the name of an interceptor class. If there is no class with the specified name, or if
-				 * 	  the class with the specified name is not an interceptor class, the container automatically detects the problem and treats it as
-				 * 	  a deployment problem.
-				 *  - If the same class is listed twice under the <interceptors> element, the container automatically detects the problem and treats it as
-				 *    a deployment problem.
-				 */
-				validateTypeBeanForBeansXml(document, beansXml, "class", false, "interceptors", CDIValidationMessages.UNKNOWN_INTERCEPTOR_CLASS_NAME, CDIValidationMessages.ILLEGAL_INTERCEPTOR_CLASS, CDIValidationMessages.DUPLICATE_INTERCEPTOR_CLASS, CDIConstants.INTERCEPTOR_ANNOTATION_TYPE_NAME); //$NON-NLS-1$
-			}
-		} catch (CoreException e) {
-			CDICorePlugin.getDefault().logError(e);
-        } catch (IOException e) {
-        	CDICorePlugin.getDefault().logError(e);
-		} finally {
-			if (model != null) {
-				model.releaseFromRead();
-			}
-		}
-	}
-
-	private void validateTypeBeanForBeansXml(IDOMDocument document, IFile beansXml, String typeElementName, boolean annotationType, String parentElementName, String unknownTypeErrorMessage, String illegalTypeErrorMessage, String duplicateTypeErrorMessage, String annotationName) {
-		try {
-			NodeList parentNodeList = document.getElementsByTagName(parentElementName);
-			for (int i = 0; i < parentNodeList.getLength(); i++) {
-				Node parentNode = parentNodeList.item(i);
-				if(parentNode instanceof Element) {
-					List<TypeNode> typeNodes = getTypeElements((Element)parentNode, typeElementName);
-					Map<String, TypeNode> uniqueTypes = new HashMap<String, TypeNode>();
-					for (TypeNode typeNode : typeNodes) {
-						IType type = getType(beansXml, typeNode, unknownTypeErrorMessage);
-						if(type!=null) {
-							if(!type.isBinary()) {
-								validationContext.addLinkedCoreResource(beansXml.getFullPath().toOSString(), type.getPath(), false);
-							}
-							if(!(annotationType?type.isAnnotation():type.isClass())) {
-								addError(illegalTypeErrorMessage, CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
-										new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml);
-							} else if(type.isBinary()) {
-								IAnnotation[] annotations = type.getAnnotations();
-								boolean found = false;
-								for (IAnnotation annotation : annotations) {
-									if(annotation.getElementName().equals(annotationName)) {
-										found = true;
-										break;
-									}
-								}
-								if(!found) {
-									addError(illegalTypeErrorMessage, CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
-											new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml);
-								}
-								continue;
-							} else {
-								// TODO we should check Decorators/Interceptors as well as Alternatives (classes/stereotypes)!
-								IClassBean classBean = getClassBean(type);
-								if(classBean==null || !classBean.isAlternative()) {
-									addError(illegalTypeErrorMessage, CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
-											new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml);
-								}
-							}
-							TypeNode node = uniqueTypes.get(typeNode.getTypeName());
-							if(node!=null) {
-								if(!node.isMarkedAsDuplicated()) {
-									addError(duplicateTypeErrorMessage, CDIPreferences.DUPLICATE_TYPE_IN_BEANS_XML,
-											new String[]{}, node.getLength(), node.getStartOffset(), beansXml);
-								}
-								node.setMarkedAsDuplicated(true);
-								addError(duplicateTypeErrorMessage, CDIPreferences.DUPLICATE_TYPE_IN_BEANS_XML,
-										new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml);
-							}
-							uniqueTypes.put(typeNode.getTypeName(), typeNode);
-						}
-					}
-				}
-			}
-		} catch (JavaModelException e) {
-			CDICorePlugin.getDefault().logError(e);
-        }
-	}
-
-	private IClassBean getClassBean(IType type) {
-		IPath path = type.getPath();
-		Set<IBean> beans = cdiProject.getBeans(path);
-		for (IBean bean : beans) {
-			if(bean instanceof IClassBean) {
-				return (IClassBean)bean;
-			}
-		}
-		return null;
-	}
-
-	private IType getType(IFile beansXml, TypeNode node, String errorMessage) {
-		IType type = null;
-		if(node.getTypeName()!=null) {
-			try {
-				type = EclipseJavaUtil.findType(javaProject, node.getTypeName());
-			} catch (JavaModelException e) {
-				CDICorePlugin.getDefault().logError(e);
-				return null;
-			}
-		}
-		if(type==null) {
-			addError(errorMessage, CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
-					new String[]{}, node.getLength(), node.getStartOffset(), beansXml);
-		}
-		return type;
-	}
-
-	private List<TypeNode> getTypeElements(Element parentElement, String typeElementName) {
-		List<TypeNode> result = new ArrayList<TypeNode>();
-		NodeList list = parentElement.getElementsByTagName(typeElementName);
-		for (int i = 0; i < list.getLength(); i++) {
-			Node classNode = list.item(i);
-			NodeList children = classNode.getChildNodes();
-
-			boolean empty = true;
-			for (int j = 0; j < children.getLength(); j++) {
-				Node node = children.item(j);
-				if(node.getNodeType() == Node.TEXT_NODE) {
-					String value = node.getNodeValue();
-					if(value!=null) {
-						String className = value.trim();
-						if(className.length()==0) {
-							continue;
-						}
-						empty = false;
-						if(node instanceof IndexedRegion) {
-							int start = ((IndexedRegion)node).getStartOffset() + value.indexOf(className);
-							int length = className.length();
-							result.add(new TypeNode(start, length, className));
-							break;
-						}
-					}
-				}
-			}
-
-			if(empty && classNode instanceof IndexedRegion) {
-				int start = ((IndexedRegion)classNode).getStartOffset();
-				int end = ((IndexedRegion)classNode).getEndOffset();
-				int length = end - start;
-				result.add(new TypeNode(start, length, null));
-			}
-		}
-		return result;
-	}
-
-	private static class TypeNode {
-		private int startOffset;
-		private int length;
-		private String typeName;
-		private boolean markedAsDuplicated;
-
-		public TypeNode(int startOffset, int length, String typeName) {
-			this.startOffset = startOffset;
-			this.length = length;
-			this.typeName = typeName;
-		}
-
-		public int getStartOffset() {
-			return startOffset;
-		}
-
-		public void setStartOffset(int startOffset) {
-			this.startOffset = startOffset;
-		}
-
-		public int getLength() {
-			return length;
-		}
-
-		public void setLength(int length) {
-			this.length = length;
-		}
-
-		public String getTypeName() {
-			return typeName;
-		}
-
-		public void setTypeName(String typeName) {
-			this.typeName = typeName;
-		}
-
-		public boolean isMarkedAsDuplicated() {
-			return markedAsDuplicated;
-		}
-
-		public void setMarkedAsDuplicated(boolean markedAsDuplicated) {
-			this.markedAsDuplicated = markedAsDuplicated;
-		}
-	}
 }
\ No newline at end of file

Modified: trunk/cdi/tests/org.jboss.tools.cdi.core.test/projects/tck/WebContent/WEB-INF/beans.xml
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/projects/tck/WebContent/WEB-INF/beans.xml	2010-08-28 19:28:10 UTC (rev 24541)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/projects/tck/WebContent/WEB-INF/beans.xml	2010-08-29 12:49:11 UTC (rev 24542)
@@ -34,8 +34,8 @@
 
 		<class>org.jboss.jsr299.tck.tests.decorators.definition.broken.enabledDecoratorIsNotDecorator.TimestampLogger</class>
 
-      	<class>org.jboss.jsr299.tck.tests.decorators.definition.broken.decoratorListedTwiceInBeansXml.PresentDecorator</decorator>
-      	<class>org.jboss.jsr299.tck.tests.decorators.definition.broken.decoratorListedTwiceInBeansXml.PresentDecorator</decorator>
+      	<class>org.jboss.jsr299.tck.tests.decorators.definition.broken.decoratorListedTwiceInBeansXml.PresentDecorator</class>
+      	<class>org.jboss.jsr299.tck.tests.decorators.definition.broken.decoratorListedTwiceInBeansXml.PresentDecorator</class>
 	</decorators>
 
 	<interceptors>

Modified: trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java	2010-08-28 19:28:10 UTC (rev 24541)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java	2010-08-29 12:49:11 UTC (rev 24542)
@@ -1472,7 +1472,7 @@
 	 */
 	public void testNoAlternativeClassWithSpecifiedName() throws Exception {
 		IFile file = tckProject.getFile("WebContent/WEB-INF/beans.xml");
-		assertMarkerIsCreated(file, CDIValidationMessages.UNKNOWN_ALTERNATIVE_BEAN_CLASS_NAME, 4);
+		assertMarkerIsCreated(file, CDIValidationMessages.UNKNOWN_ALTERNATIVE_BEAN_CLASS_NAME, false, 7);
 		assertMarkerIsNotCreated(file, CDIValidationMessages.UNKNOWN_ALTERNATIVE_BEAN_CLASS_NAME, 19);
 	}
 
@@ -1483,7 +1483,7 @@
 	 */
 	public void testIllegalAlternativeClassWithSpecifiedName() throws Exception {
 		IFile file = tckProject.getFile("WebContent/WEB-INF/beans.xml");
-		assertMarkerIsCreated(file, CDIValidationMessages.ILLEGAL_ALTERNATIVE_BEAN_CLASS, 7);
+		assertMarkerIsCreated(file, CDIValidationMessages.ILLEGAL_ALTERNATIVE_BEAN_CLASS, 4);
 		assertMarkerIsNotCreated(file, CDIValidationMessages.ILLEGAL_ALTERNATIVE_BEAN_CLASS, 19);
 	}
 
@@ -1517,22 +1517,12 @@
 	 */
 	public void testSameAlternativeClassListedTwice() throws Exception {
 		IFile file = tckProject.getFile("WebContent/WEB-INF/beans.xml");
-		assertMarkerIsCreated(file, CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE, 20, 22);
+		assertMarkerIsCreated(file, CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE, 20, 22, 26, 27);
+		assertMarkerIsNotCreated(file, CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE, 17);
 		assertMarkerIsNotCreated(file, CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE, 19);
 	}
 
 	/**
-	 * 5.1.1. Declaring selected alternatives for a bean archive
-	 * - If the same type is listed twice under the <alternatives> element, the container automatically detects the problem and
-	 *   treats it as a deployment problem.
-	 */
-	public void testSameAlternativeAnnotationListedTwice() throws Exception {
-		IFile file = tckProject.getFile("WebContent/WEB-INF/beans.xml");
-		assertMarkerIsCreated(file, CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE, 26, 27);
-		assertMarkerIsNotCreated(file, CDIValidationMessages.DUPLICATE_ALTERNATIVE_TYPE, 17);
-	}
-
-	/**
 	 * 8.2. Decorator enablement and ordering
 	 * - Each child <class> element must specify the name of a decorator bean class. If there is no class with the specified name,
 	 *   the container automatically detects the problem and treats it as a deployment problem.
@@ -1631,10 +1621,14 @@
 		return AbstractResourceMarkerTest.getMarkersNumberByGroupName(resource, null);
 	}
 
-	private static void assertMarkerIsCreated(IResource resource, String message, int... expectedLines) throws CoreException {
-		AbstractResourceMarkerTest.assertMarkerIsCreated(resource, AbstractResourceMarkerTest.MARKER_TYPE, convertMessageToPatern(message), expectedLines);
+	private static void assertMarkerIsCreated(IResource resource, String pattern, int... expectedLines) throws CoreException {
+		assertMarkerIsCreated(resource, pattern, true, expectedLines);
 	}
 
+	private static void assertMarkerIsCreated(IResource resource, String message, boolean pattern, int... expectedLines) throws CoreException {
+		AbstractResourceMarkerTest.assertMarkerIsCreated(resource, AbstractResourceMarkerTest.MARKER_TYPE, pattern?convertMessageToPatern(message):message, pattern, expectedLines);
+	}
+
 	private static void assertMarkerIsNotCreated(IResource resource, String message) throws CoreException {
 		AbstractResourceMarkerTest.assertMarkerIsNotCreated(resource, AbstractResourceMarkerTest.MARKER_TYPE, convertMessageToPatern(message));
 	}

Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidationErrorManager.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidationErrorManager.java	2010-08-28 19:28:10 UTC (rev 24541)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidationErrorManager.java	2010-08-29 12:49:11 UTC (rev 24542)
@@ -187,6 +187,10 @@
 		return this.getClass();
 	}
 
+	public IValidationContext getValidationContext() {
+		return validationContext;
+	}
+
 	/*
 	 * (non-Javadoc)
 	 * @see org.jboss.tools.seam.internal.core.validation.IValidationErrorManager#addError(java.lang.String, int, java.lang.String[], int, int, org.eclipse.core.resources.IResource)

Modified: trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java
===================================================================
--- trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java	2010-08-28 19:28:10 UTC (rev 24541)
+++ trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java	2010-08-29 12:49:11 UTC (rev 24542)
@@ -41,10 +41,10 @@
 		super(name);
 	}
 
-	public static int findMarkerLine(IResource resource, String type, String pattern)
+	public static int findMarkerLine(IResource resource, String type, String errorMessage, boolean pattern)
 			throws CoreException {
 		int number = -1;
-		List<Integer> lines = findMarkerLines(resource, type, pattern);
+		List<Integer> lines = findMarkerLines(resource, type, errorMessage, pattern);
 		if(!lines.isEmpty()) {
 			number = lines.get(0);
 		}
@@ -53,8 +53,13 @@
 
 	public static List<Integer> findMarkerLines(IResource resource, String type,
 			String pattern) throws CoreException {
+		return findMarkerLines(resource, type, pattern, true);
+	}
+
+	public static List<Integer> findMarkerLines(IResource resource, String type,
+			String errorMessage, boolean pattern) throws CoreException {
 		List<Integer> numbers = new ArrayList<Integer>();
-		IMarker[] markers = findMarkers(resource, type, pattern);
+		IMarker[] markers = findMarkers(resource, type, errorMessage, pattern);
 		for (int i = 0; i < markers.length; i++) {
 			numbers.add(markers[i].getAttribute(IMarker.LINE_NUMBER, -1));
 		}
@@ -63,11 +68,15 @@
 	}
 
 	public static IMarker[] findMarkers(IResource resource, String type, String pattern) throws CoreException {
+		return findMarkers(resource, type, pattern, true);
+	}
+
+	public static IMarker[] findMarkers(IResource resource, String type, String errorMessage, boolean pattern) throws CoreException {
 		List<IMarker> result = new ArrayList<IMarker>();
 		IMarker[] markers = resource.findMarkers(type, true, IResource.DEPTH_INFINITE);
 		for (int i = 0; i < markers.length; i++) {
 			String message = markers[i].getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
-			if ((message.matches(pattern)||message.equals(pattern)) && markers[i].exists()) {
+			if (pattern?message.matches(errorMessage)||message.equals(errorMessage):message.equals(errorMessage) && markers[i].exists()) {
 				result.add(markers[i]);
 			}
 		}
@@ -75,19 +84,23 @@
 	}
 
 	public static void assertMarkerIsCreated(IResource resource, MarkerData markerData) throws CoreException {
-		assertMarkerIsCreated(resource, markerData.type, markerData.pattern, markerData.line);
+		assertMarkerIsCreated(resource, markerData.type, markerData.pattern, true, markerData.line);
 	}
 
-	public static void assertMarkerIsCreated(IResource resource, String type, String pattern, int... expectedLines) 
+	public static void assertMarkerIsCreated(IResource resource, String type, String pattern, int... expectedLines) throws CoreException {
+		assertMarkerIsCreated(resource, type, pattern, true, expectedLines);
+	}
+
+	public static void assertMarkerIsCreated(IResource resource, String type, String errorMessage, boolean pattern, int... expectedLines) 
 		throws CoreException {
 
 		List<Integer> lines = findMarkerLines(
-				resource, type, pattern);
+				resource, type, errorMessage, pattern);
 
-		assertFalse("Marker  matches the '" + pattern + "' pattern wasn't found",  //$NON-NLS-1$ //$NON-NLS-2$
+		assertFalse("Marker  matches the '" + errorMessage + "' pattern wasn't found",  //$NON-NLS-1$ //$NON-NLS-2$
 				lines.isEmpty());
 
-		assertEquals("Wrong number of found marker matches the '" + pattern + "' pattern",  //$NON-NLS-1$//$NON-NLS-2$
+		assertEquals("Wrong number of found marker matches the '" + errorMessage + "' pattern",  //$NON-NLS-1$//$NON-NLS-2$
 				expectedLines.length, lines.size());
 
 		StringBuffer expectedString = new StringBuffer();
@@ -114,7 +127,7 @@
 					break;
 				}
 			}
-			assertTrue("Marker matches the '" + pattern + "' pattern was found at wrong lines. Expected: " + expectedString + " but were: " + realString,  //$NON-NLS-1$//$NON-NLS-2$
+			assertTrue("Marker matches the '" + errorMessage + "' pattern was found at wrong lines. Expected: " + expectedString + " but were: " + realString,  //$NON-NLS-1$//$NON-NLS-2$
 					found);
 		}
 	}
@@ -123,7 +136,7 @@
 			IResource resource, String type, String pattern, int lineNumber,
 			int startPosition, int endPosition) throws CoreException {
 
-		IMarker[] markers = findMarkers(resource, type, pattern);
+		IMarker[] markers = findMarkers(resource, type, pattern, true);
 		StringBuffer sb = new StringBuffer("[");
 		for (int i = 0; i < markers.length; i++) {
 			int line = markers[i].getAttribute(IMarker.LINE_NUMBER, -1);
@@ -149,8 +162,12 @@
 	}
 
 	public static void assertMarkerIsNotCreated(IResource resource, String type, String pattern, int expectedLine) throws CoreException {
-		List<Integer> lines = findMarkerLines(resource, type, pattern);
+		assertMarkerIsNotCreated(resource, type, pattern, true, expectedLine);
+	}
 
+	public static void assertMarkerIsNotCreated(IResource resource, String type, String errorMessage, boolean pattern, int expectedLine) throws CoreException {
+		List<Integer> lines = findMarkerLines(resource, type, errorMessage, pattern);
+
 		assertFalse("Marker  matches the '" + pattern + "' pattern was found", lines.contains(expectedLine)); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 



More information about the jbosstools-commits mailing list