03.18.10

Setting Resource[] Array properties in Spring

Posted in Programming at 5:09 pm by regolith

Had to do this recently… I wanted to generate a bunch of sqlMapConfig.xml files and have Spring load them into my SqlMapClient for me. SqlMapClientFactoryBean has a property called configLocations that takes an array of Resources, so I knew it was possible somehow. I didn’t expect it to be so easy, since this wasn’t mentioned in the Resources section of the Spring docs, so I started trying to figure out how to make a parent of my bean and then merge the two lists… But since Spring 1.2.7, you can pass a list of resources with wildcards as the value of a Resource[] property and it will resolve them correctly for you!


<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocations">
        <list>
            <value>classpath:com/instantobscurity/db/dao/support/sqlMapConfig-*.xml</value>
            <value>classpath:com/instantobscurity/db/dao/oracle/sqlMapConfigOracle.xml
        </list>
    </property>
</bean>

12.05.09

In Java: Use a static inner class as a ServletContextListener or HttpSessionListener

Posted in Uncategorized at 12:51 pm by regolith

I tried to use a static inner class as a listener in my web.xml:

<listener>
    <listener-class>com.xyz.servlet.DropboxServlet.CleanupListener</listener-class>
</listener>

but I kept getting:

2009-12-05 12:15:47.554:WARN::Could not instantiate listener com.xyz.servlet.DropboxServlet.CleanupListener
java.lang.ClassNotFoundException: com.xyz.servlet.DropboxServlet.CleanupListener

Finally, I found a hint in the Spring Manual (talking about something unrelated to J2EE) that said you needed to use the “binary” class name to instantiate a bean for a static inner class, meaning using a “$” instead of “.” to separate the inner-class from its outer-class. So now this works:

<listener>
    <listener-class>com.xyz.servlet.DropboxServlet$CleanupListener</listener-class>
</listener>

08.04.09

In Java, Access an Outer Class’s superclass methods from an Inner Class

Posted in Uncategorized at 2:05 pm by regolith

This java code makes an asynchronous call and, in the handler, calls its superclass’s doIt() method using the form ClassName.(this|super).methodName()

class OuterClass extends OuterSuperclass {
  @Override
  public void doIt() {
    // Checks something asynchronously and calls the handler when done
    ExtraThingService.checkIt(new CheckItHandler() {
      public void okToDoIt() {
        OuterClass.super.doIt();
      }
    });
  }
}

07.14.09

Git Magic

Posted in Uncategorized at 8:59 am by regolith

At work, I’ve been doing a project that’s not part of our standard codebase, so I’ve been taking it as an opportunity to learn jQuery and git. This is the most helpful git tutorial I’ve used: Git Magic.

07.13.09

Cheat sheet for jQuery

Posted in Uncategorized at 5:46 pm by regolith

I’ve been learning jQuery lately, for a project at work, and now that i’ve become pretty used to it, I still keep glancing at the api web site. I just remembered that they have such things as cheat sheets, so I found this one. Seems helpful, though I guess I still need a one-line description for those functions I don’t have intimate knowledge of.

[http://acodingfool.typepad.com/blog/jquery-13-cheat-sheet.html]