ラベル DI の投稿を表示しています。 すべての投稿を表示
ラベル DI の投稿を表示しています。 すべての投稿を表示

2011年12月20日火曜日

Spring 3.1 の Cache Abstraction

Spring 3.1 が GA になった。最後に Spring を触ったのはこれを書いたときだから、もう2年近く前になるけど、こんときは 3.0 が出た頃だった。あんまり進んでなかったのかも。

いろいろググってみると、キャッシュがどうかしたとか書いてあるので、寝る前にちょっと試してみる。

package spring.trial1.ex1;

import java.util.HashMap;
import java.util.Map;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

class Bar {
   Map<Integer, String> map = new HashMap<>();
   {
      map.put(1, "one");
      map.put(2, "two");
   }
   @Cacheable("bar")
   public String findString(int key) {
      System.out.printf("findString(%d) called%n", key);
      return map.get(key);
   }
}

public class Foo {
   public static void main(String[] args) {
   ApplicationContext ctx = new ClassPathXmlApplicationContext(
         "applicationContext.xml");
   Bar bean = ctx.getBean(Bar.class);

   System.out.println(bean.findString(1));
   System.out.println(bean.findString(2));
   System.out.println(bean.findString(3));
   System.out.println(bean.findString(1));
   System.out.println(bean.findString(2));
   System.out.println(bean.findString(3));
   }
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache"
  xmlns:p="http://www.springframework.org/schema/p"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
  <cache:annotation-driven />

  <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
    <property name="caches">
      <set>
        <bean
          class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
          p:name="bar" />
      </set>
    </property>
  </bean>
  <bean id="bar" class="spring.trial1.ex1.Bar"/>
</beans>
pom.xml の dependency に spring-context 3.1.0.RELEASE と、cglib 2.2.2 を指定して、ビルド→実行したら、以下のような結果が得られる。 (既に Maven Central に入ってるらしく、特に repository を指定したり、ローカルリポジトリに入れたりとかしなくても、普通に 3.1 がダウンロードされる。)
findString(1) called
one
findString(2) called
two
findString(3) called
null
one
two
null

findString の 中身が呼ばれるのは最初だけで、2回め以降はキャッシュが使われているらしいのが分かる。

■ 雑感

JavaConfig/JSR-330 で xml を書かずに済むようになったと思ってたけど、この <cache:annotation-driven> に関しては、やり方が分からない。

仕方なく、昔ながらのapplicationContext.xml を書いてしまった。もしかすると、ちゃんとしたやり方があるのかもしれないけど、部分的にアノテーションで部分的にXMLみたいにマジでなるとしたら、結構イヤかも。

2010年1月16日土曜日

Spring 3.0 REST/JAXB

Spring 3.0 の REST を試してみた。

■ やること
Spring 3.0 で REST がサポートされたというのでやってみる。ただし、余りサンプルを見かけない PUT をやってみる。あとJAXB のバインディングのやり方も確認しておきたい。

以下のような、なんちゃって仕様を実装する。

  • http://localhost:8888/hello-rest 以下にリソース Foo がある
  • Foo は id で識別され、プロパティを name 持つ。
  • たとえば、id=100 の リソース Foo をリクエストの内容で更新する操作は以下のようになる
    URLhttp://localhost:8888/hello-rest/foo/id/100
    methodPUT
    内容<foo><name>hoge</name></foo>
  • 実際にリソース更新する変わりに、操作の内容を標準出力に書き出す

■ 使うもの

  • Eclipse 3.5 Galileo + WTP + m2eclipse
  • Maven 2.2.1
  • Tomcat v6.0

■ サーバ

