James Law’s Joint

flex builder tip

July 28, 2008 · Leave a Comment

I have been using Flex builder on and off for the last 6 months or so, and I thought I’d share something that I (perhaps embarassingly) just realized. I have wasted countless hours of debugging as I didn’t understand an aspect of how flex builder builds the output swf file.

Background:

When you create a flex builder project, you create what adobe calls “applications”. These are usually in the form of .mxml files. Simple applications might have all their code in the .mxml itself. More complicated applications might augment this application.mxml file with a number of plain actionscript classes. For instance, if you’re using an flex MVC framework like parsley, cairngorm, pureMVC.

All artifacts declared an “application” or a “module” become a .swf file. The .swf has all the mxml, actionscript, and other resources to run within the adobe flash player.

So?

So what you say?

The flex builder compiler (I believe it is using mxmlc behind the scenes) only includes files that are reachable from what is declared as an application.

In the above image, you can see my application.mxml file. This seems to drive the flex builder compilation process.

Only actionscript classes that have a declaration will be included in the output swf file. This is probably done to minimize the size of the swf, which makes load times lower.

If you come from a java/eclipse background, you expect anything labeled source to get built. This is simply not the case with FlexBuilder. The only things that get built are those applications/modules that its been told to, and any actionscript that is reachable from them.

Why this matters?

If you’re using remoting (blaze ds), or using DI, it is likely your application may NOT have direct references to your action script classes. Thus, in the case of remoting, you may find your objects are not being deserialized to the appropriate AS3 class on the client, but you won’t know why.

How to fix:

One way is to put a variable declaration for each class inside your application class. If someone has a better way please let me know via comments. I’ve searched for hours in google land to no avail.

PS> Is there a free swf decompiler out there? So I can see what is actually being put into my swf files?

→ Leave a CommentCategories: Uncategorized

SpringSource and Adobe – A match from heaven!

June 20, 2008 · 3 Comments

This week our development teams were in training by SpringSource. For some reason I blurted out to the trainer that SpringSource should get cozy with Adobe. It was an off hand remark, but the more I think about it, the more I think it is a good partnership for both parties.

First some background: I have been involved in J2EE development for about 10 years, and lately have had a lot of concerns about the platform. Language is languishing, J2EE is way too complicated, SUN is empty, etc. I also work for a conservative IT department which isn’t going to jump head first into say- hosting our apps on the google platform, or amazon, or start writing apps in python or ruby- as cool as these ideas and languages are.

In my opinion, organizations like mine, writing applications within a large enterprise, the choice is typically Microsoft or Java. One unfortuneate aspect to the java platform at this point in time is the lack of cohesive commercial vendor support. Risk averse companies hate the idea of coordinating with multiple vendors to get support. There are moments where because of this, I actually dream about doing .net. Not because c# 3.x is cool (it is), but I wouldn’t have to deal with the bickering of the java developers as to the best way of doing something from the (far) too many options, but mostly because our organization can’t negotiate support with 20 vendors of all those cool open source jars out there. In many ways Java is the new Unix.

So why should SpringSource and Adobe join forces? First, why might it be good for ME, the developer in Corporate IT:

Spring provides 90% of the glue code I need on the java platform. By using spring to its fullest, you won’t find developers working on “frameworks” or utilities, instead, they are usually, after some training, able to actual concentrate on the business domain and its problem space. I have been successful in implementing nearly 10 medium -large size applications in the last 4 years, and I attribute most of this to the fact that Spring simply “took out the trash”. (Credits should go to Hibernate and others for the underlying technology of course)

Because of this experience, I see SpringSource as being a serious workhorse of corporate IT shops. It certainly is not limited to that, but it is a good fit.

Adobe on the other hand, does not really know how to sell and do corporate IT. I have used flex a enough to know a little about this. I don’t know if this is because there are HTML designers running the show instead of software guys, but they can miss some of the real basics. For instance, take BLAZE DS, their open source connector stuff that allows a java developer to easily connect java object back end to a flex/flash front end. The distribution is shipped as a sample war file with a bunch of sample web applications. Their idea is I’m going to deploy MY CODE to their web app. This is foolish, and would turn away a huge swath of java developers that are used to a jar file with some instructions, or perhaps some MAVEN pom’s. A serious J2EE shop isn’t going to use your tooling if their is a sample application WAR file as its main distribution.

