Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 255786 | Differences between
and this patch

Collapse All | Expand All

(-)templates/model/ValidatorClass.javajet (-10 / +50 lines)
Lines 3-9 Link Here
3
/**
3
/**
4
 * <copyright>
4
 * <copyright>
5
 *
5
 *
6
 * Copyright (c) 2002-2006 IBM Corporation and others.
6
 * Copyright (c) 2002-2009 IBM Corporation and others.
7
 * All rights reserved.   This program and the accompanying materials
7
 * All rights reserved.   This program and the accompanying materials
8
 * are made available under the terms of the Eclipse Public License v1.0
8
 * are made available under the terms of the Eclipse Public License v1.0
9
 * which accompanies this distribution, and is available at
9
 * which accompanies this distribution, and is available at
Lines 284-289 Link Here
284
284
285
<%}%>
285
<%}%>
286
<%}%>
286
<%}%>
287
<%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && genClassifier.hasValidationExpression(constraint)) {%>
288
	/**
289
	 * The cached validation expression for the <%=constraint%> constraint of '<em><%=genClassifier.getFormattedName()%></em>'.
290
	 * <!-- begin-user-doc -->
291
	 * <!-- end-user-doc -->
292
	 * @generated
293
	 */
294
	protected static final <%=genModel.getImportedName("java.lang.String")%> <%=genClassifier.getClassifierID()%>__<%=CodeGenUtil.upperName(constraint)%>__EEXPRESSION = "<%=genClassifier.getValidationExpression(constraint, genModel.getIndentation(stringBuffer))%>";<%=genModel.getNonNLS()%>
295
296
<%}%>
287
	/**
297
	/**
288
	 * Validates the <%=constraint%> constraint of '<em><%=genClassifier.getFormattedName()%></em>'.
298
	 * Validates the <%=constraint%> constraint of '<em><%=genClassifier.getFormattedName()%></em>'.
289
	 * <!-- begin-user-doc -->
299
	 * <!-- begin-user-doc -->
Lines 481-486 Link Here
481
		}
491
		}
482
		return <%=delegate%>validate<%=constraintDelegate.getName()%>_<%=constraint%>(<%=genClassifier.getSafeUncapName()%><%=accessor%>, <%=diagnostics%>, <%=context%>);
492
		return <%=delegate%>validate<%=constraintDelegate.getName()%>_<%=constraint%>(<%=genClassifier.getSafeUncapName()%><%=accessor%>, <%=diagnostics%>, <%=context%>);
483
<%} else {%>
493
<%} else {%>
494
  <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && genClassifier.hasValidationExpression(constraint)) {%>
495
		return
496
			validate
497
				(<%=genClassifier.getQualifiedClassifierAccessor()%>,
498
				 <%=genClassifier.getSafeUncapName()%>,
499
				 <%=diagnostics%>,
500
				 <%=context%>,
501
				 "<%=genClassifier.getValidationDelegate(constraint)%>",<%=genModel.getNonNLS()%>
502
				 "<%=constraint%>",<%=genModel.getNonNLS()%>
503
				 <%=genClassifier.getClassifierID()%>__<%=CodeGenUtil.upperName(constraint)%>__EEXPRESSION,
504
				 <%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
505
				 DIAGNOSTIC_SOURCE,
506
				 0);
507
  <%} else {%>
484
		// TODO implement the constraint
508
		// TODO implement the constraint
485
		// -> specify the condition that violates the constraint
509
		// -> specify the condition that violates the constraint
486
		// -> verify the diagnostic details, including severity, code, and message
510
		// -> verify the diagnostic details, including severity, code, and message
Lines 490-496 Link Here
490
			if (<%=diagnostics%> != null)
514
			if (<%=diagnostics%> != null)
491
			{
515
			{
492
				<%=diagnostics%>.add
516
				<%=diagnostics%>.add
493
<%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%>
517
    <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%>
494
					(createDiagnostic
518
					(createDiagnostic
495
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
519
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
496
						 DIAGNOSTIC_SOURCE,
520
						 DIAGNOSTIC_SOURCE,
Lines 499-516 Link Here
499
						 new Object[] { "<%=constraint%>", getValueLabel(<%=genDataType.getQualifiedClassifierAccessor()%>, <%=genClassifier.getSafeUncapName()%>, <%=context%>) },<%=genModel.getNonNLS()%>
523
						 new Object[] { "<%=constraint%>", getValueLabel(<%=genDataType.getQualifiedClassifierAccessor()%>, <%=genClassifier.getSafeUncapName()%>, <%=context%>) },<%=genModel.getNonNLS()%>
500
						 new Object[] { <%=genClassifier.getSafeUncapName()%> },
524
						 new Object[] { <%=genClassifier.getSafeUncapName()%> },
501
						 context));
525
						 context));
502
<%} else {%>
526
    <%} else {%>
503
					(new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%>
527
					(new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%>
504
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
528
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
505
						 DIAGNOSTIC_SOURCE,
529
						 DIAGNOSTIC_SOURCE,
506
						 0,
530
						 0,
507
						 <%=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)%>
531
						 <%=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)%>
508
						 new Object[] { <%=genClassifier.getSafeUncapName()%> }));
532
						 new Object[] { <%=genClassifier.getSafeUncapName()%> }));
509
<%}%>
533
    <%}%>
510
			}
534
			}
511
			return false;
535
			return false;
512
		}
536
		}
513
		return true;
537
		return true;
538
  <%}%>
514
<%}%>
539
<%}%>
515
<%} else if (constraintDelegate != null) {%>
540
<%} else if (constraintDelegate != null) {%>
516
		// TODO override the constraint, if desired
541
		// TODO override the constraint, if desired
Lines 523-529 Link Here
523
			if (<%=diagnostics%> != null)
548
			if (<%=diagnostics%> != null)
524
			{
549
			{
525
				<%=diagnostics%>.add
550
				<%=diagnostics%>.add
526
<%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%>
551
  <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%>
527
					(createDiagnostic
552
					(createDiagnostic
528
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
553
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
529
						 DIAGNOSTIC_SOURCE,
554
						 DIAGNOSTIC_SOURCE,
Lines 532-545 Link Here
532
						 new Object[] { "<%=constraint%>", getObjectLabel(<%=genClassifier.getSafeUncapName()%>, <%=context%>) },<%=genModel.getNonNLS()%>
557
						 new Object[] { "<%=constraint%>", getObjectLabel(<%=genClassifier.getSafeUncapName()%>, <%=context%>) },<%=genModel.getNonNLS()%>
533
						 new Object[] { <%=genClassifier.getSafeUncapName()%> },
558
						 new Object[] { <%=genClassifier.getSafeUncapName()%> },
534
						 context));
559
						 context));
535
<%} else {%>
560
  <%} else {%>
536
					(new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%>
561
					(new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%>
537
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
562
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
538
						 DIAGNOSTIC_SOURCE,
563
						 DIAGNOSTIC_SOURCE,
539
						 0,
564
						 0,
540
						 <%=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)%>
565
						 <%=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)%>
541
						 new Object[] { <%=genClassifier.getSafeUncapName()%> }));
566
						 new Object[] { <%=genClassifier.getSafeUncapName()%> }));
542
<%}%>
567
  <%}%>
543
			}
568
			}
544
			return false;
569
			return false;
545
		}
570
		}
Lines 547-552 Link Here
547
<%} else { GenOperation genOperation = ((GenClass)genClassifier).getInvariantOperation(constraint); if (genOperation != null) {%>
572
<%} else { GenOperation genOperation = ((GenClass)genClassifier).getInvariantOperation(constraint); if (genOperation != null) {%>
548
		return <%=genClassifier.getSafeUncapName()%>.<%=constraint%>(<%=diagnostics%>, <%=context%>);
573
		return <%=genClassifier.getSafeUncapName()%>.<%=constraint%>(<%=diagnostics%>, <%=context%>);
549
<%} else {%>
574
<%} else {%>
575
  <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && genClassifier.hasValidationExpression(constraint)) {%>
576
		return
577
			validate
578
				(<%=genClassifier.getQualifiedClassifierAccessor()%>,
579
				 <%=genClassifier.getSafeUncapName()%>,
580
				 <%=diagnostics%>,
581
				 <%=context%>,
582
				 "<%=genClassifier.getValidationDelegate(constraint)%>",<%=genModel.getNonNLS()%>
583
				 "<%=constraint%>",<%=genModel.getNonNLS()%>
584
				 <%=genClassifier.getClassifierID()%>__<%=CodeGenUtil.upperName(constraint)%>__EEXPRESSION,
585
				 <%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
586
				 DIAGNOSTIC_SOURCE,
587
				 0);
588
  <%} else {%>
550
		// TODO implement the constraint
589
		// TODO implement the constraint
551
		// -> specify the condition that violates the constraint
590
		// -> specify the condition that violates the constraint
552
		// -> verify the diagnostic details, including severity, code, and message
591
		// -> verify the diagnostic details, including severity, code, and message
Lines 556-562 Link Here
556
			if (<%=diagnostics%> != null)
595
			if (<%=diagnostics%> != null)
557
			{
596
			{
558
				<%=diagnostics%>.add
597
				<%=diagnostics%>.add
559
<%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%>
598
    <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF24_VALUE) {%>
560
					(createDiagnostic
599
					(createDiagnostic
561
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
600
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
562
						 DIAGNOSTIC_SOURCE,
601
						 DIAGNOSTIC_SOURCE,
Lines 565-582 Link Here
565
						 new Object[] { "<%=constraint%>", getObjectLabel(<%=genClassifier.getSafeUncapName()%>, <%=context%>) },<%=genModel.getNonNLS()%>
604
						 new Object[] { "<%=constraint%>", getObjectLabel(<%=genClassifier.getSafeUncapName()%>, <%=context%>) },<%=genModel.getNonNLS()%>
566
						 new Object[] { <%=genClassifier.getSafeUncapName()%> },
605
						 new Object[] { <%=genClassifier.getSafeUncapName()%> },
567
						 context));
606
						 context));
568
<%} else {%>
607
    <%} else {%>
569
					(new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%>
608
					(new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%>
570
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
609
						(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
571
						 DIAGNOSTIC_SOURCE,
610
						 DIAGNOSTIC_SOURCE,
572
						 0,
611
						 0,
573
						 <%=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)%>
612
						 <%=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)%>
574
						 new Object[] { <%=genClassifier.getSafeUncapName()%> }));
613
						 new Object[] { <%=genClassifier.getSafeUncapName()%> }));
575
<%}%>
614
    <%}%>
576
			}
615
			}
577
			return false;
616
			return false;
578
		}
617
		}
579
		return true;
618
		return true;
619
  <%}%>
580
<%}}%>
620
<%}}%>
581
	}
621
	}
582
622
(-)templates/model/Class.javajet (-2 / +28 lines)
Lines 1-9 Link Here
1
<%@ 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 $" %>
1
<%@ 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 $" %>
2
<%
2
<%
3
/**
3
/**
4
 * <copyright>
4
 * <copyright>
5
 *
5
 *
6
 * Copyright (c) 2002-2007 IBM Corporation and others.
6
 * Copyright (c) 2002-2009 IBM Corporation and others.
7
 * All rights reserved.   This program and the accompanying materials
7
 * All rights reserved.   This program and the accompanying materials
8
 * are made available under the terms of the Eclipse Public License v1.0
8
 * are made available under the terms of the Eclipse Public License v1.0
9
 * which accompanies this distribution, and is available at
9
 * which accompanies this distribution, and is available at
Lines 1320-1325 Link Here
1320
<%for (GenOperation genOperation : (isImplementation ? genClass.getImplementedGenOperations() : genClass.getDeclaredGenOperations())) {%>
1320
<%for (GenOperation genOperation : (isImplementation ? genClass.getImplementedGenOperations() : genClass.getDeclaredGenOperations())) {%>
1321
<%@ include file="Class/genOperation.override.javajetinc" fail="alternative" %>
1321
<%@ include file="Class/genOperation.override.javajetinc" fail="alternative" %>
1322
<%@ start %>
1322
<%@ start %>
1323
  <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && isImplementation && genOperation.isInvariant() && genOperation.hasValidationExpression()) {%>
1324
	/**
1325
	 * The cached validation expression for the '{@link #<%=genOperation.getName()%>(<%=genOperation.getParameterTypes(", ")%>) <em><%=genOperation.getFormattedName()%></em>}' operation.
1326
	 * <!-- begin-user-doc -->
1327
	 * <!-- end-user-doc -->
1328
	 * @see #<%=genOperation.getName()%>(<%=genOperation.getParameterTypes(", ")%>)
1329
	 * @generated
1330
	 */
