Skip to content

Commit

Permalink
Removed dependencies on log4j and xpp.
Browse files Browse the repository at this point in the history
Introduced EjbConfigurator to work with EjbJarParser.
Revised two minute tutorial.
Updated license info.
  • Loading branch information
tastapod committed Apr 21, 2004
1 parent ec0a187 commit ed71143
Show file tree
Hide file tree
Showing 37 changed files with 338 additions and 531 deletions.
2 changes: 0 additions & 2 deletions xjb/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
<classpathentry kind="lib" path="lib/j2ee.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.3.1_08"/>
<classpathentry kind="lib" path="lib/test/hsqldbmain.jar"/>
<classpathentry kind="lib" path="lib/xpp3-1.1.3.4d_b4_min.jar"/>
<classpathentry kind="lib" path="lib/test/jmock.jar"/>
<classpathentry kind="lib" path="lib/proxytoys.jar"/>
<classpathentry kind="var" path="JUNIT_HOME/junit.jar"/>
<classpathentry kind="lib" path="lib/EXML.jar"/>
<classpathentry kind="lib" path="lib/log4j.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
25 changes: 25 additions & 0 deletions xjb/etc/jmock-license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2000-2003, jMock.org
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer. Redistributions in binary form must reproduce
the above copyright notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.

Neither the name of jMock nor the names of its contributors may be used to endorse
or promote products derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
46 changes: 0 additions & 46 deletions xjb/etc/xpp3-license.txt

This file was deleted.

Binary file removed xjb/lib/xpp3-1.1.3.4d_b4_min.jar
Binary file not shown.
30 changes: 30 additions & 0 deletions xjb/src/com/thoughtworks/xjb/config/ejbjar/EjbConfigurator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Created on 21-Apr-2004
*
* (c) 2003-2004 ThoughtWorks Ltd
*
* See license.txt for license details
*/
package com.thoughtworks.xjb.config.ejbjar;
import javax.naming.NamingException;

