﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>CapableObjects Forums / ECO / General discussions  / Calling Static Methods from OCL / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>CapableObjects Forums</description><link>http://www.capableobjects.com/apps/InstantForum414/</link><webMaster>forums@capableobjects.com</webMaster><lastBuildDate>Wed, 08 Feb 2012 22:48:48 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Calling Static Methods from OCL</title><link>http://www.capableobjects.com/apps/InstantForum414/Topic4727-4-1.aspx</link><description>Thanks for the help.  What I have decided to do is create a ProductSearch class in my model.  It is similar to the ProductRepository that Peter suggested.  &lt;P&gt;This class will provide any searching needs for Product objects.  It also provides properties to enter filter criteria.  One of my goals with this is to have my OCL search queries defined in my model.  That way the OCL syntax is validated.  This is a similar goal to the ViewModels, but I would rather have my queries associated to a class and defined in the model rather than in a ViewModel.&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://www.capableobjects.com/apps/InstantForum414/uploads/Images/29785d79-5a25-4141-8a6f-be17.png"&gt;&lt;/P&gt;&lt;P&gt;After modeling this, I am liking this pattern.  The ProductSearch class provides an object to bind a user interface to for creating a search form.  I can also use it to save search criteria for later retrieval by the user.  These features are not really relevant to the word search I have talked about here, but I also want to have an advanced search where the user can enter specific values like manufacturer and price to search for products.&lt;/P&gt;&lt;P&gt;To create a search form all I need to do is get a ProductSearch object to bind the filter criteria to and bind the results to the derived association that represents the search.  &lt;/P&gt;&lt;P&gt;I haven't worked out all the details yet, but I'm hoping it works like I've planned.  One issue I do know of is that the derived association ocl does not allow for PsOcl queries.  So for large table queries I would need to call a method in the derivation ocl and in that method use a PsOclService.  I'm not sure how the derivation ocl is going to behave when the filter criteria changes.  My guess is it will requery.  This would be a good feature if it was done in a background thread, but a bad feature if done in the foreground thread.  I guess I will find out as I start to implement.&lt;/P&gt;&lt;P&gt;Brian</description><pubDate>Wed, 27 Jan 2010 05:00:30 GMT</pubDate><dc:creator>brian</dc:creator></item><item><title>RE: Calling Static Methods from OCL</title><link>http://www.capableobjects.com/apps/InstantForum414/Topic4727-4-1.aspx</link><description>Looks like you want the Repository pattern.&lt;br&gt;&lt;br&gt;I wouldn't put these as static methods on a business class.  Can a PurchaseOrder retrieve itself from your filing cabinet?  No :-)&lt;br&gt;&lt;br&gt;ProductRepository.AllByCriteria(ICriteria&amp;lt;Product&amp;gt; criteria);</description><pubDate>Mon, 25 Jan 2010 12:31:19 GMT</pubDate><dc:creator>Peter Morris</dc:creator></item><item><title>RE: Calling Static Methods from OCL</title><link>http://www.capableobjects.com/apps/InstantForum414/Topic4727-4-1.aspx</link><description>Hi&lt;P&gt;Ok - so I've done OclOperations and calling static methods dynamically.  How hard could it be to combine them???&lt;/P&gt;&lt;P&gt;So here's a sample solution (attached) that executes static methods using OCL.&lt;/P&gt;&lt;P&gt;StaticMethodInvoker is a transient class, with properties for the model dll and namespace.  These are needed to invoke the static methods using reflection.  This should be a singleton, and do not create this in code so only created using the static method StaticMethodInvoker.GetInstance().  This method also sets the values needed for reflection.&lt;/P&gt;&lt;P&gt;So an OclOperation is needed to create an instance of our StaticMethodInvoker (StaticMethodServiceCustomOcl.cs)&lt;/P&gt;&lt;P&gt;This class can then be created by the Ocl:  StaticMethodInvoker.GetStaticInvoker&lt;/P&gt;&lt;P&gt;We now have an instance of a class using ocl which is required for the Custom Ocl Operation, and this class contains the references needed for reflection.&lt;/P&gt;&lt;P&gt;We can now execute our static method invoker ocloperation with ocl like this (StaticOclMethod.cs)&lt;/P&gt;&lt;P&gt;StaticMethodInvoker.GetStaticInvoker.ExecuteStaticMethod('ClassName', 'MethodName', 'Parameters')&lt;/P&gt;&lt;P&gt;(Note all string values at this time)&lt;/P&gt;&lt;P&gt;The return types available at this time are:&lt;/P&gt;&lt;P&gt;IElement, IObject, IObjectList, string, int, datetime, long, double, bool&lt;/P&gt;&lt;P&gt;Samples in application&lt;/P&gt;&lt;P&gt;StaticMethodInvoker.GetStaticInvoker.ExecuteStaticMethod('Customer', 'GetAllByName', 'Nick') - returns IObjectList of Customer instances&lt;/P&gt;&lt;P&gt;StaticMethodInvoker.GetStaticInvoker.ExecuteStaticMethod('Customer', 'GetCurrentDateTime', '') - returns a DateTime&lt;/P&gt;&lt;P&gt;EcoSpace.cs&lt;/P&gt;&lt;P&gt;In the EcoSpace file you need to register the OclOperations on initialize.&lt;/P&gt;&lt;P&gt;Also, I need to get an IEcoServiceProvider into the OclOperationBase class, this is done by having a GlobalEcoSpace class, with a static EcoSpace value.  This is defined at the bottom of the EcoSpace.cs file and set during Initialize.&lt;/P&gt;&lt;P&gt;Help Needed&lt;/P&gt;&lt;P&gt;If anyone can give any pointers on the following:&lt;/P&gt;&lt;P&gt;1. Overloaded OclOperations so I can pass values other than strings to the same OclOperation&lt;/P&gt;&lt;P&gt;2. Open parameter number oclOperations, so more than one parameter can be passed to the static method&lt;/P&gt;&lt;P&gt;3. How to return any type, rather the IElement and simple types&lt;/P&gt;&lt;P&gt;Any other thoughts on how to improve the code would be much appreciated.&lt;/P&gt;&lt;P&gt;Hope this is of use......&lt;/P&gt;&lt;P&gt;Nick&lt;/P&gt;&lt;P&gt;PS - Credit goes to nagir for creating a transient singleton with ocl from a solution he gave me 2 years or so ago (StaticMethodServiceCustomOcl.cs)</description><pubDate>Wed, 13 Jan 2010 13:47:43 GMT</pubDate><dc:creator>nickcrisp</dc:creator></item><item><title>RE: Calling Static Methods from OCL</title><link>http://www.capableobjects.com/apps/InstantForum414/Topic4727-4-1.aspx</link><description>Hi,&lt;/P&gt;&lt;P&gt;maybe read &lt;A href="http://www.capableobjects.com/apps/InstantKB13/KnowledgebaseArticle50019.aspx"&gt;this article&lt;/A&gt; of Jonas in the knowlegde base. This could be a solution for you.</description><pubDate>Mon, 11 Jan 2010 22:10:44 GMT</pubDate><dc:creator>Peter Buchmann</dc:creator></item><item><title>RE: Calling Static Methods from OCL</title><link>http://www.capableobjects.com/apps/InstantForum414/Topic4727-4-1.aspx</link><description>Thanks for the reply Peter, but I don't want to make a custom OCL operation.  As I would need to do this over and over for each static method I define on my class.  I'm not sure why one cannot call a static method from OCL.  I would think it would be doable.  I think I'll add a feature request to Mantis.&lt;/P&gt;&lt;P&gt;For my Product Search situation I think I will just implement the Search as a normal method and create a new instance of Product to pass into the EcoDataSource.  I'm not exactly sure if or how I can do this.  Can the EcoDataSource be primed with a root object?  Or can I pass the Product object in as a parameter and use it to call the search method?&lt;/P&gt;&lt;P&gt;Brian</description><pubDate>Mon, 11 Jan 2010 21:05:35 GMT</pubDate><dc:creator>brian</dc:creator></item><item><title>RE: Calling Static Methods from OCL</title><link>http://www.capableobjects.com/apps/InstantForum414/Topic4727-4-1.aspx</link><description>[quote][b]brian (2010-01-11)[/b][hr]Is there a way to call static methods defined on a class in OCL?  &lt;P&gt;I defined a static method and set the IsQuery to true, but the OCL editor does not recognize the method.[/quote]&lt;P&gt; &lt;P&gt;Hi Brian,&lt;P&gt; &lt;P&gt;So actually you want to develop your own "CL_Class.allInstances" and call it like: CL_Class.GetObjects(parameter)?&lt;/P&gt;&lt;P&gt;You have to write a custom OCL operation and install it in the EcoSpace. Your custom OCL operation will only be available in the OCL editor when the operations are installed (e.g. when your program runs). In design mode you will get the error that the operation is not known. &lt;P&gt; </description><pubDate>Mon, 11 Jan 2010 15:56:15 GMT</pubDate><dc:creator>Peter Buchmann</dc:creator></item><item><title>RE: Calling Static Methods from OCL</title><link>http://www.capableobjects.com/apps/InstantForum414/Topic4727-4-1.aspx</link><description>I realize that I also need to pass an IEcoServiceProvider to the static method from the OCL.&lt;/P&gt;&lt;P&gt;What I am trying to do is write a static Search method for my Product class.  I pass a string of search words to the static method and it returns an IList&amp;lt;Product&amp;gt;.  &lt;/P&gt;&lt;P&gt;A ViewModel might help here, but I'd rather just put the logic into a static method on the Product class.  I'm using ASP.NET and an EcoDataSource.  I'm not sure if I can use a ViewModel from an EcoDataSource.  If I was using WPF, I would just call the static method directly.  &lt;/P&gt;&lt;P&gt;Anyone have any ideas?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Brian</description><pubDate>Mon, 11 Jan 2010 05:46:42 GMT</pubDate><dc:creator>brian</dc:creator></item><item><title>Calling Static Methods from OCL</title><link>http://www.capableobjects.com/apps/InstantForum414/Topic4727-4-1.aspx</link><description>Is there a way to call static methods defined on a class in OCL?  &lt;/P&gt;&lt;P&gt;I defined a static method and set the IsQuery to true, but the OCL editor does not recognize the method.</description><pubDate>Mon, 11 Jan 2010 03:55:35 GMT</pubDate><dc:creator>brian</dc:creator></item></channel></rss>