1331
	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()%>
1332
1333
  <%}%>
1323
<%if (isInterface) {%>
1334
<%if (isInterface) {%>
1324
<%@ include file="Class/genOperation.javadoc.override.javajetinc" fail="alternative" %>
1335
<%@ include file="Class/genOperation.javadoc.override.javajetinc" fail="alternative" %>
1325
<%@ start %>
1336
<%@ start %>
Lines 1373-1378 Link Here
1373
  <%if (genOperation.hasBody()) {%>
1384
  <%if (genOperation.hasBody()) {%>
1374
		<%=genOperation.getBody(genModel.getIndentation(stringBuffer))%>
1385
		<%=genOperation.getBody(genModel.getIndentation(stringBuffer))%>
1375
  <%} else if (genOperation.isInvariant()) {GenClass opClass = genOperation.getGenClass(); String diagnostics = genOperation.getGenParameters().get(0).getName(); String context = genOperation.getGenParameters().get(1).getName();%>
1386
  <%} else if (genOperation.isInvariant()) {GenClass opClass = genOperation.getGenClass(); String diagnostics = genOperation.getGenParameters().get(0).getName(); String context = genOperation.getGenParameters().get(1).getName();%>
1387
    <%if (genModel.getRuntimeVersion().getValue() >= GenRuntimeVersion.EMF26_VALUE && genOperation.hasValidationExpression()) {%>
1388
		return
1389
			<%=genModel.getImportedName("org.eclipse.emf.ecore.util.EObjectValidator")%>.validate
1390
				(<%=genClass.getQualifiedClassifierAccessor()%>,
1391
				 this,
1392
				 <%=diagnostics%>,
1393
				 <%=context%>,
1394
				 "<%=genOperation.getValidationDelegate()%>", //$NON-NLS-1$
1395
				 <%=opClass.getQualifiedClassifierAccessor()%>.getEOperations().get(<%=opClass.getEcoreClass().getEOperations().indexOf(genOperation.getEcoreOperation())%>),
1396
				 <%=CodeGenUtil.upperName(genOperation.getName(), genModel.getLocale())%><%=genOperation.getGenParameters().size() == 0 ? "" : "__" + CodeGenUtil.upperName(genOperation.getParameterTypes("_", false), genModel.getLocale())%>__EEXPRESSION,
1397
				 <%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
1398
				 <%=opClass.getGenPackage().getImportedValidatorClassName()%>.DIAGNOSTIC_SOURCE,
1399
				 <%=opClass.getGenPackage().getImportedValidatorClassName()%>.<%=opClass.getOperationID(genOperation)%>);
1400
    <%} else {%>
1376
		// TODO: implement this method
1401
		// TODO: implement this method
1377
		// -> specify the condition that violates the invariant
1402
		// -> specify the condition that violates the invariant
1378
		// -> verify the details of the diagnostic, including severity and message
1403
		// -> verify the details of the diagnostic, including severity and message
Lines 1392-1397 Link Here
1392
			return false;
1417
			return false;
1393
		}
1418
		}
1394
		return true;
1419
		return true;
1420
    <%}%>
1395
  <%} else {%>
1421
  <%} else {%>
1396
<%@ include file="Class/implementedGenOperation.TODO.override.javajetinc" fail="alternative" %>
1422
<%@ include file="Class/implementedGenOperation.TODO.override.javajetinc" fail="alternative" %>
1397
<%@ start %>
1423
<%@ start %>
(-)src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenEnumLiteralImpl.java (-2 / +3 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright> 
2
 * <copyright> 
3
 *
3
 *
4
 * Copyright (c) 2002-2006 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 22-27 Link Here
22
import org.eclipse.emf.codegen.ecore.genmodel.GenJDKLevel;
22
import org.eclipse.emf.codegen.ecore.genmodel.GenJDKLevel;
23
import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
23
import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
24
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
24
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
25
import org.eclipse.emf.codegen.util.CodeGenUtil;
25
import org.eclipse.emf.common.notify.Notification;
26
import org.eclipse.emf.common.notify.Notification;
26
import org.eclipse.emf.common.notify.NotificationChain;
27
import org.eclipse.emf.common.notify.NotificationChain;
27
import org.eclipse.emf.ecore.EClass;
28
import org.eclipse.emf.ecore.EClass;
Lines 328-334 Link Here
328
329
329
  public String getEnumLiteralID()
330
  public String getEnumLiteralID()
330
  {
331
  {
331
    return format(getName(), '_', null, false, true).toUpperCase(getGenModel().getLocale());
332
    return CodeGenUtil.upperName(getName(), getGenModel().getLocale());
332
  }
333
  }
333
  
334
  
334
  public String getEnumLiteralInstanceConstantName()
335
  public String getEnumLiteralInstanceConstantName()
(-)src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelPackageImpl.java (-1 / +2 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2002-2007 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 2383-2388 Link Here
2383
    addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF23);
2383
    addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF23);
2384
    addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF24);
2384
    addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF24);
2385
    addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF25);
2385
    addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF25);
2386
    addEEnumLiteral(genRuntimeVersionEEnum, GenRuntimeVersion.EMF26);
2386
2387
2387
    // Create resource
2388
    // Create resource
2388
    createResource(eNS_URI);
2389
    createResource(eNS_URI);
