Three small updates about as(...)
I've previously blogged about the
href="http://weblogs.java.net/blog/fabriziogiudici/archive/2009/11/29/using-standard-ontologies">as(...)
pattern I'm using for my projects. In an email exchange with
href="http://www.oreillynet.com/pub/au/3369">Taylor Cowan,
I've been made aware that
href="http://www.thewebsemantic.com/2008/11/22/47/">Taylor
has been using this pattern since a quite a few time in his
href="http://code.google.com/p/jenabean">JenaBean
project (Jena
is another big player in the world of RDF and Java). A stripped down
pseudocode from his example:
object.as(DCTerms.class).title("thetitle").created("2006-09-07T09:33:30Z");
Have a look at his code since the examples are much more powerful than
the excerpt above.
Second, another exchange with
Tor Norbye (for a completely different topic) made me aware
of an
updated naming convention for Java identifiers containing acronyms.
So, I'm now using SkosConcept
and OwlThing
in place of SKOSConcept
and OWLThing.
Third, my friend Uberto
Barbini suggested me that there's a way to get rid of that
style="font-family: monospace;">.class suffix,
without hoping for a compiler change. If you define such a thing as:
public interface
SkosConcept
{
style="font-family: monospace;">
public final static
Class<SkosConcept> SkosConcept
= SkosConcept.class;
style="font-family: monospace;">
...
}
style="font-family: monospace;">
public
interface GeoCoderEntityProxy
style="font-family: monospace;">
{
style="font-family: monospace;">
public final static Class<GeoCoderEntityProxy>
GeoCoderEntityProxy = GeoCoderEntityProxy.class;
style="font-family: monospace;">
...
}
you can write:
import static
it.tidalwave.semantic.SkosConcept.SkosConcept;
style="font-family: monospace;">
import static
it.tidalwave.geo.location.GeoCoderEntityProxy.GeoCoderEntityProxy;
style="font-family: monospace;">
List<GeoCoderEntityProxy>
list =
object.as(SkosConcept).findNarrowers().ofType(GeoCoderEntityProxy).results();
which is quite readable. The Java compiler is capable of understanding
the difference between a type reference (for instance the
style="font-family: monospace;">GeoCoderEntityProxy
generic parameter in
List<>) and a field reference (such as the
one statically imported). The only thing that you're loosing is that
you won't be able to invoke an hypotethical static method such as
style="font-family: monospace;">GeoCoderEntityProxy.doSomething().
But in most cases I'm dealing with interfaces, so this is not a real
issue.
- Login or register to post comments
- Printer-friendly version
- fabriziogiudici's blog
- 2076 reads






Comments
Lombok
by liquid - 2009-12-04 07:59
I could definitely see a Lombok annotation to help write the constant in the interface