Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » OCL and external mehtods
OCL and external mehtods [message #53794] Thu, 28 September 2006 11:41 Go to next message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
would the following thing b possible?

I want to do the following, I have an ocl expressions which uses a
method outside of my Ecore model.

maybe: OutSideHelper.checkName( self.name)

I there a way to do this.
Chris
Re: OCL and external mehtods [message #54065 is a reply to message #53794] Thu, 28 September 2006 13:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Yes,

You can define a custom Environment (extending AbstractEnvironment or
EcoreEnvironment is advisable) that the parser uses to look up type names
and operation signatures. You can provide fake EOperations as though they
had been defined on your model EClassifiers, and in a corresponding custom
EvaluationEnvironment implement the evaluate(EOperation, int, Object,
Object[]) method to "invoke" your "operation".

The IOCLHelper can be initialized with an EnvironmentFactory that you
provide, which is responsible for creating Environments and
EvaluationEnvironments when the parser needs them.

HTH,

Christian


Chris Lenz wrote:

> would the following thing b possible?
>
> I want to do the following, I have an ocl expressions which uses a
> method outside of my Ecore model.
>
> maybe: OutSideHelper.checkName( self.name)
>
> I there a way to do this.
> Chris
Re: OCL and external mehtods [message #54419 is a reply to message #54065] Fri, 29 September 2006 08:24 Go to previous messageGo to next message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
Is there somewhere a guide how to work with environments.
Or examples to work with environments?
Thanx Chris
Christian W. Damus schrieb:
> Yes,
>
> You can define a custom Environment (extending AbstractEnvironment or
> EcoreEnvironment is advisable) that the parser uses to look up type names
> and operation signatures. You can provide fake EOperations as though they
> had been defined on your model EClassifiers, and in a corresponding custom
> EvaluationEnvironment implement the evaluate(EOperation, int, Object,
> Object[]) method to "invoke" your "operation".
>
> The IOCLHelper can be initialized with an EnvironmentFactory that you
> provide, which is responsible for creating Environments and
> EvaluationEnvironments when the parser needs them.
>
> HTH,
>
> Christian
>
>
> Chris Lenz wrote:
>
>> would the following thing b possible?
>>
>> I want to do the following, I have an ocl expressions which uses a
>> method outside of my Ecore model.
>>
>> maybe: OutSideHelper.checkName( self.name)
>>
>> I there a way to do this.
>> Chris
>
Re: OCL and external mehtods [message #54920 is a reply to message #54419] Fri, 29 September 2006 20:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

No, sorry, there isn't any programmer's guide documentation for that, yet.
This would be a great comment to add to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=156360.

There is a limited example in the JUnit tests for the parser's support for
UML-isms such as States and Signals (browse the hierarchy of the
Environment interface to find it).

Cheers,

Christian


Chris Lenz wrote:

> Is there somewhere a guide how to work with environments.
> Or examples to work with environments?
> Thanx Chris
> Christian W. Damus schrieb:
>> Yes,
>>
>> You can define a custom Environment (extending AbstractEnvironment or
>> EcoreEnvironment is advisable) that the parser uses to look up type names
>> and operation signatures. You can provide fake EOperations as though
>> they had been defined on your model EClassifiers, and in a corresponding
>> custom EvaluationEnvironment implement the evaluate(EOperation, int,
>> Object, Object[]) method to "invoke" your "operation".
>>
>> The IOCLHelper can be initialized with an EnvironmentFactory that you
>> provide, which is responsible for creating Environments and
>> EvaluationEnvironments when the parser needs them.
>>
>> HTH,
>>
>> Christian
>>
>>
>> Chris Lenz wrote:
>>
>>> would the following thing b possible?
>>>
>>> I want to do the following, I have an ocl expressions which uses a
>>> method outside of my Ecore model.
>>>
>>> maybe: OutSideHelper.checkName( self.name)
>>>
>>> I there a way to do this.
>>> Chris
>>
Re: OCL and external mehtods [message #55730 is a reply to message #54920] Mon, 02 October 2006 16:55 Go to previous messageGo to next message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
I don't understand, what are states for OCL?? I found something in
OCL-Specification, but I am not sure I understand that.

To add a customized new function to OCLParser, to I have to add a new State?
I have also found lookup Pathname, which looksup the Classifiers.
"Helper.testfunction(self)"
so lookupPathname must have a Helper, is this right??
Chris


Christian W. Damus schrieb:
> Hi, Chris,
>
> No, sorry, there isn't any programmer's guide documentation for that, yet.
> This would be a great comment to add to
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=156360.
>
> There is a limited example in the JUnit tests for the parser's support for
> UML-isms such as States and Signals (browse the hierarchy of the
> Environment interface to find it).
>
> Cheers,
>
> Christian
>
>
> Chris Lenz wrote:
>
>> Is there somewhere a guide how to work with environments.
>> Or examples to work with environments?
>> Thanx Chris
>> Christian W. Damus schrieb:
>>> Yes,
>>>
>>> You can define a custom Environment (extending AbstractEnvironment or
>>> EcoreEnvironment is advisable) that the parser uses to look up type names
>>> and operation signatures. You can provide fake EOperations as though
>>> they had been defined on your model EClassifiers, and in a corresponding
>>> custom EvaluationEnvironment implement the evaluate(EOperation, int,
>>> Object, Object[]) method to "invoke" your "operation".
>>>
>>> The IOCLHelper can be initialized with an EnvironmentFactory that you
>>> provide, which is responsible for creating Environments and
>>> EvaluationEnvironments when the parser needs them.
>>>
>>> HTH,
>>>
>>> Christian
>>>
>>>
>>> Chris Lenz wrote:
>>>
>>>> would the following thing b possible?
>>>>
>>>> I want to do the following, I have an ocl expressions which uses a
>>>> method outside of my Ecore model.
>>>>
>>>> maybe: OutSideHelper.checkName( self.name)
>>>>
>>>> I there a way to do this.
>>>> Chris
>
Re: OCL and external mehtods [message #56156 is a reply to message #55730] Tue, 03 October 2006 14:32 Go to previous messageGo to next message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
OK I saved the problem: here a bit of code

public static class MyEnvironmentFactory extends
AbstractEnvironmentFactory {

public EvaluationEnvironment createEvaluationEnvironment() {
EvaluationEnvironment evalEnv = new EvalEnvironment();
evalEnv.add("help", OCLHelperFactory.eINSTANCE.createHelper());
return evalEnv;
}
protected Environment createEnvironment(EPackage packageContext) {
return new MyEnvironment(packageContext);
}

protected EClassifier asEClassifier(Object context) {
return (EClassifier) context;
}

protected EOperation asEOperation(Object operation) {
return (EOperation) operation;
}

protected EStructuralFeature asEStructuralFeature(Object property) {
return (EStructuralFeature) property;
}

public Environment createEnvironment(Environment parent) {
return new MyEnvironment(parent);
}
}

private static class MyEnvironment extends EcoreEnvironment {

public MyEnvironment(EPackage packageContext) {
super(packageContext);
init();
}

private void init() {
Variable vdcl = ExpressionsFactory.eINSTANCE.createVariable();
vdcl.setName("help");
vdcl.setType(TypeUtil.resolveType(this,
OCLHelperPackage.eINSTANCE.getEClassifier("Helper")));
// vdcl.setInitExpression(initExp);
this.addElement("help", vdcl, true);


}

public MyEnvironment(Environment parent) {
super(parent);
init();
}

@Override
protected void collectStates(EClassifier owner, List pathPrefix,
List states) {

super.collectStates(owner, pathPrefix, states);
}

@Override
public EClassifier lookupPathName(List names) {
if (names.get(0).equals("Helper")) {
return OCLHelperPackage.eINSTANCE.getEClassifier((String)
names.get(0));
}
return super.lookupPathName(names);
}

}

Chris Lenz schrieb:
> I don't understand, what are states for OCL?? I found something in
> OCL-Specification, but I am not sure I understand that.
>
> To add a customized new function to OCLParser, to I have to add a new State?
> I have also found lookup Pathname, which looksup the Classifiers.
> "Helper.testfunction(self)"
> so lookupPathname must have a Helper, is this right??
> Chris
>
>
> Christian W. Damus schrieb:
>> Hi, Chris,
>>
>> No, sorry, there isn't any programmer's guide documentation for that, yet.
>> This would be a great comment to add to
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=156360.
>>
>> There is a limited example in the JUnit tests for the parser's support for
>> UML-isms such as States and Signals (browse the hierarchy of the
>> Environment interface to find it).
>>
>> Cheers,
>>
>> Christian
>>
>>
>> Chris Lenz wrote:
>>
>>> Is there somewhere a guide how to work with environments.
>>> Or examples to work with environments?
>>> Thanx Chris
>>> Christian W. Damus schrieb:
>>>> Yes,
>>>>
>>>> You can define a custom Environment (extending AbstractEnvironment or
>>>> EcoreEnvironment is advisable) that the parser uses to look up type names
>>>> and operation signatures. You can provide fake EOperations as though
>>>> they had been defined on your model EClassifiers, and in a corresponding
>>>> custom EvaluationEnvironment implement the evaluate(EOperation, int,
>>>> Object, Object[]) method to "invoke" your "operation".
>>>>
>>>> The IOCLHelper can be initialized with an EnvironmentFactory that you
>>>> provide, which is responsible for creating Environments and
>>>> EvaluationEnvironments when the parser needs them.
>>>>
>>>> HTH,
>>>>
>>>> Christian
>>>>
>>>>
>>>> Chris Lenz wrote:
>>>>
>>>>> would the following thing b possible?
>>>>>
>>>>> I want to do the following, I have an ocl expressions which uses a
>>>>> method outside of my Ecore model.
>>>>>
>>>>> maybe: OutSideHelper.checkName( self.name)
>>>>>
>>>>> I there a way to do this.
>>>>> Chris
Re: OCL and external mehtods [message #56457 is a reply to message #55730] Wed, 04 October 2006 13:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

States are only defined by the CompleteOCL because state machines are a UML
modeling construct, not EMOF. In UML, an OCL constraint can query what
State an instance of a particular Classifier is in (when that Classifier is
a BehavioredClassifier defining (or inheriting) at least one StateMachine.

So, as you indicated in your follow-up, these states have nothing to do with
your problem.

Cheers,

Christian


Chris Lenz wrote:

> I don't understand, what are states for OCL?? I found something in
> OCL-Specification, but I am not sure I understand that.
>
> To add a customized new function to OCLParser, to I have to add a new
> State? I have also found lookup Pathname, which looksup the Classifiers.
> "Helper.testfunction(self)"
> so lookupPathname must have a Helper, is this right??
> Chris
>
>

<snip>
Re: OCL and external mehtods [message #56484 is a reply to message #56156] Wed, 04 October 2006 13:24 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

That looks good. You'll have an implicitly defined variable named 'help' in
the context of every OCL expression that you parse. That's neat!

This would be a good example to post on the EMFT Wiki page for others to
follow who need to get started with customizing environments. I should see
about getting a faq/example-sharing forum started there.

Cheers,

Christian


Chris Lenz wrote:

> OK I saved the problem: here a bit of code
>
> public static class MyEnvironmentFactory extends
> AbstractEnvironmentFactory {
>
> public EvaluationEnvironment createEvaluationEnvironment() {
> EvaluationEnvironment evalEnv = new EvalEnvironment();
> evalEnv.add("help", OCLHelperFactory.eINSTANCE.createHelper());
> return evalEnv;
> }
> protected Environment createEnvironment(EPackage packageContext) {
> return new MyEnvironment(packageContext);
> }
>
> protected EClassifier asEClassifier(Object context) {
> return (EClassifier) context;
> }
>
> protected EOperation asEOperation(Object operation) {
> return (EOperation) operation;
> }
>
> protected EStructuralFeature asEStructuralFeature(Object property) {
> return (EStructuralFeature) property;
> }
>
> public Environment createEnvironment(Environment parent) {
> return new MyEnvironment(parent);
> }
> }
>
> private static class MyEnvironment extends EcoreEnvironment {
>
> public MyEnvironment(EPackage packageContext) {
> super(packageContext);
> init();
> }
>
> private void init() {
> Variable vdcl = ExpressionsFactory.eINSTANCE.createVariable();
> vdcl.setName("help");
> vdcl.setType(TypeUtil.resolveType(this,
> OCLHelperPackage.eINSTANCE.getEClassifier("Helper")));
> // vdcl.setInitExpression(initExp);
> this.addElement("help", vdcl, true);
>
>
> }
>
> public MyEnvironment(Environment parent) {
> super(parent);
> init();
> }
>
> @Override
> protected void collectStates(EClassifier owner, List pathPrefix,
> List states) {
>
> super.collectStates(owner, pathPrefix, states);
> }
>
> @Override
> public EClassifier lookupPathName(List names) {
> if (names.get(0).equals("Helper")) {
> return OCLHelperPackage.eINSTANCE.getEClassifier((String)
> names.get(0));
> }
> return super.lookupPathName(names);
> }
>
> }
>

<snip>
Re: OCL and external mehtods [message #592528 is a reply to message #53794] Thu, 28 September 2006 13:25 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Yes,

You can define a custom Environment (extending AbstractEnvironment or
EcoreEnvironment is advisable) that the parser uses to look up type names
and operation signatures. You can provide fake EOperations as though they
had been defined on your model EClassifiers, and in a corresponding custom
EvaluationEnvironment implement the evaluate(EOperation, int, Object,
Object[]) method to "invoke" your "operation".

The IOCLHelper can be initialized with an EnvironmentFactory that you
provide, which is responsible for creating Environments and
EvaluationEnvironments when the parser needs them.

HTH,

Christian


Chris Lenz wrote:

> would the following thing b possible?
>
> I want to do the following, I have an ocl expressions which uses a
> method outside of my Ecore model.
>
> maybe: OutSideHelper.checkName( self.name)
>
> I there a way to do this.
> Chris
Re: OCL and external mehtods [message #592673 is a reply to message #54065] Fri, 29 September 2006 08:24 Go to previous message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
Is there somewhere a guide how to work with environments.
Or examples to work with environments?
Thanx Chris
Christian W. Damus schrieb:
> Yes,
>
> You can define a custom Environment (extending AbstractEnvironment or
> EcoreEnvironment is advisable) that the parser uses to look up type names
> and operation signatures. You can provide fake EOperations as though they
> had been defined on your model EClassifiers, and in a corresponding custom
> EvaluationEnvironment implement the evaluate(EOperation, int, Object,
> Object[]) method to "invoke" your "operation".
>
> The IOCLHelper can be initialized with an EnvironmentFactory that you
> provide, which is responsible for creating Environments and
> EvaluationEnvironments when the parser needs them.
>
> HTH,
>
> Christian
>
>
> Chris Lenz wrote:
>
>> would the following thing b possible?
>>
>> I want to do the following, I have an ocl expressions which uses a
>> method outside of my Ecore model.
>>
>> maybe: OutSideHelper.checkName( self.name)
>>
>> I there a way to do this.
>> Chris
>
Re: OCL and external mehtods [message #592905 is a reply to message #54419] Fri, 29 September 2006 20:16 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

No, sorry, there isn't any programmer's guide documentation for that, yet.
This would be a great comment to add to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=156360

There is a limited example in the JUnit tests for the parser's support for
UML-isms such as States and Signals (browse the hierarchy of the
Environment interface to find it).

Cheers,

Christian


Chris Lenz wrote:

> Is there somewhere a guide how to work with environments.
> Or examples to work with environments?
> Thanx Chris
> Christian W. Damus schrieb:
>> Yes,
>>
>> You can define a custom Environment (extending AbstractEnvironment or
>> EcoreEnvironment is advisable) that the parser uses to look up type names
>> and operation signatures. You can provide fake EOperations as though
>> they had been defined on your model EClassifiers, and in a corresponding
>> custom EvaluationEnvironment implement the evaluate(EOperation, int,
>> Object, Object[]) method to "invoke" your "operation".
>>
>> The IOCLHelper can be initialized with an EnvironmentFactory that you
>> provide, which is responsible for creating Environments and
>> EvaluationEnvironments when the parser needs them.
>>
>> HTH,
>>
>> Christian
>>
>>
>> Chris Lenz wrote:
>>
>>> would the following thing b possible?
>>>
>>> I want to do the following, I have an ocl expressions which uses a
>>> method outside of my Ecore model.
>>>
>>> maybe: OutSideHelper.checkName( self.name)
>>>
>>> I there a way to do this.
>>> Chris
>>
Re: OCL and external mehtods [message #593238 is a reply to message #54920] Mon, 02 October 2006 16:55 Go to previous message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
I don't understand, what are states for OCL?? I found something in
OCL-Specification, but I am not sure I understand that.

To add a customized new function to OCLParser, to I have to add a new State?
I have also found lookup Pathname, which looksup the Classifiers.
"Helper.testfunction(self)"
so lookupPathname must have a Helper, is this right??
Chris


Christian W. Damus schrieb:
> Hi, Chris,
>
> No, sorry, there isn't any programmer's guide documentation for that, yet.
> This would be a great comment to add to
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=156360
>
> There is a limited example in the JUnit tests for the parser's support for
> UML-isms such as States and Signals (browse the hierarchy of the
> Environment interface to find it).
>
> Cheers,
>
> Christian
>
>
> Chris Lenz wrote:
>
>> Is there somewhere a guide how to work with environments.
>> Or examples to work with environments?
>> Thanx Chris
>> Christian W. Damus schrieb:
>>> Yes,
>>>
>>> You can define a custom Environment (extending AbstractEnvironment or
>>> EcoreEnvironment is advisable) that the parser uses to look up type names
>>> and operation signatures. You can provide fake EOperations as though
>>> they had been defined on your model EClassifiers, and in a corresponding
>>> custom EvaluationEnvironment implement the evaluate(EOperation, int,
>>> Object, Object[]) method to "invoke" your "operation".
>>>
>>> The IOCLHelper can be initialized with an EnvironmentFactory that you
>>> provide, which is responsible for creating Environments and
>>> EvaluationEnvironments when the parser needs them.
>>>
>>> HTH,
>>>
>>> Christian
>>>
>>>
>>> Chris Lenz wrote:
>>>
>>>> would the following thing b possible?
>>>>
>>>> I want to do the following, I have an ocl expressions which uses a
>>>> method outside of my Ecore model.
>>>>
>>>> maybe: OutSideHelper.checkName( self.name)
>>>>
>>>> I there a way to do this.
>>>> Chris
>
Re: OCL and external mehtods [message #593453 is a reply to message #55730] Tue, 03 October 2006 14:32 Go to previous message
Chris Lenz is currently offline Chris LenzFriend
Messages: 214
Registered: July 2009
Senior Member
OK I saved the problem: here a bit of code

public static class MyEnvironmentFactory extends
AbstractEnvironmentFactory {

public EvaluationEnvironment createEvaluationEnvironment() {
EvaluationEnvironment evalEnv = new EvalEnvironment();
evalEnv.add("help", OCLHelperFactory.eINSTANCE.createHelper());
return evalEnv;
}
protected Environment createEnvironment(EPackage packageContext) {
return new MyEnvironment(packageContext);
}

protected EClassifier asEClassifier(Object context) {
return (EClassifier) context;
}

protected EOperation asEOperation(Object operation) {
return (EOperation) operation;
}

protected EStructuralFeature asEStructuralFeature(Object property) {
return (EStructuralFeature) property;
}

public Environment createEnvironment(Environment parent) {
return new MyEnvironment(parent);
}
}

private static class MyEnvironment extends EcoreEnvironment {

public MyEnvironment(EPackage packageContext) {
super(packageContext);
init();
}

private void init() {
Variable vdcl = ExpressionsFactory.eINSTANCE.createVariable();
vdcl.setName("help");
vdcl.setType(TypeUtil.resolveType(this,
OCLHelperPackage.eINSTANCE.getEClassifier("Helper")));
// vdcl.setInitExpression(initExp);
this.addElement("help", vdcl, true);


}

public MyEnvironment(Environment parent) {
super(parent);
init();
}

@Override
protected void collectStates(EClassifier owner, List pathPrefix,
List states) {

super.collectStates(owner, pathPrefix, states);
}

@Override
public EClassifier lookupPathName(List names) {
if (names.get(0).equals("Helper")) {
return OCLHelperPackage.eINSTANCE.getEClassifier((String)
names.get(0));
}
return super.lookupPathName(names);
}

}

Chris Lenz schrieb:
> I don't understand, what are states for OCL?? I found something in
> OCL-Specification, but I am not sure I understand that.
>
> To add a customized new function to OCLParser, to I have to add a new State?
> I have also found lookup Pathname, which looksup the Classifiers.
> "Helper.testfunction(self)"
> so lookupPathname must have a Helper, is this right??
> Chris
>
>
> Christian W. Damus schrieb:
>> Hi, Chris,
>>
>> No, sorry, there isn't any programmer's guide documentation for that, yet.
>> This would be a great comment to add to
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=156360
>>
>> There is a limited example in the JUnit tests for the parser's support for
>> UML-isms such as States and Signals (browse the hierarchy of the
>> Environment interface to find it).
>>
>> Cheers,
>>
>> Christian
>>
>>
>> Chris Lenz wrote:
>>
>>> Is there somewhere a guide how to work with environments.
>>> Or examples to work with environments?
>>> Thanx Chris
>>> Christian W. Damus schrieb:
>>>> Yes,
>>>>
>>>> You can define a custom Environment (extending AbstractEnvironment or
>>>> EcoreEnvironment is advisable) that the parser uses to look up type names
>>>> and operation signatures. You can provide fake EOperations as though
>>>> they had been defined on your model EClassifiers, and in a corresponding
>>>> custom EvaluationEnvironment implement the evaluate(EOperation, int,
>>>> Object, Object[]) method to "invoke" your "operation".
>>>>
>>>> The IOCLHelper can be initialized with an EnvironmentFactory that you
>>>> provide, which is responsible for creating Environments and
>>>> EvaluationEnvironments when the parser needs them.
>>>>
>>>> HTH,
>>>>
>>>> Christian
>>>>
>>>>
>>>> Chris Lenz wrote:
>>>>
>>>>> would the following thing b possible?
>>>>>
>>>>> I want to do the following, I have an ocl expressions which uses a
>>>>> method outside of my Ecore model.
>>>>>
>>>>> maybe: OutSideHelper.checkName( self.name)
>>>>>
>>>>> I there a way to do this.
>>>>> Chris
Re: OCL and external mehtods [message #593592 is a reply to message #55730] Wed, 04 October 2006 13:21 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

States are only defined by the CompleteOCL because state machines are a UML
modeling construct, not EMOF. In UML, an OCL constraint can query what
State an instance of a particular Classifier is in (when that Classifier is
a BehavioredClassifier defining (or inheriting) at least one StateMachine.

So, as you indicated in your follow-up, these states have nothing to do with
your problem.

Cheers,

Christian


Chris Lenz wrote:

> I don't understand, what are states for OCL?? I found something in
> OCL-Specification, but I am not sure I understand that.
>
> To add a customized new function to OCLParser, to I have to add a new
> State? I have also found lookup Pathname, which looksup the Classifiers.
> "Helper.testfunction(self)"
> so lookupPathname must have a Helper, is this right??
> Chris
>
>

<snip>
Re: OCL and external mehtods [message #593604 is a reply to message #56156] Wed, 04 October 2006 13:24 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Chris,

That looks good. You'll have an implicitly defined variable named 'help' in
the context of every OCL expression that you parse. That's neat!

This would be a good example to post on the EMFT Wiki page for others to
follow who need to get started with customizing environments. I should see
about getting a faq/example-sharing forum started there.

Cheers,

Christian


Chris Lenz wrote:

> OK I saved the problem: here a bit of code
>
> public static class MyEnvironmentFactory extends
> AbstractEnvironmentFactory {
>
> public EvaluationEnvironment createEvaluationEnvironment() {
> EvaluationEnvironment evalEnv = new EvalEnvironment();
> evalEnv.add("help", OCLHelperFactory.eINSTANCE.createHelper());
> return evalEnv;
> }
> protected Environment createEnvironment(EPackage packageContext) {
> return new MyEnvironment(packageContext);
> }
>
> protected EClassifier asEClassifier(Object context) {
> return (EClassifier) context;
> }
>
> protected EOperation asEOperation(Object operation) {
> return (EOperation) operation;
> }
>
> protected EStructuralFeature asEStructuralFeature(Object property) {
> return (EStructuralFeature) property;
> }
>
> public Environment createEnvironment(Environment parent) {
> return new MyEnvironment(parent);
> }
> }
>
> private static class MyEnvironment extends EcoreEnvironment {
>
> public MyEnvironment(EPackage packageContext) {
> super(packageContext);
> init();
> }
>
> private void init() {
> Variable vdcl = ExpressionsFactory.eINSTANCE.createVariable();
> vdcl.setName("help");
> vdcl.setType(TypeUtil.resolveType(this,
> OCLHelperPackage.eINSTANCE.getEClassifier("Helper")));
> // vdcl.setInitExpression(initExp);
> this.addElement("help", vdcl, true);
>
>
> }
>
> public MyEnvironment(Environment parent) {
> super(parent);
> init();
> }
>
> @Override
> protected void collectStates(EClassifier owner, List pathPrefix,
> List states) {
>
> super.collectStates(owner, pathPrefix, states);
> }
>
> @Override
> public EClassifier lookupPathName(List names) {
> if (names.get(0).equals("Helper")) {
> return OCLHelperPackage.eINSTANCE.getEClassifier((String)
> names.get(0));
> }
> return super.lookupPathName(names);
> }
>
> }
>

<snip>
Previous Topic:Teneo HibernateResource
Next Topic:CDO and ConcurrentModificationException
Goto Forum:
  


Current Time: Thu Apr 25 08:26:13 GMT 2024

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

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

Back to the top