Skip to content

Commit ed71143

Browse files
author
tastapod
committed
Removed dependencies on log4j and xpp.
Introduced EjbConfigurator to work with EjbJarParser. Revised two minute tutorial. Updated license info.
1 parent ec0a187 commit ed71143

37 files changed

Lines changed: 338 additions & 531 deletions

xjb/.classpath

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
<classpathentry kind="lib" path="lib/j2ee.jar"/>
66
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.3.1_08"/>
77
<classpathentry kind="lib" path="lib/test/hsqldbmain.jar"/>
8-
<classpathentry kind="lib" path="lib/xpp3-1.1.3.4d_b4_min.jar"/>
98
<classpathentry kind="lib" path="lib/test/jmock.jar"/>
109
<classpathentry kind="lib" path="lib/proxytoys.jar"/>
1110
<classpathentry kind="var" path="JUNIT_HOME/junit.jar"/>
1211
<classpathentry kind="lib" path="lib/EXML.jar"/>
13-
<classpathentry kind="lib" path="lib/log4j.jar"/>
1412
<classpathentry kind="output" path="bin"/>
1513
</classpath>

xjb/etc/jmock-license.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2000-2003, jMock.org
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
Redistributions of source code must retain the above copyright notice, this list of
8+
conditions and the following disclaimer. Redistributions in binary form must reproduce
9+
the above copyright notice, this list of conditions and the following disclaimer in
10+
the documentation and/or other materials provided with the distribution.
11+
12+
Neither the name of jMock nor the names of its contributors may be used to endorse
13+
or promote products derived from this software without specific prior written
14+
permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
17+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19+
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
24+
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25+
DAMAGE.

xjb/etc/xpp3-license.txt

Lines changed: 0 additions & 46 deletions
This file was deleted.

xjb/lib/xpp3-1.1.3.4d_b4_min.jar

-24 KB
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Created on 21-Apr-2004
3+
*
4+
* (c) 2003-2004 ThoughtWorks Ltd
5+
*
6+
* See license.txt for license details
7+
*/
8+
package com.thoughtworks.xjb.config.ejbjar;
9+
import javax.naming.NamingException;
10+
11+
import com.thoughtworks.xjb.ejb.HomeFactory;
12+
/**
13+
* @author <a href="mailto:dan.north@thoughtworks.com">Dan North</a>
14+
*/
15+
public interface EjbConfigurator {
16+
boolean STATELESS = HomeFactory.STATELESS;
17+
boolean STATEFULL = HomeFactory.STATEFUL;
18+
19+
void registerSessionBean(String ejbName, Class homeInterface,
20+
Class remoteInterface, Class ejbClass, boolean isStateless)
21+
throws InstantiationException, IllegalAccessException;
22+
23+
void registerEnvEntry(String ejbName, String entryName, Class entryType,
24+
String entryValue) throws Exception;
25+
26+
void registerResourceRef(String ejbName, String refName, Class resType)
27+
throws ClassCastException, NamingException;
28+
29+
void registerEjbRef(String ejbName, String jndiName, String targetEjbName);
30+
}

