if (!shouldGenerate(metadata)) {
return null;
}
JavaField field;
JavaMethod method;
JavaClass retVal = createDynamicJavaClass(getDestinationClassname(metadata),
getDestinationPackage(metadata), null, getMetadataProvider());
retVal.setModifiers(new String[] { "public" });
if (getEjbUtils().isMessageDrivenBean(metadata)) {
field = new JavaField(new Type(String.class.getName()), "DESTINATION_JNDI_NAME");
field.setModifiers(new String[] { "private", "final", "static" });
retVal.addField(field);
field = new JavaField(new Type(String.class.getName()), "CONNECTION_FACTORY_JNDI_NAME");
field.setModifiers(new String[] { "private", "final", "static" });
retVal.addField(field);
}
if (isCachehomes()) {
if (getEjbUtils().isMessageDrivenBean(metadata)) {
field = new JavaField(new Type("javax.jms.Queue"), "cachedQueue");
field.setModifiers(new String[] { "private", "static" });
retVal.addField(field);
field = new JavaField(new Type("javax.jms.QueueConnectionFactory"), "cachedConnectionFactory");
field.setModifiers(new String[] { "private", "static" });
retVal.addField(field);
} else {
if (hasRemoteView(metadata)) {
field = new JavaField(new Type(getRemoteHomeInterfacePlugin().getVirtualType(metadata)
.toString()), "cachedRemoteHome");
field.setModifiers(new String[] { "private", "static" });
retVal.addField(field);
}
if (hasLocalView(metadata)) {
field = new JavaField(new Type(getLocalHomeInterfacePlugin().getVirtualType(metadata)
.toString()), "cachedHome");
field.setModifiers(new String[] { "private", "static" });
retVal.addField(field);
}
}
}
method = new JavaMethod(getDestinationClassname(metadata));
method.setConstructor(true);
method.setModifiers(new String[] { "private" });
retVal.addMethod(method);
if (getEjbUtils().isMessageDrivenBean(metadata)) {
method = new JavaMethod("getQueue");
method.setModifiers(new String[] { "public", "static" });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
method.setReturns(new Type("javax.jms.Queue"));
retVal.addMethod(method);
method = new JavaMethod("getQueue");
method.setModifiers(new String[] { "public", "static" });
method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"),
"environment") });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
method.setReturns(new Type("javax.jms.Queue"));
retVal.addMethod(method);
method = new JavaMethod("getQueueConnection");
method.setModifiers(new String[] { "public", "static" });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException"),
new Type("javax.jms.JMSException") });
method.setReturns(new Type("javax.jms.QueueConnection"));
retVal.addMethod(method);
method = new JavaMethod("getQueueConnection");
method.setModifiers(new String[] { "public", "static" });
method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"),
"environment") });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException"),
new Type("javax.jms.JMSException") });
method.setReturns(new Type("javax.jms.QueueConnection"));
retVal.addMethod(method);
} else {
if (hasRemoteView(metadata)) {
method = new JavaMethod("getHome");
method.setModifiers(new String[] { "public", "static" });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
method
.setReturns(new Type(getRemoteHomeInterfacePlugin().getVirtualType(metadata)
.toString()));
retVal.addMethod(method);
method = new JavaMethod("getHome");
method.setModifiers(new String[] { "public", "static" });
method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"),
"env") });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
method
.setReturns(new Type(getRemoteHomeInterfacePlugin().getVirtualType(metadata)
.toString()));
retVal.addMethod(method);
}
if (hasLocalView(metadata)) {
method = new JavaMethod("getLocalHome");
method.setModifiers(new String[] { "public", "static" });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
method
.setReturns(new Type(getLocalHomeInterfacePlugin().getVirtualType(metadata)
.toString()));
retVal.addMethod(method);
method = new JavaMethod("getLocalHome");
method.setModifiers(new String[] { "public", "static" });
method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"),
"env") });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
method
.setReturns(new Type(getLocalHomeInterfacePlugin().getVirtualType(metadata)
.toString()));
retVal.addMethod(method);
}
method = new JavaMethod("lookupHome");
method.setModifiers(new String[] { "private", "static" });
method.setParameters(new JavaParameter[] {
new JavaParameter(new Type("java.util.Hashtable"), "env"),
new JavaParameter(new Type("java.lang.String"), "jndiName"),
new JavaParameter(new Type("java.lang.Class"), "narrowTo") });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
method.setReturns(new Type("java.lang.Object"));
retVal.addMethod(method);
}
method = new JavaMethod("lookup");
method.setModifiers(new String[] { "public", "static" });
method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"), "env"),
new JavaParameter(new Type("java.lang.String"), "jndiName") });
method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
method.setReturns(new Type("java.lang.Object"));
retVal.addMethod(method);
if (isIncludeGUID()) {
method = new JavaMethod("generateGUID");
method.setModifiers(new String[] { "public", "final", "static" });
method.setParameters(new JavaParameter[] {
new JavaParameter(new Type("java.lang.Object"), "o") });
method.setReturns(new Type("java.lang.String"));
retVal.addMethod(method);
field = new JavaField(new Type("java.lang.String"), "hexServerIP");
field.setModifiers(new String[] { "private", "static" });
retVal.addField(field);
field = new JavaField(new Type("java.security.SecureRandom"), "seeder");
field.setModifiers(new String[] { "private", "final", "static" });
retVal.addField(field);
method = new JavaMethod("hexFormat");
method.setModifiers(new String[] { "private", "static" });
method.setParameters(new JavaParameter[] {
new JavaParameter(new Type("byte", 1), "value"), new JavaParameter(new Type("int"), "length") });
method.setReturns(new Type("java.lang.String"));
retVal.addMethod(method);
method = new JavaMethod("hexFormat");
method.setModifiers(new String[] { "private", "static" });
method.setParameters(new JavaParameter[] {
new JavaParameter(new Type("int"), "value"), new JavaParameter(new Type("int"), "length") });
method.setReturns(new Type("java.lang.String"));
retVal.addMethod(method);
}
return new JavaClass[] { retVal };
}