summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi')
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java22
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java11
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java13
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java29
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java32
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml62
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties4
7 files changed, 173 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java
new file mode 100644
index 0000000..1500a48
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java
@@ -0,0 +1,22 @@
+package examples.jndi;
+
+import javax.naming.*;
+import javax.rmi.*;
+
+public class Client {
+
+ public static void main (String[] args) throws Exception {
+
+ // Lookup the remote object via JNDI
+ Context ctx = new InitialContext(System.getProperties());
+ Object remoteObject = ctx.lookup("PKGenerator");
+
+ // Cast the remote object, RMI-IIOP style
+ PrimaryKeyGenerator generator = (PrimaryKeyGenerator)
+ PortableRemoteObject.narrow(
+ remoteObject, PrimaryKeyGenerator.class);
+
+ // Generate a PK by calling the RMI-IIOP stub
+ System.out.println(generator.generate());
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java
new file mode 100644
index 0000000..dca940f
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java
@@ -0,0 +1,11 @@
+package examples.jndi;
+
+public class InitContext {
+ public static void main(String args[]) throws Exception {
+ // Form an Initial Context
+ javax.naming.Context ctx =
+ new javax.naming.InitialContext(System.getProperties());
+ System.err.println("Success!");
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java
new file mode 100644
index 0000000..d866f9d
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java
@@ -0,0 +1,13 @@
+package examples.jndi;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * The remote interface for the remote object. Clients use it
+ * for all operations on the remote object.
+ */
+
+public interface PrimaryKeyGenerator extends Remote {
+ public long generate() throws RemoteException;
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java
new file mode 100644
index 0000000..eeb08cb
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java
@@ -0,0 +1,29 @@
+package examples.jndi;
+
+import java.rmi.RemoteException;
+import javax.rmi.PortableRemoteObject;
+
+/**
+ * The implementation of a remote object which generates primary keys
+ */
+public class PrimaryKeyGeneratorImpl
+ extends PortableRemoteObject
+ implements PrimaryKeyGenerator {
+
+ private static long i = System.currentTimeMillis();
+
+ public PrimaryKeyGeneratorImpl() throws Exception, RemoteException {
+ /*
+ * Since we extend PortableRemoteObject, the super
+ * class will export our remote object here.
+ */
+ super();
+ }
+
+ /**
+ * Generates a unique primary key
+ */
+ public synchronized long generate() throws RemoteException {
+ return i++;
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java
new file mode 100644
index 0000000..c6e9afa
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java
@@ -0,0 +1,32 @@
+package examples.jndi;
+import javax.naming.*;
+
+/**
+ * A helper class which starts our RMI-IIOP server
+ */
+public class Startup {
+
+ /**
+ * Our main() method starts things up
+ */
+ public static void main(String args[]) throws Exception {
+
+ /*
+ * Start up our PKGenerator remote object. It will
+ * automatically export itself.
+ */
+ PrimaryKeyGenerator generator = new PrimaryKeyGeneratorImpl();
+
+ /*
+ * Bind our PKGenerator remote object to the JNDI tree
+ */
+ Context ctx = new InitialContext(System.getProperties());
+ ctx.rebind("PKGenerator", generator);
+ System.out.println("PKGenerator bound to JNDI tree.");
+
+ // wait for clients
+ synchronized (generator) {
+ generator.wait();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml
new file mode 100644
index 0000000..d7c9690
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-jndi" default="compile" basedir="../../..">
+
+ &include;
+
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property file="${basedir}/etc/common.properties"/>
+
+ <path id="classpath">
+ <pathelement location="${build.classes.dir}"/>
+ </path>
+
+ <!-- =================================================================== -->
+ <!-- Prepares the build directory -->
+ <!-- =================================================================== -->
+ <target name="prepare">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.classes.dir}"/>
+ </target>
+
+ <target name="rmic" depends="prepare">
+ <javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="on" deprecation="on" optimize="off" includes="examples/jndi/PrimaryKeyGeneratorImpl.java">
+ <classpath refid="classpath" />
+ </javac>
+ <rmic base="${build.classes.dir}" classpath="${build.classes.dir}" classname="examples.jndi.PrimaryKeyGeneratorImpl" iiop="true" />
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the source code -->
+ <!-- =================================================================== -->
+ <target name="compile" depends="rmic">
+ <javac srcdir="${src.dir}"
+ destdir="${build.classes.dir}"
+ debug="on"
+ deprecation="on"
+ optimize="off"
+ includes="examples/jndi/**">
+ </javac>
+ </target>
+
+ <target name="run" depends="compile">
+ <parallel>
+ <java classname="examples.jndi.Startup" fork="yes" dir=".">
+ <classpath refid="classpath"/>
+ </java>
+
+ <java classname="examples.jndi.Client" fork="yes" dir=".">
+ <classpath refid="classpath"/>
+ </java>
+ </parallel>
+ </target>
+
+ <target name="clean">
+ <delete dir="${build.dir}/classes/examples/jndi"/>
+ </target>
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties
new file mode 100644
index 0000000..98cfb22
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties
@@ -0,0 +1,4 @@
+java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
+#java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
+#java.naming.provider.url=file:c
+java.naming.provider.url=corbaloc::localhost:3528/NameService \ No newline at end of file