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

(-)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="constraints_delegator_registry" name="%_UI_ConstraintsDelegatorRegistry_extensionpoint" schema="schema/constraints_delegator_registry.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 (+2 lines)
Lines 116-121 Link Here
116
_UI_ContentHandler_extensionpoint = Content Handler Registry
116
_UI_ContentHandler_extensionpoint = Content Handler Registry
117
_UI_URIMappingRegistry_extensionpoint = URI Converter Mapping Registry
117
_UI_URIMappingRegistry_extensionpoint = URI Converter Mapping Registry
118
_UI_PackageRegistryImplementation_extensionpoint = Ecore Package Registry Implementation
118
_UI_PackageRegistryImplementation_extensionpoint = Ecore Package Registry Implementation
119
_UI_ConstraintsDelegatorRegistry_extensionpoint = Constraints Delegator Registry
120
119
121
120
_UI_GenericInvariant_diagnostic = The ''{0}'' invariant is violated on ''{1}''
122
_UI_GenericInvariant_diagnostic = The ''{0}'' invariant is violated on ''{1}''
121
_UI_GenericConstraint_diagnostic = The ''{0}'' constraint is violated on ''{1}''
123
_UI_GenericConstraint_diagnostic = The ''{0}'' constraint is violated on ''{1}''
(-)src/org/eclipse/emf/ecore/plugin/EcorePlugin.java (-62 / +65 lines)
Lines 55-61 Link Here
55
 * A collection of platform-neutral static utilities
55
 * A collection of platform-neutral static utilities
56
 * as well as Eclipse support utilities.
56
 * as well as Eclipse support utilities.
57
 */
57
 */
58
public class EcorePlugin  extends EMFPlugin
58
public class EcorePlugin extends EMFPlugin
59
{
59
{
60
  /**
60
  /**
61
   * The singleton instance of the plugin.
61
   * The singleton instance of the plugin.
Lines 67-73 Link Here
67
   */
67
   */
68
  private EcorePlugin()
68
  private EcorePlugin()
69
  {
69
  {
70
    super(new ResourceLocator[] {});
70
    super(new ResourceLocator []{});
71
  }
71
  }
72
72
73
  @Override
73
  @Override
Lines 162-168 Link Here
162
   * @param arguments an array of "command line" options.
162
   * @param arguments an array of "command line" options.
163
   * @return the arguments stripped of those recognized as platform resource options.
163
   * @return the arguments stripped of those recognized as platform resource options.
164
   */
164
   */
165
  public static String [] handlePlatformResourceOptions(String [] arguments)
165
  public static String[] handlePlatformResourceOptions(String[] arguments)
166
  {
166
  {
167
    getPlatformResourceMap();
167
    getPlatformResourceMap();
168
168
Lines 204-210 Link Here
204
          }
204
          }
205
        }
205
        }
206
206
207
        String [] remainingArguments = new String [arguments.length - (i - start)];
207
        String[] remainingArguments = new String [arguments.length - (i - start)];
208
        System.arraycopy(arguments, 0, remainingArguments, 0, start);
208
        System.arraycopy(arguments, 0, remainingArguments, 0, start);
209
        System.arraycopy(arguments, i, remainingArguments, start, arguments.length - i);
209
        System.arraycopy(arguments, i, remainingArguments, start, arguments.length - i);
210
        return remainingArguments;
210
        return remainingArguments;
Lines 213-219 Link Here
213
213
214
    return arguments;
214
    return arguments;
215
  }
215
  }
216
  