(-)src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenBaseImpl.java (-2 / +7 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright> 
2
 * <copyright> 
3
 *
3
 *
4
 * Copyright (c) 2002-2007 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 2502-2514 Link Here
2502
2502
2503
  protected String indent(String text, String indentation)
2503
  protected String indent(String text, String indentation)
2504
  {
2504
  {
2505
    return indent(text, indentation, getGenModel().getLineDelimiter());
2506
  }
2507
2508
  protected String indent(String text, String indentation, String lineDelimiter)
2509
  {
2505
    if (text == null)
2510
    if (text == null)
2506
    {
2511
    {
2507
      return null;
2512
      return null;
2508
    }
2513
    }
2509
    else
2514
    else
2510
    {
2515
    {
2511
      String separator = getGenModel().getLineDelimiter() + indentation;
2516
      String separator = lineDelimiter + indentation;
2512
      int increment = separator.length() - 1;
2517
      int increment = separator.length() - 1;
2513
      StringBuffer stringBuffer = new StringBuffer(text);
2518
      StringBuffer stringBuffer = new StringBuffer(text);
2514
      for (int i = 0; i < stringBuffer.length(); ++i)
2519
      for (int i = 0; i < stringBuffer.length(); ++i)
(-)src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenOperationImpl.java (-1 / +37 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright> 
2
 * <copyright> 
3
 *
3
 *
4
 * Copyright (c) 2002-2006 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 927-932 Link Here
927
    }
927
    }
928
  }
928
  }
929
929
930
  protected String getValidationExpression()
931
  {
932
    for (String validationDelegate : EcoreUtil.getValidationDelegates(getGenPackage().getEcorePackage()))
933
    {
934
      String expression = EcoreUtil.getAnnotation(getEcoreOperation(), validationDelegate, "body");
935
      if (expression != null)
936
      {
937
        return expression;
938
      }
939
    }
940
    return null;
941
  }
942
943
  public boolean hasValidationExpression()
944
  {
945
    return getValidationExpression() != null;
946
  }
947
948
  public String getValidationExpression(String indentation)
949
  {
950
    return indent(getValidationExpression(), indentation + "\"", "\" +" + getGenModel().getNonNLS() + getGenModel().getLineDelimiter());
951
  }
952
953
  public String getValidationDelegate()
954
  {
955
    for (String validationDelegate : EcoreUtil.getValidationDelegates(getGenPackage().getEcorePackage()))
956
    {
957
      String expression = EcoreUtil.getAnnotation(getEcoreOperation(), validationDelegate, "body");
958
      if (expression != null)
959
      {
960
        return validationDelegate;
961
      }
962
    }
963
    return null;
964
  }
965
930
  public List<GenClassifier> getGenExceptions()
966
  public List<GenClassifier> getGenExceptions()
931
  {
967
  {
932
    List<GenClassifier> result = new ArrayList<GenClassifier>();
968
    List<GenClassifier> result = new ArrayList<GenClassifier>();
(-)src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenClassifierImpl.java (-1 / +37 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright> 
2
 * <copyright> 
3
 *
3
 *
4
 * Copyright (c) 2002-2006 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 303-306 Link Here
303
  {
303
  {
304
    return getImportedInstanceClassName();
304
    return getImportedInstanceClassName();
305
  }
305
  }
306
307
  protected String getValidationExpression(String constraint)
308
  {
309
    for (String validationDelegate : EcoreUtil.getValidationDelegates(getGenPackage().getEcorePackage()))
310
    {
311
      String expression = EcoreUtil.getAnnotation(getEcoreClassifier(), validationDelegate, constraint);
312
      if (expression != null)
313
      {
314
        return expression;
315
      }
316
    }
317
    return null;
318
  }
319
320
  public boolean hasValidationExpression(String constraint)
321
  {
322
    return getValidationExpression(constraint) != null;
323
  }
324
325
  public String getValidationExpression(String constraint, String indentation)
326
  {
327
    return indent(getValidationExpression(constraint), indentation);
328
  }
329
330
  public String getValidationDelegate(String constraint)
331
  {
332
    for (String validationDelegate : EcoreUtil.getValidationDelegates(getGenPackage().getEcorePackage()))
333
    {
334
      String expression = EcoreUtil.getAnnotation(getEcoreClassifier(), validationDelegate, constraint);
335
      if (expression != null)
336
      {
337
        return validationDelegate;
338
      }
339
    }
340
    return null;
341
  }
306
}
342
}
(-)src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenFeatureImpl.java (-2 / +3 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright> 
2
 * <copyright> 
3
 *
3
 *
4
 * Copyright (c) 2002-2006 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 33-38 Link Here
33
import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
33
import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
34
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
34
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
35
import org.eclipse.emf.codegen.ecore.genmodel.GenPropertyKind;
35
import org.eclipse.emf.codegen.ecore.genmodel.GenPropertyKind;
36
import org.eclipse.emf.codegen.util.CodeGenUtil;
36
import org.eclipse.emf.common.notify.Notification;
37
import org.eclipse.emf.common.notify.Notification;
37
import org.eclipse.emf.common.notify.NotificationChain;
38
import org.eclipse.emf.common.notify.NotificationChain;
38
import org.eclipse.emf.common.util.EList;
39
import org.eclipse.emf.common.util.EList;
Lines 969-975 Link Here
969
970
970
  public String getUpperName()
971
  public String getUpperName()
971
  {
972
  {
972
    return format(getName(), '_', null, false, true).toUpperCase(getGenModel().getLocale());
973
    return CodeGenUtil.upperName(getName(), getGenModel().getLocale());
973
  }
974
  }
974
975
975
  public String getUncapName()
976
  public String getUncapName()
(-)model/GenModel.ecore (+1 lines)
Lines 308-312 Link Here
308
    <eLiterals name="EMF23" value="1" literal="2.3"/>
308
    <eLiterals name="EMF23" value="1" literal="2.3"/>
309
    <eLiterals name="EMF24" value="2" literal="2.4"/>
309
    <eLiterals name="EMF24" value="2" literal="2.4"/>
310
    <eLiterals name="EMF25" value="3" literal="2.5"/>
310
    <eLiterals name="EMF25" value="3" literal="2.5"/>
311
    <eLiterals name="EMF26" value="4" literal="2.6"/>
311
  </eClassifiers>
312
  </eClassifiers>
312
</ecore:EPackage>
313
</ecore:EPackage>
(-)model/GenModel.genmodel (-4 / +4 lines)
Lines 5-16 Link Here
5
    creationCommands="false" editDirectory="/org.eclipse.emf.codegen.ecore.ui/src"
5
    creationCommands="false" editDirectory="/org.eclipse.emf.codegen.ecore.ui/src"
6
    editorDirectory="/org.eclipse.emf.codegen.ecore.ui/src" modelPluginID="org.eclipse.emf.codegen.ecore"
6
    editorDirectory="/org.eclipse.emf.codegen.ecore.ui/src" modelPluginID="org.eclipse.emf.codegen.ecore"
7
    runtimeJar="true" modelName="GenModel" editPluginClass="org.eclipse.emf.codegen.ecore.genmodel.provider.GenModelEditPlugin"
7
    runtimeJar="true" modelName="GenModel" editPluginClass="org.eclipse.emf.codegen.ecore.genmodel.provider.GenModelEditPlugin"
8
    editorPluginClass="" updateClasspath="false" testsDirectory="" importerID="org.eclipse.emf.importer.rose"
8
    editorPluginClass="" updateClasspath="false" testsDirectory="" importerID="org.eclipse.emf.importer.ecore"
9
    complianceLevel="5.0" editPluginID="org.eclipse.emf.codegen.ecore.ui" language="en"
9
    complianceLevel="5.0" editPluginID="org.eclipse.emf.codegen.ecore.ui" language="en"
10
    usedGenPackages="../../org.eclipse.emf.ecore/model/Ecore.genmodel#//ecore">
10
    usedGenPackages="../../org.eclipse.emf.ecore/model/Ecore.genmodel#//ecore">
11
  <foreignModel>GenModel.mdl</foreignModel>
11
  <foreignModel>GenModel.ecore</foreignModel>
12
  <foreignModel>VABASE_PLUGINS_PATH</foreignModel>
13
  <foreignModel>../..</foreignModel>
14
  <genPackages prefix="GenModel" basePackage="org.eclipse.emf.codegen.ecore" disposableProviderFactory="true"
12
  <genPackages prefix="GenModel" basePackage="org.eclipse.emf.codegen.ecore" disposableProviderFactory="true"
15
      multipleEditorPages="false" generateModelWizard="false" contentTypeIdentifier="org.eclipse.emf.codegen.genmodel"
13
      multipleEditorPages="false" generateModelWizard="false" contentTypeIdentifier="org.eclipse.emf.codegen.genmodel"
16
      ecorePackage="GenModel.ecore#/">
14
      ecorePackage="GenModel.ecore#/">
Lines 45-50 Link Here
45
      <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF22"/>
43
      <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF22"/>
46
      <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF23"/>
44
      <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF23"/>
47
      <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF24"/>
45
      <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF24"/>
46
      <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF25"/>
47
      <genEnumLiterals ecoreEnumLiteral="GenModel.ecore#//GenRuntimeVersion/EMF26"/>
48
    </genEnums>
48
    </genEnums>
49
    <genClasses ecoreClass="GenModel.ecore#//GenModel">
49
    <genClasses ecoreClass="GenModel.ecore#//GenModel">
50
      <genFeatures createChild="false" propertyCategory="All" propertyDescription="A copyright string to appear in the header of each generated artifact"
50
      <genFeatures createChild="false" propertyCategory="All" propertyDescription="A copyright string to appear in the header of each generated artifact"
(-)src/org/eclipse/emf/codegen/ecore/genmodel/GenRuntimeVersion.java (-2 / +24 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2008 IBM Corporation and others.
4
 * Copyright (c) 2008-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 66-72 Link Here
66
   * @generated
66
   * @generated
67
   * @ordered
67
   * @ordered
68
   */
68
   */
69
  EMF25(3, "EMF25", "2.5");
69
  EMF25(3, "EMF25", "2.5"), /**
70
   * The '<em><b>EMF26</b></em>' literal object.
71
   * <!-- begin-user-doc -->
72
   * <!-- end-user-doc -->
73
   * @see #EMF26_VALUE
74
   * @generated
75
   * @ordered
76
   */
77
  EMF26(4, "EMF26", "2.6");
70
78
71
  /**
79
  /**
72
   * The '<em><b>EMF22</b></em>' literal value.
80
   * The '<em><b>EMF22</b></em>' literal value.
Lines 114-119 Link Here
114
  public static final int EMF25_VALUE = 3;
122
  public static final int EMF25_VALUE = 3;
115
123
116
  /**
124
  /**
125
   * The '<em><b>EMF26</b></em>' literal value.
126
   * <!-- begin-user-doc -->
127
   * @since 2.6
128
   * <!-- end-user-doc -->
129
   * @see #EMF26
130
   * @model literal="2.6"
131
   * @generated
132
   * @ordered
133
   */
134
  public static final int EMF26_VALUE = 4;
135
136
  /**
117
   * An array of all the '<em><b>Gen Runtime Version</b></em>' enumerators.
137
   * An array of all the '<em><b>Gen Runtime Version</b></em>' enumerators.
118
   * <!-- begin-user-doc -->
138
   * <!-- begin-user-doc -->
119
   * <!-- end-user-doc -->
139
   * <!-- end-user-doc -->
Lines 126-131 Link Here
126
      EMF23,
146
      EMF23,
127
      EMF24,
147
      EMF24,
128
      EMF25,
148
      EMF25,
149
      EMF26,
129
    };
150
    };
130
151
131
  /**
152
  /**
Lines 188-193 Link Here
188
      case EMF23_VALUE: return EMF23;
209
      case EMF23_VALUE: return EMF23;
189
      case EMF24_VALUE: return EMF24;
210
      case EMF24_VALUE: return EMF24;
190
      case EMF25_VALUE: return EMF25;
211
      case EMF25_VALUE: return EMF25;
212
      case EMF26_VALUE: return EMF26;
191
    }
213
    }
192
    return null;
214
    return null;
193
  }
215
  }
(-)src/org/eclipse/emf/codegen/ecore/genmodel/GenClassifier.java (-1 / +16 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright> 
2
 * <copyright> 
3
 *
3
 *
4
 * Copyright (c) 2002-2006 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 127-130 Link Here
127
  boolean hasOnlyDefaultConstraints();
127
  boolean hasOnlyDefaultConstraints();
128
128
129
  String getGeneratedInstanceClassFlag();
129
  String getGeneratedInstanceClassFlag();
130
131
  /**
132
   * @since 2.6
133
   */
134
  boolean hasValidationExpression(String constraint);
135
136
  /**
137
   * @since 2.6
138
   */
139
  String getValidationExpression(String constraint, String indentation);
140
141
  /**
142
   * @since 2.6
143
   */
144
  String getValidationDelegate(String constraint);
130
}
145
}
(-)src/org/eclipse/emf/codegen/ecore/genmodel/GenOperation.java (-1 / +16 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright> 
2
 * <copyright> 
3
 *
3
 *
4
 * Copyright (c) 2002-2006 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 191-196 Link Here
191
  boolean hasBody();
191
  boolean hasBody();
192
  String getBody(String indentation);
192
  String getBody(String indentation);
193
193
194
  /**
195
   * @since 2.6
196
   */
197
  boolean hasValidationExpression();
198
199
  /**
200
   * @since 2.6
201
   */
202
  String getValidationExpression(String indentation);
203
204
  /**
205
   * @since 2.6
206
   */
207
  String getValidationDelegate();
208
194
  List<GenClassifier> getGenExceptions();
209
  List<GenClassifier> getGenExceptions();
195
210
196
  /**
211
  /**
(-)plugin.properties (-2 / +2 lines)
Lines 1-7 Link Here
1
# /**
1
# /**
2
#  * <copyright>
2
#  * <copyright>
3
#  *
3
#  *
4
#  * Copyright (c) 2002-2008 IBM Corporation and others.
4
#  * Copyright (c) 2002-2009 IBM Corporation and others.
5
#  * All rights reserved.   This program and the accompanying materials
5
#  * All rights reserved.   This program and the accompanying materials
6
#  * are made available under the terms of the Eclipse Public License v1.0
6
#  * are made available under the terms of the Eclipse Public License v1.0
7
#  * which accompanies this distribution, and is available at
7
#  * which accompanies this distribution, and is available at
Lines 320-326 Link Here
320
_UI_GenPackage_multipleEditorPages_feature = Multiple Editor Pages
320
_UI_GenPackage_multipleEditorPages_feature = Multiple Editor Pages
321
_UI_GenPackage_multipleEditorPages_description = Whether the generated editor should have multiple pages
321
_UI_GenPackage_multipleEditorPages_description = Whether the generated editor should have multiple pages
322
_UI_CreateModelError_message = Problems encountered in file "{0}"
322
_UI_CreateModelError_message = Problems encountered in file "{0}"
323
_UI_SelectionPage_label = Generator
323
_UI_SelectionPage_label = Generator
324
_UI_GenFeature_propertyMultiLine_feature = Property Multi-line
324
_UI_GenFeature_propertyMultiLine_feature = Property Multi-line
325
_UI_GenFeature_propertyMultiLine_description = Whether this feature should be edited as a multi-line property
325
_UI_GenFeature_propertyMultiLine_description = Whether this feature should be edited as a multi-line property
326
_UI_GenFeature_propertySortChoices_feature = Property Sort Choices
326
_UI_GenFeature_propertySortChoices_feature = Property Sort Choices
(-)src/org/eclipse/emf/ecore/util/Diagnostician.java (-4 / +5 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2004-2006 IBM Corporation and others.
4
 * Copyright (c) 2004-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 146-154 Link Here
146
  public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context)
146
  public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context)
147
  {
147
  {
148
    Object eValidator;
148
    Object eValidator;
149
    while ((eValidator = eValidatorRegistry.get(eClass.eContainer())) == null)
149
    EClass eType = eClass;
150
    while ((eValidator = eValidatorRegistry.get(eType.eContainer())) == null)
150
    {
151
    {
151
      List<EClass> eSuperTypes = eClass.getESuperTypes();
152
      List<EClass> eSuperTypes = eType.getESuperTypes();
152
      if (eSuperTypes.isEmpty())
153
      if (eSuperTypes.isEmpty())
153
      {
154
      {
154
        eValidator = eValidatorRegistry.get(null);
155
        eValidator = eValidatorRegistry.get(null);
Lines 156-162 Link Here
156
      }
157
      }
157
      else
158
      else
158
      {
159
      {
159
        eClass = eSuperTypes.get(0);
160
        eType = eSuperTypes.get(0);
160
      }
161
      }
161
    }
162
    }
162
    boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject;
163
    boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject;
(-)src/org/eclipse/emf/ecore/util/EcoreUtil.java (+68 lines)
Lines 4087-4092 Link Here
4087
    }
4087
    }
4088
  }
4088
  }
4089
4089
4090
  /**
4091
   * @since 2.6
4092
   */
4093
  public static boolean isInvariant(EOperation eOperation)
4094
  {
4095
    return eOperation.getEType() == EcorePackage.Literals.EBOOLEAN &&
4096
      eOperation.getEParameters().size() == 2 &&
4097
      eOperation.getEParameters().get(0).getEType() == EcorePackage.Literals.EDIAGNOSTIC_CHAIN &&
4098
      eOperation.getEParameters().get(1).getEType() == EcorePackage.Literals.EMAP;
4099
  }
4100
4101
  /**
4102
   * @since 2.6
4103
   */
4104
  public static List<String> getValidationDelegates(EPackage ePackage)
4105
  {
4106
    EAnnotation eAnnotation = ePackage.getEAnnotation(EcorePackage.eNS_URI);
4107
    if (eAnnotation != null)
4108
    {
4109
      String validationDelegates = eAnnotation.getDetails().get("validationDelegates");
4110
      if (validationDelegates != null)
4111
      {
4112
        List<String> result = new ArrayList<String>();
4113
        for (StringTokenizer stringTokenizer = new StringTokenizer(validationDelegates); stringTokenizer.hasMoreTokens();)
4114
        {
4115
          String validationDelegate = stringTokenizer.nextToken();
4116
          result.add(validationDelegate);
4117
        }
4118
        return result;
4119
      }
4120
    }
4121
    return Collections.emptyList();
4122
  }
4123
4124
  /**
4125
   * @since 2.6
4126
   */
4127
  public static void setValidationDelegates(EPackage ePackage, List<String> constraints)
4128
  {
4129
    EAnnotation eAnnotation = ePackage.getEAnnotation(EcorePackage.eNS_URI);
4130
    if (constraints == null || constraints.isEmpty())
4131
    {
4132
      if (eAnnotation != null)
4133
      {
4134
        eAnnotation.getDetails().remove("validationDelegates");
4135
      }
4136
    }
4137
    else
4138
    {
4139
      if (eAnnotation == null)
4140
      {
4141
        eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
4142
        eAnnotation.setSource(EcorePackage.eNS_URI);
4143
        ePackage.getEAnnotations().add(eAnnotation);
4144
      }
4145
      StringBuffer value = new StringBuffer();
4146
      for (Iterator<String> i = constraints.iterator(); i.hasNext();)
4147
      {
4148
        value.append(i.next());
4149
        if (i.hasNext())
4150
        {
4151
          value.append(' ');
4152
        }
4153
      }
4154
      eAnnotation.getDetails().put("validationDelegates", value.toString());
4155
    }
4156
  }
4157
4090
  /*
4158
  /*
4091
   static 
4159
   static 
4092
   {
4160
   {
(-)src/org/eclipse/emf/ecore/util/EObjectValidator.java (-39 / +400 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2004-2007 IBM Corporation and others.
4
 * Copyright (c) 2004-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 35-50 Link Here
35
import org.eclipse.emf.common.util.EMap;
35
import org.eclipse.emf.common.util.EMap;
36
import org.eclipse.emf.common.util.ResourceLocator;
36
import org.eclipse.emf.common.util.ResourceLocator;
37
37
38
import org.eclipse.emf.ecore.EValidator;
39
40
import org.eclipse.emf.ecore.EAttribute;
38
import org.eclipse.emf.ecore.EAttribute;
41
import org.eclipse.emf.ecore.EObject;
42
import org.eclipse.emf.ecore.EClass;
39
import org.eclipse.emf.ecore.EClass;
43
import org.eclipse.emf.ecore.EReference;
44
import org.eclipse.emf.ecore.EcorePackage;
45
import org.eclipse.emf.ecore.EDataType;
40
import org.eclipse.emf.ecore.EDataType;
41
import org.eclipse.emf.ecore.EObject;
42
import org.eclipse.emf.ecore.EOperation;
46
import org.eclipse.emf.ecore.EPackage;
43
import org.eclipse.emf.ecore.EPackage;
44
import org.eclipse.emf.ecore.EReference;
47
import org.eclipse.emf.ecore.EStructuralFeature;
45
import org.eclipse.emf.ecore.EStructuralFeature;
46
import org.eclipse.emf.ecore.EValidator;
47
import org.eclipse.emf.ecore.EcorePackage;
48
import org.eclipse.emf.ecore.InternalEObject;
48
import org.eclipse.emf.ecore.InternalEObject;
49
49
50
import org.eclipse.emf.ecore.plugin.EcorePlugin;
50
import org.eclipse.emf.ecore.plugin.EcorePlugin;
Lines 166-171 Link Here
166
  }
166
  }
167
167
168
  /**
168
  /**
169
   * @since 2.6
170
   */
171
  protected static EValidator.ValidationDelegate.Registry getValidationDelegateRegistry(Map<Object, Object> context)
172
  {
173
    if (context != null)
174
    {
175
      EValidator.ValidationDelegate.Registry result = (EValidator.ValidationDelegate.Registry)context.get(EValidator.ValidationDelegate.Registry.class);
176
      if (result != null)
177
      {
178
        return result;
179
      }
180
    }
181
182
    return EValidator.ValidationDelegate.Registry.INSTANCE;
183
  }
184
185
  /**
186
   * @since 2.6
187
   */
188
  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)
189
  {
190
    ValidationDelegate delegate = getValidationDelegateRegistry(context).getValidationDelegate(validationDelegate);
191
    if (delegate != null)
192
    {
193
      try
194
      {
195
        if (!delegate.validate(eClass, eObject, context, invariant, expression))
196
        {
197
          if (diagnostics != null)
198
            reportInvariantDelegateViolation(eClass, eObject, diagnostics, context, invariant, severity, source, code);
199
          return false;
200
        }
201
      }
202
      catch (Throwable throwable)
203
      {
204
        if (diagnostics != null)
205
          reportInvariantDelegateException(eClass, eObject, diagnostics, context, invariant, severity, source, code, throwable);
206
      }
207
    }
208
    else
209
    {
210
      if (diagnostics != null)
211
        reportInvariantDelegateNotFound(eClass, eObject, diagnostics, context, invariant, severity, source, code, validationDelegate);
212
    }
213
    return true;
214
  }
215
216
  /**
217
   * @since 2.6
218
   */
219
  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)
220
  {
221
    ValidationDelegate delegate = getValidationDelegateRegistry(context).getValidationDelegate(validationDelegate);
222
    if (delegate != null)
223
    {
224
      try
225
      {
226
        if (!delegate.validate(eClass, eObject, context, constraint, expression))
227
        {
228
          if (diagnostics != null)
229
            reportConstraintDelegateViolation(eClass, eObject, diagnostics, context, constraint, severity, source, code);
230
          return false;
231
        }
232
      }
233
      catch (Throwable throwable)
234
      {
235
        if (diagnostics != null)
236
          reportConstraintDelegateException(eClass, eObject, diagnostics, context, constraint, severity, source, code, throwable);
237
      }
238
    }
239
    else
240
    {
241
      if (diagnostics != null)
242
        reportConstraintDelegateNotFound(eClass, eObject, diagnostics, context, constraint, severity, source, code, validationDelegate);
243
    }
244
    return true;
245
  }
246
247
  /**
248
   * @since 2.6
249
   */
250
  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)
251
  {
252
    ValidationDelegate delegate = getValidationDelegateRegistry(context).getValidationDelegate(validationDelegate);
253
    if (delegate != null)
254
    {
255
      try
256
      {
257
        if (!delegate.validate(eDataType, value, context, constraint, expression))
258
        {
259
          if (diagnostics != null)
260
            reportConstraintDelegateViolation(eDataType, value, diagnostics, context, constraint, severity, source, code);
261
          return false;
262
        }
263
      }
264
      catch (Throwable throwable)
265
      {
266
        if (diagnostics != null)
267
          reportConstraintDelegateException(eDataType, value, diagnostics, context, constraint, severity, source, code, throwable);
268
      }
269
    }
270
    else
271
    {
272
      if (diagnostics != null)
273
        reportConstraintDelegateNotFound(eDataType, value, diagnostics, context, constraint, severity, source, code, validationDelegate);
274
    }
275
    return true;
276
  }
277
278
  /**
169
   * Validates the object in the given context, optionally producing diagnostics.
279
   * Validates the object in the given context, optionally producing diagnostics.
170
   * @param diagnostics a place to accumulate diagnostics; if it's <code>null</code>, no diagnostics should be produced.
280
   * @param diagnostics a place to accumulate diagnostics; if it's <code>null</code>, no diagnostics should be produced.
171
   * @param context a place to cache information, if it's <code>null</code>, no cache is supported.
281
   * @param context a place to cache information, if it's <code>null</code>, no cache is supported.
Lines 184-194 Link Here
184
    }
294
    }
185
    else
295
    else
186
    {
296
    {
187
      List<EClass> eSuperTypes = eClass.getESuperTypes();
297
      return new DynamicEClassValidator()
188
      return
298
        {
189
        eSuperTypes.isEmpty() ?
299
          // Ensure that the class loader for this class will be used downstream.
190
          validate_EveryDefaultConstraint(eObject, diagnostics, context) :
300
          //
191
          validate(eSuperTypes.get(0), eObject, diagnostics, context);
301
        }.validate(eClass, eObject, diagnostics, context);
192
    }
302
    }
193
  }
303
  }
194
304
Lines 836-849 Link Here
836
      }
946
      }
837
    }
947
    }
838
948
839
    public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context)
949
    protected boolean validateDelegatedConstraints(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context)
840
    {
950
    {
841
      boolean result = true;
951
      boolean result = true;
952
      List<String> validationDelegates = EcoreUtil.getValidationDelegates(eDataType.getEPackage());
953
954
      if (!validationDelegates.isEmpty())
955
      {
956
        CONSTRAINTS: for (String constraint : EcoreUtil.getConstraints(eDataType))
957
        {
958
          for (String validationDelegate : validationDelegates)
959
          {
960
            String expression = EcoreUtil.getAnnotation(eDataType, validationDelegate, constraint);
961
            if (expression != null)
962
            {
963
              result &= EObjectValidator.validate(eDataType, value, diagnostics, context, validationDelegate, constraint, expression, Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0);
964
              if (!result && diagnostics == null)
965
                break CONSTRAINTS;
966
            }
967
          }
968
        }
969
      }
970
971
      return result;
972
    }
973
974
    protected boolean validateSchemaConstraints(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context)
975
    {
976
      boolean result = true;
977
842
      if (effectiveEnumeration != null)
978
      if (effectiveEnumeration != null)
843
      {
979
      {
844
        if (!effectiveEnumeration.contains(value))
980
        if (!effectiveEnumeration.contains(value))
845
        {
981
        {
846
          if (diagnostics != null) reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context);
982
          if (diagnostics != null)
983
            reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context);
847
          result = false;
984
          result = false;
848
        }
985
        }
849
      }
986
      }
Lines 855-864 Link Here
855
992
856
      if (effectiveMin != null)
993
      if (effectiveMin != null)
857
      {
994
      {
858
        @SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin;
995
        @SuppressWarnings("unchecked")
859
        if (effectiveMinIsInclusive ?
996
        Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin;
860
              comparableObject.compareTo(value) > 0:
997
        if (effectiveMinIsInclusive ? comparableObject.compareTo(value) > 0 : comparableObject.compareTo(value) >= 0)
861
              comparableObject.compareTo(value) >= 0)
862
        {
998
        {
863
          if (diagnostics != null)
999
          if (diagnostics != null)
864
          {
1000
          {
Lines 877-886 Link Here
877
1013
878
      if (effectiveMax != null)
1014
      if (effectiveMax != null)
879
      {
1015
      {
880
        @SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax;
1016
        @SuppressWarnings("unchecked")
881
        if (effectiveMaxIsInclusive ?
1017
        Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax;
882
              comparableObject.compareTo(value) < 0:
1018
        if (effectiveMaxIsInclusive ? comparableObject.compareTo(value) < 0 : comparableObject.compareTo(value) <= 0)
883
              comparableObject.compareTo(value) <= 0)
884
        {
1019
        {
885
          if (diagnostics != null)
1020
          if (diagnostics != null)
886
          {
1021
          {
Lines 944-983 Link Here
944
          result = false;
1079
          result = false;
945
        }
1080
        }
946
      }
1081
      }
1082
      
1083
      return result;
1084
    }
1085
1086
    public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context)
1087
    {
1088
      boolean result = validateDelegatedConstraints(eDataType, value, diagnostics, context);
947
1089
948
      if (itemType != null)
1090
      if (result || diagnostics != null)
949
      {
1091
      {
950
        EValidator rootValidator = getRootEValidator(context);
1092
        result &= validateSchemaConstraints(eDataType, value, diagnostics, context);
951
        for (Iterator<?> i = ((List<?>)value).iterator(); i.hasNext() && (result || diagnostics != null); )
1093
1094
        if (itemType != null)
1095
        {
1096
          EValidator rootValidator = getRootEValidator(context);
1097
          for (Iterator< ? > i = ((List< ? >)value).iterator(); i.hasNext() && (result || diagnostics != null);)
1098
          {
1099
            result &= rootValidator.validate(itemType, i.next(), diagnostics, context);
1100
          }
1101
          return result;
1102
        }
1103
        else if (!memberTypes.isEmpty())
952
        {
1104
        {
953
          result &= rootValidator.validate(itemType, i.next(), diagnostics, context);
1105
          EValidator rootValidator = getRootEValidator(context);
1106
1107
          for (EDataType memberType : memberTypes)
1108
          {
1109
            if (rootValidator.validate(memberType, value, null, context))
1110
            {
1111
              return true;
1112
            }
1113
          }
1114
          for (EDataType memberType : memberTypes)
1115
          {
1116
            if (memberType.isInstance(value))
1117
            {
1118
              return rootValidator.validate(memberType, value, diagnostics, context);
1119
            }
1120
          }
1121
          return false;
1122
        }
1123
        else
1124
        {
1125
          return result;
954
        }
1126
        }
955
        return result;
956
      }
1127
      }
957
      else if (!memberTypes.isEmpty())
1128
1129
      return result;
1130
    }
1131
  }
1132
1133
  public class DynamicEClassValidator
1134
  {
1135
    protected boolean validateDelegatedInvariants(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context)
1136
    {
1137
      boolean result = true;
1138
      List<String> validationDelegates = EcoreUtil.getValidationDelegates(eClass.getEPackage());
1139
1140
      if (!validationDelegates.isEmpty())
958
      {
1141
      {
959
        EValidator rootValidator = getRootEValidator(context);
1142
        INVARIANTS: for (EOperation eOperation : eClass.getEOperations())
960
        
961
        for (EDataType memberType : memberTypes)
962
        {
1143
        {
963
          if (rootValidator.validate(memberType, value, null, context))
1144
          if (EcoreUtil.isInvariant(eOperation))
964
          {
1145
          {
965
            return true;
1146
            for (String validationDelegate : validationDelegates)
1147
            {
1148
              String expression = EcoreUtil.getAnnotation(eOperation, validationDelegate, "body");
1149
              if (expression != null)
1150
              {
1151
                result &= EObjectValidator.validate(eClass, eObject, diagnostics, context, validationDelegate, eOperation, expression, Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0);
1152
                if (!result && diagnostics == null)
1153
                  break INVARIANTS;
1154
              }
1155
            }
966
          }
1156
          }
967
        }
1157
        }
968
        for (EDataType memberType : memberTypes)
1158
      }
1159
1160
      return result;
1161
    }
1162
    
1163
    protected boolean validateDelegatedConstraints(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context)
1164
    {
1165
      boolean result = true;
1166
      List<String> validationDelegates = EcoreUtil.getValidationDelegates(eClass.getEPackage());
1167
1168
      if (!validationDelegates.isEmpty())
1169
      {
1170
        CONSTRAINTS: for (String constraint : EcoreUtil.getConstraints(eClass))
969
        {
1171
        {
970
          if (memberType.isInstance(value))
1172
          for (String validationDelegate : validationDelegates)
971
          {
1173
          {
972
            return rootValidator.validate(memberType, value, diagnostics, context);
1174
            String expression = EcoreUtil.getAnnotation(eClass, validationDelegate, constraint);
1175
            if (expression != null)
1176
            {
1177
              result &= EObjectValidator.validate(eClass, eObject, diagnostics, context, validationDelegate, constraint, expression, Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0);
1178
              if (!result && diagnostics == null)
1179
                break CONSTRAINTS;
1180
            }
973
          }
1181
          }
974
        }
1182
        }
975
        return false;
976
      }
1183
      }
977
      else
1184
1185
      return result;
1186
    }
1187
    
1188
    public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context)
1189
    {
1190
      boolean result = validateDelegatedInvariants(eClass, eObject, diagnostics, context);
1191
1192
      if (result || diagnostics != null)
978
      {
1193
      {
979
        return result;
1194
        result &= validateDelegatedConstraints(eClass, eObject, diagnostics, context);
1195
        
1196
        if (result || diagnostics != null)
1197
        {
1198
          List<EClass> eSuperTypes = eClass.getESuperTypes();
1199
          result &= eSuperTypes.isEmpty() ?
1200
            validate_EveryDefaultConstraint(eObject, diagnostics, context) :
1201
            validate(eSuperTypes.get(0), eObject, diagnostics, context);
1202
        }
980
      }
1203
      }
1204
1205
      return result;
981
    }
1206
    }
982
  }
1207
  }
983
1208
Lines 1202-1207 Link Here
1202
         context));
1427
         context));
1203
  }
1428
  }
1204
1429
1430
  /**
1431
   * @since 2.6
1432
   */
1433
  protected static void reportConstraintDelegateViolation(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code)
1434
  {
1435
    diagnostics.add
1436
      (new BasicDiagnostic
1437
        (severity,
1438
         source,
1439
         code,
1440
         EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { constraint, getValueLabel(eDataType, value, context) }),
1441
         new Object [] { value }));
1442
  }
