Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
{snippet:id=props|url=openejb3/examples/custom-injection/src/main/resources/META-INF/env-entries.properties|lang=none}

The Custom Type and Editor

Support for java.lang.Enum types is already built-in, but we've decided we'd like to allow abbreviated versions of the enum constants to be usable. We do this by creating a custom PropertyEditor for our Pickup enum like so:

Wiki Markup
{snippet:id=code|url=openejb3/examples/custom-injection/src/main/java/org/superbiz/enventries/PickupEditor.java|lang=java}

We cleverly install this PropertyEditor in a static block in the Pickup class that will be executed should someone actually reference the Pickup type.

Wiki Markup
{snippet:id=code|url=openejb3/examples/custom-injection/src/main/java/org/superbiz/enventries/Pickup.java|lang=java}

Test Case

Wiki Markup
{snippet:id=code|url=openejb3/examples/custom-injection/src/test/java/org/superbiz/enventries/StratocasterTest.java|lang=java}

Running it

Running the example is fairly simple. In the "custom-injection" directory of the examples zip, just run:

$ mvn clean install

Which should create output like the following.

No Format

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.superbiz.enventries.StratocasterTest
Apache OpenEJB 3.1-SNAPSHOT    build: 20080409-12:05
http://openejb.apache.org/
INFO - openejb.home = /Users/dblevins/work/openejb3/examples/custom-injection
INFO - openejb.base = /Users/dblevins/work/openejb3/examples/custom-injection
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring Service(id=Default JDK 1.3 ProxyFactory, type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
INFO - Found EjbModule in classpath: /Users/dblevins/work/openejb3/examples/custom-injection/target/classes
INFO - Configuring app: /Users/dblevins/work/openejb3/examples/custom-injection/target/classes
INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean StratocasterImpl: Container(type=STATELESS, id=Default Stateless Container)
INFO - Loaded Module: /Users/dblevins/work/openejb3/examples/custom-injection/target/classes
INFO - Assembling app: /Users/dblevins/work/openejb3/examples/custom-injection/target/classes
INFO - Jndi(name=StratocasterImplLocal) --> Ejb(deployment-id=StratocasterImpl)
INFO - Created Ejb(deployment-id=StratocasterImpl, ejb-name=StratocasterImpl, container=Default Stateless Container)
INFO - Deployed Application(path=/Users/dblevins/work/openejb3/examples/custom-injection/target/classes)
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.705 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0