Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Xcore] Imposing constraints on Xcore model
[Xcore] Imposing constraints on Xcore model [message #896657] Thu, 19 July 2012 10:02 Go to next message
Wouter Schaekers is currently offline Wouter Schaekers
Messages: 17
Registered: July 2012
Junior Member
Hi

I'm working with Xcore to develop a model.
Now, I want to impose constraints on that model. I used to do it with OCL in Xtext (in the ecore file). Is it possible to implement constraints in an Xcore model? It doesn't have to be OCL.

Any help or clues are welcome.

Thanks for your time.
Re: [Xcore] Imposing constraints on Xcore model [message #896675 is a reply to message #896657] Thu, 19 July 2012 10:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26086
Registered: July 2009
Senior Member
Wouter,

Sorry, Xcore doesn't currently support specifying the behavior of
constraints. You can declare them with @Ecore annotations, but that's
it. Hopefully during the Kepler release cycle I can find time to add that.


On 19/07/2012 12:02 PM, Wouter Schaekers wrote:
> Hi
>
> I'm working with Xcore to develop a model.
> Now, I want to impose constraints on that model. I used to do it with
> OCL in Xtext (in the ecore file). Is it possible to implement
> constraints in an Xcore model? It doesn't have to be OCL.
>
> Any help or clues are welcome.
>
> Thanks for your time.
Re: [Xcore] Imposing constraints on Xcore model [message #896695 is a reply to message #896675] Thu, 19 July 2012 12:05 Go to previous messageGo to next message
Wouter Schaekers is currently offline Wouter Schaekers
Messages: 17
Registered: July 2012
Junior Member
Ed Merks wrote on Thu, 19 July 2012 06:58
Wouter,

Sorry, Xcore doesn't currently support specifying the behavior of
constraints. You can declare them with @Ecore annotations, but that's
it. Hopefully during the Kepler release cycle I can find time to add that.


Thanks for your answer.
Can you give a simple example? That would help a lot.
Re: [Xcore] Imposing constraints on Xcore model [message #896702 is a reply to message #896695] Thu, 19 July 2012 12:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26086
Registered: July 2009
Senior Member
Wouter,

If you have an existing *.genmodel, you can export the model to Xcore
(as described in the wiki). Below is Ecore.genmodel exported to Xcore.
Note the @Ecore(constraints="...") declarations.

@Ecore(nsURI="http://www.eclipse.org/emf/2002/Ecore")
@GenModel(modelDirectory="/org.eclipse.emf.ecore/src",
runtimeJar="true", updateClasspath="false", booleanFlagsField="eFlags",
booleanFlagsReservedBits="8",
importerID="org.eclipse.emf.importer.ecore", containmentProxies="true",
minimalReflectiveMethods="false",
language="en")
package org.eclipse.emf.ecore

@Ecore(constraints="ConsistentTransient")
class EAttribute extends EStructuralFeature
{
EBoolean iD
refers readonly transient volatile derived EDataType [1] eAttributeType
}

@Ecore(constraints="WellFormedSourceURI")
class EAnnotation extends EModelElement
{
EString source
contains EStringToStringMapEntry [] details
container transient EModelElement eModelElement opposite eAnnotations
contains EObject [] contents
refers EObject [] references
}

@Ecore(constraints="InterfaceIsAbstract AtMostOneID UniqueFeatureNames
UniqueOperationSignatures NoCircularSuperTypes WellFormedMapEntryClass
ConsistentSuperTypes DisjointFeatureAndOperationSignatures")
class EClass extends EClassifier
{
EBoolean ^abstract
EBoolean ^interface
@GenModel(suppressedIsSetVisibility="true",
suppressedUnsetVisibility="true")
refers unsettable EClass [] eSuperTypes
contains EOperation [] eOperations opposite eContainingClass
refers readonly transient volatile derived EAttribute [] eAllAttributes
refers readonly transient volatile derived EReference [] eAllReferences
refers readonly transient volatile derived EReference [] eReferences
refers readonly transient volatile derived EAttribute [] eAttributes
refers readonly transient volatile derived EReference []
eAllContainments
refers readonly transient volatile derived EOperation [] eAllOperations
refers readonly transient volatile derived EStructuralFeature []
eAllStructuralFeatures
refers readonly transient volatile derived EClass [] eAllSuperTypes
refers local readonly transient volatile derived EAttribute
eIDAttribute
contains EStructuralFeature [] eStructuralFeatures opposite
eContainingClass
@GenModel(suppressedIsSetVisibility="true",
suppressedUnsetVisibility="true")
contains unsettable EGenericType [] eGenericSuperTypes
refers readonly transient volatile derived EGenericType []
eAllGenericSuperTypes
op EBoolean isSuperTypeOf(EClass someClass)
op EInt getFeatureCount()
op EStructuralFeature getEStructuralFeature(EInt featureID)
op EInt getFeatureID(EStructuralFeature feature)
op EStructuralFeature getEStructuralFeature(EString featureName)
op EInt getOperationCount()
op EOperation getEOperation(EInt operationID)
op EInt getOperationID(EOperation operation)
op EOperation getOverride(EOperation operation)
}

@Ecore(constraints="WellFormedInstanceTypeName UniqueTypeParameterNames")
abstract class EClassifier extends ENamedElement
{
@GenModel(suppressedIsSetVisibility="true",
suppressedUnsetVisibility="true")
volatile unsettable EString instanceClassName
readonly transient volatile derived EJavaClass<?> instanceClass
readonly transient volatile derived EJavaObject defaultValue
@GenModel(suppressedIsSetVisibility="true",
suppressedUnsetVisibility="true")
volatile unsettable EString instanceTypeName
container resolving readonly transient EPackage ePackage opposite
eClassifiers
contains resolving ETypeParameter [] eTypeParameters
op EBoolean isInstance(EJavaObject object)
op EInt getClassifierID()
}

class EDataType extends EClassifier
{
EBoolean serializable = "true"
}

@Ecore(constraints="UniqueEnumeratorNames UniqueEnumeratorLiterals")
class EEnum extends EDataType
{
contains EEnumLiteral [] eLiterals opposite eEnum
op EEnumLiteral getEEnumLiteral(EString name)
op EEnumLiteral getEEnumLiteral(EInt value)
op EEnumLiteral getEEnumLiteralByLiteral(EString literal)
}

class EEnumLiteral extends ENamedElement
{
EInt value
transient EEnumerator instance
EString literal
container readonly transient EEnum eEnum opposite eLiterals
}

class EFactory extends EModelElement
{
refers local transient EPackage [1] ePackage opposite eFactoryInstance
op EObject ^create(EClass eClass)
op EJavaObject createFromString(EDataType eDataType, EString
literalValue)
op EString convertToString(EDataType eDataType, EJavaObject
instanceValue)
}

abstract class EModelElement
{
contains EAnnotation [] eAnnotations opposite eModelElement
op EAnnotation getEAnnotation(EString source)
}

@Ecore(constraints="WellFormedName")
abstract class ENamedElement extends EModelElement
{
EString name
}

class EObject
{
op EClass eClass()
op EBoolean eIsProxy()
op EResource eResource()
op EObject eContainer()
op EStructuralFeature eContainingFeature()
op EReference eContainmentFeature()
op EEList<EObject> eContents()
op ETreeIterator<EObject> eAllContents()
op EEList<EObject> eCrossReferences()
op EJavaObject eGet(EStructuralFeature feature)
op EJavaObject eGet(EStructuralFeature feature, EBoolean resolve)
op void eSet(EStructuralFeature feature, EJavaObject newValue)
op EBoolean eIsSet(EStructuralFeature feature)
op void eUnset(EStructuralFeature feature)
op EJavaObject eInvoke(EOperation operation, EEList<?> arguments)
throws EInvocationTargetException
}

@Ecore(constraints="UniqueParameterNames UniqueTypeParameterNames
NoRepeatingVoid")
class EOperation extends ETypedElement
{
container readonly transient EClass eContainingClass opposite
eOperations
contains resolving ETypeParameter [] eTypeParameters
contains EParameter [] eParameters opposite eOperation
@GenModel(suppressedIsSetVisibility="true",
suppressedUnsetVisibility="true")
refers unsettable EClassifier [] eExceptions
@GenModel(suppressedIsSetVisibility="true",
suppressedUnsetVisibility="true")
contains unsettable EGenericType [] eGenericExceptions
op EInt getOperationID()
op EBoolean isOverrideOf(EOperation someOperation)
}

@Ecore(constraints="WellFormedNsURI WellFormedNsPrefix
UniqueSubpackageNames UniqueClassifierNames UniqueNsURIs")
class EPackage extends ENamedElement
{
EString nsURI
EString nsPrefix
refers local transient EFactory [1] eFactoryInstance opposite ePackage
contains resolving EClassifier [] eClassifiers opposite ePackage
contains resolving EPackage [] eSubpackages opposite eSuperPackage
container resolving readonly transient EPackage eSuperPackage
opposite eSubpackages
op EClassifier getEClassifier(EString name)
}

class EParameter extends ETypedElement
{
container readonly transient EOperation eOperation opposite eParameters
}

@Ecore(constraints="ConsistentOpposite SingleContainer ConsistentKeys
ConsistentUnique ConsistentContainer")
class EReference extends EStructuralFeature
{
EBoolean containment
readonly transient volatile derived EBoolean ^container
EBoolean resolveProxies = "true"
refers EReference eOpposite
refers readonly transient volatile derived EClass [1] eReferenceType
refers EAttribute [] eKeys
}

@Ecore(constraints="ValidDefaultValueLiteral")
abstract class EStructuralFeature extends ETypedElement
{
EBoolean changeable = "true"
EBoolean ^volatile
EBoolean ^transient
EString defaultValueLiteral
readonly transient volatile derived EJavaObject defaultValue
EBoolean ^unsettable
EBoolean ^derived
container readonly transient EClass eContainingClass opposite
eStructuralFeatures
op EInt getFeatureID()
op EJavaClass<?> getContainerClass()
}

@Ecore(constraints="ValidLowerBound ValidUpperBound ConsistentBounds
ValidType")
abstract class ETypedElement extends ENamedElement
{
EBoolean ordered = "true"
EBoolean ^unique = "true"
EInt lowerBound
EInt upperBound = "1"
readonly transient volatile derived EBoolean many
readonly transient volatile derived EBoolean required
@GenModel(suppressedIsSetVisibility="true",
suppressedUnsetVisibility="true")
refers volatile unsettable EClassifier eType
@GenModel(suppressedIsSetVisibility="true",
suppressedUnsetVisibility="true")
contains volatile unsettable EGenericType eGenericType

}
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#decimal")

type EBigDecimal wraps java.math.BigDecimal
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#integer")

type EBigInteger wraps java.math.BigInteger
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#boolean")

type EBoolean wraps boolean
@ExtendedMetaData(baseType="EBoolean", name="EBoolean:Object")

type EBooleanObject wraps Boolean
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#byte")

type EByte wraps byte
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#hexBinary")

type EByteArray wraps byte [ ]
@ExtendedMetaData(baseType="EByte", name="EByte:Object")

type EByteObject wraps Byte

type EChar wraps char @ExtendedMetaData(baseType="EChar",
name="EChar:Object")

type ECharacterObject wraps Character

type EDate wraps java.util.Date

type EDiagnosticChain wraps org.eclipse.emf.common.util.DiagnosticChain
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#double")

type EDouble wraps double @ExtendedMetaData(baseType="EDouble",
name="EDouble:Object")

type EDoubleObject wraps Double

type EEList < E > wraps org.eclipse.emf.common.util.EList

type EEnumerator wraps org.eclipse.emf.common.util.Enumerator

type EFeatureMap wraps util.FeatureMap

type EFeatureMapEntry wraps util.FeatureMap$Entry
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#float")

type EFloat wraps float @ExtendedMetaData(baseType="EFloat",
name="EFloat:Object")

type EFloatObject wraps Float
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#int")

type EInt wraps int @ExtendedMetaData(baseType="EInt", name="EInt:Object")

type EIntegerObject wraps Integer

type EJavaClass < T > wraps Class

type EJavaObject wraps Object
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#long")

type ELong wraps long @ExtendedMetaData(baseType="ELong",
name="ELong:Object")

type ELongObject wraps Long

type EMap < K , V > wraps java.util.Map

type EResource wraps resource.Resource

type EResourceSet wraps resource.ResourceSet
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#short")

type EShort wraps short @ExtendedMetaData(baseType="EShort",
name="EShort:Object")

type EShortObject wraps Short
@ExtendedMetaData(baseType="http://www.w3.org/2001/XMLSchema#string")

type EString wraps String

class EStringToStringMapEntry wraps java.util.Map$Entry
{
EString key
EString value
}

type ETreeIterator < E > wraps org.eclipse.emf.common.util.TreeIterator
@Ecore(constraints="ConsistentType ConsistentBounds ConsistentArguments")

class EGenericType
{
contains EGenericType eUpperBound
contains EGenericType [] eTypeArguments
refers readonly transient derived EClassifier [1] eRawType
contains EGenericType eLowerBound
refers local ETypeParameter eTypeParameter
refers EClassifier eClassifier
}

class ETypeParameter extends ENamedElement
{
contains EGenericType [] eBounds
}

type EInvocationTargetException wraps reflect.InvocationTargetException


On 19/07/2012 2:05 PM, Wouter Schaekers wrote:
> Ed Merks wrote on Thu, 19 July 2012 06:58
>> Wouter,
>>
>> Sorry, Xcore doesn't currently support specifying the behavior of
>> constraints. You can declare them with @Ecore annotations, but
>> that's it. Hopefully during the Kepler release cycle I can find time
>> to add that.
>
>
> Thanks for your answer.
> Can you give a simple example? That would help a lot.
>
Re: [Xcore] Imposing constraints on Xcore model [message #896879 is a reply to message #896675] Fri, 20 July 2012 09:10 Go to previous messageGo to next message
Eclipse User is currently offline Eclipse User
Messages: 257
Registered: July 2009
Senior Member
On 07/19/2012 12:58 PM, Ed Merks wrote:
> Wouter,
>
> Sorry, Xcore doesn't currently support specifying the behavior of
> constraints. You can declare them with @Ecore annotations, but that's
> it. Hopefully during the Kepler release cycle I can find time to add that.
>

In the meantime, maybe you could have two projects: first project with
your domain model implemented using XCore and the other project with a
_constraint model_ implemented using the OCL XText based editor???

>
> On 19/07/2012 12:02 PM, Wouter Schaekers wrote:
>> Hi
>>
>> I'm working with Xcore to develop a model.
>> Now, I want to impose constraints on that model. I used to do it with
>> OCL in Xtext (in the ecore file). Is it possible to implement
>> constraints in an Xcore model? It doesn't have to be OCL.
>>
>> Any help or clues are welcome.
>>
>> Thanks for your time.
>
Re: [Xcore] Imposing constraints on Xcore model [message #901182 is a reply to message #896879] Fri, 10 August 2012 08:41 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 356
Registered: December 2010
Location: Germany
Senior Member
Hi

I have started working with xcore and love it! Right now I am facing the same situation, as the original poster: I want to add constraints and/or invariants to the model.

Both approaches have the excpected result:
@Ecore(constraints="foo")
class Bar {
  ...
}
and
class Bar {
  ...
  op boolean hasFoo(EDiagnosticChain diagnostics, EMap<Object, Object> context)
}

The corresponding methods in Bar and *Validator are created. The only draw back is, that these methods need to be manualy changed and will therefore be overwritten by a project "clean".

Are there any best practices on working with these situations. Are there any current developments that might help?

Greetings
Christoph
Re: [Xcore] Imposing constraints on Xcore model [message #901189 is a reply to message #901182] Fri, 10 August 2012 09:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26086
Registered: July 2009
Senior Member
Christoph,

Comments below.

On 10/08/2012 10:41 AM, Christoph Keimel wrote:
> Hi
>
> I have started working with xcore and love it! Right now I am facing
> the same situation, as the original poster: I want to add constraints
> and/or invariants to the model.
>
> Both approaches have the excpected result:
> @Ecore(constraints="foo")
> class Bar {
> ...
> } and
> class Bar {
> ...
> op boolean hasFoo(EDiagnosticChain diagnostics, EMap<Object, Object>
> context)
For the invariant you can specify the actual body...
> }
> The corresponding methods in Bar and *Validator are created. The only
> draw back is, that these methods need to be manualy changed and will
> therefore be overwritten by a project "clean".
That's true for the constraint, but for the invariant you can specify
the body, right? If you avoid generating into the src-gen folder (the
folder specified in the Xcore compiler options), it won't get cleaned.
You can specify the model directory with an @GenModel annotation.
>
> Are there any best practices on working with these situations. Are
> there any current developments that might help?
Hopefully I'll have time to get constraints working nicely for Kepler...
>
> Greetings
> Christoph
Re: [Xcore] Imposing constraints on Xcore model [message #901193 is a reply to message #901182] Fri, 10 August 2012 09:10 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 356
Registered: December 2010
Location: Germany
Senior Member
Experimenting further ... this approach seems to be a good start:
(The goal of this experiment is to introduce an invariant on the attribute name which can not be null or an empty string.)

class CompanyElement {
	String name
	op boolean hasName(EDiagnosticChain diagnostics, EMap<Object, Object> context) {
		if (name == null || name == "") {
	    	if (diagnostics != null) {
	        	diagnostics.add(new BasicDiagnostic(Diagnostic::ERROR,
	            		CompanyValidator::DIAGNOSTIC_SOURCE,
	             		CompanyValidator::COMPANY_ELEMENT__HAS_NAME,
	             		"The Name can not be empty",
	             		null))
	      }
	    } else true
	}
}

The "null" as last parameter to BasicDiagnostics is wrong of course. I couldn't figure out how to write "new Object [] { this }" in xcore. Any pointers on this?

What do you think about this approach?

Greetings
Christoph

Re: [Xcore] Imposing constraints on Xcore model [message #901216 is a reply to message #901189] Fri, 10 August 2012 11:36 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 356
Registered: December 2010
Location: Germany
Senior Member
Hi Ed,

thanks for the reply.

[quote title=Ed Merks wrote on Fri, 10 August 2012 11:01]
> That's true for the constraint, but for the invariant you can specify
> the body, right?

Yes, but you also need to include the stuff that is normaly generated. I got stuck with that experiment on the array definition. See my later post: 901193

> If you avoid generating into the src-gen folder (the
> folder specified in the Xcore compiler options), it won't get cleaned.
> You can specify the model directory with an @GenModel annotation.

Good tip. Thanks.

> Hopefully I'll have time to get constraints working nicely for Kepler...

Is there a bug where you are tracking the development in this area?

Greetings
Christoph
Re: [Xcore] Imposing constraints on Xcore model [message #901222 is a reply to message #901216] Fri, 10 August 2012 12:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26086
Registered: July 2009
Senior Member
Christoph,

Comments below.

On 10/08/2012 1:36 PM, Christoph Keimel wrote:
> Hi Ed,
>
> thanks for the reply.
>
> [quote title=Ed Merks wrote on Fri, 10 August 2012 11:01]
>> That's true for the constraint, but for the invariant you can specify
>> the body, right?
>
> Yes, but you also need to include the stuff that is normaly generated.
> I got stuck with that experiment on the array definition. See my later
> post:
> http://www.eclipse.org/forums/index.php/mv/msg/367759/901193/#msg_901193
I'll look...
>
>> If you avoid generating into the src-gen folder (the folder specified
>> in the Xcore compiler options), it won't get cleaned. You can
>> specify the model directory with an @GenModel annotation.
>
> Good tip. Thanks.
>
>> Hopefully I'll have time to get constraints working nicely for Kepler...
>
> Is there a bug where you are tracking the development in this area?
No, feel free to open one for tracking purposes.
>
> Greetings
> Christoph
Re: [Xcore] Imposing constraints on Xcore model [message #901225 is a reply to message #901193] Fri, 10 August 2012 12:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26086
Registered: July 2009
Senior Member
Christoph,

This approach looks good. I'm not sure the Xbase syntax for an array
literal or if it even has one. In the worst case, I guess you can
create an array of the right size and assign the elements.

I'd suggest asking on eclipse.tmf with a subject starting with [xbase]
what the recommended equivalent of Java's "new Object [] { value }" is
in Xbase.


On 10/08/2012 11:10 AM, Christoph Keimel wrote:
> Experimenting further ... this approach seems to be a good start:
> (The goal of this experiment is to introduce an invariant on the
> attribute name which can not be null or an empty string.)
>
> class CompanyElement {
> String name
> op boolean hasName(EDiagnosticChain diagnostics, EMap<Object,
> Object> context) {
> if (name == null || name == "") {
> if (diagnostics != null) {
> diagnostics.add(new BasicDiagnostic(Diagnostic::ERROR,
> CompanyValidator::DIAGNOSTIC_SOURCE,
> CompanyValidator::COMPANY_ELEMENT__HAS_NAME,
> "The Name can not be empty",
> null))
> }
> } else true
> }
> }
> The "null" as last parameter to BasicDiagnostics is wrong of course. I
> couldn't figure out how to write "new Object [] { this }" in xcore.
> Any pointers on this?
>
> What do you think about this approach?
>
> Greetings
> Christoph
>
>
Re: [Xcore] Imposing constraints on Xcore model [message #901232 is a reply to message #901222] Fri, 10 August 2012 12:49 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 356
Registered: December 2010
Location: Germany
Senior Member
[quote title=Ed Merks wrote on Fri, 10 August 2012 14:13]Christoph,
> > Is there a bug where you are tracking the development in this area?
> No, feel free to open one for tracking purposes.

Bug 387010

Re: [Xcore] Imposing constraints on Xcore model [message #901241 is a reply to message #901225] Fri, 10 August 2012 13:20 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 356
Registered: December 2010
Location: Germany
Senior Member
[quote title=Ed Merks wrote on Fri, 10 August 2012 14:17]Christoph,
> This approach looks good. I'm not sure the Xbase syntax for an array
> literal or if it even has one. In the worst case, I guess you can
> create an array of the right size and assign the elements.

I am having trouble with arrays, but this works:
val List<Object> list = new ArrayList
list.add(this)
diagnostics.add(new BasicDiagnostic(Diagnostic::ERROR,
	CompanyValidator::DIAGNOSTIC_SOURCE,
	CompanyValidator::COMPANY_ELEMENT__HAS_NAME,
	"The Name must be filled.",
	list))

> I'd suggest asking on eclipse.tmf with a subject starting with [xbase]
> what the recommended equivalent of Java's "new Object [] { value }" is
> in Xbase.

http://www.eclipse.org/forums/index.php/m/901235/#msg_901235
Re: [Xcore] Imposing constraints on Xcore model [message #901436 is a reply to message #901241] Sun, 12 August 2012 10:48 Go to previous message
Christoph Keimel is currently offline Christoph Keimel
Messages: 356
Registered: December 2010
Location: Germany
Senior Member
In case anybody needs this: After some help from Christian Dietrich (thanks!) I came up with the following transfer of the generated validation code to xcore:

package de.emsw.model.company

import org.eclipse.emf.common.util.BasicDiagnostic
import org.eclipse.emf.common.util.Diagnostic
import org.eclipse.emf.ecore.EDiagnosticChain
import org.eclipse.emf.ecore.EMap
import org.eclipse.emf.ecore.plugin.EcorePlugin
import org.eclipse.emf.ecore.util.EObjectValidator

class CompanyElement {
	String name
	op boolean hasName(EDiagnosticChain diagnostics, EMap<Object, Object> context) {
		if (name == null || name == "") {
			if (diagnostics != null) {
				diagnostics.add(new BasicDiagnostic(Diagnostic::ERROR,
					"de.emsw.model.company", //CompanyValidator::DIAGNOSTIC_SOURCE,
					0, //CompanyValidator::COMPANY_ELEMENT__HAS_NAME,
					EcorePlugin::INSTANCE.getString("_UI_GenericInvariant_diagnostic", <Object>newArrayList("hasName", EObjectValidator::getObjectLabel(this, context))),
					<Object>newArrayList(this)))
			}
		} else true
	}
}

The part including the block "if (diagnostics != null)" is normally generated by ecore when an invariant is recognised.

Lines 16 and 17 are hard coded here, because CompanyValidator only exists after the build and not before leading to a build dead lock. See: Bug 387015
Previous Topic:[CDO] CDOStaleReferencePolicy.PROXY
Next Topic:How to force generation of Validator
Goto Forum:
  


Current Time: Tue Sep 30 13:54:50 GMT 2014

Powered by FUDForum. Page generated in 0.13335 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software