  • Java Project を作って、Dynamic Web Project 且つ Maven Project にする。
  • POM には 以下の依存を記述
    groupIdartifactIdversion
    org.springframeworkspring-webmvc3.0.0.RELEASE
    org.springframeworkspring-oxm3.0.0.RELEASE
    javax.servletservlet-api2.5
  • リソース Foo は以下のようなクラスで表現する(以下、パッケージはどれも springmvc.web とした)
    @XmlRootElement
    public class Foo {
       String name = "";
       public Foo() {}
       public Foo(String name) { this.name = name; }
       public void setName(String name) { this.name = name; }
       public String getName() { return name; }
    }
  • コントローラはこんな風になる。
    @Controller
    @RequestMapping("/foo")
    public class FooController {
       @RequestMapping(
             value = "/id/{fooId}", method = RequestMethod.PUT)
       public View handle(
             @RequestBody Foo foo, 
             @PathVariable int fooId) throws IOException {
          System.out.printf(
                "name of Foo(id=%d)  --> %s%n",
                fooId, foo.getName());
          return new StatusOK();
       }
    }
  • StatusOK はこんなふうにした。(合ってるかどうか、ちょい不安)
    class StatusOK implements View {
       public String getContentType() { return null; }
       public void render(Map model, HttpServletRequest request,
             HttpServletResponse response) throws Exception {
          response.setStatus(200);
       }
    }
  • これらのクラスをこんな設定ファイルで協調させる。
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
       <context:component-scan base-package="springmvc.web" />
       <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
          <property name="messageConverters">
             <list>
                <bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
                   <property name="unmarshaller" ref="restXmlMarshaller" />
                </bean>
             </list>
          </property>
       </bean>
       <bean id="restXmlMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
          <property name="contextPaths">
             <list><value>springmvc.web</value></list>
          </property>
       </bean>
    </beans>
  • web.xml はほぼ自明なので省略。ただし DispatcherServlet の url-pattern は "/" とする。
  • Foo.java と同じフォルダに jaxb.index ファイルを置く。中身は単に、一言 Foo とだけ書く。
できたら、Tomcat サーバに hello-rest プロジェクトを[Add] して、エラー無くデプロイされる事を確認。

■ クライアント
クライアント用の Java プロジェクトを作って、

  • Build Path に サーバ側プロジェクトへの依存も含め、
  • POM で org.springframework の spring-webmvc の 3.0.0.RELEASE への依存を指定する
クライアントはこんなコードにする。
public class App {
   public static void main(String[] args) {
      final String uri = "http://localhost:8888/hello-rest/foo/id/100";
      RestTemplate template = new RestTemplate();
      template.put(uri, new Foo("hoge"));
   }
}
POM の<dependencies>には org.springframework の spring-webmvc の 3.0.0.RELEASE だけ指定. また、Build Path に サーバ側プロジェクトへの依存も含めておく。

実行すると、サーバ側のConsole ビューに "name of Foo(id=100) --> hoge" と 表示される。

ちなみに TCPMon で見るとこんな感じ

request
PUT /hello-rest/foo/id/100 HTTP/1.1
Content-Type: application/xml
User-Agent: Java/1.6.0_13
Host: 127.0.0.1:8888
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 83

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   <foo>
      <name>hoge</name>
   </foo>
response
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Language: ja-JP
Content-Length: 0
Date: Thu, 14 Jan 2010 13:18:45 GMT

■ 参考サイト
この辺り

  • http://www.developer.com/java/web/article.php/10935_3854986_2/Get-RESTful-with-Spring-30.htm
  • http://grzegorzborkowski.blogspot.com/2009/03/test-drive-of-spring-30-m2-rest-support.html

2010年1月14日木曜日

Spring 3.0 MVC

Spring 3.0 の Spring MVC を Eclipse で試してみる。

■ 前提

  • ローカルの Maven リポジトリに Spring 3.0 のjar が登録済み[参考]。
  • Eclipse に WTP と m2eclipse がインストール済み。
  • Tomcat v6.0 がServer および Server Runtime として構成済み。

■ 構築

