dblevins 2005/08/03 21:20:06
Modified: modules/core/src/java/org/openejb/alt/config
AutoDeployer.java ConfigurationFactory.java
Deploy.java EjbJarUtils.java EjbSet.java
EjbValidator.java
Log:
Cleaning statics out of deployment/validation code
Revision Changes Path
1.5 +3 -16
openejb1/modules/core/src/java/org/openejb/alt/config/AutoDeployer.java
Index: AutoDeployer.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/AutoDeployer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AutoDeployer.java 16 Jun 2005 22:29:50 -0000 1.4
+++ AutoDeployer.java 4 Aug 2005 01:20:06 -0000 1.5
@@ -107,16 +107,10 @@
public void init() throws OpenEJBException {
}
- public OpenejbJar deploy(String jarLocation) throws OpenEJBException {
- EjbJar jar = EjbJarUtils.readEjbJar(jarLocation);
-
- return deploy(jar, jarLocation);
- }
-
- public OpenejbJar deploy(EjbJar jar,String jarLocation) throws
OpenEJBException {
+ public OpenejbJar deploy(EjbJarUtils ejbJarUtils, String jarLocation)
throws OpenEJBException {
OpenejbJar openejbJar = new OpenejbJar();
- Bean[] beans = getBeans(jar);
+ Bean[] beans = ejbJarUtils.getBeans();
for (int i = 0; i < beans.length; i++) {
openejbJar.addEjbDeployment(deployBean(beans[i], jarLocation));
@@ -201,13 +195,6 @@
link.setResId(resources[0].getId());
return link;
}
-
- /*------------------------------------------------------*/
- /* Refactored Methods */
- /*------------------------------------------------------*/
- private Bean[] getBeans(EjbJar jar) {
- return EjbJarUtils.getBeans(jar);
- }
private Container[] getUsableContainers(Bean bean) {
return EjbJarUtils.getUsableContainers(containers, bean);
1.15 +10 -15
openejb1/modules/core/src/java/org/openejb/alt/config/ConfigurationFactory.java
Index: ConfigurationFactory.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/ConfigurationFactory.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ConfigurationFactory.java 12 Jul 2005 23:51:16 -0000 1.14
+++ ConfigurationFactory.java 4 Aug 2005 01:20:06 -0000 1.15
@@ -1261,15 +1261,21 @@
String jarLocation = jarsToLoad[i];
try {
- EjbJar ejbJar = EjbJarUtils.readEjbJar(jarLocation);
+ EjbJarUtils ejbJarUtils = new EjbJarUtils(jarLocation);
+ EjbJar ejbJar = ejbJarUtils.getEjbJar();
/* If there is no openejb-jar.xml attempt to auto deploy it.
*/
OpenejbJar openejbJar =
ConfigUtils.readOpenejbJar(jarLocation);
if (openejbJar == null) {
- openejbJar = deployer.deploy(ejbJar, jarLocation);
+ openejbJar = deployer.deploy(ejbJarUtils, jarLocation);
+ }
+
+ EjbSet set = validator.validateJar( ejbJarUtils );
+ if (set.hasErrors() || set.hasFailures()) {
+ //System.out.println("[] INVALID "+ jarLocation);
+ throw new OpenEJBException("Jar failed validation. Use
the validation tool for more details");
}
- validateJar(ejbJar, jarLocation);
/* Add it to the Vector ***************/
jarsVect.add(new DeployedJar(jarLocation, ejbJar,
openejbJar));
@@ -1282,17 +1288,6 @@
DeployedJar[] jars = new DeployedJar[jarsVect.size()];
jarsVect.copyInto(jars);
return jars;
- }
-
- private void validateJar(EjbJar ejbJar, String jarLocation) throws
OpenEJBException {
-
- EjbValidator validator = new EjbValidator();
- EjbSet set = validator.validateJar(ejbJar, jarLocation);
- if (set.hasErrors() || set.hasFailures()) {
- //System.out.println("[] INVALID "+ jarLocation);
- throw new OpenEJBException("Jar failed validation. Use the
validation tool for more details");
- }
-
}
public Service initService(Service service, String defaultName) throws
OpenEJBException {
1.9 +5 -12
openejb1/modules/core/src/java/org/openejb/alt/config/Deploy.java
Index: Deploy.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/Deploy.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Deploy.java 12 Jul 2005 23:51:16 -0000 1.8
+++ Deploy.java 4 Aug 2005 01:20:06 -0000 1.9
@@ -271,9 +271,10 @@
/*------------------------------------------------------*/
private void deploy(String jarLocation) throws OpenEJBException {
- EjbValidator validator = new EjbValidator();
+ EjbJarUtils ejbJarUtils = new EjbJarUtils(jarLocation);
- EjbSet set = validator.validateJar(jarLocation);
+ EjbValidator validator = new EjbValidator();
+ EjbSet set = validator.validateJar(ejbJarUtils);
if (set.hasErrors() || set.hasFailures()) {
validator.printResults(set);
@@ -284,11 +285,10 @@
System.out.println("See http://www.openejb.org/validate.html for
usage." );
return;
}
- EjbJar jar = set.getEjbJar();
OpenejbJar openejbJar = new OpenejbJar();
- Bean[] beans = getBeans(jar);
+ Bean[] beans = ejbJarUtils.getBeans();
listBeanNames(beans);
@@ -919,13 +919,6 @@
// Print error message to stderr
private static void error(String msg) {
System.err.println("\nERROR: " + msg + "\n");
- }
-
- /*------------------------------------------------------*/
- /* Refactored Methods */
- /*------------------------------------------------------*/
- private Bean[] getBeans(EjbJar jar) {
- return EjbJarUtils.getBeans(jar);
}
private String moveJar(String jar) throws OpenEJBException {
1.6 +32 -20
openejb1/modules/core/src/java/org/openejb/alt/config/EjbJarUtils.java
Index: EjbJarUtils.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/EjbJarUtils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- EjbJarUtils.java 9 Jul 2005 08:50:59 -0000 1.5
+++ EjbJarUtils.java 4 Aug 2005 01:20:06 -0000 1.6
@@ -71,21 +71,28 @@
import org.openejb.util.Messages;
/**
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">David Blevins</a>
*/
public class EjbJarUtils {
protected static final Messages _messages = new
Messages("org.openejb.util.resources");
- public static EjbJar readEjbJar(String jarFile) throws OpenEJBException {
+ private final EjbJar ejbJar;
+ private String jarLocation;
+
+ // TODO Make this a plain EjbJar instance with String jarFile as
constructor
+ // TODO Add support for unpacked jars (jarFile is a directory)
+ public EjbJarUtils(String jarLocation) throws OpenEJBException {
/*[1.1] Get the jar ***************/
- JarFile jar = JarUtils.getJarFile(jarFile);
+ this.jarLocation = jarLocation;
+ JarFile jar = JarUtils.getJarFile(jarLocation);
/*[1.2] Find the ejb-jar.xml from the jar ***************/
JarEntry entry = jar.getJarEntry("META-INF/ejb-jar.xml");
if (entry == null) entry = jar.getJarEntry("ejb-jar.xml");
- if (entry == null) handleException("conf.3900", jarFile, "no
message");
+ if (entry == null) handleException("conf.3900", jarLocation, "no
message");
/*[1.3] Get the ejb-jar.xml from the jar ***************/
Reader reader = null;
@@ -94,7 +101,7 @@
stream = jar.getInputStream(entry);
reader = new InputStreamReader(stream);
} catch (Exception e) {
- handleException("conf.3110", jarFile, e.getLocalizedMessage());
+ handleException("conf.3110", jarLocation,
e.getLocalizedMessage());
}
/*[1.4] Get the OpenejbJar from the openejb-jar.xml ***************/
@@ -103,16 +110,16 @@
obj = unmarshalEjbJar(reader);
} catch (MarshalException e) {
if (e.getException() instanceof UnknownHostException) {
- handleException("conf.3121", jarFile,
e.getLocalizedMessage());
+ handleException("conf.3121", jarLocation,
e.getLocalizedMessage());
} else if (e.getException() instanceof org.xml.sax.SAXException)
{
- handleException("conf.3140", jarFile,
e.getLocalizedMessage());
+ handleException("conf.3140", jarLocation,
e.getLocalizedMessage());
} else if (e.getException() instanceof IOException) {
- handleException("conf.3110", jarFile,
e.getLocalizedMessage());
+ handleException("conf.3110", jarLocation,
e.getLocalizedMessage());
} else {
- handleException("conf.3120", jarFile,
e.getLocalizedMessage());
+ handleException("conf.3120", jarLocation,
e.getLocalizedMessage());
}
} catch (ValidationException e) {
- handleException("conf.3130", jarFile, e.getLocalizedMessage());
+ handleException("conf.3130", jarLocation,
e.getLocalizedMessage());
}
/*[1.5] Clean up ***************/
@@ -121,15 +128,23 @@
reader.close();
jar.close();
} catch (Exception e) {
- handleException("file.0020", jarFile, e.getLocalizedMessage());
+ handleException("file.0020", jarLocation,
e.getLocalizedMessage());
}
- return obj;
+ this.ejbJar = obj;
+ }
+
+ public String getJarLocation() {
+ return jarLocation;
+ }
+
+ public EjbJar getEjbJar() {
+ return ejbJar;
}
private static DTDResolver resolver = new DTDResolver();
- private static EjbJar unmarshalEjbJar(java.io.Reader reader)
+ private EjbJar unmarshalEjbJar(java.io.Reader reader)
throws MarshalException, ValidationException {
Unmarshaller unmarshaller = new
Unmarshaller(org.openejb.alt.config.ejb11.EjbJar.class);
unmarshaller.setEntityResolver(resolver);
@@ -137,7 +152,7 @@
return (org.openejb.alt.config.ejb11.EjbJar)
unmarshaller.unmarshal(reader);
}
- public static void writeEjbJar(String xmlFile, EjbJar ejbJarObject)
throws OpenEJBException {
+ public void writeEjbJar(String xmlFile) throws OpenEJBException {
/* TODO: Just to be picky, the xml file created by
Castor is really hard to read -- it is all on one line.
People might want to edit this in the future by hand, so if Castor
can
@@ -148,7 +163,7 @@
try {
File file = new File(xmlFile);
writer = new FileWriter(file);
- ejbJarObject.marshal(writer);
+ ejbJar.marshal(writer);
} catch (IOException e) {
handleException("conf.3040", xmlFile, e.getLocalizedMessage());
} catch (MarshalException e) {
@@ -301,11 +316,8 @@
return useableContainers;
}
- /*------------------------------------------------------*/
- /* Methods for collecting beans */
- /*------------------------------------------------------*/
- public static Bean[] getBeans(EjbJar jar) {
- EnterpriseBeansItem[] items =
jar.getEnterpriseBeans().getEnterpriseBeansItem();
+ public Bean[] getBeans() {
+ EnterpriseBeansItem[] items =
ejbJar.getEnterpriseBeans().getEnterpriseBeansItem();
Bean[] beans = new Bean[items.length];
for (int i = 0; i < items.length; i++) {
if (items[i].getEntity() == null) {
1.4 +10 -13
openejb1/modules/core/src/java/org/openejb/alt/config/EjbSet.java
Index: EjbSet.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/EjbSet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EjbSet.java 9 Jul 2005 05:14:47 -0000 1.3
+++ EjbSet.java 4 Aug 2005 01:20:06 -0000 1.4
@@ -53,21 +53,18 @@
*/
public class EjbSet {
- protected Vector failures = new Vector();
- protected Vector warnings = new Vector();
- protected Vector errors = new Vector();
+ private final Vector failures = new Vector();
+ private final Vector warnings = new Vector();
+ private final Vector errors = new Vector();
- protected Bean[] beans;
- protected EjbJar jar;
- protected String jarPath;
+ private final String jarPath;
+ private final EjbJar jar;
+ private final Bean[] beans;
- public EjbSet(String jarPath) {
+ public EjbSet(String jarPath, EjbJar jar, Bean[] beans) {
this.jarPath = jarPath;
- }
-
- public void setEjbJar(EjbJar jar) {
this.jar = jar;
- this.beans = EjbJarUtils.getBeans(jar);
+ this.beans = beans;
}
public void addWarning(ValidationWarning warning) {
1.10 +8 -29
openejb1/modules/core/src/java/org/openejb/alt/config/EjbValidator.java
Index: EjbValidator.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/alt/config/EjbValidator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EjbValidator.java 12 Jul 2005 23:51:17 -0000 1.9
+++ EjbValidator.java 4 Aug 2005 01:20:06 -0000 1.10
@@ -91,39 +91,17 @@
return ejbSets;
}
+ public EjbSet validateJar(EjbJarUtils ejbJarUtils){
+ EjbSet set = null;
- public EjbSet validateJar(String jarLocation){
- EjbSet set = new EjbSet(jarLocation);
-
- try {
- set.setEjbJar( EjbJarUtils.readEjbJar(jarLocation) );
- validateJar( set );
- } catch ( Throwable e ) {
- e.printStackTrace(System.out);
- ValidationError err = new ValidationError( "cannot.validate" );
- err.setDetails( e.getMessage() );
- set.addError( err );
- }
- return set;
- }
-
- public EjbSet validateJar(EjbJar ejbJar, String jarLocation) {
- // Create the EjbSet
- EjbSet set = new EjbSet(jarLocation);
- set.setEjbJar(ejbJar);
- return validateJar( set );
- }
-
- public EjbSet validateJar(EjbSet set) {
try {
- //System.out.println("[] validating "+ set.getJarPath());
- // Run the validation rules
+ set = new EjbSet(ejbJarUtils.getJarLocation(),
ejbJarUtils.getEjbJar(), ejbJarUtils.getBeans());
ValidationRule[] rules = getValidationRules();
for (int i=0; i < rules.length; i++){
rules[i].validate( set );
}
} catch ( Throwable e ) {
- e.printStackTrace();
+ e.printStackTrace(System.out);
ValidationError err = new ValidationError( "cannot.validate" );
err.setDetails( e.getMessage() );
set.addError( err );
@@ -363,8 +341,9 @@
// We must have reached the jar list
for (; i < args.length; i++){
try{
- EjbSet set = v.validateJar( args[i] );
- v.addEjbSet( set );
+ EjbJarUtils ejbJarUtils = new
EjbJarUtils(args[i]);
+ EjbSet set = v.validateJar( ejbJarUtils );
+ v.addEjbSet( set );
} catch (Exception e){
e.printStackTrace();
}