xjb/src/com/thoughtworks/xjb/config/ejbjar/EjbJarConfigurator.java renamed to xjb/src/com/thoughtworks/xjb/config/ejbjar/EjbJarParser.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515
*
1616
* @author <a href="mailto:dan.north@thoughtworks.com">Dan North</a>
1717
*/
18-
public interface EjbJarConfigurator {
18+
public interface EjbJarParser {
19+
20+
/**
21+
* Read an <tt>ejb-jar.xml</tt> file from a <tt>Reader</tt>
22+
*
23+
* @throws RemoteException if anything goes wrong
24+
*/
1925
void read(Reader in) throws RemoteException;
26+
27+
/**
28+
* Read an <tt>ejb-jar.xml</tt> file from a URL.
29+
*
30+
* @throws RemoteException if anything goes wrong
31+
*/
2032
void read(String url) throws RemoteException;
2133
}

xjb/src/com/thoughtworks/xjb/config/ejbjar/EjbJarConfiguratorSupport.java renamed to xjb/src/com/thoughtworks/xjb/config/ejbjar/XjbEjbConfigurator.java

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
*/
88
package com.thoughtworks.xjb.config.ejbjar;
99

10-
import java.io.InputStreamReader;
1110
import java.io.Reader;
1211
import java.lang.reflect.Constructor;
1312
import java.lang.reflect.InvocationTargetException;
14-
import java.rmi.RemoteException;
1513
import java.util.ArrayList;
1614
import java.util.HashMap;
1715
import java.util.Iterator;
@@ -20,19 +18,20 @@
2018

2119
import javax.ejb.EJBHome;
2220
import javax.naming.Context;
21+
import javax.naming.InitialContext;
2322
import javax.naming.NamingException;
2423
import javax.rmi.PortableRemoteObject;
2524

26-
import org.apache.log4j.Logger;
27-
2825
import com.thoughtworks.xjb.ejb.XjbHomeFactory;
2926
import com.thoughtworks.xjb.jndi.JndiRegistry;
27+
import com.thoughtworks.xjb.jndi.XjbInitialContextFactory;
28+
import com.thoughtworks.xjb.util.Logger;
3029

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

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

55-
protected EjbJarConfiguratorSupport(JndiRegistry jndiRegistry, Context context) throws NamingException {
55+
public XjbEjbConfigurator(JndiRegistry jndiRegistry, Context context) throws NamingException {
5656
this.jndiRegistry = jndiRegistry;
5757
this.context = context;
58+
// TODO inject this
59+
homeFactory = new XjbHomeFactory();
5860
}
5961

60-
/**
61-
* Read an <tt>ejb-jar.xml</tt> deployment descriptor file.
62-
*
63-
* @throws RemoteException if anything goes wrong
62+
public XjbEjbConfigurator() throws NamingException {
63+
this(new XjbInitialContextFactory(), new InitialContext());
64+
}
65+
66+
/**
67+
* Create a session bean and register it in the global context
68+
* under several common JNDI names
6469
*/
65-
public abstract void read(Reader in) throws RemoteException;
70+
public void registerSessionBean(String ejbName,
71+
Class homeInterface, Class remoteInterface, Class ejbClass, boolean isStateless)
72+
throws InstantiationException, IllegalAccessException {
73+
EJBHome ejbHome = homeFactory.createSessionBeanHome(ejbName,
74+
homeInterface, remoteInterface, ejbClass.newInstance(),
75+
isStateless);
76+
registerCommonGlobalNames(ejbName, remoteInterface.getName(), ejbHome);
77+
registeredBeans.put(ejbName, ejbHome);
78+
resolveOutstandingEjbRefs();
79+
}
6680

67-
/**
68-
* Convenience method to read an <tt>ejb-jar.xml</tt> file from a URL.
69-
* <br>
70-
* The URL is resolved into a {@link Reader} using the current classloader.
71-
*
72-
* @throws RemoteException if anything goes wrong
73-
*/
74-
public void read(String url) throws RemoteException {
75-
read(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(url)));
76-
}
77-
78-
protected void registerSessionBean(String ejbName, Class homeInterface, Class remoteInterface, Class ejbClass, boolean isStateless) throws InstantiationException, IllegalAccessException {
79-
EJBHome home = new XjbHomeFactory().createHome(
80-
ejbName,
81-
homeInterface, remoteInterface,
82-
ejbClass.newInstance(), isStateless);
83-
registerCommonGlobalNames(ejbName, remoteInterface.getName(), home);
84-
registeredBeans.put(ejbName, home);
85-
resolveOutstandingEjbRefs();
81+
private void registerCommonGlobalNames(String ejbName, String remoteClassName, EJBHome ejbHome) {
82+
// Generic
83+
String genericName = "ejb/" + ejbName;
84+
85+
// Orion
86+
String orionName = ejbName;
87+
88+
// WebSphere
89+
StringBuffer buf = new StringBuffer();
90+
char[] chars = remoteClassName.toCharArray();
91+
for (int i = 0; i < chars.length; i++) {
92+
buf.append(chars[i] == '.' ? '/' : chars[i]);
93+
}
94+
String websphereName = buf.toString();
95+
96+
jndiRegistry.register(genericName, ejbHome);
97+
jndiRegistry.register(orionName, ejbHome);
98+
jndiRegistry.register(websphereName, ejbHome);
8699
}
87100

88-
protected void registerEnvEntry(String ejbName, String entryName, Class entryType, String entryValue) throws Exception {
101+
public void registerEnvEntry(String ejbName, String entryName, Class entryType, String entryValue) throws Exception {
89102
try {
90103
Constructor ctor = entryType.getConstructor(new Class[] {String.class});
91104
Object value = ctor.newInstance(new Object[] {entryValue});
@@ -95,14 +108,14 @@ protected void registerEnvEntry(String ejbName, String entryName, Class entryTyp
95108
}
96109
}
97110

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

105-
protected void registerEjbRef(String ejbName, String jndiName, String targetEjbName) {
118+
public void registerEjbRef(String ejbName, String jndiName, String targetEjbName) {
106119
EJBHome targetHome = (EJBHome)registeredBeans.get(targetEjbName);
107120
if (targetHome != null) {
108121
log.debug("Registering " + targetHome + " as " + jndiName + " for " + ejbName);
@@ -114,33 +127,13 @@ protected void registerEjbRef(String ejbName, String jndiName, String targetEjbN
114127
}
115128
}
116129

117-
private void registerCommonGlobalNames(String ejbName, String remoteClassName, EJBHome ejbHome) {
118-
// Generic
119-
String genericName = "ejb/" + ejbName;
120-
121-
// Orion
122-
String orionName = ejbName;
123-
124-
// WebSphere
125-
StringBuffer buf = new StringBuffer();
126-
char[] remoteChars = remoteClassName.toCharArray();
127-
for (int i = 0; i < remoteChars.length; i++) {
128-
buf.append(remoteChars[i] == '.' ? '/' : remoteChars[i]);
129-
}
130-
String websphereName = buf.toString();
131-
132-
jndiRegistry.register(genericName, ejbHome);
133-
jndiRegistry.register(orionName, ejbHome);
134-
jndiRegistry.register(websphereName, ejbHome);
135-
}
136-
137130
/**
138131
* Resolve all <tt>&lt;ejb-ref&gt;</tt> EJB references.
139132
*
140133
* This is a second pass after all the <tt>ejb-jar.xml</tt> files have been read
141-
* using {@link #read(Reader)}
134+
* using {@link EjbJarParser#read(Reader)}
142135
*/
143-
protected void resolveOutstandingEjbRefs() {
136+
private void resolveOutstandingEjbRefs() {
144137
for (Iterator i = unresolvedEjbRefs.iterator(); i.hasNext(); ) {
145138
EjbRef ejbRef = (EjbRef) i.next();
146139
Object targetHome = registeredBeans.get(ejbRef.targetEjbName);

0 commit comments

Comments
 (0)