216
217
  /**
217
  /**
218
   * Returns a map from {@link EPackage#getNsURI() package namespace URI} (represented as a String) 
218
   * Returns a map from {@link EPackage#getNsURI() package namespace URI} (represented as a String) 
219
   * to the location of the GenModel containing a GenPackage for the package (represented as a {@link URI URI}).
219
   * to the location of the GenModel containing a GenPackage for the package (represented as a {@link URI URI}).
Lines 258-267 Link Here
258
    }
258
    }
259
    return result;
259
    return result;
260
  }
260
  }
261
  
261
262
  private static Pattern bundleSymbolNamePattern;
262
  private static Pattern bundleSymbolNamePattern;
263
  private static byte [] NO_BYTES = new byte [0];
263
  private static byte[] NO_BYTES = new byte [0];
264
  
264
265
  /**
265
  /**
266
   * Computes a map from <code>platform:/plugin/&lt;plugin-id>/</code> {@link URI} to 
266
   * Computes a map from <code>platform:/plugin/&lt;plugin-id>/</code> {@link URI} to 
267
   * <code>platform:/resource/&lt;plugin-location>/</code> URI
267
   * <code>platform:/resource/&lt;plugin-location>/</code> URI
Lines 277-288 Link Here
277
    Map<URI, URI> result = new HashMap<URI, URI>();
277
    Map<URI, URI> result = new HashMap<URI, URI>();
278
    IWorkspaceRoot root = getWorkspaceRoot();
278
    IWorkspaceRoot root = getWorkspaceRoot();
279
    if (root != null)
279
    if (root != null)
280
    { 
280
    {
281
      IProject [] projects = root.getProjects();
281
      IProject[] projects = root.getProjects();
282
      if (projects != null)
282
      if (projects != null)
283
      {
283
      {
284
        String pluginID = null;
284
        String pluginID = null;
285
        
285
286
        class Handler extends DefaultHandler
286
        class Handler extends DefaultHandler
287
        {
287
        {
288
          public String pluginID;
288
          public String pluginID;
Lines 298-308 Link Here
298
          }
298
          }
299
        }
299
        }
300
        Handler handler = new Handler();
300
        Handler handler = new Handler();
301
        
301
302
        SAXParserFactory parserFactory= SAXParserFactory.newInstance();
302
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
303
        parserFactory.setNamespaceAware(true);
303
        parserFactory.setNamespaceAware(true);
304
        SAXParser parser = null;
304
        SAXParser parser = null;
305
        
305
306
        try
306
        try
307
        {
307
        {
308
          parser = parserFactory.newSAXParser();
308
          parser = parserFactory.newSAXParser();
Lines 311-324 Link Here
311
        {
311
        {
312
          INSTANCE.log(exception);
312
          INSTANCE.log(exception);
313
        }
313
        }
314
        
314
315
        if (bundleSymbolNamePattern == null)
315
        if (bundleSymbolNamePattern == null)
316
        {
316
        {
317
          bundleSymbolNamePattern = Pattern.compile("^\\s*Bundle-SymbolicName\\s*:\\s*([^\\s;]*)\\s*(;.*)?$", Pattern.MULTILINE);
317
          bundleSymbolNamePattern = Pattern.compile("^\\s*Bundle-SymbolicName\\s*:\\s*([^\\s;]*)\\s*(;.*)?$", Pattern.MULTILINE);
318
        }
318
        }
319
        
319
320
        byte [] bytes = NO_BYTES;
320
        byte[] bytes = NO_BYTES;
321
        
321
322
        for (int i = 0, size = projects.length; i < size; ++i)
322
        for (int i = 0, size = projects.length; i < size; ++i)
323
        {
323
        {
324
          IProject project = projects[i];
324
          IProject project = projects[i];
Lines 331-337 Link Here
331
              InputStream inputStream = null;
331
              InputStream inputStream = null;
332
              try
332
              try
333
              {
333
              {
334
                inputStream = manifest.getContents(); 
334
                inputStream = manifest.getContents();
335
                int available = inputStream.available();
335
                int available = inputStream.available();
336
                if (bytes.length < available)
336
                if (bytes.length < available)
337
                {
337
                {
Lines 386-406 Link Here
386
                }
386
                }
387
              }
387
              }
388
            }
388
            }
389
            
389
390
            if (pluginID != null)
390
            if (pluginID != null)
391
            {
391
            {
392
              URI platformPluginURI = URI.createPlatformPluginURI(pluginID + "/", false);
392
              URI platformPluginURI = URI.createPlatformPluginURI(pluginID + "/", false);
393
              URI platformResourceURI = URI.createPlatformResourceURI(project.getName() + "/",  true);
393
              URI platformResourceURI = URI.createPlatformResourceURI(project.getName() + "/", true);
394
              result.put(platformPluginURI, platformResourceURI);
394
              result.put(platformPluginURI, platformResourceURI);
395
            }
395
            }
396
          }
396
          }
397
        }
397
        }
398
      }
398
      }
399
    }
399
    }
400
    
400
401
    return result;
401
    return result;
402
  }
402
  }
403
  
403
404
  /**
404
  /**
405
   * Computes a map so that plugins in the workspace will override those in the environment
405
   * Computes a map so that plugins in the workspace will override those in the environment
406
   * and so that plugins with Ecore and GenModels will look like projects in the workspace.
406
   * and so that plugins with Ecore and GenModels will look like projects in the workspace.
Lines 425-437 Link Here
425
    result.putAll(computePlatformResourceToPlatformPluginMap(new HashSet<URI>(EcorePlugin.getEPackageNsURIToGenModelLocationMap().values())));
425
    result.putAll(computePlatformResourceToPlatformPluginMap(new HashSet<URI>(EcorePlugin.getEPackageNsURIToGenModelLocationMap().values())));
426
    return result;
426
    return result;
427
  }
427
  }
428
  
428
429
  /**
429
  /**
430
   * The platform resource map.
430
   * The platform resource map.
431
   * @see #getPlatformResourceMap
431
   * @see #getPlatformResourceMap
432
   */