  • Java プロジェクト "hello-spring"を作って、これを Maven Project にして、さらに Dynamic Web Project にもする
  • POM に以下を追加する
    groupIdorg.springframework
    artifactIdspring-webmvc
    version3.0.0.RELEASE
    groupIdjavax.servlet
    artifactIdjstl
    version1.2
  • src/main/webapp/jsp/下に hello.jsp を作成する
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <html><body><p>${msg}</p></body></html>
  • WEB-INF 下の web.xml を編集
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4"
          xmlns="http://java.sun.com/xml/ns/j2ee" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
          http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
       <servlet>
          <servlet-name>springmvc</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          <load-on-startup>1</load-on-startup>
       </servlet>
       <servlet-mapping>
          <servlet-name>springmvc</servlet-name>
          <url-pattern>/</url-pattern>
       </servlet-mapping>
    </web-app>
  • src/main/webapp/WEB-INF/下 に springmvc-servlet.xmlを作成 context:component-scan の記述により、@Contoller の付いたクラスがコントローラとして扱われるようになる。
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
       <context:component-scan base-package="studies.spring30mvc" />
       <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="viewClass"
             value="org.springframework.web.servlet.view.JstlView" />
          <property name="prefix" value="/jsp/" />
          <property name="suffix" value=".jsp" />
       </bean>
    </beans>
  • 以下のようなコントローラクラスを作成
    package studies.spring30mvc;
     
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    @RequestMapping("/hello")
    public class HelloWorldController {
     
       @RequestMapping("/{who}")
       public String handle(@PathVariable String who, Model model) {
          model.addAttribute("msg", String.format("Hello, %s!", who));
          return "hello";
       }
    }

■ 実行

