Using Models in Templates

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

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

A wrapper is a Java class that implements the IArtifactWrapper 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 Wrapper class.

A sample Model class is as follows:

1. public class EntityWrapper implements IArtifactWrapper {

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. }

11.}

Within your template, you can access the methods of your Wrapper class using $modelName.method with arguments passed (as necessary). Where wrapperName is the name you provided in your rule specification. Assuming the above model definition with a wrapper 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