432
   */
433
  private static Map<String, URI> platformResourceMap;
433
  private static Map<String, URI> platformResourceMap;
434
  
434
435
  /**
435
  /**
436
   * The map from package namespace URIs to the location of the GenModel for that package.
436
   * The map from package namespace URIs to the location of the GenModel for that package.
437
   * @see #getPlatformResourceMap
437
   * @see #getPlatformResourceMap
Lines 452-458 Link Here
452
      super();
452
      super();
453
      plugin = this;
453
      plugin = this;
454
    }
454
    }
455
  
455
456
    /**
456
    /**
457
     * Starts up this plugin by reading some extensions and populating the relevant registries.
457
     * Starts up this plugin by reading some extensions and populating the relevant registries.
458
     * <p>
458
     * <p>
Lines 520-571 Link Here
520
        workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
520
        workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
521
      }
521
      }
522
522
523
      new RegistryReader
523
      new RegistryReader(
524
        (Platform.getExtensionRegistry(),
524
        Platform.getExtensionRegistry(),
525
         EcorePlugin.getPlugin().getBundle().getSymbolicName(), 
525
        EcorePlugin.getPlugin().getBundle().getSymbolicName(),
526
         PACKAGE_REGISTRY_IMPLEMENTATION_PPID)
526
        PACKAGE_REGISTRY_IMPLEMENTATION_PPID)
527
      {
528
        IConfigurationElement previous;
529
530
        @Override
531
        protected boolean readElement(IConfigurationElement element)
532
        {
527
        {
533
          if (element.getName().equals("registry"))
528
          IConfigurationElement previous;
529
530
          @Override
531
          protected boolean readElement(IConfigurationElement element)
534
          {
532
          {
535
            String implementationClass = element.getAttribute("class");
533
            if (element.getName().equals("registry"))
536
            if (implementationClass == null)
537
            {
534
            {
538
              logMissingAttribute(element, "class");
535
              String implementationClass = element.getAttribute("class");
539
            }
536
              if (implementationClass == null)
540
            else
537
              {
541
            {
538
                logMissingAttribute(element, "class");
542
              if (defaultRegistryImplementation != null)
539
              }
540
              else
543
              {
541
              {
544
                if (previous != null)
542
                if (defaultRegistryImplementation != null)
545
                {
543
                {
546
                  log("Both '" + previous.getContributor().getName() + "' and '" + element.getContributor().getName() + "' register a package registry implementation");
544
                  if (previous != null)
545
                  {
546
                    log("Both '" + previous.getContributor().getName() + "' and '" + element.getContributor().getName()
547
                      + "' register a package registry implementation");
548
                  }
549
                  if (defaultRegistryImplementation instanceof EPackageRegistryImpl.Delegator)
550
                  {
551
                    return false;
552
                  }
547
                }
553
                }
548
                if (defaultRegistryImplementation instanceof EPackageRegistryImpl.Delegator)
554
                try
549
                {
555
                {
550
                  return false;
556
                  defaultRegistryImplementation = (EPackage.Registry)element.createExecutableExtension("class");
557
                  previous = element;
551
                }
558
                }
559
                catch (CoreException exception)
560
                {
561
                  log(exception);
562
                }
563
                return true;
552
              }
564
              }
553
              try
554
              {
555
                defaultRegistryImplementation = (EPackage.Registry)element.createExecutableExtension("class");
556
                previous = element;
557
              }
558
              catch (CoreException exception)
559
              {
560
                log(exception);
561
              }
562
              return true;
563
            }
565
            }
566
            return false;
564
          }
567
          }
565
          return false;
568
566
        }
569
        }.readRegistry();
567
        
568
      }.readRegistry();
569
570
570
      new GeneratedPackageRegistryReader(getEPackageNsURIToGenModelLocationMap()).readRegistry();
571
      new GeneratedPackageRegistryReader(getEPackageNsURIToGenModelLocationMap()).readRegistry();
571
      new DynamicPackageRegistryReader().readRegistry();
572
      new DynamicPackageRegistryReader().readRegistry();
Lines 575-587 Link Here
575
      new ContentParserRegistryReader().readRegistry();
576
      new ContentParserRegistryReader().readRegistry();
576
      new ContentHandlerRegistryReader().readRegistry();
577
      new ContentHandlerRegistryReader().readRegistry();
577
      new URIMappingRegistryReader().readRegistry();
578
      new URIMappingRegistryReader().readRegistry();
579
      new ConstraintsDelegatorFactoryRegistryReader().readRegistry();
578
    }
580
    }
579
  }
581
  }
580
582
581
  /**
583
  /**
582
   * The default registry implementation singleton.
584
   * The default registry implementation singleton.
583
   */
