From: <st...@us...> - 2001-06-10 20:50:32
|
User: starksm Date: 01/06/10 13:50:31 Modified: src/main/org/jboss/ejb Container.java ContainerFactory.java EnterpriseContext.java Log: Implement support for EJB 2.0 resource-env-ref element Revision Changes Path 1.43 +51 -50 jboss/src/main/org/jboss/ejb/Container.java Index: Container.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/Container.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- Container.java 2001/06/03 20:59:40 1.42 +++ Container.java 2001/06/10 20:50:31 1.43 @@ -49,6 +49,7 @@ import org.jboss.metadata.EjbRefMetaData; import org.jboss.metadata.EjbLocalRefMetaData; import org.jboss.metadata.ResourceRefMetaData; +import org.jboss.metadata.ResourceEnvRefMetaData; import org.jboss.metadata.ApplicationMetaData; import org.jnp.interfaces.Naming; @@ -71,7 +72,8 @@ * @see ContainerFactory * @author Rickard Öberg (ric...@te...) * @author <a href="mar...@te...">Marc Fleury</a> - * @version $Revision: 1.42 $ + * @author Sco...@di... + * @version $Revision: 1.43 $ */ public abstract class Container { @@ -326,7 +328,7 @@ localContainerInvoker.init(); if (localHomeInterface != null) application.addLocalHome(this, localContainerInvoker.getEJBLocalHome() ); - // Setup "java:" namespace + // Setup "java:comp/env" namespace setupEnvironment(); } @@ -401,7 +403,7 @@ * setupEnvironment * * This method sets up the naming environment of the bean. - * We create the java: namespace with properties, EJB-References, and + * We create the java:comp/env namespace with properties, EJB-References, and * DataSource ressources. * */ @@ -410,56 +412,36 @@ { try { + BeanMetaData beanMetaData = getBeanMetaData(); + Logger.debug("Begin java:comp/env for EJB: "+beanMetaData.getEjbName()); + Logger.debug("TCL: "+Thread.currentThread().getContextClassLoader()); // Since the BCL is already associated with this thread we can start using the java: namespace directly Context ctx = (Context) new InitialContext().lookup("java:comp"); - ctx = ctx.createSubcontext("env"); + Context envCtx = ctx.createSubcontext("env"); + Logger.debug("java:comp/env: "+envCtx); // Bind environment properties { - Iterator enum = getBeanMetaData().getEnvironmentEntries(); + Iterator enum = beanMetaData.getEnvironmentEntries(); while(enum.hasNext()) { EnvEntryMetaData entry = (EnvEntryMetaData)enum.next(); - if (entry.getType().equals("java.lang.Integer")) + try { - bind(ctx, entry.getName(), new Integer(entry.getValue())); + Logger.debug("Binding env-entry: "+entry.getName()+" of type: "+entry.getType()+" to value:"+entry.getValue()); + EnvEntryMetaData.bindEnvEntry(envCtx, entry); } - else if (entry.getType().equals("java.lang.Long")) + catch(ClassNotFoundException e) { - bind(ctx, entry.getName(), new Long(entry.getValue())); + Logger.exception(e); + throw new DeploymentException("Could not set up environment", e); } - else if (entry.getType().equals("java.lang.Double")) - { - bind(ctx, entry.getName(), new Double(entry.getValue())); - } - else if (entry.getType().equals("java.lang.Float")) - { - bind(ctx, entry.getName(), new Float(entry.getValue())); - } - else if (entry.getType().equals("java.lang.Byte")) - { - bind(ctx, entry.getName(), new Byte(entry.getValue())); - } - else if (entry.getType().equals("java.lang.Short")) - { - bind(ctx, entry.getName(), new Short(entry.getValue())); - } - else if (entry.getType().equals("java.lang.Boolean")) - { - bind(ctx, entry.getName(), new Boolean(entry.getValue())); - } - else - { - // Unknown type - // Default is string - bind(ctx, entry.getName(), entry.getValue()); - } } } // Bind EJB references { - Iterator enum = getBeanMetaData().getEjbReferences(); + Iterator enum = beanMetaData.getEjbReferences(); while(enum.hasNext()) { @@ -470,12 +452,13 @@ { // Internal link Logger.debug("Binding "+ref.getName()+" to internal JNDI source: "+ref.getLink()); - if (getApplication().getContainer(ref.getLink()) == null) + Container refContainer = getApplication().getContainer(ref.getLink()); + if (refContainer == null) throw new DeploymentException ("Bean "+ref.getLink()+" not found within this application."); - bind(ctx, ref.getName(), new LinkRef(getApplication().getContainer(ref.getLink()).getBeanMetaData().getJndiName())); + bind(envCtx, ref.getName(), new LinkRef(refContainer.getBeanMetaData().getJndiName())); - // bind(ctx, ref.getName(), new Reference(ref.getHome(), new StringRefAddr("Container",ref.getLink()), getClass().getName()+".EjbReferenceFactory", null)); - // bind(ctx, ref.getName(), new LinkRef(ref.getLink())); + // bind(envCtx, ref.getName(), new Reference(ref.getHome(), new StringRefAddr("Container",ref.getLink()), getClass().getName()+".EjbReferenceFactory", null)); + // bind(envCtx, ref.getName(), new LinkRef(ref.getLink())); } else { @@ -485,14 +468,14 @@ throw new DeploymentException("ejb-ref "+ref.getName()+", expected either ejb-link in ejb-jar.xml or jndi-name in jboss.xml"); } Logger.debug("Binding "+ref.getName()+" to external JNDI source: "+ref.getJndiName()); - bind(ctx, ref.getName(), new LinkRef(ref.getJndiName())); + bind(envCtx, ref.getName(), new LinkRef(ref.getJndiName())); } } } // Bind Local EJB references { - Iterator enum = getBeanMetaData().getEjbLocalReferences(); + Iterator enum = beanMetaData.getEjbLocalReferences(); // unique key name String uniqueKey = Long.toString( (new java.util.Date()).getTime() ); while(enum.hasNext()) @@ -514,7 +497,7 @@ StringRefAddr refAddr = new StringRefAddr("nns", uniqueKey+ref.getName() ); Reference jndiRef = new Reference(ref.getLocalHome(), refAddr, LocalHomeObjectFactory.class.getName(), null ); - bind(ctx, ref.getName(), jndiRef ); + bind(envCtx, ref.getName(), jndiRef ); } else @@ -526,10 +509,10 @@ // Bind resource references { - Iterator enum = getBeanMetaData().getResourceReferences(); + Iterator enum = beanMetaData.getResourceReferences(); // let's play guess the cast game ;) New metadata should fix this. - ApplicationMetaData application = getBeanMetaData().getApplicationMetaData(); + ApplicationMetaData application = beanMetaData.getApplicationMetaData(); while(enum.hasNext()) { @@ -576,8 +559,8 @@ // URL bindings try { - Logger.debug("Binding URL "+finalName+ " to JDNI ENC " +ref.getRefName()); - bind(ctx, ref.getRefName(), new URL(finalName)); + Logger.debug("Binding URL: "+finalName+ " to JDNI ENC as: " +ref.getRefName()); + bind(envCtx, ref.getRefName(), new URL(finalName)); } catch (MalformedURLException e) { throw new NamingException("Malformed URL:"+e.getMessage()); @@ -585,18 +568,36 @@ } else { - // Resource Manager bindings - Logger.debug("Binding resource manager "+finalName+ " with JDNI ENC " +ref.getRefName()); - bind(ctx, ref.getRefName(), new LinkRef(finalName)); + // Resource Manager bindings, should validate the type... + Logger.debug("Binding resource manager: "+finalName+ " to JDNI ENC as: " +ref.getRefName()); + bind(envCtx, ref.getRefName(), new LinkRef(finalName)); } } } + + // Bind resource env references + { + Iterator enum = beanMetaData.getResourceEnvReferences(); + while( enum.hasNext() ) + { + ResourceEnvRefMetaData resRef = (ResourceEnvRefMetaData) enum.next(); + String encName = resRef.getRefName(); + String jndiName = resRef.getJndiName(); + // Should validate the type... + Logger.debug("Binding env resource: "+jndiName+ " to JDNI ENC as: " +encName); + bind(envCtx, encName, new LinkRef(jndiName)); + } + } + + Logger.debug("End java:comp/env for EJB: "+beanMetaData.getEjbName()); } catch (NamingException e) { Logger.exception(e); e.getRootCause().printStackTrace(); throw new DeploymentException("Could not set up environment", e); } + + } 1.74 +2 -2 jboss/src/main/org/jboss/ejb/ContainerFactory.java Index: ContainerFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/ContainerFactory.java,v retrieving revision 1.73 retrieving revision 1.74 diff -u -r1.73 -r1.74 --- ContainerFactory.java 2001/06/09 19:34:44 1.73 +++ ContainerFactory.java 2001/06/10 20:50:31 1.74 @@ -83,7 +83,7 @@ * @author Peter Antman (pet...@ti...) * @author Scott Stark(Sco...@di...) * -* @version $Revision: 1.73 $ +* @version $Revision: 1.74 $ */ public class ContainerFactory extends org.jboss.util.ServiceMBeanSupport @@ -701,7 +701,7 @@ throws NamingException, DeploymentException { // Create classloader for this container - // Only used to identify bean. Not really used for class loading! + // Only used to unique the bean ENC and does not augment class loading container.setClassLoader( new URLClassLoader( new URL[ 0 ], cl ) ); // Create local classloader for this container // For loading resources that must come from the local jar. Not for loading classes! 1.30 +2 -8 jboss/src/main/org/jboss/ejb/EnterpriseContext.java Index: EnterpriseContext.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/EnterpriseContext.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- EnterpriseContext.java 2001/06/04 21:42:27 1.29 +++ EnterpriseContext.java 2001/06/10 20:50:31 1.30 @@ -41,7 +41,7 @@ * @author <a href="mailto:mar...@te...">Marc Fleury</a> * @author <a href="mailto:seb...@m4...">Sebastien Alborini</a> * @author <a href="mailto:ju...@jb...">Juha Lindfors</a> - * @version $Revision: 1.29 $ + * @version $Revision: 1.30 $ */ public abstract class EnterpriseContext { @@ -180,8 +180,6 @@ implements EJBContext { /** - * - * * @deprecated */ public Identity getCallerIdentity() @@ -257,8 +255,6 @@ } /** - * - * * @deprecated */ public Properties getEnvironment() @@ -289,8 +285,6 @@ } /** - * - * * @deprecated */ public boolean isCallerInRole(Identity id) @@ -309,7 +303,7 @@ // the security role refs in the descriptor but for backward // compability we're not enforcing this requirement. // - // TODO (2.3): add a conditional check using jboss.xml <secure> element + // TODO (2.3): add a conditional check using jboss.xml <enforce-ejb-restrictions> element // which will throw an exception in case no matching // security ref is found. Iterator it = getContainer().getBeanMetaData().getSecurityRoleReferences(); |