<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: HATEOAS for legacy object models</title>
	<atom:link href="http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/feed/" rel="self" type="application/rss+xml" />
	<link>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/</link>
	<description>&#955; Thoughts and rants</description>
	<lastBuildDate>Mon, 28 Nov 2011 14:13:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: HATEOAS: URITemplateAspects, LinkAwareModels and LinkTemplateProcessors - brettdargan.com</title>
		<link>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/comment-page-1/#comment-383</link>
		<dc:creator>HATEOAS: URITemplateAspects, LinkAwareModels and LinkTemplateProcessors - brettdargan.com</dc:creator>
		<pubDate>Wed, 29 Apr 2009 12:24:50 +0000</pubDate>
		<guid isPermaLink="false">http://brettdargan.com/blog/?p=196#comment-383</guid>
		<description>[...] I have some old code, to show this working. One day I&#039;ll get a chance to clarify terms and simplify the code [...]</description>
		<content:encoded><![CDATA[<p>[...] I have some old code, to show this working. One day I&#8217;ll get a chance to clarify terms and simplify the code [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross McDonald</title>
		<link>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/comment-page-1/#comment-366</link>
		<dc:creator>Ross McDonald</dc:creator>
		<pubDate>Sat, 04 Apr 2009 14:07:33 +0000</pubDate>
		<guid isPermaLink="false">http://brettdargan.com/blog/?p=196#comment-366</guid>
		<description>Hi.

OK, I added a &#039;private Long id&#039; to Country, and ran your sample.

I added some debug so the line numbers are different, but the error is occurring on line :

&#039;Class clazz = entity.getClass();&#039; in the &#039;getResourceLinkFields&#039; method.

Stacktrace below:

Hit ENTER for redeploy
Entity is : [com.example.rest.model.jaxb.Country@7f6a92, com.example.rest.model.jaxb.Country@2dbcf0]
clazz is : class com.example.rest.model.jaxb.Country
declared fields of : com.example.rest.model.jaxb.Country@7f6a92 are : [Ljava.lang.reflect.Field;@cf64f8
Apr 4, 2009 3:01:27 PM org.apache.catalina.core.StandardWrapperValve log
SEVERE: StandardWrapperValve[Jersey Web Application]: PWC1406: Servlet.service() for servlet Jersey Web Application threw exception
java.lang.NullPointerException
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.getResourceLinkFields(ResourceLinkResponseFilterDumb.java:101)
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.addResourceLinks(ResourceLinkResponseFilterDumb.java:65)
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.getResourceLinkFields(ResourceLinkResponseFilterDumb.java:109)
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.addResourceLinks(ResourceLinkResponseFilterDumb.java:65)
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.filter(ResourceLinkResponseFilterDumb.java:46)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:581)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:514)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:505)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:359)


Thanks for your help,