585
   */
584
  private static EPackage.Registry defaultRegistryImplementation; 
586
  private static EPackage.Registry defaultRegistryImplementation;
585
587
586
  /**
588
  /**
587
   * Returns the default registry implementation singleton.
589
   * Returns the default registry implementation singleton.
Lines 631-634 Link Here
631
  public static final String SCHEME_PARSER_PPID = "scheme_parser";
633
  public static final String SCHEME_PARSER_PPID = "scheme_parser";
632
  public static final String URI_MAPPING_PPID = "uri_mapping";
634
  public static final String URI_MAPPING_PPID = "uri_mapping";
633
  public static final String PACKAGE_REGISTRY_IMPLEMENTATION_PPID = "package_registry_implementation";
635
  public static final String PACKAGE_REGISTRY_IMPLEMENTATION_PPID = "package_registry_implementation";
636
  public static final String CONSTRAINTS_DELEGATOR_FACTORY = "constraints_delegator_registry";
634
}
637
}
(-)src/org/eclipse/emf/ecore/util/EObjectValidator.java (-14 / +139 lines)
Lines 16-22 Link Here
16
 */
16
 */
17
package org.eclipse.emf.ecore.util;
17
package org.eclipse.emf.ecore.util;
18
18
19
19
import java.lang.reflect.Array;
20
import java.math.BigDecimal;
20
import java.util.ArrayList;
21
import java.util.ArrayList;
21
import java.util.Collection;
22
import java.util.Collection;
22
import java.util.HashMap;
23
import java.util.HashMap;
Lines 25-57 Link Here
25
import java.util.ListIterator;
26
import java.util.ListIterator;
26
import java.util.Map;
27
import java.util.Map;
27
28
28
import java.lang.reflect.Array;
29
import java.math.BigDecimal;
30
31
import org.eclipse.emf.common.util.BasicDiagnostic;
29
import org.eclipse.emf.common.util.BasicDiagnostic;
32
import org.eclipse.emf.common.util.BasicEList;
30
import org.eclipse.emf.common.util.BasicEList;
33
import org.eclipse.emf.common.util.Diagnostic;
31
import org.eclipse.emf.common.util.Diagnostic;
34
import org.eclipse.emf.common.util.DiagnosticChain;
32
import org.eclipse.emf.common.util.DiagnosticChain;
35
import org.eclipse.emf.common.util.EMap;
33
import org.eclipse.emf.common.util.EMap;
36
import org.eclipse.emf.common.util.ResourceLocator;
34
import org.eclipse.emf.common.util.ResourceLocator;
37
35
import org.eclipse.emf.ecore.EAnnotation;
38
import org.eclipse.emf.ecore.EValidator;
39
40
import org.eclipse.emf.ecore.EAttribute;
36
import org.eclipse.emf.ecore.EAttribute;
41
import org.eclipse.emf.ecore.EObject;
42
import org.eclipse.emf.ecore.EClass;
37
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;
38
import org.eclipse.emf.ecore.EDataType;
39
import org.eclipse.emf.ecore.EObject;
46
import org.eclipse.emf.ecore.EPackage;
40
import org.eclipse.emf.ecore.EPackage;
41
import org.eclipse.emf.ecore.EReference;
47
import org.eclipse.emf.ecore.EStructuralFeature;
42
import org.eclipse.emf.ecore.EStructuralFeature;
43
import org.eclipse.emf.ecore.EValidator;
44
import org.eclipse.emf.ecore.EcorePackage;
48
import org.eclipse.emf.ecore.InternalEObject;
45
import org.eclipse.emf.ecore.InternalEObject;
49
50
import org.eclipse.emf.ecore.plugin.EcorePlugin;
46
import org.eclipse.emf.ecore.plugin.EcorePlugin;
51
52
import org.eclipse.emf.ecore.resource.Resource;
47
import org.eclipse.emf.ecore.resource.Resource;
53
import org.eclipse.emf.ecore.resource.ResourceSet;
48
import org.eclipse.emf.ecore.resource.ResourceSet;
54
49
import org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory;
55
import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil;
50
import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil;
56
51
57
52
Lines 82-87 Link Here
82
  