1443
1444
  /**
1445
   * @since 2.6
1446
   */
1447
  protected static void reportConstraintDelegateException(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, Throwable throwable)
1448
  {
1449
    diagnostics.add
1450
      (new BasicDiagnostic
1451
        (severity,
1452
         source,
1453
         code,
1454
         EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateException_diagnostic", new Object[] { constraint, getValueLabel(eDataType, value, context), throwable.getLocalizedMessage() }),
1455
         new Object [] { value }));
1456
  }
1457
1458
  /**
1459
   * @since 2.6
1460
   */
1461
  protected static void reportConstraintDelegateNotFound(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, String validationDelegate)
1462
  {
1463
    diagnostics.add
1464
      (new BasicDiagnostic
1465
        (severity,
1466
         source,
1467
         code,
1468
         EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateNotFound_diagnostic", new Object[] { constraint, getValueLabel(eDataType, value, context), validationDelegate }),
1469
         new Object [] { value }));
1470
  }
1471
1472
  /**
1473
   * @since 2.6
1474
   */
1475
  protected static void reportConstraintDelegateViolation(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code)
1476
  {
1477
    diagnostics.add
1478
      (new BasicDiagnostic
1479
        (severity,
1480
         source,
1481
         code,
1482
         EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context) }),
1483
         new Object [] { eObject }));