After some time, I figured out the actual architecture and added the flex servlet (they call it the messagebrokerservlet) to my existing J2EE application. Actually, their underlying technology is pretty good. Flex is great, and from a corporate development perspective is nearly perfect: Deployment (easy), coding (Actionscript, easy), WebBased distribution… well, flash is excellent for UI development, and certainly easier than the alternative (AJAX+ ?)

However, I do think Adobe is trying to get better at servicing “enterprise” customers. A few months ago Adobe was doing some internal re-org to make an entire section of the company aligned with selling to organizations like where I work. I read their 10k financial reports , as I was considering purchasing their stock after seeing their amazing forms stuff. The reports do seem to point toward a more directed mission to selling to folks like us.

Thus, I see Adobe as needing Spring Source as they know how to sell to corporate IT. They have millions of downloads, and presumably thousands of enterprise IT customers in consulting, training, and support. They write software that developers love, business folks should love (if they knew software). In addition, SPringSource knows how todo the details to deliver to the dev community: packaging, deployment, excellent documentation.

SpringSource also has huge J2EE “street cred” and mindshare. Adobe is not a company an IT shop thinks of when it thinks of solutions. SpringSource and serious java platform support would be a huge asset to Adobe.

So what could this partnership bring to SpringSource?

The java platform has no shortage of UI frameworks, none really making it easy for developers to build a world class UI. JSF is ubsurdly complex, and still falls short of usability expectations, even with 3 layers of added glue (Ajax, seam, Spring Webflow). SpringSource has helped integrate many java based UI frameworks, but has yet to pick a serious “RIA” platform to integrate with. Working with Adobe would bring the support of the top RIA platform. (Silverlight and JavaFX are still years away from being on PAR).

Another concern with SpringSource is the buyout scenario. Eventually someone WILL buy them. Their VC’s will want a return on investment. Oracle, IBM, and many others would be nasty partners that would inevitably lead to eventual brain drain. I think Adobe’s lack of overlapping technology would NOT lead to the negatives that others might. Widespread panic by spring developers would not take place. Sure they would wonder why the photoshop guys would want them, but they would come around.

Back to the enterprise IT shop. I get one stop shopping. Spring AS, with Spring Framework, bundled support with the UI needs for the data entry apps from adobe. Sounds good doesn’t it?

What do you think?

→ 3 CommentsCategories: Uncategorized

Injecting Spring Beans into Domain Model

June 18, 2008 · 1 Comment

I’ve had this challenge on my tasklist as a developer for some time now. If you are inclined to do “Domain model” programing and avoid the “Anemic Domain” model and you use Spring and HIbernate than hopefully this may help.

Problem:

Spring is great at doing DI with all your service and DAO classes, but in its standard usage which uses proxies provided by the JDK or by CGLib, it has no control over creation of Domain Model objects. In a typical J2ee application Domain Objects are, of course, loaded via Hibernate, IBatis, or perhaps even JDBC.

I have found that to a large degree, I can eliminate a huge amount of code in “service” classes by depending largely Hibernate’s ability to lazily load parts of the object graph (assuming good DB design, and well mapped entity relations), as well as its “tranparent persistence” features. In other words, when I need to make changes, just change the domain objects by loading a single domain object, and change related objects via navigation. For example:

Order.addItem(Item item)
{
//bus logic here
items.add(item);
}

