Com a ajuda de Jonas Hogstrom e Jan Norden eu ter escrito 2 funções para avaliar OCL.
Em primeiro lugar está a avaliar em EcoSpace OCL:
público objeto EvaluateOclInEcoSpace (IElement rootValue, string OCL)
(
objeto resultado = null;
IElement e = ((IOclService)
this.GetEcoService (typeof (IOclService))). EvaluateAndSubscribe (rootValue, OCL,
null, null);
if (e! = null)
resultado = e.AsObject;
return resultado;
)
Segunda-se a avaliar no PS OCL:
público objeto EvaluateOclInDB (IElement rootValue, string OCL)
(
objeto resultado = null;
IElement InternalElement = null;IOclService oclService = (IOclService)
this.GetEcoService (typeof (IOclService));
IPersistenceService persistenceService = (IPersistenceService)
this.GetEcoService (typeof (IPersistenceService));
AbstractCondition condutor = oclService.CreateRetrieveCondition (rootValue,
null, OCL);
InternalElement = persistenceService.GetAllWithCondition (condutor, 1, 0);if ((InternalElement! = null) & & ((InternalElement como IObjectList). Contagem
== 1))
resultado = (InternalElement como IObjectList) [0]. AsObject;
return resultado;)
Claro que você pode fazer estas funções mais complexas.
Você pode retornar resultados diferentes tipos, como por exemplo IObjectList, alterar os parâmetros para GetAllWithCondition - nesta versão, retorna apenas o primeiro objeto.

Delicious
Digg
Google
Yahoo