1484
  }
1485
1486
  /**
1487
   * @since 2.6
1488
   */
1489
  protected static void reportConstraintDelegateException(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, Throwable throwable)
1490
  {
1491
    diagnostics.add
1492
      (new BasicDiagnostic
1493
        (severity,
1494
         source,
1495
         code,
1496
         EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateException_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context), throwable.getLocalizedMessage() }),
1497
         new Object [] { eObject }));
1498
  }
1499
1500
  /**
1501
   * @since 2.6
1502
   */
1503
  protected static void reportConstraintDelegateNotFound(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, String validationDelegate)
1504
  {
1505
    diagnostics.add
1506
      (new BasicDiagnostic
1507
        (severity,
1508
         source,
1509
         code,
1510
         EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateNotFound_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context), validationDelegate }),
1511
         new Object [] { eObject }));
1512
  }
1513
1514
  /**
1515
   * @since 2.6
1516
   */
1517
  protected static void reportInvariantDelegateViolation(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, EOperation invariant, int severity, String source, int code)
1518
  {
1519
    diagnostics.add
1520
      (new BasicDiagnostic
1521
        (severity,
1522
         source,
1523
         code,
1524
         EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { invariant.getName(), getObjectLabel(eObject, context) }),
1525
         new Object [] { eObject }));
