Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 148787 Details for
Bug 291361
[validator] OCL Feature Setting Delegate
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
initial patch
291361.patch (text/plain), 30.08 KB, created by
Kenn Hussey
on 2009-10-05 11:23:37 EDT
(
hide
)
Description:
initial patch
Filename:
MIME Type:
Creator:
Kenn Hussey
Created:
2009-10-05 11:23:37 EDT
Size:
30.08 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ocl.ecore >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.mdt/org.eclipse.ocl/plugins/org.eclipse.ocl.ecore/META-INF/MANIFEST.MF,v >retrieving revision 1.12 >diff -u -r1.12 MANIFEST.MF >--- META-INF/MANIFEST.MF 25 Aug 2009 20:35:31 -0000 1.12 >+++ META-INF/MANIFEST.MF 5 Oct 2009 14:56:16 -0000 >@@ -14,6 +14,8 @@ > Bundle-ActivationPolicy: lazy > Export-Package: org.eclipse.ocl.ecore, > org.eclipse.ocl.ecore.impl, >+ org.eclipse.ocl.ecore.dynamic, > org.eclipse.ocl.ecore.internal;x-friends:="org.eclipse.ocl.ecore.tests", >+ org.eclipse.ocl.ecore.internal.l10n, > org.eclipse.ocl.ecore.util > Bundle-RequiredExecutionEnvironment: J2SE-1.5 >Index: src/org/eclipse/ocl/ecore/internal/l10n/OCLEcoreMessages.properties >=================================================================== >RCS file: src/org/eclipse/ocl/ecore/internal/l10n/OCLEcoreMessages.properties >diff -N src/org/eclipse/ocl/ecore/internal/l10n/OCLEcoreMessages.properties >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ocl/ecore/internal/l10n/OCLEcoreMessages.properties 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,22 @@ >+############################################################################### >+# Copyright (c) 2008 Zeligsoft Inc. and others. >+# All rights reserved. This program and the accompanying materials >+# are made available under the terms of the Eclipse Public License v1.0 >+# which accompanies this distribution, and is available at >+# http://www.eclipse.org/legal/epl-v10.html >+# >+# Contributors: >+# Zeligsoft - initial API and implementation >+# >+# $Id$ >+# >+############################################################################### >+ >+# >+# Indicates an invalid derivation expression for an EStructuralFeature >+# in the OCL setting delegate annotation >+# >+# 0 - the EClass name that owns the feature >+# 1 - the EStructuralFeature name >+# 2 - the OCL parser's error message >+bad_attribute_derivation = Invalid OCL attribute derivation for {0}.{1}: {2} >Index: src/org/eclipse/ocl/ecore/internal/l10n/IMessages.java >=================================================================== >RCS file: src/org/eclipse/ocl/ecore/internal/l10n/IMessages.java >diff -N src/org/eclipse/ocl/ecore/internal/l10n/IMessages.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ocl/ecore/internal/l10n/IMessages.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,65 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2006, 2008 IBM Corporation, Zeligsoft Inc., and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ * Zeligsoft - Bug 216701 >+ * >+ * </copyright> >+ * >+ * $Id: IMessages.java,v 1.2 2007/02/14 14:46:07 cdamus Exp $ >+ */ >+package org.eclipse.ocl.ecore.internal.l10n; >+ >+import java.text.MessageFormat; >+ >+/** >+ * Abstraction of the OSGi runtime's NLS class, to abstract the dependency on >+ * Eclipse platform. >+ * >+ * @author Christian W. Damus (cdamus) >+ */ >+interface IMessages { >+ String bind(String message, Object arg); >+ String bind(String message, Object arg1, Object arg2); >+ String bind(String message, Object[] args); >+ >+ class Default implements IMessages { >+ public String bind(String message, Object arg) { >+ return MessageFormat.format(message, new Object[] {arg}); >+ } >+ >+ public String bind(String message, Object arg1, Object arg2) { >+ return MessageFormat.format(message, new Object[] {arg1, arg2}); >+ } >+ >+ public String bind(String message, Object[] args) { >+ return MessageFormat.format(message, args); >+ } >+ } >+ >+ class NLS implements IMessages { >+ public NLS() { >+ org.eclipse.osgi.util.NLS.initializeMessages( >+ OCLEcoreMessages.BUNDLE_NAME, OCLEcoreMessages.class); >+ } >+ >+ public String bind(String message, Object arg) { >+ return org.eclipse.osgi.util.NLS.bind(message, arg); >+ } >+ >+ public String bind(String message, Object arg1, Object arg2) { >+ return org.eclipse.osgi.util.NLS.bind(message, arg1, arg2); >+ } >+ >+ public String bind(String message, Object[] args) { >+ return org.eclipse.osgi.util.NLS.bind(message, args); >+ } >+ } >+} >Index: src/org/eclipse/ocl/ecore/dynamic/OCLSettingDelegate.java >=================================================================== >RCS file: src/org/eclipse/ocl/ecore/dynamic/OCLSettingDelegate.java >diff -N src/org/eclipse/ocl/ecore/dynamic/OCLSettingDelegate.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ocl/ecore/dynamic/OCLSettingDelegate.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,127 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2008 Zeligsoft Inc. and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Zeligsoft - Initial API and implementation >+ * >+ * </copyright> >+ * >+ * $Id$ >+ */ >+ >+package org.eclipse.ocl.ecore.dynamic; >+ >+import java.util.Collection; >+ >+import org.eclipse.emf.common.util.BasicEList; >+import org.eclipse.emf.common.util.ECollections; >+import org.eclipse.emf.ecore.EClass; >+import org.eclipse.emf.ecore.EClassifier; >+import org.eclipse.emf.ecore.EPackage; >+import org.eclipse.emf.ecore.EStructuralFeature; >+import org.eclipse.emf.ecore.EcorePackage; >+import org.eclipse.emf.ecore.InternalEObject; >+import org.eclipse.emf.ecore.util.BasicSettingDelegate; >+import org.eclipse.emf.ecore.util.EcoreUtil; >+import org.eclipse.ocl.ParserException; >+import org.eclipse.ocl.ecore.OCL; >+import org.eclipse.ocl.expressions.OCLExpression; >+ >+/** >+ * An implementation of a setting delegate that computes OCL derived features. >+ * >+ * @author Christian W. Damus (cdamus) >+ * @since 1.3 >+ */ >+public class OCLSettingDelegate >+ extends BasicSettingDelegate.Stateless { >+ >+ private OCL ocl; >+ >+ private OCLExpression<EClassifier> query; >+ >+ private ValueConverter converter; >+ >+ /** >+ * Initializes me with my structural feature. >+ * >+ * @param structuralFeature >+ * the structural feature that I handle >+ * >+ * @throws ParserException >+ * if the structural feature's OCL derivation is invalid >+ */ >+ protected OCLSettingDelegate(EStructuralFeature structuralFeature, >+ OCLSettingDelegateFactory.OCLCache oclCache) >+ throws ParserException { >+ >+ super(structuralFeature); >+ >+ EClass context = structuralFeature.getEContainingClass(); >+ EPackage ePackage = context.getEPackage(); >+ >+ this.ocl = oclCache.getOCL(ePackage); >+ >+ OCL.Helper helper = ocl.createOCLHelper(); >+ helper.setAttributeContext(context, structuralFeature); >+ >+ String expr = EcoreUtil.getAnnotation(structuralFeature, >+ EcorePackage.eNS_URI, "OCL"); //$NON-NLS-1$ >+ >+ this.query = helper.createDerivedValueExpression(expr) >+ .getSpecification().getBodyExpression(); >+ >+ this.converter = structuralFeature.isMany() >+ ? ValueConverter.LIST >+ : ValueConverter.VERBATIM; >+ } >+ >+ @Override >+ protected Object get(InternalEObject owner, boolean resolve, >+ boolean coreType) { >+ >+ return converter.convert(ocl, ocl.evaluate(owner, query)); >+ } >+ >+ @Override >+ protected boolean isSet(InternalEObject owner) { >+ return false; // derived features are, implicitly, never set >+ } >+ >+ // >+ // Nested classes >+ // >+ >+ private static interface ValueConverter { >+ >+ ValueConverter VERBATIM = new ValueConverter() { >+ >+ public Object convert(OCL ocl, Object value) { >+ // no way to report problem to the user in invalid case >+ return ocl.isInvalid(value)? null : value; >+ } >+ }; >+ >+ ValueConverter LIST = new ValueConverter() { >+ >+ public Object convert(OCL ocl, Object value) { >+ if (ocl.isInvalid(value)) { >+ // no way to report specific problem to the user >+ return ECollections.EMPTY_ELIST; >+ } >+ >+ Collection<?> collection = (Collection<?>) value; >+ return new BasicEList.UnmodifiableEList<Object>(collection >+ .size(), collection.toArray()); >+ } >+ }; >+ >+ Object convert(OCL ocl, Object value); >+ } >+} >Index: src/org/eclipse/ocl/ecore/internal/l10n/OCLEcoreMessages.java >=================================================================== >RCS file: src/org/eclipse/ocl/ecore/internal/l10n/OCLEcoreMessages.java >diff -N src/org/eclipse/ocl/ecore/internal/l10n/OCLEcoreMessages.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ocl/ecore/internal/l10n/OCLEcoreMessages.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,101 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2005, 2008 IBM Corporation, Zeligsoft Inc., and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ * Zeligsoft - Bug 216701 >+ * >+ * </copyright> >+ * >+ * $Id: OCLMessages.java,v 1.6 2007/12/12 22:08:04 cdamus Exp $ >+ */ >+ >+package org.eclipse.ocl.ecore.internal.l10n; >+ >+import java.lang.reflect.Field; >+import java.lang.reflect.Modifier; >+import java.util.MissingResourceException; >+import java.util.ResourceBundle; >+ >+/** >+ * An accessor class for externalized strings. >+ * >+ * @author Christian Vogt (cvogt) >+ * @since 1.3 >+ */ >+public class OCLEcoreMessages { >+ >+ static final String BUNDLE_NAME = "org.eclipse.ocl.ecore.internal.l10n.OCLMessages"; //$NON-NLS-1$ >+ >+ public static String bad_attribute_derivation; >+ >+ private static IMessages messagesImpl; >+ >+ public static String bind(String message, Object arg) { >+ return messagesImpl.bind(message, arg); >+ } >+ >+ public static String bind(String message, Object arg1, Object arg2) { >+ return messagesImpl.bind(message, arg1, arg2); >+ } >+ >+ public static String bind(String message, Object[] args) { >+ return messagesImpl.bind(message, args); >+ } >+ >+ static { >+ try { >+ @SuppressWarnings("unchecked") >+ Class<IMessages> nlsClass = (Class<IMessages>) Class.forName("org.eclipse.ocl.ecore.internal.l10n.IMessages$NLS"); //$NON-NLS-1$ >+ messagesImpl = nlsClass.newInstance(); >+ } catch (NoClassDefFoundError e) { >+ // expected in non-Eclipse environment >+ } catch (Exception e) { >+ // expected in non-Eclipse environment >+ } >+ >+ if (messagesImpl == null) { >+ // could not find the NLS class. Try initializing the messages, >+ // ourselves >+ initializeMessages(); >+ messagesImpl = new IMessages.Default(); >+ } >+ } >+ >+ private static void initializeMessages() { >+ ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME); >+ int publicStatic = Modifier.PUBLIC | Modifier.STATIC; >+ >+ Class<OCLEcoreMessages> clazz = OCLEcoreMessages.class; >+ >+ if (bundle != null) { >+ Field[] fields = clazz.getDeclaredFields(); >+ >+ for (int i = 0; i < fields.length; i++) { >+ Field next = fields[i]; >+ >+ if (((next.getModifiers() & publicStatic) == publicStatic) >+ && (next.getType() == String.class)) { >+ String name = next.getName(); >+ >+ try { >+ try { >+ next.set(null, bundle.getString(name)); >+ } catch (MissingResourceException e) { >+ // just use its own name, then >+ next.set(null, "Missing message for key: " + name); //$NON-NLS-1$ >+ } >+ } catch (Exception e) { >+ // oh, well. Can't set a value for this one >+ } >+ } >+ } >+ } >+ } >+} >Index: src/org/eclipse/ocl/ecore/dynamic/OCLSettingDelegateFactory.java >=================================================================== >RCS file: src/org/eclipse/ocl/ecore/dynamic/OCLSettingDelegateFactory.java >diff -N src/org/eclipse/ocl/ecore/dynamic/OCLSettingDelegateFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ocl/ecore/dynamic/OCLSettingDelegateFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,159 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2008 Zeligsoft Inc. and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Zeligsoft - Initial API and implementation >+ * >+ * </copyright> >+ * >+ * $Id$ >+ */ >+ >+package org.eclipse.ocl.ecore.dynamic; >+ >+import java.lang.ref.Reference; >+ >+import org.eclipse.emf.common.notify.Notification; >+import org.eclipse.emf.common.notify.impl.AdapterImpl; >+import org.eclipse.emf.common.util.ECollections; >+import org.eclipse.emf.ecore.EPackage; >+import org.eclipse.emf.ecore.EStructuralFeature; >+import org.eclipse.emf.ecore.InternalEObject; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.util.BasicSettingDelegate; >+import org.eclipse.ocl.ParserException; >+import org.eclipse.ocl.ecore.EcoreEnvironmentFactory; >+import org.eclipse.ocl.ecore.OCL; >+import org.eclipse.ocl.ecore.internal.OCLEcorePlugin; >+import org.eclipse.ocl.ecore.internal.l10n.OCLEcoreMessages; >+ >+/** >+ * Factory for OCL derived-attribute setting delegates. >+ * >+ * @author Christian W. Damus (cdamus) >+ * >+ * @since 1.3 >+ */ >+public class OCLSettingDelegateFactory >+ implements EStructuralFeature.Internal.SettingDelegate.Factory { >+ >+ private OCLCache oclCache = new OCLCache(); >+ >+ public EStructuralFeature.Internal.SettingDelegate createSettingDelegate( >+ EStructuralFeature structuralFeature) { >+ >+ EStructuralFeature.Internal.SettingDelegate result; >+ >+ try { >+ result = new OCLSettingDelegate(structuralFeature, oclCache); >+ } catch (ParserException e) { >+ // I will not be able to return any values >+ OCLEcorePlugin.error(1, OCLEcoreMessages.bind( >+ OCLEcoreMessages.bad_attribute_derivation, new Object[]{ >+ structuralFeature.getEContainingClass().getName(), >+ structuralFeature.getName(), e.getLocalizedMessage()})); >+ >+ // so, return a setting delegate that has no value, ever >+ return new BasicSettingDelegate.Stateless(structuralFeature) { >+ >+ @Override >+ protected Object get(InternalEObject owner, boolean resolve, >+ boolean coreType) { >+ >+ return eStructuralFeature.isMany() >+ ? ECollections.EMPTY_ELIST >+ : null; >+ } >+ >+ @Override >+ protected boolean isSet(InternalEObject owner) { >+ return false; >+ } >+ >+ }; >+ } >+ >+ return result; >+ } >+ >+ /** >+ * Creates the OCL environment in which to parse setting delegates for the >+ * specified environment. Subclasses may override to create custom >+ * environments, but should note that the result is cached. >+ * >+ * @param ePackage >+ * an Ecore package for which to create a setting delegate >+ * environment >+ * @return the environment >+ */ >+ protected OCL createOCL(final EPackage ePackage) { >+ Resource res = ePackage.eResource(); >+ EcoreEnvironmentFactory envFactory; >+ >+ if ((res != null) && (res.getResourceSet() != null)) { >+ // it's a dynamic package. Use the local package registry >+ envFactory = new EcoreEnvironmentFactory(res.getResourceSet() >+ .getPackageRegistry()); >+ >+ // and expunge when it's unloaded >+ res.eAdapters().add(new AdapterImpl() { >+ @Override >+ public void notifyChanged(Notification msg) { >+ if ((msg.getFeatureID(Resource.class) == Resource.RESOURCE__IS_LOADED) && !msg.getNewBooleanValue()) { >+ oclCache.expunge(ePackage); >+ } >+ } >+ }); >+ } else { >+ // the shared instance uses the static package registry >+ envFactory = EcoreEnvironmentFactory.INSTANCE; >+ } >+ >+ return OCL.newInstance(envFactory); >+ } >+ >+ // >+ // Nested classes >+ // >+ >+ /** >+ * A doubly-weak-referenced cache of OCL environments created to handle >+ * Ecore packages. >+ */ >+ protected class OCLCache >+ extends java.util.WeakHashMap<EPackage, Reference<OCL>> { >+ >+ protected synchronized OCL getOCL(EPackage ePackage) { >+ Reference<OCL> result = get(ePackage); >+ >+ if ((result == null) || (result.get() == null)) { >+ result = new java.lang.ref.WeakReference<OCL>( >+ createOCL(ePackage)); >+ } >+ >+ put(ePackage, result); >+ >+ return result.get(); >+ } >+ >+ protected synchronized void expunge(EPackage ePackage) { >+ Reference<OCL> oclRef = get(ePackage); >+ if (oclRef != null) { >+ OCL ocl = oclRef.get(); >+ >+ if (ocl != null) { >+ ocl.dispose(); >+ } >+ >+ remove(ePackage); >+ } >+ } >+ } >+ >+} >#P org.eclipse.ocl.ecore.tests >Index: src/org/eclipse/ocl/ecore/tests/AbstractTestSuite.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.mdt/org.eclipse.ocl/tests/org.eclipse.ocl.ecore.tests/src/org/eclipse/ocl/ecore/tests/AbstractTestSuite.java,v >retrieving revision 1.19 >diff -u -r1.19 AbstractTestSuite.java >--- src/org/eclipse/ocl/ecore/tests/AbstractTestSuite.java 1 Sep 2009 20:10:53 -0000 1.19 >+++ src/org/eclipse/ocl/ecore/tests/AbstractTestSuite.java 5 Oct 2009 14:56:17 -0000 >@@ -9,7 +9,7 @@ > * > * Contributors: > * IBM - Initial API and implementation >- * Zeligsoft - Bugs 243079, 244948, 244886, 245619 >+ * Zeligsoft - Bugs 243079, 244948, 244886, 245619, 216701 > * > * </copyright> > * >@@ -197,6 +197,7 @@ > result.addTest(RegressionTest.suite()); > result.addTest(EcoreEnvironmentTest.suite()); > result.addTest(ExtensibilityTest.suite()); >+ result.addTest(OCLSettingDelegateTest.suite()); > result.addTest(ValidationTest.suite()); > result.addTest(ProblemOptionTest.suite()); > result.addTest(ParsingOptionsTest.suite()); >Index: src/org/eclipse/ocl/ecore/tests/OCLSettingDelegateTest.java >=================================================================== >RCS file: src/org/eclipse/ocl/ecore/tests/OCLSettingDelegateTest.java >diff -N src/org/eclipse/ocl/ecore/tests/OCLSettingDelegateTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ocl/ecore/tests/OCLSettingDelegateTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,293 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2008 Zeligsoft Inc. and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Zeligsoft - Initial API and implementation >+ * >+ * </copyright> >+ * >+ * $Id$ >+ */ >+ >+package org.eclipse.ocl.ecore.tests; >+ >+import java.util.Arrays; >+import java.util.Map; >+ >+import junit.framework.Test; >+import junit.framework.TestSuite; >+ >+import org.eclipse.emf.common.util.BasicEList; >+import org.eclipse.emf.common.util.EList; >+import org.eclipse.emf.common.util.Enumerator; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.ecore.EAttribute; >+import org.eclipse.emf.ecore.EClass; >+import org.eclipse.emf.ecore.EEnum; >+import org.eclipse.emf.ecore.EFactory; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.EPackage; >+import org.eclipse.emf.ecore.EReference; >+import org.eclipse.emf.ecore.EStructuralFeature; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.resource.ResourceSet; >+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; >+import org.eclipse.ocl.ecore.dynamic.OCLSettingDelegateFactory; >+ >+/** >+ * Tests for the OCL setting delegate implementation. >+ * >+ * @author Christian W. Damus (cdamus) >+ */ >+@SuppressWarnings("nls") >+public class OCLSettingDelegateTest >+ extends AbstractTestSuite { >+ >+ private ResourceSet rset; >+ >+ private Resource testResource; >+ >+ private EPackage companyPackage; >+ >+ private EFactory companyFactory; >+ >+ private EClass companyClass; >+ >+ private EAttribute companyName; >+ >+ private EReference companyEmployees; >+ >+ private EAttribute companySize; >+ >+ private EClass employeeClass; >+ >+ private EAttribute employeeName; >+ >+ private EReference employeeManager; >+ >+ private EReference employeeDirectReports; >+ >+ private EReference employeeAllReports; >+ >+ private EEnum sizeKind; >+ >+ private Enumerator sizeSmall; >+ >+ private Enumerator sizeMedium; >+ >+ private Enumerator sizeLarge; >+ >+ private EObject acme; >+ >+ private Map<String, EObject> employees; >+ >+ public OCLSettingDelegateTest(String name) { >+ super(name); >+ } >+ >+ public static Test suite() { >+ return new TestSuite(OCLSettingDelegateTest.class, >+ "OCL Setting Delegate Tests"); >+ } >+ >+ public void test_eattributeDerivation() { >+ assertSame(sizeSmall, size(acme)); >+ >+ // add a load of employees >+ EList<EObject> emps = employees(acme); >+ for (int i = 0; i < 60; i++) { >+ emps.add(companyFactory.create(employeeClass)); >+ } >+ >+ assertSame(sizeMedium, size(acme)); >+ >+ // and another bunch >+ for (int i = 0; i < 1000; i++) { >+ emps.add(companyFactory.create(employeeClass)); >+ } >+ >+ assertSame(sizeLarge, size(acme)); >+ } >+ >+ public void test_ereferenceDerivation() { >+ EList<EObject> amyReports = directReports(employee("Amy")); >+ assertEquals(3, amyReports.size()); >+ assertTrue(amyReports.contains(employee("Bob"))); >+ assertTrue(amyReports.contains(employee("Jane"))); >+ assertTrue(amyReports.contains(employee("Fred"))); >+ >+ EList<EObject> bobReports = directReports(employee("Bob")); >+ assertEquals(2, bobReports.size()); >+ assertTrue(bobReports.contains(employee("Norbert"))); >+ assertTrue(bobReports.contains(employee("Sally"))); >+ >+ EList<EObject> sallyReports = directReports(employee("Sally")); >+ assertEquals(0, sallyReports.size()); >+ } >+ >+ public void test_allInstances() { >+ EList<EObject> amyAllReports = allReports(employee("Amy")); >+ assertEquals(5, amyAllReports.size()); >+ assertTrue(amyAllReports.contains(employee("Bob"))); >+ assertTrue(amyAllReports.contains(employee("Jane"))); >+ assertTrue(amyAllReports.contains(employee("Fred"))); >+ assertTrue(amyAllReports.contains(employee("Norbert"))); >+ assertTrue(amyAllReports.contains(employee("Sally"))); >+ >+ // change the set of all instances of Employee >+ set(create(acme, companyEmployees, employeeClass, "Manuel"), >+ employeeManager, employee("Bob")); >+ >+ amyAllReports = allReports(employee("Amy")); >+ assertEquals(6, amyAllReports.size()); >+ assertTrue(amyAllReports.contains(employee("Manuel"))); >+ } >+ >+ // >+ // Test framework >+ // >+ >+ @Override >+ protected void setUp() >+ throws Exception { >+ >+ super.setUp(); >+ >+ ((EStructuralFeature.Internal.SettingDelegate.Factory.Registry.Impl) EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE) >+ .put("org.eclipse.ocl.ecore.OCL", new OCLSettingDelegateFactory()); >+ >+ rset = new ResourceSetImpl(); >+ testResource = rset.getResource(URI.createPlatformPluginURI( >+ "/org.eclipse.ocl.ecore.tests/model/TestCompany.xmi", true), true); >+ >+ acme = testResource.getContents().get(0); >+ >+ companyClass = acme.eClass(); >+ companyPackage = companyClass.getEPackage(); >+ companyFactory = companyPackage.getEFactoryInstance(); >+ >+ companyName = (EAttribute) companyClass.getEStructuralFeature("name"); >+ companyEmployees = (EReference) companyClass >+ .getEStructuralFeature("employees"); >+ companySize = (EAttribute) companyClass.getEStructuralFeature("size"); >+ >+ employeeClass = companyEmployees.getEReferenceType(); >+ employeeName = (EAttribute) employeeClass.getEStructuralFeature("name"); >+ employeeManager = (EReference) employeeClass >+ .getEStructuralFeature("manager"); >+ employeeDirectReports = (EReference) employeeClass >+ .getEStructuralFeature("directReports"); >+ employeeAllReports = (EReference) employeeClass >+ .getEStructuralFeature("allReports"); >+ >+ sizeKind = (EEnum) companySize.getEAttributeType(); >+ sizeSmall = sizeKind.getEEnumLiteral("small"); >+ sizeMedium = sizeKind.getEEnumLiteral("medium"); >+ sizeLarge = sizeKind.getEEnumLiteral("large"); >+ >+ employees = new java.util.HashMap<String, EObject>(); >+ } >+ >+ @Override >+ protected void tearDown() >+ throws Exception { >+ >+ for (Resource next : rset.getResources()) { >+ next.unload(); >+ } >+ rset.getResources().clear(); >+ rset = null; >+ testResource = null; >+ companyPackage = null; >+ companyFactory = null; >+ employees = null; >+ >+ ((EStructuralFeature.Internal.SettingDelegate.Factory.Registry.Impl) EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE) >+ .remove("org.eclipse.ocl.ecore.OCL"); >+ >+ super.tearDown(); >+ } >+ >+ EObject employee(String name) { >+ EObject result = employees.get(name); >+ if (result == null) { >+ EList<EObject> emps = get(acme, companyEmployees); >+ for (EObject next : emps) { >+ if (name.equals(name(next))) { >+ result = next; >+ employees.put(name, result); >+ break; >+ } >+ } >+ } >+ >+ return result; >+ } >+ >+ String name(EObject employeeOrCompany) { >+ EAttribute name = employeeClass.isInstance(employeeOrCompany) >+ ? employeeName >+ : companyName; >+ return get(employeeOrCompany, name); >+ } >+ >+ EObject manager(EObject employee) { >+ return get(employee, employeeManager); >+ } >+ >+ EList<EObject> directReports(EObject employee) { >+ return get(employee, employeeDirectReports); >+ } >+ >+ EList<EObject> allReports(EObject employee) { >+ return get(employee, employeeAllReports); >+ } >+ >+ EList<EObject> employees(EObject company) { >+ return get(company, companyEmployees); >+ } >+ >+ Enumerator size(EObject company) { >+ return get(company, companySize); >+ } >+ >+ @SuppressWarnings("unchecked") >+ <T> T get(EObject owner, EStructuralFeature feature) { >+ return (T) owner.eGet(feature); >+ } >+ >+ void set(EObject owner, EStructuralFeature feature, Object value) { >+ owner.eSet(feature, value); >+ } >+ >+ void add(EObject owner, EStructuralFeature feature, Object value) { >+ this.<EList<Object>> get(owner, feature).add(value); >+ } >+ >+ EObject create(EObject owner, EReference containment, EClass type, >+ String name) { >+ EObject result = companyFactory.create(type); >+ >+ if (containment.isMany()) { >+ add(owner, containment, result); >+ } else { >+ set(owner, containment, result); >+ } >+ >+ if (name != null) { >+ set(result, type.getEStructuralFeature("name"), name); >+ } >+ >+ return result; >+ } >+ >+ <T> EList<T> list(T... element) { >+ return new BasicEList<T>(Arrays.asList(element)); >+ } >+} >Index: model/SettingDelegateTest.ecore >=================================================================== >RCS file: model/SettingDelegateTest.ecore >diff -N model/SettingDelegateTest.ecore >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ model/SettingDelegateTest.ecore 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+<?xml version="1.0" encoding="UTF-8"?> >+<ecore:EPackage xmi:version="2.0" >+ xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="settingtest" >+ nsURI="http://www.eclipse.org/ocl/test/2008/SettingDelegate" nsPrefix="st"> >+ <eClassifiers xsi:type="ecore:EClass" name="Company"> >+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> >+ <eStructuralFeatures xsi:type="ecore:EReference" name="employees" upperBound="-1" >+ eType="#//Employee" containment="true" eOpposite="#//Employee/company"/> >+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="size" lowerBound="1" eType="#//CompanySizeKind" >+ changeable="false" volatile="true" transient="true" derived="true"> >+ <eAnnotations source="http://www.eclipse.org/emf/2002/Ecore"> >+ <details key="settingDelegate" value="org.eclipse.ocl.ecore.OCL"/> >+ <details key="OCL" value="let table : Set(Tuple(range : Sequence(Integer), size : CompanySizeKind)) =
 Set{Tuple{range=Sequence{0..49}, size=CompanySizeKind::small},
 Tuple{range=Sequence{50..999}, size=CompanySizeKind::medium},
 Tuple{range=Sequence{1000..1000000}, size=CompanySizeKind::large}} in
