Use dynamic-generated JAXB compiled-classes

K

kevincw01

I have a requirement to create an app that can generate static html
webpages. The app must be stand alone as I cannot just serve the pages
from an application server like jboss or tomcat. My prototype is as
follows.

I use velocity from the apache foundation as my template engine and xml
and xsd for the data that goes into the template. I have pre-compiled
JAXB classes generated from several xml schemas(xsd) which I use to
unmarshall the xml data into a java bean/object which is then merged
with the velocity template and results in the html output.

The problem I have is that the end-user admin of the app must not have
to know java to create new types of pages. Here's the scenario for an
admin creating a new template/page-type:

1. Create a new velocity template(no problem)
2. Create new XML schema and associated xml data(no problem)
3. Generate the JAXB classes for the schema(ant task, no problem)
4. Reference these new classes in the app so that it can unmarhsal the
xml data to a bean and give it to velocity(uh-oh).

My problem is obviously #4. I was thinking of having a properties file
where the admin could specify the jaxb generated classes for this
particular page type. But...wouldn't I then need to add the import
statments into the application code, change the bean data type and
re-compile the main application? This would be unacceptable given the
requirement that the admin wouldn't know java.

thanks for your tips,
Kevin
 
K

kevincw01

well it looks like talking it out in my post helped me figure it out.
I think it had to do with the way I was used to using jaxb.

Object bean = null;
JAXBContext jc = null;
Unmarshaller um = null;

jc = JAXBContext.newInstance(props.getProperty("jaxb-class"));
um = jc.createUnmarshaller();
bean = um.unmarshal(new
FileInputStream(props.getProperty("template-xml")));

//setup velocity and merge bean with template here

I was using the specific jaxb-generated class as my 'bean's type and I
was setting the jaxbcontext with the jaxb-generated specific
objectfactory. But the way I do it here, it will find and bind the
classes at runtime. No jaxb-generated classes were imported or
referenced for this code and my html output is identical to how it was
before. Hope this helps anyone else who may have been thinking like I
was thinking.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,118
Latest member
LatishaWhy
Top