cancel
Showing results for 
Search instead for 
Did you mean: 

automatic invoking of policy and behaviour

pmarreddy
Champ in-the-making
Champ in-the-making
hi,


how exactly is policy is invoked (i.e automatically like it is doine in audit), i saw the tests but i cant not understand them clearly.

if any body could explain me with an example that would be great.

thanks in adv

prasanth.
4 REPLIES 4

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Have a look at VersionableAspect.java (found in the repository project) as an  example of code that binds behaviour to a particular policy (in this case it is used to implement the auto-version behaviour).

Could you provide some details about what you would like to achieve?  This info may help in providing you a more helpful answer.

Thanks,
Roy

pmarreddy
Champ in-the-making
Champ in-the-making
hi thank u for ur prompt reply,

my question is in VersionableAspect.java there are three behaviors.

onAddAspect, onContentUpdate, onCopyNode how exactly does the program knows which behavior gets instantiated,

I am looking to create a new policy that gets instantiated automatically. 


thanks prasanth

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Ok, I'll talk you through some of the relevant code in VersionableAspect and hopefully it will answer your question.

Lets say, for example, you would like a chunk of code to be executed every time an aspect of a particular type is applied to a node.  In this example we are interested in binding behaviour to the 'onAddAspect' policy.

You can think of a policy as a repository event.  For example every time an aspect is applied to a node the repository triggers the onAddAspect policy.  At this point any behaviours (like event handlers) that have been registered for that policy and meet the type restrictions defined, when the behaviour was bound, will be fired.

To bind to behaviour to a policy we use code similar to this …



   this.policyComponent.bindClassBehaviour(
                QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"),
                ContentModel.ASPECT_VERSIONABLE,
                new JavaBehaviour(this, "onAddAspect"));


Here we are binding to the onAddAspect behaviour (1st parameter), this behaviour will only be fired if the node in question has the versionable aspect applied (2nd parameter).  The behaviour implementation is the 3rd parameter and in this example its a method called "onAddAspect" in "this" class.

This is what the method could look like …



   public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
   {
    // Do some stuff ….  
   }


I hope this helps to explain things,
Roy

pmarreddy
Champ in-the-making
Champ in-the-making
thank u verymuch for ur kind reply.