77
  
83
  static final int EOBJECT_DIAGNOSTIC_CODE_COUNT = EOBJECT__NO_CIRCULAR_CONTAINMENT;
78
  static final int EOBJECT_DIAGNOSTIC_CODE_COUNT = EOBJECT__NO_CIRCULAR_CONTAINMENT;
84
  
79
  
80
  // constants for user validation
81
  private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_FACTORY = "factory";
82
  private static final String USER_CONSTRAINT_VALIDATION_NAME = "name";
83
  private static final String USER_CONSTRAINT_VALIDATION_MESSAGE = "message";
84
  private static final String USER_CONSTRAINT_VALIDATION_SEVERITY = "severity";
85
  private static final String USER_CONSTRAINT_VALIDATION_CONSTRAINT = "constraint";
86
  private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_INHERITANCE = "inheritsConstraints";
87
  private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_ECORE = "http://www.eclipse.org/emf/2002/Ecore";
88
  
85
  /**
89
  /**
86
   * A key to be used in <code>context</code> maps to indicate the root object at which validation started.
90
   * A key to be used in <code>context</code> maps to indicate the root object at which validation started.
87
   * It's used to detect {@link #EOBJECT__NO_CIRCULAR_CONTAINMENT circular containment}
91
   * It's used to detect {@link #EOBJECT__NO_CIRCULAR_CONTAINMENT circular containment}
Lines 228-233 Link Here
228
    {
232
    {
229
      result &= validate_EveryMapEntryUnique(object, theDiagnostics, context);
233
      result &= validate_EveryMapEntryUnique(object, theDiagnostics, context);
230
    }
234
    }
235
    if (result || theDiagnostics != null)
236
    {
237
      result &= validate_UserConstraints(object, theDiagnostics, context);
238
    }
231
    return result;
239
    return result;
232
  }
240
  }
233
241
Lines 1417-1423 Link Here
1417
        }
1425
        }
1418
      }
1426
      }
1419
    }
1427
    }
1420
1428
        return result;
1429
  }
1430
  
1431
  /**
1432
   * @since 2.5
1433
   * @param theEClass the eclass of the eobject
1434
   * @param objectn the eobject to check
1435
   * @param theDiagnostics the diagnostic chain to modify if problems
1436
   * @param context the context
1437
   * @return true if user constraint ok false else
1438
   */
