Custom OCL Operations Part III: What if I want to add more than one operation?
It seems that the EcoOclOperationAttribute can only be used once per EcoSpace. If you try to register a second custom operation, you get the following error:
[Pascal Error] CustomOCLCommaTextEcoSpace.pas(49): E2326 Attribute ‘EcoOclOperationAttribute’ can only be used once per target
Being such a great framework, ECO wouldn’t disappoint us, would it? Of course not! There’s another way to add custom OCL operations to EcoSpaces and Jesper Hogstrom tells us all about it in the ECO wiki: http://homepages.codegear.com/ecoteam/pmwiki/pmwiki.php?n=Eco.DesignTimeOclOperations
Here’s the Delphi version of the C# code found in the wiki:
//install custom operations
class procedure TCustomOCLCommaTextEcoSpace.InstallOperations(OclSvc: IOclTypeService);
begin
OclSvc.InstallOperation(InvCommaText.Create);
OclSvc.InstallOperation(CommaText.Create);
end;
//install design-time support for the operations
class constructor TCustomOCLCommaTextEcoSpace.Create;
var
OclSvc: IOclTypeService;
begin
fTypeSystemProviderLock := TObject.Create;
//obtain OclTypeService
OclSvc := GetTypeSystemService.StaticEcoServices.GetEcoService(typeof(IOclTypeService)) as
IOclTypeService;
//install the operations
InstallOperations(OclSvc);
end;
constructor TCustomOCLCommaTextEcoSpace.Create;
begin
inherited Create;
InitializeComponent;
//install run-time support for operations
InstallOperations(OclService);
end;
Share This | Email this page to a friend
Posted by Daniel Polistchuck on December 12th, 2005 under Delphi | 1 Comment »Custom OCL Operations Part II: Design-time and update
Just got a message from Jonas, one of the ECO Gandalfian developers, with more info… they are so great that I’d like to share them with you!
This is going to be a two round fight with a guaranteed knock out in the second round!
Round 1 - Getting rid of the constructor and installation methods
Jonas told me that the “secret” Support property, inherited from OclOperationBase already had most of the services that I’d need, including OclService… so let’s get rid of the constructor
While we’re doing that, let’s also throw the class procedure Install out… since we’re going to knock you out with new installation procedure for design and runtime in the next round.
Here’s the new and streamlined source code for our operation:
unit Borland.Eco.Ocl.Support.CommaText;
interface
uses
Borland.Eco.Ocl.Support,
Borland.Eco.ObjectRepresentation,
Borland.Eco.UmlRt,
Borland.Eco.Handles,
Borland.Eco.Services,
Borland.Eco.Subscription;
type
CommaText = class (OclOperationBase)
strict protected
procedure Init; override;
public
procedure Evaluate(oclParameters: IOclOperationParameters); override;
end;
implementation
uses
System.Text;
{ CommaText }
procedure CommaText.Evaluate(oclParameters: IOclOperationParameters);
var
ElemCol: IElementCollection;
Elem: IElement;
Res : String;
SB: StringBuilder;
begin
inherited;
//gimme the collection
ElemCol := oclParameters.Values[0].Element.GetAsCollection;
//gimme the OclService as welll
//for each element in the collection, get me the default string representation
SB := StringBuilder.Create;
for Elem in ElemCol do
SB.Append(Support.OclService.Evaluate(Elem,’self.AsString’).AsObject.ToString+‘,’);
Res := SB.ToString;
if Length(Res)>0 then
Delete (Res,Length(Res),1);
//return Res as a string
oclParameters.Result.SetOwnedElement(Support.CreateNewConstant(Support.StringType,Res));
end;
procedure CommaText.Init;
var
OclParams : array of IOclType;
begin
//tell the framework I have only one parameter
SetLength (OclParams,1);
//the parameter is an ObjectList (collection)
OclParams[0] := Support.ObjectListType;
//inform the operation name, its parameters, and result type
InternalInit (‘commaText’,OclParams,Support.StringType);
end;
end.
Round 2 - Installing both at design-time and at runtime.
This is gonna knock you out … no doubt about it! To make this new operation available both at design and run time, just add the following attribute to your EcoSpace class:
[EcoOclOperationAttribute (typeof(CommaText), true)]
The first parameter is the type of your OCL operation class and the second is true if you want to make it available both for OCL and ECO Action Language expressions. False will install it as an ECO Action Language operation only:

