Using Models in Templates

Note: This section is only applicable for Artifact based rules.

You can specify a Model class for use within an Artifact based rule. The Model class and it's name is specified on the Rules section of the Plug-in Project Descriptor.

A model is a Java class that you implement in the IArtifactModel interface specified in the Tigerstripe external API. The Artifact being processed is passed to the class using the setIArtifact method to which Tigerstripe automatically calls, and passes the current Artifact to your Model class.

A sample Model class is as follows:

1. public class EntityModel implements IArtifactModel {

2. private IArtifact artifact;

3. public void setIArtifact(IArtifact artifact) {

4. this.artifact = artifact;

5. }

6. public String getOutPath(){

7. String packageName = this.artifact().getPackage();

8. String path = packageName.replaceAll("\\.", "/");

9. return path;

10. }


Within your template, you can access the methods of your Model class using the $modelName.method method with arguments passed (as necessary). Where modelName is the name you provided in your rule specification. Assuming the above model definition with a model name of entity, your template could call the getOutPath method as follows:

$entity.getOutPath() - Returns a String similar to com/mycompany/myPackage.

© copyright 2005, 2006, 2007 Cisco Systems, Inc. - All rights reserved