1439
  protected boolean validate_UserConstraintsByEClass(
1440
    EClass theEClass,
1441
    EObject object,
1442
    DiagnosticChain theDiagnostics,
1443
    Map<Object, Object> context)
1444
  {
1445
    // we check if the factory is declared in EPackage if it 's not the case. Constraints can't be checked
1446
    Collection<EAnnotation> annotations = theEClass.getEAnnotations();
1447
    EAnnotation annotationPackage = theEClass.getEPackage().getEAnnotation(USER_CONSTRAINT_VALIDATION_EANNOTATION_ECORE);
1448
    boolean result = true;
1449
    boolean inheritsConstraints = true;
1450
    if (annotationPackage != null && annotationPackage.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_EANNOTATION_FACTORY))
1451
    {
1452
      String factoryName = "";
1453
      String keyName = "";
1454
      String strFactory = annotationPackage.getDetails().get(USER_CONSTRAINT_VALIDATION_EANNOTATION_FACTORY);
1455
      String[] strs = strFactory.split("#");
1456
      if (strs != null && strs.length == 2)
1457
      {
1458
        factoryName = strs[0];
1459
        keyName = strs[1];
1460
      }
1461
      else
1462
      {
1463
        factoryName = strFactory;
1464
        keyName = strFactory;
1465
      }
1466
      Factory factory = ConstraintsDelegator.Factory.Registry.INSTANCE.getFactory(factoryName);
1467
      if (factory != null)
1468
      {
1469
        for (EAnnotation e : annotations)
1470
        {
1471
          // for validation
1472
          String rule = "";
1473
          String ruleName = "";
1474
          String message = "";
1475
          int severity = Diagnostic.WARNING;
1476
          if (keyName.equals(e.getSource()) || factoryName.equals(e.getSource()))
1477
          {
1478
            if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_EANNOTATION_INHERITANCE))
1479
            {
1480
              String value = e.getDetails().get(USER_CONSTRAINT_VALIDATION_EANNOTATION_INHERITANCE);
1481
              if (value != null && ("true".equals(value.trim().toLowerCase()) || "false".equals(value.trim().toLowerCase())))
1482
              {
1483
                inheritsConstraints = Boolean.valueOf(value);
1484
              }
1485
            }
1486
            if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_CONSTRAINT))
1487
            {
1488
              rule = e.getDetails().get(USER_CONSTRAINT_VALIDATION_CONSTRAINT);
1489
              // default value
1490
              ruleName = rule;
1491
              message = "problem with rule " + rule;
1492
              // we need at least a constraint to work
1493
              if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_MESSAGE))
1494
              {
1495
                message = e.getDetails().get(USER_CONSTRAINT_VALIDATION_MESSAGE);
1496
              }
1497
              if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_NAME))
1498
              {
1499
                ruleName = e.getDetails().get(USER_CONSTRAINT_VALIDATION_NAME);
1500
              }
1501
              if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_SEVERITY))
1502
              {
1503
                String severityS = e.getDetails().get(USER_CONSTRAINT_VALIDATION_SEVERITY);
1504
                severityS = severityS.toLowerCase().trim();
1505
                if ("warning".equals(severityS))
1506
                {
1507
                  severity = Diagnostic.WARNING;
1508
                }
1509
                else if ("error".equals(severityS))
1510
                {
1511
                  severity = Diagnostic.ERROR;
1512
                }
1513
              }
1514
              ConstraintsDelegator constraintDelegator = factory.createConstraintDelegator();
1515
              if (constraintDelegator != null)
1516
              {
1517
                result &= constraintDelegator.validate(rule, ruleName, severity, message, object, theDiagnostics, context);
1518
              }
1519
            }
1520
          }
1521
        }
1522
        // we check inherited constraints
1523
        if (inheritsConstraints)
1524
        {
1525
          for (EClass c : theEClass.getESuperTypes())
1526
          {
1527
            result &= validate_UserConstraintsByEClass(c, object, theDiagnostics, context);
1528
          }
1529
        }
1530
      }