This works well, assuming everything comes out of a database, but here are some cases where something else is needed:

  • You’d like transient summary total information in domain objects (Perhaps a “Account” object with a sum total generated manually via a DAO and JDBC
  • There’s a vendor API that needs to be linked in as part of your domain model is being outsourced or SASSed
  • Other infrastructure services (Email, notification come to mind)
  • Maybe you just like RAILS approach of having finders on the domain object

While I am not inclined to use this for 3,4, I do think the other cases result in some kludgy workarounds.

HOW-TO

First, you’ll need some background from the spring folks. Read this section:

http://static.springframework.org/spring/docs/2.0.x/reference/aop.html#aop-atconfigurable

After reading this you should realize there are 2 options. Use the load time weaver, or an ant task. I have tried the loadtimeweaver (LTW) in the past, and while it works, I have ruled it out for a few reasons mainly:

1. For automated “integration” type of tests, adding javaagent stuff everytime I need to run a test inside eclipse seems like a serious pain

2. Coordination with the folks that run with the application servers

3. And it seemed slow when I tried it many months ago (added 20 or so seconds to tomcat load time for our project)

So, IF youre still with me and want to use the ant task to achieve this goal, here’s my list:

Set-up your bean container with the magic:

Add the following to your spring xml files:

<!--  allows domain objects to get configured via @Configurable -->
<context:spring-configured/>

My understanding is that this causes a reference to the spring container to be made available to the ASPECTS provided by spring.

Add spring-aspects-2.5.x to your project

If you haven’t already, the buildpath must include this jar, as it contains the Aspect that is needed. In particular, the Aspect is an “AnnotationBeanConfigurerAspect”. This aspect will get applied to the Domain Objects.

Grab aspectJ anttools

Download these, then run the jar to extract the package (I used v1.53)

From the installed aspectJ Tools, take note of the jar inside it: aspectjtools.jar. This has the ant task. Put it whever you put your ant tasks.

Make sure aspectjrt-xx is in your buildpath

I am fairly certain this is a required jar for spring so its probably already on the project classpath. If you don’t, then add it

Make an ant build for aspectj

Now the hard part. It took some time for me to figure this out, as IMO it has way too many options and should have more tasks with less options, but thats probably my lack of aspectj knowledge …

Anyway, here’s my ant build (stripped down some)

<project name="aspectBuild" >
<!-- need to tell ant where the aspectj tooling jar is -->
  <taskdef
      resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
    <classpath>
      <pathelement location="aspectjtools.jar"/>
    </classpath>
  </taskdef>
<!-- the path to the aspects already created by the Spring dudes -->
<path id="aspect.path">
		<pathelement location ="spring-aspects-2.5.jar" />
</path>
<!-- the projects buildpath -->
<path id="classpath.path">
<fileset dir="build/lib">
<include name="**/*.jar" />
</fileset>
</path>
<!-- here, I'm using the output dir as both the input (where are the .class files)
but also where to put the instrumeneted files as well -->
<path id="output.path" >
	<pathelement location="../classes"/>
</path>

<target name="compile" >
    <iajc verbose="true"
    inpathref="output.path"
    	aspectpathref="aspect.path"
    	classpathRef ="classpath.path"
    	destdir="../classes"
    />
  </target>
</project>

For further info on the ant task, try here.

After creation of the ant task, if you’re using eclipse, you can automate the running of the ant task

with every complile via project properties- “builders”. Very handy

If for some reason you don’t need to automate builds, and you use eclipse, the ant stuff can be eliminated by using aspectj eclipse tooling. Pretty easy so I’ll just summarize quickly:

  • “aspectJ” enable the eclipse project after installing ajdt tooling
  • under project-aspectjbuild, go to “aspectpath” and give it the spring-aspects.xx jar
  • Done!

TODO:

Find out how to do incremental instrumentation

Next week:

Instrumentation tasks for HIbernate and Terracotta

→ 1 CommentCategories: Uncategorized
Tagged: , , ,

link blog 6_9_2008

June 9, 2008 · Leave a Comment

InfoQ: Does My Bus Look Big in This?
http://www.infoq.com/presentations/soa-without-esb

Martin Fowler and other thoughtworks guy on the evil of middleware stacks. Funny presentation. Light on alternatives though.

JavaScript Closures for Dummies | Developing thoughts — Morris Johns
http://blog.morrisjohns.com/javascript_closures_for_dummies.html

Practical explanation for closures, in this case in javascript

Ted On Flex: Flex 3 – Thursday: Dramatically Smaller Flex SWF Files
http://www.onflex.org/ted/2007/06/flex-3-thursday-dramatically-smaller.php

One thing the ajax guys like to say about flex/flash is files are too big. Looks like next player will make this no longer the case.

Look Out Oracle: MapReduce Might Be Able To Do JOINs | Bex Huff
http://bexhuff.com/2008/06/look-out-oracle-mapreduce-might-be-able-to-do-joins
Oracle's clock is ticking…?

Technology Architecture & Projects: Enterprise Architecture: A Joke, A Failure…or an Opportunity?

http://enterprisearchitect.typepad.com/ea/2008/06/interesting-dis.html


Enterprise Architecture: A Joke, A Failure…or an Opportunity?


→ Leave a CommentCategories: Uncategorized

linkblog 1

May 2, 2008 · Leave a Comment

springsource ide plugin coolness link

jcs cache aop with spring link

json options with java link

test coverage tool for flex link

→ Leave a CommentCategories: Uncategorized

Hello world!

May 2, 2008 · Leave a Comment

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

→ Leave a CommentCategories: Uncategorized