Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Wednesday, 8 January 2014

Using JAXB to Parse a List of Items and References

I recently hit a problem using JAXB to parse a list of items in XML that contains both the actual items and references to items.
<examplelist>
  <item>A</item>
  <item>B</item>
  <item-ref uri="itemC.xml"/>
  <item-ref uri="itemD.xml"/>
  <item>E</item>
</examplelist>
I had implemented an adapter to transform an ItemRef instance to an Item, but the following code did not work as I had expected.
@XmlElements({
  @XmlElement(name = "item", type = Item.class),
  @XmlElement(name = "item-ref", type = ItemRef.class)
})
private List<ability> items = new LinkedList<item>();
Instead of applying the adapter to the item-ref elements, it applied the adapter to all elements mapped to the list (it took a while to work this one out). The fix was to create a new adapter class that mapped Item to Item and use this as the adapter for item-ref elements. If this adapter was passed an ItemRef, it adapted it to an Item, otherwise it returned it unmodified.

Tuesday, 20 April 2010

Android

So yesterday I decided that I would look into what is involved in writing an app for Android, Google's mobile phone OS.

I downloaded the various SDKs, eclipse plugins and emulators and spend about half a day setting them all up (Tip of the day, if using this in a Jazz client, change the Jazz client to use a Sun JVM instead of the default IBM one).

Once the set up was done, I jumped right in at the deep end and started to put together a UI for a very simple app designed to display a D&D character builder save file. I originally tried to build the UI using java, but nothing appeared. Puzzled, I looked through a the docs and tutorials and nearly everything used XML files to define the UI instead, so I tried that and quickly got something up and running. It wasn't pretty, but it did the job.

I'll reserve judgement until I see how hard it is to make it pretty (including the support of changing orientation to landscape).

Thursday, 11 February 2010

Embedding Images in a Wave

OK, I'm sure this has been done before.
But after looking for a robot to automagically embed linked images into a wave, I decided to create my own.

It's pretty basic, just looks for URLs starting "http:" and ending with a known image extension. But after a quick test it seems to work OK.

If anyone wants to give it a go, just invite wog-embedder@appspot.com to your wave and type in some image URLs.