1531
    }
1532
    return result;
1533
  }
1534
  
1535
  /**
1536
     * @since 2.5
1537
     * @param object the eobject to check
1538
     * @param theDiagnostics the diagnostic to modify if problem
1539
     * @param context the context
1540
     * @return true if user constraint is ok false else
1541
     */
1542
  protected boolean validate_UserConstraints(EObject object, DiagnosticChain theDiagnostics, Map<Object, Object> context)
1543
  {
1544
    EClass theclass = object.eClass();
1545
    boolean result = validate_UserConstraintsByEClass(theclass, object, theDiagnostics, context);
1421
    return result;
1546
    return result;
1422
  }
1547
  }
1423
1548
(-)src/org/eclipse/emf/ecore/plugin/ConstraintsDelegatorFactoryRegistryReader.java (+87 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Common Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/cpl-v10.html
9
 * 
10
 * Contributors: 
11
 *   IBM - Initial API and implementation
12
 *
13
 * </copyright>
14
 *
15
 * $Id: EMF_codetemplates.xml,v 1.1 2008/05/06 20:12:20 nickb Exp $
16
 */
17
package org.eclipse.emf.ecore.plugin;
18
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.emf.common.util.WrappedException;
23
import org.eclipse.emf.ecore.util.ConstraintsDelegator;
24
import org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory;
25
26
/**
27
 * A plugin extension reader that populates the
28
 * {@link org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory.Registry#INSTANCE global} resource factory's
29
 * Clients are not expected to use this class directly.
30
 */
31
public class ConstraintsDelegatorFactoryRegistryReader extends RegistryReader
32
{
33
  static final String TAG_FACTORY = "factory";
34
  static final String ATT_URI = "uri";
35
  static final String ATT_CLASS = "class";
36
  
37
  public ConstraintsDelegatorFactoryRegistryReader()
38
  {
39
    super
40
    (Platform.getExtensionRegistry(),
41
     EcorePlugin.getPlugin().getBundle().getSymbolicName(), 
42
     EcorePlugin.CONSTRAINTS_DELEGATOR_FACTORY);
43
  }
44
  
45
  @Override
46
  protected boolean readElement(IConfigurationElement element, boolean add)
47
  {
48
    if (element.getName().equals(TAG_FACTORY))
49
    {
50
      String packageURI = element.getAttribute(ATT_URI);
51
      if (packageURI == null)
52
      {
53
        logMissingAttribute(element, ATT_URI);
54
      }
55
      else if (element.getAttribute(ATT_CLASS) == null)
56
      {
57
        logMissingAttribute(element, ATT_CLASS);
58
      }
59
      else
60
      {
61
        try
62
        {
63
          Object o = element.createExecutableExtension(ATT_CLASS);
64
          if (o instanceof ConstraintsDelegator.Factory)
65
          {
66
            Factory tmp = ConstraintsDelegator.Factory.Registry.INSTANCE.getFactory(packageURI);
67
            if (tmp != null)
68
            {
69
              EcorePlugin.INSTANCE.log
70
              ("factory '" + o.getClass().getName() + "'tries to override '" + packageURI + "' instead of factor '" + tmp.getClass().getName()+"'");
71
            }
72
            else 
73
            {
74
              ConstraintsDelegator.Factory.Registry.INSTANCE.putFactory(packageURI, (Factory)o);
75
            }
76
          }
77
          return true;
78
        }
79
        catch (CoreException e)
80
        {
81
          throw new WrappedException(e);
82
        }
83
      }
84
    }
85
    return false;
86
  }
87
}
(-)schema/constraints_delegator_registry.exsd (+113 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="constraints_delegator_registry" name="%_UI_ConstraintsDelegatorRegistry_extensionpoint"/>
7
      </appinfo>
8
      <documentation>
9
         Adds a ConstraintDelegatorFactory to check constraints in Ecore models
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="factory"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="factory">
51
      <complexType>
52
         <attribute name="uri" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  the uri which will be inserted by user to check constraints
56
               </documentation>
57
            </annotation>
58
         </attribute>
59
         <attribute name="class" type="string" use="required">
60
            <annotation>
61
               <documentation>
62
                  A fully qualified name of the Java class implementing &lt;samp&gt;org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory
63
&lt;/samp&gt;.
64
               </documentation>
65
               <appinfo>
66
                  <meta.attribute kind="java" basedOn=":org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory"/>
67
               </appinfo>
68
            </annotation>
69
         </attribute>
70
      </complexType>
71
   </element>
72
73
   <annotation>
74
      <appinfo>
75
         <meta.section type="since"/>
76
      </appinfo>
77
      <documentation>
78
         2.5.0
79
      </documentation>
80
   </annotation>
81
82
   <annotation>
83
      <appinfo>
84
         <meta.section type="examples"/>
85
      </appinfo>
86
      <documentation>
87
         Following is an example of implementation
88
&lt;pre&gt;
89
&lt;extension
90
         point=&quot;org.eclipse.emf.ecore.constraints_delegator_regstry&quot;&gt;
91
      &lt;factory
92
            class=&quot;ocl.test.ConstraintsDelegator.MyFactory&quot;
93
            uri=&quot;org.eclipse.emf.ocl&quot;&gt;
94
      &lt;/factory&gt;
95
   &lt;/extension&gt;
96
&lt;/pre&gt;
97
      </documentation>
98
   </annotation>
99
100
101
102
   <annotation>
103
      <appinfo>
104
         <meta.section type="copyright"/>
105
      </appinfo>
106
      <documentation>
107
         Copyright (c) 2002, 2004 IBM Corporation and others.&lt;br&gt;
108
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 
109
href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
110
      </documentation>
111
   </annotation>
112
113
</schema>
(-)src/org/eclipse/emf/ecore/util/ConstraintsDelegator.java (+85 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 *
4
 * Copyright (c) 2005 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Common Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/cpl-v10.html
9
 * 
10
 * Contributors: 
11
 *   IBM - Initial API and implementation
12
 *
13
 * </copyright>
14
 *
15
 * $Id: ConstraintsDelegator.java,v 1.0 2008/11/19 16:37:42 tfaure Exp $
16
 */
17
package org.eclipse.emf.ecore.util;
18
19
import java.util.HashMap;
20
import java.util.Map;
21
22
import org.eclipse.emf.common.util.DiagnosticChain;
23
import org.eclipse.emf.ecore.EObject;
24
25
26
/**
27
 * An interface to validate a constraint
28
 * The only method to implement is {@link #validate(String, EObject, DiagnosticChain, Map)
29
 * To add a factory please see extension point : constraints_delegator_regstry
30
 */
31
public interface ConstraintsDelegator
32
{
33
  interface Factory
34
  {
35
    interface Registry
36
    {
37
      Registry INSTANCE = new Impl();
38
39
      /**
40
       * Returns the factory identified by the key
41
       * @param key the factory id
42
       * @return the factory or null if it doesn't exist
43
       */
44
      Factory getFactory(String key);
45
46
      /**
47
       * Registers a factory and associates it to an id
48
       * @param key the id
49
       * @param value the factory
50
       */
51
      void putFactory(String key, Factory value);
52
53
      class Impl extends HashMap<String, Factory> implements Registry
54
      {
55
        private static final long serialVersionUID = 1L;
56
57
        public Factory getFactory(String key)
58
        {
59
          return get(key);
60
        }
61
62
        public void putFactory(String key, Factory value)
63
        {
64
          put(key, value);
65
        }
66
      }
67
    }
68
69
    /**
70
     * Create a constraint delegator which is able to check a constraint
71
     * @return the constraint Delegator
72
     */
73
    ConstraintsDelegator createConstraintDelegator();
74
  }
75
76
  /**
77
   * Validate a constraint and add to the diagnostic chain the evaluation's diagnostic
78
   * @param value the expression to manage
79
   * @param object the current EObject
80
   * @param theDiagnostics the diagnostic's chain
81
   * @param context the context of the current validation
82
   * @return true if it's OK else false
83
   */
84
  boolean validate(String constraint,String name, int severity, String message, EObject object, DiagnosticChain theDiagnostics, Map<Object, Object> context);
85
}

Return to bug 255786