Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 114267 Details for
Bug 249496
Need a way to add a constraint filter to any validator (live or batch)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed enhancement for constraint exclusions
bug249496.patch (text/plain), 39.30 KB, created by
Christian Damus
on 2008-10-04 19:02:30 EDT
(
hide
)
Description:
Proposed enhancement for constraint exclusions
Filename:
MIME Type:
Creator:
Christian Damus
Created:
2008-10-04 19:02:30 EDT
Size:
39.30 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.emf.validation >Index: src/org/eclipse/emf/validation/internal/service/ClientContextManager.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.validation/plugins/org.eclipse.emf.validation/src/org/eclipse/emf/validation/internal/service/ClientContextManager.java,v >retrieving revision 1.5 >diff -u -r1.5 ClientContextManager.java >--- src/org/eclipse/emf/validation/internal/service/ClientContextManager.java 15 Dec 2007 20:49:11 -0000 1.5 >+++ src/org/eclipse/emf/validation/internal/service/ClientContextManager.java 4 Oct 2008 22:42:59 -0000 >@@ -1,12 +1,13 @@ > /****************************************************************************** >- * Copyright (c) 2005, 2007 IBM Corporation and others. >+ * Copyright (c) 2005, 2008 IBM Corporation, Zeligsoft Inc., and others. > * All rights reserved. This program and the accompanying materials > * are 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: >- * IBM Corporation - initial API and implementation >+ * IBM Corporation - initial API and implementation >+ * Zeligsoft - Bug 249496 > ****************************************************************************/ > > package org.eclipse.emf.validation.internal.service; >@@ -45,8 +46,10 @@ > private static final String E_BINDING = "binding"; //$NON-NLS-1$ > private static final String A_CONTEXT = "context"; //$NON-NLS-1$ > >- private static final String A_CONSTRAINT = "constraint"; //$NON-NLS-1$ >- private static final String A_CATEGORY = "category"; //$NON-NLS-1$ >+ private static final String E_CONSTRAINT = "constraint"; //$NON-NLS-1$ >+ private static final String E_CATEGORY = "category"; //$NON-NLS-1$ >+ private static final String E_EXCLUDE_CONSTRAINT = "excludeConstraint"; //$NON-NLS-1$ >+ private static final String E_EXCLUDE_CATEGORY = "excludeCategory"; //$NON-NLS-1$ > private static final String A_REF = "ref"; //$NON-NLS-1$ > > private static final ClientContextManager INSTANCE = new ClientContextManager(); >@@ -299,7 +302,7 @@ > // add the constraint to all default contexts so that we don't do > // this computation again > for (ClientContext next : defaultContexts) { >- next.bindConstraint(id); >+ next.includeConstraint(id); > } > } > >@@ -400,47 +403,47 @@ > * @param config a particular <code><binding></config> element > */ > private void configureBindings(ClientContext context, IConfigurationElement config) { >- String id = config.getAttribute(A_CONSTRAINT); >+ String id = config.getAttribute(E_CONSTRAINT); > > if (id != null) { >- context.bindConstraint(id); >+ context.includeConstraint(id); > } > >- id = config.getAttribute(A_CATEGORY); >+ id = config.getAttribute(E_CATEGORY); > > if (id != null) { >- context.bindCategory(id); >+ context.includeCategory(id); > } > >- IConfigurationElement[] children = config.getChildren(A_CONSTRAINT); >+ IConfigurationElement[] children = config.getChildren(); > for (IConfigurationElement element : children) { >+ final String name = element.getName(); > final String ref = element.getAttribute(A_REF); > > if (ref == null) { >- Log.warningMessage( >- EMFModelValidationStatusCodes.BINDING_NO_CONSTRAINT, >- ValidationMessages.binding_noConstraintRef_WARN_, >- new Object[] { >- context.getId(), >- config.getDeclaringExtension().getNamespaceIdentifier()}); >- } else { >- context.bindConstraint(ref); >- } >- } >- >- children = config.getChildren(A_CATEGORY); >- for (IConfigurationElement element : children) { >- final String ref = element.getAttribute(A_REF); >- >- if (ref == null) { >- Log.errorMessage( >- EMFModelValidationStatusCodes.BINDING_NO_CATEGORY, >- ValidationMessages.binding_noCategoryRef_WARN_, >- new Object[] { >- context.getId(), >- config.getDeclaringExtension().getNamespaceIdentifier()}); >- } else { >- context.bindCategory(ref); >+ if (E_CONSTRAINT.equals(name) || E_EXCLUDE_CONSTRAINT.equals(name)) { >+ Log.warningMessage( >+ EMFModelValidationStatusCodes.BINDING_NO_CONSTRAINT, >+ ValidationMessages.binding_noConstraintRef_WARN_, >+ new Object[] { >+ context.getId(), >+ config.getDeclaringExtension().getNamespaceIdentifier()}); >+ } else { >+ Log.errorMessage( >+ EMFModelValidationStatusCodes.BINDING_NO_CATEGORY, >+ ValidationMessages.binding_noCategoryRef_WARN_, >+ new Object[] { >+ context.getId(), >+ config.getDeclaringExtension().getNamespaceIdentifier()}); >+ } >+ } else if (E_CONSTRAINT.equals(name)) { >+ context.includeConstraint(ref); >+ } else if (E_CATEGORY.equals(name)) { >+ context.includeCategory(ref); >+ } else if (E_EXCLUDE_CONSTRAINT.equals(name)) { >+ context.excludeConstraint(ref); >+ } else if (E_EXCLUDE_CATEGORY.equals(name)) { >+ context.excludeCategory(ref); > } > } > } >Index: src/org/eclipse/emf/validation/internal/service/ClientContext.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.validation/plugins/org.eclipse.emf.validation/src/org/eclipse/emf/validation/internal/service/ClientContext.java,v >retrieving revision 1.5 >diff -u -r1.5 ClientContext.java >--- src/org/eclipse/emf/validation/internal/service/ClientContext.java 24 Apr 2008 00:47:58 -0000 1.5 >+++ src/org/eclipse/emf/validation/internal/service/ClientContext.java 4 Oct 2008 22:42:50 -0000 >@@ -1,25 +1,25 @@ > /****************************************************************************** >- * Copyright (c) 2005, 2007 IBM Corporation and others. >+ * Copyright (c) 2005, 2008 IBM Corporation, Zeligsoft Inc., and others. > * All rights reserved. This program and the accompanying materials > * are 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: >- * IBM Corporation - initial API and implementation >+ * IBM Corporation - initial API and implementation >+ * Zeligsoft - Bug 249496 > ****************************************************************************/ > > package org.eclipse.emf.validation.internal.service; > > import java.util.Collection; >-import java.util.Iterator; >+import java.util.Map; > import java.util.Set; > > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IConfigurationElement; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; >- > import org.eclipse.emf.validation.internal.EMFModelValidationPlugin; > import org.eclipse.emf.validation.internal.EMFModelValidationStatusCodes; > import org.eclipse.emf.validation.internal.l10n.ValidationMessages; >@@ -52,11 +52,13 @@ > private final IClientSelector selector; > private final boolean isDefault; > >- // set of String constraint IDs that are bound to me >- private final Set<String> constraintBindings = new java.util.HashSet<String>(); >+ // map of String constraint IDs that are bound to me, the boolean value >+ // indicating absolute inclusion or exclusion. Absence of a value means >+ // that we still need to compute >+ private final Map<String, Boolean> constraintBindings = new java.util.HashMap<String, Boolean>(); > > // set of String category IDs that are bound to me >- private final Set<String> categoryBindings = new java.util.HashSet<String>(); >+ private BindingFilter filter = BindingFilter.NULL; > > /** > * Initializes me with my XML configuration. >@@ -235,21 +237,19 @@ > } > > public boolean includes(IModelConstraint constraint) { >- boolean result = false; >+ Boolean result; > > IConstraintDescriptor descriptor = constraint.getDescriptor(); > >- if (descriptor != null) { >- result = constraintBindings.contains(descriptor.getId()); >+ if (descriptor == null) { >+ result = Boolean.FALSE; >+ } else { >+ result = constraintBindings.get(descriptor.getId()); > >- if (!result && !categoryBindings.isEmpty()) { >- // look for a bound category >- result = hasCategoryBinding(descriptor.getCategories()); >- >- if (result) { >- // cache the result for this constraint >- bindConstraint(descriptor.getId()); >- } >+ if (result == null) { >+ // cache the result for this constraint >+ result = filter.getBinding(descriptor); >+ constraintBindings.put(descriptor.getId(), result); > } > } > >@@ -257,58 +257,41 @@ > } > > /** >- * Determines whether any of the specified <code>categories</code> is bound >- * to me. >+ * Adds a constraint inclusion binding to me. > * >- * @param categories a collection of categories (usually from a constraint) >- * @return <code>true</code> if any of the <code>categories</code> is bound, >- * or if any of their ancestors is bound; <code>false</code>, otherwise >+ * @param constraintId the ID of a constraint that is to be included in me > */ >- private boolean hasCategoryBinding(Collection<Category> categories) { >- boolean result = false; >- >- for (Iterator<Category> iter = categories.iterator(); !result && iter.hasNext();) { >- Category category = iter.next(); >- >- result = categoryBindings.contains(category.getPath()); >- >- if (!result) { >- // search the ancestors >- Category ancestor = category.getParent(); >- >- while ((ancestor != null) && !result) { >- result = categoryBindings.contains(ancestor.getPath()); >- ancestor = ancestor.getParent(); >- } >- >- if (result) { >- // cache the original category for quicker results on the >- // next constraint that it includes >- bindCategory(category.getPath()); >- } >- } >- } >- >- return result; >+ void includeConstraint(String constraintId) { >+ filter = filter.includeConstraint(constraintId); >+ } >+ >+ /** >+ * Adds a constraint exclusion binding to me. >+ * >+ * @param constraintId the ID of a constraint that is to be excluded from me >+ */ >+ void excludeConstraint(String constraintId) { >+ filter = filter.excludeConstraint(constraintId); > } > > /** >- * Binds a constraint to me. >+ * Adds a constraint category inclusion to me. > * >- * @param constraintId the ID of a constraint that is to be bound to me >+ * @param categoryId the qualified ID (path) of a constraint category that >+ * is to be included in me > */ >- void bindConstraint(String constraintId) { >- constraintBindings.add(constraintId); >+ void includeCategory(String categoryId) { >+ filter = filter.includeCategory(categoryId); > } > > /** >- * Binds a constraint category to me. >+ * Adds a constraint category exclusion to me. > * > * @param categoryId the qualified ID (path) of a constraint category that >- * is to be bound to me >+ * is to be excluded from me > */ >- void bindCategory(String categoryId) { >- categoryBindings.add(categoryId); >+ void excludeCategory(String categoryId) { >+ filter = filter.excludeCategory(categoryId); > } > > /** >@@ -332,4 +315,296 @@ > public String toString() { > return "ClientContext[" + getId() + ']'; //$NON-NLS-1$ > } >+ >+ >+ /** >+ * A chain-structured constraint-binding filter. Filters are chained in >+ * the order in which they are parsed from the extension point. The head of >+ * the filter chain applies its filter and, if it doesn't find any match, >+ * delegates down the chain. The chain is terminated by the {@link #NULL} >+ * filter, which always excludes the constraint. >+ * >+ * @author Christian W. Damus (cdamus) >+ */ >+ private static class BindingFilter { >+ private BindingFilter next; >+ >+ /** A filter that excludes every constraint. */ >+ static final BindingFilter NULL = new BindingFilter() { >+ boolean getBinding(IConstraintDescriptor constraint) {return false;} >+ }; >+ >+ /** >+ * Queries whether the specified constraint is definitely included >+ * (<code>true</code>) or excluded (<code>false</code>) from the client >+ * context. If I don't have definitive knowledge of this constraint, >+ * I delegate to the next in the chain. >+ * >+ * @param constraint a constraint descriptor >+ * @return whether the constraint is included >+ */ >+ boolean getBinding(IConstraintDescriptor constraint) { >+ return isExcluded(constraint) >+ ? false >+ : isIncluded(constraint) >+ ? true >+ : next().getBinding(constraint); >+ } >+ >+ /** >+ * Queries whether I know that a constraint is included. >+ * >+ * @param constraint a constraint descriptor >+ * @return <code>true</code> if the constraint is included, or >+ * <code>false</code> if I do not know >+ */ >+ boolean isExcluded(IConstraintDescriptor constraint) { >+ return false; >+ } >+ >+ /** >+ * Queries whether I know that a constraint is excluded. >+ * >+ * @param constraint a constraint descriptor >+ * @return <code>true</code> if the constraint is excluded, or >+ * <code>false</code> if I do not know >+ */ >+ boolean isIncluded(IConstraintDescriptor constraint) { >+ return false; >+ } >+ >+ /** >+ * Obtains the next filter in my chain. >+ * >+ * @return my next, or <code>null</code> if I am the end of the chain >+ */ >+ BindingFilter next() { >+ return next; >+ } >+ >+ /** >+ * Assigns my next filter. >+ * >+ * @param next my new next >+ */ >+ void setNext(BindingFilter next) { >+ this.next = next; >+ } >+ >+ /** >+ * Obtains a filter, chaining me, that definitively includes the >+ * specified category and all of its constraints and sub-categories. The >+ * result may be optimized to be myself augmented with this category, if >+ * I am a filter of the appropriate kind. Or, the result may be a new >+ * filter chain. >+ * >+ * @param category >+ * a category to include >+ * >+ * @return a filter that includes the category >+ */ >+ BindingFilter includeCategory(String category) { >+ CategoryInclusion result = new CategoryInclusion(category); >+ result.setNext(this); >+ return result; >+ } >+ >+ /** >+ * Obtains a filter, chaining me, that definitively excludes the >+ * specified category and all of its constraints and sub-categories. The >+ * result may be optimized to be myself augmented with this category, if >+ * I am a filter of the appropriate kind. Or, the result may be a new >+ * filter chain. >+ * >+ * @param category >+ * a category to exclude >+ * >+ * @return a filter that excludes the category >+ */ >+ BindingFilter excludeCategory(String category) { >+ CategoryExclusion result = new CategoryExclusion(category); >+ result.setNext(this); >+ return result; >+ } >+ >+ /** >+ * Obtains a filter, chaining me, that definitively includes the >+ * specified constraint. The result may be optimized to be myself >+ * augmented with this category, if I am a filter of the appropriate >+ * kind. Or, the result may be a new filter chain. >+ * >+ * @param constraint >+ * a constraint to include >+ * >+ * @return a filter that includes the constraint >+ */ >+ BindingFilter includeConstraint(String constraint) { >+ ConstraintInclusion result = new ConstraintInclusion(constraint); >+ result.setNext(this); >+ return result; >+ } >+ >+ /** >+ * Obtains a filter, chaining me, that definitively excludes the >+ * specified constraint. The result may be optimized to be myself >+ * augmented with this category, if I am a filter of the appropriate >+ * kind. Or, the result may be a new filter chain. >+ * >+ * @param constraint >+ * a constraint to exclude >+ * >+ * @return a filter that excludes the constraint >+ */ >+ BindingFilter excludeConstraint(String constraint) { >+ ConstraintExclusion result = new ConstraintExclusion(constraint); >+ result.setNext(this); >+ return result; >+ } >+ } >+ >+ /** >+ * A binding filter that definitively includes one or more constraints. >+ * >+ * @author Christian W. Damus (cdamus) >+ */ >+ private static class ConstraintInclusion extends BindingFilter { >+ private final Set<String> constraints = new java.util.HashSet<String>(); >+ >+ ConstraintInclusion(String constraint) { >+ constraints.add(constraint); >+ } >+ >+ @Override >+ boolean isIncluded(IConstraintDescriptor constraint) { >+ return constraints.contains(constraint.getId()); >+ } >+ >+ @Override >+ BindingFilter includeConstraint(String constraint) { >+ constraints.add(constraint); >+ return this; >+ } >+ } >+ >+ /** >+ * A binding filter that definitively excludes one or more constraints. >+ * >+ * @author Christian W. Damus (cdamus) >+ */ >+ private static class ConstraintExclusion extends BindingFilter { >+ private final Set<String> constraints = new java.util.HashSet<String>(); >+ >+ ConstraintExclusion(String constraint) { >+ constraints.add(constraint); >+ } >+ >+ @Override >+ boolean isExcluded(IConstraintDescriptor constraint) { >+ return constraints.contains(constraint.getId()); >+ } >+ >+ @Override >+ BindingFilter excludeConstraint(String constraint) { >+ constraints.add(constraint); >+ return this; >+ } >+ } >+ >+ /** >+ * A binding filter that definitively includes one or more categories. >+ * >+ * @author Christian W. Damus (cdamus) >+ */ >+ private static class CategoryInclusion extends BindingFilter { >+ private final CategorySet categories; >+ >+ CategoryInclusion(String category) { >+ categories = new CategorySet(category); >+ } >+ >+ @Override >+ boolean isIncluded(IConstraintDescriptor constraint) { >+ return categories.containsAny(constraint.getCategories()); >+ } >+ >+ @Override >+ BindingFilter includeCategory(String category) { >+ categories.add(category); >+ return this; >+ } >+ } >+ >+ /** >+ * A binding filter that definitively excludes one or more categories. >+ * >+ * @author Christian W. Damus (cdamus) >+ */ >+ private static class CategoryExclusion extends BindingFilter { >+ private final CategorySet categories; >+ >+ CategoryExclusion(String category) { >+ categories = new CategorySet(category); >+ } >+ >+ @Override >+ boolean isExcluded(IConstraintDescriptor constraint) { >+ return categories.containsAny(constraint.getCategories()); >+ } >+ >+ @Override >+ BindingFilter excludeCategory(String category) { >+ categories.add(category); >+ return this; >+ } >+ } >+ >+ private static final class CategorySet { >+ private final Set<String> categories = new java.util.HashSet<String>(); >+ >+ CategorySet(String category) { >+ categories.add(category); >+ } >+ >+ boolean containsAny(Collection<? extends Category> categories) { >+ boolean result = false; >+ >+ for (Category next : categories) { >+ if (contains(next)) { >+ result = true; >+ break; >+ } >+ } >+ >+ return result; >+ } >+ >+ boolean contains(Category category) { >+ boolean result = false; >+ >+ String path = category.getPath(); >+ result = categories.contains(path); >+ >+ if (!result) { >+ // search the ancestors >+ Category ancestor = category.getParent(); >+ >+ while ((ancestor != null) && !result) { >+ result = categories.contains(ancestor.getPath()); >+ ancestor = ancestor.getParent(); >+ } >+ >+ if (result) { >+ // cache the original category for quicker results on the >+ // next category that it contains >+ add(path); >+ } >+ } >+ >+ return result; >+ } >+ >+ void add(String category) { >+ categories.add(category); >+ } >+ } > } >Index: schema/constraintBindings.exsd >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.validation/plugins/org.eclipse.emf.validation/schema/constraintBindings.exsd,v >retrieving revision 1.4 >diff -u -r1.4 constraintBindings.exsd >--- schema/constraintBindings.exsd 29 Mar 2007 22:54:06 -0000 1.4 >+++ schema/constraintBindings.exsd 4 Oct 2008 22:42:50 -0000 >@@ -1,10 +1,10 @@ > <?xml version='1.0' encoding='UTF-8'?> > <!-- Schema file written by PDE --> >-<schema targetNamespace="org.eclipse.emf.validation"> >+<schema targetNamespace="org.eclipse.emf.validation" xmlns="http://www.w3.org/2001/XMLSchema"> > <annotation> >- <appInfo> >+ <appinfo> > <meta.schema plugin="org.eclipse.emf.validation" id="constraintBindings" name="EMF Validation Constraint Bindings"/> >- </appInfo> >+ </appinfo> > <documentation> > This extension point allows clients of the EMF Validation > framework to define "client contexts" that describe the >@@ -17,6 +17,11 @@ > <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/> > > <element name="extension"> >+ <annotation> >+ <appinfo> >+ <meta.element /> >+ </appinfo> >+ </annotation> > <complexType> > <sequence> > <element ref="clientContext" minOccurs="0" maxOccurs="unbounded"/> >@@ -41,9 +46,9 @@ > <documentation> > > </documentation> >- <appInfo> >+ <appinfo> > <meta.attribute translatable="true"/> >- </appInfo> >+ </appinfo> > </annotation> > </attribute> > </complexType> >@@ -51,9 +56,9 @@ > > <element name="clientContext"> > <annotation> >- <appInfo> >+ <appinfo> > <meta.element labelAttribute="id"/> >- </appInfo> >+ </appinfo> > <documentation> > <p> > Definition of a client context, representing a class of >@@ -110,9 +115,9 @@ > Identifies a class implementing the <code>org.eclipse.emf.validation.internal.model.IClientSelector</code> > internal API interface. > </documentation> >- <appInfo> >+ <appinfo> > <meta.attribute kind="java" basedOn="org.eclipse.emf.validation.internal.model.IClientSelector"/> >- </appInfo> >+ </appinfo> > </annotation> > </attribute> > </complexType> >@@ -120,9 +125,9 @@ > > <element name="binding"> > <annotation> >- <appInfo> >+ <appinfo> > <meta.element labelAttribute="context"/> >- </appInfo> >+ </appinfo> > <documentation> > <p> > Declares a binding between a client context and one or more >@@ -131,6 +136,7 @@ > </p> > <p> > The constraints to be bound may be specified by either: >+</p> > <ul> > <li>the <code>constraint</code> attribute, to reference > a single constraint</li> >@@ -141,13 +147,19 @@ > and/or <code>&lt;category&gt;</code> elements to > reference multiple constraints and/or categories</li> > </ul> >+<p> >+Since the 1.3 release, selective exclusion of constraints and sub-categories that are contained by included categories is supported. Within a <code>&lt;binding&gt;</code> element, ordering of inclusion and exclusion elements is significant: they are processed in the order in which they are declared in the extension. However, the order of inclusions and exclusions in separate bindings for the same context is undefined. > </p> > </documentation> > </annotation> > <complexType> > <sequence> >- <element ref="constraint" minOccurs="0" maxOccurs="unbounded"/> >- <element ref="category" minOccurs="0" maxOccurs="unbounded"/> >+ <choice minOccurs="0" maxOccurs="unbounded"> >+ <element ref="category"/> >+ <element ref="constraint"/> >+ <element ref="excludeCategory"/> >+ <element ref="excludeConstraint"/> >+ </choice> > </sequence> > <attribute name="context" type="string" use="required"> > <annotation> >@@ -185,9 +197,9 @@ > > <element name="constraint"> > <annotation> >- <appInfo> >+ <appinfo> > <meta.element labelAttribute="ref"/> >- </appInfo> >+ </appinfo> > <documentation> > Includes a constraint in a client context > <code>&lt;binding&gt;</code>. >@@ -209,9 +221,9 @@ > > <element name="category"> > <annotation> >- <appInfo> >+ <appinfo> > <meta.element labelAttribute="ref"/> >- </appInfo> >+ </appinfo> > <documentation> > Includes a constraint category in a client context > <code>&lt;binding&gt;</code>. All of the referenced >@@ -233,19 +245,63 @@ > </complexType> > </element> > >+ <element name="excludeCategory"> >+ <annotation> >+ <documentation> >+ Since 1.3. Excludes a constraint category from a client context >+<code>&lt;binding&gt;</code>. All of the referenced >+category's constraints and those of any sub-categories >+(recursively) are excluded. This is useful when including some parent category, to filter out selective sub-categories. Not only is it simpler than explicitly including all of the desired sub-categories, but it ensures that sub-categories that are added later will be included implicitly. >+ </documentation> >+ </annotation> >+ <complexType> >+ <attribute name="ref" type="string" use="required"> >+ <annotation> >+ <documentation> >+ References the fully-qualified ID of a constraint category to >+exclude from the client context. The category ID does not >+necessarily include its contributing plug-in ID, but is a >+path reflecting the hierarchical structure of categories. >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="excludeConstraint"> >+ <annotation> >+ <documentation> >+ Since 1.3. Excludes a constraint from a client context >+<code>&lt;binding&gt;</code>. This is useful when including some parent category, to filter out selective constraints cointained within it. Not only is it simpler than explicitly including all of the desired constraints and sub-categories, but it ensures that constraints and sub-categories that are added later will be included implicitly. >+ </documentation> >+ </annotation> >+ <complexType> >+ <attribute name="ref" type="string" use="required"> >+ <annotation> >+ <documentation> >+ References the fully-qualified ID of a constraint to exclude >+from the client context. The ID includes the constraint's >+contributing plug-in ID, if it is not explicit in the XML >+definition of the constraint. >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ > <annotation> >- <appInfo> >+ <appinfo> > <meta.section type="since"/> >- </appInfo> >+ </appinfo> > <documentation> > 1.0 > </documentation> > </annotation> > > <annotation> >- <appInfo> >+ <appinfo> > <meta.section type="examples"/> >- </appInfo> >+ </appinfo> > <documentation> > <p> > Example of a context which includes <code>EObjects</code> in *.library resources only, not >@@ -291,30 +347,14 @@ > </documentation> > </annotation> > >- <annotation> >- <appInfo> >- <meta.section type="apiInfo"/> >- </appInfo> >- <documentation> >- >- </documentation> >- </annotation> > >- <annotation> >- <appInfo> >- <meta.section type="implementation"/> >- </appInfo> >- <documentation> >- >- </documentation> >- </annotation> > > <annotation> >- <appInfo> >+ <appinfo> > <meta.section type="copyright"/> >- </appInfo> >+ </appinfo> > <documentation> >- Copyright (c) 2005 IBM Corporation and others.<br> >+ Copyright (c) 2005, 2008 IBM Corporation, Zeligsoft Inc., and others.<br> > All rights reserved. This program and the accompanying materials > are made available under the terms of the Eclipse Public License v1.0 > which accompanies this distribution, and is available at >#P org.eclipse.emf.validation.tests >Index: src/org/eclipse/emf/validation/internal/service/impl/tests/AllTests.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.validation/tests/org.eclipse.emf.validation.tests/src/org/eclipse/emf/validation/internal/service/impl/tests/AllTests.java,v >retrieving revision 1.3 >diff -u -r1.3 AllTests.java >--- src/org/eclipse/emf/validation/internal/service/impl/tests/AllTests.java 10 Oct 2006 14:31:05 -0000 1.3 >+++ src/org/eclipse/emf/validation/internal/service/impl/tests/AllTests.java 4 Oct 2008 22:43:03 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2003, 2006 IBM Corporation and others. >+ * Copyright (c) 2003, 2008 IBM Corporation, Zeligsoft Inc., and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -9,6 +9,7 @@ > * > * Contributors: > * IBM - Initial API and implementation >+ * Zeligsoft - Bug 249496 > * > * </copyright> > * >@@ -43,5 +44,7 @@ > > addTestSuite(BatchValidatorTest.class); > addTestSuite(LiveValidatorTest.class); >+ >+ addTest(ClientContextTest.suite()); > } > } >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.validation/tests/org.eclipse.emf.validation.tests/plugin.xml,v >retrieving revision 1.11 >diff -u -r1.11 plugin.xml >--- plugin.xml 31 Oct 2007 19:58:44 -0000 1.11 >+++ plugin.xml 4 Oct 2008 22:43:03 -0000 >@@ -470,4 +470,96 @@ > </eclass> > </traversalStrategy> > </extension> >+ >+ <!-- Constraints only used for client-context inclusion/exclusion testing --> >+ <extension name="Contraints for client-context testing" point="org.eclipse.emf.validation.constraintProviders"> >+ <category id="clientContextTest" name="JUnit Client Context Testing Context"/> >+ <category id="clientContextTest/one" name="First level of nesting"/> >+ <category id="clientContextTest/one/two" name="Second level of nesting"/> >+ <category id="clientContextTest/one/twoA" name="Second level of nesting (A)"/> >+ <category id="clientContextTest/one/two/three" name="Third level of nesting"/> >+ <category id="clientContextTest/one/two/threeA" name="Third level of nesting (A)"/> >+ <constraintProvider> >+ <package namespaceUri="http://www.eclipse.org/emf/2002/Ecore" /> >+ <constraints categories="clientContextTest/one"> >+ <constraint name="Dummy1.1" statusCode="1" lang="OCL" id="clientContext.1.1"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ <constraint name="Dummy1.2" statusCode="1" lang="OCL" id="clientContext.1.2"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ </constraints> >+ <constraints categories="clientContextTest/one/two"> >+ <constraint name="Dummy2.1" statusCode="1" lang="OCL" id="clientContext.2.1"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ <constraint name="Dummy2.2" statusCode="1" lang="OCL" id="clientContext.2.2"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ </constraints> >+ <constraints categories="clientContextTest/one/twoA"> >+ <constraint name="Dummy2a.1" statusCode="1" lang="OCL" id="clientContext.2a.1"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ <constraint name="Dummy2a.2" statusCode="1" lang="OCL" id="clientContext.2a.2"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ </constraints> >+ <constraints categories="clientContextTest/one/two/three"> >+ <constraint name="Dummy3.1" statusCode="1" lang="OCL" id="clientContext.3.1"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ <constraint name="Dummy3.2" statusCode="1" lang="OCL" id="clientContext.3.2"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ </constraints> >+ <constraints categories="clientContextTest/one/two/threeA"> >+ <constraint name="Dummy3a.1" statusCode="1" lang="OCL" id="clientContext.3a.1"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ <constraint name="Dummy3a.2" statusCode="1" lang="OCL" id="clientContext.3a.2"> >+ <message>Nothing to say.</message> >+ <target class="EAnnotation"/> >+ true >+ </constraint> >+ </constraints> >+ </constraintProvider> >+ </extension> >+ <!-- A client-context only used for inclusion/exclusion testing --> >+ <extension point="org.eclipse.emf.validation.constraintBindings"> >+ <clientContext >+ id="org.eclipse.emf.validation.tests.testcontext"> >+ <!-- We are never enabled --> >+ <enablement> >+ <systemTest property="BOGUS_SYSTEM_PROPERTY" value="1"/> >+ </enablement> >+ </clientContext> >+ <binding context="org.eclipse.emf.validation.tests.testcontext"> >+ <category ref="clientContextTest/one"/> >+ <excludeCategory ref="clientContextTest/one/two"/> >+ <category ref="clientContextTest/one/two/three"/> >+ <excludeConstraint ref="org.eclipse.emf.validation.tests.clientContext.1.1"/> >+ <excludeConstraint ref="org.eclipse.emf.validation.tests.clientContext.2a.1"/> >+ <constraint ref="org.eclipse.emf.validation.tests.clientContext.2.2"/> >+ <constraint ref="org.eclipse.emf.validation.tests.clientContext.3a.2"/> >+ </binding> >+ </extension> > </plugin> >Index: src/org/eclipse/emf/validation/internal/service/impl/tests/ClientContextTest.java >=================================================================== >RCS file: src/org/eclipse/emf/validation/internal/service/impl/tests/ClientContextTest.java >diff -N src/org/eclipse/emf/validation/internal/service/impl/tests/ClientContextTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/validation/internal/service/impl/tests/ClientContextTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,156 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2008 Zeligsoft Inc. and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Zeligsoft - Initial API and implementation >+ * >+ * </copyright> >+ * >+ * $Id$ >+ */ >+ >+package org.eclipse.emf.validation.internal.service.impl.tests; >+ >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.emf.ecore.EcoreFactory; >+import org.eclipse.emf.validation.IValidationContext; >+import org.eclipse.emf.validation.internal.service.ClientContext; >+import org.eclipse.emf.validation.internal.service.ClientContextManager; >+import org.eclipse.emf.validation.internal.service.IClientContext; >+import org.eclipse.emf.validation.model.EvaluationMode; >+import org.eclipse.emf.validation.model.IModelConstraint; >+import org.eclipse.emf.validation.service.ConstraintRegistry; >+import org.eclipse.emf.validation.service.IConstraintDescriptor; >+import org.eclipse.emf.validation.service.ModelValidationService; >+ >+/** >+ * Tests the {@link ClientContext} class. >+ * >+ * @author Christian W. Damus (cdamus) >+ */ >+@SuppressWarnings("nls") >+public class ClientContextTest >+ extends TestCase { >+ >+ private IModelConstraint constraint1_1; >+ >+ private IModelConstraint constraint1_2; >+ >+ private IModelConstraint constraint2_1; >+ >+ private IModelConstraint constraint2_2; >+ >+ private IModelConstraint constraint2a_1; >+ >+ private IModelConstraint constraint2a_2; >+ >+ private IModelConstraint constraint3_1; >+ >+ private IModelConstraint constraint3_2; >+ >+ private IModelConstraint constraint3a_1; >+ >+ private IModelConstraint constraint3a_2; >+ >+ private IClientContext fixture; >+ >+ /** >+ * Initialize me with my name. >+ * >+ * @param name >+ * my name >+ */ >+ public ClientContextTest(String name) { >+ super(name); >+ } >+ >+ public static Test suite() { >+ return new TestSuite(ClientContextTest.class, "Client context tests"); >+ } >+ >+ public void test_includedChildOfExcludedCategory() { >+ assertTrue("Constraint is excluded", fixture.includes(constraint3_1)); >+ assertTrue("Constraint is excluded", fixture.includes(constraint3_2)); >+ } >+ >+ public void test_constraintExcludedFromIncludedCategory() { >+ assertFalse("Constraint is included", fixture.includes(constraint1_1)); >+ assertTrue("Constraint is excluded", fixture.includes(constraint1_2)); >+ } >+ >+ public void test_constraintIncludedInExcludedCategory() { >+ assertFalse("Constraint is included", fixture.includes(constraint2_1)); >+ assertTrue("Constraint is excluded", fixture.includes(constraint2_2)); >+ } >+ >+ public void test_constraintExcludedFromIncludedCategory_nested() { >+ assertFalse("Constraint is included", fixture.includes(constraint2a_1)); >+ assertTrue("Constraint is excluded", fixture.includes(constraint2a_2)); >+ } >+ >+ public void test_constraintIncludedInExcludedCategory_nested() { >+ assertFalse("Constraint is included", fixture.includes(constraint3a_1)); >+ assertTrue("Constraint is excluded", fixture.includes(constraint3a_2)); >+ } >+ >+ // >+ // Test framework >+ // >+ >+ @Override >+ protected void setUp() >+ throws Exception { >+ >+ super.setUp(); >+ >+ fixture = ClientContextManager.getInstance().getClientContext( >+ "org.eclipse.emf.validation.tests.testcontext"); >+ >+ final String prefix = "org.eclipse.emf.validation.tests.clientContext."; >+ final ConstraintRegistry reg = ConstraintRegistry.getInstance(); >+ >+ // cause our test constraints to be created >+ ModelValidationService.getInstance().newValidator(EvaluationMode.BATCH) >+ .validate(EcoreFactory.eINSTANCE.createEAnnotation()); >+ >+ constraint1_1 = new TestConstraint(reg.getDescriptor(prefix + "1.1")); >+ constraint1_2 = new TestConstraint(reg.getDescriptor(prefix + "1.2")); >+ constraint2_1 = new TestConstraint(reg.getDescriptor(prefix + "2.1")); >+ constraint2_2 = new TestConstraint(reg.getDescriptor(prefix + "2.2")); >+ constraint2a_1 = new TestConstraint(reg.getDescriptor(prefix + "2a.1")); >+ constraint2a_2 = new TestConstraint(reg.getDescriptor(prefix + "2a.2")); >+ constraint3_1 = new TestConstraint(reg.getDescriptor(prefix + "3.1")); >+ constraint3_2 = new TestConstraint(reg.getDescriptor(prefix + "3.2")); >+ constraint3a_1 = new TestConstraint(reg.getDescriptor(prefix + "3a.1")); >+ constraint3a_2 = new TestConstraint(reg.getDescriptor(prefix + "3a.2")); >+ } >+ >+ private static final class TestConstraint >+ implements IModelConstraint { >+ >+ private IConstraintDescriptor desc; >+ >+ TestConstraint(IConstraintDescriptor desc) { >+ this.desc = desc; >+ } >+ >+ public IStatus validate(IValidationContext c) { >+ return Status.OK_STATUS; >+ } >+ >+ public IConstraintDescriptor getDescriptor() { >+ return desc; >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 249496
:
114267
|
114617
|
115192