writing JAXB extension plugins
Thursday, November 01, 2012
JAXB extension plugins (1) give the user more power than simple binding alterations, plus can encourage clean schemas by keeping the code extensions out of the xsd's. But finding up-to-date documentation on this can be a pain, most predates maven.
In hindsight, the process is actually quite simple and there are some good references, but it still takes collation of quite a few sites to make it work. Here I hope to capture them all for a cohesive approach.
Note that 'plugin' is a ubiquitous term and here can mean many things. For disambiguation I've added a postscript number to each use of the term. See footnotes at the bottom for meanings.
JAXB runtime
This post assumes you're using maven. And if so, the JAXB plugin (2) to use is maven-jaxb2-plugin. Add the latest version to your pom http://mvnrepository.com/artifact/org.jvnet.jaxb2.maven2/maven-jaxb2-plugin. Then get your schema generation working OK as documented plenty of places elsewhere on the web. If you're looking at this page then you're probably well past that step anyway.Plugin project skeleton
Create a new maven project to hold your plugin (1). For this example we'll call it my-jaxb-plugin.In the pom add a dependency on jaxb xjc, eg:
<groupid>com.sun.xml.bind</groupid>
<artifactid>jaxb-xjc</artifactid>
<version>2.2.6</version>
</dependency>
Create a new class, call it MyPlugin1 in package com.eg, extending from com.sun.tools.xjc.Plugin. For now just implement the required methods returning "XmyJaxb" from getOptionName(), and implement run() as System.out.println("***working!"); (or similar :).
Now create new folders META-INF/services on the classpath (eg src/main/resources). Add a text file in there called com.sun.tools.xjc.Plugin.In this file is a list of all the plugins that this project provides, one per line. So for now add your new plugin class:
Run a maven install on the project to make it available (not needed later if you use workspace resolution with eclipse maven plugin (3))
Employ the plugin (1)
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<extension>true</extension>
<args>
<arg>-debug</arg>
<arg>-XmyJaxb</arg>
</args>
<plugins>
<plugin>
<groupId>nz.govt.police</groupId>
<artifactId>esbschema-jaxb-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
The -debug arg can be removed later as needed. You may also find it useful to use -X after your mvn install command to get verbose output from the maven build.
More
For taking your plugin (1) further, read the key post from 2005, resources incl javadoc for jaxb-xjc, and the sun codemodel javadocs which you'll be using to modify the code generation.Footnotes
mongodb script types
Monday, April 23, 2012
There's the obvious choice of client drivers in your language of choice for application-based mongodb connections, but for server-side admin and scripting, js is best. But from the shell and cron, often they get wrapped in shell scripts. This table-esque post outlines some of the decision points to use when approaching this, plus some guidance as to how to write them.
Interactive shell
Syntax:mongo
About:
--eval
Syntax: mongo dbname --eval "db.coll..."
About:
- see printjson
js file
Syntax: mongo dbname filename.js
About:
eval + js file
Syntax: mongo dbname --eval "param1=val1;param2=val2" filename.js
About:
All within one sh script
Syntax:
js here
js here
eof
- Cannot be run inside an --eval
- From mapreduce docs { inline : 1} - With this option, no collection will be created, and the whole map-reduce operation will happen in RAM. Also, the results of the map-reduce will be returned within the result object. Note that this option is possible only when the result set fits within the 16MB limit of a single document. In v2.0, this is your only available option on a replica set secondary.
- Queries (such as count(), sort()) cannot be run on inline results (as of mongodb 2.1+ new aggregation features may allow this). For versions <2.1, seeing as cannot run these queries on inline results, and can't have temp collections on secondary servers, have to run these on primary server so can save to a temp collection and run queries against that.
TurnKey Linux
Saturday, February 18, 2012
TurnKey is yet another Linux distro, but it's come a long way since I last checked it out. Initially providing images for LAMP and 2x CMS stacks only, it now boasts nearly 50 different appliances, with an impending launch of up to 150. There are now commercial options for managed cloud deployments as well. Nice offerring