  • Servers ビューからTomcat を起動
  • hello-spring プロジェクトを [Add]
  • ブラウザで http://localhost:8080/hello-spring/hello/spring30 を見るとHello, spring30!と表示される
  • URL の hello の後ろを変えたらメッセージも変わる

Spring 3.0/SpEL

Spring 3.0 の SpEL のドキュメントを読んでみた。

Collection の扱いがちょっと面白い。集合の選択と射影がサポートされている。

サンプルに無かったので、プリミティブ型の配列でどうなるか試してみたら、入力としては OKだけど、出力で Integer[] に変換される様子。また Collection 操作をつなげることもできた。

public class App2 {
   public static void print(Object result) {
      System.out.println(Arrays.toString((Integer[])result));
   }
   public static void main(String[] args) {
      ExpressionParser parser = new SpelExpressionParser();

      Expression even = parser.parseExpression(
         "#root.?[0 == #this % 2]");
      Expression doub1e= parser.parseExpression(
         "#root.![#this * 2].?[#this > 5]");

      int[] ints = {1, 2, 3, 4};
      print(even.getValue(ints));
      print(doub1e.getValue(ints));
   }
}

こんな出力が出た
[2, 4]
[6, 8]

あと、Groovy から、Elvis 演算子という三項演算子の短縮形を取り込んだらしい。
 null!=a ? a: b  a ?: b 
名前の由来はプレスリーの髪型とのこと。Groovy 界隈ではだいぶ前からあったらしいが、不勉強で知らなかった。

Spring 3.0/JSR-330/JavaConfig

Spring 3.0 の JSR-330 と JavaConfig をちょっとだけ試してみた。

====

以下のような2クラスを考える。
  ┌───────┐                ┌─────┐
  │   Greeter    │ 《dependency》 │ Greeting │
  │==============│--------------->│==========│
  │greet(person) │                │getWord() │
  └───────┘                └─────┘
ここで
  • Greeting.getWord() メソッドは、挨拶の言葉を返す。
  • Greeter.greet() メソッドは、Greeting.getWord() で取得した挨拶の言葉に、引数 person を連結して返す。
これを Spring 3.0 で書いてみる。 Greeter と Greeting を Spring 管理下に置くための設定は、従来、XML ファイルで書いていたが、GUICE みたいに Java で書けるようになった。
@Configuration
public class AppConfig {
   @Bean public Greeter greeter() {
      return new Greeter();
   }
   @Bean public Greeting greeting() {
      return new Greeting();
   }
}
Greeter は以下のようになる。Greeting への依存は @Inject で表現する。
public class Greeter {
   @Inject
   private Greeting greeting;
   public String greet(String person) {
      return String.format("%s, %s!", greeting.getWord(), person);
   }
}
Greeting は、まあ適当
public class Greeting {
   public String getWord() { return "Hello"; }
}
こんなコードで実行すると、
public class App {
   public static void main(String[] args) {
      ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
      Greeter bean = ctx.getBean(Greeter.class);

      System.out.println(bean.greet("Spring3.0"));
   }
}
以下のような出力を得る
Hello, Spring3.0!
■ Eclipse で動かすには
  • Spring3.0 の dist 下の jar 群をローカル Maven リポジトリに登録する.[参考]
  • javax.inject も リポジトリに登録。[download]
    mvn install:install-file \
    -DgroupId=javax.inject \
    -DartifactId=com.springsource.javax.inject -Dversion=1.0.0 \
    -Dsources=com.springsource.javax.inject-sources-1.0.0.jar \
    -Dfile=com.springsource.javax.inject-1.0.0.jar \
    -Dpackaging=jar -DgeneratePom=true
  • Eclipse で Maven Project を作成する
  • pom に以下の依存を指定
    groupIdorg.springframework
    artifactIdspring-context
    version3.0.0.RELEASE
    groupIdcglib
    artifactIdcglib
    version2.2
    groupIdjavax.inject
    artifactIdcom.springsource.javax.inject
    version1.0.0

Spring 3.0をローカルリポジトリに登録

Spring 3.0 がリリースされたが、まだ巷の Maven リポジトリに見当たらないので、ダウンロードしてローカルリポジトリに登録する事にした。(Spring の EBR というリポジトリを使うやり方はここに詳しい)

Spring 3.0 を展開したフォルダ構成を見ると、dist 下に かなりの数の Spring3.0 関連 jar がある。で、それぞれの pom.xml は、projects 下の個別プロジェクトフォルダ直下においてある。例えば、org.springframework.aop ならこんな位置関係になる。
{spring-install-folder}/
dist/
org.springframework.aop-3.0.0.RELEASE.jar
projects/
org.springframework.aop/
pom.xml

Cygwin で Spring 展開フォルダの下の dist に行って、以下のコマンドを発行する。(本当は一行で)
$ ls|gawk '{print $9}'|perl -e 'while() {s/((\S+)-3.+)$/mvn install:install-file -Dfile=$1 -DpomFile=..\/projects\/$2\/pom.xml/;print $_; }'


以下のような出力が得られる。
mvn install:install-file -Dfile=org.springframework.aop-3.0.0.RELEASE.jar -DpomFile=../projects/org.springframework.aop/pom.xml
mvn install:install-file -Dfile=org.springframework.asm-3.0.0.RELEASE.jar -DpomFile=../projects/org.springframework.asm/pom.xml
・・・略・・・
mvn install:install-file -Dfile=org.springframework.web.struts-3.0.0.RELEASE.jar -DpomFile=../projects/org.springframework.web.struts/pom.xml

これを全部コピぺするなりファイルに書き出すなりして実行すれば、dist 下の jar が全部登録される。

いつもはサクラエディタのキーボードマクロでやっていて、そっちの方が簡単だけど、ちょっと練習のためにやってみた。

2009年10月29日木曜日

Spring 2.5/JSR-250

Spring 2.5 の JSR-250 対応APIを調べてみる。 具体的には、@Resource, @PostConstruct, @PreDestroy という三つのアノテーションで、以下のような、無味乾燥なコードで挙動を確かめてみたい。(ただしローカル前提とし、@Resource の JNDI LookUp は度外視する。)
package net.xad.spring25.trial1.jsr250_2;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class ServiceA {
   @Resource
   private ServiceB serviceB;

   private boolean initialized = false;
   private boolean cleanedUp = false;

   @PostConstruct
   private void initialize() {
      initialized = true;
   }
   @PreDestroy
   private void cleanUp() {
      cleanedUp = true;
   }
   public boolean isInjectedCorrectly() {
      return null != serviceB;
   }
   public boolean isInitializedCalled() {
      return initialized;
   }
   public boolean isCleanUpCalled() {
      return cleanedUp;
   }
}
ソースの意味は以下
  • フィールド serviceB はリソースとしてインジェクトされる beanで、クラスServiceBは以下のような定義。単なる実験用なので、以下のような空実装で手を抜く。
    package net.xad.spring25.trial1.jsr250_2;
    import org.springframework.stereotype.Service;
    @Service public class ServiceB {}
  • フィールド initialized は、@PostConstruct が付いたメソッド initialize()が呼ばれた時、false から true になる。
  • フィールド cleanedUp は、@PreDestroy が付いたメソッド cleanUp() が呼ばれた時、false から true になる。
  • ※ serviceB に setter が無い事と、serviceB, initialize(), cleanUp()が private である事に注意。
この ServiceAクラスを以下のようなテストクラスで確かめてみる。
package net.xad.spring25.trial1.jsr250_2;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AppTest {
   @Test
   public void testApp() {
      AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
         "classpath:application-context.xml");

      ServiceA serviceA = (ServiceA)ctx.getBean("serviceA");

      //ServiceB がちゃんとインジェクト済み
      assertTrue(serviceA.isInjectedCorrectly());
      //initialize() が呼ばれた
      assertTrue(serviceA.isInitializedCalled());
      //cleanUp() はまだ呼ばれてない
      assertFalse(serviceA.isCleanUpCalled());

      ctx.close();
      //cleanUp() が呼ばれた
      assertTrue(serviceA.isCleanUpCalled());
   }
}
プロジェクトは以下のように作る。
  • maven-archetype-quickstart でプロジェクト作成
  • 自動生成の不要ファイルを削除する
  • 上記ソースを、適当に作成
  • pom.xml の dependencies を以下のように編集
       <dependencies>
          <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring</artifactId>
             <version>2.5.6</version>
          </dependency>
          <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
             <version>5.1.10</version>
          </dependency>
          <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.7</version>
          </dependency>
       </dependencies>
    
  • 以下のような application-context.xml を、src/main/resources などに追加。
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    
     <context:component-scan base-package="net.xad.spring25.trial1" />
    </beans>