There it is… plug ‘n play folks!
Share This | Email this page to a friend
Posted by Daniel Polistchuck on December 7th, 2005 under Delphi | 3 Comments »Delphi and Custom OCL Operations
I always liked TStringList.CommaText, so I decided to try and implement a “commaText“ custom OCL Operation for Collections… I couldn’t believe how easy it was going to be until I tried: here it is:
unit Borland.Eco.Ocl.Support.CommaText;
interface
uses
Borland.Eco.Ocl.Support,
Borland.Eco.ObjectRepresentation,
Borland.Eco.UmlRt,
Borland.Eco.Handles,
Borland.Eco.Services,
Borland.Eco.Subscription;
type
CommaText = class (OclOperationBase)
strict protected
procedure Init; override;
public
constructor Create (ES : EcoSpace);
procedure Evaluate(oclParameters: IOclOperationParameters); override;
class procedure Install (ES: EcoSpace);
strict private
MyEcoSpace: EcoSpace;
end;
implementation
{ CommaText }
constructor CommaText.Create(ES: EcoSpace);
begin
inherited Create;
//will be necessary for evaluation of the default string representation of collection
//elements
MyEcoSpace := ES;
end;
procedure CommaText.Evaluate(oclParameters: IOclOperationParameters);
var
ElemCol: IElementCollection;
Elem: IElement;
Res : String;
OclService: IOclService;
SB: StringBuilder;
begin
inherited;
//gimme the collection
ElemCol := oclParameters.Values[0].Element.GetAsCollection;
//gimme the OclService as welll
OclService := MyEcoSpace.GetEcoService(typeof(IOclService)) as IOclService;
//for each element in the collection, get me the default string representation
SB := StringBuilder.Create;
for Elem in ElemCol do
SB.Append(OclService.Evaluate(Elem,’self.AsString’).AsObject.ToString+‘,’);
Res := SB.ToString;
if Length(Res)>0 then
Delete (Res,Length(Res),1);
//return Res as a string
oclParameters.Result.SetOwnedElement(Support.CreateNewConstant(Support.StringType,Res));
end;
procedure CommaText.Init;
var
OclParams : array of IOclType;
begin
//tell the framework I have only one parameter
SetLength (OclParams,1);
//the parameter is an ObjectList (collection)
OclParams[0] := Support.ObjectListType;
//inform the operation name, its parameters, and result type
InternalInit (‘commaText’,OclParams,Support.StringType);
end;
class procedure CommaText.Install(ES: EcoSpace);
var
OclService: IOclService;
begin
//gimme the OclService
OclService := ES.GetEcoService(typeof(IOclService)) as IOclService;
//install the new operation
OclService.InstallOperation(CommaText.Create(ES));
end;
end.
Here’s how you install it:
CommaText.Install(EcoSpace);
Here’s how to use it:Customer.Create(EcoSpace).name := ‘Daniel’;
Customer.Create(EcoSpace).name := ‘John’;
Customer.Create(EcoSpace).name := ‘Jesper’;
Customer.Create(EcoSpace).name := ‘Jan’;
Customer.Create(EcoSpace).name := ‘Jonas’;
ExpressionHandle1.Expression := ‘Customer.allInstances->commaText’;
MessageBox.Show(ExpressionHandle1.Element.AsObject.ToString);
Have fun!
Oh, by the way… it doesn’t work at design time yet… stay tuned.
Share This | Email this page to a friend
Posted by Daniel Polistchuck on December 7th, 2005 under Delphi | 6 Comments »EcoSpace Validando Constraints
Ao desenvolver aplicações ECO, às vezes nos deparamos com o intrigante pensamento: “por que meu EcoSpace não verifica meus constraints antes de atualizar a base, levantando uma exceção?“. Há um demo C# no Delphi que nos mostra como desenvolver um novo PersistenceService que faz exatamente isso. Fiz uma versão simplificada em Delphi (com uma classe, somente) baseada na em C# com um projeto demo. Para reutilizarmos o ValidatingPersistenceService, basta dar um uses na sua unit, declarar um ValidatingPersistenceService assim:
strict private
VPS : ValidatingPersistenceService;
e dar um override no método Initialize de seu EcoSpace assim:
procedure TProject128EcoSpace.Initialize;
begin
inherited;
VPS := ValidatingPersistenceService.Create;
VPS.InstallService(Self.EcoServiceProvider);
end;
Agora, sempre que você chamar EcoSpace.UpdateDatabase, o ValidatingPersistenceService entrará em ação e levantará uma exceção com todos os constraints quebrados.
O código para o ValidatingPersistenceService e o projeto demo pode ser baixado do CodeCentral: http://cc.borland.com/item.aspx?id=23858
Share This | Email this page to a friend
Posted by Daniel Polistchuck on November 24th, 2005 under Delphi em Português | Comment now »Validating EcoSpace
While developing ECO applications we sometimes find ourselves thinking: why doesn’t my EcoSpace check my constraints and automatically raises exceptions when they are not met? There’s a C# demo that comes with Delphi that shows us how to develop a new PersistenceService. I’ve created a simplified Delphi version (with a single class) based on the C# one with a demo project. In order to reuse this ValidatingPersistenceService, just use its unit, declare a private ValidatingPeristenceService like this:
strict private
VPS : ValidatingPersistenceService;
and override the Initialize method of your EcoSpace like this
procedure TProject128EcoSpace.Initialize;
begin
inherited;
VPS := ValidatingPersistenceService.Create;
VPS.InstallService(Self.EcoServiceProvider);
end;
Now, whenever you call EcoSpace.UpdateDatabase, the ValidatingPersistenceService will kick in and raise an exception with all the constraints that were broken.
The ValidatingPersistenceService code and a demo project can be downloaded from: http://cc.borland.com/item.aspx?id=23858
Share This | Email this page to a friend
Posted by Daniel Polistchuck on November 24th, 2005 under Delphi | Comment now »Links interesantes de ECO
ECO Wiki - http://homepages.codegear.com/ecoteam/pmwiki/pmwiki.php
R&D Blog - http://blogs.codegear.com/team/eco
Malcom’s Blog - http://www.malcolmgroves.com
Peter Morris - http://www.howtodothings.com
ECO Delphi Newsgroup - nntp://borland.public.delphi.modeldrivenarchitecture.eco
ECO C# Newsgroup - nntp://borland.public.csharpbuilder.modeldrivenarchitecture.eco
ECO BDN Section - http://bdn.borland.com/delphi/eco
Dr. Bob’s ECO Articles - http://www.drbob42.com/eco/
Dr. Bob’s Blog - http://www.drbob42.com/blog
Deem uma olhada nesses sites… vocês encontrarão diversas “pérolas escondidas”.
Share This | Email this page to a friend
Posted by Daniel Polistchuck on November 21st, 2005 under Delphi em Português | Comment now »Interesting ECO Links
Here’s a list of interesting ECO links:
ECO Wiki - http://homepages.codegear.com/ecoteam/pmwiki/pmwiki.php
R&D Blog - http://blogs.codegear.com/team/eco
Malcom’s Blog - http://www.malcolmgroves.com
Peter Morris - http://www.howtodothings.com
ECO Delphi Newsgroup - nntp://borland.public.delphi.modeldrivenarchitecture.eco
ECO C# Newsgroup - nntp://borland.public.csharpbuilder.modeldrivenarchitecture.eco
ECO BDN Section - http://bdn.borland.com/delphi/eco
Dr. Bob’s ECO Articles - http://www.drbob42.com/eco/
Dr. Bob’s Blog - http://www.drbob42.com/blog
Be sure to check those resources above… you’ll find many “hidden pearls” there!
Share This | Email this page to a friend
Posted by Daniel Polistchuck on November 21st, 2005 under Delphi | 3 Comments »BorCon Brasil e ECOmmunity BR
Acabou a BorCon Brasil 2005!
Gostaria de agradecer a presença dos mais de 600 participantes, tanto nas palestras Management, quanto nas Developer! Também queria agradecer aos nossos palestrantes… vocês foram nota 10!
Durante meu curso de ECO, surgiu a idéia de se criar um grupo de discussão para aprendermos mais sobre o assunto com nossas experiências compartilhadas. Não importa se você é iniciante ou faixa-preta… bem vindo ao grupo! Para se inscrever:
| Participe do grupo ECOmmunity BR | |
| Pesquisar o arquivo do grupo groups.google.com.br | ||
Se a caixa acima não te levar para o site do Google Groups com um aviso sobre sua inscrição, clique neste link: http://groups.google.com.br/group/ECOmmunity-BR/subscribe
Share This | Email this page to a friend
Posted by Daniel Polistchuck on November 20th, 2005 under Delphi em Português | Comment now »Come
Olá Pessoal,
Acabei de sair da sessão de abertura do DevCon 2005 USA! Tivemos a surpresa de ser apresentados ao novo CEO (cartola, saca, Walter?) da Borland: Tod Nielsen.
Acho que vamos todos gostar dele, porque ele fez questão de deixar claro que “Developers Rule the World”, ou seja, “Desenvolvedores Mandam no Mundo!”
Hehehe…
Share This | Email this page to a friend
Posted by Daniel Polistchuck on November 8th, 2005 under Delphi em Português | 2 Comments »Source-code for the Delphi TechWeekend ECO mini-course
Hi everyone!
Here’s the source-code for the ECO mini-course that I gave in the last Delphi TechWeekend! Thanks for your attendance and active participation!
Download here: http://cc.borland.com/item.aspx?id=23429
Share This | Email this page to a friend
Posted by Daniel Polistchuck on July 27th, 2005 under Delphi | 2 Comments »

RSS Feed
