jPOS-EE Constants

/by apr/ If you use the jPOS’ TransactionManager, and you use a Map to pass around your Context among participants, you may find yourself creating some kind of Contants kind of class in order to define your Context’s keys. If you use jPOS-EE-SDK component model, you may find yourself creating a lot of those. distributed among different files, etc. and your code has to extend or implement many different interfaces in order to access them. I found a very simple solution. as part of jPOS-EE eecore module build, we search for .k files and create a single org.jpos.ee.Constants file that you can rely to be there. So you write things like: *Context.k**

public static final String REQUEST = “REQUEST”
public static final String RESPONSE = “RESPONSE”;
public static final String TERMINAL = “TERMINAL”;

ErrorCode.k

public static final String OK = “ok”;
public static final String INVALID _ISSUER = “invalid.issuer”;
public static final String INVALID_TERMINAL = “invalid.terminal”;

that would create an interface org.jpos.ee.Constants like this:

package org.jpos.ee;
public interface Constants {
public static final String REQUEST = “REQUEST”
public static final String RESPONSE = “RESPONSE”;
public static final String TERMINAL = “TERMINAL”;
public static final String OK = “ok”;
public static final String INVALID _ISSUER = “invalid.issuer”;
public static final String INVALID_TERMINAL = “invalid.terminal”;
}

We do the same with *.p files, we create a single org/jpos/ee/Constants.properties, so you can write something like this:

# # defined in modules/mymodules/src/org/jpos/myapp/MyErrors.p
# ok = 00 APPROVED
invalid.terminal = 14 INVALID TERMINAL

There’s also a handy class called org.jpos.ee.K that implements Constants and give you access to the Constants.properties ResourceBundle by using code like this:

String message = K.get (K.OK); // would give you a “00 APPROVED”

PS.- Sorry to disappoint you… no fancy doclet processing here… this is just a very simple build patch that happens to do what I need. I hope you find it useful.