Asimov Technologies
J2EE, JEE, PHP
Frank D. Martínez’s Blog
Software & Fun
Welcome to my technical blog. Here you can find my opinions and proposals over many software development things, mainly on open source projects.
Actor-Role Pattern. A JPA Implementation.
Actor-Role Pattern introduction
You can find a quick intro to the pattern in wikipedia: http://en.wikipedia.org/wiki/Role_Class_Model
JPA Implementation (Mapping)
Here is the source code with JPA annotations:
Download source here (Netbeans 6.0 Project)
The basic idea of this pattern is “use delegation instead of inheritance” then you can refer the actor through its role which also provides specific attributes and behaviors in relation to the context where it is used.
For example, in the Invoice Class you reference a Customer (Not a Person) but you can access the person through a invoice.getCustomer().getActor().
The rest is straightforward, see the code.
VelFop = Velocity + Fop
I have developed a simple dynamic FOP processor with Velocity. I used it to make dynamic pdf reports and i got very good results.
You can download it from here:
- The jar file only: velfop.jar
You need to download velocity, fop and its dependencies from Apache. - The source code: velfop.zip
A Netbeans 6 project, A Basic example, and All dependency jars.
This is only a glue of two good projects from Apache.
For documentation please go to Apache projects homes.
Example usage:
// Velocity initialization.
VelocityEngine ve = new VelocityEngine();
ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this);
ve.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH,
new File(".").getCanonicalPath());
ve.init();
// Load the context.
Context context = new VelocityContext();
context.put("messages", Arrays.asList(
new String[] {"Message one", "Message Two", "Message three"}));
// Init source template and target output.
Template t = ve.getTemplate("src/report1.velfop");
FileOutputStream out = new FileOutputStream(
new File("./src/report1.pdf").getCanonicalPath());
// Do the magic
VelFopProcessor vfp = new VelFopProcessor();
vfp.merge(t, context, "application/pdf", out);
JPA: A Basic Intro.
This is a basic intro to JPA. It is not a manual neither a reference, it is just an intro to the concepts.
Xavar: SQL Query to XML,JSON,Text, etc .. For RESTful Applications.
Xavar is a small library I developed to provide some database queries through a RESTful interface in XML and JSON formats.
The basic feature is:
Make a hierarchic query to a relational database and serialize the output to an OutputStream. The serialization format must be pluggable.
And there is it: http://www.ibstaff.net/fmartinez/?page_id=9
You can extend it as you need because i published the source code under the LGPL. And it is designed thinking of pluggability of the executors.
This site contains personal opinions about many things and does not intend to be normative in any aspect.
Java, J2EE, J2SE, JEE, Are trademarks of Sun Microsystems Inc.