Ross</description>
		<content:encoded><![CDATA[<p>Hi.</p>
<p>OK, I added a &#8216;private Long id&#8217; to Country, and ran your sample.</p>
<p>I added some debug so the line numbers are different, but the error is occurring on line :</p>
<p>&#8216;Class clazz = entity.getClass();&#8217; in the &#8216;getResourceLinkFields&#8217; method.</p>
<p>Stacktrace below:</p>
<p>Hit ENTER for redeploy<br />
Entity is : [com.example.rest.model.jaxb.Country@7f6a92, com.example.rest.model.jaxb.Country@2dbcf0]<br />
clazz is : class com.example.rest.model.jaxb.Country<br />
declared fields of : com.example.rest.model.jaxb.Country@7f6a92 are : [Ljava.lang.reflect.Field;@cf64f8<br />
Apr 4, 2009 3:01:27 PM org.apache.catalina.core.StandardWrapperValve log<br />
SEVERE: StandardWrapperValve[Jersey Web Application]: PWC1406: Servlet.service() for servlet Jersey Web Application threw exception<br />
java.lang.NullPointerException<br />
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.getResourceLinkFields(ResourceLinkResponseFilterDumb.java:101)<br />
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.addResourceLinks(ResourceLinkResponseFilterDumb.java:65)<br />
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.getResourceLinkFields(ResourceLinkResponseFilterDumb.java:109)<br />
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.addResourceLinks(ResourceLinkResponseFilterDumb.java:65)<br />
	at com.example.rest.connectedness.filter.ResourceLinkResponseFilterDumb.filter(ResourceLinkResponseFilterDumb.java:46)<br />
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:581)<br />
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:514)<br />
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:505)<br />
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:359)</p>
<p>Thanks for your help,</p>
<p>Ross</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/comment-page-1/#comment-362</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 31 Mar 2009 23:26:28 +0000</pubDate>
		<guid isPermaLink="false">http://brettdargan.com/blog/?p=196#comment-362</guid>
		<description>sure, send me the stack trace and I&#039;ll take a look.</description>
		<content:encoded><![CDATA[<p>sure, send me the stack trace and I&#8217;ll take a look.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross McDonald</title>
		<link>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/comment-page-1/#comment-361</link>
		<dc:creator>Ross McDonald</dc:creator>
		<pubDate>Mon, 30 Mar 2009 10:54:09 +0000</pubDate>
		<guid isPermaLink="false">http://brettdargan.com/blog/?p=196#comment-361</guid>
		<description>Hi Brett.

This is great stuff, it is exactly what I need to do.  However, my domain objects have an ID of type &#039;Long&#039;, and the &#039;getResourceLinkFields&#039; method in the filter is falling over with an NPE.  I am having trouble modifying the code to work with Longs rather than strings like in your example.

Can you suggest how to update the code to work in my case ?</description>
		<content:encoded><![CDATA[<p>Hi Brett.</p>
<p>This is great stuff, it is exactly what I need to do.  However, my domain objects have an ID of type &#8216;Long&#8217;, and the &#8216;getResourceLinkFields&#8217; method in the filter is falling over with an NPE.  I am having trouble modifying the code to work with Longs rather than strings like in your example.</p>
<p>Can you suggest how to update the code to work in my case ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/comment-page-1/#comment-110</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sat, 17 Jan 2009 01:56:57 +0000</pubDate>
		<guid isPermaLink="false">http://brettdargan.com/blog/?p=196#comment-110</guid>
		<description>Although I label &quot;HATEOAS4legacy&quot;, the technique isn&#039;t just for applicable for legacy models nor jaxb annotated models.

This is all about getting a degree of decoupling from your model objects through to your representations aka views. We all know this separation has worked well for us in the past.

You could avoid this separation and implement it in a simpler fashion, but it you would only solve it for a specific problem or set of classes.

There are three main parts of this technique:
 1. Enhance your model objects so  they have a placeholder/collection so you can accumulate links
 2. Annotate your model at interesting members where you want links
 3. In a ContentResponseFilter, scanning for annotations of interest and inserting them into the collection

Step 1, I used aspectj, to keep things decoupled, but you could take a simpler and more intrusive approach and add in a Links collection to your hibernate objects that isn&#039;t persisted. To use aspectj on this over your hibernate objects, would likely lead to complications.

In Step 2, If you are doing really simple links like parent to child etc. you probably could get away with this.

In Step 3, You can scan any parts of your class, scanning annotations is convenient, but you could just as easily scan for particular classes or fields, but once again that is more coupling than the annotation scanning.

In my sample code I had link generation being done by a LinkTemplateProcessor, but maybe you could have a HibernateAssociationProcessor.

Largely it will depend on the links you need to generate and whether or not you can get enough contextual information from your hibernate annotation.
Some links you will want to drill down, others you may want to jump back up to a parent, or even just a particular page for a particular user, like user preferences. 

More specifically when you have links that aren&#039;t in hibernate mapping, how are you going to specify and generate them?

Sure you can insert them directly, probably in your ContainerResponseFilterDumb, it&#039;s just a matter of choice.

Overall, for really simple links, I guess you could probably use Hibernate.
 But for some of the other links, it may just be easier to use the LinkTemplate annotations I&#039;m suggesting.

The ContainerResponseFilterDumb that I&#039;ve implemented, is really shabby and inefficient. Time permitting, I should improve on it, probably  using something like scannotations.sf.net, it may be a good fit.

On a side note, I personally would not advocate using Hibernate for this approach in general as it takes away from the designing of your resources free (kind of) of the constraints of database implementation.

But yes I&#039;m pragmatic enough to understand there are times when you just need to pump stuff out.</description>
		<content:encoded><![CDATA[<p>Although I label &#8220;HATEOAS4legacy&#8221;, the technique isn&#8217;t just for applicable for legacy models nor jaxb annotated models.</p>
<p>This is all about getting a degree of decoupling from your model objects through to your representations aka views. We all know this separation has worked well for us in the past.</p>
<p>You could avoid this separation and implement it in a simpler fashion, but it you would only solve it for a specific problem or set of classes.</p>
<p>There are three main parts of this technique:<br />
 1. Enhance your model objects so  they have a placeholder/collection so you can accumulate links<br />
 2. Annotate your model at interesting members where you want links<br />
 3. In a ContentResponseFilter, scanning for annotations of interest and inserting them into the collection</p>
<p>Step 1, I used aspectj, to keep things decoupled, but you could take a simpler and more intrusive approach and add in a Links collection to your hibernate objects that isn&#8217;t persisted. To use aspectj on this over your hibernate objects, would likely lead to complications.</p>
<p>In Step 2, If you are doing really simple links like parent to child etc. you probably could get away with this.</p>
<p>In Step 3, You can scan any parts of your class, scanning annotations is convenient, but you could just as easily scan for particular classes or fields, but once again that is more coupling than the annotation scanning.</p>
<p>In my sample code I had link generation being done by a LinkTemplateProcessor, but maybe you could have a HibernateAssociationProcessor.</p>
<p>Largely it will depend on the links you need to generate and whether or not you can get enough contextual information from your hibernate annotation.<br />
Some links you will want to drill down, others you may want to jump back up to a parent, or even just a particular page for a particular user, like user preferences. </p>
<p>More specifically when you have links that aren&#8217;t in hibernate mapping, how are you going to specify and generate them?</p>
<p>Sure you can insert them directly, probably in your ContainerResponseFilterDumb, it&#8217;s just a matter of choice.</p>
<p>Overall, for really simple links, I guess you could probably use Hibernate.<br />
 But for some of the other links, it may just be easier to use the LinkTemplate annotations I&#8217;m suggesting.</p>
<p>The ContainerResponseFilterDumb that I&#8217;ve implemented, is really shabby and inefficient. Time permitting, I should improve on it, probably  using something like scannotations.sf.net, it may be a good fit.</p>
<p>On a side note, I personally would not advocate using Hibernate for this approach in general as it takes away from the designing of your resources free (kind of) of the constraints of database implementation.</p>
<p>But yes I&#8217;m pragmatic enough to understand there are times when you just need to pump stuff out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NN</title>
		<link>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/comment-page-1/#comment-109</link>
		<dc:creator>NN</dc:creator>
		<pubDate>Fri, 16 Jan 2009 08:23:30 +0000</pubDate>
		<guid isPermaLink="false">http://brettdargan.com/blog/?p=196#comment-109</guid>
		<description>O.k. so this is for &quot;legacy&quot; models. But what about say hibernate annotated models or models where I can put up my own annotation. Is there any library that achieves an automatic interconnectednes output for jersey?</description>
		<content:encoded><![CDATA[<p>O.k. so this is for &#8220;legacy&#8221; models. But what about say hibernate annotated models or models where I can put up my own annotation. Is there any library that achieves an automatic interconnectednes output for jersey?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

