<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi Rafael,</div><div><br></div>There are two things you need to do:<div>1) "understand" the Person class</div><div>2) generate new code</div><div><br></div><div><br></div><div>1)</div><div>You can use a command parameter to get the Person class:&nbsp;@Option(name = "class", required = true, type = PromptType.JAVA_CLASS) JavaResource classUnderTest</div><div><br></div><div>JavaResource is a rich file representation of the class.&nbsp;</div><div>Now you can use the JavaSourceFacet to get information about the class itself:</div><div><div><br></div><div>JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);</div><div>JavaSource&lt;?&gt; javaSource = classUnderTest.getJavaSource();</div></div><div><br></div><div>javaSource has methods such as getPackage() etc.</div><div><br></div><div>2)</div><div>Now you have to generate code. There are two ways to do this, depending on your needs.</div><div>The most elegant way is to use the "JavaParser" builder API:</div><div><br></div><div><div>JavaClass javaClass = JavaParser.create(JavaClass.class)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.setPackage(entityPackage)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.setName(entityName)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.setPublic()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.addAnnotation(Entity.class).getOrigin()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.addInterface(Serializable.class);</div></div><div>Field&lt;JavaClass&gt; id = javaClass.addField("private Long id = null;");&nbsp;</div><div>….</div><div><br></div><div>My experience is that this works best for small classes. If you need to generate a lot of code it might be better to use a tempting framework such as Apache Velocity.</div><div>You can find an example of this in the code of the Arquillian plugin:&nbsp;<a href="https://github.com/forge/plugin-arquillian/blob/master/src/main/java/org/jboss/seam/forge/arquillian/ArquillianPlugin.java#L93">https://github.com/forge/plugin-arquillian/blob/master/src/main/java/org/jboss/seam/forge/arquillian/ArquillianPlugin.java#L93</a></div><div><br></div><div>You can just add Velocity to your pom file and it will work.</div><div><br></div><div>If you have any more questions, let us know! What kind of plugin are you writing?</div><div><br></div><div>Paul Bakker</div><div><br></div><div><br><div><div><div>On Oct 23, 2011, at 2:26 AM, Rafael Pestano wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi everyone,<br><br>this is my first mail to this list and id like to <span id="result_box" class="short_text" lang="en"><span class="hps">congratulate the Forge team</span></span> for their work.<br><br>my question is, what's the best way to generate .java, .xhtml files with forge?<br>

<br>Id like to write a plugin which would receive an entity class as parameter and generate some code on top of it, eg:<br><br><code class="java plain">$ generate-service Person</code><br><code class="java plain">$ generate-controller Person</code><br>

<code class="java plain">$ </code><code class="java plain">generate-view</code> <code class="java plain">Person</code><br><br><br>Where Person is a domain object, is it possible with Forge? if yes, whats the best way?<br>

<br><br>thanks in advance.<br><br><br><br clear="all"><br>-- <br><a href="http://www.advancedit.com.br/" target="_blank"><span style="color:black;text-decoration:none"></span></a><span></span><span><span style="color:rgb(192, 192, 192)">Att, </span><br style="color:rgb(192, 192, 192)">

<br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Rafael M. Pestano</span><br style="color:rgb(192, 192, 192)"><br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul</span><br style="color:rgb(192, 192, 192)">

<span style="color:rgb(192, 192, 192)">Graduando em Ciência da Computação UFRGS</span></span><br>
_______________________________________________<br>forge-dev mailing list<br><a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/forge-dev<br></blockquote></div><br></div></div></body></html>