import com.thoughtworks.xjb.ejb.HomeFactory;
/**
* @author <a href="mailto:dan.north@thoughtworks.com">Dan North</a>
*/
public interface EjbConfigurator {
boolean STATELESS = HomeFactory.STATELESS;
boolean STATEFULL = HomeFactory.STATEFUL;

void registerSessionBean(String ejbName, Class homeInterface,
Class remoteInterface, Class ejbClass, boolean isStateless)
throws InstantiationException, IllegalAccessException;

void registerEnvEntry(String ejbName, String entryName, Class entryType,
String entryValue) throws Exception;

void registerResourceRef(String ejbName, String refName, Class resType)
throws ClassCastException, NamingException;

void registerEjbRef(String ejbName, String jndiName, String targetEjbName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@
*
* @author <a href="mailto:dan.north@thoughtworks.com">Dan North</a>
*/
public interface EjbJarConfigurator {
public interface EjbJarParser {

/**
* Read an <tt>ejb-jar.xml</tt> file from a <tt>Reader</tt>
*
* @throws RemoteException if anything goes wrong
*/
void read(Reader in) throws RemoteException;

/**
* Read an <tt>ejb-jar.xml</tt> file from a URL.
*
* @throws RemoteException if anything goes wrong
*/
void read(String url) throws RemoteException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
*/
package com.thoughtworks.xjb.config.ejbjar;

import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -20,19 +18,20 @@

import javax.ejb.EJBHome;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

import org.apache.log4j.Logger;

import com.thoughtworks.xjb.ejb.XjbHomeFactory;
import com.thoughtworks.xjb.jndi.JndiRegistry;
import com.thoughtworks.xjb.jndi.XjbInitialContextFactory;
import com.thoughtworks.xjb.util.Logger;

/**
* @author <a href="mailto:dan.north@thoughtworks.com">Dan North</a>
*/
public abstract class EjbJarConfiguratorSupport implements EjbJarConfigurator {
private static final Logger log = Logger.getLogger(EjbJarConfiguratorSupport.class);
public class XjbEjbConfigurator implements EjbConfigurator {
private static final Logger log = Logger.getLogger(XjbEjbConfigurator.class);

/** Represents an <ejb-ref> element */
private static class EjbRef {
Expand All @@ -51,41 +50,55 @@ public EjbRef(String ejbName, String jndiName, String targetEjbName) {
private final List unresolvedEjbRefs = new ArrayList();
protected final JndiRegistry jndiRegistry;
private final Context context;
private final XjbHomeFactory homeFactory;

protected EjbJarConfiguratorSupport(JndiRegistry jndiRegistry, Context context) throws NamingException {
public XjbEjbConfigurator(JndiRegistry jndiRegistry, Context context) throws NamingException {
this.jndiRegistry = jndiRegistry;
this.context = context;
// TODO inject this
homeFactory = new XjbHomeFactory();
}

/**
* Read an <tt>ejb-jar.xml</tt> deployment descriptor file.
*
* @throws RemoteException if anything goes wrong
public XjbEjbConfigurator() throws NamingException {
this(new XjbInitialContextFactory(), new InitialContext());
}

/**
* Create a session bean and register it in the global context
* under several common JNDI names
*/
public abstract void read(Reader in) throws RemoteException;
public void registerSessionBean(String ejbName,
Class homeInterface, Class remoteInterface, Class ejbClass, boolean isStateless)
throws InstantiationException, IllegalAccessException {
EJBHome ejbHome = homeFactory.createSessionBeanHome(ejbName,
homeInterface, remoteInterface, ejbClass.newInstance(),
isStateless);
registerCommonGlobalNames(ejbName, remoteInterface.getName(), ejbHome);
registeredBeans.put(ejbName, ejbHome);
resolveOutstandingEjbRefs();
}

/**
* Convenience method to read an <tt>ejb-jar.xml</tt> file from a URL.
* <br>
* The URL is resolved into a {@link Reader} using the current classloader.
*
* @throws RemoteException if anything goes wrong
*/
public void read(String url) throws RemoteException {
read(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(url)));
}

protected void registerSessionBean(String ejbName, Class homeInterface, Class remoteInterface, Class ejbClass, boolean isStateless) throws InstantiationException, IllegalAccessException {
EJBHome home = new XjbHomeFactory().createHome(
ejbName,
homeInterface, remoteInterface,
ejbClass.newInstance(), isStateless);
registerCommonGlobalNames(ejbName, remoteInterface.getName(), home);
registeredBeans.put(ejbName, home);
resolveOutstandingEjbRefs();
private void registerCommonGlobalNames(String ejbName, String remoteClassName, EJBHome ejbHome) {
// Generic
String genericName = "ejb/" + ejbName;

// Orion
String orionName = ejbName;

// WebSphere
StringBuffer buf = new StringBuffer();
char[] chars = remoteClassName.toCharArray();
for (int i = 0; i < chars.length; i++) {
buf.append(chars[i] == '.' ? '/' : chars[i]);
}
String websphereName = buf.toString();

jndiRegistry.register(genericName, ejbHome);
jndiRegistry.register(orionName, ejbHome);
jndiRegistry.register(websphereName, ejbHome);
}

protected void registerEnvEntry(String ejbName, String entryName, Class entryType, String entryValue) throws Exception {
public void registerEnvEntry(String ejbName, String entryName, Class entryType, String entryValue) throws Exception {
try {
Constructor ctor = entryType.getConstructor(new Class[] {String.class});
Object value = ctor.newInstance(new Object[] {entryValue});
Expand All @@ -95,14 +108,14 @@ protected void registerEnvEntry(String ejbName, String entryName, Class entryTyp
}
}

protected void registerResourceRef(String ejbName, String refName, Class resType) throws ClassCastException, NamingException {
public void registerResourceRef(String ejbName, String refName, Class resType) throws ClassCastException, NamingException {
log.debug("Checking for " + refName + " for " + ejbName);
Object resource = PortableRemoteObject.narrow(context.lookup(refName), resType);
log.debug("found it!");
jndiRegistry.register(ejbName, refName, resource);
}

protected void registerEjbRef(String ejbName, String jndiName, String targetEjbName) {
public void registerEjbRef(String ejbName, String jndiName, String targetEjbName) {
EJBHome targetHome = (EJBHome)registeredBeans.get(targetEjbName);
if (targetHome != null) {
log.debug("Registering " + targetHome + " as " + jndiName + " for " + ejbName);
Expand All @@ -114,33 +127,13 @@ protected void registerEjbRef(String ejbName, String jndiName, String targetEjbN
}
}

private void registerCommonGlobalNames(String ejbName, String remoteClassName, EJBHome ejbHome) {
// Generic
String genericName = "ejb/" + ejbName;

// Orion
String orionName = ejbName;

// WebSphere
StringBuffer buf = new StringBuffer();
char[] remoteChars = remoteClassName.toCharArray();
for (int i = 0; i < remoteChars.length; i++) {
buf.append(remoteChars[i] == '.' ? '/' : remoteChars[i]);
}
String websphereName = buf.toString();

jndiRegistry.register(genericName, ejbHome);
jndiRegistry.register(orionName, ejbHome);
jndiRegistry.register(websphereName, ejbHome);
}

/**
* Resolve all <tt>&lt;ejb-ref&gt;</tt> EJB references.
*
* This is a second pass after all the <tt>ejb-jar.xml</tt> files have been read
* using {@link #read(Reader)}
* using {@link EjbJarParser#read(Reader)}
*/
protected void resolveOutstandingEjbRefs() {
private void resolveOutstandingEjbRefs() {
for (Iterator i = unresolvedEjbRefs.iterator(); i.hasNext(); ) {
EjbRef ejbRef = (EjbRef) i.next();
Object targetHome = registeredBeans.get(ejbRef.targetEjbName);
Expand Down
Loading

0 comments on commit ed71143

Please sign in to comment.