1526
  }
1527
1528
  /**
1529
   * @since 2.6
1530
   */
1531
  protected static void reportInvariantDelegateException(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, EOperation invariant, int severity, String source, int code, Throwable throwable)
1532
  {
1533
    diagnostics.add
1534
      (new BasicDiagnostic
1535
        (severity,
1536
         source,
1537
         code,
1538
         EcorePlugin.INSTANCE.getString("_UI_InvariantDelegateException_diagnostic", new Object[] { invariant.getName(), getObjectLabel(eObject, context), throwable.getLocalizedMessage() }),
1539
         new Object [] { eObject }));
1540
  }
1541
1542
  /**
1543
   * @since 2.6
1544
   */
1545
  protected static void reportInvariantDelegateNotFound(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, EOperation invariant, int severity, String source, int code, String validationDelegate)
1546
  {
1547
    diagnostics.add
1548
    (new BasicDiagnostic
1549
      (severity,
1550
       source,
1551
       code,
1552
       EcorePlugin.INSTANCE.getString("_UI_InvariantDelegateNotFound_diagnostic", new Object[] { invariant.getName(), getObjectLabel(eObject, context), validationDelegate }),
1553
       new Object [] { eObject }));
1554
  }
1555
1205
  protected static Collection<Object> wrapEnumerationValues(Object [] values)
1556
  protected static Collection<Object> wrapEnumerationValues(Object [] values)
1206
  {
1557
  {
1207
    return java.util.Arrays.asList(values);
1558
    return java.util.Arrays.asList(values);
Lines 1471-1476 Link Here
1471
  }
1822
  }
1472
1823
1473
  /**
1824
  /**
1825
   * @since 2.6
1826
   */
1827
  protected boolean isEcoreString(String key)
