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 147449 Details for
Bug 255786
Investigate support for Constraints directly annotated to Ecore
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]
final (hopefully) patch
255786.patch (text/plain), 75.49 KB, created by
Kenn Hussey
on 2009-09-17 11:34:07 EDT
(
hide
)
Description:
final (hopefully) patch
Filename:
MIME Type:
Creator:
Kenn Hussey
Created:
2009-09-17 11:34:07 EDT
Size:
75.49 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.emf.codegen.ecore >Index: templates/model/ValidatorClass.javajet >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/templates/model/ValidatorClass.javajet,v >retrieving revision 1.33 >diff -u -r1.33 ValidatorClass.javajet >--- templates/model/ValidatorClass.javajet 7 Jan 2009 01:58:23 -0000 1.33 >+++ templates/model/ValidatorClass.javajet 17 Sep 2009 15:34:48 -0000 >@@ -3,7 +3,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2006 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -284,6 +284,16 @@ > > <%}%> > <%}%> >+<%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && genClassifier.hasValidationExpression(constraint)) {%> >+ /** >+ * The cached validation expression for the <%=constraint%> constraint of '<em><%=genClassifier.getFormattedName()%></em>'. >+ * <!-- begin-user-doc --> >+ * <!-- end-user-doc --> >+ * @generated >+ */ >+ protected static final <%=genModel.getImportedName("java.lang.String")%> <%=genClassifier.getClassifierID()%>__<%=CodeGenUtil.upperName(constraint)%>__EEXPRESSION = "<%=genClassifier.getValidationExpression(constraint, genModel.getIndentation(stringBuffer))%>";<%=genModel.getNonNLS()%> >+ >+<%}%> > /** > * Validates the <%=constraint%> constraint of '<em><%=genClassifier.getFormattedName()%></em>'. > * <!-- begin-user-doc --> >@@ -481,6 +491,20 @@ > } > return <%=delegate%>validate<%=constraintDelegate.getName()%>_<%=constraint%>(<%=genClassifier.getSafeUncapName()%><%=accessor%>, <%=diagnostics%>, <%=context%>); > <%} else {%> >+ <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && genClassifier.hasValidationExpression(constraint)) {%> >+ return >+ validate >+ (<%=genClassifier.getQualifiedClassifierAccessor()%>, >+ <%=genClassifier.getSafeUncapName()%>, >+ <%=diagnostics%>, >+ <%=context%>, >+ "<%=genClassifier.getValidationDelegate(constraint)%>",<%=genModel.getNonNLS()%> >+ "<%=constraint%>",<%=genModel.getNonNLS()%> >+ <%=genClassifier.getClassifierID()%>__<%=CodeGenUtil.upperName(constraint)%>__EEXPRESSION, >+ <%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR, >+ DIAGNOSTIC_SOURCE, >+ 0); >+ <%} else {%> > // TODO implement the constraint > // -> specify the condition that violates the constraint > // -> verify the diagnostic details, including severity, code, and message >@@ -490,7 +514,7 @@ > if (<%=diagnostics%> != null) > { > <%=diagnostics%>.add >-<%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%> >+ <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%> > (createDiagnostic > (<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR, > DIAGNOSTIC_SOURCE, >@@ -499,18 +523,19 @@ > new Object[] { "<%=constraint%>", getValueLabel(<%=genDataType.getQualifiedClassifierAccessor()%>, <%=genClassifier.getSafeUncapName()%>, <%=context%>) },<%=genModel.getNonNLS()%> > new Object[] { <%=genClassifier.getSafeUncapName()%> }, > context)); >-<%} else {%> >+ <%} else {%> > (new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%> > (<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR, > DIAGNOSTIC_SOURCE, > 0, > <%=genModel.getImportedName("org.eclipse.emf.ecore.plugin.EcorePlugin")%>.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { "<%=constraint%>", getValueLabel(<%=genDataType.getQualifiedClassifierAccessor()%>, <%=genClassifier.getSafeUncapName()%>, <%=context%>) }),<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%> > new Object[] { <%=genClassifier.getSafeUncapName()%> })); >-<%}%> >+ <%}%> > } > return false; > } > return true; >+ <%}%> > <%}%> > <%} else if (constraintDelegate != null) {%> > // TODO override the constraint, if desired >@@ -523,7 +548,7 @@ > if (<%=diagnostics%> != null) > { > <%=diagnostics%>.add >-<%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%> >+ <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%> > (createDiagnostic > (<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR, > DIAGNOSTIC_SOURCE, >@@ -532,14 +557,14 @@ > new Object[] { "<%=constraint%>", getObjectLabel(<%=genClassifier.getSafeUncapName()%>, <%=context%>) },<%=genModel.getNonNLS()%> > new Object[] { <%=genClassifier.getSafeUncapName()%> }, > context)); >-<%} else {%> >+ <%} else {%> > (new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%> > (<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR, > DIAGNOSTIC_SOURCE, > 0, > <%=genModel.getImportedName("org.eclipse.emf.ecore.plugin.EcorePlugin")%>.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { "<%=constraint%>", getObjectLabel(<%=genClassifier.getSafeUncapName()%>, <%=context%>) }),<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%> > new Object[] { <%=genClassifier.getSafeUncapName()%> })); >-<%}%> >+ <%}%> > } > return false; > } >@@ -547,6 +572,20 @@ > <%} else { GenOperation genOperation = ((GenClass)genClassifier).getInvariantOperation(constraint); if (genOperation != null) {%> > return <%=genClassifier.getSafeUncapName()%>.<%=constraint%>(<%=diagnostics%>, <%=context%>); > <%} else {%> >+ <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && genClassifier.hasValidationExpression(constraint)) {%> >+ return >+ validate >+ (<%=genClassifier.getQualifiedClassifierAccessor()%>, >+ <%=genClassifier.getSafeUncapName()%>, >+ <%=diagnostics%>, >+ <%=context%>, >+ "<%=genClassifier.getValidationDelegate(constraint)%>",<%=genModel.getNonNLS()%> >+ "<%=constraint%>",<%=genModel.getNonNLS()%> >+ <%=genClassifier.getClassifierID()%>__<%=CodeGenUtil.upperName(constraint)%>__EEXPRESSION, >+ <%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR, >+ DIAGNOSTIC_SOURCE, >+ 0); >+ <%} else {%> > // TODO implement the constraint > // -> specify the condition that violates the constraint > // -> verify the diagnostic details, including severity, code, and message >@@ -556,7 +595,7 @@ > if (<%=diagnostics%> != null) > { > <%=diagnostics%>.add >-<%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%> >+ <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%> > (createDiagnostic > (<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR, > DIAGNOSTIC_SOURCE, >@@ -565,18 +604,19 @@ > new Object[] { "<%=constraint%>", getObjectLabel(<%=genClassifier.getSafeUncapName()%>, <%=context%>) },<%=genModel.getNonNLS()%> > new Object[] { <%=genClassifier.getSafeUncapName()%> }, > context)); >-<%} else {%> >+ <%} else {%> > (new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%> > (<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR, > DIAGNOSTIC_SOURCE, > 0, > <%=genModel.getImportedName("org.eclipse.emf.ecore.plugin.EcorePlugin")%>.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { "<%=constraint%>", getObjectLabel(<%=genClassifier.getSafeUncapName()%>, <%=context%>) }),<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%> > new Object[] { <%=genClassifier.getSafeUncapName()%> })); >-<%}%> >+ <%}%> > } > return false; > } > return true; >+ <%}%> > <%}}%> > } > >Index: templates/model/Class.javajet >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/templates/model/Class.javajet,v >retrieving revision 1.85 >diff -u -r1.85 Class.javajet >--- templates/model/Class.javajet 18 Apr 2009 12:13:48 -0000 1.85 >+++ templates/model/Class.javajet 17 Sep 2009 15:34:48 -0000 >@@ -1,9 +1,9 @@ >-<%@ jet package="org.eclipse.emf.codegen.ecore.templates.model" imports="java.util.* org.eclipse.emf.codegen.ecore.genmodel.*" class="Class" version="$Id: Class.javajet,v 1.85 2009/04/18 12:13:48 emerks Exp $" %> >+<%@ jet package="org.eclipse.emf.codegen.ecore.templates.model" imports="java.util.* org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.emf.codegen.util.CodeGenUtil" class="Class" version="$Id: Class.javajet,v 1.85 2009/04/18 12:13:48 emerks Exp $" %> > <% > /** > * <copyright> > * >- * Copyright (c) 2002-2007 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -1320,6 +1320,17 @@ > <%for (GenOperation genOperation : (isImplementation ? genClass.getImplementedGenOperations() : genClass.getDeclaredGenOperations())) {%> > <%@ include file="Class/genOperation.override.javajetinc" fail="alternative" %> > <%@ start %> >+ <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && isImplementation && genOperation.isInvariant() && genOperation.hasValidationExpression()) {%> >+ /** >+ * The cached validation expression for the '{@link #<%=genOperation.getName()%>(<%=genOperation.getParameterTypes(", ")%>) <em><%=genOperation.getFormattedName()%></em>}' operation. >+ * <!-- begin-user-doc --> >+ * <!-- end-user-doc --> >+ * @see #<%=genOperation.getName()%>(<%=genOperation.getParameterTypes(", ")%>) >+ * @generated >+ */ >+ protected static final <%=genModel.getImportedName("java.lang.String")%> <%=CodeGenUtil.upperName(genOperation.getName(), genModel.getLocale())%><%=genOperation.getGenParameters().size() == 0 ? "" : "__" + CodeGenUtil.upperName(genOperation.getParameterTypes("_", false), genModel.getLocale())%>__EEXPRESSION = "<%=genOperation.getValidationExpression("\t\t")%>";<%=genModel.getNonNLS()%> >+ >+ <%}%> > <%if (isInterface) {%> > <%@ include file="Class/genOperation.javadoc.override.javajetinc" fail="alternative" %> > <%@ start %> >@@ -1373,6 +1384,20 @@ > <%if (genOperation.hasBody()) {%> > <%=genOperation.getBody(genModel.getIndentation(stringBuffer))%> > <%} else if (genOperation.isInvariant()) {GenClass opClass = genOperation.getGenClass(); String diagnostics = genOperation.getGenParameters().get(0).getName(); String context = genOperation.getGenParameters().get(1).getName();%> >+ <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && genOperation.hasValidationExpression()) {%> >+ return >+ <%=genModel.getImportedName("org.eclipse.emf.ecore.util.EObjectValidator")%>.validate >+ (<%=genClass.getQualifiedClassifierAccessor()%>, >+ this, >+ <%=diagnostics%>, >+ <%=context%>, >+ "<%=genOperation.getValidationDelegate()%>", //$NON-NLS-1$ >+ <%=opClass.getQualifiedClassifierAccessor()%>.getEOperations().get(<%=opClass.getEcoreClass().getEOperations().indexOf(genOperation.getEcoreOperation())%>), >+ <%=CodeGenUtil.upperName(genOperation.getName(), genModel.getLocale())%><%=genOperation.getGenParameters().size() == 0 ? "" : "__" + CodeGenUtil.upperName(genOperation.getParameterTypes("_", false), genModel.getLocale())%>__EEXPRESSION, >+ <%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR, >+ <%=opClass.getGenPackage().getImportedValidatorClassName()%>.DIAGNOSTIC_SOURCE, >+ <%=opClass.getGenPackage().getImportedValidatorClassName()%>.<%=opClass.getOperationID(genOperation)%>); >+ <%} else {%> > // TODO: implement this method > // -> specify the condition that violates the invariant > // -> verify the details of the diagnostic, including severity and message >@@ -1392,6 +1417,7 @@ > return false; > } > return true; >+ <%}%> > <%} else {%> > <%@ include file="Class/implementedGenOperation.TODO.override.javajetinc" fail="alternative" %> > <%@ start %> >Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenEnumLiteralImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenEnumLiteralImpl.java,v >retrieving revision 1.19 >diff -u -r1.19 GenEnumLiteralImpl.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenEnumLiteralImpl.java 18 Apr 2009 11:38:01 -0000 1.19 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenEnumLiteralImpl.java 17 Sep 2009 15:34:43 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2006 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -22,6 +22,7 @@ > import org.eclipse.emf.codegen.ecore.genmodel.GenJDKLevel; > import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; > import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; >+import org.eclipse.emf.codegen.util.CodeGenUtil; > import org.eclipse.emf.common.notify.Notification; > import org.eclipse.emf.common.notify.NotificationChain; > import org.eclipse.emf.ecore.EClass; >@@ -328,7 +329,7 @@ > > public String getEnumLiteralID() > { >- return format(getName(), '_', null, false, true).toUpperCase(getGenModel().getLocale()); >+ return CodeGenUtil.upperName(getName(), getGenModel().getLocale()); > } > > public String getEnumLiteralInstanceConstantName() >Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelPackageImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelPackageImpl.java,v >retrieving revision 1.60 >diff -u -r1.60 GenModelPackageImpl.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelPackageImpl.java 12 May 2009 15:54:38 -0000 1.60 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelPackageImpl.java 17 Sep 2009 15:34:46 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2007 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -2383,6 +2383,7 @@ > addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF23); > addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF24); > addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF25); >+ addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF26); > > // Create resource > createResource(eNS_URI); >Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenBaseImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenBaseImpl.java,v >retrieving revision 1.69 >diff -u -r1.69 GenBaseImpl.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenBaseImpl.java 13 Mar 2009 21:09:02 -0000 1.69 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenBaseImpl.java 17 Sep 2009 15:34:43 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2007 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -2502,13 +2502,18 @@ > > protected String indent(String text, String indentation) > { >+ return indent(text, indentation, getGenModel().getLineDelimiter()); >+ } >+ >+ protected String indent(String text, String indentation, String lineDelimiter) >+ { > if (text == null) > { > return null; > } > else > { >- String separator = getGenModel().getLineDelimiter() + indentation; >+ String separator = lineDelimiter + indentation; > int increment = separator.length() - 1; > StringBuffer stringBuffer = new StringBuffer(text); > for (int i = 0; i < stringBuffer.length(); ++i) >Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenOperationImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenOperationImpl.java,v >retrieving revision 1.36 >diff -u -r1.36 GenOperationImpl.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenOperationImpl.java 18 Apr 2009 11:38:01 -0000 1.36 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenOperationImpl.java 17 Sep 2009 15:34:46 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2006 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -927,6 +927,42 @@ > } > } > >+ protected String getValidationExpression() >+ { >+ for (String validationDelegate : EcoreUtil.getValidationDelegates(getGenPackage().getEcorePackage())) >+ { >+ String expression = EcoreUtil.getAnnotation(getEcoreOperation(), validationDelegate, "body"); >+ if (expression != null) >+ { >+ return expression; >+ } >+ } >+ return null; >+ } >+ >+ public boolean hasValidationExpression() >+ { >+ return getValidationExpression() != null; >+ } >+ >+ public String getValidationExpression(String indentation) >+ { >+ return indent(getValidationExpression(), indentation + "\"", "\" +" + getGenModel().getNonNLS() + getGenModel().getLineDelimiter()); >+ } >+ >+ public String getValidationDelegate() >+ { >+ for (String validationDelegate : EcoreUtil.getValidationDelegates(getGenPackage().getEcorePackage())) >+ { >+ String expression = EcoreUtil.getAnnotation(getEcoreOperation(), validationDelegate, "body"); >+ if (expression != null) >+ { >+ return validationDelegate; >+ } >+ } >+ return null; >+ } >+ > public List<GenClassifier> getGenExceptions() > { > List<GenClassifier> result = new ArrayList<GenClassifier>(); >Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenClassifierImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenClassifierImpl.java,v >retrieving revision 1.14 >diff -u -r1.14 GenClassifierImpl.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenClassifierImpl.java 10 Mar 2008 19:10:25 -0000 1.14 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenClassifierImpl.java 17 Sep 2009 15:34:43 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2006 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -303,4 +303,40 @@ > { > return getImportedInstanceClassName(); > } >+ >+ protected String getValidationExpression(String constraint) >+ { >+ for (String validationDelegate : EcoreUtil.getValidationDelegates(getGenPackage().getEcorePackage())) >+ { >+ String expression = EcoreUtil.getAnnotation(getEcoreClassifier(), validationDelegate, constraint); >+ if (expression != null) >+ { >+ return expression; >+ } >+ } >+ return null; >+ } >+ >+ public boolean hasValidationExpression(String constraint) >+ { >+ return getValidationExpression(constraint) != null; >+ } >+ >+ public String getValidationExpression(String constraint, String indentation) >+ { >+ return indent(getValidationExpression(constraint), indentation); >+ } >+ >+ public String getValidationDelegate(String constraint) >+ { >+ for (String validationDelegate : EcoreUtil.getValidationDelegates(getGenPackage().getEcorePackage())) >+ { >+ String expression = EcoreUtil.getAnnotation(getEcoreClassifier(), validationDelegate, constraint); >+ if (expression != null) >+ { >+ return validationDelegate; >+ } >+ } >+ return null; >+ } > } >Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenFeatureImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenFeatureImpl.java,v >retrieving revision 1.57 >diff -u -r1.57 GenFeatureImpl.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenFeatureImpl.java 18 Apr 2009 11:38:01 -0000 1.57 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenFeatureImpl.java 17 Sep 2009 15:34:44 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2006 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -33,6 +33,7 @@ > import org.eclipse.emf.codegen.ecore.genmodel.GenOperation; > import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; > import org.eclipse.emf.codegen.ecore.genmodel.GenPropertyKind; >+import org.eclipse.emf.codegen.util.CodeGenUtil; > import org.eclipse.emf.common.notify.Notification; > import org.eclipse.emf.common.notify.NotificationChain; > import org.eclipse.emf.common.util.EList; >@@ -969,7 +970,7 @@ > > public String getUpperName() > { >- return format(getName(), '_', null, false, true).toUpperCase(getGenModel().getLocale()); >+ return CodeGenUtil.upperName(getName(), getGenModel().getLocale()); > } > > public String getUncapName() >Index: model/GenModel.ecore >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/model/GenModel.ecore,v >retrieving revision 1.41 >diff -u -r1.41 GenModel.ecore >--- model/GenModel.ecore 9 Feb 2009 12:51:26 -0000 1.41 >+++ model/GenModel.ecore 17 Sep 2009 15:34:40 -0000 >@@ -308,5 +308,6 @@ > <eLiterals name="EMF23" value="1" literal="2.3"/> > <eLiterals name="EMF24" value="2" literal="2.4"/> > <eLiterals name="EMF25" value="3" literal="2.5"/> >+ <eLiterals name="EMF26" value="4" literal="2.6"/> > </eClassifiers> > </ecore:EPackage> >Index: model/GenModel.genmodel >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel,v >retrieving revision 1.47 >diff -u -r1.47 GenModel.genmodel >--- model/GenModel.genmodel 11 Dec 2008 01:51:45 -0000 1.47 >+++ model/GenModel.genmodel 17 Sep 2009 15:34:41 -0000 >@@ -5,12 +5,10 @@ > creationCommands="false" editDirectory="/org.eclipse.emf.codegen.ecore.ui/src" > editorDirectory="/org.eclipse.emf.codegen.ecore.ui/src" modelPluginID="org.eclipse.emf.codegen.ecore" > runtimeJar="true" modelName="GenModel" editPluginClass="org.eclipse.emf.codegen.ecore.genmodel.provider.GenModelEditPlugin" >- editorPluginClass="" updateClasspath="false" testsDirectory="" importerID="org.eclipse.emf.importer.rose" >+ editorPluginClass="" updateClasspath="false" testsDirectory="" importerID="org.eclipse.emf.importer.ecore" > complianceLevel="5.0" editPluginID="org.eclipse.emf.codegen.ecore.ui" language="en" > usedGenPackages="../../org.eclipse.emf.ecore/model/Ecore.genmodel#//ecore"> >- <foreignModel>GenModel.mdl</foreignModel> >- <foreignModel>VABASE_PLUGINS_PATH</foreignModel> >- <foreignModel>../..</foreignModel> >+ <foreignModel>GenModel.ecore</foreignModel> > <genPackages prefix="GenModel" basePackage="org.eclipse.emf.codegen.ecore" disposableProviderFactory="true" > multipleEditorPages="false" generateModelWizard="false" contentTypeIdentifier="org.eclipse.emf.codegen.genmodel" > ecorePackage="GenModel.ecore#/"> >@@ -45,6 +43,8 @@ > <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF22"/> > <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF23"/> > <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF24"/> >+ <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF25"/> >+ <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF26"/> > </genEnums> > <genClasses ecoreClass="GenModel.ecore#//GenModel"> > <genFeatures createChild="false" propertyCategory="All" propertyDescription="A copyright string to appear in the header of each generated artifact" >Index: src/org/eclipse/emf/codegen/ecore/genmodel/GenRuntimeVersion.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/GenRuntimeVersion.java,v >retrieving revision 1.3 >diff -u -r1.3 GenRuntimeVersion.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/GenRuntimeVersion.java 9 Feb 2009 12:51:26 -0000 1.3 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/GenRuntimeVersion.java 17 Sep 2009 15:34:41 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2008 IBM Corporation and others. >+ * Copyright (c) 2008-2009 IBM Corporation 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 >@@ -66,7 +66,15 @@ > * @generated > * @ordered > */ >- EMF25(3, "EMF25", "2.5"); >+ EMF25(3, "EMF25", "2.5"), /** >+ * The '<em><b>EMF26</b></em>' literal object. >+ * <!-- begin-user-doc --> >+ * <!-- end-user-doc --> >+ * @see #EMF26_VALUE >+ * @generated >+ * @ordered >+ */ >+ EMF26(4, "EMF26", "2.6"); > > /** > * The '<em><b>EMF22</b></em>' literal value. >@@ -114,6 +122,18 @@ > public static final int EMF25_VALUE = 3; > > /** >+ * The '<em><b>EMF26</b></em>' literal value. >+ * <!-- begin-user-doc --> >+ * @since 2.6 >+ * <!-- end-user-doc --> >+ * @see #EMF26 >+ * @model literal="2.6" >+ * @generated >+ * @ordered >+ */ >+ public static final int EMF26_VALUE = 4; >+ >+ /** > * An array of all the '<em><b>Gen Runtime Version</b></em>' enumerators. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >@@ -126,6 +146,7 @@ > EMF23, > EMF24, > EMF25, >+ EMF26, > }; > > /** >@@ -188,6 +209,7 @@ > case EMF23_VALUE: return EMF23; > case EMF24_VALUE: return EMF24; > case EMF25_VALUE: return EMF25; >+ case EMF26_VALUE: return EMF26; > } > return null; > } >Index: src/org/eclipse/emf/codegen/ecore/genmodel/GenClassifier.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/GenClassifier.java,v >retrieving revision 1.12 >diff -u -r1.12 GenClassifier.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/GenClassifier.java 4 May 2008 17:03:27 -0000 1.12 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/GenClassifier.java 17 Sep 2009 15:34:41 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2006 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -127,4 +127,19 @@ > boolean hasOnlyDefaultConstraints(); > > String getGeneratedInstanceClassFlag(); >+ >+ /** >+ * @since 2.6 >+ */ >+ boolean hasValidationExpression(String constraint); >+ >+ /** >+ * @since 2.6 >+ */ >+ String getValidationExpression(String constraint, String indentation); >+ >+ /** >+ * @since 2.6 >+ */ >+ String getValidationDelegate(String constraint); > } >Index: src/org/eclipse/emf/codegen/ecore/genmodel/GenOperation.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/GenOperation.java,v >retrieving revision 1.18 >diff -u -r1.18 GenOperation.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/GenOperation.java 4 May 2008 17:03:27 -0000 1.18 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/GenOperation.java 17 Sep 2009 15:34:41 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2006 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -191,6 +191,21 @@ > boolean hasBody(); > String getBody(String indentation); > >+ /** >+ * @since 2.6 >+ */ >+ boolean hasValidationExpression(); >+ >+ /** >+ * @since 2.6 >+ */ >+ String getValidationExpression(String indentation); >+ >+ /** >+ * @since 2.6 >+ */ >+ String getValidationDelegate(); >+ > List<GenClassifier> getGenExceptions(); > > /** >#P org.eclipse.emf.codegen.ecore.ui >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore.ui/plugin.properties,v >retrieving revision 1.76 >diff -u -r1.76 plugin.properties >--- plugin.properties 18 Apr 2009 11:38:07 -0000 1.76 >+++ plugin.properties 17 Sep 2009 15:34:51 -0000 >@@ -1,7 +1,7 @@ > # /** > # * <copyright> > # * >-# * Copyright (c) 2002-2008 IBM Corporation and others. >+# * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -320,7 +320,7 @@ > _UI_GenPackage_multipleEditorPages_feature = Multiple Editor Pages > _UI_GenPackage_multipleEditorPages_description = Whether the generated editor should have multiple pages > _UI_CreateModelError_message = Problems encountered in file "{0}" >- _UI_SelectionPage_label = Generator >+_UI_SelectionPage_label = Generator > _UI_GenFeature_propertyMultiLine_feature = Property Multi-line > _UI_GenFeature_propertyMultiLine_description = Whether this feature should be edited as a multi-line property > _UI_GenFeature_propertySortChoices_feature = Property Sort Choices >#P org.eclipse.emf.ecore >Index: src/org/eclipse/emf/ecore/util/Diagnostician.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java,v >retrieving revision 1.10 >diff -u -r1.10 Diagnostician.java >--- src/org/eclipse/emf/ecore/util/Diagnostician.java 20 Feb 2009 12:44:50 -0000 1.10 >+++ src/org/eclipse/emf/ecore/util/Diagnostician.java 17 Sep 2009 15:34:53 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2004-2006 IBM Corporation and others. >+ * Copyright (c) 2004-2009 IBM Corporation 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 >@@ -146,9 +146,10 @@ > public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) > { > Object eValidator; >- while ((eValidator = eValidatorRegistry.get(eClass.eContainer())) == null) >+ EClass eType = eClass; >+ while ((eValidator = eValidatorRegistry.get(eType.eContainer())) == null) > { >- List<EClass> eSuperTypes = eClass.getESuperTypes(); >+ List<EClass> eSuperTypes = eType.getESuperTypes(); > if (eSuperTypes.isEmpty()) > { > eValidator = eValidatorRegistry.get(null); >@@ -156,7 +157,7 @@ > } > else > { >- eClass = eSuperTypes.get(0); >+ eType = eSuperTypes.get(0); > } > } > boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject; >Index: src/org/eclipse/emf/ecore/util/EcoreUtil.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/EcoreUtil.java,v >retrieving revision 1.67 >diff -u -r1.67 EcoreUtil.java >--- src/org/eclipse/emf/ecore/util/EcoreUtil.java 3 Jul 2009 15:41:08 -0000 1.67 >+++ src/org/eclipse/emf/ecore/util/EcoreUtil.java 17 Sep 2009 15:34:56 -0000 >@@ -4087,6 +4087,74 @@ > } > } > >+ /** >+ * @since 2.6 >+ */ >+ public static boolean isInvariant(EOperation eOperation) >+ { >+ return eOperation.getEType() == EcorePackage.Literals.EBOOLEAN && >+ eOperation.getEParameters().size() == 2 && >+ eOperation.getEParameters().get(0).getEType() == EcorePackage.Literals.EDIAGNOSTIC_CHAIN && >+ eOperation.getEParameters().get(1).getEType() == EcorePackage.Literals.EMAP; >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ public static List<String> getValidationDelegates(EPackage ePackage) >+ { >+ EAnnotation eAnnotation = ePackage.getEAnnotation(EcorePackage.eNS_URI); >+ if (eAnnotation != null) >+ { >+ String validationDelegates = eAnnotation.getDetails().get("validationDelegates"); >+ if (validationDelegates != null) >+ { >+ List<String> result = new ArrayList<String>(); >+ for (StringTokenizer stringTokenizer = new StringTokenizer(validationDelegates); stringTokenizer.hasMoreTokens();) >+ { >+ String validationDelegate = stringTokenizer.nextToken(); >+ result.add(validationDelegate); >+ } >+ return result; >+ } >+ } >+ return Collections.emptyList(); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ public static void setValidationDelegates(EPackage ePackage, List<String> constraints) >+ { >+ EAnnotation eAnnotation = ePackage.getEAnnotation(EcorePackage.eNS_URI); >+ if (constraints == null || constraints.isEmpty()) >+ { >+ if (eAnnotation != null) >+ { >+ eAnnotation.getDetails().remove("validationDelegates"); >+ } >+ } >+ else >+ { >+ if (eAnnotation == null) >+ { >+ eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); >+ eAnnotation.setSource(EcorePackage.eNS_URI); >+ ePackage.getEAnnotations().add(eAnnotation); >+ } >+ StringBuffer value = new StringBuffer(); >+ for (Iterator<String> i = constraints.iterator(); i.hasNext();) >+ { >+ value.append(i.next()); >+ if (i.hasNext()) >+ { >+ value.append(' '); >+ } >+ } >+ eAnnotation.getDetails().put("validationDelegates", value.toString()); >+ } >+ } >+ > /* > static > { >Index: src/org/eclipse/emf/ecore/util/EObjectValidator.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/EObjectValidator.java,v >retrieving revision 1.30 >diff -u -r1.30 EObjectValidator.java >--- src/org/eclipse/emf/ecore/util/EObjectValidator.java 20 Feb 2009 12:44:50 -0000 1.30 >+++ src/org/eclipse/emf/ecore/util/EObjectValidator.java 17 Sep 2009 15:34:54 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2004-2007 IBM Corporation and others. >+ * Copyright (c) 2004-2009 IBM Corporation 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 >@@ -35,16 +35,16 @@ > import org.eclipse.emf.common.util.EMap; > import org.eclipse.emf.common.util.ResourceLocator; > >-import org.eclipse.emf.ecore.EValidator; >- > import org.eclipse.emf.ecore.EAttribute; >-import org.eclipse.emf.ecore.EObject; > import org.eclipse.emf.ecore.EClass; >-import org.eclipse.emf.ecore.EReference; >-import org.eclipse.emf.ecore.EcorePackage; > import org.eclipse.emf.ecore.EDataType; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.EOperation; > import org.eclipse.emf.ecore.EPackage; >+import org.eclipse.emf.ecore.EReference; > import org.eclipse.emf.ecore.EStructuralFeature; >+import org.eclipse.emf.ecore.EValidator; >+import org.eclipse.emf.ecore.EcorePackage; > import org.eclipse.emf.ecore.InternalEObject; > > import org.eclipse.emf.ecore.plugin.EcorePlugin; >@@ -166,6 +166,116 @@ > } > > /** >+ * @since 2.6 >+ */ >+ protected static EValidator.ValidationDelegate.Registry getValidationDelegateRegistry(Map<Object, Object> context) >+ { >+ if (context != null) >+ { >+ EValidator.ValidationDelegate.Registry result = (EValidator.ValidationDelegate.Registry)context.get(EValidator.ValidationDelegate.Registry.class); >+ if (result != null) >+ { >+ return result; >+ } >+ } >+ >+ return EValidator.ValidationDelegate.Registry.INSTANCE; >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ public static boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String validationDelegate, EOperation invariant, String expression, int severity, String source, int code) >+ { >+ ValidationDelegate delegate = getValidationDelegateRegistry(context).getValidationDelegate(validationDelegate); >+ if (delegate != null) >+ { >+ try >+ { >+ if (!delegate.validate(eClass, eObject, context, invariant, expression)) >+ { >+ if (diagnostics != null) >+ reportInvariantDelegateViolation(eClass, eObject, diagnostics, context, invariant, severity, source, code); >+ return false; >+ } >+ } >+ catch (Throwable throwable) >+ { >+ if (diagnostics != null) >+ reportInvariantDelegateException(eClass, eObject, diagnostics, context, invariant, severity, source, code, throwable); >+ } >+ } >+ else >+ { >+ if (diagnostics != null) >+ reportInvariantDelegateNotFound(eClass, eObject, diagnostics, context, invariant, severity, source, code, validationDelegate); >+ } >+ return true; >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ public static boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String validationDelegate, String constraint, String expression, int severity, String source, int code) >+ { >+ ValidationDelegate delegate = getValidationDelegateRegistry(context).getValidationDelegate(validationDelegate); >+ if (delegate != null) >+ { >+ try >+ { >+ if (!delegate.validate(eClass, eObject, context, constraint, expression)) >+ { >+ if (diagnostics != null) >+ reportConstraintDelegateViolation(eClass, eObject, diagnostics, context, constraint, severity, source, code); >+ return false; >+ } >+ } >+ catch (Throwable throwable) >+ { >+ if (diagnostics != null) >+ reportConstraintDelegateException(eClass, eObject, diagnostics, context, constraint, severity, source, code, throwable); >+ } >+ } >+ else >+ { >+ if (diagnostics != null) >+ reportConstraintDelegateNotFound(eClass, eObject, diagnostics, context, constraint, severity, source, code, validationDelegate); >+ } >+ return true; >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ public static boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String validationDelegate, String constraint, String expression, int severity, String source, int code) >+ { >+ ValidationDelegate delegate = getValidationDelegateRegistry(context).getValidationDelegate(validationDelegate); >+ if (delegate != null) >+ { >+ try >+ { >+ if (!delegate.validate(eDataType, value, context, constraint, expression)) >+ { >+ if (diagnostics != null) >+ reportConstraintDelegateViolation(eDataType, value, diagnostics, context, constraint, severity, source, code); >+ return false; >+ } >+ } >+ catch (Throwable throwable) >+ { >+ if (diagnostics != null) >+ reportConstraintDelegateException(eDataType, value, diagnostics, context, constraint, severity, source, code, throwable); >+ } >+ } >+ else >+ { >+ if (diagnostics != null) >+ reportConstraintDelegateNotFound(eDataType, value, diagnostics, context, constraint, severity, source, code, validationDelegate); >+ } >+ return true; >+ } >+ >+ /** > * Validates the object in the given context, optionally producing diagnostics. > * @param diagnostics a place to accumulate diagnostics; if it's <code>null</code>, no diagnostics should be produced. > * @param context a place to cache information, if it's <code>null</code>, no cache is supported. >@@ -184,11 +294,11 @@ > } > else > { >- List<EClass> eSuperTypes = eClass.getESuperTypes(); >- return >- eSuperTypes.isEmpty() ? >- validate_EveryDefaultConstraint(eObject, diagnostics, context) : >- validate(eSuperTypes.get(0), eObject, diagnostics, context); >+ return new DynamicEClassValidator() >+ { >+ // Ensure that the class loader for this class will be used downstream. >+ // >+ }.validate(eClass, eObject, diagnostics, context); > } > } > >@@ -836,14 +946,41 @@ > } > } > >- public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) >+ protected boolean validateDelegatedConstraints(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) > { > boolean result = true; >+ List<String> validationDelegates = EcoreUtil.getValidationDelegates(eDataType.getEPackage()); >+ >+ if (!validationDelegates.isEmpty()) >+ { >+ CONSTRAINTS: for (String constraint : EcoreUtil.getConstraints(eDataType)) >+ { >+ for (String validationDelegate : validationDelegates) >+ { >+ String expression = EcoreUtil.getAnnotation(eDataType, validationDelegate, constraint); >+ if (expression != null) >+ { >+ result &= EObjectValidator.validate(eDataType, value, diagnostics, context, validationDelegate, constraint, expression, Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0); >+ if (!result && diagnostics == null) >+ break CONSTRAINTS; >+ } >+ } >+ } >+ } >+ >+ return result; >+ } >+ >+ protected boolean validateSchemaConstraints(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) >+ { >+ boolean result = true; >+ > if (effectiveEnumeration != null) > { > if (!effectiveEnumeration.contains(value)) > { >- if (diagnostics != null) reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context); >+ if (diagnostics != null) >+ reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context); > result = false; > } > } >@@ -855,10 +992,9 @@ > > if (effectiveMin != null) > { >- @SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin; >- if (effectiveMinIsInclusive ? >- comparableObject.compareTo(value) > 0: >- comparableObject.compareTo(value) >= 0) >+ @SuppressWarnings("unchecked") >+ Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin; >+ if (effectiveMinIsInclusive ? comparableObject.compareTo(value) > 0 : comparableObject.compareTo(value) >= 0) > { > if (diagnostics != null) > { >@@ -877,10 +1013,9 @@ > > if (effectiveMax != null) > { >- @SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax; >- if (effectiveMaxIsInclusive ? >- comparableObject.compareTo(value) < 0: >- comparableObject.compareTo(value) <= 0) >+ @SuppressWarnings("unchecked") >+ Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax; >+ if (effectiveMaxIsInclusive ? comparableObject.compareTo(value) < 0 : comparableObject.compareTo(value) <= 0) > { > if (diagnostics != null) > { >@@ -944,40 +1079,130 @@ > result = false; > } > } >+ >+ return result; >+ } >+ >+ public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) >+ { >+ boolean result = validateDelegatedConstraints(eDataType, value, diagnostics, context); > >- if (itemType != null) >+ if (result || diagnostics != null) > { >- EValidator rootValidator = getRootEValidator(context); >- for (Iterator<?> i = ((List<?>)value).iterator(); i.hasNext() && (result || diagnostics != null); ) >+ result &= validateSchemaConstraints(eDataType, value, diagnostics, context); >+ >+ if (itemType != null) >+ { >+ EValidator rootValidator = getRootEValidator(context); >+ for (Iterator< ? > i = ((List< ? >)value).iterator(); i.hasNext() && (result || diagnostics != null);) >+ { >+ result &= rootValidator.validate(itemType, i.next(), diagnostics, context); >+ } >+ return result; >+ } >+ else if (!memberTypes.isEmpty()) > { >- result &= rootValidator.validate(itemType, i.next(), diagnostics, context); >+ EValidator rootValidator = getRootEValidator(context); >+ >+ for (EDataType memberType : memberTypes) >+ { >+ if (rootValidator.validate(memberType, value, null, context)) >+ { >+ return true; >+ } >+ } >+ for (EDataType memberType : memberTypes) >+ { >+ if (memberType.isInstance(value)) >+ { >+ return rootValidator.validate(memberType, value, diagnostics, context); >+ } >+ } >+ return false; >+ } >+ else >+ { >+ return result; > } >- return result; > } >- else if (!memberTypes.isEmpty()) >+ >+ return result; >+ } >+ } >+ >+ public class DynamicEClassValidator >+ { >+ protected boolean validateDelegatedInvariants(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) >+ { >+ boolean result = true; >+ List<String> validationDelegates = EcoreUtil.getValidationDelegates(eClass.getEPackage()); >+ >+ if (!validationDelegates.isEmpty()) > { >- EValidator rootValidator = getRootEValidator(context); >- >- for (EDataType memberType : memberTypes) >+ INVARIANTS: for (EOperation eOperation : eClass.getEOperations()) > { >- if (rootValidator.validate(memberType, value, null, context)) >+ if (EcoreUtil.isInvariant(eOperation)) > { >- return true; >+ for (String validationDelegate : validationDelegates) >+ { >+ String expression = EcoreUtil.getAnnotation(eOperation, validationDelegate, "body"); >+ if (expression != null) >+ { >+ result &= EObjectValidator.validate(eClass, eObject, diagnostics, context, validationDelegate, eOperation, expression, Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0); >+ if (!result && diagnostics == null) >+ break INVARIANTS; >+ } >+ } > } > } >- for (EDataType memberType : memberTypes) >+ } >+ >+ return result; >+ } >+ >+ protected boolean validateDelegatedConstraints(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) >+ { >+ boolean result = true; >+ List<String> validationDelegates = EcoreUtil.getValidationDelegates(eClass.getEPackage()); >+ >+ if (!validationDelegates.isEmpty()) >+ { >+ CONSTRAINTS: for (String constraint : EcoreUtil.getConstraints(eClass)) > { >- if (memberType.isInstance(value)) >+ for (String validationDelegate : validationDelegates) > { >- return rootValidator.validate(memberType, value, diagnostics, context); >+ String expression = EcoreUtil.getAnnotation(eClass, validationDelegate, constraint); >+ if (expression != null) >+ { >+ result &= EObjectValidator.validate(eClass, eObject, diagnostics, context, validationDelegate, constraint, expression, Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0); >+ if (!result && diagnostics == null) >+ break CONSTRAINTS; >+ } > } > } >- return false; > } >- else >+ >+ return result; >+ } >+ >+ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) >+ { >+ boolean result = validateDelegatedInvariants(eClass, eObject, diagnostics, context); >+ >+ if (result || diagnostics != null) > { >- return result; >+ result &= validateDelegatedConstraints(eClass, eObject, diagnostics, context); >+ >+ if (result || diagnostics != null) >+ { >+ List<EClass> eSuperTypes = eClass.getESuperTypes(); >+ result &= eSuperTypes.isEmpty() ? >+ validate_EveryDefaultConstraint(eObject, diagnostics, context) : >+ validate(eSuperTypes.get(0), eObject, diagnostics, context); >+ } > } >+ >+ return result; > } > } > >@@ -1202,6 +1427,132 @@ > context)); > } > >+ /** >+ * @since 2.6 >+ */ >+ protected static void reportConstraintDelegateViolation(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code) >+ { >+ diagnostics.add >+ (new BasicDiagnostic >+ (severity, >+ source, >+ code, >+ EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { constraint, getValueLabel(eDataType, value, context) }), >+ new Object [] { value })); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ protected static void reportConstraintDelegateException(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, Throwable throwable) >+ { >+ diagnostics.add >+ (new BasicDiagnostic >+ (severity, >+ source, >+ code, >+ EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateException_diagnostic", new Object[] { constraint, getValueLabel(eDataType, value, context), throwable.getLocalizedMessage() }), >+ new Object [] { value })); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ protected static void reportConstraintDelegateNotFound(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, String validationDelegate) >+ { >+ diagnostics.add >+ (new BasicDiagnostic >+ (severity, >+ source, >+ code, >+ EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateNotFound_diagnostic", new Object[] { constraint, getValueLabel(eDataType, value, context), validationDelegate }), >+ new Object [] { value })); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ protected static void reportConstraintDelegateViolation(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code) >+ { >+ diagnostics.add >+ (new BasicDiagnostic >+ (severity, >+ source, >+ code, >+ EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context) }), >+ new Object [] { eObject })); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ protected static void reportConstraintDelegateException(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, Throwable throwable) >+ { >+ diagnostics.add >+ (new BasicDiagnostic >+ (severity, >+ source, >+ code, >+ EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateException_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context), throwable.getLocalizedMessage() }), >+ new Object [] { eObject })); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ protected static void reportConstraintDelegateNotFound(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, String validationDelegate) >+ { >+ diagnostics.add >+ (new BasicDiagnostic >+ (severity, >+ source, >+ code, >+ EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateNotFound_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context), validationDelegate }), >+ new Object [] { eObject })); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ protected static void reportInvariantDelegateViolation(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, EOperation invariant, int severity, String source, int code) >+ { >+ diagnostics.add >+ (new BasicDiagnostic >+ (severity, >+ source, >+ code, >+ EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { invariant.getName(), getObjectLabel(eObject, context) }), >+ new Object [] { eObject })); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ protected static void reportInvariantDelegateException(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, EOperation invariant, int severity, String source, int code, Throwable throwable) >+ { >+ diagnostics.add >+ (new BasicDiagnostic >+ (severity, >+ source, >+ code, >+ EcorePlugin.INSTANCE.getString("_UI_InvariantDelegateException_diagnostic", new Object[] { invariant.getName(), getObjectLabel(eObject, context), throwable.getLocalizedMessage() }), >+ new Object [] { eObject })); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ protected static void reportInvariantDelegateNotFound(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, EOperation invariant, int severity, String source, int code, String validationDelegate) >+ { >+ diagnostics.add >+ (new BasicDiagnostic >+ (severity, >+ source, >+ code, >+ EcorePlugin.INSTANCE.getString("_UI_InvariantDelegateNotFound_diagnostic", new Object[] { invariant.getName(), getObjectLabel(eObject, context), validationDelegate }), >+ new Object [] { eObject })); >+ } >+ > protected static Collection<Object> wrapEnumerationValues(Object [] values) > { > return java.util.Arrays.asList(values); >@@ -1471,6 +1822,16 @@ > } > > /** >+ * @since 2.6 >+ */ >+ protected boolean isEcoreString(String key) >+ { >+ return "_UI_GenericConstraint_diagnostic".equals(key) || "_UI_GenericInvariant_diagnostic".equals(key) >+ || "_UI_ConstraintDelegateException_diagnostic".equals(key) || "_UI_InvariantDelegateException_diagnostic".equals(key) >+ || "_UI_ConstraintDelegateNotFound_diagnostic".equals(key) || "_UI_InvariantDelegateNotFound_diagnostic".equals(key); >+ } >+ >+ /** > * Returns a translated message with the given substitutions. > * The {@link #getResourceLocator() resource locator} is used. > * @param key the key for the message. >@@ -1480,7 +1841,7 @@ > */ > protected String getString(String key, Object [] substitutions) > { >- return getString("_UI_GenericConstraint_diagnostic".equals(key) ? getEcoreResourceLocator() : getResourceLocator(), key, substitutions); >+ return getString(isEcoreString(key) ? getEcoreResourceLocator() : getResourceLocator(), key, substitutions); > } > > /** >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/plugin.xml,v >retrieving revision 1.23 >diff -u -r1.23 plugin.xml >--- plugin.xml 17 Mar 2009 13:09:13 -0000 1.23 >+++ plugin.xml 17 Sep 2009 15:34:52 -0000 >@@ -10,6 +10,7 @@ > <extension-point id="content_handler" name="%_UI_ContentHandlerRegistry_extensionpoint" schema="schema/content_handler.exsd"/> > <extension-point id="uri_mapping" name="%_UI_URIMappingRegistry_extensionpoint" schema="schema/uri_mapping.exsd"/> > <extension-point id="package_registry_implementation" name="%_UI_PackageRegistryImplementation_extensionpoint" schema="schema/package_registry_implementation.exsd"/> >+ <extension-point id="validation_delegate" name="%_UI_ValidationDelegateRegistry_extensionpoint" schema="schema/validation_delegate.exsd"/> > > <extension point="org.eclipse.emf.ecore.generated_package"> > <package >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/plugin.properties,v >retrieving revision 1.35 >diff -u -r1.35 plugin.properties >--- plugin.properties 7 Apr 2009 18:58:12 -0000 1.35 >+++ plugin.properties 17 Sep 2009 15:34:52 -0000 >@@ -1,7 +1,7 @@ > # /** > # * <copyright> > # * >-# * Copyright (c) 2002-2008 IBM Corporation and others. >+# * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -194,5 +194,11 @@ > _UI_EClassifierInstanceTypeNameExpectedSpace_diagnostic = Expecting '' '' at index {0} > _UI_EClassifierInstanceTypeNameUnexpectedSpace_diagnostic = Unexpected '' '' at index {0} > >+_UI_InvariantDelegateException_diagnostic = An exception occurred while delegating evaluation of the ''{0}'' invariant on ''{1}'': {2} >+_UI_InvariantDelegateNotFound_diagnostic = Unable to find delegate to evaluate the ''{0}'' invariant on ''{1}'': {2} >+ >+_UI_ConstraintDelegateException_diagnostic = An exception occurred while delegating evaluation of the ''{0}'' constraint on ''{1}'': {2} >+_UI_ConstraintDelegateNotFound_diagnostic = Unable to find delegate to evaluate the ''{0}'' constraint on ''{1}'': {2} >+ > # This is in org.eclipse.emf.ecore.xmi > #_UI_Ecore_content_type = Ecore File >Index: src/org/eclipse/emf/ecore/plugin/EcorePlugin.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/plugin/EcorePlugin.java,v >retrieving revision 1.23 >diff -u -r1.23 EcorePlugin.java >--- src/org/eclipse/emf/ecore/plugin/EcorePlugin.java 2 Aug 2008 13:40:51 -0000 1.23 >+++ src/org/eclipse/emf/ecore/plugin/EcorePlugin.java 17 Sep 2009 15:34:53 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2006 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -575,6 +575,7 @@ > new ContentParserRegistryReader().readRegistry(); > new ContentHandlerRegistryReader().readRegistry(); > new URIMappingRegistryReader().readRegistry(); >+ new ValidationDelegateRegistryReader().readRegistry(); > } > } > >@@ -631,4 +632,5 @@ > public static final String SCHEME_PARSER_PPID = "scheme_parser"; > public static final String URI_MAPPING_PPID = "uri_mapping"; > public static final String PACKAGE_REGISTRY_IMPLEMENTATION_PPID = "package_registry_implementation"; >+ public static final String VALIDATION_DELEGATE_PPID = "validation_delegate"; > } >\ No newline at end of file >Index: src/org/eclipse/emf/ecore/EValidator.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EValidator.java,v >retrieving revision 1.8 >diff -u -r1.8 EValidator.java >--- src/org/eclipse/emf/ecore/EValidator.java 14 Jun 2007 18:32:46 -0000 1.8 >+++ src/org/eclipse/emf/ecore/EValidator.java 17 Sep 2009 15:34:52 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2004-2006 IBM Corporation and others. >+ * Copyright (c) 2004-2009 IBM Corporation 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 >@@ -117,6 +117,62 @@ > } > > /** >+ * An interface for delegating validation expression evaluation. >+ * @since 2.6 >+ */ >+ interface ValidationDelegate >+ { >+ /** >+ * A <code>ValidationDelegate</code> wrapper that is used by the {@link ValidationDelegate.Registry}. >+ */ >+ public interface Descriptor >+ { >+ /** >+ * Returns the validation delegate. >+ * @return the validation delegate. >+ */ >+ ValidationDelegate getValidationDelegate(); >+ } >+ >+ /** >+ * A map from {@link java.lang.String String} to {@link ValidationDelegate}. >+ */ >+ interface Registry extends Map<String, Object> >+ { >+ /** >+ * Looks up the validation delegate in the map. >+ */ >+ ValidationDelegate getValidationDelegate(String id); >+ >+ /** >+ * The global instance of a validation delegate registry. >+ */ >+ Registry INSTANCE = new org.eclipse.emf.ecore.impl.ValidationDelegateRegistryImpl(); >+ } >+ >+ /** >+ * Evaluates the given validation expression for the invariant against the object in the given context. >+ * @param context a place to cache information, if it's <code>null</code>, no cache is supported. >+ * @return the result of the expression evaluation. >+ */ >+ boolean validate(EClass eClass, EObject eObject, Map<Object, Object> context, EOperation invariant, String expression); >+ >+ /** >+ * Evaluates the given validation expression for the constraint against the object in the given context. >+ * @param context a place to cache information, if it's <code>null</code>, no cache is supported. >+ * @return the result of the expression evaluation. >+ */ >+ boolean validate(EClass eClass, EObject eObject, Map<Object, Object> context, String constraint, String expression); >+ >+ /** >+ * Evaluates the given validation expression for the constraint against the value in the given context. >+ * @param context a place to cache information, if it's <code>null</code>, no cache is supported. >+ * @return the result of the expression evaluation. >+ */ >+ boolean validate(EDataType eDataType, Object value, Map<Object, Object> context, String constraint, String expression); >+ } >+ >+ /** > * Validates the object in the given context, optionally producing diagnostics. > * @param diagnostics a place to accumulate diagnostics; if it's <code>null</code>, no diagnostics should be produced. > * @param context a place to cache information, if it's <code>null</code>, no cache is supported. >Index: src/org/eclipse/emf/ecore/plugin/ValidationDelegateRegistryReader.java >=================================================================== >RCS file: src/org/eclipse/emf/ecore/plugin/ValidationDelegateRegistryReader.java >diff -N src/org/eclipse/emf/ecore/plugin/ValidationDelegateRegistryReader.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/ecore/plugin/ValidationDelegateRegistryReader.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,93 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2009 Kenn Hussey 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: >+ * Kenn Hussey - Initial API and implementation >+ * >+ * </copyright> >+ * >+ * $Id$ >+ */ >+package org.eclipse.emf.ecore.plugin; >+ >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.Platform; >+ >+import org.eclipse.emf.ecore.EValidator; >+ >+ >+/** >+ * A plugin extension reader that populates the >+ * {@link org.eclipse.emf.ecore.EValidator.ValidationDelegate.Registry#INSTANCE global} validation delegate registry. >+ * Clients are not expected to use this class directly. >+ */ >+class ValidationDelegateRegistryReader extends RegistryReader >+{ >+ static class ValidationDelegateDescriptor extends PluginClassDescriptor implements EValidator.ValidationDelegate.Descriptor >+ { >+ protected EValidator.ValidationDelegate validationDelegate; >+ >+ public ValidationDelegateDescriptor(IConfigurationElement e, String attrName) >+ { >+ super(e, attrName); >+ } >+ >+ public EValidator.ValidationDelegate getValidationDelegate() >+ { >+ if (validationDelegate == null) >+ { >+ validationDelegate = (EValidator.ValidationDelegate)createInstance(); >+ } >+ return validationDelegate; >+ } >+ } >+ >+ static final String TAG_DELEGATE = "delegate"; >+ static final String ATT_ID = "id"; >+ static final String ATT_CLASS = "class"; >+ >+ public ValidationDelegateRegistryReader() >+ { >+ super(Platform.getExtensionRegistry(), EcorePlugin.getPlugin().getBundle().getSymbolicName(), EcorePlugin.VALIDATION_DELEGATE_PPID); >+ } >+ >+ @Override >+ protected boolean readElement(IConfigurationElement element, boolean add) >+ { >+ if (element.getName().equals(TAG_DELEGATE)) >+ { >+ String id = element.getAttribute(ATT_ID); >+ if (id == null) >+ { >+ logMissingAttribute(element, ATT_ID); >+ } >+ else if (element.getAttribute(ATT_CLASS) == null) >+ { >+ logMissingAttribute(element, ATT_CLASS); >+ } >+ else if (add) >+ { >+ Object previous = EValidator.ValidationDelegate.Registry.INSTANCE.put(id, new ValidationDelegateDescriptor(element, ATT_CLASS)); >+ if (previous instanceof ValidationDelegateDescriptor) >+ { >+ ValidationDelegateDescriptor descriptor = (ValidationDelegateDescriptor)previous; >+ EcorePlugin.INSTANCE.log("Both '" + descriptor.element.getContributor().getName() + "' and '" + element.getContributor().getName() + "' register a validation delegate for '" + id + "'"); >+ } >+ return true; >+ } >+ else >+ { >+ EValidator.ValidationDelegate.Registry.INSTANCE.remove(id); >+ return true; >+ } >+ } >+ >+ return false; >+ } >+} >Index: src/org/eclipse/emf/ecore/impl/ValidationDelegateRegistryImpl.java >=================================================================== >RCS file: src/org/eclipse/emf/ecore/impl/ValidationDelegateRegistryImpl.java >diff -N src/org/eclipse/emf/ecore/impl/ValidationDelegateRegistryImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/ecore/impl/ValidationDelegateRegistryImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,84 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2009 Kenn Hussey 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: >+ * Kenn Hussey - Initial API and implementation >+ * >+ * </copyright> >+ * >+ * $Ids$ >+ */ >+package org.eclipse.emf.ecore.impl; >+ >+import java.util.HashMap; >+ >+import org.eclipse.emf.ecore.EValidator; >+ >+ >+/** >+ * An implementation of a validation delegate registry. >+ */ >+public class ValidationDelegateRegistryImpl extends HashMap<String, Object> implements EValidator.ValidationDelegate.Registry >+{ >+ private static final long serialVersionUID = 1L; >+ >+ protected EValidator.ValidationDelegate.Registry delegateRegistry; >+ >+ public ValidationDelegateRegistryImpl() >+ { >+ super(); >+ } >+ >+ public ValidationDelegateRegistryImpl(EValidator.ValidationDelegate.Registry delegateRegistry) >+ { >+ this.delegateRegistry = delegateRegistry; >+ } >+ >+ @Override >+ public Object get(Object key) >+ { >+ Object validationDelegate = super.get(key); >+ if (validationDelegate instanceof EValidator.ValidationDelegate.Descriptor) >+ { >+ EValidator.ValidationDelegate.Descriptor validationDelegateDescriptor = (EValidator.ValidationDelegate.Descriptor)validationDelegate; >+ validationDelegate = validationDelegateDescriptor.getValidationDelegate(); >+ put((String)key, validationDelegate); >+ return validationDelegate; >+ } >+ else if (validationDelegate != null) >+ { >+ return validationDelegate; >+ } >+ else >+ { >+ return delegatedGet(key); >+ } >+ } >+ >+ public EValidator.ValidationDelegate getValidationDelegate(String id) >+ { >+ return (EValidator.ValidationDelegate)get(id); >+ } >+ >+ protected Object delegatedGet(Object key) >+ { >+ if (delegateRegistry != null) >+ { >+ return delegateRegistry.get(key); >+ } >+ >+ return null; >+ } >+ >+ @Override >+ public boolean containsKey(Object key) >+ { >+ return super.containsKey(key) || delegateRegistry != null && delegateRegistry.containsKey(key); >+ } >+} >Index: schema/validation_delegate.exsd >=================================================================== >RCS file: schema/validation_delegate.exsd >diff -N schema/validation_delegate.exsd >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ schema/validation_delegate.exsd 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,124 @@ >+<?xml version='1.0' encoding='UTF-8'?> >+<!-- Schema file written by PDE --> >+<schema targetNamespace="org.eclipse.emf.ecore" xmlns="http://www.w3.org/2001/XMLSchema"> >+<annotation> >+ <appInfo> >+ <meta.schema plugin="org.eclipse.emf.ecore" id="validation_delegate" name="Validation Delegate Registry"/> >+ </appInfo> >+ <documentation> >+ This extension point is used to define a validation delegate that evaluates expressions whose type is identified by a unique identifier (e.g., a URI). The global EMF validation delegate registry, <samp>EValidator.ValidationDelegate.Factory.Registry.INSTANCE</samp>, is used to record the registration. >+ </documentation> >+ </annotation> >+ >+ <element name="extension"> >+ <annotation> >+ <appInfo> >+ <meta.element /> >+ </appInfo> >+ </annotation> >+ <complexType> >+ <sequence> >+ <element ref="delegate" minOccurs="1" maxOccurs="unbounded"/> >+ </sequence> >+ <attribute name="point" type="string" use="required"> >+ <annotation> >+ <documentation> >+ A fully qualified identifier of the target extension point. >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="id" type="string"> >+ <annotation> >+ <documentation> >+ An optional identifier of the extension instance. >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="name" type="string"> >+ <annotation> >+ <documentation> >+ An optional name of the extension instance. >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="delegate"> >+ <annotation> >+ <appInfo> >+ <meta.element labelAttribute="id"/> >+ </appInfo> >+ </annotation> >+ <complexType> >+ <attribute name="id" type="string" use="required"> >+ <annotation> >+ <documentation> >+ A unique identifier (e.g., a URI) for the type of expressions that can be evaluated by the validation delegate. >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="class" type="string" use="required"> >+ <annotation> >+ <documentation> >+ The fully qualified name of a Java class implementing <samp>org.eclipse.emf.ecore.EValidator.ValidationDelegate</samp>. >+ </documentation> >+ <appInfo> >+ <meta.attribute kind="java" basedOn="org.eclipse.emf.ecore.EValidator.ValidationDelegate"/> >+ </appInfo> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="since"/> >+ </appInfo> >+ <documentation> >+ 2.6.0 >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="examples"/> >+ </appInfo> >+ <documentation> >+ Following is an example of how a validation delegate can be registered: >+<pre> >+ <extension point="org.eclipse.emf.ecore.validation_delegate" > >+ <delegate uri="org.eclipse.ocl.ecore.OCL" class="org.eclipse.ocl.OCLValidationDelegate"/> >+ </extension> >+</pre> >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="apiInfo"/> >+ </appInfo> >+ <documentation> >+ The value of the class attribute must represent a class that implements <samp>org.eclipse.emf.ecore.EValidator.ValidationDelegate</samp> and has a no argument contructor. >+<p> >+A validation delegate can be also registered from the source code with the <samp>EValidator.ValidationDelegate.Registry.INSTANCE</samp> as follows: >+</p> >+<pre> >+ EValidator.ValidationDelegate.Registry.INSTANCE.put(URI.createURI("org.eclipse.ocl.ecore.OCL"), new OCLValidationDelegate()); >+</pre> >+ </documentation> >+ </annotation> >+ >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="copyright"/> >+ </appInfo> >+ <documentation> >+ Copyright (c) 2009 Kenn Hussey 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 <a >+href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> >+ </documentation> >+ </annotation> >+ >+</schema> >#P org.eclipse.emf.codegen >Index: src/org/eclipse/emf/codegen/util/CodeGenUtil.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen/src/org/eclipse/emf/codegen/util/CodeGenUtil.java,v >retrieving revision 1.33 >diff -u -r1.33 CodeGenUtil.java >--- src/org/eclipse/emf/codegen/util/CodeGenUtil.java 21 Apr 2009 19:23:00 -0000 1.33 >+++ src/org/eclipse/emf/codegen/util/CodeGenUtil.java 17 Sep 2009 15:35:00 -0000 >@@ -1,7 +1,7 @@ > /** > * <copyright> > * >- * Copyright (c) 2002-2007 IBM Corporation and others. >+ * Copyright (c) 2002-2009 IBM Corporation 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 >@@ -477,6 +477,22 @@ > } > > /** >+ * @since 2.6 >+ */ >+ public static String upperName(String name, Locale locale) >+ { >+ return format(name, '_', null, false, true).toUpperCase(locale); >+ } >+ >+ /** >+ * @since 2.6 >+ */ >+ public static String upperName(String name) >+ { >+ return upperName(name, Locale.getDefault()); >+ } >+ >+ /** > * @deprecated In 2.2. Please use {@link #format(String, char, String, boolean, boolean)} instead. > */ > @Deprecated
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 255786
:
118244
|
118245
|
118338
|
123880
|
123881
|
123883
|
123885
|
126724
|
126725
|
126726
|
126727
|
126729
|
146761
|
146762
|
146778
|
146787
|
147341
|
147449
|
147455
|
147479