ビルド・エラー等が無い事を確認して、AppTest.java上 の Alt+Shift+Tで実行。 上手くいったことを確認。めでたしめでたし。

2009年10月28日水曜日

Spring 2.5.6+Eclipse+Maven

この「Getting started with Maven and Spring」という記事を、ほんの少しアレンジしてやってみる。 元記事との相違点は以下のとおり。
  • コマンドラインではなく、Eclipse3.5 を使っている
  • Spring 2.5.5ではなく、2.5.6 を使っている
  • bean定義に DTDではなくXMLSchemaを使っている
  • パッケージ名とか固有名詞を適当に変えた
■ Maven Project 作成
  • archetype: maven-archetype-quickstart 1.0
  • group id: net.yasuabe.spring25.trial1
  • artifact id: hello-world-1
  • version: 0.0.1-SNAPSHOT
  • package: net.yasuabe.spring25.trial1.hello_world_1
※group id、artifact id は適当。versionはデフォルト、package は group id とartifact id から自動生成されるデフォルト。 ■ pomを編集
  • dependenciesに以下を追加
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring</artifactId>
      <version>2.5.6</version>
    </dependency>
    
  • PackageExplorer のMavenDependencies 下にspring とcommons-loggingが追加されるのを確認
■ App.java
  • 自動生成されている App.java のmain()を、以下の用に編集
      public static void main(String[] args) {
        BeanFactory factory = new XmlBeanFactory(
            new ClassPathResource("application-context.xml"));
        SayHello hello = (SayHello) factory.getBean("hello");
        hello.greet();
      }
    
  • 赤アンダーライン上の Ctrl+1 でimport を追加
■ SayHello.java
  • 以下のクラスを追加
    package net.yasuabe.spring25.trial1.hello_world_1;
    
    public class SayHello {
      private String name;
    
      public void setName(String name) {
        this.name = name;
      }
      public String getName() {
        return name;
      }
      public void greet() {
        System.out.println("Hello " + getName());
      }
    }
    
■ application-context.xml
  • [New Source Folder]でsrc/main/resourcesを作成
  • 以下のようにapplication-context.xmlを作成
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
     <bean id="hello" class="net.yasuabe.spring25.trial1.hello_world_1.SayHello">
      <property name="name" value="Pookey" />
     </bean>
    </beans>
    
■ 実行
  • App.java 上で Alt + Shift + jで実行、コンソールに"Hello Pookey"が出力されるのを確認
※注意 org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException が、実行時に出たら、ひとまず Eclipse の Preference からvalidation のXML、XSLあたりのチェックを外してみると、多分大丈夫。一旦、実行に成功すると、validation のチェックを戻しても動くようになってるはず。