table->any(range->includes(employees->size())).size"/> >+ </eAnnotations> >+ </eStructuralFeatures> >+ </eClassifiers> >+ <eClassifiers xsi:type="ecore:EClass" name="Employee"> >+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> >+ <eStructuralFeatures xsi:type="ecore:EReference" name="manager" eType="#//Employee"/> >+ <eStructuralFeatures xsi:type="ecore:EReference" name="company" lowerBound="1" >+ eType="#//Company" eOpposite="#//Company/employees"/> >+ <eStructuralFeatures xsi:type="ecore:EReference" name="directReports" upperBound="-1" >+ eType="#//Employee" changeable="false" volatile="true" transient="true" derived="true"> >+ <eAnnotations source="http://www.eclipse.org/emf/2002/Ecore"> >+ <details key="settingDelegate" value="org.eclipse.ocl.ecore.OCL"/> >+ <details key="OCL" value="company.employees->select(manager = self)"/> >+ </eAnnotations> >+ </eStructuralFeatures> >+ <eStructuralFeatures xsi:type="ecore:EReference" name="allReports" ordered="false" >+ upperBound="-1" eType="#//Employee" changeable="false" volatile="true" transient="true" >+ derived="true"> >+ <eAnnotations source="http://www.eclipse.org/emf/2002/Ecore"> >+ <details key="settingDelegate" value="org.eclipse.ocl.ecore.OCL"/> >+ <details key="OCL" value="Employee.allInstances()->select(e | e->closure(manager)->includes(self))"/> >+ </eAnnotations> >+ </eStructuralFeatures> >+ </eClassifiers> >+ <eClassifiers xsi:type="ecore:EEnum" name="CompanySizeKind"> >+ <eLiterals name="small"/> >+ <eLiterals name="medium" value="1"/> >+ <eLiterals name="large" value="2"/> >+ </eClassifiers> >+</ecore:EPackage> >Index: model/TestCompany.xmi >=================================================================== >RCS file: model/TestCompany.xmi >diff -N model/TestCompany.xmi >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ model/TestCompany.xmi 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,9 @@ >+<?xml version="1.0" encoding="ASCII"?> >+<st:Company xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:st="http://www.eclipse.org/ocl/test/2008/SettingDelegate" xsi:schemaLocation="http://www.eclipse.org/ocl/test/2008/SettingDelegate SettingDelegateTest.ecore" name="Acme"> >+ <employees name="Bob" manager="//@employees.3"/> >+ <employees name="Jane" manager="//@employees.3"/> >+ <employees name="Fred" manager="//@employees.3"/> >+ <employees name="Amy"/> >+ <employees name="Norbert" manager="//@employees.0"/> >+ <employees name="Sally" manager="//@employees.0"/> >+</st:Company>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
ed
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 291361
: 148787