1828
  {
1829
    return "_UI_GenericConstraint_diagnostic".equals(key) || "_UI_GenericInvariant_diagnostic".equals(key)
1830
      || "_UI_ConstraintDelegateException_diagnostic".equals(key) || "_UI_InvariantDelegateException_diagnostic".equals(key)
1831
      || "_UI_ConstraintDelegateNotFound_diagnostic".equals(key) || "_UI_InvariantDelegateNotFound_diagnostic".equals(key);
1832
  }
1833
1834
  /**
1474
   * Returns a translated message with the given substitutions.
1835
   * Returns a translated message with the given substitutions.
1475
   * The {@link #getResourceLocator() resource locator} is used.
1836
   * The {@link #getResourceLocator() resource locator} is used.
1476
   * @param key the key for the message.
1837
   * @param key the key for the message.
Lines 1480-1486 Link Here
1480
   */
1841
   */
1481
  protected String getString(String key, Object [] substitutions)
1842
  protected String getString(String key, Object [] substitutions)
1482
  {
1843
  {
1483
    return getString("_UI_GenericConstraint_diagnostic".equals(key) ? getEcoreResourceLocator() : getResourceLocator(), key, substitutions);
1844
    return getString(isEcoreString(key) ? getEcoreResourceLocator() : getResourceLocator(), key, substitutions);
1484
  }
1845
  }
1485
1846
1486
  /**
1847
  /**
(-)plugin.xml (+1 lines)
Lines 10-15 Link Here
10
   <extension-point id="content_handler" name="%_UI_ContentHandlerRegistry_extensionpoint" schema="schema/content_handler.exsd"/>
10
   <extension-point id="content_handler" name="%_UI_ContentHandlerRegistry_extensionpoint" schema="schema/content_handler.exsd"/>
11
   <extension-point id="uri_mapping" name="%_UI_URIMappingRegistry_extensionpoint" schema="schema/uri_mapping.exsd"/>
11
   <extension-point id="uri_mapping" name="%_UI_URIMappingRegistry_extensionpoint" schema="schema/uri_mapping.exsd"/>
12
   <extension-point id="package_registry_implementation" name="%_UI_PackageRegistryImplementation_extensionpoint" schema="schema/package_registry_implementation.exsd"/>
12
   <extension-point id="package_registry_implementation" name="%_UI_PackageRegistryImplementation_extensionpoint" schema="schema/package_registry_implementation.exsd"/>
13
   <extension-point id="validation_delegate" name="%_UI_ValidationDelegateRegistry_extensionpoint" schema="schema/validation_delegate.exsd"/>
13
14
14
   <extension point="org.eclipse.emf.ecore.generated_package">
15
   <extension point="org.eclipse.emf.ecore.generated_package">
15
      <package
16
      <package
(-)plugin.properties (-1 / +7 lines)
Lines 1-7 Link Here
1
# /**
1
# /**
2
#  * <copyright>
2
#  * <copyright>
3
#  *
3
#  *
4
#  * Copyright (c) 2002-2008 IBM Corporation and others.
4
#  * Copyright (c) 2002-2009 IBM Corporation and others.
5
#  * All rights reserved.   This program and the accompanying materials
5
#  * All rights reserved.   This program and the accompanying materials
6
#  * are made available under the terms of the Eclipse Public License v1.0
6
#  * are made available under the terms of the Eclipse Public License v1.0
7
#  * which accompanies this distribution, and is available at
7
#  * which accompanies this distribution, and is available at
Lines 194-198 Link Here
194
_UI_EClassifierInstanceTypeNameExpectedSpace_diagnostic = Expecting '' '' at index {0}
194
_UI_EClassifierInstanceTypeNameExpectedSpace_diagnostic = Expecting '' '' at index {0}
195
_UI_EClassifierInstanceTypeNameUnexpectedSpace_diagnostic = Unexpected '' '' at index {0}
195
_UI_EClassifierInstanceTypeNameUnexpectedSpace_diagnostic = Unexpected '' '' at index {0}
196
196
197
_UI_InvariantDelegateException_diagnostic = An exception occurred while delegating evaluation of the ''{0}'' invariant on ''{1}'': {2}
198
_UI_InvariantDelegateNotFound_diagnostic = Unable to find delegate to evaluate the ''{0}'' invariant on ''{1}'': {2}
199
200
_UI_ConstraintDelegateException_diagnostic = An exception occurred while delegating evaluation of the ''{0}'' constraint on ''{1}'': {2}
201
_UI_ConstraintDelegateNotFound_diagnostic = Unable to find delegate to evaluate the ''{0}'' constraint on ''{1}'': {2}
202
197
# This is in org.eclipse.emf.ecore.xmi
203
# This is in org.eclipse.emf.ecore.xmi
198
#_UI_Ecore_content_type = Ecore File
204
#_UI_Ecore_content_type = Ecore File
(-)src/org/eclipse/emf/ecore/plugin/EcorePlugin.java (-1 / +3 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2002-2006 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 575-580 Link Here
575
      new ContentParserRegistryReader().readRegistry();
575
      new ContentParserRegistryReader().readRegistry();
576
      new ContentHandlerRegistryReader().readRegistry();
576
      new ContentHandlerRegistryReader().readRegistry();
577
      new URIMappingRegistryReader().readRegistry();
577
      new URIMappingRegistryReader().readRegistry();
578
      new ValidationDelegateRegistryReader().readRegistry();
578
    }
579
    }
579
  }
580
  }
580
581
Lines 631-634 Link Here
631
  public static final String SCHEME_PARSER_PPID = "scheme_parser";
632
  public static final String SCHEME_PARSER_PPID = "scheme_parser";
632
  public static final String URI_MAPPING_PPID = "uri_mapping";
633
  public static final String URI_MAPPING_PPID = "uri_mapping";
633
  public static final String PACKAGE_REGISTRY_IMPLEMENTATION_PPID = "package_registry_implementation";
634
  public static final String PACKAGE_REGISTRY_IMPLEMENTATION_PPID = "package_registry_implementation";
635
  public static final String VALIDATION_DELEGATE_PPID = "validation_delegate";  
634
}
636
}
(-)src/org/eclipse/emf/ecore/EValidator.java (-1 / +57 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2004-2006 IBM Corporation and others.
4
 * Copyright (c) 2004-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 117-122 Link Here
117
  }
117
  }
118
118
119
  /**
119
  /**
120
   * An interface for delegating validation expression evaluation.
121
   * @since 2.6
122
   */
123
  interface ValidationDelegate
124
  {
125
    /**
126
     * A <code>ValidationDelegate</code> wrapper that is used by the {@link ValidationDelegate.Registry}.
127
     */
128
    public interface Descriptor
129
    {
130
      /**
131
       * Returns the validation delegate.
132
       * @return the validation delegate.
133
       */
134
      ValidationDelegate getValidationDelegate();
135
    }
136
137
    /**
138
     * A map from {@link java.lang.String String} to {@link ValidationDelegate}.
139
     */
140
    interface Registry extends Map<String, Object>
141
    {
142
      /**
143
       * Looks up the validation delegate in the map.
144
       */
145
      ValidationDelegate getValidationDelegate(String id);
146
147
      /**
148
       * The global instance of a validation delegate registry.
149
       */
150
      Registry INSTANCE = new org.eclipse.emf.ecore.impl.ValidationDelegateRegistryImpl();
151
    }
152
153
    /**
154
     * Evaluates the given validation expression for the invariant against the object in the given context.
155
     * @param context a place to cache information, if it's <code>null</code>, no cache is supported.
156
     * @return the result of the expression evaluation.
157
     */
158
    boolean validate(EClass eClass, EObject eObject, Map<Object, Object> context, EOperation invariant, String expression);
159
160
    /**
161
     * Evaluates the given validation expression for the constraint against the object in the given context.
162
     * @param context a place to cache information, if it's <code>null</code>, no cache is supported.
163
     * @return the result of the expression evaluation.
164
     */
165
    boolean validate(EClass eClass, EObject eObject, Map<Object, Object> context, String constraint, String expression);
166
167
    /**
168
     * Evaluates the given validation expression for the constraint against the value in the given context.
169
     * @param context a place to cache information, if it's <code>null</code>, no cache is supported.
170
     * @return the result of the expression evaluation.
171
     */
172
    boolean validate(EDataType eDataType, Object value, Map<Object, Object> context, String constraint, String expression);
173
  }
174
175
  /**
120
   * Validates the object in the given context, optionally producing diagnostics.
176
   * Validates the object in the given context, optionally producing diagnostics.
121
   * @param diagnostics a place to accumulate diagnostics; if it's <code>null</code>, no diagnostics should be produced.
177
   * @param diagnostics a place to accumulate diagnostics; if it's <code>null</code>, no diagnostics should be produced.
122
   * @param context a place to cache information, if it's <code>null</code>, no cache is supported.
178
   * @param context a place to cache information, if it's <code>null</code>, no cache is supported.
(-)src/org/eclipse/emf/ecore/plugin/ValidationDelegateRegistryReader.java (+93 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 *
4
 * Copyright (c) 2009 Kenn Hussey and others.
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 * 
10
 * Contributors: 
11
 *   Kenn Hussey - Initial API and implementation
12
 *
13
 * </copyright>
14
 *
15
 * $Id$
16
 */
17
package org.eclipse.emf.ecore.plugin;
18
19
import org.eclipse.core.runtime.IConfigurationElement;
20
import org.eclipse.core.runtime.Platform;
21
22
import org.eclipse.emf.ecore.EValidator;
23
24
25
/**
26
 * A plugin extension reader that populates the
27
 * {@link org.eclipse.emf.ecore.EValidator.ValidationDelegate.Registry#INSTANCE global} validation delegate registry.
28
 * Clients are not expected to use this class directly.
29
 */
