Two functions to evaluate OCL

With the help of Jonas Hogstrom and Jan Nordén I have written 2 functions to evaluate OCL.
First is to evaluate OCL in EcoSpace:

  public object EvaluateOclInEcoSpace(IElement rootValue, string ocl)
  {
   object result = null;
   IElement e = ((IOclService)
this.GetEcoService(typeof(IOclService))).EvaluateAndSubscrib­e(rootValue, ocl,
null, null);
   if (e != null)
    result = e.AsObject;
   return result;
  }

Second is to evaluate OCL in PS:

  public object EvaluateOclInDB(IElement rootValue , string ocl)
  {
   object result = null;
   IElement InternalElement = null;
   IOclService oclService = (IOclService)
this.GetEcoService(typeof(IOcl­Service));
   IPersistenceService persistenceService = (IPersistenceService)
this.GetEcoService(typeof(IPer­sistenceService));

   AbstractCondition cond = oclService.CreateRetrieveCondi­tion(rootValue,
null, ocl);
   InternalElement = persistenceService.GetAllWithCondition(cond, 1, 0);
   if ((InternalElement != null) && ((InternalElement as IObjectList).Count
== 1))
    result = (InternalElement as IObjectList)[0].AsObject;
   return result;
  }

Of course you can make these functions more complex.

You can return different results types, for example IObjectList, change parameters for GetAllWithCondition - in this version it returns only the first object.

 

Share this article!

Follow us!

Find more helpful articles: