Archive

Archive for the ‘Java’ Category

Adobe XMP Packet Extraction for the Aperture Framework

August 9th, 2009

When it comes to manipulating photographs, I live in Photoshop. One feature of all Adobe products that I like is the ability to annotate images and other documents using their eXtensible Metadata Platform, or XMP. XMP is a collection of RDF statements that get embedded into a document that describe many facets of the document. I’ve always wanted to be able to somehow get that data out of these files and doing something with it for application purposes.

There are projects like Jempbox, which work on manipulating the XMP data but offers no facilities to extract the XMP packet from image files. The Apache XML Graphics Commons is more the ticket I was looking for. The library includes and XMP parser that performs by scanning a files for the XMP header. The approach works quite well and supports pretty much every format supported by the XMP specification. The downside of XML Graphics Commons is that it doesn’t property read all of the RDF statements. Some of the data is skipped or missed completely. To top it off, neither framework allows you to get at the raw RDF data.

What I really wanted to do was to get the XMP packet in its entirety and load it into a triples store like Sesame or Virtuoso. This of course means that you want to have the data available as RDF. Rather than inventing my own framework to do all of this, I found the Aperture Framework. Aperture is simply amazing framework that can extract RDF statements from just about anything. Of course, the one thing that is missing is XMP support. So, I set out on implementing my own Extractor that can suck out the entire XMP packet as RDF. It’s based on the work started in the XML Graphics Commons project, but modified significantly so that it pulls out the RDF data. Once extracted, it’s very easy to store the statements into a triple store and execute SPARQL queries on it.

Right now the, this  XMPExtractor can read XMP from the following formats:

  • JPEG Images (image/jpeg)
  • TIFF Images (image/tiff)
  • Adobe DNG (image/x-adobe-dng)
  • Portable Network Graphic (image/png)
  • PDF (application/pdf)
  • EPS, Postscipt, and Adobe Illustrator files (application/postscript)
  • Quicktime (video/quicktime)
  • AVI (video/x-msvideo)
  • MPEG-4 (video/mp4)
  • MPEG-2 (video/mpeg)
  • MP3 (audio/mpeg)
  • WAV Audio (audio/x-wav)

On the downside, I’ve found that if you use the XMPExtractor with a Crawler, you’ll run into some problems with Adobe Illustrator files. The problem is that the PDFExtractor mistakes these files for PDFs and then fails. But as long as you’re not using Illustrator files, you should be ok. There’s also a few nitpicks with JPEG files and the JpgExtractor in that the sample files included in the XMP SDK are flagged as invalid JPEG files. However, every JPEG file I created from Photoshop and iPhoto seem to work fine. But after a little more testing, I’ll look at offering it up as a contribution to the project.

Semantic Web Icon and Logo Stencil for OmniGraffle

July 21st, 2009

I’ve been doing a lot of diagrams related to some of the projects that I have doing with RDF and other Semantic Web technologies. Rather that cut and paste PNG icons into OmniGraffle, I decided to start putting together a stencil. Here’s what it looks like so far:Semantic Web Icons

It’s not much right now, but I’ll try and keep it up to date as I add more icons from the W3C site and other sources. It should be up on GraffleTopia soon.

Update: And here’s the direct link to the stencil.

Author: Ryan Categories: Java Tags:

Eclipse 3.5RC3 Gives New Life to SWT on OS X

June 12th, 2009

I’ve been a long time user of Eclipse, but also a critic of SWT – the UI toolkit that Eclipse uses. While Eclipse has always been a very productive tool on OS X, SWT has always lagged a bit behind other platforms. But the great thing about Eclipse 3.5, and SWT in general, is that it is now using Cocoa instead of Carbon. Additionally, the SWT guys have paid attention to a lot of little details, such as sheets and Mac-looking drag and drop indicators to name a few. There’s a lot that’s gone into this SWT release that makes me rethink my position on Swing.

One other thing to point out is that the Eclipse 3.5 release candidates are friggin’ snappy as hell. Startup times on all three platforms are very good and responsiveness is simply better overall. This is a release I’m really looking forward to.

Author: Ryan Categories: Java, SWT Tags:

Eclipse on Mac Java 6 Reveals More SWT Shortcomings

November 29th, 2008

Two years ago, I raised a few points about some of the short comings of SWT. Because of it’s native bindings, SWT makes the Java mantra of “write once, run anywhere” quite a bit more daunting. For the most part, SWT’s cross-platform support is actually quite good and it is a decent in terms of performance. And, if weren’t for SWT’s existence, we probably wouldn’t have seen Sun address Swing’s performance issues like they did in Java 6. Unfortunately, when a minority platform like OS X makes some steep architectural changes, SWT-based applications end up with more work on thier hands.

