Update of
/cvsroot/xdoclet-plugins/xdoclet-plugins/testapp-ejb/src/main/java/org/xdoclet/testapp/ejb/util
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28575/testapp-ejb/src/main/java/org/xdoclet/testapp/ejb/util
Added Files:
AccountUtil.java TransferReceiverUtil.java
Log Message:
* Added LookupObjectPlugin
* Finished PrimaryKeyClassPlugin
* Fixed small bugs
--- NEW FILE: TransferReceiverUtil.java ---
package org.xdoclet.testapp.ejb.util;
/**
* This class would normally be generated by XDoclet, but we keep it in the
codebase only to ensure that the
* testapp can compile without XDoclet.
* This source is also used by the xdoclet-ejb plugin to compare the generated
output.
*
* @author Diogo Quintela
* @version $Revision: 1.1 $
*/
public class TransferReceiverUtil {
private static final java.lang.String DESTINATION_JNDI_NAME =
"dest/jndi/queue";
private static final java.lang.String CONNECTION_FACTORY_JNDI_NAME =
"jndi/conn/factory";
private static javax.jms.Queue cachedQueue = null;
private static javax.jms.QueueConnectionFactory cachedConnectionFactory =
null;
/**
* Obtain destination queue from default initial context
*
* @return Destination JMS Queue for TransferReceiverBean.
*/
public static javax.jms.Queue getQueue() throws
javax.naming.NamingException {
javax.jms.Queue retVal = cachedQueue;
if (retVal == null) {
retVal = (javax.jms.Queue) lookup(null, DESTINATION_JNDI_NAME);
cachedQueue = retVal;
}
return retVal;
}
/**
* Obtain destination queue from parameterized initial context
*
* @param environment Parameters to use for creating initial context
* @return Destination JMS Queue for TransferReceiverBean.
*/
public static javax.jms.Queue getQueue(java.util.Hashtable environment)
throws javax.naming.NamingException {
return (javax.jms.Queue) lookup(environment, DESTINATION_JNDI_NAME);
}
public static javax.jms.QueueConnection getQueueConnection() throws
javax.naming.NamingException, javax.jms.JMSException {
javax.jms.QueueConnectionFactory factory = cachedConnectionFactory;
if (factory == null) {
factory = (javax.jms.QueueConnectionFactory) lookup(null,
CONNECTION_FACTORY_JNDI_NAME);
cachedConnectionFactory = factory;
}
return factory.createQueueConnection();
}
public static javax.jms.QueueConnection
getQueueConnection(java.util.Hashtable environment) throws
javax.naming.NamingException, javax.jms.JMSException {
javax.jms.QueueConnectionFactory factory =
(javax.jms.QueueConnectionFactory) lookup(environment,
CONNECTION_FACTORY_JNDI_NAME);
return factory.createQueueConnection();
}
/**
* Retrieves the named object.
*
* @param env the environment properties
* @param jndiName the name of the object to look up
* @return the object bound to <tt>name</tt>
* @throws NamingException if a naming exception is encountered
*/
public static Object lookup(java.util.Hashtable env, String jndiName)
throws javax.naming.NamingException {
javax.naming.InitialContext initialContext = new
javax.naming.InitialContext(env);
try {
return initialContext.lookup(jndiName);
} finally {
initialContext.close();
}
}
// ----------------------------------------------------------------
// Define your custom append code in a file called util-custom.vm
// and place it in your merge directory.
// ----------------------------------------------------------------
/**
* A 32 byte GUID generator (Globally Unique ID). These artificial keys
SHOULD <strong>NOT </strong> be seen by the user,
* not even touched by the DBA but with very rare exceptions, just
manipulated by the database and the programs.
*
* Usage: Add an id field (type java.lang.String) to your EJB, and add
setId(XXXUtil.generateGUID(this)); to the ejbCreate method.
*/
public static final String generateGUID(Object o) {
if (hexServerIP == null) {
byte[] ipBytes;
try {
ipBytes = java.net.InetAddress.getLocalHost().getAddress();
} catch (java.net.UnknownHostException uhe) {
// In worst case cenario, seed 32 bits
ipBytes = new byte[4];
seeder.nextBytes(ipBytes);
}
hexServerIP = hexFormat(ipBytes, 8);
}
long timeNow = System.currentTimeMillis();
int timeLow = (int)timeNow & 0xFFFFFFFF;
int node = seeder.nextInt();
StringBuffer guid = new StringBuffer(32);
guid.append(hexFormat(timeLow, 8));
guid.append(hexServerIP);
guid.append(hexFormat(System.identityHashCode(o), 8));
guid.append(hexFormat(node, 8));
return guid.toString();
}
// Cached per JVM server IP.
private static String hexServerIP = null;
// initialise the secure random instance
private static final java.security.SecureRandom seeder = new
java.security.SecureRandom();
private static String hexFormat(byte[] value, int length) {
StringBuffer retBuf = new StringBuffer();
for (int i = 0; i < value.length; i++) {
int x = (value[i] & 0xFF);
retBuf.append((x < 0x10 ? "0" : "") + Integer.toString(x, 16));
}
while (retBuf.length() < length) {
retBuf.insert(0, '0');
}
return retBuf.toString();
}
private static String hexFormat(int value, int length) {
StringBuffer retBuf = new StringBuffer(Integer.toHexString(value));
while (retBuf.length() < length) {
retBuf.insert(0, '0');
}
return retBuf.toString();
}
}
--- NEW FILE: AccountUtil.java ---
package org.xdoclet.testapp.ejb.util;
/**
* This class would normally be generated by XDoclet, but we keep it in the
codebase only to ensure that the
* testapp can compile without XDoclet.
* This source is also used by the xdoclet-ejb plugin to compare the generated
output.
*
* @author Diogo Quintela
* @version $Revision: 1.1 $
*/
public class AccountUtil {
private static org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome
cachedRemoteHome = null;
private static org.xdoclet.testapp.ejb.interfaces.AccountLocalHome
cachedHome = null;
public org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome getHome()
throws javax.naming.NamingException {
org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome retVal =
cachedRemoteHome;
if (retVal == null) {
retVal = (org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome)
lookupHome(null,
org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome.JNDI_NAME,
org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome.class);
cachedRemoteHome = retVal;
}
return retVal;
}
public org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome
getHome(java.util.Hashtable env) throws javax.naming.NamingException {
return (org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome)
lookupHome(env, org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome.JNDI_NAME,
org.xdoclet.testapp.ejb.interfaces.AccountRemoteHome.class);
}
public org.xdoclet.testapp.ejb.interfaces.AccountLocalHome getLocalHome()
throws javax.naming.NamingException {
org.xdoclet.testapp.ejb.interfaces.AccountLocalHome retVal = cachedHome;
if (retVal == null) {
retVal = (org.xdoclet.testapp.ejb.interfaces.AccountLocalHome)
lookupHome(null, org.xdoclet.testapp.ejb.interfaces.AccountLocalHome.JNDI_NAME,
org.xdoclet.testapp.ejb.interfaces.AccountLocalHome.class);
cachedHome = retVal;
}
return retVal;
}
public org.xdoclet.testapp.ejb.interfaces.AccountLocalHome
getLocalHome(java.util.Hashtable env) throws javax.naming.NamingException {
return (org.xdoclet.testapp.ejb.interfaces.AccountLocalHome)
lookupHome(env, org.xdoclet.testapp.ejb.interfaces.AccountLocalHome.JNDI_NAME,
org.xdoclet.testapp.ejb.interfaces.AccountLocalHome.class);
}
/**
* Retrieves the named home interfaces, narrowing if needed.
*
* @param env the environment properties
* @param jndiName the name of the object to look up
* @param narrowTo the class expected to the looked up object
* @return the object bound to <tt>name</tt>, narrowed if needed
* @throws NamingException if a naming exception is encountered
*/
private static Object lookupHome(java.util.Hashtable env, String jndiName,
Class narrowTo) throws javax.naming.NamingException {
Object retVal = lookup(env, jndiName);
// Only narrow if necessary
if (java.rmi.Remote.class.isAssignableFrom(narrowTo)) {
retVal = javax.rmi.PortableRemoteObject.narrow(retVal, narrowTo);
}
return retVal;
}
/**
* Retrieves the named object.
*
* @param env the environment properties
* @param jndiName the name of the object to look up
* @return the object bound to <tt>name</tt>
* @throws NamingException if a naming exception is encountered
*/
public static Object lookup(java.util.Hashtable env, String jndiName)
throws javax.naming.NamingException {
javax.naming.InitialContext initialContext = new
javax.naming.InitialContext(env);
try {
return initialContext.lookup(jndiName);
} finally {
initialContext.close();
}
}
// ----------------------------------------------------------------
// Define your custom append code in a file called util-custom.vm
// and place it in your merge directory.
// ----------------------------------------------------------------
/**
* A 32 byte GUID generator (Globally Unique ID). These artificial keys
SHOULD <strong>NOT </strong> be seen by the user,
* not even touched by the DBA but with very rare exceptions, just
manipulated by the database and the programs.
*
* Usage: Add an id field (type java.lang.String) to your EJB, and add
setId(XXXUtil.generateGUID(this)); to the ejbCreate method.
*/
public static final String generateGUID(Object o) {
if (hexServerIP == null) {
byte[] ipBytes;
try {
ipBytes = java.net.InetAddress.getLocalHost().getAddress();
} catch (java.net.UnknownHostException uhe) {
// In worst case cenario, seed 32 bits
ipBytes = new byte[4];
seeder.nextBytes(ipBytes);
}
hexServerIP = hexFormat(ipBytes, 8);
}
long timeNow = System.currentTimeMillis();
int timeLow = (int)timeNow & 0xFFFFFFFF;
int node = seeder.nextInt();
StringBuffer guid = new StringBuffer(32);
guid.append(hexFormat(timeLow, 8));
guid.append(hexServerIP);
guid.append(hexFormat(System.identityHashCode(o), 8));
guid.append(hexFormat(node, 8));
return guid.toString();
}
// Cached per JVM server IP.
private static String hexServerIP = null;
// initialise the secure random instance
private static final java.security.SecureRandom seeder = new
java.security.SecureRandom();
private static String hexFormat(byte[] value, int length) {
StringBuffer retBuf = new StringBuffer();
for (int i = 0; i < value.length; i++) {
int x = (value[i] & 0xFF);
retBuf.append((x < 0x10 ? "0" : "") + Integer.toString(x, 16));
}
while (retBuf.length() < length) {
retBuf.insert(0, '0');
}
return retBuf.toString();
}
private static String hexFormat(int value, int length) {
StringBuffer retBuf = new StringBuffer(Integer.toHexString(value));
while (retBuf.length() < length) {
retBuf.insert(0, '0');
}
return retBuf.toString();
}
}
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
xdoclet-plugins-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xdoclet-plugins-commits