Software Design

Wednesday, June 18, 2008

URI Templates in JAX-RS

The JAX-RS - The Java API for RESTful Web Services JSR has much potential -- it's always refreshing to see innovative APIs. As an improvement to the @Path and @PathParams annotations, I think we can strengthen the grantees of how URI templates are managed and defined. As always, I follow the conviction that an API-proposal needs to fit on one piece of page. So let me contrast JAX-RS' current design with a DRY approach by providing an example. I propose a distinct unit (here ResourceURI) which know about the internal URI contract requirements.

In code,
/**
* Abstraction for a URI template.
*/
@Path("{path}/{urn}")
CoolResourceURI implements ResourceURI {

@Variable("path")
private final String path;

@Variable("urn", "urn:\\.*")
private final URI urn;

getPath() {
return path;
}

getURN() {
return urn;
}

...
}
/**
* Associate a {@code CoolResource} with the {@code CoolResourceURI} contract.
*/

class CoolResource implements Resource<CoolResourceURI>.Get {

/**
* Handle {@code GET} HTTP/1.1 request for resources that map to {path}/{urn}
*
* @see Resource<T extends ResourceURI>.Get#get(T)
*/

get(CoolResourceURI uri) {
// do something with the URI components
// Ex: "/some/path/urn:cool:cow"
// --> path="/some/path", urn="urn:cool:cow"
...(uri.getPath(), uri.getURN());
}

...
}

Notice how this different design strategy would strengthen the weakly-typed approach that we currently see in the JSR draft. I tried to demonstrate an improvement to the API by showing REST components that use ResourceURIs (see CoolResourceURI) as a means to encapsulate the URI contract to which the REST service must adhere. This is what we would expect from a DRY design.

Also note how the get(CoolResourceURI) is a type-strong and an expressive way of saying that only GET HTTP/1.1 requests for a specific URI contract should be fulfilled. I would expect this design to simplify the JAX-RS implementation because all URI parsing logic would be directed by the annotations found in the ResourceURI class (i.e. CoolResourceURI).

Friday, November 03, 2006

Radiant "Corex" Branch Merges With Official Branch.

For several months I have been working with John W Long on Radiant. In order to introduce several improvements to the content management system I had had created a branch called "corex." The core features of my branch have been now successfully merged back into the official developer tree. There are a couple outstanding features that didn't make it but overall I am very satisfied with the outcome. Notably, "corex" marked a major milestone in the project architecture. Foremost, the new tagging system supports modularization and polymorphism and models several key features of ASP.NET 2.0 server controls. Another improvement is a the redesign of the dynamic page database model. I strongly feel the Radiant developer team is very progressive and the core developers have a positive attitude toward change. Each team member contributes with a different skill set and it is good to see the project grow. It's a nice piece of software.

Friday, October 06, 2006

Radiant "Corex" Branch

If you are a core Radiant developer or you have been following the mailing list you have noticed the new "corex" branch. The goal of this branch is to improve the design of the software and to address certain shortcomings identified in Sepember. All the improvements are driven by unit tests. Here is the list of changes I have made to the software so far till revision 144:

1) Eliminate nested tag blocks, simplify internal architecture of the tag system.

class MyPage < Page

define_tag 'my_tag' do |tag|
...
end

define_tag 'your_tag' do |tag|
...
end

end

2) Move basic tags from PageContext to the Page class using the new tag system.

class Page

define_tag 'children:each' do |tag|
...
end
...

end

3) Exclude extraneous software components as plugins and develop more cohesive software core. As of revision 139 the following features have been excluded from the core and replaced by generic core unit tests:

* Archiver pages
* Test filters

4) Build Setup::Base class to intergrate setup scripts and database migrations

5) Ensure unit tests are generic as opposed to tailored to specific page types.

6) With revision 142 tags are inheritable.

class YourPage < Page

define_tag 'hello' do

'Hello world'
end

end

class MyPage < YourPage

define_tag 'hello' do

super + '!!!'
end


end

Tuesday, September 26, 2006

Radiant Development

After contributions and collaboration with a new open-source community I have recently become part of the core developer team for the Ruby on Rails content management system called Radiant. Radiant powers, for instance, the official Ruby website. With the development of a search plugin I had a chance to identify strengths and weaknesses of the current Radiant software plugin system. Within Radiant, plug-ins are a collection of several modules that need to work together in order to hook into the application.

Generally (well-desinged) standalone web applications follow the Model-View-Controller paradigm. The current Radiant Plugin System however does not compartmentalize a single plugin into independent or semi-independent pieces. Instead, for example, the HTML render logic and other data or control constructs form one class that is currently referred to as "behaviors." Shortcoming of this design include: missing access to the web frameworkÂ’s HTML render methods, code duplication, and a highly tangled knot of message delegations.

In order to address this issue I have been working with John W Long and other developers on planning the design of a new architecture that allows us to extend and improve the existing plugin system. I have spent some time coming up with an implementation of a proof-of-concept. However the new code clearly suggests that we would need to introduce major changes to the core software if we would decide to peruse this direction. However the new architecture features a much improved inheritance model that eliminates a majority of the delegations between objects. I have pushed for this class design because I have had good experience with it when I was developing Hieraki (documentation publishing software). It simplifies matters a lot. The goal always is simplicity over complexity.


John expressed concerns though that the new design might actually be more what we need. We both also sense that the underlying problem is due to the traditional MVC layout. By that I mean MVC is at most ambiguous for a content management system because dynamic page creation is such an integral part of the software. Further investigation is required before I will be able to put my finger on "what is wrong" with MVC and Radiant. But I am confident we will be able to find a solution that fits our needs and addresses the shortcoming of the current system.