As most folks know, Java 6 on Mac OS X 10.5 was a long time coming. It took Apple over a full year after the initial release of Java 6 to get it running on Mac OS X. Now that it’s here and working pretty much “ok”, I decided it was time to start running Java 6 as my default JVM. Then the surprise: Eclipse won’t run under Java 6 on the Mac. Why? Because Java 6 under Leopard is 64-bit. The current version of SWT on OS X relies on Carbon, which is 32-bit and we won’t be seeing 64-bit Carbon anytime soon. Support for 32-bit Cocoa is planned for later next year, but I didn’t see word on when 64-bit Cocoa or even just Java 6 support might arrive.

Eclipse is still a great IDE even if I have to continue to run it under Java 5. However, this is one of those things that is annoying each time a platform needs to make significant changes. But this time, you can’t put all of the blame on the Eclipse crew. Apple did an absolutely terrible job keeping the Java community abreast of what thier plans were with Java 6. In fact, it almost seemed that Java 6 would never appear on Leaopard. Coupled with the fact that Java 6 was now going to be only 64-bit and Carbon was not goning to see 64-bit support. But long story short, SWT and therefore Eclipse is always going to be hindered by OS changes to a greater degree than say NetBeans or IDEA.

Author: Ryan Categories: Java, Technology Tags: , , , , , ,

Wordpress Update Gone Bad

November 15th, 2008

It’s always annoying to upgrade Wordpress and then to find out 2 days later that all of your links now return a 404 error. All this depsite the fact that it was all working just fine after the update. It turns out there seemed to be some kind of global change my hosting providers mod_rewrite rules which, in turn caused the links to fail. Thankfully, I was able to correct it by adding a revised .htaccess file. It’s trivial but also disturbing seeing as how I didn’t need maintain a separate .htaccess until now.

Author: Ryan Categories: Java Tags:

Better Questions Get Better Answers

November 11th, 2008

Did you ever have that teacher or professor who always tried to tell you that: “there is no such thing as a stupid question?” This may have been true in school, but in a professional software engineering environment, I can confidently tell you there are some really dumb questions being asked. Before I rant on, I’ll qualify this further by saying the majority of these questions are not stupid because people are utter morons, but because people are either completely lazy or don’t know how to compose a question to get the answers they seek.

No doubt business and project management folks ask questions that you may want to categorize as dumb or stupid. However, most of these folks aren’t as technical as you, and the questions maybe hilarious at times. My personal favorite:

“So, do you use pixels because some people don’t have fonts installed on their machines?”

(This one was from a project manger trying to figure out why a web developer used “px” instead on “pt” in CSS). These types of questions from this group are not the targets of this post. That will certainly be the subject of another post.

In this post, I’m focusing on the technical folks who fancy themselves software engineers capable of solving problems. My hope with this post is that people think about the kind of answer they are actually looking for while also considering how their line of questioning is perceived. To help out, I’ve categorized a group of question types that can be categorized as not terribly thoughtful without some qualifiers. Here’s a list of a few:

The “How Do I” Question

No doubt, this is a very popular category of question.  This question can often be valid a number of times especially in absence of adequate documentation. This may be because the API or programming language is new, or you’re working with a homegrown internal framework developed by one guy who has the details all in his head. In these situations, asking: “How do I…?” can be perfectly valid.

However, here are a few cases where it’s not. Take this question for example:

“How do I create a new URL in Java?”

Blink. Blink. A guy with supposedly 6 years Java experience asked me this question 5 years ago and I’m still amazed to this day it was even asked.  You might say that this could be considered a total newbie question and it’s okay. Even so, a newbie should be able to figure out the basics. A little research by Googling “create new URL in Java” would eventually bring you to:

http://java.sun.com/docs/books/tutorial/networking/urls/creatingUrls.html

A two second task and this guy could have snowed us for another day or two. It’s the lack of effort and research know-how that makes the question stupid. You’ve demonstrated that you don’t know what you’re doing and you aren’t capable of solving a trivial problem on your own by performing at least some investigation.

The developer might have been seen in a better light had he made an attempt at searching the docs himself and tried creating a new URL in some type of test case. Had he done that and perhaps asked something like:

“I tried following the docs here, and created a test case to validate my understanding, but I’m not getting the results I had excepted. How do I create a new URL in Java?”

Even though the question is exactly the same, it’s been qualified with some effort. Now I can tell the guy is really trying to figure this out, and more importantly, he wants to solve it but needs a hand. Granted creating a new URL is a weak-ass example, but showing some initiative helps make the question not stupid.

The “Will this Work” Question

It also make my blood boil when I get asked the hypothetical question that goes a little like:

“If I code X and pass it this, will I get Y?”

“Can I create a criteria to query to get this object?”

Here’s a thought: write a damn unit test to validate your question first. Asking, “will this work” without taking a stab at it, demonstrates a severe lack of initiative. What you end up with is a perception of trying to get other people to do your work for you. And that’s what makes this question stupid. Generally, a better what to phrase this is: “I’ve created a test case to pass X through Y, but it failed, and here’s the stack trace.” Now we’ve got something to talk about!

The “Why do I get this error” Question

This question can be absolutely mind boggling sometimes, mainly because you can spend a fraction of a second looking at an error and reading the error message back to a developer just as it was sent to you. My favorite recurring error is with Hibernate apps and some one gets a HibernateException and emails me the stack trace and is “confused” as to why they get the error. Just by scrolling down page to the very end, you can read: “TABLE OR VIEW DOES NOT EXIST.” About 90% of the time, the table name is misspelled in the mappings.

No doubt, sometimes this could be a perfectly valid question and sometimes. But as with all other points in this post, a little research goes a long way. Taking the “TABLE OR VIEW DOES NOT EXIST” error again, while your mapping files may be correct, a DBA may have not provided the developer appropriate grants to the developer. So the question could be rephrased as:

“Why do I get this error? I’ve checked the mapping files and verified the table and column names, but it keeps happening. Any ideas?”

Again, the developers done some digging, but still can’t get to the bottom of it. A developer who’s not thinking about developer grants is not stupid, he may not have considered it and may need a hand at exploring all angles of the problem.

The “What Should I do” Question?

No doubt, you’ve come across the type of problem that seems hopeless and you’re out of ideas. One question that’s generally not a wise one to ask is “What should I do?” A better way to ask such a question would be to have some basic ideas in hand and seek validation. Like:

“hey, I’m stuck on this but I was thinking of trying A and B out to see if that fixes it?”

You’re either going to hear one of three types of responses:

  • “No, that won’t work” or “we don’t have time to do it that way”. Try this approach instead. (If you get a rude response to your idea or get simply shot down without any alternative options, fire up your resume).
  • Yeah, that sound reasonable.
  • Hmm, could work. If doesn’t, maybe try tweaking A with Z and see how that pans out. If that doesn’t work, lets come up with another strategy.

By asking “what should I do” with out any qualifier clearly indicates that you’ve completely given up and you’re not able to take the next step in trying solving your issue. This type of question can be a career-limiting move if asked to your projects team lead or architect. You’ve got to come to the table with at least something moderately intelligent. Otherwise, you’re company definitely paying you more than enough.

No doubt, developers are chronically faced with unrealistic deadlines and given problems that they can’t solve in five minutes. However, if you want to be perceived as a problem-solving engineer type rather that the “I can just bang out code given a spec” programmer type, you need to think about the questions your asking with respect to the answers you want. By providing more context to your question, the quality of of any answer will be greatly improved.

Author: Ryan Categories: Java, Technology Tags:

Hibernate and and the “Found two representations of same collection” error

August 20th, 2008

Last night I spent an extended work day trying to track down the source of a Hibernate exception that I have never encountered before. The application in question is a simple data loader application that reads in an XML file populates a Hibernate object graph. The data in the XML file changes from day to day and if element exists in the XML file one day and not the next, the entity is removed from the object graph. All had been working fine until suddenly I started seeing this in my error logs:


Caused by: org.hibernate.HibernateException: Found two representations of same collection: ...

The odd thing was that there can ever be more than one representation of this collection in the application, so I had wonder WTF? I then came across this thread on the Hibernate Forums, but I wasn’t doing anything with Session.clear(). In fact, we weren’t doing manual session management (i.e. flush, etc.).

To make a long story short, the issue was traced down to mapping error. The object hierarchy is as follows:

parent +
       + Component +
                   + component attribute

The removals were being performed on the component by removing a component attribute the Component.componentAttributes collection. The component attribute maintains a bi-directional relationship with its owning component. However, the mapping for the component attributes parent was as follows:

@NaturalId
@ManyToOne(fetch = FetchType.LAZY,
           cascade = { CascadeType.PERSIST,
                       CascadeType.MERGE,
                       CascadeType.REMOVE })
private Component parentComponent;

Note the CascadeType.REMOVE. This meant that when this child was removed, it’s parent would also be removed, hence the duplicate collection. The issue was resolved once the mapping was changed to:

@NaturalId
@ManyToOne(fetch = FetchType.LAZY,
           cascade = { CascadeType.PERSIST,
                       CascadeType.MERGE })
private Component parentComponent;

