Color Coding Source Files
This upcoming feature about color coding file scopes in IntelliJ IDEA Maia looks awfully lot like a plugin idea I and a colleague had once. We had the idea, that different “layers” or “modules” of the source of an application could be color coded differently inside IDEA. This way, one would have a direct visual indication, if one for instance were editing core domain source or maybe some web layer source.
Nice to see JetBrains are thinking some of the same thoughts, considering we never followed through on our own idea way back.
August 20, 2009
Tags: IDEA Posted in: Tools
No Comments
IDEAs Deep Flex-Mojos Support
If you are writing Flex applications using IntelliJ IDEA, you should also choose the Flexmojos maven plugin for building (if you build with maven, that is) and not the other alternatives. Why? Well, for once, it seems to be the best plugin around for flex building, but also because IDEA has deep support for it.
Currently, with the IDEA8, there is some support for importing POMs that use flexmojos. With the upcoming Maia release, this integration is further enhanced.
In this blogpost, JetBrains explains how to import for POM, and there are some good pointers, that I need to remember for my next POM import. Most notably, enabling the generation of a compiler config file, to have the same settings used by IDEA as flexmojos do at compilation.
August 20, 2009
Tags: flex, flex-mojos, IDEA Posted in: Tools
No Comments
Multiple iPhoto Libraries
Just discovered a cool feature of iPhoto (’08) that I did not know about. It can handle multiple iPhoto libraries.
Due to serious color-related limitations on the display of my wifes laptop, she currently imports her pictures onto my Mac. In addition, my oldest child is taking more and more pictures with her camera, all of which also goes onto my Mac. To avoid “polluting” my own iPhoto library, I wanted to create and manage separate libraries.
It turns out, that if you hold down the Option-key (Alt-key) while starting iPhoto, it will popup a dialog with the options to either create a new library or choose an existing one.
Nice!
August 15, 2009
Tags: iphoto, mac, OSX Posted in: Photography, Tools
One Comment
Tip: Debugging JAXP Internals
In my latest battle with JAXP and Schema validation, I found out a little trick. It turns out, that implementation classes in JAXP use a debug flag to control stdout debugging. And this little flag is initialized from the system property jaxp.debug
So, starting your program, application server, … with -Djaxp.debug=true enables all sorts of initialization/bootstrap debug information, that can be helpful.
June 25, 2009
Tags: jaxp, xml Posted in: Programming
No Comments
JAXP Schema Validation in Java5 and Java6
I have had a little battle with schema validation of XML documents and thought I would share it with the world.
I wrote the below code on Java5, thinking this was a way of validating a piece of XML against a schema definition. And indeed, it does work on Java5:
SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setSchema(sf.newSchema(schemaUrl));
DocumentBuilder parser = dbf.newDocumentBuilder();
parser.parse(new InputSource(new CharArrayReader(xml.toCharArray())));
Only thing is, this does not validate on Java6. In fact, if I install an ErrorHandler on the DocumentBuilder that simply rethrows exceptions, the parsing will complain about the very first attribute it meets, even though the Schema allows it.
It took me a while, to figure out what to do. In the process, I debugged into both Apache and the com.sun…apache packages, to try and find out what was different with parser behaviour on Java6. In the end, it proved really simple. I just hard to learn to actually use the javax.xml.validation API instead. An API made for, … validation. Duuh! Here is the code, that works on both Java5 and Java6:
SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = sf.newSchema(schemaUrl);
Validator validator = schema.newValidator();
Source source = new StreamSource(new CharArrayReader(xml.toCharArray()));
validator.validate(source);
June 25, 2009
Tags: jaxp, schema, validation, xml Posted in: Programming
One Comment
How To Acess Target Object Behind a Spring Proxy
When annotating spring managed beans with stuff like @Transactional, spring will behind the scenes produce code, that ensures that transaction logic is applied before and after your code. Depending on the configuration, this is often done using a JDK proxy, which is a dynamically generated class implementing the bean interfaces. This dynamically generated code will apply its logic and then dispatch the call on to what is called the “target object”, that is, the object that has been proxied.
But sometimes, it would be nice to have direct access to the instance behind the proxy. In my case, it was in a test case, where I wanted to inject one dependency out of many, with a stub implementation. I am using the spring AbstractJpaTests class, which will inject proxied dependencies of beans into my testcase. All the dependencies of the injected, proxied class has also been setup by spring from the context, but I would like to set one specific of them to a stub implementation.
Problem is, the setters for dependency injection is not on the bean interface, and as such, I cannot call them on the bean instance. I also cannot cast it to the implementation class, because in my case, spring is applying the aspect using a JDK proxy, hence it is not the the implementation type, only the interface type.
Here is the code I ended up with for getting the target object:
@SuppressWarnings({"unchecked"})
protected <T> T getTargetObject(Object proxy, Class<T> targetClass) throws Exception {
if (AopUtils.isJdkDynamicProxy(proxy)) {
return (T) ((Advised)proxy).getTargetSource().getTarget();
} else {
return (T) proxy; // expected to be cglib proxy then, which is simply a specialized class
}
}
I found out (by debugger inspection), that the proxy class that spring generates implements Advised, which contains the getTargetSource() method. And on a TargetSource, one can get the actual target. I am not sure if all spring proxies always implement Advised, but it seems to do in my code
I am using the code like this:
@Override
protected void onSetUp() throws Exception {
getTargetObject(fooBean, FooBeanImpl.class).setBarRepository(new MyStubBarRepository());
}
One question: The targetClass parameter on the above getTargetObject method is not used within the method itself. But I cannot find another good way to pass the type paramter into the method. Can you?
Another question: Are there any other good ways, from a test, to inject one dependency on a spring managed bean?
June 5, 2009
Tags: Java, spring Posted in: Programming
6 Comments
Auto-Grabbing Dependencies with Groovy Scripts
Now here’s something cool for your once-in-while, small, groovy sysadmin scripts…
When you write a groovy script, chances are that, when it gets just a little bigger than damn-small, it will require some third party dependencies, to be able to run properly. So, what do you do? You end up either a) package dependent jars in a lib folder and dist as a zip with a script that can build a classpath or, b) re-package all dependencies into one big runnable jar including both dependencies and your not so little script anymore.
But now, there’s “Grab”
@Grab(group='com.ancientprogramming.fixedformat4j', module='fixedformat4j', version='1.2.2')
class Grabber {
Grabber() {
println "Code that is supposed to use fixedformat4j"
}
}
new Grabber()
The “Grabber” class above is an example of a class, which is pretending it needs fixedformat4j in its classpath. When compiled, the groovy compiler will add code to lookup and download the dependencies from some repository (maven, ivy). When run, this generated code is executed, dependencies located and downloaded (if needed), and your script is then executed with access to the downloaded classes/jars.
After trying it out, a little digging around made me discover, that the downloaded dependencies end up in $HOME/.groovy/grapes
Cool?
May 18, 2009
Posted in: Uncategorized
No Comments
Compile Time Meta Programming in Groovy
Today at gr8conf–which by the way is a grait conference–I heard Guillaume LaForge, talk about the new stuff in groovy 1.6. One of those being AST transformations or what they call compile time meta programming.
Through annotations, one is able to tell the compiler to change the code, before it is producing actual byte-code output from the AST. One example is the ever present Singleton “pattern”, which is implemented as an annotation, like this:
@Singleton
public class SingletonTest {
}
new SingletonTest()
When run, this code will produce an exception at runtime, like this:
Caught: java.lang.RuntimeException: Can't instantiate singleton SingletonTest. Use SingletonTest.instance
at SingletonTest.<init>(SingletonMain.groovy)
at SingletonMain.run(SingletonMain.groovy:4)
What happens here is, that the compiler is producing a singleton from SingletonTest, putting a property “instance” on the class, at compile-time.
I guess stuff like this are making the job even harder for IDE developers. Not only do they not get as much type information to work with as with statically typed languages, but also shall they know about meta-programming like this, that changes the code when compiled. The code above does not color red in IDEA (yet).
May 18, 2009
Tags: groovy Posted in: Programming
No Comments
Open RAWs from iPhoto in External Editor
I finally got my Adobe Photoshop Elements for Mac and of course jumped right into iPhoto to try and open an image in the great Camera Raw converter.
First thing to do was to go into iPhoto preferences “General” and set Photoshop Elements as the external editor program. Nice and easy. I then tried to open my photos in external editor and sure enough, photoshop elements opened up, … with the JPEG image
Here is the tip: You need to set the “Use RAW when using external editor” inside iPhoto preferences “Advanced”. Like this pictures shows:
Only thing I need now, is to find out how to make iPhoto notice the edits in Photoshop Elements when I come back. Anyone know how to do that?
May 14, 2009
Tags: elements, iphoto Posted in: Photography, Tools
2 Comments
Oracle, WebLogic and “The Network Adapter could not establish the connection”
Today I battled a periodic error, where my development WebLogic would not start, due to connection problems against the database. It was kinda strange, because other Java tools like DbVisualizer had no trouble. The exception:
Error starting JDBC transaction. Cause: java.sql.SQLException: Io-exeption: The Network Adapter could not establish the connection.
..turned out to lead me in the wrong direction.
I have had these kind of exceptions before, saying “The Network Adapter could not establish the connection”, and it has always been a problem of network connectivity. But this time, it was due to a driver misconfiguration. Or at least, an update of the ojdbc14.jar inside weblogic lib directory made the problem go away.
I do not know which version of ojdbc14.jar that came with my weblogic 8.1, but I dropped a v10.2.0.2.0 there, and it worked.
April 28, 2009
Tags: jdbc, oracle Posted in: Programming
No Comments