30
class ValidationDelegateRegistryReader extends RegistryReader
31
{
32
  static class ValidationDelegateDescriptor extends PluginClassDescriptor implements EValidator.ValidationDelegate.Descriptor
33
  {
34
    protected EValidator.ValidationDelegate validationDelegate;
35
36
    public ValidationDelegateDescriptor(IConfigurationElement e, String attrName)
37
    {
38
      super(e, attrName);
39
    }
40
41
    public EValidator.ValidationDelegate getValidationDelegate()
42
    {
43
      if (validationDelegate == null)
44
      {
45
        validationDelegate = (EValidator.ValidationDelegate)createInstance();
46
      }
47
      return validationDelegate;
48
    }
49
  }
50
51
  static final String TAG_DELEGATE = "delegate";
52
  static final String ATT_ID = "id";
53
  static final String ATT_CLASS = "class";
54
55
  public ValidationDelegateRegistryReader()
56
  {
57
    super(Platform.getExtensionRegistry(), EcorePlugin.getPlugin().getBundle().getSymbolicName(), EcorePlugin.VALIDATION_DELEGATE_PPID);
58
  }
59
60
  @Override
61
  protected boolean readElement(IConfigurationElement element, boolean add)
62
  {
63
    if (element.getName().equals(TAG_DELEGATE))
64
    {
65
      String id = element.getAttribute(ATT_ID);
66
      if (id == null)
67
      {
68
        logMissingAttribute(element, ATT_ID);
69
      }
70
      else if (element.getAttribute(ATT_CLASS) == null)
71
      {
72
        logMissingAttribute(element, ATT_CLASS);
73
      }
74
      else if (add)
75
      {
76
        Object previous = EValidator.ValidationDelegate.Registry.INSTANCE.put(id, new ValidationDelegateDescriptor(element, ATT_CLASS));
77
        if (previous instanceof ValidationDelegateDescriptor)
78
        {
79
          ValidationDelegateDescriptor descriptor = (ValidationDelegateDescriptor)previous;
80
          EcorePlugin.INSTANCE.log("Both '" + descriptor.element.getContributor().getName() + "' and '" + element.getContributor().getName() + "' register a validation delegate for '" + id + "'");
81
        }
82
        return true;
83
      }
84
      else
85
      {
86
        EValidator.ValidationDelegate.Registry.INSTANCE.remove(id);
87
        return true;
88
      }
89
    }
90
91
    return false;
92
  }
93
}
(-)src/org/eclipse/emf/ecore/impl/ValidationDelegateRegistryImpl.java (+84 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 *
4
 * Copyright (c) 2009 Kenn Hussey and others.
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 * 
10
 * Contributors: 
11
 *   Kenn Hussey - Initial API and implementation
12
 *
13
 * </copyright>
14
 *
15
 * $Ids$
16
 */
17
package org.eclipse.emf.ecore.impl;
18
19
import java.util.HashMap;
20
21
import org.eclipse.emf.ecore.EValidator;
22
23
24
/**
25
 * An implementation of a validation delegate registry.
26
 */
27
public class ValidationDelegateRegistryImpl extends HashMap<String, Object> implements EValidator.ValidationDelegate.Registry
28
{
29
  private static final long serialVersionUID = 1L;
30
31
  protected EValidator.ValidationDelegate.Registry delegateRegistry;
32
33
  public ValidationDelegateRegistryImpl()
34
  {
35
    super();
36
  }
37
38
  public ValidationDelegateRegistryImpl(EValidator.ValidationDelegate.Registry delegateRegistry)
39
  {
40
    this.delegateRegistry = delegateRegistry;
41
  }
42
43
  @Override
44
  public Object get(Object key)
45
  {
46
    Object validationDelegate = super.get(key);
47
    if (validationDelegate instanceof EValidator.ValidationDelegate.Descriptor)
48
    {
49
      EValidator.ValidationDelegate.Descriptor validationDelegateDescriptor = (EValidator.ValidationDelegate.Descriptor)validationDelegate;
50
      validationDelegate = validationDelegateDescriptor.getValidationDelegate();
51
      put((String)key, validationDelegate);
52
      return validationDelegate;
53
    }
54
    else if (validationDelegate != null)
55
    {
56
      return validationDelegate;
57
    }
58
    else
59
    {
60
      return delegatedGet(key);
61
    }
62
  }
63
64
  public EValidator.ValidationDelegate getValidationDelegate(String id)
65
  {
66
    return (EValidator.ValidationDelegate)get(id);
67
  }
68
69
  protected Object delegatedGet(Object key)
70
  {
71
    if (delegateRegistry != null)
72
    {
73
      return delegateRegistry.get(key);
74
    }
75
76
    return null;
77
  }
78
79
  @Override
80
  public boolean containsKey(Object key)
81
  {
82
    return super.containsKey(key) || delegateRegistry != null && delegateRegistry.containsKey(key);
83
  }
84
}
(-)schema/validation_delegate.exsd (+124 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.emf.ecore" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.emf.ecore" id="validation_delegate" name="Validation Delegate Registry"/>
7
      </appInfo>
8
      <documentation>
9
         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, &lt;samp&gt;EValidator.ValidationDelegate.Factory.Registry.INSTANCE&lt;/samp&gt;, is used to record the registration.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="delegate" minOccurs="1" maxOccurs="unbounded"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  A fully qualified identifier of the target extension point.
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  An optional identifier of the extension instance.
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  An optional name of the extension instance.
41
               </documentation>
42
            </annotation>
43
         </attribute>
44
      </complexType>
45
   </element>
46
47
   <element name="delegate">
48
      <annotation>
49
         <appInfo>
50
            <meta.element labelAttribute="id"/>
51
         </appInfo>
52
      </annotation>
53
      <complexType>
54
         <attribute name="id" type="string" use="required">
55
            <annotation>
56
               <documentation>
57
                  A unique identifier (e.g., a URI) for the type of expressions that can be evaluated by the validation delegate.
58
               </documentation>
59
            </annotation>
60
         </attribute>
61
         <attribute name="class" type="string" use="required">
62
            <annotation>
63
               <documentation>
64
                  The fully qualified name of a Java class implementing &lt;samp&gt;org.eclipse.emf.ecore.EValidator.ValidationDelegate&lt;/samp&gt;.
65
               </documentation>
66
               <appInfo>
67
                  <meta.attribute kind="java" basedOn="org.eclipse.emf.ecore.EValidator.ValidationDelegate"/>
68
               </appInfo>
69
            </annotation>
70
         </attribute>
71
      </complexType>
72
   </element>
73
74
   <annotation>
75
      <appInfo>
76
         <meta.section type="since"/>
77
      </appInfo>
78
      <documentation>
79
         2.6.0
80
      </documentation>
81
   </annotation>
82
83
   <annotation>
84
      <appInfo>
85
         <meta.section type="examples"/>
86
      </appInfo>
87
      <documentation>
88
         Following is an example of how a validation delegate can be registered: 
89
&lt;pre&gt;
90
  &lt;extension point=&quot;org.eclipse.emf.ecore.validation_delegate&quot; &gt;
91
    &lt;delegate uri=&quot;org.eclipse.ocl.ecore.OCL&quot; class=&quot;org.eclipse.ocl.OCLValidationDelegate&quot;/&gt; 
92
  &lt;/extension&gt;
93
&lt;/pre&gt;
94
      </documentation>
95
   </annotation>
96
97
   <annotation>
98
      <appInfo>
99
         <meta.section type="apiInfo"/>
100
      </appInfo>
101
      <documentation>
102
         The value of the class attribute must represent a class that implements &lt;samp&gt;org.eclipse.emf.ecore.EValidator.ValidationDelegate&lt;/samp&gt; and has a no argument contructor.
103
&lt;p&gt;
104
A validation delegate can be also registered from the source code with the &lt;samp&gt;EValidator.ValidationDelegate.Registry.INSTANCE&lt;/samp&gt; as follows:
105
&lt;/p&gt;
106
&lt;pre&gt;
107
  EValidator.ValidationDelegate.Registry.INSTANCE.put(URI.createURI(&quot;org.eclipse.ocl.ecore.OCL&quot;), new OCLValidationDelegate());
108
&lt;/pre&gt;
109
      </documentation>
110
   </annotation>
111
112
113
   <annotation>
114
      <appInfo>
115
         <meta.section type="copyright"/>
116
      </appInfo>
117
      <documentation>
118
         Copyright (c) 2009 Kenn Hussey and others.&lt;br&gt;
119
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 &lt;a 
120
href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
121
      </documentation>
122
   </annotation>
123
124
</schema>
(-)src/org/eclipse/emf/codegen/util/CodeGenUtil.java (-1 / +17 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2002-2007 IBM Corporation and others.
4
 * Copyright (c) 2002-2009 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 477-482 Link Here
477
  }
477
  }
478
478
479
  /**
479
  /**
480
   * @since 2.6
481
   */
482
  public static String upperName(String name, Locale locale)
483
  {
484
    return format(name, '_', null, false, true).toUpperCase(locale);
485
  }
486
487
  /**
488
   * @since 2.6
489
   */
490
  public static String upperName(String name)
491
  {
492
    return upperName(name, Locale.getDefault());
493
  }
494
495
  /**
480
   * @deprecated In 2.2. Please use {@link #format(String, char, String, boolean, boolean)} instead.
496
   * @deprecated In 2.2. Please use {@link #format(String, char, String, boolean, boolean)} instead.
481
   */
497
   */
482
  @Deprecated
498
  @Deprecated

Return to bug 255786