1 package org.acme.movie; 2 3 import javax.ejb.SessionBean ; 4 import javax.ejb.EJBException ; 5 import javax.ejb.SessionContext ; 6 import javax.ejb.EJBLocalHome ; 7 import javax.ejb.CreateException ; 8 import javax.ejb.EJBLocalObject ; 9 import javax.ejb.RemoveException ; 10 import javax.naming.NamingException ; 11 import javax.naming.InitialContext ; 12 import javax.naming.Context ; 13 import javax.naming.Name ; 14 import javax.naming.NamingEnumeration ; 15 import javax.naming.NameParser ; 16 import java.rmi.RemoteException ; 17 import java.util.Hashtable ; 18 import java.util.Properties ; 19 20 24 public interface JndiContext extends Context { 25 public static final String LOCAL_NAME = "ContextEJBLocal"; 26 27 28 31 public interface LocalHome extends EJBLocalHome { 32 JndiContext.Local create() throws CreateException ; 33 } 34 35 38 public interface Local extends EJBLocalObject , JndiContext { 39 } 40 41 44 public static final Local LOCAL = new Local(){ 45 private Local object; 46 private Local object(){ 47 if (object == null){ 48 object = getObject(); 49 } 50 return object; 51 } 52 private Local getObject() { 53 try { 54 Properties p = new Properties (System.getProperties()); 55 p.put("java.naming.factory.initial", "org.openejb.client.LocalInitialContextFactory"); 56 InitialContext initialContext = new InitialContext (p); 57 LocalHome home = (LocalHome ) initialContext.lookup(LOCAL_NAME); 58 return home.create(); 59 } catch (NamingException e) { 60 throw (IllegalStateException ) new IllegalStateException (LOCAL_NAME + " cannot be retrieved from JNDI.").initCause(e); 61 } catch (CreateException e) { 62 throw (IllegalStateException ) new IllegalStateException ("Cannot create session bean "+LOCAL_NAME).initCause(e); 63 } 64 } 65 66 public EJBLocalHome getEJBLocalHome() throws EJBException { 67 return getObject().getEJBLocalHome(); 68 } 69 70 public java.lang.Object getPrimaryKey() throws EJBException { 71 return getObject().getPrimaryKey(); 72 } 73 74 public boolean isIdentical(EJBLocalObject ejbLocalObject) throws EJBException { 75 return getObject().isIdentical(ejbLocalObject); 76 } 77 78 public void remove() throws RemoveException , EJBException { 79 getObject().remove(); 80 } 81 82 public java.lang.Object lookup(Name name) throws NamingException { 83 return getObject().lookup(name); 84 } 85 86 public java.lang.Object lookup(String name) throws NamingException { 87 return getObject().lookup(name); 88 } 89 90 public void bind(Name name, java.lang.Object obj) throws NamingException { 91 getObject().bind(name, obj); 92 } 93 94 public void bind(String name, java.lang.Object obj) throws NamingException { 95 getObject().bind(name, obj); 96 } 97 98 public void rebind(Name name, java.lang.Object obj) throws NamingException { 99 getObject().rebind(name, obj); 100 } 101 102 public void rebind(String name, java.lang.Object obj) throws NamingException { 103 getObject().rebind(name, obj); 104 } 105 106 public void unbind(Name name) throws NamingException { 107 getObject().unbind(name); 108 } 109 110 public void unbind(String name) throws NamingException { 111 getObject().unbind(name); 112 } 113 114 public void rename(Name oldName, Name newName) throws NamingException { 115 getObject().rename(oldName, newName); 116 } 117 118 public void rename(String oldName, String newName) throws NamingException { 119 getObject().rename(oldName, newName); 120 } 121 122 public NamingEnumeration list(Name name) throws NamingException { 123 return getObject().list(name); 124 } 125 126 public NamingEnumeration list(String name) throws NamingException { 127 return getObject().list(name); 128 } 129 130 public NamingEnumeration listBindings(Name name) throws NamingException { 131 return getObject().listBindings(name); 132 } 133 134 public NamingEnumeration listBindings(String name) throws NamingException { 135 return getObject().listBindings(name); 136 } 137 138 public void destroySubcontext(Name name) throws NamingException { 139 getObject().destroySubcontext(name); 140 } 141 142 public void destroySubcontext(String name) throws NamingException { 143 getObject().destroySubcontext(name); 144 } 145 146 public Context createSubcontext(Name name) throws NamingException { 147 return getObject().createSubcontext(name); 148 } 149 150 public Context createSubcontext(String name) throws NamingException { 151 return getObject().createSubcontext(name); 152 } 153 154 public java.lang.Object lookupLink(Name name) throws NamingException { 155 return getObject().lookupLink(name); 156 } 157 158 public java.lang.Object lookupLink(String name) throws NamingException { 159 return getObject().lookupLink(name); 160 } 161 162 public NameParser getNameParser(Name name) throws NamingException { 163 return getObject().getNameParser(name); 164 } 165 166 public NameParser getNameParser(String name) throws NamingException { 167 return getObject().getNameParser(name); 168 } 169 170 public Name composeName(Name name, Name prefix) throws NamingException { 171 return getObject().composeName(name, prefix); 172 } 173 174 public String composeName(String name, String prefix) 175 throws NamingException { 176 return getObject().composeName(name, prefix); 177 } 178 179 public java.lang.Object addToEnvironment(String propName, java.lang.Object propVal) 180 throws NamingException { 181 return getObject().addToEnvironment(propName, propVal); 182 } 183 184 public java.lang.Object removeFromEnvironment(String propName) 185 throws NamingException { 186 return getObject().removeFromEnvironment(propName); 187 } 188 189 public Hashtable getEnvironment() throws NamingException { 190 return getObject().getEnvironment(); 191 } 192 193 public void close() throws NamingException { 194 getObject().close(); 195 } 196 197 public String getNameInNamespace() throws NamingException { 198 return getObject().getNameInNamespace(); 199 } 200 }; 201 202 } 203 | Popular Tags |