Of course this could have been caught sooner had some unit tests been a little better, but the cause of this issue sure was a bitch to find. In end it was a subtle mapping issue that ended up getting introduced and wreaking havoc on my day. Hopefully this post can spare someone else some lost hours.

Author: Ryan Categories: Hibernate, Java, Technology Tags:

My Wife was SOOO Right!

July 6th, 2008

I should know better by now, but the Mrs. has a decent track record of being right. Sometimes. Had I agreed the first time around, we’d have had the right color paint up on the walls this time and we’d be that much closer to getting our loft on the market. As part of my penance and punishment for being wrong, I must inform the internets that my wife was yet again correct the first time and I was SOOOO wrong. You have no idea how wrong. ;) I now must find out how to get this statement up on the Green Monster or at the very least, up on the score board at LeLacheur park. Being wrong sucks :(

Author: Ryan Categories: Java Tags:

RESTEasy and Seam

July 2nd, 2008

There has been some discussion lately regarding integrating JBoss Seam with RESTEasy. Jay Balunas recently made about post on his thoughts on ths subject, so I thought I’d post some of mine. For the record, I am a huge fan of Seam and I think there’s definitely a place for Seam in RESTEasy, so here’s a few of my musing on the subject:

Seam Managed Persistence Contexts

This is a really great feature of Seam and it adds a lot of value to a framework like RESTEasy. If you have a resource that returns a entity that is a complex object graph that will be marshalled to XML, you have a high potential for hitting a LazyInitialzationException. This is especially true if you’re calling a SLSB to get your data because the marshalling process is handled on the web tier, outside of the EJB transaction. If the entity was not fully initialized, your object graph will be incomplete and you will get a LazyInitialzationException. In the initial version of RESTEasy, I used a Seam managed persistence context in order successfully marshall a complex entity using JAXB without getting a LazyInitializationException. I could have written a filter that was similar to the Spring OpenSessionInViewFilter to span the transaction over the entire HTTP request, but Seam made this problem transparently go away in very elegant manner.

Transactions/Conversations

Conversations are one feature of Seam that cause a lot of folks to raise concerns about the stateful nature of the framework in regards to REST. However, I think in some instances, some of the conversational aspects of Seam can be utilized in a RESTful design. Take this thread on the JSR-311 mailing list from Bill regarding Transactions in JAX-RS:

No, I don’t want JAX-RS to have a transaction model :)

One pattern I’ve seen in REST is how they solve distributed
transactions.  The pattern seems to be

/transactions/{tx-id}/.../whatever/your/real/resources/are

So really the transaction resource is allowed to contain any resource
the server supports.  (I hope you are following me, if not I’ll expand).

IMHO, this is something I think Seam could lend a hand with. Taking both Seam’s support for conversations and jBPM, you could conceivably use a long-running conversation to implement such a feature whereby you might end up with something like:

/transactions/{conversation-id}/.../whatever/your/real/resources/are

It’s not a fully baked idea, nor might it be quite the same thing that Bill is talking about. However, it could potentially be RESTful if implemented properly and Seam already provides the plumbing for this out of the box.

Entity Resources

The Seam framework (as in org.jboss.seam.framework), offers a lot of convenience features that make working with JPA and Hibernate a breeze. I had a silly idea a while a back about how to expose entity beans as a resource without the need for a dedicated resource class. The idea wasn’t fully baked (and in hind sight, those details are actually kinda crappy and overly verbose), but the general idea was to make it easy to navigate elements of an object graph. For example, if you were to access the following URI:

http://myhost/contacts/12345

You’d end up with the full object graph as XML for contact ID 12345. If you just wanted to look at one address for that contact, you should be able to call:

http://myhost/contacts/12345/addresses/home

And you would get just the XML element for the contact’s “home” address. What I don’t want to do is create a separate resource class for each element and each collection type in the object graph. You shouldn’t have to create a ContactsResource, ContactResource, AddressesResource, AddressResource, etc. Ideally, you should be able to have one class, or just the entity itself, that can represent the resource. I’m currently working to refine this idea for RESTEasy and much of the Seam framework API could be useful in making this a reality.

I could go on, but I think there’s a lot of value that Seam can bring to RESTEasy.

Author: Ryan Categories: Hibernate, Java, REST, Technology Tags:

Announcing JBoss RESTEasy Beta1

February 25th, 2008

In case you didn’t see Bill’s post on the subject, I wanted to let folks know that RESTEasy entered it’s first beta release as JBoss RESTEasy Beta 1. You can read more here and you can get the release here.

Author: Ryan Categories: Java, REST, Technology Tags:
Buy bed in a bag bedding canopy bedding. Leather furniture furniture furniture sofas. discounted furniture furniture care discount furniture stores furniture showrooms kids furniture buy furniture online buy furniture kitchen furniture furniture shops