[Jboss-cvs] JBossAS SVN: r56620 - in branches/Branch_4_0/ejb3/src/main/org/jboss: . annotation/ejb annotation/ejb/cache/simple annotation/ejb/cache/tree annotation/security ejb ejb3 ejb3/cache ejb3/cache/simple ejb3/cache/tree ejb3/enc ejb3/entity ejb3/iiop ejb3/interceptor ejb3/mdb ejb3/mdb/inflow ejb3/metamodel ejb3/naming ejb3/naming/client ejb3/naming/client/java ejb3/remoting ejb3/security ejb3/service ejb3/session ejb3/stateful ejb3/stateless ejb3/timerservice ejb3/timerservice/jboss ejb3/timerservice/quartz ejb3/timerservice/quartz/jmx ejb3/tx injection metamodel metamodel/descriptor

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 7 22:18:57 EDT 2006


Author: bill.burke at jboss.com
Date: 2006-09-07 22:18:23 -0400 (Thu, 07 Sep 2006)
New Revision: 56620

Added:
   branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfigImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/PersistenceManagerImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfigImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb/DeclareRolesImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ClientKernelAbstraction.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxClientKernelAbstraction.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxEARImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/KernelAbstractionFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/DeploymentEjbResolver.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/DeploymentPersistenceUnitResolver.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/EjbModuleEjbResolver.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/EjbModulePersistenceUnitResolver.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/EJB3IIOPWebClassLoader.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/.cvsignore
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ActivationConfig.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationException.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/AssemblyDescriptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CacheConfig.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ClusterConfig.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CmpField.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CmrField.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Consumer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ContainerTransaction.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CurrentMessage.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbJarDD.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbJarDDObjectFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbRelation.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbRelationshipRole.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBean.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBeans.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EntityEnterpriseBean.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeClassInterceptors.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeDefaultInterceptors.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeList.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InitList.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InitMethod.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Inject.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Injectable.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Interceptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InterceptorBinding.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InterceptorOrder.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Interceptors.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/JBossDDObjectFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDestination.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDrivenBean.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDrivenDestination.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageProperties.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Method.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MethodAttributes.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MethodPermission.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/PoolConfig.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Producer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Query.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/QueryMethod.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RelationshipRoleSource.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Relationships.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoteBinding.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoveList.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoveMethod.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ResourceManager.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/SecurityIdentity.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Service.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/SessionEnterpriseBean.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/XmlAnnotation.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/BrainlessContext.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/client/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/client/java/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/client/java/javaURLContextFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/JavassistProxy.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/JavassistProxyReplacement.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/package.html
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerJob.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerService.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerServiceMBean.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/package.html
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsFieldInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsMethodInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBContextFieldInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBContextMethodInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EjbEncInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EncInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EntityManagerFactoryFieldInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EntityManagerFactoryMethodInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EnvEntryEncInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ExtendedPersistenceContextInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionContainer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionUtil.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/Injector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiInjectHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiMethodInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/LinkRefEncInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PcEncInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PersistenceContextHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PersistenceUnitHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PojoInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PuEncInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ResourceHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/TimerServiceFieldInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/TimerServiceMethodInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/UserTransactionFieldInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/UserTransactionMethodInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ValueEncInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/injection/WebServiceHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/BaseEjbRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/DDObjectFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EjbLocalRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EjbRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EnvEntry.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EnvironmentRefGroup.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/InjectionTarget.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/JndiRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/Listener.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/MessageDestination.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/MessageDestinationRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/NameValuePair.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/PersistenceContextRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/PersistenceUnitRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/Ref.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/ResourceEnvRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/ResourceRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/RunAs.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/SecurityRole.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/SecurityRoleRef.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/WebServiceRef.java
Modified:
   branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/RemoteBinding.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/RemoteBindingImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/security/SecurityDomainImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/BaseContext.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Container.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3AnnotationHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3HandlerFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3JmxDeployment.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxDependencyPolicy.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxKernelAbstraction.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/KernelAbstraction.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Pool.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/StatefulReplicationInterceptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationCacheLoader.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationEvictionPolicy.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationTreeCache.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulCacheLoader.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulEvictionPolicy.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/entity/PersistenceUnitDeployment.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsInterceptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfo.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInjector.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/LifecycleInterceptorHandler.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/LocalProducerFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ProducerFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ProducerManagerImpl.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/RemoteProducerFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/inflow/MessageInflowLocalProxy.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/Ejb3AuthenticationInterceptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptorFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RunAsSecurityInterceptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RunAsSecurityInterceptorFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/Ejb3TxPolicy.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java
   branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java
Log:


Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/RemoteBinding.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/RemoteBinding.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/RemoteBinding.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -43,7 +43,7 @@
 
    String interceptorStack() default "";
 
-   String clientBindUrl() default "socket://0.0.0.0:3873";
+   String clientBindUrl() default "";
 
    Class factory() default org.jboss.ejb3.remoting.RemoteProxyFactory.class;
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/RemoteBindingImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/RemoteBindingImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/RemoteBindingImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -46,7 +46,7 @@
    {
       jndi = "";
       stack = "";
-      bindUrl = "socket://0.0.0.0:3873";
+      bindUrl = "";
       proxyFactory = org.jboss.ejb3.remoting.RemoteProxyFactory.class;
    }
 
@@ -73,6 +73,11 @@
       this.jndi = jndi;
    }
    
+   public void setBindUrl(String bindUrl)
+   {
+      this.bindUrl = bindUrl;
+   }
+   
    public String jndiBinding()
    {
       return jndi;
@@ -113,4 +118,16 @@
    {
       return null;
    }
+   
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[RemoteBindingImpl:");
+      sb.append(", jndi=" + jndi);
+      sb.append(", stack=" + stack);
+      sb.append(", bindUrl=" + bindUrl);
+      sb.append(", proxyFactory=" + proxyFactory);
+      sb.append(']');
+      return sb.toString();
+   }
 }

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfigImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfigImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfigImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,63 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.annotation.ejb.cache.simple;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * @version <tt>$Revision: 45045 $</tt>
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class CacheConfigImpl implements CacheConfig
+{
+   private int maxSize = 100000;
+   private long idleTimeoutSeconds = 300;
+
+   public CacheConfigImpl()
+   {
+   }
+   
+   public int maxSize()
+   {
+      return maxSize;
+   }
+   
+   public void setMaxSize(int maxSize)
+   {
+      this.maxSize = maxSize;
+   }
+
+   public long idleTimeoutSeconds()
+   {
+      return idleTimeoutSeconds;
+   }
+   
+   public void setIdleTimeoutSeconds(long idleTimeoutSeconds)
+   {
+      this.idleTimeoutSeconds = idleTimeoutSeconds;
+   }
+
+   public Class<? extends Annotation> annotationType()
+   {
+      return CacheConfig.class;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/PersistenceManagerImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/PersistenceManagerImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/PersistenceManagerImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,54 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.annotation.ejb.cache.simple;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager;
+
+/**
+ * @version <tt>$Revision: 45045 $</tt>
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class PersistenceManagerImpl implements PersistenceManager
+{
+   private Class value = StatefulSessionFilePersistenceManager.class;
+
+   public PersistenceManagerImpl()
+   {
+   }
+   
+   public Class value()
+   {
+      return value;
+   }
+   
+   public void setValue(Class value)
+   {
+      this.value = value;
+   }
+
+   public Class<? extends Annotation> annotationType()
+   {
+      return PersistenceManager.class;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfigImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfigImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfigImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,74 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.annotation.ejb.cache.tree;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * @version <tt>$Revision: 45045 $</tt>
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class CacheConfigImpl implements CacheConfig
+{
+   private String name = "jboss.cache:service=EJB3SFSBClusteredCache";
+   private int maxSize = 100000;
+   private long idleTimeoutSeconds = 300;
+
+   public CacheConfigImpl()
+   {
+   }
+   
+   public String name()
+   {
+      return name;
+   }
+   
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+   
+   public int maxSize()
+   {
+      return maxSize;
+   }
+   
+   public void setMaxSize(int maxSize)
+   {
+      this.maxSize = maxSize;
+   }
+
+   public long idleTimeoutSeconds()
+   {
+      return idleTimeoutSeconds;
+   }
+   
+   public void setIdleTimeoutSeconds(long idleTimeoutSeconds)
+   {
+      this.idleTimeoutSeconds = idleTimeoutSeconds;
+   }
+
+   public Class<? extends Annotation> annotationType()
+   {
+      return CacheConfig.class;
+   }
+}

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/security/SecurityDomainImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/security/SecurityDomainImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/annotation/security/SecurityDomainImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -32,7 +32,7 @@
 public class SecurityDomainImpl implements SecurityDomain
 {
    private String value;
-   private String unauthenticatedPrincipal;
+   private String unauthenticatedPrincipal = null;
   
    public SecurityDomainImpl(String value)
    {
@@ -58,4 +58,14 @@
    {
       return org.jboss.annotation.security.SecurityDomain.class;
    }
+   
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("SecurityDomainImpl[");
+      sb.append("value=").append(value);
+      sb.append(", unauthenticatedPrincipal=").append(unauthenticatedPrincipal);
+      sb.append("]");
+      return sb.toString();
+   }
 }

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb/DeclareRolesImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb/DeclareRolesImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb/DeclareRolesImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,50 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb;
+
+
+/**
+ * // *
+ *
+ * @author <a href="mailto:bill at jboss.org">William DeCoste</a>
+ * @version $Revision: 45726 $
+ */
+public class DeclareRolesImpl implements javax.annotation.security.DeclareRoles
+{
+   private String[] v;
+
+   public DeclareRolesImpl(String[] v)
+   {
+      this.v = v;
+   }
+
+   public String[] value()
+   {
+      return v;
+   }
+
+   public Class annotationType()
+   {
+      return javax.annotation.security.DeclareRoles.class;
+   }
+
+}

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/AbstractPool.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/AbstractPool.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,7 +21,7 @@
 */
 package org.jboss.ejb3;
 
-import org.jboss.ejb3.injection.Injector;
+import org.jboss.injection.Injector;
 import org.jboss.ejb3.stateful.StatefulBeanContext;
 import org.jboss.logging.Logger;
 import org.jboss.util.id.GUID;
@@ -53,6 +53,10 @@
       this.container = container;
    }
 
+   public void setMaxSize(int maxSize)
+   {
+   }
+
    protected BeanContext create()
    {
       Object bean;
@@ -166,7 +170,6 @@
 
    public void remove(BeanContext ctx)
    {
-      Object bean = ctx.getInstance();
       container.invokePreDestroy(ctx);
       ctx.remove();
    }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/BaseContext.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/BaseContext.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/BaseContext.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -102,7 +102,6 @@
       {
          HashMap<Class,InterceptorInjector> interceptorInjectors = ((EJBContainer)container).getInterceptorInjectors();
          interceptorInstances = new HashMap<Class, Object>();
-
          for (InterceptorInfo info : interceptors)
          {
             try

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -320,9 +320,9 @@
       return ((EJBContainer)container).getBusinessObject(baseContext, businessInterface); 
    }
    
-   public Object getInvokedBusinessInterface() throws IllegalStateException
+   public Class getInvokedBusinessInterface() throws IllegalStateException
    {
-      return ((EJBContainer)container).getInvokedBusinessInterface(baseContext);
+      return ((SessionContainer)container).getInvokedBusinessInterface();
    }
 
    public MessageContext getMessageContext() throws IllegalStateException

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ClientKernelAbstraction.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ClientKernelAbstraction.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ClientKernelAbstraction.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3;
+
+import javax.management.ObjectName;
+
+import javax.management.MBeanServer;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface ClientKernelAbstraction
+{
+   Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws Exception;
+
+   public Object getAttribute(ObjectName name, String attribute) throws Exception;
+}

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Container.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Container.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Container.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -45,6 +45,11 @@
 
    TimerService getTimerService();
 
+   /**
+    * This method is called by EJBTimerServiceImpl to re-establish a persistent timer.
+    */
+   TimerService getTimerService(Object pKey);
+
    Pool getPool();
 
    Object construct();
@@ -75,8 +80,6 @@
 
    Context getEnc();
 
-   void addEncLinkRefEntry(String name, String mappedName);
-
    void processMetadata(DependencyPolicy dependencyPolicy);
 
    DependencyPolicy getDependencyPolicy();

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -391,7 +391,7 @@
       {
          if (e instanceof DeploymentException)
          {
-            throw (DeploymentException)e;
+            throw (DeploymentException) e;
          }
          throw new DeploymentException( "failed to initialize", e );
       }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -23,21 +23,36 @@
 
 import org.jboss.annotation.ejb.PoolClass;
 import org.jboss.aop.AspectManager;
+import org.jboss.aop.ClassAdvisor;
 import org.jboss.aop.ClassContainer;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.annotation.AnnotationElement;
 import org.jboss.aop.joinpoint.ConstructorInvocation;
-import org.jboss.ejb3.dd.AssemblyDescriptor;
-import org.jboss.ejb3.dd.EnterpriseBean;
-import org.jboss.ejb3.dd.PersistenceContextRef;
-import org.jboss.ejb3.injection.*;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
 import org.jboss.ejb3.interceptor.InterceptorInfo;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
 import org.jboss.ejb3.interceptor.InterceptorInjector;
 import org.jboss.ejb3.interceptor.LifecycleInterceptorHandler;
+import org.jboss.ejb3.metamodel.AssemblyDescriptor;
+import org.jboss.ejb3.metamodel.EnterpriseBean;
 import org.jboss.ejb3.security.JaccHelper;
 import org.jboss.ejb3.tx.UserTransactionImpl;
+import org.jboss.injection.DependsHandler;
+import org.jboss.injection.EJBHandler;
+import org.jboss.injection.EncInjector;
+import org.jboss.injection.InjectionContainer;
+import org.jboss.injection.InjectionHandler;
+import org.jboss.injection.InjectionUtil;
+import org.jboss.injection.Injector;
+import org.jboss.injection.JndiInjectHandler;
+import org.jboss.injection.PersistenceContextHandler;
+import org.jboss.injection.PersistenceUnitHandler;
+import org.jboss.injection.ResourceHandler;
+import org.jboss.injection.WebServiceHandler;
 import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.PersistenceContextRef;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
 import org.jboss.naming.Util;
 
 import javax.annotation.PostConstruct;
@@ -50,11 +65,23 @@
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.LinkRef;
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
-import java.lang.reflect.*;
-import java.util.*;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
 
 /**
  * Comment
@@ -62,7 +89,7 @@
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
  */
-public abstract class EJBContainer extends ClassContainer implements Container
+public abstract class EJBContainer extends ClassContainer implements Container, InjectionContainer
 {
 
    private static final Logger log = Logger.getLogger(EJBContainer.class);
@@ -79,7 +106,8 @@
 
    protected ClassLoader classloader;
 
-   protected Injector[] injectors;
+   // for performance there is an array.
+   protected List<Injector> injectors = new ArrayList<Injector>();
 
    protected Context enc;
    protected Context encEnv;
@@ -91,18 +119,12 @@
 
    protected Hashtable initialContextProperties;
 
-   protected HashMap envEntries = new HashMap();
+   protected Map<String, EncInjector> encInjectors = new HashMap<String, EncInjector>();
 
-   protected HashMap<String, String> encLinkRefEntries = new HashMap<String, String>();
-
-   protected HashMap<String, String> ejbRefDependencies = new HashMap<String, String>();
-   protected HashMap<String, String> puEncXmlEntries = new HashMap<String, String>();
-   protected HashMap<String, PersistenceContextRef> pcEncXmlEntries = new HashMap<String, PersistenceContextRef>();
-
    protected EnterpriseBean xml;
    protected AssemblyDescriptor assembly;
 
-   protected HashMap<AccessibleObject, Injector> encInjections = new HashMap<AccessibleObject, Injector>();
+   protected Map<String, Map<AccessibleObject, Injector>> encInjections = new HashMap<String, Map<AccessibleObject, Injector>>();
 
    protected InterceptorInfoRepository interceptorRepository;
 
@@ -110,20 +132,21 @@
 
    protected LinkedHashSet<InterceptorInfo> applicableInterceptors;
 
-   private HashMap<Class, InterceptorInjector> interceptorInjectors;
+   private HashMap<Class, InterceptorInjector> interceptorInjectors = new HashMap<Class, InterceptorInjector>();
 
    private Ejb3Deployment deployment;
 
    private DependencyPolicy dependencyPolicy;
 
    private String jaccContextId;
-   protected HashMap extendedPCs = new HashMap();
 
+   protected HashMap invokedMethod = new HashMap();
+
+
    /**
-    *
-    * @param name Advisor name
-    * @param manager Domain to get interceptor bindings from
-    * @param cl the EJB's classloader
+    * @param name                  Advisor name
+    * @param manager               Domain to get interceptor bindings from
+    * @param cl                    the EJB's classloader
     * @param beanClassName
     * @param ejbName
     * @param ctxProperties
@@ -136,7 +159,6 @@
                        InterceptorInfoRepository interceptorRepository, Ejb3Deployment deployment)
    {
       super(name, manager);
-      this.xml = xml;
       this.deployment = deployment;
       this.beanClassName = beanClassName;
       this.classloader = cl;
@@ -173,21 +195,17 @@
       this.interceptorRepository = interceptorRepository;
       this.interceptorRepository.addBeanClass(clazz.getName());
    }
-
-   public HashMap<String, String> getEjbRefDependencies()
+   
+   public EnvironmentRefGroup getEnvironmentRefGroup()
    {
-      return ejbRefDependencies;
+      return xml;
    }
 
-   public HashMap<String, String> getPuEncXmlEntries()
+   public List<Injector> getInjectors()
    {
-      return puEncXmlEntries;
+      return injectors;
    }
 
-   public HashMap<String, PersistenceContextRef> getPcEncXmlEntries()
-   {
-      return pcEncXmlEntries;
-   }
 
    public String getJaccContextId()
    {
@@ -222,7 +240,7 @@
    /**
     * introspects EJB container to find all dependencies
     * and initialize any extra metadata.
-    *
+    * <p/>
     * This must be called before container is registered with any microcontainer
     *
     * @param dependencyPolicy
@@ -230,24 +248,46 @@
    public void processMetadata(DependencyPolicy dependencyPolicy)
    {
       this.dependencyPolicy = dependencyPolicy;
-      PersistenceContextHandler.loadDependencies(xml, this, clazz, true);
-      PersistenceUnitHandler.loadDependencies(xml, this, clazz, true);
-      if (xml != null)
+      // XML must be done first so that any annotation overrides are initialized
+
+      // todo injection handlers should be pluggable from XML
+      Collection<InjectionHandler> handlers = new ArrayList<InjectionHandler>();
+      handlers.add(new EJBHandler());
+      handlers.add(new DependsHandler());
+      handlers.add(new JndiInjectHandler());
+      handlers.add(new PersistenceContextHandler());
+      handlers.add(new PersistenceUnitHandler());
+      handlers.add(new ResourceHandler());
+      handlers.add(new WebServiceHandler());
+
+      ClassLoader old = Thread.currentThread().getContextClassLoader();
+      Thread.currentThread().setContextClassLoader(classloader);
+      try
       {
-         for (String depends : xml.getDependencies())
+         // EJB container's XML must be processed before interceptor's as it may override interceptor's references
+         for (InjectionHandler handler : handlers) handler.loadXml(xml, this);
+
+         Map<AccessibleObject, Injector> tmp = InjectionUtil.processAnnotations(this, handlers, getBeanClass());
+         injectors.addAll(tmp.values());
+
+         initialiseInterceptors();
+         for (InterceptorInfo interceptorInfo : applicableInterceptors)
          {
-            dependencyPolicy.addDependency(depends);
+            for (InjectionHandler handler : handlers)
+            {
+               handler.loadXml(interceptorInfo.getXml(), this);
+            }
          }
+         for (InterceptorInfo interceptorInfo : applicableInterceptors)
+         {
+            Map<AccessibleObject, Injector> tmpInterceptor = InjectionUtil.processAnnotations(this, handlers, interceptorInfo.getClazz());
+            InterceptorInjector injector = new InterceptorInjector(this, interceptorInfo, tmpInterceptor);
+            interceptorInjectors.put(interceptorInfo.getClazz(), injector);
+         }
       }
-      DependsHandler.loadDependencies(this, clazz);
-      EJBHandler.loadDependencies(xml, this, clazz, true);
-      initialiseInterceptors();
-      for (InterceptorInfo interceptorInfo : applicableInterceptors)
+      finally
       {
-         PersistenceContextHandler.loadDependencies(interceptorInfo.getXml(), this, interceptorInfo.getClazz(), false);
-         PersistenceUnitHandler.loadDependencies(interceptorInfo.getXml(), this, interceptorInfo.getClazz(), false);
-         DependsHandler.loadDependencies(this, interceptorInfo.getClazz());
-         EJBHandler.loadDependencies(interceptorInfo.getXml(), this, interceptorInfo.getClazz(), true);
+         Thread.currentThread().setContextClassLoader(old);
       }
    }
 
@@ -294,26 +334,17 @@
       return interceptorInjectors;
    }
 
-   public ClassLoader getClassloader()
-   {
-      return classloader;
-   }
 
-   public HashMap<String, String> getEncLinkRefEntries()
+   public Map<String, EncInjector> getEncInjectors()
    {
-      return encLinkRefEntries;
+      return encInjectors;
    }
 
-   public void addEncLinkRefEntry(String name, String mappedName)
+   public ClassLoader getClassloader()
    {
-      encLinkRefEntries.put(name, mappedName);
+      return classloader;
    }
 
-   public void addEncInjector(AccessibleObject acc, Injector inj)
-   {
-      encInjections.put(acc, inj);
-   }
-
    public InitialContext getInitialContext()
    {
       try
@@ -329,26 +360,11 @@
       }
    }
 
-   public HashMap<AccessibleObject, Injector> getEncInjections()
+   public Map<String, Map<AccessibleObject, Injector>> getEncInjections()
    {
       return encInjections;
    }
 
-   public boolean hasEnvEntry(String name)
-   {
-      return envEntries.containsKey(name);
-   }
-
-   public void addEnvEntry(String name, String type, String value) throws ClassNotFoundException
-   {
-         envEntries.put(name, getEnvEntryValue(name, type, value));
-   }
-
-   public boolean hasEncEntry(String name)
-   {
-      return encLinkRefEntries.containsKey(name);
-   }
-
    public Context getEnc()
    {
       return enc;
@@ -359,63 +375,6 @@
       return enc;
    }
 
-   protected Object getEnvEntryValue(String name, String entryType, String value) throws ClassNotFoundException
-   {
-      Class type = this.classloader.loadClass(entryType);
-      if (type == String.class)
-      {
-         return value;
-      }
-      else if (type == Integer.class)
-      {
-         return new Integer(value);
-      }
-      else if (type == Long.class)
-      {
-         return new Long(value);
-      }
-      else if (type == Double.class)
-      {
-         return new Double(value);
-      }
-      else if (type == Float.class)
-      {
-         return new Float(value);
-      }
-      else if (type == Byte.class)
-      {
-         return new Byte(value);
-      }
-      else if (type == Character.class)
-      {
-         String input = value;
-         if (input == null || input.length() == 0)
-         {
-            return new Character((char) 0);
-         }
-         else
-         {
-            if (input.length() > 1)
-               // TODO: Add deployment context
-               log.warn("Warning character env-entry is too long: binding="
-                        + name + " value=" + input);
-            return new Character(input.charAt(0));
-         }
-      }
-      else if (type == Short.class)
-      {
-         return new Short(value);
-      }
-      else if (type == Boolean.class)
-      {
-         return new Boolean(value);
-      }
-      else
-      {
-         return value;
-      }
-   }
-
    public Hashtable getInitialContextProperties()
    {
       return initialContextProperties;
@@ -500,33 +459,22 @@
             break;
          }
       }
-      createEnvEntries();
       initializePool();
-      resolveInterceptorInjectors();
 
-      // add extendedPC injectors to be first in list
-      ArrayList injectors2 = new ArrayList();
-      injectors2.addAll(extendedPCs.values());
-      if (injectors != null) injectors2.addAll(Arrays.asList(injectors));
-      injectors = (Injector[])injectors2.toArray(new Injector[injectors2.size()]);
-      if (pool != null) pool.setInjectors(injectors);
+      for (EncInjector injector : encInjectors.values())
+      {
+         injector.inject(this);   
+      }
 
+      // creating of injector array should come after injection into ENC as an ENC injector
+      // may add additional injectors into the injector list.  An example is an extended persistence
+      // context which mush be created and added to the SFSB bean context.
+
+      Injector[] injectors2 = injectors.toArray(new Injector[injectors.size()]);
+      if (pool != null) pool.setInjectors(injectors2);
+
       createCallbackHandler();
 
-      for (String encName : encLinkRefEntries.keySet())
-      {
-         String mappedName = encLinkRefEntries.get(encName);
-         try
-         {
-            Util.bind(enc, encName, new LinkRef(mappedName));
-            log.debug("binding enc: " + encName + " to " + mappedName);
-         } catch (NamingException e)
-         {
-            NamingException namingException = new NamingException("Could not bind EJB container with ejb name " + ejbName + " into JNDI under jndiName: " + enc.getNameInNamespace() + "/" + encName);
-            namingException.setRootCause(e);
-            throw namingException;
-         }
-      }
       JaccHelper.configureContainer(jaccContextId, this);
       log.info("STARTED EJB: " + clazz.getName() + " ejbName: " + ejbName);
    }
@@ -539,28 +487,6 @@
    {
    }
 
-   protected void createEnvEntries() throws NamingException
-   {
-      Iterator names = envEntries.keySet().iterator();
-      while (names.hasNext())
-      {
-         String name = (String) names.next();
-         Object value = envEntries.get(name);
-              
-         try 
-         {
-            Util.bind(encEnv,
-                      name,
-                      value);
-         } catch (NamingException e)
-         {
-            NamingException namingException = new NamingException("Could not bind env entry for ejb name " + ejbName + " into JNDI under jndiName: " + encEnv.getNameInNamespace() + "/" + name);
-            namingException.setRootCause(e);
-            throw namingException;
-         }
-      }
-   }
-
    public void initializePool() throws Exception
    {
       PoolClass poolClass = (PoolClass) resolveAnnotation(PoolClass.class);
@@ -571,7 +497,7 @@
       pool.initialize(this, beanContextClass, clazz, maxSize, timeout);
 
       resolveInjectors();
-      pool.setInjectors(injectors);
+      pool.setInjectors(injectors.toArray(new Injector[injectors.size()]));
    }
 
    public void invokePostConstruct(BeanContext beanContext)
@@ -609,11 +535,6 @@
 
    public static final String ENTITY_MANAGER_FACTORY = "EntityManagerFactory";
 
-   public HashMap getExtendedPCs()
-   {
-      return extendedPCs;
-   }
-
    protected void resolveInjectors() throws Exception
    {
       ThreadLocalENCFactory.push(enc);
@@ -622,24 +543,14 @@
          Thread.currentThread().setContextClassLoader(classloader);
          try
          {
-            Util.bind(enc, "UserTransaction", new UserTransactionImpl());
-         } catch (NamingException e)
+            Util.rebind(enc, "UserTransaction", new UserTransactionImpl());
+         }
+         catch (NamingException e)
          {
             NamingException namingException = new NamingException("Could not bind user transaction for ejb name " + ejbName + " into JNDI under jndiName: " + enc.getNameInNamespace() + "/" + "UserTransaction");
             namingException.setRootCause(e);
             throw namingException;
          }
-
-         List list = new ArrayList();
-         PersistenceContextHandler.loadInjectors(this);
-         PersistenceUnitHandler.loadInjectors(this);
-         list.addAll(JndiInjectHandler.loadInjectors(this));
-         ResourceHandler.loadInjectors(this);
-         WebServiceHandler.loadInjectors(this);
-         EJBHandler.loadInjectors(this);
-         list.addAll(DependsHandler.loadInjectors(this));
-         list.addAll(encInjections.values());
-         injectors = (Injector[]) list.toArray(new Injector[list.size()]);
       }
       finally
       {
@@ -647,39 +558,17 @@
       }
    }
 
-   protected void resolveInterceptorInjectors() throws Exception
-   {
-      ThreadLocalENCFactory.push(enc);
-      try
-      {
-         Thread.currentThread().setContextClassLoader(classloader);
-         if (applicableInterceptors != null && applicableInterceptors.size() > 0)
-         {
-            interceptorInjectors = new HashMap<Class, InterceptorInjector>();
-            for (InterceptorInfo interceptorInfo : applicableInterceptors)
-            {
-               InterceptorInjector injector = new InterceptorInjector(this, interceptorInfo);
-               interceptorInjectors.put(interceptorInfo.getClazz(), injector);
-            }
-         }
-      }
-      finally
-      {
-         ThreadLocalENCFactory.pop();
-      }
-   }
-
    protected void createCallbackHandler()
    {
       try
       {
          callbackHandler = new LifecycleInterceptorHandler(this,
-                                                           getHandledCallbacks());
+                 getHandledCallbacks());
       }
       catch (Exception e)
       {
          throw new RuntimeException("Error creating callback handler for bean "
-                                    + beanClassName, e);
+                 + beanClassName, e);
       }
    }
 
@@ -717,12 +606,12 @@
          log.debug("All applicable interceptor classes: " + applicableInterceptors);
       }
    }
-   
+
    public Object getBusinessObject(BeanContext beanContext, Class businessObject) throws IllegalStateException
    {
       throw new IllegalStateException("Not implemented");
    }
-   
+
    public Object getInvokedBusinessInterface(BeanContext beanContext) throws IllegalStateException
    {
       throw new IllegalStateException("Not implemented");
@@ -730,11 +619,11 @@
 
    protected Object getInvokedInterface(Method method)
    {
-      Remote remoteAnnotation = (Remote)resolveAnnotation(Remote.class);
+      Remote remoteAnnotation = (Remote) resolveAnnotation(Remote.class);
       if (remoteAnnotation != null)
       {
          Class[] remotes = remoteAnnotation.value();
-         for (int i = 0 ; i < remotes.length ; ++i)
+         for (int i = 0; i < remotes.length; ++i)
          {
             try
             {
@@ -742,25 +631,26 @@
                return remotes[i];
             }
             catch (NoSuchMethodException e)
-            {}
+            {
+            }
          }
       }
-      
-      Local localAnnotation = (Local)resolveAnnotation(Local.class);
+
+      Local localAnnotation = (Local) resolveAnnotation(Local.class);
       if (localAnnotation != null)
       {
          Class[] locals = localAnnotation.value();
-         for (int i = 0 ; i < locals.length ; ++i)
+         for (int i = 0; i < locals.length; ++i)
          {
             Method[] interfaceMethods = locals[i].getMethods();
-            for ( int j = 0 ; j < interfaceMethods.length ; ++j)
+            for (int j = 0; j < interfaceMethods.length; ++j)
             {
                if (interfaceMethods[j].equals(method))
                   return locals[i];
             }
          }
       }
-      
+
       return null;
    }
 
@@ -771,7 +661,7 @@
       {
          Class ann = classloader.loadClass(annotation);
          if (!ann.isAnnotation()) return null;
-         Retention retention = (Retention)ann.getAnnotation(Retention.class);
+         Retention retention = (Retention) ann.getAnnotation(Retention.class);
          if (retention != null && retention.value() == RetentionPolicy.RUNTIME) return ann;
 
       }
@@ -803,7 +693,6 @@
    @Override
    public boolean hasAnnotation(Method m, String annotation)
    {
-
       if (annotations.hasAnnotation(m, annotation)) return true;
       try
       {
@@ -851,4 +740,128 @@
          throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
       }
    }
+
+   public Container resolveEjbContainer(String link, Class businessIntf)
+   {
+      return deployment.getEjbContainer(link, businessIntf);
+   }
+
+   public Container resolveEjbContainer(Class businessIntf) throws NameNotFoundException
+   {
+      return deployment.getEjbContainer(businessIntf);
+   }
+
+   public <T> T getAnnotation(Class<T> annotationType, Class clazz)
+   {
+      if (clazz == this.getBeanClass())
+      {
+         return (T) resolveAnnotation(annotationType);
+      }
+      return (T) clazz.getAnnotation(annotationType);
+   }
+
+   public <T> T getAnnotation(Class<T> annotationType, Class clazz, Method method)
+   {
+      if (clazz == this.getBeanClass())
+      {
+         return (T) resolveAnnotation(method, annotationType);
+      }
+      Class aclass = annotationType;
+      return (T) method.getAnnotation(aclass);
+   }
+   
+   public <T> T getAnnotation(Class<T> annotationType, Method method)
+   {
+      return (T) resolveAnnotation(method, annotationType);
+   }
+
+   public <T> T getAnnotation(Class<T> annotationType, Class clazz, Field field)
+   {
+      if (clazz == this.getBeanClass())
+      {
+         return (T) resolveAnnotation(field, annotationType);
+      }
+      Class aclass = annotationType;
+      return (T) field.getAnnotation(aclass);
+   }
+   
+   public <T> T getAnnotation(Class<T> annotationType, Field field)
+   {
+      return (T) resolveAnnotation(field, annotationType);
+   }
+   
+   public Object resolveAnnotation(Method m, Class annotation)
+   {
+      Object value = super.resolveAnnotation(m, annotation);
+      if (value == null && m.isBridge()) value = getBridgedAnnotation(m, annotation);
+      return value;
+   }
+   
+   protected Object getBridgedAnnotation(Method bridgeMethod, Class annotation)
+   {
+      Method[] methods = bridgeMethod.getDeclaringClass().getMethods();
+      int i = 0;
+      boolean found = false;
+      Class[] bridgeParams = bridgeMethod.getParameterTypes();
+      while (i < methods.length && !found)
+      {
+         if (!methods[i].isBridge() && methods[i].getName().equals(bridgeMethod.getName()))
+         {
+            Class[] params = methods[i].getParameterTypes();
+            if (params.length == bridgeParams.length)
+            {
+               int j = 0;
+               boolean matches = true;
+               while (j < params.length && matches)
+               {
+                  if (!bridgeParams[j].isAssignableFrom(params[j]))
+                     matches = false;
+                  ++j;
+               }
+               
+               if (matches)
+                  return resolveAnnotation(methods[i], annotation);
+            }
+         }
+         ++i;
+      }
+ 
+      return null;
+   }
+   
+   public Object resolveAnnotation(Method m, Class[] annotationChoices)
+   {
+      Object value = null;
+      int i = 0;
+      while (value == null && i < annotationChoices.length){
+         value = resolveAnnotation(m, annotationChoices[i++]);
+      }
+      
+      return value;
+   }
+
+   public String getIdentifier()
+   {
+      return getEjbName();
+   }
+
+   public String getDeploymentDescriptorType()
+   {
+      return "ejb-jar.xml";
+   }
+
+   public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
+   {
+      return deployment.getPersistenceUnitDeployment(unitName);
+   }
+
+   public String getEjbJndiName(Class businessInterface) throws NameNotFoundException
+   {
+      return deployment.getEjbJndiName(businessInterface);
+   }
+
+   public String getEjbJndiName(String link, Class businessInterface)
+   {
+      return deployment.getEjbJndiName(link, businessInterface);
+   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3AnnotationHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3AnnotationHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3AnnotationHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -28,7 +28,8 @@
 import org.jboss.annotation.ejb.ResourceAdapter;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.DomainDefinition;
-import org.jboss.ejb3.dd.EnterpriseBean;
+import org.jboss.ejb3.metamodel.EnterpriseBean;
+import org.jboss.ejb3.metamodel.MessageDrivenBean;
 import org.jboss.ejb3.mdb.ConsumerContainer;
 import org.jboss.ejb3.mdb.MDB;
 import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
@@ -55,8 +56,6 @@
       STATELESS, STATEFUL, MESSAGE_DRIVEN, ENTITY, SERVICE, CONSUMER
    }
 
-   ;
-
    protected DeploymentUnit di;
 
    protected ClassFile cf;
@@ -70,7 +69,6 @@
    protected String defaultSLSBDomain;
    protected String defaultSFSBDomain;
    protected String defaultMDBDomain;
-   protected String defaultMessagingInflowDrivenBeanDomain;
    protected String defaultServiceDomain;
    protected String defaultConsumerDomain;
    protected Ejb3Deployment deployment;
@@ -87,7 +85,6 @@
       defaultMDBDomain = deployment.getDefaultMDBDomain();
       defaultServiceDomain = deployment.getDefaultServiceDomain();
       defaultConsumerDomain = deployment.getDefaultConsumerDomain();
-      defaultMessagingInflowDrivenBeanDomain = deployment.getDefaultMessageInflowDrivenBeanDomain();
    }
 
    public void setCtxProperties(Hashtable ctxProperties)
@@ -132,14 +129,12 @@
          {
             StatelessContainer container = getStatelessContainer(ejbIndex);
             container.setJaccContextId(getJaccContextId());
-            container.setDefaultClientBinding(deployment.getDefaultClientBinding());
             containers.add(container);
          }
          else if (ejbType == EJB_TYPE.STATEFUL)
          {
             StatefulContainer container = getStatefulContainer(ejbIndex);
             container.setJaccContextId(getJaccContextId());
-            container.setDefaultClientBinding(deployment.getDefaultClientBinding());
             containers.add(container);
          }
          else if (ejbType == EJB_TYPE.MESSAGE_DRIVEN)
@@ -234,11 +229,7 @@
 
    protected String getMDBDomainName(int ejbIndex)
    {
-      String domainName = defaultMDBDomain;
-      if (ejbClass.isAnnotationPresent(ResourceAdapter.class))
-         domainName = defaultMessagingInflowDrivenBeanDomain;
-
-      return domainName;
+      return defaultMDBDomain;
    }
 
    protected void createProxyFactories()
@@ -254,7 +245,7 @@
    protected MDB getMDB(int ejbIndex, EnterpriseBean xml) throws Exception
    {
       String domainName = getMDBDomainName(ejbIndex);
-
+      
       String containerName = getAspectDomain(ejbIndex, domainName);
       DomainDefinition domain = AspectManager.instance().getContainer(containerName);
 
@@ -264,12 +255,6 @@
 
       MDB container = new MDB(ejbNames.get(ejbIndex), (AspectManager) domain.getManager(), di.getClassLoader(), cf.getName(),
               ctxProperties, di.getInterceptorInfoRepository(), deployment);
-      if (domainName.equals(defaultMessagingInflowDrivenBeanDomain))
-      {
-         JBossMessageEndpointFactory factory = new JBossMessageEndpointFactory();
-         factory.setContainer(container);
-         container.setMessageEndpointFactory(factory);
-      }
 
       return container;
    }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -22,15 +22,15 @@
 package org.jboss.ejb3;
 
 import javassist.bytecode.ClassFile;
+import org.hibernate.cfg.EJB3DTDEntityResolver;
 import org.hibernate.ejb.packaging.PersistenceMetadata;
 import org.hibernate.ejb.packaging.PersistenceXmlLoader;
-import org.hibernate.cfg.EJB3DTDEntityResolver;
+import org.jboss.ejb3.enc.EjbModuleEjbResolver;
+import org.jboss.ejb3.enc.EjbModulePersistenceUnitResolver;
 import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.ejb3.remoting.RemoteProxyFactory;
 import org.jboss.logging.Logger;
 import org.jboss.util.file.ArchiveBrowser;
 import org.jboss.util.file.ClassFileFilter;
-import org.jboss.util.xml.JBossEntityResolver;
 
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -43,7 +43,11 @@
 import java.io.DataInputStream;
 import java.io.InputStream;
 import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
 
 /**
  * An EjbModule represents a collection of beans that are deployed as a unit.
@@ -65,32 +69,32 @@
    protected boolean hasEntities;
    protected List<String> explicitEntityClasses = new ArrayList<String>();
 
-   protected List<PersistenceUnitDeployment> persistenceUnitDeployments;
+   protected List<PersistenceUnitDeployment> persistenceUnitDeployments = new ArrayList<PersistenceUnitDeployment>();
+;
 
    protected String defaultSLSBDomain = "Stateless Bean";
    protected String defaultSFSBDomain = "Stateful Bean";
    protected String defaultMDBDomain = "Message Driven Bean";
-   protected String defaultMessageInflowDrivenDomain = "Message Inflow Driven Bean";
    protected String defaultConsumerDomain = "Consumer Bean";
    protected String defaultServiceDomain = "Service Bean";
    protected InitialContext initialContext;
 
-   // This is used to push the default client binding to the ProxyDeployer
-   protected String defaultClientBinding = RemoteProxyFactory.DEFAULT_CLIENT_BINDING;
-
    protected KernelAbstraction kernelAbstraction;
 
    // used for @Management interfaces
    protected MBeanServer mbeanServer;
 
    protected EAR ear;
+   protected EjbModuleEjbResolver ejbRefResolver;
+   protected EjbModulePersistenceUnitResolver persistenceUnitResolver;
 
    //The JACC PolicyConfiguration
    PolicyConfiguration pc;
 
-   public Ejb3Deployment(DeploymentUnit di)
+   public Ejb3Deployment(DeploymentUnit di, EAR ear)
    {
       this.di = di;
+      this.ear = ear;
       try
       {
          initialContext = EJB3Util.getInitialContext(di.getJndiProperties());
@@ -99,6 +103,8 @@
       {
          throw new RuntimeException(e);
       }
+      ejbRefResolver = new EjbModuleEjbResolver(ear, di.getShortName(), ejbContainers, this);
+      persistenceUnitResolver = new EjbModulePersistenceUnitResolver(persistenceUnitDeployments, ear, ejbContainers);
    }
 
    public EAR getEar()
@@ -132,11 +138,6 @@
    }
 
 
-   public String getDefaultClientBinding()
-   {
-      return defaultClientBinding;
-   }
-
    /**
     * Returns a partial MBean attribute name of the form
     * ",ear=foo.ear,jar=foo.jar"
@@ -186,11 +187,6 @@
       return defaultMDBDomain;
    }
 
-   public String getDefaultMessageInflowDrivenBeanDomain()
-   {
-      return defaultMessageInflowDrivenDomain;
-   }
-
    /**
     * The default AOP domain for message driven beans.
     *
@@ -234,192 +230,38 @@
 
    public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
    {
-      if ("".equals(unitName))
-      {
-         if (persistenceUnitDeployments == null)
-         {
-            throw new NameNotFoundException("EMPTY STRING unitName but there is no deployments in scope");
-         }
-         if (persistenceUnitDeployments.size() == 1 && ejbContainers.size() > 0)
-         {
-            return persistenceUnitDeployments.get(0);
-         }
-         else if (persistenceUnitDeployments.size() > 1)
-         {
-            throw new NameNotFoundException("EMPTY STRING unitName and there is more than one scoped persistence unit");
-         }
-         throw new NameNotFoundException("There is no default persistence unit in this deployment.");
-      }
-      int hashIndex = unitName.indexOf('#');
-      if (hashIndex != -1)
-      {
-         String relativePath = unitName.substring(0, hashIndex);
-         String name = unitName.substring(hashIndex + 1);
-         if (ear == null)
-         {
-            String relativeJarName = relativePath.substring(3);
-            // look in global EJB jars.
-            for (PersistenceUnitDeployment pud : PersistenceUnitRegistry.getPersistenceUnits())
-            {
-               String jarName = pud.getDeployment().getDeploymentUnit().getShortName() + ".jar";
-               if (pud.getDeployment().getEar() == null
-                       && jarName.equals(relativeJarName)
-                       && pud.getEntityManagerName().equals(name)
-                       && pud.isScoped())
-               {
-                  return pud;
-               }
-            }
-            return null;
-         }
-         Ejb3Deployment dep = ear.findRelativeDeployment(relativePath);
-         if (dep == null)
-         {
-            return null;
-         }
-         PersistenceUnitDeployment rtn = dep.getPersistenceUnitDeploymentInternal(name);
-         return rtn;
-      }
-      PersistenceUnitDeployment rtn = getPersistenceUnitDeploymentInternal(unitName);
-      if (rtn != null) return rtn;
-
-      for (PersistenceUnitDeployment deployment : PersistenceUnitRegistry.getPersistenceUnits())
-      {
-         if (deployment.isScoped()) continue;
-         if (deployment.getEntityManagerName().equals(unitName)) return deployment;
-      }
-      return rtn;
+      return persistenceUnitResolver.getPersistenceUnitDeployment(unitName);
    }
 
-   protected PersistenceUnitDeployment getPersistenceUnitDeploymentInternal(String unitName)
+   public PersistenceUnitDeployment getPersistenceUnitDeploymentInternal(String unitName)
    {
-      if (persistenceUnitDeployments != null)
-      {
-         for (PersistenceUnitDeployment deployment : persistenceUnitDeployments)
-         {
-            if (deployment.getEntityManagerName().equals(unitName))
-            {
-               return deployment;
-            }
-         }
-      }
-      return null;
+      return persistenceUnitResolver.getPersistenceUnitDeploymentInternal(unitName);
    }
 
 
    public EJBContainer getEjbContainer(String ejbLink, Class businessIntf)
    {
-      int hashIndex = ejbLink.indexOf('#');
-      if (hashIndex != -1)
-      {
-         if (ear == null) return null;
-         String relativePath = ejbLink.substring(0, hashIndex);
-         Ejb3Deployment dep = ear.findRelativeDeployment(relativePath);
-         if (dep == null) return null;
-         String ejbName = ejbLink.substring(hashIndex);
-         return dep.getEjbContainer(ejbName, businessIntf);
-      }
-      for (Object obj : ejbContainers.values())
-      {
-         EJBContainer container = (EJBContainer) obj;
-         if (container.getEjbName().equals(ejbLink))
-         {
-            return container;
-         }
-      }
-      for (Object obj : Ejb3Registry.getContainers())
-      {
-         EJBContainer container = (EJBContainer) obj;
-         if (container.getEjbName().equals(ejbLink))
-         {
-            return container;
-         }
-      }
-      return null;
+      return ejbRefResolver.getEjbContainer(ejbLink, businessIntf);
    }
 
    public String getEjbJndiName(String ejbLink, Class businessIntf)
    {
-      EJBContainer container = getEjbContainer(ejbLink, businessIntf);
-      if (container == null) return null;
-      return ProxyFactoryHelper.getJndiName(container, businessIntf);
+      return ejbRefResolver.getEjbJndiName(ejbLink, businessIntf);
    }
 
    public EJBContainer getEjbContainer(Ejb3Deployment deployment, Class businessIntf) throws NameNotFoundException
    {
-      EJBContainer container = null;
-      // search in myself
-      for (Object obj : deployment.ejbContainers.values())
-      {
-         EJBContainer newContainer = (EJBContainer) obj;
-         if (container == newContainer) continue;
-         if (ProxyFactoryHelper.publishesInterface(newContainer, businessIntf))
-         {
-            if (container != null) throw new NameNotFoundException("duplicated in " + di.getShortName());
-            container = newContainer;
-         }
-      }
-      return container;
+      return ejbRefResolver.getEjbContainer(deployment, businessIntf);
    }
 
    public EJBContainer getEjbContainer(Class businessIntf) throws NameNotFoundException
    {
-      EJBContainer rtnContainer = null;
-      // search in myself
-      rtnContainer = getEjbContainer(this, businessIntf);
-      if (rtnContainer != null) return rtnContainer;
-      // search in EAR
-      String jarName = null;
-      if (ear != null)
-      {
-         for (Ejb3Deployment deployment : ear.getEjbDeployments())
-         {
-            EJBContainer newContainer = getEjbContainer(deployment, businessIntf);
-            if (rtnContainer == newContainer) continue; // don't check self
-            if (rtnContainer != null && newContainer != null)
-            {
-               throw new NameNotFoundException("duplicated in .ear within " + jarName +
-                       " and " + deployment.getDeploymentUnit().getShortName());
-            }
-            if (newContainer != null)
-            {
-               rtnContainer = newContainer;
-               jarName = deployment.getDeploymentUnit().getShortName();
-            }
-         }
-      }
-      if (rtnContainer != null)
-      {
-         return rtnContainer;
-      }
-      // search everywhere
-      Iterator containers = Ejb3Registry.getContainers().iterator();
-      while (containers.hasNext())
-      {
-         Container container = (Container)containers.next();
-         EJBContainer ejbContainer = (EJBContainer) container;
-         if (ejbContainer == rtnContainer) continue;
-         if (ProxyFactoryHelper.publishesInterface(container, businessIntf))
-         {
-            if (rtnContainer != null)
-            {
-               throw new NameNotFoundException("duplicated in " + ejbContainer.getDeployment().getDeploymentUnit().getShortName()
-                       + " and " + jarName);
-            }
-            rtnContainer = ejbContainer;
-            jarName = ejbContainer.getDeployment().getDeploymentUnit().getShortName();
-         }
-      }
-      if (rtnContainer != null) return rtnContainer;
-      throw new NameNotFoundException("not used by any EJBs");
+      return ejbRefResolver.getEjbContainer(businessIntf);
    }
 
    public String getEjbJndiName(Class businessIntf) throws NameNotFoundException
    {
-      EJBContainer container = getEjbContainer(businessIntf);
-      String jndiName = ProxyFactoryHelper.getJndiName(container, businessIntf);
-      if (jndiName == null) throw new NameNotFoundException("not used by any EJBs");
-      return jndiName;
+      return ejbRefResolver.getEjbJndiName(businessIntf);
    }
 
    protected void processEJBContainerMetadata(Container container)
@@ -600,7 +442,6 @@
 
       // scope the unitName if this is an ejb archive
       List<PersistenceMetadata> persistenceMetadata = PersistenceXmlLoader.deploy(persistenceXmlUrl, new HashMap(), new EJB3DTDEntityResolver());
-      persistenceUnitDeployments = new ArrayList<PersistenceUnitDeployment>();
       for (PersistenceMetadata metadata : persistenceMetadata)
       {
          String earShortName = ear == null ? null : ear.getShortName();
@@ -660,6 +501,7 @@
             kernelAbstraction.uninstall(on.getCanonicalName());
             Container container = (Container) ejbContainers.get(on);
             Ejb3Registry.unregister(container);
+            container.stop();
          }
          catch (Exception e)
          {

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,58 +21,60 @@
  */
 package org.jboss.ejb3;
 
-import java.io.IOException;
-import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-import javax.annotation.security.DenyAll;
-import javax.annotation.security.PermitAll;
-import javax.annotation.security.RolesAllowed;
-import javax.annotation.security.RolesReferenced;
-import javax.annotation.PostConstruct;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.ExcludeClassInterceptors;
-import javax.interceptor.ExcludeDefaultInterceptors;
-import javax.ejb.Init;
-import javax.interceptor.Interceptors;
-import javax.ejb.Local;
-import javax.ejb.LocalHome;
-import javax.ejb.MessageDriven;
-import javax.ejb.PostActivate;
-import javax.annotation.PreDestroy;
-import javax.ejb.PrePassivate;
-import javax.ejb.Remote;
-import javax.ejb.RemoteHome;
-import javax.ejb.Remove;
-import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.ejb.TransactionManagement;
 
 import javassist.bytecode.ClassFile;
-import org.jboss.annotation.*;
-import org.jboss.annotation.ejb.*;
+import org.jboss.annotation.IgnoreDependency;
+import org.jboss.annotation.IgnoreDependencyImpl;
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.ClusteredImpl;
+import org.jboss.annotation.ejb.Consumer;
+import org.jboss.annotation.ejb.ConsumerImpl;
+import org.jboss.annotation.ejb.CurrentMessage;
+import org.jboss.annotation.ejb.CurrentMessageImpl;
+import org.jboss.annotation.ejb.DefaultActivationSpecs;
+import org.jboss.annotation.ejb.DefaultActivationSpecsImpl;
+import org.jboss.annotation.ejb.DeliveryMode;
+import org.jboss.annotation.ejb.Depends;
+import org.jboss.annotation.ejb.DependsImpl;
+import org.jboss.annotation.ejb.ExcludeClassInterceptorsImpl;
+import org.jboss.annotation.ejb.ExcludeDefaultInterceptorsImpl;
+import org.jboss.annotation.ejb.LocalBinding;
+import org.jboss.annotation.ejb.LocalBindingImpl;
+import org.jboss.annotation.ejb.LocalHomeImpl;
+import org.jboss.annotation.ejb.Management;
+import org.jboss.annotation.ejb.ManagementImpl;
+import org.jboss.annotation.ejb.MessageProperties;
+import org.jboss.annotation.ejb.MessagePropertiesImpl;
+import org.jboss.annotation.ejb.PoolClass;
+import org.jboss.annotation.ejb.PoolClassImpl;
+import org.jboss.annotation.ejb.Producers;
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.annotation.ejb.RemoteBindingImpl;
+import org.jboss.annotation.ejb.RemoteBindings;
+import org.jboss.annotation.ejb.RemoteBindingsImpl;
+import org.jboss.annotation.ejb.RemoteHomeImpl;
+import org.jboss.annotation.ejb.ResourceAdapter;
+import org.jboss.annotation.ejb.ResourceAdapterImpl;
+import org.jboss.annotation.ejb.SerializedConcurrentAccess;
+import org.jboss.annotation.ejb.SerializedConcurrentAccessImpl;
+import org.jboss.annotation.ejb.Service;
+import org.jboss.annotation.ejb.ServiceImpl;
+import org.jboss.annotation.ejb.TransactionTimeout;
+import org.jboss.annotation.ejb.TransactionTimeoutImpl;
+import org.jboss.annotation.ejb.cache.Cache;
+import org.jboss.annotation.ejb.cache.CacheImpl;
+import org.jboss.annotation.ejb.cache.simple.PersistenceManager;
+import org.jboss.annotation.ejb.cache.simple.PersistenceManagerImpl;
 import org.jboss.annotation.internal.DefaultInterceptorMarker;
 import org.jboss.annotation.internal.DefaultInterceptorMarkerImpl;
 import org.jboss.annotation.security.RunAsPrincipalImpl;
 import org.jboss.annotation.security.SecurityDomain;
 import org.jboss.annotation.security.SecurityDomainImpl;
-import org.jboss.aop.AspectManager;
-import org.jboss.aop.advice.AdviceStack;
-import org.jboss.aop.advice.AspectDefinition;
-import org.jboss.aop.advice.GenericAspectFactory;
-import org.jboss.aop.advice.Scope;
-import org.jboss.aop.advice.ScopedInterceptorFactory;
 import org.jboss.aop.annotation.AnnotationRepository;
 import org.jboss.ejb.ActivationConfigPropertyImpl;
 import org.jboss.ejb.AroundInvokeImpl;
+import org.jboss.ejb.DeclareRolesImpl;
 import org.jboss.ejb.DenyAllImpl;
 import org.jboss.ejb.InitImpl;
 import org.jboss.ejb.InterceptorsImpl;
@@ -86,58 +88,78 @@
 import org.jboss.ejb.RemoteImpl;
 import org.jboss.ejb.RemoveImpl;
 import org.jboss.ejb.RolesAllowedImpl;
-import org.jboss.ejb.RolesReferencedImpl;
 import org.jboss.ejb.RunAsImpl;
 import org.jboss.ejb.StatelessImpl;
 import org.jboss.ejb.TransactionAttributeImpl;
 import org.jboss.ejb.TransactionManagementImpl;
-import org.jboss.ejb3.dd.ActivationConfig;
-import org.jboss.ejb3.dd.ActivationConfigProperty;
-import org.jboss.ejb3.dd.AssemblyDescriptor;
-import org.jboss.ejb3.dd.ClusterConfig;
-import org.jboss.ejb3.dd.ContainerTransaction;
-import org.jboss.ejb3.dd.EjbJarDD;
-import org.jboss.ejb3.dd.EjbJarDDObjectFactory;
-import org.jboss.ejb3.dd.EnterpriseBean;
-import org.jboss.ejb3.dd.EnterpriseBeans;
-import org.jboss.ejb3.dd.EnvEntry;
-import org.jboss.ejb3.dd.ExcludeList;
-import org.jboss.ejb3.dd.InitMethod;
-import org.jboss.ejb3.dd.InjectionTarget;
-import org.jboss.ejb3.dd.InterceptorBinding;
-import org.jboss.ejb3.dd.JBossDDObjectFactory;
-import org.jboss.ejb3.dd.MessageDestination;
-import org.jboss.ejb3.dd.MessageDestinationRef;
-import org.jboss.ejb3.dd.MessageDrivenBean;
-import org.jboss.ejb3.dd.MessageDrivenDestination;
-import org.jboss.ejb3.dd.Method;
-import org.jboss.ejb3.dd.MethodAttributes;
-import org.jboss.ejb3.dd.MethodPermission;
-import org.jboss.ejb3.dd.RemoveMethod;
-import org.jboss.ejb3.dd.ResourceEnvRef;
-import org.jboss.ejb3.dd.ResourceRef;
-import org.jboss.ejb3.dd.SecurityIdentity;
-import org.jboss.ejb3.dd.SecurityRole;
-import org.jboss.ejb3.dd.SessionEnterpriseBean;
-import org.jboss.ejb3.injection.InjectionUtil;
-import org.jboss.ejb3.injection.Injector;
-import org.jboss.ejb3.injection.JndiFieldInjector;
-import org.jboss.ejb3.injection.JndiMethodInjector;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
 import org.jboss.ejb3.mdb.ConsumerContainer;
 import org.jboss.ejb3.mdb.MDB;
 import org.jboss.ejb3.mdb.ProducerImpl;
 import org.jboss.ejb3.mdb.ProducersImpl;
+import org.jboss.ejb3.metamodel.ActivationConfig;
+import org.jboss.ejb3.metamodel.AssemblyDescriptor;
+import org.jboss.ejb3.metamodel.CacheConfig;
+import org.jboss.ejb3.metamodel.ClusterConfig;
+import org.jboss.ejb3.metamodel.ContainerTransaction;
+import org.jboss.ejb3.metamodel.EjbJarDD;
+import org.jboss.ejb3.metamodel.EnterpriseBean;
+import org.jboss.ejb3.metamodel.EnterpriseBeans;
+import org.jboss.ejb3.metamodel.ExcludeList;
+import org.jboss.ejb3.metamodel.InitMethod;
+import org.jboss.ejb3.metamodel.InterceptorBinding;
+import org.jboss.ejb3.metamodel.MessageDestination;
+import org.jboss.ejb3.metamodel.MessageDrivenBean;
+import org.jboss.ejb3.metamodel.MessageDrivenDestination;
+import org.jboss.ejb3.metamodel.Method;
+import org.jboss.ejb3.metamodel.MethodAttributes;
+import org.jboss.ejb3.metamodel.MethodPermission;
+import org.jboss.ejb3.metamodel.PoolConfig;
+import org.jboss.ejb3.metamodel.RemoveMethod;
+import org.jboss.ejb3.metamodel.SecurityIdentity;
+import org.jboss.ejb3.metamodel.SessionEnterpriseBean;
+import org.jboss.ejb3.metamodel.XmlAnnotation;
 import org.jboss.ejb3.service.ServiceContainer;
 import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.ejb3.stateless.StatelessContainer;
 import org.jboss.logging.Logger;
-import org.jboss.util.xml.JBossEntityResolver;
-import org.jboss.xb.binding.JBossXBException;
-import org.jboss.xb.binding.ObjectModelFactory;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.metamodel.descriptor.InjectionTarget;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.NameValuePair;
+import org.jboss.metamodel.descriptor.ResourceRef;
+import org.jboss.metamodel.descriptor.RunAs;
+import org.jboss.metamodel.descriptor.SecurityRole;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.security.DeclareRoles;
+import javax.annotation.security.DenyAll;
+import javax.annotation.security.PermitAll;
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.LocalHome;
+import javax.ejb.MessageDriven;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remote;
+import javax.ejb.RemoteHome;
+import javax.ejb.Remove;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.ExcludeClassInterceptors;
+import javax.interceptor.ExcludeDefaultInterceptors;
+import javax.interceptor.Interceptors;
+import java.lang.reflect.Member;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
 /**
  * @version <tt>$Revision$</tt>
  * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
@@ -294,7 +316,7 @@
    {
       String ejbName = ejbNames.get(ejbIndex);
 
-      org.jboss.ejb3.dd.Service service = (org.jboss.ejb3.dd.Service) ejbs
+      org.jboss.ejb3.metamodel.Service service = (org.jboss.ejb3.metamodel.Service) ejbs
             .get(ejbIndex);
 
       ServiceContainer container = super.getServiceContainer(ejbIndex);
@@ -326,7 +348,7 @@
    {
       String ejbName = ejbNames.get(ejbIndex);
 
-      org.jboss.ejb3.dd.Consumer consumer = (org.jboss.ejb3.dd.Consumer) ejbs
+      org.jboss.ejb3.metamodel.Consumer consumer = (org.jboss.ejb3.metamodel.Consumer) ejbs
             .get(ejbIndex);
 
       ConsumerContainer container = super.getConsumerContainer(ejbIndex);
@@ -365,17 +387,7 @@
 
    protected String getMDBDomainName(int ejbIndex)
    {
-      String domainName = defaultMDBDomain;
-
-      EnterpriseBean enterpriseBean = ejbs.get(ejbIndex);
-      if (enterpriseBean != null)
-      {
-         MessageDrivenBean mdb = (MessageDrivenBean) enterpriseBean;
-         if (mdb.getMessageDrivenDestination() == null)
-            domainName = defaultMessagingInflowDrivenBeanDomain;
-      }
-
-      return domainName;
+      return defaultMDBDomain;
    }
 
    protected MDB getMDB(int ejbIndex) throws Exception
@@ -405,7 +417,7 @@
          String aopDomainName = enterpriseBean.getAopDomainName();
          if (aopDomainName != null)
          {
-            log.info("Found aop-domain-name element for annotation "
+            log.debug("Found aop-domain-name element for annotation "
                   + aopDomainName + " for ejbName "
                   + enterpriseBean.getEjbName());
 
@@ -441,9 +453,12 @@
                      "destinationType", destination.getDestinationType()));
             if (destination.getSubscriptionDurability() != null)
             {
-               properties.add(new ActivationConfigPropertyImpl("durability",
-                     destination.getSubscriptionDurability()));
+               String durable = "false";
                if (destination.getSubscriptionDurability().equals("Durable"))
+                  durable = "true";
+               properties.add(new ActivationConfigPropertyImpl("subscriptionDurability",
+                     durable));
+               if (destination.getSubscriptionDurability().equals("Durable"))
                   properties.add(new ActivationConfigPropertyImpl(
                         "subscriptionName", "subscriptionName"));
 
@@ -462,7 +477,7 @@
          {
             for (Object o : activationConfig.getActivationConfigProperties())
             {
-               ActivationConfigProperty property = (ActivationConfigProperty) o;
+               NameValuePair property = (NameValuePair) o;
                properties.add(new ActivationConfigPropertyImpl(property
                      .getName(), property.getValue()));
             }
@@ -486,7 +501,14 @@
                   .getMdbPassword()));
 
          }
+         
+         if (mdb.getMdbSubscriptionId() != null)
+         {
+            properties.add(new ActivationConfigPropertyImpl("subscriptionName", mdb
+                  .getMdbSubscriptionId()));
 
+         }
+
          ActivationConfigPropertyImpl[] propsArray = new ActivationConfigPropertyImpl[properties
                .size()];
          properties.toArray(propsArray);
@@ -511,9 +533,32 @@
          }
 
          addClassAnnotation(container, MessageDriven.class, annotation);
+
+         addDefaultActivationConfig(container, mdb);
       }
    }
 
+   private void addDefaultActivationConfig(MDB container, MessageDrivenBean mdb)
+   {
+      ActivationConfig defaultActivationConfig = mdb.getDefaultActivationConfig();
+      if (defaultActivationConfig != null)
+      {
+         DefaultActivationSpecsImpl activationAnnotation = new DefaultActivationSpecsImpl();
+         for (Object o : defaultActivationConfig.getActivationConfigProperties())
+         {
+            NameValuePair property = (NameValuePair) o;
+            activationAnnotation.addActivationConfigProperty(new ActivationConfigPropertyImpl(property
+                  .getName(), property.getValue()));
+         }
+
+         DefaultActivationSpecs existingAnnotation = (DefaultActivationSpecs)ejbClass.getAnnotation(DefaultActivationSpecs.class);
+         if (existingAnnotation != null)
+            activationAnnotation.merge(existingAnnotation);
+
+         addClassAnnotation(container, DefaultActivationSpecs.class, activationAnnotation);
+      }
+   }
+
    private void addInterfaces(EJBContainer container,
          EnterpriseBean enterpriseBean) throws ClassNotFoundException
    {
@@ -556,53 +601,6 @@
       }
    }
 
-   public static EjbJarDD parseDescriptors(DeploymentUnit di)
-         throws JBossXBException, IOException
-   {
-      ObjectModelFactory factory = null;
-      Unmarshaller unmarshaller = null;
-      EjbJarDD dd = null;
-
-      URL ddResource = di.getEjbJarXml();
-      if (ddResource != null)
-      {
-         log.debug("found ejb-jar.xml " + ddResource);
-
-         factory = new EjbJarDDObjectFactory();
-         UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory
-               .newInstance();
-         unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, true);
-         unmarshaller = unmarshallerFactory.newUnmarshaller();
-         JBossEntityResolver entityResolver = new JBossEntityResolver();
-         unmarshaller.setEntityResolver(entityResolver);
-
-         dd = (EjbJarDD) unmarshaller.unmarshal(ddResource.openStream(),
-               factory, null);
-      }
-
-      ddResource = di.getJbossXml();
-      if (ddResource != null)
-      {
-         log.debug("found jboss.xml " + ddResource);
-
-         if (dd == null)
-            dd = new EjbJarDD();
-
-         factory = new JBossDDObjectFactory(dd);
-         UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory
-               .newInstance();
-         unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, true);
-         unmarshaller = unmarshallerFactory.newUnmarshaller();
-         JBossEntityResolver entityResolver = new JBossEntityResolver();
-         unmarshaller.setEntityResolver(entityResolver);
-
-         dd = (EjbJarDD) unmarshaller.unmarshal(ddResource.openStream(),
-               factory, null);
-      }
-
-      return dd;
-   }
-
    private void addDescriptorAnnotations(EJBContainer container,
          EnterpriseBean enterpriseBean, String ejbName) throws Exception
    {
@@ -742,9 +740,9 @@
                roleList.add(role.getRoleName());
 
             }
-            RolesReferencedImpl annotation = new RolesReferencedImpl(
+            DeclareRolesImpl annotation = new DeclareRolesImpl(
                   (String[]) roleList.toArray(new String[roleList.size()]));
-            addClassAnnotation(container, RolesReferenced.class, annotation);
+            addClassAnnotation(container, DeclareRoles.class, annotation);
          }
 
          List methodPermissions = assembly.getMethodPermissions();
@@ -1050,43 +1048,218 @@
       {
          addHomeAnnotations(container, enterpriseBean);
 
-         addClusterAnnotations(container, enterpriseBean);
-
          addJndiAnnotations(container, enterpriseBean);
 
          addInterceptorMethodAnnotations(container, enterpriseBean);
 
-         handleEnvEntries(container, enterpriseBean.getEnvEntries(), container
-               .getBeanClass(), container.getEncInjections());
-
          handleResourceRefs(container, enterpriseBean.getResourceRefs());
 
-         handleResourceEnvRefs(container, enterpriseBean.getResourceEnvRefs());
+         addMessageDestinationAnnotations(container, enterpriseBean.getMessageDestinationRefs());
 
-         addMessageDestinationAnnotations(container, enterpriseBean
-               .getMessageDestinationRefs(), container.getEncInjections());
-
          addSecurityIdentityAnnotation(container, enterpriseBean
                .getSecurityIdentity());
 
          addDependencies(container, enterpriseBean);
+
+         addPoolAnnotations(container, enterpriseBean);
+         
+         addXmlAnnotations(container, enterpriseBean);
+
+         if (enterpriseBean instanceof SessionEnterpriseBean)
+         {
+            addConcurrentAnnotations(container, (SessionEnterpriseBean)enterpriseBean);
+            addClusterAnnotations(container, (SessionEnterpriseBean)enterpriseBean);
+            addCacheAnnotations(container, (SessionEnterpriseBean)enterpriseBean);
+         }
       }
    }
 
-   private void addClusterAnnotations(EJBContainer container,
+   private void addConcurrentAnnotations(EJBContainer container,
+         SessionEnterpriseBean enterpriseBean) throws Exception
+   {
+      if (enterpriseBean.getConcurrent() != null)
+      {
+         boolean concurrent = Boolean.getBoolean(enterpriseBean.getConcurrent());
+         if (concurrent)
+         {
+            SerializedConcurrentAccessImpl annotation = new SerializedConcurrentAccessImpl();
+            addClassAnnotation(container, SerializedConcurrentAccess.class, annotation);
+         }
+         else
+         {
+            container.getAnnotations().disableAnnotation(SerializedConcurrentAccess.class.getName());
+         }
+      }
+   }
+
+   private void addPoolAnnotations(EJBContainer container,
          EnterpriseBean enterpriseBean) throws Exception
    {
-      if (enterpriseBean.isClustered())
+      if (enterpriseBean.getPoolConfig() != null)
       {
-         ClusterConfig config = enterpriseBean.getClusterConfig();
-         ClusteredImpl annotation = new ClusteredImpl();
+         PoolConfig config = enterpriseBean.getPoolConfig();
+
+         PoolClassImpl poolAnnotation = new PoolClassImpl();
+
+         if (config.getPoolClass() != null)
+            poolAnnotation.setValue(di.getClassLoader().loadClass(config.getPoolClass()));
+
+         if (config.getMaxSize() != null)
+            poolAnnotation.setMaxSize(Integer.parseInt(config.getMaxSize()));
+
+         if (config.getTimeout() != null)
+            poolAnnotation.setTimeout(Long.parseLong(config.getTimeout()));
+
+         addClassAnnotation(container, PoolClass.class, poolAnnotation);
+      }
+   }
+   
+   private void addXmlAnnotations(EJBContainer container,
+         EnterpriseBean enterpriseBean) throws Exception
+   {
+      Iterator xmlAnnotations = enterpriseBean.getXmlAnnotations().iterator();
+      while (xmlAnnotations.hasNext())
+      {
+         XmlAnnotation xmlAnnotation = (XmlAnnotation)xmlAnnotations.next();
+
+         Class annotationClass = di.getClassLoader().loadClass(xmlAnnotation.getAnnotationClass());
+         Class annotationImplementationClass = di.getClassLoader().loadClass(xmlAnnotation.getAnnotationImplementationClass());
+         Object annotation = annotationImplementationClass.newInstance();
+         
+         Iterator properties = xmlAnnotation.getProperties().iterator();
+         while (properties.hasNext())
+         {
+            NameValuePair property = (NameValuePair)properties.next();
+            Field field = annotationImplementationClass.getDeclaredField(property.getName());
+            setAnnotationPropertyField(field, annotation, property.getValue());
+         }
+            
+         if (xmlAnnotation.getInjectionTarget() == null)
+         {
+            addClassAnnotation(container, annotationClass, annotation);
+         } 
+         else
+         {
+            Method method = new Method();
+            method.setMethodName(xmlAnnotation.getInjectionTarget().getTargetName());
+            addAnnotations(annotationClass, annotation, container, method);
+         }
+      }
+   }
+   
+   protected void setAnnotationPropertyField(Field field, Object annotation, String value) throws Exception
+   {
+      if (field.getType() == String.class)
+         field.set(annotation, value);
+      else if (field.getType() == Long.class)
+         field.setLong(annotation, Long.parseLong(value));
+      else if (field.getType() == Integer.class)
+         field.setInt(annotation, Integer.parseInt(value));
+      else if (field.getType() == Class.class)
+         field.set(annotation, di.getClassLoader().loadClass(value));
+      else if (field.getType() == Boolean.class)
+         field.setBoolean(annotation, Boolean.parseBoolean(value));
+   }
+
+   private void addCacheAnnotations(EJBContainer container,
+         SessionEnterpriseBean enterpriseBean) throws Exception
+   {
+      if (enterpriseBean.getCacheConfig() != null)
+      {
+         CacheConfig config = enterpriseBean.getCacheConfig();
+         if (config.getCacheClass() != null)
+         {
+            Class cacheClass = di.getClassLoader().loadClass(config.getCacheClass());
+            CacheImpl cacheAnnotation = new CacheImpl(cacheClass);
+            addClassAnnotation(container, Cache.class, cacheAnnotation);
+
+            if (cacheClass == org.jboss.ejb3.cache.simple.SimpleStatefulCache.class)
+            {
+               if (!ejbClass.isAnnotationPresent(PersistenceManager.class))
+               {
+                  PersistenceManagerImpl persistenceAnnotation = new PersistenceManagerImpl();
+                  if (config.getPersistenceManager() != null)
+                     persistenceAnnotation.setValue(di.getClassLoader().loadClass(config.getPersistenceManager()));
+                  addClassAnnotation(container, PersistenceManager.class, persistenceAnnotation);
+               }
+            }
+         }
+
+         if (config.getName() != null)
+         {
+            org.jboss.annotation.ejb.cache.tree.CacheConfigImpl configAnnotation = new org.jboss.annotation.ejb.cache.tree.CacheConfigImpl();
+
+            configAnnotation.setName(config.getName());
+
+            if (config.getMaxSize() != null)
+               configAnnotation.setMaxSize(Integer.parseInt(config.getMaxSize()));
+
+            if (config.getIdleTimeoutSeconds() != null)
+               configAnnotation.setIdleTimeoutSeconds(Long.parseLong(config.getIdleTimeoutSeconds()));
+
+            addClassAnnotation(container, org.jboss.annotation.ejb.cache.tree.CacheConfig.class, configAnnotation);
+         }
+         else
+         {
+            org.jboss.annotation.ejb.cache.simple.CacheConfigImpl configAnnotation = new org.jboss.annotation.ejb.cache.simple.CacheConfigImpl();
+
+            if (config.getMaxSize() != null)
+               configAnnotation.setMaxSize(Integer.parseInt(config.getMaxSize()));
+
+            if (config.getIdleTimeoutSeconds() != null)
+               configAnnotation.setIdleTimeoutSeconds(Long.parseLong(config.getIdleTimeoutSeconds()));
+
+            addClassAnnotation(container, org.jboss.annotation.ejb.cache.simple.CacheConfig.class, configAnnotation);
+         }
+      }
+
+   }
+
+   private void addClusterAnnotations(EJBContainer container,
+         SessionEnterpriseBean enterpriseBean) throws Exception
+   {
+      ClusteredImpl clusteredAnnotation = null;
+
+      if (enterpriseBean.getClustered() != null)
+      {
+         Clustered existingAnnotation = (Clustered)ejbClass.getAnnotation(Clustered.class);
+
+         boolean clustered = Boolean.parseBoolean(enterpriseBean.getClustered());
+         if (!clustered)
+         {
+            if (existingAnnotation != null)
+              container.getAnnotations().disableAnnotation(Clustered.class.getName());
+
+            return;
+         }
+         else
+         {
+            if (existingAnnotation == null)
+               clusteredAnnotation = new ClusteredImpl();
+         }
+      }
+
+      ClusterConfig config = enterpriseBean.getClusterConfig();
+      if (config != null)
+      {
+         if (clusteredAnnotation == null)
+            clusteredAnnotation = new ClusteredImpl();
+
          if (config.getLoadBalancePolicy() != null)
-            annotation.setLoadBalancePolicy(di.getClassLoader().loadClass(
-                  config.getLoadBalancePolicy()));
+         {
+            Class policy = di.getClassLoader().loadClass(config.getLoadBalancePolicy());
+            clusteredAnnotation.setLoadBalancePolicy(policy);
+         }
+
          if (config.getPartition() != null)
-            annotation.setPartition(config.getPartition());
+         {
+            clusteredAnnotation.setPartition(config.getPartition());
+         }
+      }
 
-         addClassAnnotation(container, Clustered.class, annotation);
+      if (clusteredAnnotation != null)
+      {
+         addClassAnnotation(container, Clustered.class, clusteredAnnotation);
       }
    }
 
@@ -1105,7 +1278,7 @@
 
          addClassAnnotation(container, Depends.class, annotation);
       }
-   
+
       if (enterpriseBean.getIgnoreDependencies().size() > 0)
       {
          Iterator<InjectionTarget> ignores = enterpriseBean.getIgnoreDependencies().iterator();
@@ -1113,10 +1286,10 @@
          {
             InjectionTarget ignore = ignores.next();
             IgnoreDependencyImpl annotation = new IgnoreDependencyImpl();
-            
+
             Method method = new Method();
             method.setMethodName(ignore.getTargetName());
-            
+
             addAnnotations(IgnoreDependency.class, annotation, container, method);
          }
       }
@@ -1125,7 +1298,7 @@
    private void addServiceAnnotations(EJBContainer container, EnterpriseBean ejb)
          throws ClassNotFoundException
    {
-      org.jboss.ejb3.dd.Service service = (org.jboss.ejb3.dd.Service) ejb;
+      org.jboss.ejb3.metamodel.Service service = (org.jboss.ejb3.metamodel.Service) ejb;
 
       if (service == null)
          return;
@@ -1144,7 +1317,7 @@
          EnterpriseBean ejb) throws ClassNotFoundException,
          NoSuchFieldException, NoSuchMethodException
    {
-      org.jboss.ejb3.dd.Consumer consumer = (org.jboss.ejb3.dd.Consumer) ejb;
+      org.jboss.ejb3.metamodel.Consumer consumer = (org.jboss.ejb3.metamodel.Consumer) ejb;
 
       if (consumer == null)
          return;
@@ -1157,7 +1330,7 @@
          Iterator producers = consumer.getProducers().iterator();
          while (producers.hasNext())
          {
-            org.jboss.ejb3.dd.Producer producer = (org.jboss.ejb3.dd.Producer) producers
+            org.jboss.ejb3.metamodel.Producer producer = (org.jboss.ejb3.metamodel.Producer) producers
                   .next();
             ProducerImpl annotation = new ProducerImpl(di.getClassLoader()
                   .loadClass(producer.getClassName()));
@@ -1169,7 +1342,7 @@
          producers = consumer.getLocalProducers().iterator();
          while (producers.hasNext())
          {
-            org.jboss.ejb3.dd.Producer producer = (org.jboss.ejb3.dd.Producer) producers
+            org.jboss.ejb3.metamodel.Producer producer = (org.jboss.ejb3.metamodel.Producer) producers
                   .next();
             ProducerImpl annotation = new ProducerImpl(di.getClassLoader()
                   .loadClass(producer.getClassName()));
@@ -1180,7 +1353,7 @@
          addClassAnnotation(container, Producers.class, producersAnnotation);
       }
 
-      org.jboss.ejb3.dd.CurrentMessage currentMessage = consumer
+      org.jboss.ejb3.metamodel.CurrentMessage currentMessage = consumer
             .getCurrentMessage();
       if (currentMessage != null)
       {
@@ -1193,7 +1366,7 @@
          }
       }
 
-      org.jboss.ejb3.dd.MessageProperties properties = consumer
+      org.jboss.ejb3.metamodel.MessageProperties properties = consumer
             .getMessageProperties();
       if (properties != null)
       {
@@ -1230,87 +1403,86 @@
    private void addJndiAnnotations(EJBContainer container,
          EnterpriseBean enterpriseBean) throws ClassNotFoundException
    {
-      String jndiName = enterpriseBean.getJndiName();
+      addLocalJndiAnnotations(container, enterpriseBean);
+      addRemoteJndiAnnotations(container, enterpriseBean);
+   }
 
+   private void addLocalJndiAnnotations(EJBContainer container,
+         EnterpriseBean enterpriseBean) throws ClassNotFoundException
+   {
+      String localJndiName = enterpriseBean.getLocalJndiName();
+      if (localJndiName != null)
+      {
+         LocalBindingImpl localBinding = new LocalBindingImpl(localJndiName);
+         addClassAnnotation(container, LocalBinding.class, localBinding);
+      }
+   }
+
+   private void addRemoteJndiAnnotations(EJBContainer container,
+         EnterpriseBean enterpriseBean) throws ClassNotFoundException
+   {
+      List<org.jboss.ejb3.metamodel.RemoteBinding> bindingsList = enterpriseBean.getRemoteBindings();
+      if (bindingsList.size() == 0)
+      {
+         addSimpleJndiAnnotations(container, enterpriseBean);
+         return;
+      }
+
       AnnotationRepository annotations = container.getAnnotations();
-      
+
+      annotations.disableAnnotation(RemoteBinding.class.getName());
+
+      List<RemoteBindingImpl> bindingAnnotationsList = new ArrayList();
+
+      Iterator bindings = bindingsList.iterator();
+      while(bindings.hasNext())
+      {
+         org.jboss.ejb3.metamodel.RemoteBinding binding = (org.jboss.ejb3.metamodel.RemoteBinding)bindings.next();
+         RemoteBindingImpl bindingAnnotation = new RemoteBindingImpl();
+
+         if (binding.getJndiName() != null)
+            bindingAnnotation.setJndiBinding(binding.getJndiName());
+
+         if (binding.getClientBindUrl() != null)
+            bindingAnnotation.setBindUrl(binding.getClientBindUrl());
+
+         if (binding.getInterceptorStack() != null)
+            bindingAnnotation.setStack(binding.getInterceptorStack());
+
+         if (binding.getProxyFactory() != null)
+            bindingAnnotation.setFactory(di.getClassLoader().loadClass(binding.getProxyFactory()));
+
+         bindingAnnotationsList.add(bindingAnnotation);
+
+      }
+
+      RemoteBindingsImpl bindingsAnnotation = new RemoteBindingsImpl(bindingAnnotationsList);
+      addClassAnnotation(container, RemoteBindings.class, bindingsAnnotation);
+   }
+
+   private void addSimpleJndiAnnotations(EJBContainer container,
+         EnterpriseBean enterpriseBean) throws ClassNotFoundException
+   {
       RemoteBindingImpl remoteBinding = null;
+
+      String jndiName = enterpriseBean.getJndiName();
       if (jndiName != null)
       {
          remoteBinding = new RemoteBindingImpl();
          remoteBinding.setJndiBinding(jndiName);
          addClassAnnotation(container, RemoteBinding.class, remoteBinding);
       }
-      
-      String interceptorStack = enterpriseBean.getInterceptorStack();
-      if (interceptorStack != null)
-      {
-         if (remoteBinding == null)
-            remoteBinding = new RemoteBindingImpl();
-         
-         remoteBinding.setStack(interceptorStack);
-      }
-      
-      String proxyFactory = enterpriseBean.getProxyFactory();
-      if (proxyFactory != null)
-      {
-         if (remoteBinding == null)
-            remoteBinding = new RemoteBindingImpl();
-         
-         remoteBinding.setFactory(di.getClassLoader().loadClass(proxyFactory));
-      }
-      
+
       if (remoteBinding != null)
       {
          RemoteBinding existingBinding = (RemoteBinding)ejbClass.getAnnotation(RemoteBinding.class);
          if (existingBinding != null)
             remoteBinding.merge(existingBinding);
-         
+
          addClassAnnotation(container, RemoteBinding.class, remoteBinding);
       }
-
-      String localJndiName = enterpriseBean.getLocalJndiName();
-      if (localJndiName != null)
-      {
-         LocalBindingImpl localBinding = new LocalBindingImpl(localJndiName);
-         addClassAnnotation(container, LocalBinding.class, localBinding);
-      }
    }
 
-   private void handleEnvEntries(EJBContainer container,
-         Collection<EnvEntry> envEntryList, Class clazz,
-         HashMap<AccessibleObject, Injector> injectors)
-         throws ClassNotFoundException, NoSuchMethodException,
-         NoSuchFieldException, javax.naming.NamingException
-   {
-      Iterator refs = envEntryList.iterator();
-      while (refs.hasNext())
-      {
-         EnvEntry entry = (EnvEntry) refs.next();
-
-         container.addEnvEntry(entry.getEnvEntryName(),
-               entry.getEnvEntryType(), entry.getEnvEntryValue());
-
-         if (entry.getInjectionTarget() != null)
-         {
-            // todo, get injection target class
-            AccessibleObject ao = InjectionUtil.findInjectionTarget(clazz,
-                  entry.getInjectionTarget());
-            if (ao instanceof Field)
-            {
-               injectors.put(ao, new JndiFieldInjector((Field) ao, "env/"
-                     + entry.getEnvEntryName(), container.getEnc()));
-            } else
-            {
-               injectors.put(ao, new JndiMethodInjector(
-                     (java.lang.reflect.Method) ao, "env/"
-                           + entry.getEnvEntryName(), container.getEnc()));
-            }
-         }
-
-      }
-   }
-
    private void handleResourceRefs(EJBContainer container,
          Collection<ResourceRef> resourceRefList)
    {
@@ -1328,19 +1500,8 @@
       }
    }
 
-   private void handleResourceEnvRefs(EJBContainer container,
-         Collection<ResourceEnvRef> resourceEnvRefList)
-   {
-      Iterator refs = resourceEnvRefList.iterator();
-      while (refs.hasNext())
-      {
-         ResourceEnvRef ref = (ResourceEnvRef) refs.next();
-      }
-   }
-
    private void addMessageDestinationAnnotations(EJBContainer container,
-         Collection destinationRefList,
-         HashMap<AccessibleObject, Injector> injectors)
+         Collection destinationRefList)
 
    {
       Iterator refs = destinationRefList.iterator();
@@ -1361,32 +1522,6 @@
                }
             }
          }
-
-         if (ref.getMappedName() == null || ref.getMappedName().equals(""))
-            throw new RuntimeException("mapped-name is required for "
-                  + ref.getMessageDestinationRefName() + " of EJB "
-                  + container.getEjbName());
-         else
-            container.addEncLinkRefEntry("env/"
-                  + ref.getMessageDestinationRefName(), ref.getMappedName());
-
-         if (ref.getInjectionTarget() != null)
-         {
-            // todo, get injection target class
-            AccessibleObject ao = InjectionUtil.findInjectionTarget(clazz, ref
-                  .getInjectionTarget());
-            if (ao instanceof Field)
-            {
-               injectors.put(ao, new JndiFieldInjector((Field) ao, "env/"
-                     + ref.getMessageDestinationRefName(), container.getEnc()));
-            } else
-            {
-               injectors.put(ao, new JndiMethodInjector(
-                     (java.lang.reflect.Method) ao, "env/"
-                           + ref.getMessageDestinationRefName(), container
-                           .getEnc()));
-            }
-         }
       }
    }
 
@@ -1498,12 +1633,12 @@
    private void addSecurityIdentityAnnotation(EJBContainer container,
          SecurityIdentity identity)
    {
-      if (identity != null)
+      if (identity != null && !identity.isUseCallerIdentity())
       {
-         String runAs = identity.getRunAs();
+         RunAs runAs = identity.getRunAs();
          if (runAs != null)
          {
-            RunAsImpl annotation = new RunAsImpl(runAs);
+            RunAsImpl annotation = new RunAsImpl(runAs.getRoleName());
             addClassAnnotation(container, annotation.annotationType(),
                   annotation);
 
@@ -1511,7 +1646,7 @@
             if (runAsPrincipal != null)
             {
                RunAsPrincipalImpl principalAnnotation = new RunAsPrincipalImpl(
-                     runAs);
+                     runAs.getRoleName());
                addClassAnnotation(container, principalAnnotation
                      .annotationType(), principalAnnotation);
             }
@@ -1548,8 +1683,10 @@
    private void addClassAnnotation(EJBContainer container,
          Class annotationClass, Object annotation)
    {
-      log.info("adding class annotation " + annotationClass.getName() + " to "
+      log.debug("adding class annotation " + annotationClass.getName() + " to "
             + ejbClass.getName() + " " + annotation);
+      log.debug("adding class annotation " + annotationClass.getName() + " to "
+            + ejbClass.getName() + " " + annotation);
       container.getAnnotations()
             .addClassAnnotation(annotationClass, annotation);
    }
@@ -1588,6 +1725,9 @@
                   log.debug("adding " + annotationClass.getName()
                         + " method annotation to " + ejbClass.getName() + "."
                         + methodName);
+                  log.debug("adding " + annotationClass.getName()
+                        + " method annotation to " + ejbClass.getName() + "."
+                        + methodName);
                   annotations.addAnnotation(methods[methodIndex],
                         annotationClass, annotation);
                   overrideAnnotations(container, methods[methodIndex],

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3HandlerFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3HandlerFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3HandlerFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -22,7 +22,9 @@
 package org.jboss.ejb3;
 
 import java.net.URL;
-import org.jboss.ejb3.dd.EjbJarDD;
+import org.jboss.ejb3.metamodel.EjbJarDD;
+import org.jboss.ejb3.metamodel.EjbJarDDObjectFactory;
+import org.jboss.ejb3.metamodel.JBossDDObjectFactory;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
 
 import javassist.bytecode.ClassFile;
@@ -39,7 +41,9 @@
       public DDFactory(Ejb3Deployment di) throws Exception
       {
          this.di = di;
-         this.dd = Ejb3DescriptorHandler.parseDescriptors(di.getDeploymentUnit());
+         this.dd = EjbJarDDObjectFactory.parse(di.getDeploymentUnit().getEjbJarXml());
+         this.dd = JBossDDObjectFactory.parse(di.getDeploymentUnit().getJbossXml(), dd);
+         
          InterceptorInfoRepository repository = this.di.getDeploymentUnit().getInterceptorInfoRepository(); 
          repository.initialise(dd);
       }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3JmxDeployment.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3JmxDeployment.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3JmxDeployment.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,13 +21,10 @@
 */
 package org.jboss.ejb3;
 
-import javax.management.ObjectName;
 import javax.security.jacc.PolicyConfiguration;
 import org.jboss.deployment.DeploymentInfo;
 import org.jboss.ejb3.security.JaccHelper;
 import org.jboss.logging.Logger;
-import org.jboss.mx.util.MBeanProxyExt;
-import org.jboss.remoting.transport.ConnectorMBean;
 
 /**
  * JBoss 4.0 Microkernel specific implementation
@@ -43,13 +40,12 @@
 
    public Ejb3JmxDeployment(DeploymentInfo di, EAR ear)
    {
-      super(new JmxDeploymentUnit(di));
+      super(new JmxDeploymentUnit(di), ear);
       this.deploymentInfo = di;
       kernelAbstraction = new JmxKernelAbstraction(di);
 
       // todo maybe mbeanServer should be injected?
       mbeanServer = di.getServer();
-      this.ear = ear;
    }
 
    protected PolicyConfiguration createPolicyConfiguration() throws Exception
@@ -71,21 +67,6 @@
 
    }
 
-   @Override
-   public String getDefaultClientBinding()
-   {
-      try
-      {
-         ObjectName on = new ObjectName("jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3");
-         ConnectorMBean connector = (ConnectorMBean) MBeanProxyExt.create(ConnectorMBean.class, on, deploymentInfo.getServer());
-         return connector.getInvokerLocator();
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-
    public DependencyPolicy createDependencyPolicy()
    {
       return new JmxDependencyPolicy();

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Ejb3Module.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,9 +21,7 @@
   */
 package org.jboss.ejb3;
 
-import java.util.Collection;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 import javax.management.ObjectName;
 import org.jboss.deployment.DeploymentInfo;
 import org.jboss.system.ServiceMBeanSupport;
@@ -43,78 +41,32 @@
    private Ejb3JmxDeployment deployment;
    private DeploymentInfo di;
 
-   private static class EARImpl implements EAR
-   {
-      private ConcurrentHashMap<String, Ejb3Deployment> deployments = new ConcurrentHashMap<String, Ejb3Deployment>();
-      private String shortName;
-      private String baseName;
+    public Ejb3Module(DeploymentInfo di)
+    {
+       EAR ear = null;
+       if (di.parent != null)
+       {
+          if (di.parent.shortName.endsWith(".ear") || di.parent.shortName.endsWith(".ear/"))
+          {
+             synchronized(di.parent.context)
+             {
+                ear = (EAR)di.parent.context.get("EJB3_EAR_METADATA");
+                if (ear == null)
+                {
+                   ear = new JmxEARImpl(di.parent.shortName);
+                   di.parent.context.put("EJB3_EAR_METADATA", ear);
+                }
+             }
+          }
+       }
+       deployment = new Ejb3JmxDeployment(di, ear);
+       if (ear != null)
+       {
+          ear.register(deployment);
+       }
+       this.di = di;
+    }
 
-      public EARImpl(String shortName)
-      {
-         this.shortName = shortName;
-         int idx = shortName.lastIndexOf('.');
-         baseName = shortName.substring(0, idx);
-      }
-
-      public Collection<Ejb3Deployment> getEjbDeployments()
-      {
-         return deployments.values();
-      }
-
-      public void register(Ejb3Deployment deployment)
-      {
-         deployments.put(deployment.getDeploymentUnit().getShortName(), deployment);
-      }
-
-      public void unregister(Ejb3Deployment deployment)
-      {
-         deployments.remove(deployment.getDeploymentUnit().getShortName());
-      }
-
-      public Ejb3Deployment findRelativeDeployment(String relativeName)
-      {
-         String relativeShortName = relativeName.substring(3);
-         return deployments.get(relativeShortName);
-      }
-
-      public String getShortName()
-      {
-         return shortName;
-      }
-
-      public String getBaseName()
-      {
-         return baseName;
-      }
-
-   }
-
-   public Ejb3Module(DeploymentInfo di)
-   {
-      EAR ear = null;
-      if (di.parent != null)
-      {
-         if (di.parent.shortName.endsWith(".ear") || di.parent.shortName.endsWith(".ear/"))
-         {
-            synchronized(di.parent.context)
-            {
-               ear = (EAR)di.parent.context.get("EJB3_EAR_METADATA");
-               if (ear == null)
-               {
-                  ear = new EARImpl(di.parent.shortName);
-                  di.parent.context.put("EJB3_EAR_METADATA", ear);
-               }
-            }
-         }
-      }
-      deployment = new Ejb3JmxDeployment(di, ear);
-      if (ear != null)
-      {
-         ear.register(deployment);
-      }
-      this.di = di;
-   }
-
    protected void createService() throws Exception
    {
       super.createService();

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,78 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * @version <tt>$Revision: 54985 $</tt>
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class InitialContextFactory
+{
+   private static Properties props = null;
+   private static Properties securityProperties = null;
+   
+   public static InitialContext getInitialContext() throws NamingException
+   {
+      InitialContext jndiContext;
+      
+      if (props == null)
+         jndiContext = new InitialContext();
+      else
+      {
+         if (securityProperties != null)
+         {
+            Properties combinedProps = new Properties();
+            combinedProps.putAll(props);
+            combinedProps.putAll(securityProperties);
+            jndiContext = new InitialContext(combinedProps);
+         }
+         else
+            jndiContext = new InitialContext(props);
+      }
+      
+      return jndiContext;
+   }
+   
+   public static void setProperties(Properties properties)
+   {
+      props = properties;
+   }
+   
+   public static void setSecurity(String user, String password)
+   {
+      if (props != null)
+      {
+         securityProperties = new Properties();
+         securityProperties.put(Context.SECURITY_PRINCIPAL, user);
+         securityProperties.put(Context.SECURITY_CREDENTIALS, password);
+         securityProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
+      }
+   }
+   
+}
+

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxClientKernelAbstraction.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxClientKernelAbstraction.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxClientKernelAbstraction.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class JmxClientKernelAbstraction implements ClientKernelAbstraction
+{
+   private static final Logger log = Logger.getLogger(JmxKernelAbstraction.class);
+
+   private MBeanServerConnection server;
+
+   public JmxClientKernelAbstraction(MBeanServerConnection server)
+   {
+      this.server = server;
+   }
+   
+   public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws Exception
+   {
+      return server.invoke(name, operationName, params, signature);
+   }
+   
+   public Object getAttribute(ObjectName name, String attribute) throws Exception
+   {
+      return server.getAttribute(name, attribute);
+   }
+}

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxDependencyPolicy.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxDependencyPolicy.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxDependencyPolicy.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -73,7 +73,8 @@
       {
          ds = ds.substring(5);
       }
-      String onStr = "jboss.jca:name=" + ds + ",service=ManagedConnectionFactory";
+      //tring onStr = "jboss.jca:name=" + ds + ",service=ManagedConnectionFactory";
+      String onStr = "jboss.jca:name=" + ds + ",service=DataSourceBinding";
 
       try
       {

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxEARImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxEARImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxEARImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,77 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Collection;
+
+/**
+ * JMX JBoss 4.x Kernel abstraction for an ear.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 1.17 $
+ */
+public class JmxEARImpl implements EAR
+{
+   private ConcurrentHashMap<String, Ejb3Deployment> deployments = new ConcurrentHashMap<String, Ejb3Deployment>();
+   private String shortName;
+   private String baseName;
+
+   public JmxEARImpl(String shortName)
+   {
+      this.shortName = shortName;
+      int idx = shortName.lastIndexOf('.');
+      baseName = shortName.substring(0, idx);
+   }
+
+   public Collection<Ejb3Deployment> getEjbDeployments()
+   {
+      return deployments.values();
+   }
+
+   public void register(Ejb3Deployment deployment)
+   {
+      deployments.put(deployment.getDeploymentUnit().getShortName(), deployment);
+   }
+
+   public void unregister(Ejb3Deployment deployment)
+   {
+      deployments.remove(deployment.getDeploymentUnit().getShortName());
+   }
+
+   public Ejb3Deployment findRelativeDeployment(String relativeName)
+   {
+      String relativeShortName = relativeName.substring(3);
+      return deployments.get(relativeShortName);
+   }
+
+   public String getShortName()
+   {
+      return shortName;
+   }
+
+   public String getBaseName()
+   {
+      return baseName;
+   }
+
+}

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxKernelAbstraction.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxKernelAbstraction.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/JmxKernelAbstraction.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -36,7 +36,9 @@
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
  */
-public class JmxKernelAbstraction implements KernelAbstraction
+public class JmxKernelAbstraction
+   extends JmxClientKernelAbstraction
+   implements KernelAbstraction
 {
    private static final Logger log = Logger.getLogger(JmxKernelAbstraction.class);
 
@@ -46,12 +48,20 @@
 
    public JmxKernelAbstraction(DeploymentInfo di)
    {
+      super(di.getServer());
       this.server = di.getServer();
       serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class, ServiceControllerMBean.OBJECT_NAME,
-                                                                        server);
+            di.getServer());
       this.di = di;
    }
    
+   public JmxKernelAbstraction(MBeanServer server)
+   {
+      super(server);
+      serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class, ServiceControllerMBean.OBJECT_NAME,
+                                                                        server);
+   }
+   
    public void setMbeanServer(MBeanServer server)
    {
       this.server = server;
@@ -75,6 +85,10 @@
             log.info("\t" + obj);
          }
          ObjectName on = new ObjectName(name);
+         
+         if(policy.getDependencies().contains(on))
+            throw new IllegalStateException("circular dependencies detected");
+         
          server.registerMBean(service, on);
          addParentDependency(on);
 
@@ -103,6 +117,16 @@
       parent.mbeans.add(on);
 
    }
+   
+   private void removeParentDependency(ObjectName on)
+   {
+      DeploymentInfo parent = di;
+      while (parent.parent != null)
+      {
+         parent = parent.parent;
+      }
+      parent.mbeans.remove(on);
+   }
 
    public void installMBean(ObjectName on, DependencyPolicy dependencies, Object service)
    {
@@ -127,6 +151,8 @@
          serviceController.stop(on);
          serviceController.destroy(on);
          serviceController.remove(on);
+         removeParentDependency(on);
+         server.unregisterMBean(on);
       }
       catch (Exception e)
       {
@@ -136,16 +162,16 @@
 
    public void uninstall(String name)
    {
+      ObjectName on;
       try
       {
-         ObjectName on = new ObjectName(name);
-         serviceController.stop(on);
-         serviceController.destroy(on);
-         serviceController.remove(on);
+         on = new ObjectName(name);
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);
       }
+      
+      uninstallMBean(on);
    }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/KernelAbstraction.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/KernelAbstraction.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/KernelAbstraction.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -31,7 +31,7 @@
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
  */
-public interface KernelAbstraction
+public interface KernelAbstraction extends ClientKernelAbstraction
 {
    public void install(String name, DependencyPolicy dependencies, Object service);
 

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/KernelAbstractionFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/KernelAbstractionFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/KernelAbstractionFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,80 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerConnection;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @version <tt>$Revision: 46471 $</tt>
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class KernelAbstractionFactory
+{
+   private static final Logger log = Logger.getLogger(KernelAbstractionFactory.class);
+   
+   private static ClientKernelAbstraction clientKernelAbstraction = null;
+   private static KernelAbstraction kernelAbstraction = null;
+  
+   public static KernelAbstraction getInstance() throws Exception
+   {  
+      if (kernelAbstraction == null)
+      {
+         // TODO always use JmxKernelAbstraction in Branch_4_0
+         MBeanServer mbeanServer = (MBeanServer)getMBeanServer();
+         kernelAbstraction = new JmxKernelAbstraction(mbeanServer);
+      }
+     
+     return kernelAbstraction;
+   }
+   
+   public static ClientKernelAbstraction getClientInstance() throws Exception
+   {
+      if (clientKernelAbstraction == null)
+      {
+         MBeanServerConnection mbeanServer = (MBeanServerConnection)getMBeanServer();
+         clientKernelAbstraction = new JmxClientKernelAbstraction(mbeanServer);
+      }
+     
+     return clientKernelAbstraction;
+   }
+  
+   protected static MBeanServerConnection getMBeanServer() throws Exception
+   {
+      MBeanServerConnection mbeanServer;
+         
+      try
+      {
+         mbeanServer = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
+      }
+      catch (IllegalStateException e)
+      {
+         String adaptorName = System.getProperty("jbosstest.server.name", "jmx/invoker/RMIAdaptor");
+         mbeanServer = (MBeanServerConnection)InitialContextFactory.getInitialContext().lookup(adaptorName);
+      }
+      
+      return mbeanServer;
+   }
+}
+

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Pool.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Pool.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/Pool.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,7 +21,7 @@
   */
 package org.jboss.ejb3;
 
-import org.jboss.ejb3.injection.Injector;
+import org.jboss.injection.Injector;
 
 /**
  * Minimally a pool acts as a factory for a bean.  It will handle callbacks
@@ -60,4 +60,6 @@
    public void setInjectors(Injector[] injectors);
 
    void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout);
+
+   void setMaxSize(int maxSize);
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyDeployer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -22,6 +22,8 @@
 package org.jboss.ejb3;
 
 import java.util.ArrayList;
+import java.util.List;
+
 import org.jboss.annotation.ejb.Clustered;
 import org.jboss.annotation.ejb.LocalBinding;
 import org.jboss.annotation.ejb.LocalBindingImpl;
@@ -54,8 +56,7 @@
    private static final Logger log = Logger.getLogger(ProxyDeployer.class);
    private Container container;
    private Advisor advisor;
-   private ArrayList proxyFactories = new ArrayList();
-   private String defaultClientBinding = RemoteProxyFactory.DEFAULT_CLIENT_BINDING;
+   private ArrayList<ProxyFactory> proxyFactories = new ArrayList<ProxyFactory>();
    private RemoteBindings remoteBindings;
    private LocalBinding localBinding;
 
@@ -65,10 +66,7 @@
       this.advisor = (Advisor) container;
    }
 
-   public void setDefaultClientBinding(String defaultClientBinding)
-   {
-      this.defaultClientBinding = defaultClientBinding;
-   }
+   public List<ProxyFactory> getProxyFactories() { return proxyFactories; }
 
    public void start() throws Exception
    {
@@ -136,8 +134,7 @@
                log.debug("there is remote interfaces for " + container.getEjbName());
                String jndiName = ProxyFactoryHelper.getDefaultRemoteJndiName(container);
                log.debug("default remote binding has jndiName of " + jndiName);
-               // todo we need to have a way to define default configuration
-               String uri = defaultClientBinding;
+               String uri = ""; // use the default
                Class factory = null;
                factory = getDefaultRemoteProxyFactory();
                RemoteBinding[] list = {new RemoteBindingImpl(jndiName, "", uri, factory)};

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -31,8 +31,12 @@
 {
    public void setContainer(Container container);
 
+   public Object createHomeProxy();
+   
    public Object createProxy();
 
+   public Object createProxy(Object id);
+   
    public void start() throws Exception;
 
    public void stop() throws Exception;

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ProxyFactoryHelper.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -28,12 +28,14 @@
 import org.jboss.ejb.LocalImpl;
 import org.jboss.ejb.RemoteImpl;
 import org.jboss.logging.Logger;
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
 
 import javax.ejb.Local;
 import javax.ejb.LocalHome;
 import javax.ejb.Remote;
 import javax.ejb.RemoteHome;
 import javax.jws.WebService;
+import javax.management.ObjectName;
 import javax.naming.Context;
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
@@ -416,5 +418,24 @@
       if (ear != null) return ear.getBaseName() + "/" + name;
       return name;
    }
-
+   
+   public static String getClientBindUrl(RemoteBinding binding) throws Exception
+   {
+      String clientBindUrl = binding.clientBindUrl();
+      if (clientBindUrl.trim().length() == 0)
+      {
+         ObjectName connectionON = new ObjectName("jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3");
+         KernelAbstraction kernelAbstraction = KernelAbstractionFactory.getInstance();
+         try
+         {
+            clientBindUrl = (String)kernelAbstraction.getAttribute(connectionON, "InvokerLocator");
+         }
+         catch (Exception e)
+         {
+            clientBindUrl = RemoteProxyFactory.DEFAULT_CLIENT_BINDING;
+         }
+      }
+      
+      return clientBindUrl;
+   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -23,6 +23,9 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+
+import javax.ejb.TimerService;
+
 import org.jboss.system.ServiceMBeanSupport;
 
 /**
@@ -138,4 +141,10 @@
          else throw new RuntimeException(t);
       }
    }
+   
+   // FIXME: this is here for EJBTHREE-630, re-establishing timers
+   public TimerService getTimerService(Object pKey)
+   {
+      return ((Container) delegate).getTimerService(pKey);
+   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,6 +21,8 @@
 */
 package org.jboss.ejb3;
 
+import javax.ejb.TimerService;
+
 import org.jboss.system.ServiceMBean;
 
 /**
@@ -31,4 +33,6 @@
  */
 public interface ServiceDelegateWrapperMBean extends ServiceMBean
 {
+   // FIXME: this is here to re-establish timers (EJBTHREE-630), do not use for other purposes
+   TimerService getTimerService(Object pKey);
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/SessionContainer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/SessionContainer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -25,15 +25,22 @@
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
+
+import javax.ejb.EJBObject;
+import javax.ejb.Handle;
 import javax.ejb.LocalHome;
 import javax.ejb.RemoteHome;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.Dispatcher;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aop.util.MethodHashing;
+import org.jboss.aspects.asynch.FutureHolder;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
 import org.jboss.ejb3.remoting.IsLocalInterceptor;
+import org.jboss.ejb3.stateful.StatefulContainerInvocation;
 import org.jboss.logging.Logger;
 import org.jboss.serial.io.MarshalledObjectForLocalCalls;
 
@@ -45,11 +52,26 @@
  */
 public abstract class SessionContainer extends EJBContainer
 {
+   @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(SessionContainer.class);
 
    protected ProxyDeployer proxyDeployer;
    protected Map clusterFamilies = new HashMap();
 
+   public class InvokedMethod
+   {
+      public InvokedMethod(boolean localInterface, Method method)
+      {
+         isLocalInterface = localInterface;
+         this.method = method;
+      }
+
+      public boolean isLocalInterface;
+      public Method method;
+   }
+
+   protected ThreadLocalStack<InvokedMethod> invokedMethod = new ThreadLocalStack<InvokedMethod>();
+
    public SessionContainer(ClassLoader cl, String beanClassName, String ejbName, AspectManager manager,
                            Hashtable ctxProperties, InterceptorInfoRepository interceptorRepository,
                            Ejb3Deployment deployment)
@@ -58,9 +80,26 @@
       proxyDeployer = new ProxyDeployer(this);
    }
 
-   public void setDefaultClientBinding(String binding)
+   public Class getInvokedBusinessInterface()
    {
-      proxyDeployer.setDefaultClientBinding(binding);
+      InvokedMethod method = invokedMethod.get();
+      if (method == null) throw new IllegalStateException("getInvokedBusinessInterface() being invoked outside of a business invocation");
+      if (method.method == null) throw new IllegalStateException("getInvokedBusinessInterface() being invoked outside of a business invocation");
+      if (method.isLocalInterface) return method.method.getDeclaringClass();
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(this);
+      for (Class intf : remoteInterfaces)
+      {
+         try
+         {
+            intf.getMethod(method.method.getName(), method.method.getParameterTypes());
+            return intf;
+         }
+         catch (NoSuchMethodException ignored)
+         {
+            // continue
+         }
+      }
+      throw new IllegalStateException("Unable to find geInvokedBusinessInterface()");
    }
 
    @Override
@@ -187,7 +226,9 @@
 
       InvocationResponse response = new InvocationResponse();
       response.setContextInfo(responseContext);
+
       response.addAttachment(IsLocalInterceptor.IS_LOCAL_EXCEPTION, new MarshalledObjectForLocalCalls(exception));
+
       return response;
    }
 
@@ -207,4 +248,174 @@
       response.setContextInfo(responseContext);
       return response;
    }
+   
+   /**
+    * Invoke a method on the virtual EJB bean. The method must be one of the methods defined in one
+    * of the business interfaces (or home interface) of the bean.
+    * 
+    * TODO: work in progress
+    * 
+    * @param factory    the originating end point
+    * @param id         unique identifier (primary key), can be null for stateless
+    * @param method     the business or home method to invoke
+    * @param args       the arguments for the method
+    * @param provider   for asynchronous usage
+    */
+   public Object invoke(ProxyFactory factory, Object id, Method method, Object args[], FutureHolder provider) throws Throwable
+   {
+      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+      ThreadLocalENCFactory.push(enc);
+      try
+      {
+         long hash = MethodHashing.calculateHash(method);
+         MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
+         if (info == null)
+         {
+            throw new RuntimeException(
+                    "Could not resolve beanClass method from proxy call: "
+                            + method.toString());
+         }
+
+         Method unadvisedMethod = info.getUnadvisedMethod();
+
+         if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
+         {
+            return invokeHomeMethod(factory, info, args);
+         }
+         else if (unadvisedMethod != null && isEJBObjectMethod(unadvisedMethod))
+         {
+            return invokeEJBObjectMethod(factory, id, info, args);
+         }
+
+         Interceptor[] aspects = info.getInterceptors();
+         // FIXME: Ahem, stateful container invocation works on all.... (violating contract though)
+         EJBContainerInvocation nextInvocation = new StatefulContainerInvocation(info, aspects, id);
+         nextInvocation.setAdvisor(this);
+         nextInvocation.setArguments(args);
+         
+         // allow a container to supplement information into an invocation
+         nextInvocation = populateInvocation(nextInvocation);
+
+         ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
+         try
+         {
+            invokedMethod.push(new InvokedMethod(true, method));
+            return nextInvocation.invokeNext();
+         }
+         finally
+         {
+            invokedMethod.pop();
+         }
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(oldLoader);
+         ThreadLocalENCFactory.pop();
+      }
+   }
+   
+   /**
+    * TODO: work in progress (refactor both invokeHomeMethod's, localHomeInvoke)
+    */
+   private Object invokeHomeMethod(ProxyFactory factory, MethodInfo info, Object args[]) throws Exception
+   {
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if (unadvisedMethod.getName().equals("create"))
+      {
+         Class[] initParameterTypes = {};
+         Object[] initParameterValues = {};
+         if (unadvisedMethod.getParameterTypes().length > 0)
+         {
+            initParameterTypes = unadvisedMethod.getParameterTypes();
+            initParameterValues = args;
+         }
+
+         Object id = createSession(initParameterTypes, initParameterValues);
+         
+         Object proxy = factory.createProxy(id);
+
+         return proxy;
+      }
+      else if (unadvisedMethod.getName().equals("remove"))
+      {
+         if(args[0] instanceof Handle)
+            removeHandle((Handle) args[0]);
+         else
+            destroySession(args[0]);
+
+         return null;
+      }
+      else
+      {
+         throw new IllegalArgumentException("illegal home method " + unadvisedMethod);
+      }
+   }
+   
+   /**
+    * Create session to an EJB bean.
+    * 
+    * @param initParameterTypes     the parameter types used by the home's create method
+    * @param initParameterValues    the arguments for the home's create method
+    * @return   the identifier of the session
+    */
+   abstract protected Object createSession(Class initParameterTypes[], Object initParameterValues[]);
+   
+   /**
+    * Destroy a created session.
+    * 
+    * @param id     the identifier of the session
+    */
+   protected void destroySession(Object id)
+   {
+      throw new RuntimeException("NYI");
+   }
+   
+   protected Object invokeEJBObjectMethod(ProxyFactory factory, Object id, MethodInfo info, Object args[]) throws Exception
+   {
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if(unadvisedMethod.getName().equals("getEJBHome"))
+      {
+         return factory.createHomeProxy();
+      }
+      if(unadvisedMethod.getName().equals("getPrimaryKey"))
+      {
+         return id;
+      }
+      if(unadvisedMethod.getName().equals("isIdentical"))
+      {
+         // object has no identity
+         if(id == null)
+            return false;
+         
+         EJBObject bean = (EJBObject) args[0];
+
+         Object primaryKey = bean.getPrimaryKey();
+         if(primaryKey == null)
+            return false;
+
+         boolean isIdentical = id.equals(primaryKey);
+
+         return isIdentical;
+      }
+      if (unadvisedMethod.getName().equals("remove"))
+      {
+         destroySession(id);
+
+         return null;
+      }
+      throw new RuntimeException("NYI");
+   }
+   
+   /**
+    * Allow a container sub class to supplement an invocation. Per default nothing to supplement.
+    * 
+    * @param invocation
+    * @return
+    */
+   protected EJBContainerInvocation populateInvocation(EJBContainerInvocation invocation)
+   {
+      return invocation;
+   }
+   
+   abstract protected void removeHandle(Handle handle) throws Exception;
 }
\ No newline at end of file

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -77,6 +77,12 @@
       this.strictMaxSize = new FIFOSemaphore(maxSize);
       this.strictTimeout = timeout;
    }
+   
+   public void setMaxSize(int maxSize)
+   {
+      this.maxSize = maxSize;
+      this.strictMaxSize = new FIFOSemaphore(maxSize);
+   }
 
    /**
     * Get an instance without identity.

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/StatefulReplicationInterceptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/StatefulReplicationInterceptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/StatefulReplicationInterceptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -56,8 +56,13 @@
       StatefulContainerInvocation ejb = (StatefulContainerInvocation) invocation;
       StatefulBeanContext ctx = (StatefulBeanContext) ejb.getBeanContext();
       StatefulContainer container = (StatefulContainer) ejb.getAdvisor();
-      ClusteredStatefulCache cache = (ClusteredStatefulCache) container.getCache();
-      cache.replicate(ctx);
+      // has not been overriden
+      if (container.getCache() instanceof ClusteredStatefulCache)
+      {
+         ClusteredStatefulCache cache = (ClusteredStatefulCache) container.getCache();
+         cache.replicate(ctx);
+      }
+      
       return rtn;
    }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -154,7 +154,8 @@
       CacheConfig config = (CacheConfig) advisor.resolveAnnotation(CacheConfig.class);
       maxSize = config.maxSize();
       sessionTimeout = config.idleTimeoutSeconds();
-      log.info("initialize: session timeout " +sessionTimeout + " and maxSize " +maxSize);
+      log.info("Initializing SimpleStatefulCache with maxSize: " +maxSize + " timeout: " +sessionTimeout +
+              " for " +container.getObjectName().getCanonicalName() );
       timeoutTask = new SessionTimeoutTask("SFSB Passivation Thread - " + container.getObjectName().getCanonicalName());
    }
 
@@ -192,7 +193,6 @@
       try
       {
          Thread.currentThread().setContextClassLoader(((EJBContainer) ctx.getContainer()).getClassloader());
-         log.debug("passivate: session id " +ctx.getId());
          pm.passivateSession(ctx);
       }
       finally
@@ -268,7 +268,6 @@
             throw new EJBNoSuchObjectException("Could not find Stateful bean: " + key);
          }
          entry = (StatefulBeanContext) bean;
-         log.debug("get: activated session id " +entry.getId());
          synchronized (cacheMap)
          {
             cacheMap.put(key, entry);
@@ -299,8 +298,7 @@
       {
          ctx = (StatefulBeanContext) cacheMap.remove(key);
       }
-      // EJBTHREE-662
-//      if (ctx != null) pool.remove(ctx);
+      if (ctx != null) pool.remove(ctx);
    }
 
 

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationCacheLoader.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationCacheLoader.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationCacheLoader.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -28,66 +28,25 @@
 import java.util.Set;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.loader.FileCacheLoader;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
 import org.jboss.system.server.ServerConfig;
 
 /**
  * Comment
  *
- * @deprecated since RC9. Will use JBoss Cache 1.4 feature instead.
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @deprecated Use direct JBossCache passivation now.
  * @version $Revision$
  */
 public class PassivationCacheLoader extends FileCacheLoader
 {
-   protected String filename;
-
-   public void setConfig(Properties p)
-   {
-      String url = p.getProperty("location");
-      String filename = System.getProperty(ServerConfig.SERVER_TEMP_DIR) + "/" + url;
-      File fp = new File(filename);
-      fp.mkdirs();
-      p.setProperty("location", filename);
-      super.setConfig(p);
-   }
-
-   public Set getChildrenNames(Fqn fqn) throws Exception
-   {
-
-      return null;
-   }
-
-   public Object get(Fqn fqn, Object key) throws Exception
-   {
-      throw new Exception("NOT IMPLEMENTED");
-   }
-
-
    public Map get(Fqn fqn) throws Exception
    {
       Map map = super.get(fqn);
-      if (map != null)
-      {
-         // remove the SFSB from disk when loaded
-         remove(fqn);
-      }
+      
+      if (map == null)
+         return new java.util.HashMap();
+      
       return map;
    }
-
-   public Object put(Fqn fqn, Object key, Object value) throws Exception
-   {
-      return null;
-   }
-
-   public void put(Fqn fqn, Map attributes) throws Exception
-   {
-   }
-
-   public void put(Fqn fqn, Map attributes, boolean erase) throws Exception
-   {
-   }
-
-   public void put(List modifications) throws Exception
-   {
-   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationEvictionPolicy.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationEvictionPolicy.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationEvictionPolicy.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,79 +21,24 @@
   */
 package org.jboss.ejb3.cache.tree;
 
-import java.util.Properties;
 import org.jboss.cache.Fqn;
-import org.jboss.cache.Node;
-import org.jboss.cache.TreeCache;
 import org.jboss.cache.eviction.LRUPolicy;
-import org.jboss.cache.eviction.Region;
-import org.jboss.cache.eviction.RegionNameConflictException;
-import org.jboss.cache.loader.FileCacheLoader;
-import org.jboss.system.server.ServerConfig;
-import org.jboss.util.xml.XmlHelper;
-import org.w3c.dom.Element;
+import org.jboss.logging.Logger;
 
 /**
  * Comment
  *
- * @deprecated since RC9. Will use JBoss Cache 1.4 feature instead.
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @deprecated Use direct JBossCache passivation now.
  * @version $Revision$
  */
 public class PassivationEvictionPolicy extends LRUPolicy
 {
-   protected FileCacheLoader fileCacheLoader = new FileCacheLoader();
-
-   public void createRegion(String name, int maxSize, long timeToLive)
-   {
-      if (regionManager_.hasRegion(name)) return;
-      try
-      {
-         Region region = regionManager_.createRegion(name, getEvictionAlgorithm());
-         region.setTimeToLiveSeconds(timeToLive);
-         region.setMaxNodes(maxSize);
-      }
-      catch (RegionNameConflictException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-
-   public void removeRegion(String name)
-   {
-      regionManager_.removeRegion(name);
-   }
-
-   public void superEvict(Fqn fqn) throws Exception
-   {
-      super.evict(fqn);
-   }
-
+   private static final Logger log = Logger.getLogger(PassivationEvictionPolicy.class);
+   
    public void evict(Fqn fqn) throws Exception
    {
-      Node node = cache_.get(fqn);
-      //System.out.println("EVICTING: " + fqn.toString() + " size: " + fqn.size() + " 0: " + fqn.get(0));
-      fileCacheLoader.put(fqn, node.getData(), true);
+      log.info("EVICTING: " + fqn.toString() + " size: " + fqn.size() + " 0: " + fqn.get(0));
       super.evict(fqn);
    }
-
-   public void configure(TreeCache cache)
-   {
-      super.configure(cache);
-      Element elem = cache.getEvictionPolicyConfig();
-      try
-      {
-         String name = XmlHelper.getUniqueChildContent(elem, "name");
-         String filename = System.getProperty(ServerConfig.SERVER_TEMP_DIR) + "/" + name;
-         Properties p = new Properties();
-         p.put("location", filename);
-         fileCacheLoader.setConfig(p);
-         fileCacheLoader.create();
-         fileCacheLoader.start();
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationTreeCache.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationTreeCache.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationTreeCache.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -23,12 +23,19 @@
 
 import org.jboss.cache.TreeCache;
 import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.eviction.LRUAlgorithm;
+import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.eviction.Region;
+import org.jboss.cache.eviction.RegionManager;
+import org.jboss.cache.eviction.RegionNameConflictException;
+import org.jboss.logging.Logger;
 
 /**
  * Comment
  *
- * @deprecated since RC9. Will use JBoss Cache 1.4 feature instead.
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @deprecated Use direct JBossCache passivation now.
  * @version $Revision$
  */
 public class PassivationTreeCache extends TreeCache
@@ -36,10 +43,6 @@
    public PassivationTreeCache()
            throws Exception
    {
+      super();
    }
-
-   public EvictionPolicy getEvictionPolicy()
-   {
-      return (EvictionPolicy) eviction_policy_provider;
-   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulCacheLoader.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulCacheLoader.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulCacheLoader.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -28,8 +28,8 @@
 /**
  * Comment
  *
- * @deprecated since RC9. Will use JBoss Cache 1.4 feature instead.
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @deprecated Use direct JBossCache passivation now.
  * @version $Revision$
  */
 public class StatefulCacheLoader extends PassivationCacheLoader
@@ -37,12 +37,14 @@
 
    public StatefulCacheLoader()
    {
+      super();
    }
 
    public Map get(Fqn fqn) throws Exception
    {
       Map map = super.get(fqn);
-      if (map != null)
+      
+      if (map.size() > 0)
       {
          if (fqn.size() == 2)
          {

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulEvictionPolicy.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulEvictionPolicy.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulEvictionPolicy.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,25 +21,27 @@
 */ 
 package org.jboss.ejb3.cache.tree;
 
-import java.util.HashMap;
 import java.util.Map;
 
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
 import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.logging.Logger;
 
 /**
  * Comment
  *
- * @deprecated since RC9. Will use JBoss Cache 1.4 feature instead.
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @deprecated Use direct JBossCache passivation now.
  * @version $Revision$
  */
 public class StatefulEvictionPolicy extends PassivationEvictionPolicy
 {
+   private static final Logger log = Logger.getLogger(StatefulEvictionPolicy.class);
 
    public StatefulEvictionPolicy()
    {
+      super();
    }
 
    public void evict(Fqn fqn) throws Exception
@@ -47,21 +49,11 @@
       // never allow root node to be evicted
       if (fqn.size() == 2)
       {
-         Node node = cache_.get(fqn);
+         StatefulBeanContext bean = (StatefulBeanContext) cache_.get(fqn, "bean");
          
-         if (node == null)
-            return;
-         
-         StatefulBeanContext bean = null;
-         Map data = node.getData();
-         if (data != null)
-         {
-            bean = (StatefulBeanContext) data.get("bean");
-         }         
-         
          if (bean == null)
          {
-            superEvict(fqn);
+            super.evict(fqn);
             return;
          }
          synchronized (bean)
@@ -69,44 +61,11 @@
             if (bean.inUse)
             {
                bean.markedForPassivation = true;
-               superEvict(fqn);
+               super.evict(fqn);
                return;
             }
-            superEvict(fqn);
-            passivate(node, bean);
+            super.evict(fqn);
          }
       }
    }
-
-   public void passivate(Node node, StatefulBeanContext bean) throws Exception
-   {
-      ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
-      try
-      {
-         bean.prePassivate();
-         fileCacheLoader.put(node.getFqn(), node.getData(), true);
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(oldCl);
-      }
-   }
-
-   public void passivate(Fqn fqn, StatefulBeanContext bean) throws Exception
-   {
-      ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
-      try
-      {
-         bean.prePassivate();
-         HashMap map = new HashMap();
-         map.put("bean", bean);
-         fileCacheLoader.put(fqn, map, true);
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(oldCl);
-      }
-   }
-
-
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -154,7 +154,6 @@
       {
          throw new RuntimeException(e);
       }
-      // EJBTHREE-662
 //      if (ctx != null) pool.remove(ctx);
    }
 

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/DeploymentEjbResolver.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/DeploymentEjbResolver.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/DeploymentEjbResolver.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,171 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.enc;
+
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.Ejb3Registry;
+import org.jboss.ejb3.ProxyFactoryHelper;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.EAR;
+
+import javax.naming.NameNotFoundException;
+import java.util.Iterator;
+
+/**
+ * Class to resolve EJB containers from ejb-ref or @EJB metadata
+ * This class is overriden for specific behaviors, specifically whether or not
+ * to resolve the EJB internally in a specific deployment or not.  There will be one for
+ * an EJB jar deployment and a WAR deployment and any other deployment package that needs to
+ * use @EJB.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56489 $
+ */
+public abstract class DeploymentEjbResolver
+{
+   protected EAR ear;
+   protected String errorName;
+
+   protected DeploymentEjbResolver(EAR ear, String errorName)
+   {
+      this.ear = ear;
+      this.errorName = errorName;
+   }
+
+   protected abstract EJBContainer searchDeploymentInternally(String ejbLink, Class businessIntf);
+
+   public EJBContainer getEjbContainer(String ejbLink, Class businessIntf)
+   {
+      int hashIndex = ejbLink.indexOf('#');
+      if (hashIndex != -1)
+      {
+         if (ear == null) return null;
+         String relativePath = ejbLink.substring(0, hashIndex);
+         Ejb3Deployment dep = ear.findRelativeDeployment(relativePath);
+         if (dep == null) return null;
+         String ejbName = ejbLink.substring(hashIndex);
+         return dep.getEjbContainer(ejbName, businessIntf);
+      }
+      // look internally
+      EJBContainer ejb = searchDeploymentInternally(ejbLink, businessIntf);
+      if (ejb != null) return ejb;
+      for (Object obj : Ejb3Registry.getContainers())
+      {
+         EJBContainer container = (EJBContainer) obj;
+         if (container.getEjbName().equals(ejbLink))
+         {
+            return container;
+         }
+      }
+      return null;
+   }
+
+   public String getEjbJndiName(String ejbLink, Class businessIntf)
+   {
+      EJBContainer container = getEjbContainer(ejbLink, businessIntf);
+      if (container == null)
+      {
+         return null;
+      }
+      return ProxyFactoryHelper.getJndiName(container, businessIntf);
+   }
+
+   public EJBContainer getEjbContainer(Ejb3Deployment deployment, Class businessIntf) throws NameNotFoundException
+   {
+      EJBContainer container = null;
+      // search in myself
+      for (Object obj : deployment.getEjbContainers().values())
+      {
+         EJBContainer newContainer = (EJBContainer) obj;
+         if (container == newContainer) continue;
+         if (ProxyFactoryHelper.publishesInterface(newContainer, businessIntf))
+         {
+            if (container != null) throw new NameNotFoundException("duplicated in " + errorName);
+            container = newContainer;
+         }
+      }
+      return container;
+   }
+
+   public EJBContainer getEjbContainer(Class businessIntf) throws NameNotFoundException
+   {
+      EJBContainer rtnContainer = null;
+      // search in deployment first
+      rtnContainer = searchForEjbContainerInternally(businessIntf);
+      if (rtnContainer != null) return rtnContainer;
+      // search in EAR
+      String jarName = null;
+      if (ear != null)
+      {
+         for (Ejb3Deployment deployment : ear.getEjbDeployments())
+         {
+            EJBContainer newContainer = getEjbContainer(deployment, businessIntf);
+            if (rtnContainer == newContainer) continue; // don't check self
+            if (rtnContainer != null && newContainer != null)
+            {
+               throw new NameNotFoundException("duplicated in .ear within " + jarName +
+                       " and " + deployment.getDeploymentUnit().getShortName());
+            }
+            if (newContainer != null)
+            {
+               rtnContainer = newContainer;
+               jarName = deployment.getDeploymentUnit().getShortName();
+            }
+         }
+      }
+      if (rtnContainer != null)
+      {
+         return rtnContainer;
+      }
+      // search everywhere
+      Iterator containers = Ejb3Registry.getContainers().iterator();
+      while (containers.hasNext())
+      {
+         Container container = (Container)containers.next();
+         EJBContainer ejbContainer = (EJBContainer) container;
+         if (ejbContainer == rtnContainer) continue;
+         if (ProxyFactoryHelper.publishesInterface(container, businessIntf))
+         {
+            if (rtnContainer != null)
+            {
+               throw new NameNotFoundException("duplicated in " + ejbContainer.getDeployment().getDeploymentUnit().getShortName()
+                       + " and " + jarName);
+            }
+            rtnContainer = ejbContainer;
+            jarName = ejbContainer.getDeployment().getDeploymentUnit().getShortName();
+         }
+      }
+      if (rtnContainer != null) return rtnContainer;
+      throw new NameNotFoundException("not used by any EJBs");
+   }
+
+   protected abstract EJBContainer searchForEjbContainerInternally(Class businessIntf) throws NameNotFoundException;
+
+   public String getEjbJndiName(Class businessIntf) throws NameNotFoundException
+   {
+      EJBContainer container = getEjbContainer(businessIntf);
+      String jndiName = ProxyFactoryHelper.getJndiName(container, businessIntf);
+      if (jndiName == null) throw new NameNotFoundException("not used by any EJBs");
+      return jndiName;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/DeploymentPersistenceUnitResolver.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/DeploymentPersistenceUnitResolver.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/DeploymentPersistenceUnitResolver.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,125 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.enc;
+
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.ejb3.PersistenceUnitRegistry;
+import org.jboss.ejb3.EAR;
+import org.jboss.ejb3.Ejb3Deployment;
+
+import javax.naming.NameNotFoundException;
+import java.util.List;
+import java.util.LinkedHashMap;
+
+/**
+ * Resolves persistence units for @PersistenceContext and @PersistenceUnit
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 45989 $
+ */
+public class DeploymentPersistenceUnitResolver
+{
+   protected List<PersistenceUnitDeployment> persistenceUnitDeployments;
+   protected EAR ear;
+   protected LinkedHashMap ejbContainers;
+
+   public DeploymentPersistenceUnitResolver(List<PersistenceUnitDeployment> persistenceUnitDeployments, EAR ear, LinkedHashMap ejbContainers)
+   {
+      this.persistenceUnitDeployments = persistenceUnitDeployments;
+      this.ear = ear;
+      this.ejbContainers = ejbContainers;
+   }
+
+   public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
+   {
+      if ("".equals(unitName))
+      {
+         if (persistenceUnitDeployments == null)
+         {
+            throw new NameNotFoundException("EMPTY STRING unitName but there is no deployments in scope");
+         }
+         if (persistenceUnitDeployments.size() == 1 && ejbContainers.size() > 0)
+         {
+            return persistenceUnitDeployments.get(0);
+         }
+         else if (persistenceUnitDeployments.size() > 1)
+         {
+            throw new NameNotFoundException("EMPTY STRING unitName and there is more than one scoped persistence unit");
+         }
+         throw new NameNotFoundException("There is no default persistence unit in this deployment.");
+      }
+      int hashIndex = unitName.indexOf('#');
+      if (hashIndex != -1)
+      {
+         String relativePath = unitName.substring(0, hashIndex);
+         String name = unitName.substring(hashIndex + 1);
+         if (ear == null)
+         {
+            String relativeJarName = relativePath.substring(3);
+            // look in global EJB jars.
+            for (PersistenceUnitDeployment pud : PersistenceUnitRegistry.getPersistenceUnits())
+            {
+               String jarName = pud.getDeployment().getDeploymentUnit().getShortName() + ".jar";
+               if (pud.getDeployment().getEar() == null
+                       && jarName.equals(relativeJarName)
+                       && pud.getEntityManagerName().equals(name)
+                       && pud.isScoped())
+               {
+                  return pud;
+               }
+            }
+            return null;
+         }
+         Ejb3Deployment dep = ear.findRelativeDeployment(relativePath);
+         if (dep == null)
+         {
+            return null;
+         }
+         PersistenceUnitDeployment rtn = dep.getPersistenceUnitDeploymentInternal(name);
+         return rtn;
+      }
+      PersistenceUnitDeployment rtn = getPersistenceUnitDeploymentInternal(unitName);
+      if (rtn != null) return rtn;
+
+      for (PersistenceUnitDeployment deployment : PersistenceUnitRegistry.getPersistenceUnits())
+      {
+         if (deployment.isScoped()) continue;
+         if (deployment.getEntityManagerName().equals(unitName)) return deployment;
+      }
+      return rtn;
+   }
+
+   public PersistenceUnitDeployment getPersistenceUnitDeploymentInternal(String unitName)
+   {
+      if (persistenceUnitDeployments != null)
+      {
+         for (PersistenceUnitDeployment deployment : persistenceUnitDeployments)
+         {
+            if (deployment.getEntityManagerName().equals(unitName))
+            {
+               return deployment;
+            }
+         }
+      }
+      return null;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/EjbModuleEjbResolver.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/EjbModuleEjbResolver.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/EjbModuleEjbResolver.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,71 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.enc;
+
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.EAR;
+
+import javax.naming.NameNotFoundException;
+import java.util.LinkedHashMap;
+
+/**
+ * Resolve EJBs.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 45989 $
+ */
+public class EjbModuleEjbResolver extends DeploymentEjbResolver
+{
+   protected LinkedHashMap ejbContainers;
+   protected Ejb3Deployment deployment;
+
+   public EjbModuleEjbResolver(EAR ear, String errorName, LinkedHashMap ejbContainers, Ejb3Deployment deployment)
+   {
+      super(ear, errorName);
+      this.ejbContainers = ejbContainers;
+      this.deployment = deployment;
+   }
+
+   @Override
+   protected EJBContainer searchDeploymentInternally(String ejbLink, Class businessIntf)
+   {
+      for (Object obj : ejbContainers.values())
+      {
+         EJBContainer container = (EJBContainer) obj;
+         if (container.getEjbName().equals(ejbLink))
+         {
+            return container;
+         }
+      }
+      return null;
+   }
+
+   @Override
+   protected EJBContainer searchForEjbContainerInternally(Class businessIntf) throws NameNotFoundException
+   {
+      EJBContainer rtnContainer;
+      rtnContainer = getEjbContainer(deployment, businessIntf);
+      return rtnContainer;
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/EjbModulePersistenceUnitResolver.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/EjbModulePersistenceUnitResolver.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/enc/EjbModulePersistenceUnitResolver.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.enc;
+
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.ejb3.EAR;
+
+import java.util.List;
+import java.util.LinkedHashMap;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 45989 $
+ */
+public class EjbModulePersistenceUnitResolver extends DeploymentPersistenceUnitResolver
+{
+   public EjbModulePersistenceUnitResolver(List<PersistenceUnitDeployment> persistenceUnitDeployments, EAR ear, LinkedHashMap ejbContainers)
+   {
+      super(persistenceUnitDeployments, ear, ejbContainers);
+   }
+}

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/entity/PersistenceUnitDeployment.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/entity/PersistenceUnitDeployment.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/entity/PersistenceUnitDeployment.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -269,13 +269,13 @@
       if (entityManagerJndiName != null)
       {
          EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
-         NonSerializableFactory.bind(initialContext, entityManagerJndiName, injectedManager);
+         NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager);
       }
       String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
       if (entityManagerFactoryJndiName != null)
       {
          EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
-         NonSerializableFactory.bind(initialContext, entityManagerFactoryJndiName, injectedFactory);
+         NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory);
       }
    }
 

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/BeanCorbaServant.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,252 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.iiop;
+
+import java.lang.reflect.Method;
+import java.security.Principal;
+import java.util.HashMap;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.SessionContainer;
+import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.ejb3.stateless.StatelessContainer;
+import org.jboss.iiop.CorbaORB;
+import org.jboss.iiop.csiv2.SASCurrent;
+import org.jboss.iiop.rmi.AttributeAnalysis;
+import org.jboss.iiop.rmi.InterfaceAnalysis;
+import org.jboss.iiop.rmi.OperationAnalysis;
+import org.jboss.iiop.rmi.RmiIdlUtil;
+import org.jboss.iiop.rmi.marshal.strategy.SkeletonStrategy;
+import org.jboss.invocation.iiop.ReferenceData;
+import org.jboss.logging.Logger;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
+import org.jboss.tm.TransactionManagerLocator;
+import org.jboss.tm.iiop.TxServerInterceptor;
+import org.omg.CORBA.BAD_OPERATION;
+import org.omg.CORBA.InterfaceDef;
+import org.omg.CORBA.SystemException;
+import org.omg.CORBA.ORBPackage.InvalidName;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.InvokeHandler;
+import org.omg.CORBA.portable.OutputStream;
+import org.omg.CORBA.portable.ResponseHandler;
+import org.omg.PortableServer.Current;
+import org.omg.PortableServer.POA;
+import org.omg.PortableServer.Servant;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 55486 $
+ */
+public class BeanCorbaServant extends Servant
+   implements InvokeHandler
+{
+   private static final Logger log = Logger.getLogger(BeanCorbaServant.class);
+
+   private final IORFactory factory;
+   private final Current poaCurrent;
+   private final Container container;
+   private final InterfaceDef interfaceDef;
+   private final String repositoryIds[];
+   private SASCurrent sasCurrent;
+
+   private HashMap<String, SkeletonStrategy> methodMap;
+   
+   protected BeanCorbaServant(IORFactory factory, Current poaCurrent, Container container, InterfaceDef interfaceDef, InterfaceAnalysis interfaceAnalysis)
+   {
+      assert factory != null;
+      assert poaCurrent != null;
+      assert container != null;
+      assert container instanceof SessionContainer; // see invoke
+      assert interfaceDef != null;
+      assert interfaceAnalysis != null;
+      
+      this.factory = factory;
+      this.poaCurrent = poaCurrent;
+      this.container = container;
+      this.interfaceDef = interfaceDef;
+      this.repositoryIds = interfaceAnalysis.getAllTypeIds();
+      
+      try
+      {
+         this.sasCurrent = (SASCurrent) CorbaORB.getInstance().resolve_initial_references("SASCurrent");
+      }
+      catch (InvalidName e)
+      {
+         log.warn("Can't find SASCurrent");
+         this.sasCurrent = null;
+      }
+      
+      this.methodMap = new HashMap<String, SkeletonStrategy>();
+      AttributeAnalysis[] attrs = interfaceAnalysis.getAttributes();
+      for (int i = 0; i < attrs.length; i++) {
+         OperationAnalysis op = attrs[i].getAccessorAnalysis();
+
+         log.debug("    " + op.getJavaName() + ": " + op.getIDLName());
+         methodMap.put(op.getIDLName(),
+                           new SkeletonStrategy(op.getMethod()));
+         op = attrs[i].getMutatorAnalysis();
+         if (op != null) {
+            log.debug("    " + op.getJavaName() + ": " + op.getIDLName());
+            methodMap.put(op.getIDLName(),
+                              new SkeletonStrategy(op.getMethod()));
+         }
+      }
+
+      OperationAnalysis[] ops = interfaceAnalysis.getOperations();
+      for (int i = 0; i < ops.length; i++) {
+         log.debug("    " + ops[i].getJavaName() + ": " + ops[i].getIDLName());
+         methodMap.put(ops[i].getIDLName(),
+                           new SkeletonStrategy(ops[i].getMethod()));
+      }
+   }
+   
+   @Override
+   public String[] _all_interfaces(POA poa, byte[] objectId)
+   {
+      return (String[]) repositoryIds.clone();
+   }
+
+   /**
+    * Returns an IR object describing the bean's remote interface.
+    */
+   @Override
+   public org.omg.CORBA.Object _get_interface_def()
+   {
+      if (interfaceDef != null)
+         return interfaceDef;
+      else
+         return super._get_interface_def();
+   }
+   
+   public OutputStream _invoke(String opName, InputStream in, ResponseHandler handler) throws SystemException
+   {
+      log.trace("invoke: " + opName);
+      
+      SkeletonStrategy op = (SkeletonStrategy) methodMap.get(opName);
+      if (op == null)
+      {
+         log.debug("Unable to find opname '" + opName + "' valid operations:" + methodMap.keySet());
+         throw new BAD_OPERATION(opName);
+      }
+
+      org.omg.CORBA_2_3.portable.OutputStream out;
+      try
+      {
+         Object id = ReferenceData.extractObjectId(poaCurrent.get_object_id());
+         log.trace("id = " + id);
+         
+         Transaction tx = TxServerInterceptor.getCurrentTransaction();
+         log.trace("tx = " + tx);
+         
+         if(sasCurrent != null)
+         {
+            byte username[] = sasCurrent.get_incoming_username();
+            byte credentials[] = sasCurrent.get_incoming_password();
+            byte principalName[] = sasCurrent.get_incoming_principal_name();
+            
+            if(username != null && username.length > 0)
+            {
+               String name = new String(username, "UTF-8");
+               int domainIndex = name.lastIndexOf("@");
+               if(domainIndex > 0)
+                  name = name.substring(0, domainIndex);
+               log.debug("username = " + name);
+               Principal principal = new SimplePrincipal(name);
+               SecurityAssociation.setPrincipal(principal);
+            }
+            
+            if(credentials != null && credentials.length > 0)
+            {
+               SecurityAssociation.setCredential(new String(credentials, "UTF-8").toCharArray());
+            }
+            
+            if(principalName != null && principalName.length > 0)
+               log.warn("principalName = " + new String(principalName, "UTF-8")); // FIXME: implement principalName support
+         }
+         
+         Object args[] = op.readParams((org.omg.CORBA_2_3.portable.InputStream) in);
+         
+         Object retVal = invoke(tx, id, op.getMethod(), args);
+         
+         out = (org.omg.CORBA_2_3.portable.OutputStream) handler.createReply();
+         if(op.isNonVoid())
+            op.writeRetval(out, retVal);
+      }
+      catch(Throwable t)
+      {
+         // TODO: check log level before stacktrace?
+         t.printStackTrace();
+         if(t instanceof Exception)
+         {
+            Exception e = (Exception) t;
+            RmiIdlUtil.rethrowIfCorbaSystemException(e);
+            out = (org.omg.CORBA_2_3.portable.OutputStream) handler.createExceptionReply();
+            op.writeException(out, e);
+         }
+         else
+            throw new RuntimeException("NYI");
+      }
+      return out;
+   }
+
+   private TransactionManager getTransactionManager()
+   {
+      //return TxUtil.getTransactionManager();
+      return TransactionManagerLocator.getInstance().locate();
+   }
+   
+   private Object invoke(Object id, Method method, Object args[]) throws Throwable
+   {
+      // TODO: Support other containers beside Stateless and Stateful?
+      return ((SessionContainer) container).invoke(factory, id, method, args, null);
+   }
+   
+   private Object invoke(Transaction tx, Object id, Method method, Object args[]) throws Throwable
+   {
+      if(tx == null)
+         return invoke(id, method, args);
+      
+      // FIXME: refactor TxServerInterceptor so that it pushed the tpc into the invocation like ClientTxPropegationInterceptor
+      // this would require the localInvoke to be also refactored, so that it uses invocation instead of localInvoke.
+      TransactionManager tm = getTransactionManager();
+      
+      // see TxPropagationInterceptor
+      if(tm.getTransaction() != null)
+         throw new RuntimeException("cannot import a transaction context when a transaction is already associated with the thread");
+      tm.resume(tx);
+      try
+      {
+         return invoke(id, method, args);
+      }
+      finally
+      {
+         tm.suspend();
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/EJB3IIOPWebClassLoader.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/EJB3IIOPWebClassLoader.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/EJB3IIOPWebClassLoader.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,55 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.iiop;
+
+import javax.management.ObjectName;
+
+import org.jboss.iiop.WebCL;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * The getKey method of the WebCL class is not working in EJB3, this class fixes that.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 46552 $
+ */
+public class EJB3IIOPWebClassLoader extends WebCL
+{
+   private String jndiName;
+   
+   public EJB3IIOPWebClassLoader(ObjectName container, RepositoryClassLoader parent, String jndiName)
+   {
+      super(container, parent);
+      this.jndiName = jndiName;
+   }
+
+   @Override
+   public String getKey()
+   {
+      String className = getClass().getName();
+      int dot = className.lastIndexOf('.');
+      if( dot >= 0 )
+          className = className.substring(dot+1);
+      String key =  className + '[' + jndiName + ']';
+      return key;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/iiop/IORFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,444 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.iiop;
+
+import java.lang.annotation.Annotation;
+import java.net.URL;
+
+import javax.ejb.EJBHome;
+import javax.ejb.EJBObject;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.rmi.PortableRemoteObject;
+
+import org.jboss.annotation.ejb.IIOP;
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.NonSerializableFactory;
+import org.jboss.ejb3.ProxyFactoryHelper;
+import org.jboss.ejb3.SessionContainer;
+import org.jboss.ejb3.remoting.RemoteProxyFactory;
+import org.jboss.iiop.CorbaORBService;
+import org.jboss.iiop.codebase.CodebasePolicy;
+import org.jboss.iiop.csiv2.CSIv2Policy;
+import org.jboss.iiop.rmi.InterfaceAnalysis;
+import org.jboss.iiop.rmi.ir.InterfaceRepository;
+import org.jboss.invocation.iiop.ReferenceFactory;
+import org.jboss.invocation.iiop.ServantRegistries;
+import org.jboss.invocation.iiop.ServantRegistry;
+import org.jboss.invocation.iiop.ServantRegistryKind;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.IorSecurityConfigMetaData;
+import org.jboss.mx.loading.RepositoryClassLoader;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.proxy.ejb.handle.HandleDelegateImpl;
+import org.jboss.system.Registry;
+import org.jboss.web.WebClassLoader;
+import org.jboss.web.WebServiceMBean;
+import org.omg.CORBA.Any;
+import org.omg.CORBA.InterfaceDef;
+import org.omg.CORBA.InterfaceDefHelper;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Policy;
+import org.omg.CORBA.Repository;
+import org.omg.CORBA.UserException;
+import org.omg.CosNaming.NameComponent;
+import org.omg.CosNaming.NamingContext;
+import org.omg.CosNaming.NamingContextExt;
+import org.omg.CosNaming.NamingContextExtHelper;
+import org.omg.CosNaming.NamingContextHelper;
+import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
+import org.omg.CosNaming.NamingContextPackage.CannotProceed;
+import org.omg.CosNaming.NamingContextPackage.InvalidName;
+import org.omg.CosNaming.NamingContextPackage.NotFound;
+import org.omg.PortableServer.Current;
+import org.omg.PortableServer.CurrentHelper;
+import org.omg.PortableServer.POA;
+import org.omg.PortableServer.Servant;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 56434 $
+ */
+public class IORFactory
+   implements RemoteProxyFactory
+{
+   private static final Logger log = Logger.getLogger(IORFactory.class);
+   
+   private Container container;
+   private Advisor advisor;
+   private RemoteBinding binding;
+   private String webServiceName = "jboss:service=WebService"; // TODO: make webServiceName configurable
+   
+   // after start available
+   private String beanRepositoryIds[];
+   private String homeRepositoryIds[];
+//   private InterfaceAnalysis interfaceAnalysis;
+   private ORB orb;
+//   private POA poa;
+   private POA irPoa;
+   private InterfaceRepository iri;
+   private ServantRegistry servantRegistry;
+   private ServantRegistry homeServantRegistry;
+   private WebClassLoader wcl;
+   private ReferenceFactory referenceFactory;
+   private ReferenceFactory homeReferenceFactory;
+
+   // TODO: create a default IIOP annotation
+   private static final IIOP defaultIIOP = new IIOP()
+   {
+      public boolean interfaceRepositorySupported()
+      {
+         return false;
+      }
+
+      public String poa()
+      {
+         return POA_PER_SERVANT;
+      }
+      
+      public Class<? extends Annotation> annotationType()
+      {
+         return IIOP.class;
+      }
+   };
+   
+   // TODO: do I really need this method
+   public Object createHomeProxy()
+   {
+      try
+      {
+         org.omg.CORBA.Object corbaRef = homeReferenceFactory.createReference(homeRepositoryIds[0]);
+         
+         EJBHome corbaObj = (EJBHome) PortableRemoteObject.narrow(corbaRef, EJBHome.class);
+         
+         return corbaObj;
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   public Object createProxy()
+   {
+      try
+      {
+         org.omg.CORBA.Object corbaRef = referenceFactory.createReference(beanRepositoryIds[0]);
+         
+         EJBObject corbaObj = (EJBObject) PortableRemoteObject.narrow(corbaRef, EJBObject.class);
+         
+         return corbaObj;
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   public Object createProxy(Object id)
+   {
+      try
+      {
+         org.omg.CORBA.Object corbaRef = referenceFactory.createReferenceWithId(id, beanRepositoryIds[0]);
+         
+         EJBObject corbaObj = (EJBObject) PortableRemoteObject.narrow(corbaRef, EJBObject.class);
+         
+         return corbaObj;
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   private IIOP getIIOP()
+   {
+      IIOP iiop = (IIOP) advisor.resolveAnnotation(IIOP.class);
+      if(iiop != null)
+         return iiop;
+      
+      return defaultIIOP;
+   }
+   
+   private String getJndiName()
+   {
+      return ProxyFactoryHelper.getDefaultRemoteJndiName(container);
+   }
+   
+   private String getServantName()
+   {
+      // TODO: is "Servant/" a good prefix for servant name
+      return "Servant/" + getJndiName();
+   }
+   
+   private WebServiceMBean getWebServer() throws MalformedObjectNameException
+   {
+      if(webServiceName == null)
+         throw new IllegalStateException("iiop is not going to work without a web service");
+      
+      return (WebServiceMBean) MBeanProxyExt.create(WebServiceMBean.class, webServiceName);
+   }
+   
+   /**
+    * Literal copy from org.jboss.proxy.ejb.IORFactory
+    */
+   private void rebind(NamingContextExt ctx, String strName, org.omg.CORBA.Object obj) throws Exception
+   {
+      NameComponent[] name = ctx.to_name(strName);
+      NamingContext intermediateCtx = ctx;
+
+      for (int i = 0; i < name.length - 1; i++ ) {
+         NameComponent[] relativeName = new NameComponent[] { name[i] };
+         try {
+            intermediateCtx = NamingContextHelper.narrow(
+                  intermediateCtx.resolve(relativeName));
+         }
+         catch (NotFound e) {
+            intermediateCtx = intermediateCtx.bind_new_context(relativeName);
+         }
+      }
+      intermediateCtx.rebind(new NameComponent[] { name[name.length - 1] }, obj);
+   }
+   
+   private void removeWebClassLoader() throws MalformedObjectNameException
+   {
+      getWebServer().removeClassLoader(wcl);
+   }
+   
+   public void setContainer(Container container)
+   {
+      this.container = container;
+      this.advisor = (Advisor) container; // TODO: why the cast?
+   }
+   
+   public void setRemoteBinding(RemoteBinding binding)
+   {
+      this.binding = binding;
+   }
+   
+   public void setWebServiceName(String name)
+   {
+      this.webServiceName = name;
+   }
+   
+   public void start() throws Exception
+   {
+      // TODO: IORFactory only supports 1 remote interface
+      Class remoteInterfaces[] = ProxyFactoryHelper.getRemoteInterfaces(container);
+      if(remoteInterfaces.length > 1)
+         log.warn("IIOP binding only works on 1 interface, using: " + remoteInterfaces[0].getName());
+      InterfaceAnalysis interfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(remoteInterfaces[0]);
+      this.beanRepositoryIds = interfaceAnalysis.getAllTypeIds();
+      
+      InterfaceAnalysis homeInterfaceAnalysis = null;
+      Class homeInterface = ProxyFactoryHelper.getRemoteHomeInterface(container);
+      if(homeInterface != null)
+      {
+         if(!EJBHome.class.isAssignableFrom(homeInterface))
+            throw new IllegalArgumentException("home interface " + homeInterface.getName() + " must extend javax.ejb.EJBHome (EJB3 4.6.8)");
+         homeInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(homeInterface);
+         this.homeRepositoryIds = homeInterfaceAnalysis.getAllTypeIds();
+      }
+      // To allow EJB3 Stateless beans to operate we can function without a home interface.
+      
+      // Get orb and irPoa references
+      try {
+         orb = (ORB)new InitialContext().lookup("java:/" + CorbaORBService.ORB_NAME);
+      }
+      catch (NamingException e) {
+         throw new Exception("Cannot lookup java:/" + CorbaORBService.ORB_NAME + ": " + e);
+      }
+      try {
+         irPoa = (POA)new InitialContext().lookup("java:/" + CorbaORBService.IR_POA_NAME);
+      }
+      catch (NamingException e) {
+         throw new Exception("Cannot lookup java:/" + CorbaORBService.IR_POA_NAME + ": " + e);
+      }
+      
+      IIOP iiop = getIIOP();
+      if(iiop.interfaceRepositorySupported())
+      {
+         this.iri = new InterfaceRepository(orb, irPoa, getJndiName());
+         iri.mapClass(remoteInterfaces[0]);
+         if(homeInterface != null)
+            iri.mapClass(homeInterface);
+         iri.finishBuild();
+      }
+      
+      // TODO: obtain the iiop invoker name properly
+      ObjectName invokerName = new ObjectName("jboss:service=invoker,type=iiop");
+      ServantRegistries servantRegistries = (ServantRegistries) Registry.lookup(invokerName);
+      if(servantRegistries == null)
+         throw new Exception("can't find iiop invoker");
+      ServantRegistryKind registryWithTransientPOA;
+      ServantRegistryKind registryWithPersistentPOA; 
+      if(iiop.poa().equals(IIOP.POA_PER_SERVANT))
+      {
+         registryWithTransientPOA = ServantRegistryKind.TRANSIENT_POA_PER_SERVANT;
+         registryWithPersistentPOA = ServantRegistryKind.PERSISTENT_POA_PER_SERVANT;
+      }
+      else if(iiop.poa().equals(IIOP.POA_SHARED))
+      {
+         registryWithTransientPOA = ServantRegistryKind.SHARED_TRANSIENT_POA;
+         registryWithPersistentPOA = ServantRegistryKind.SHARED_PERSISTENT_POA;
+      }
+      else
+         throw new IllegalArgumentException("@IIOP.poa can only be 'per-servant' or 'shared'");
+      // Only works for session container
+      this.servantRegistry = servantRegistries.getServantRegistry(registryWithTransientPOA);
+      this.homeServantRegistry = servantRegistries.getServantRegistry(registryWithPersistentPOA); // TODO: why is home interface in persistent poa?
+      
+      // Hack in a WebCL (from org.jboss.ejb.EjbModule.initializeContainer)
+      // TODO:  seting up a WebClassLoader needs to be done somewhere where
+      ObjectName on = container.getObjectName();
+      this.wcl = new EJB3IIOPWebClassLoader(on, (RepositoryClassLoader) ((SessionContainer) container).getClassloader(), getJndiName());
+      WebServiceMBean webServer = getWebServer();
+      URL[] codebaseURLs = {webServer.addClassLoader(wcl)};
+      wcl.setWebURLs(codebaseURLs);
+      
+      // setup a codebase policy, the CodebaseInterceptor will translate this to a TAG_JAVA_CODEBASE
+      String codebaseString = wcl.getCodebaseString();
+      log.debug("codebase = " + codebaseString);
+      Any codebase = orb.create_any();
+      codebase.insert_string(codebaseString);
+      Policy codebasePolicy;
+      codebasePolicy = orb.create_policy(CodebasePolicy.TYPE, codebase);
+      
+      // Create csiv2Policy for both home and remote containing
+      // IorSecurityConfigMetadata
+      Any secPolicy = orb.create_any();
+//      IorSecurityConfigMetaData iorSecurityConfigMetaData =
+//         container.getBeanMetaData().getIorSecurityConfigMetaData();
+      IorSecurityConfigMetaData iorSecurityConfigMetaData = new IorSecurityConfigMetaData(); // TODO: make ior security configurable
+      secPolicy.insert_Value(iorSecurityConfigMetaData);
+      Policy csiv2Policy = orb.create_policy(CSIv2Policy.TYPE, secPolicy);
+      
+      Policy policies[] = { codebasePolicy, csiv2Policy };
+      
+      InterfaceDef interfaceDef = null;
+      if(iri != null)
+      {
+         Repository ir = iri.getReference();
+         interfaceDef = InterfaceDefHelper.narrow(ir.lookup_id(beanRepositoryIds[0]));
+      }
+      
+      Current poaCurrent = CurrentHelper.narrow(orb.resolve_initial_references("POACurrent"));
+
+      NamingContextExt ctx = getNamingContextExt();
+
+      log.debug("binding servant name " + getServantName());
+      
+      Servant servant = new BeanCorbaServant(this, poaCurrent, container, interfaceDef, interfaceAnalysis);
+      this.referenceFactory = servantRegistry.bind(getServantName(), servant, policies);
+      
+      EJBObject corbaObj = (EJBObject) createProxy();
+      
+      rebind(ctx, getJndiName(), (org.omg.CORBA.Object) corbaObj);
+      
+      // TODO: use iri
+      if(homeInterfaceAnalysis != null)
+      {
+         servant = new BeanCorbaServant(this, poaCurrent, container, null, homeInterfaceAnalysis);
+         this.homeReferenceFactory = homeServantRegistry.bind(getServantName() + "Home", servant, policies);
+         
+         Object homeObject = createHomeProxy();
+         
+         rebind(ctx, getJndiName() + "Home", (org.omg.CORBA.Object) homeObject);
+      }
+      
+      // bind HandleDelegate stuff
+      Context compCtx = (Context) new InitialContext().lookup("java:comp");
+      NonSerializableFactory.rebind(compCtx, "ORB", orb);
+      NonSerializableFactory.rebind(compCtx, "HandleDelegate", new HandleDelegateImpl());
+   }
+   
+   public void stop() throws Exception
+   {
+      if(homeReferenceFactory != null)
+      {
+         unbind(getJndiName() + "Home");
+         unbindHomeServant();
+      }
+      unbind(getJndiName());
+      
+      unbindServant();
+      
+      removeWebClassLoader();
+   }
+   
+   /**
+    * Unbind the bean from CosNaming
+    */
+   private void unbind(String strName)
+   {
+      try
+      {
+         NamingContextExt corbaContext = getNamingContextExt();
+         NameComponent n[] = corbaContext.to_name(strName);
+         getNamingContextExt().unbind(n);
+      }
+      catch(Exception e)
+      {
+         log.warn("unable to unbind '" + strName + "'", e);
+      }
+   }
+   
+   private void unbindHomeServant()
+   {
+      try
+      {
+         homeServantRegistry.unbind(getServantName() + "Home");
+      }
+      catch(Exception e)
+      {
+         log.warn("unable to unbind home servant", e);
+      }
+   }
+   
+   private void unbindServant()
+   {
+      try
+      {
+         servantRegistry.unbind(getServantName());
+      }
+      catch(Exception e)
+      {
+         log.warn("unable to unbind servant", e);
+      }
+   }
+
+   private NamingContextExt getNamingContextExt() throws NamingException
+   {
+      Context initialContext = new InitialContext();
+      
+      // NOTE: eclipse editor parser crashes silently on this line (because of org.jboss.iiop.CorbaNamingService) with unknown reason
+      // that's why this method is at the end
+      return NamingContextExtHelper.narrow((org.omg.CORBA.Object) initialContext.lookup("java:/" + org.jboss.iiop.CorbaNamingService.NAMING_NAME));
+   }
+}
\ No newline at end of file

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsInterceptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsInterceptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/EJB3InterceptorsInterceptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -53,7 +53,7 @@
    public Object invoke(Invocation invocation) throws Throwable
    {
       EJBContainerInvocation inv = (EJBContainerInvocation) invocation;
-      
+                                
       //We need to do this every time to make sure we have interceptor instances corresponding 
       //to the bean instance
       //TODO Cache this for non-stateful beans?

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfo.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfo.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfo.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -27,7 +27,7 @@
 import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 
-import org.jboss.ejb3.dd.Interceptor;
+import org.jboss.ejb3.metamodel.Interceptor;
 
 /**
  * We cannot use annotation overrides for the interceptor stuff since they do not have a 

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInfoRepository.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,38 +21,28 @@
  */
 package org.jboss.ejb3.interceptor;
 
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.metamodel.EjbJarDD;
+import org.jboss.ejb3.metamodel.Interceptor;
+import org.jboss.ejb3.metamodel.InterceptorBinding;
+import org.jboss.ejb3.metamodel.Interceptors;
+import org.jboss.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.ExcludeClassInterceptors;
+import javax.interceptor.ExcludeDefaultInterceptors;
+import javax.interceptor.InvocationContext;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.ExcludeClassInterceptors;
-import javax.interceptor.ExcludeDefaultInterceptors;
-import javax.interceptor.InvocationContext;
-import javax.ejb.PostActivate;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.ejb.PrePassivate;
-
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.dd.EjbJarDD;
-import org.jboss.ejb3.dd.Interceptor;
-import org.jboss.ejb3.dd.InterceptorBinding;
-import org.jboss.ejb3.dd.Interceptors;
-import org.jboss.logging.Logger;
-
 /**
  * A repository of interceptor details shared amongst all containers in this deployment.
  * Interceptors differ from other ejb 3 artifacts in that we can have annotations on the
@@ -203,7 +193,9 @@
       {
          HashSet<InterceptorInfo> infos = getDefaultInterceptors();
          if (infos != null)
+         {
             interceptors.addAll(trimUnwanted(infos, type));
+         }
          sorter.sortDefaultInterceptors(container, interceptors);
       }
 
@@ -212,7 +204,9 @@
       {
          List<InterceptorInfo> infos = container.getClassInterceptors();
          if (infos != null)
+         {
             interceptors.addAll(trimUnwanted(infos, type));
+         }
          
          if (type != AroundInvoke.class)
          {
@@ -368,7 +362,7 @@
    private InterceptorInfo initialiseSuperClassesFirstFromXmlOrAnnotations(
          HashMap<String, AnnotationInitialiser> initialisers, String superClassName)
    {
-      if (superClassName == "java.lang.Object")
+      if ("java.lang.Object".equals(superClassName))
       {
          return null;
       }
@@ -781,7 +775,7 @@
          return info;
       }
 
-      java.lang.reflect.Method findInterceptorMethodFromXml(Class clazz, String lookingFor, org.jboss.ejb3.dd.Method xml)
+      java.lang.reflect.Method findInterceptorMethodFromXml(Class clazz, String lookingFor, org.jboss.ejb3.metamodel.Method xml)
       {
          if (xml == null)
             return null;

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/InterceptorInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,23 +21,16 @@
 */ 
 package org.jboss.ejb3.interceptor;
 
-import java.lang.reflect.AccessibleObject;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
 import org.jboss.ejb3.BeanContext;
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.dd.Interceptor;
-import org.jboss.ejb3.injection.EJBHandler;
-import org.jboss.ejb3.injection.Injector;
-import org.jboss.ejb3.injection.JndiInjectHandler;
-import org.jboss.ejb3.injection.PersistenceContextHandler;
-import org.jboss.ejb3.injection.PersistenceUnitHandler;
-import org.jboss.ejb3.injection.PojoInjector;
-import org.jboss.ejb3.injection.ResourceHandler;
-import org.jboss.ejb3.injection.WebServiceHandler;
+import org.jboss.injection.Injector;
+import org.jboss.injection.PojoInjector;
+import org.jboss.ejb3.metamodel.Interceptor;
 
+import java.lang.reflect.AccessibleObject;
+import java.util.Map;
+
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
@@ -48,30 +41,15 @@
    EJBContainer container;
    InterceptorInfo info;
    PojoInjector[] injectors;
-   protected HashMap<AccessibleObject, Injector> encInjections = new HashMap<AccessibleObject, Injector>();
+   protected Map<AccessibleObject, Injector> encInjections;
    
-   public InterceptorInjector(Container container, InterceptorInfo info) throws Exception
+   public InterceptorInjector(Container container, InterceptorInfo info, Map<AccessibleObject, Injector> injections)
    {
       this.container = (EJBContainer)container;
       this.info = info;
-
-      List list = new ArrayList();
-      list.addAll(JndiInjectHandler.loadInjectors(this));
-      ResourceHandler.loadInjectors(this);
-      EJBHandler.loadInjectors(this);
-      WebServiceHandler.loadInjectors(this);
-      //list.addAll(DependsHandler.loadInjectors(this));
-      PersistenceContextHandler.loadInjectors(this);
-      PersistenceUnitHandler.loadInjectors(this);
-      list.addAll(encInjections.values());
-      injectors = (PojoInjector[]) list.toArray(new PojoInjector[list.size()]);
+      injectors = injections.values().toArray(new PojoInjector[injections.size()]);
    }
 
-   public HashMap<AccessibleObject, Injector> getEncInjections()
-   {
-      return encInjections;
-   }
-   
    public Interceptor getXml()
    {
       return info.getXml();

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/LifecycleInterceptorHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/LifecycleInterceptorHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/interceptor/LifecycleInterceptorHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -34,7 +34,9 @@
 
 import org.jboss.ejb3.BeanContext;
 import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
 import org.jboss.util.MethodHashing;
+import org.jboss.logging.Logger;
 
 /**
  * 
@@ -43,6 +45,8 @@
  */
 public class LifecycleInterceptorHandler
 {
+   private static final Logger log = Logger.getLogger(LifecycleInterceptorHandler.class);
+
    private EJBContainer container;
    private InterceptorInfo[] postConstructs;
    private InterceptorInfo[] postActivates;
@@ -54,7 +58,7 @@
    private Method[] beanPreDestroys;
    private Method timeoutCallbackMethod;
    private long timeoutCalllbackHash;
-   
+
    public LifecycleInterceptorHandler(EJBContainer container, Class[] handledCallbacks)
    {
       this.container = container;
@@ -87,7 +91,7 @@
          }
       }
    }
-   
+
    public long getTimeoutCalllbackHash()
    {
       return timeoutCalllbackHash;
@@ -98,9 +102,9 @@
       try
       {
          InvocationContext ic = LifecycleInvocationContextImpl.getLifecycleInvocationContext(
-               PostConstruct.class, 
-               ctx, 
-               postConstructs, 
+               PostConstruct.class,
+               ctx,
+               postConstructs,
                beanPostConstructs);
          ic.proceed();
       }
@@ -112,11 +116,16 @@
 
    public void preDestroy(BeanContext ctx)
    {
+      Object id = null;
+      if (ctx instanceof StatefulBeanContext)
+      {
+         id = ((StatefulBeanContext)ctx).getId();
+      }
       try
       {
          InvocationContext ic = LifecycleInvocationContextImpl.getLifecycleInvocationContext(
                PreDestroy.class,
-               ctx, 
+               ctx,
                preDestroys,
                beanPreDestroys);
          ic.proceed();
@@ -132,8 +141,8 @@
       try
       {
          InvocationContext ic = LifecycleInvocationContextImpl.getLifecycleInvocationContext(
-               PostActivate.class, 
-               ctx, 
+               PostActivate.class,
+               ctx,
                postActivates,
                beanPostActivates);
          ic.proceed();
@@ -149,7 +158,7 @@
       try
       {
          InvocationContext ic = LifecycleInvocationContextImpl.getLifecycleInvocationContext(
-               PrePassivate.class, 
+               PrePassivate.class,
                ctx,
                prePassivates,
                beanPrePassivates);
@@ -173,8 +182,8 @@
       {
          if (container.resolveAnnotation(method, Timeout.class) != null)
          {
-            if (Modifier.isPublic(method.getModifiers()) && 
-                  method.getReturnType().equals(Void.TYPE) && 
+            if (Modifier.isPublic(method.getModifiers()) &&
+                  method.getReturnType().equals(Void.TYPE) &&
                   method.getParameterTypes().length == 1 &&
                   method.getParameterTypes()[0].equals(Timer.class))
             {
@@ -186,24 +195,24 @@
             }
          }
       }
-      
-      try 
+
+      try
       {
          if (timeoutCallbackMethod == null && javax.ejb.TimedObject.class.isAssignableFrom(container.getBeanClass()))
          {
             Class[] params = new Class[]{Timer.class};
             timeoutCallbackMethod = container.getBeanClass().getMethod("ejbTimeout", params);
          }
-      } 
+      }
       catch (Exception e)
       {
          e.printStackTrace();
       }
-      
+
       if (timeoutCallbackMethod != null)
       {
          timeoutCalllbackHash = MethodHashing.calculateHash(timeoutCallbackMethod);
       }
-   }   
+   }
 
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -27,7 +27,11 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
+import java.util.Map;
+
+import javax.ejb.ActivationConfigProperty;
 import javax.ejb.EJBException;
+import javax.ejb.MessageDriven;
 import javax.ejb.Timer;
 import javax.ejb.TimerService;
 import javax.ejb.TransactionAttribute;
@@ -70,16 +74,17 @@
 import org.jboss.aop.util.MethodHashing;
 import org.jboss.aop.util.PayloadKey;
 import org.jboss.deployment.DeploymentException;
-import org.jboss.ejb.txtimer.TimedObjectInvoker;
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.EJBContainer;
 import org.jboss.ejb3.EJBContainerInvocation;
 import org.jboss.ejb3.Ejb3Module;
-import org.jboss.ejb3.EjbTimerUtil;
+import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.ThreadLocalENCFactory;
 import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.ejb3.dd.EnterpriseBean;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.ejb3.timerservice.TimerServiceFactory;
 import org.jboss.ejb3.tx.TxUtil;
 import org.jboss.jms.ConnectionFactoryHelper;
 import org.jboss.jms.asf.ServerSessionPoolFactory;
@@ -93,22 +98,15 @@
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
  */
-public class ConsumerContainer extends EJBContainer implements TimedObjectInvoker
+public class ConsumerContainer extends MessagingContainer
 {
    private static final Logger log = Logger.getLogger(ConsumerContainer.class);
-
-   protected TimerService timerService;
-   protected ActivationSpec activationSpec = new ActivationSpec();
-   protected boolean isContainerManagedTx;
-   protected AcknowledgementMode acknowledgeMode;
-   protected Connection connection;
-   protected MDBConfig config;
-   protected ExceptionListenerImpl exListener;
-   protected DLQHandler dlqHandler;
-   protected HashMap<Long, ConnectionConsumer> connectionConsumers = new HashMap<Long, ConnectionConsumer>();
-   protected HashMap<Long, ServerSessionPool> serverSessionPools = new HashMap<Long, ServerSessionPool>();
+   
+   protected Class messagingType = null;
+   protected Method ON_MESSAGE;
+   
    protected ArrayList<ProducerFactory> producers = new ArrayList<ProducerFactory>();
-
+   
    /**
     * Default destination type. Used when no message-driven-destination is given
     * in ejb-jar, and a lookup of destinationJNDI from jboss.xml is not
@@ -121,7 +119,6 @@
     * This is needed because API changed from JBoss 4.0.1sp1 to 4.0.2
     * TODO remove this after 4.0.2 is out.
     */
-   protected Method getServerSessionPool;
    public static final String CONSUMER_MESSAGE = "CONSUMER_MESSAGE";
 
 
@@ -129,20 +126,121 @@
                             Hashtable ctxProperties, InterceptorInfoRepository interceptorRepository,
                             Ejb3Deployment deployment)
    {
-      super(Ejb3Module.BASE_EJB3_JMX_NAME + ",name=" + ejbName, manager, cl, beanClassName, ejbName, ctxProperties, interceptorRepository, deployment);
-      beanContextClass = MDBContext.class;
-      Method[] methods = ServerSessionPoolFactory.class.getMethods();
-      for (Method m : methods)
+      super(ejbName, manager, cl, beanClassName, ctxProperties, interceptorRepository, deployment);
+   }
+   
+   public InvocationResponse dynamicInvoke(Invocation invocation) throws Throwable
+   {
+      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+      EJBContainerInvocation newSi = null;
+      ThreadLocalENCFactory.push(enc);
+      try
       {
-         if (m.getName().equals("getServerSessionPool"))
+         Thread.currentThread().setContextClassLoader(classloader);
+         MethodInvocation si = (MethodInvocation) invocation;
+         MethodInfo info = (MethodInfo) methodInterceptors.get(si.getMethodHash());
+         if (info == null)
          {
-            getServerSessionPool = m;
-            break;
+            throw new RuntimeException("Could not resolve beanClass method from proxy call");
          }
+       
+         Interceptor[] aspects = info.getInterceptors();
+         newSi = new EJBContainerInvocation(info, aspects);
+         newSi.setArguments(si.getArguments());
+         newSi.setMetaData(si.getMetaData());
+         newSi.setAdvisor(this);
+
+         InvocationResponse response = new InvocationResponse(newSi.invokeNext());
+         response.setContextInfo(newSi.getResponseContextInfo());
+         return response;
       }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(oldLoader);
+         ThreadLocalENCFactory.pop();
+      }
    }
+   
+   protected Method getOnMessage()
+   {
+      if (ON_MESSAGE != null)
+         return ON_MESSAGE;
+      
+      try
+      {
+         final Class arg = Message.class;
+         ON_MESSAGE = javax.jms.MessageListener.class.getMethod("onMessage", new Class[]{arg});
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+         throw new ExceptionInInitializerError(e);
+      }
 
+      return ON_MESSAGE;
+   }
+   
+   public Object localInvoke(MethodInfo info, Object[] args) throws Throwable
+   {     
+      if (info.getAdvisedMethod().equals(getOnMessage()))
+      {
+         ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+         ThreadLocalENCFactory.push(enc);
+         
+         try
+         {
+            Message message = (Message)args[0];
+            MethodInvocation invocation = (MethodInvocation) ((ObjectMessage) message).getObject();
+            invocation.getMetaData().addMetaData(CONSUMER_MESSAGE, CONSUMER_MESSAGE, message, PayloadKey.TRANSIENT);
+            return this.dynamicInvoke(invocation);
+         }
+         finally
+         {
+            Thread.currentThread().setContextClassLoader(oldLoader);
+            ThreadLocalENCFactory.pop();
+         }
+      }
+      else
+         return super.localInvoke(info, args);
+   }
+   
+   public Class getMessagingType()
+   {
+      return javax.jms.MessageListener.class;
+   }
+   
+   public MethodInfo getMethodInfo(Method method)
+   {
+      MethodInfo info = new MethodInfo();
+      info.setAdvisor(this);
+      info.setAdvisedMethod(method);
+      info.setUnadvisedMethod(method);
+    
+      return info;
+   }
+ 
+   public Map getActivationConfigProperties()
+   {
+      HashMap result = new HashMap();
+      Consumer annotation = (Consumer) resolveAnnotation(Consumer.class);
+      for (ActivationConfigProperty property : annotation.activationConfig())
+      {
+         addActivationSpecProperty(result, property);
+      }
+      
+      DefaultActivationSpecs defaultSpecsAnnotation = (DefaultActivationSpecs)resolveAnnotation(DefaultActivationSpecs.class);
+      if (defaultSpecsAnnotation != null)
+      {
+         for (ActivationConfigProperty property : defaultSpecsAnnotation.value())
+         {
+            addActivationSpecProperty(result, property);
+         }
+      }
+      
+      return result;
+   }
 
+
    /**
     * Initialize the container invoker. Sets up a connection, a server session
     * pool and a connection consumer for the configured destination.
@@ -155,45 +253,7 @@
    public void start() throws Exception
    {
       super.start();
-      exListener = new ExceptionListenerImpl(this);
-
-      populateActivationSpec();
-
-      config = MDBConfig.createMDBConfig(activationSpec);
-
-      try
-      {
-         innerCreate();
-      }
-      catch (final JMSException e)
-      {
-         log.error("FAILED INNER CREATE", e);
-         //
-         // start a thread up to handle recovering the connection. so we can
-         // attach to the jms resources once they become available
-         //
-         new Thread("EJB3 MDB Create Recovery Thread")
-         {
-            public void run()
-            {
-               exListener.onException(e);
-            }
-         }.start();
-         return;
-      }
-
-      if (dlqHandler != null)
-      {
-         dlqHandler.start();
-      }
-
-      if (connection != null)
-      {
-         connection.setExceptionListener(exListener);
-         connection.start();
-      }
-      timerService = EjbTimerUtil.getTimerService(this, this);
-
+      
       registerProducers();
    }
 
@@ -240,7 +300,7 @@
 
    protected void registerProducers() throws Exception
    {
-      Destination dest = (Destination) getInitialContext().lookup(config.getDestination());
+      Destination dest = (Destination) getInitialContext().lookup(getDestination());
       Class[] producers = getProducerInterfaces(this);
       MessageProperties props = (MessageProperties) resolveAnnotation(MessageProperties.class);
       if (props == null) props = new MessagePropertiesImpl();
@@ -268,564 +328,9 @@
          factory.stop();
       }
    }
-
-   private void innerCreate() throws Exception
+   
+   protected void populateActivationSpec()
    {
-      log.debug("Initializing");
-
-      Consumer Consumer = (Consumer) resolveAnnotation(Consumer.class);
-
-      // Get the JMS provider
-      // todo get rid of server module dependency
-      JMSProviderAdapter adapter = getJMSProviderAdapter();
-      log.debug("Provider adapter: " + adapter);
-
-      setupDLQ(adapter);
-
-
-      // Is container managed?
-      TransactionManagement transactionManagement = (TransactionManagement) resolveAnnotation(TransactionManagement.class);
-      if (transactionManagement == null)
-         isContainerManagedTx = true;
-      else
-         isContainerManagedTx = transactionManagement.value() == TransactionManagementType.CONTAINER;
-      String ackMode = config.getAcknowledgeMode();
-      if (ackMode != null && (ackMode.equals("DUPS_OK_ACKNOWLEDGE")
-                              || ackMode.equals(AcknowledgementMode.AUTO_ACKNOWLEDGE.name())
-                              || ackMode.equals("Dups-ok-acknowledge")))
-      {
-         acknowledgeMode = AcknowledgementMode.DUPS_OK;
-      }
-      else
-      {
-         acknowledgeMode = AcknowledgementMode.AUTO_ACKNOWLEDGE;
-      }
-
-
-      // Connect to the JNDI server and get a reference to root context
-      Context context = adapter.getInitialContext();
-      log.debug("context: " + context);
-
-      // if we can't get the root context then exit with an exception
-      if (context == null)
-      {
-         throw new RuntimeException("Failed to get the root context");
-      }
-
-      String destinationType = config.getDestinationType();
-
-      // Unfortunately the destination is optional, so if we do not have one
-      // here we have to look it up if we have a destinationJNDI, else give it
-      // a default.
-      if (destinationType == null)
-      {
-         log.warn("No message-driven-destination given; using; guessing type");
-         destinationType = getDestinationType(context, config.getDestination());
-      }
-
-      if ("javax.jms.Topic".equals(destinationType))
-      {
-         innerCreateTopic(context, adapter);
-
-      }
-      else if ("javax.jms.Queue".equals(destinationType))
-      {
-         innerCreateQueue(context, adapter);
-
-      }
-      else
-         throw new DeploymentException("Unknown destination-type " + destinationType);
-
-      log.debug("Initialized with config " + toString());
-
-      context.close();
-   }
-
-   private void innerCreateQueue(Context context, JMSProviderAdapter adapter)
-           throws Exception
-   {
-      log.debug("Got destination type Queue for " + ejbName);
-
-      // Get the JNDI suffix of the destination
-      String jndiSuffix = parseJndiSuffix(config.getDestination(), ejbName);
-      log.debug("jndiSuffix: " + jndiSuffix);
-
-      // create a queue connection
-      Object qFactory = context.lookup(adapter.getQueueFactoryRef());
-      QueueConnection qConnection = null;
-      try
-      {
-         qConnection = ConnectionFactoryHelper.createQueueConnection(qFactory, config.getUser(), config.getPassword());
-         connection = qConnection;
-      }
-      catch (ClassCastException e)
-      {
-         throw new DeploymentException("Expected a QueueConnection check your provider adaptor: "
-                                       + adapter.getQueueFactoryRef());
-      }
-
-      // Set the optional client id
-      String clientId = config.getClientID();
-
-      log.debug("Using client id: " + clientId);
-      if (clientId != null && clientId.length() > 0)
-         connection.setClientID(clientId);
-
-      // lookup or create the destination queue
-      Queue queue = null;
-      try
-      {
-         // First we try the specified queue
-         if (config.getDestination() != null)
-            queue = (Queue) context.lookup(config.getDestination());
-      }
-      catch (NamingException e)
-      {
-         log.warn("Could not find the queue destination-jndi-name=" + config.getDestination());
-      }
-      catch (ClassCastException e)
-      {
-         throw new DeploymentException("Expected a Queue destination-jndi-name=" + config.getDestination());
-      }
-
-      // FIXME: This is not portable, only works for JBossMQ
-      if (queue == null)
-         queue = (Queue) createDestination(Queue.class,
-                                           context,
-                                           "queue/" + jndiSuffix,
-                                           jndiSuffix);
-
-      registerQueueListeners(qConnection, queue);
-
-   }
-
-   private void registerQueueListeners(QueueConnection qConnection, Queue queue)
-           throws NamingException, JMSException
-   {
-      MessageListener listener = new MessageListenerImpl(this);
-      Class[] producers = getProducerInterfaces(this);
-      HashSet visited = new HashSet();
-      for (Class producer : producers)
-      {
-         for (Method method : producer.getMethods())
-         {
-            long hash = MethodHashing.calculateHash(method);
-            if (visited.contains(hash)) continue;
-            visited.add(hash);
-            Method methodMessage = (Method) advisedMethods.get(hash);
-
-            // set up the server session pool
-            ServerSessionPool serverSessionPool = createSessionPool(queue,
-                                                                    qConnection,
-                                                                    true, // tx
-                                                                    acknowledgeMode.ordinal(),
-                                                                    listener,
-                                                                    methodMessage);
-            log.debug("Server session pool: " + serverSessionPool);
-            serverSessionPools.put(hash, serverSessionPool);
-
-            // create the connection consumer
-            ConnectionConsumer connectionConsumer =
-                    qConnection.createConnectionConsumer(queue,
-                                                         config.getMessageSelector(),
-                                                         serverSessionPool,
-                                                         config.getMaxMessages());
-            log.debug("Connection consumer: " + connectionConsumer);
-            connectionConsumers.put(hash, connectionConsumer);
-         }
-
-      }
-   }
-
-   private void innerCreateTopic(Context context, JMSProviderAdapter adapter)
-           throws Exception
-   {
-      log.debug("Got destination type Topic for " + ejbName);
-
-      // Get the JNDI suffix of the destination
-      String jndiSuffix = parseJndiSuffix(config.getDestination(), ejbName);
-      log.debug("jndiSuffix: " + jndiSuffix);
-
-      // create a topic connection
-      Object factory = context.lookup(adapter.getTopicFactoryRef());
-      TopicConnection tConnection = null;
-      try
-      {
-         tConnection = ConnectionFactoryHelper.createTopicConnection(factory, config.getUser(), config.getPassword());
-         connection = tConnection;
-      }
-      catch (ClassCastException e)
-      {
-         throw new DeploymentException("Expected a TopicConnection check your provider adaptor: "
-                                       + adapter.getTopicFactoryRef());
-      }
-
-      // Fix: ClientId must be set as the first method call after connection creation.
-      // Fix: ClientId is necessary for durable subscriptions.
-
-      String clientId = config.getClientID();
-
-      log.debug("Using client id: " + clientId);
-      if (clientId != null && clientId.length() > 0)
-         connection.setClientID(clientId);
-
-      // lookup or create the destination topic
-      Topic topic = null;
-      try
-      {
-         // First we try the specified topic
-         if (config.getDestination() != null)
-            topic = (Topic) context.lookup(config.getDestination());
-      }
-      catch (NamingException e)
-      {
-         log.warn("Could not find the topic destination-jndi-name=" + config.getDestination());
-      }
-      catch (ClassCastException e)
-      {
-         throw new DeploymentException("Expected a Topic destination-jndi-name=" + config.getDestination());
-      }
-
-      // FIXME: This is not portable, only works for JBossMQ
-      if (topic == null)
-         topic = (Topic) createDestination(Topic.class,
-                                           context,
-                                           "topic/" + jndiSuffix,
-                                           jndiSuffix);
-
-
-      String durability = config.getDurability();
-      Durability subscriptionDurability;
-
-      if (durability != null && durability.equals("Durable"))
-      {
-         subscriptionDurability = Durability.DURABLE;
-      }
-      else
-      {
-         subscriptionDurability = Durability.NON_DURABLE;
-      }
-
-      registerTopicListeners(tConnection, subscriptionDurability, topic);
-
-   }
-
-   private void registerTopicListeners(TopicConnection tConnection, Durability subscriptionDurability, Topic topic)
-           throws NamingException, JMSException
-   {
-      MessageListener listener = new MessageListenerImpl(this);
-      Class[] producers = getProducerInterfaces(this);
-      HashSet visited = new HashSet();
-      for (Class producer : producers)
-      {
-         for (Method method : producer.getMethods())
-         {
-            long hash = MethodHashing.calculateHash(method);
-            if (visited.contains(hash)) continue;
-            visited.add(hash);
-            Method methodMessage = (Method) advisedMethods.get(hash);
-
-            // set up the server session pool
-            ServerSessionPool serverSessionPool = createSessionPool(topic,
-                                                                    tConnection,
-                                                                    true, // tx
-                                                                    acknowledgeMode.ordinal(),
-                                                                    listener,
-                                                                    methodMessage);
-
-            serverSessionPools.put(hash, serverSessionPool);
-            // To be no-durable or durable
-            ConnectionConsumer connectionConsumer = null;
-            if (subscriptionDurability == Durability.NON_DURABLE)
-            {
-               // Create non durable
-               connectionConsumer =
-               tConnection.createConnectionConsumer(topic,
-                                                    config.getMessageSelector(),
-                                                    serverSessionPool,
-                                                    config.getMaxMessages());
-            }
-            else
-            {
-               // Durable subscription
-               String durableName = config.getSubscriptionName();
-
-               connectionConsumer =
-               tConnection.createDurableConnectionConsumer(topic,
-                                                           durableName,
-                                                           config.getMessageSelector(),
-                                                           serverSessionPool,
-                                                           config.getMaxMessages());
-            }
-            connectionConsumers.put(hash, connectionConsumer);
-            log.debug("Topic connectionConsumer set up");
-         }
-      }
-   }
-
-   /**
-    * Create a server session pool for the given connection.
-    *
-    * @param dest         The destination to use
-    * @param connection   The connection to use.
-    * @param minSession   The minumum number of sessions
-    * @param maxSession   The maximum number of sessions.
-    * @param keepAlive    The time to keep sessions alive
-    * @param isTransacted True if the sessions are transacted.
-    * @param ack          The session acknowledgement mode.
-    * @param listener     The message listener.
-    * @return A server session pool.
-    * @throws javax.jms.JMSException
-    * @throws javax.naming.NamingException Description of Exception
-    */
-   protected ServerSessionPool
-           createSessionPool(final Destination dest,
-                             final Connection connection,
-                             final boolean isTransacted,
-                             int ack,
-                             final MessageListener listener,
-                             Method method)
-           throws NamingException, JMSException
-   {
-      ServerSessionPool pool;
-      Context context = getInitialContext();
-
-      try
-      {
-         // first lookup the factory
-         log.debug("looking up session pool factory: " +
-                   config.getServerSessionPoolFactoryJNDI());
-         ServerSessionPoolFactory factory = (ServerSessionPoolFactory)
-                 context.lookup(config.getServerSessionPoolFactoryJNDI());
-         TransactionAttribute trans = (TransactionAttribute) resolveAnnotation(method, TransactionAttribute.class);
-         TransactionAttributeType txType = trans == null ? TransactionAttributeType.REQUIRED : trans.value();
-
-         boolean isNotSupportedTx = txType == TransactionAttributeType.NOT_SUPPORTED;
-
-         // the create the pool
-         // To work with JBoss 4.0.1SP1 and JBoss 4.0.2
-         // TODO remove this once JBoss 4.0.2 comes out
-         if (getServerSessionPool.getParameterTypes().length == 9)
-         {
-            // the create the pool
-            try
-            {
-               pool = (ServerSessionPool) getServerSessionPool.invoke(factory, dest, connection, config.getMinPoolSize(), config.getMaxPoolSize(), config.getKeepAlive(), isTransacted, ack, !isContainerManagedTx || isNotSupportedTx, listener);
-            }
-            catch (IllegalAccessException e)
-            {
-               throw new RuntimeException(e);
-            }
-            catch (InvocationTargetException e)
-            {
-               throw new RuntimeException(e);
-            }
-         }
-         else
-         {
-            // the create the pool
-            try
-            {
-               pool = (ServerSessionPool) getServerSessionPool.invoke(factory, connection, config.getMinPoolSize(), config.getMaxPoolSize(), config.getKeepAlive(), isTransacted, ack, !isContainerManagedTx || isNotSupportedTx, listener);
-            }
-            catch (IllegalAccessException e)
-            {
-               throw new RuntimeException(e);
-            }
-            catch (InvocationTargetException e)
-            {
-               throw new RuntimeException(e);
-            }
-         }
-      }
-      finally
-      {
-         context.close();
-      }
-
-      return pool;
-   }
-
-   /**
-    * Create and or lookup a JMS destination.
-    *
-    * @param type       Either javax.jms.Queue or javax.jms.Topic.
-    * @param ctx        The naming context to lookup destinations from.
-    * @param jndiName   The name to use when looking up destinations.
-    * @param jndiSuffix The name to use when creating destinations.
-    * @return The destination.
-    * @throws IllegalArgumentException Type is not Queue or Topic.
-    * @throws Exception                Description of Exception
-    */
-   protected Destination createDestination(final Class type,
-                                           final Context ctx,
-                                           final String jndiName,
-                                           final String jndiSuffix)
-           throws Exception
-   {
-      try
-      {
-         // first try to look it up
-         return (Destination) ctx.lookup(jndiName);
-      }
-      catch (NamingException e)
-      {
-         // if the lookup failes, the try to create it
-         log.warn("destination not found: " + jndiName + " reason: " + e);
-         log.warn("creating a new temporary destination: " + jndiName);
-
-         //
-         // jason: we should do away with this...
-         //
-         // attempt to create the destination (note, this is very
-         // very, very unportable).
-         //
-
-         MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
-
-         String methodName;
-         if (type == Topic.class)
-         {
-            methodName = "createTopic";
-         }
-         else if (type == Queue.class)
-         {
-            methodName = "createQueue";
-         }
-         else
-         {
-            // type was not a Topic or Queue, bad user
-            throw new IllegalArgumentException
-                    ("Expected javax.jms.Queue or javax.jms.Topic: " + type);
-         }
-
-         // invoke the server to create the destination
-         server.invoke(new ObjectName("jboss.mq:service=DestinationManager"),
-                       methodName,
-                       new Object[]{jndiSuffix},
-                       new String[]{"java.lang.String"});
-
-         // try to look it up again
-         return (Destination) ctx.lookup(jndiName);
-      }
-   }
-
-   /**
-    * Parse the JNDI suffix from the given JNDI name.
-    *
-    * @param jndiname     The JNDI name used to lookup the destination.
-    * @param defautSuffix Description of Parameter
-    * @return The parsed suffix or the defaultSuffix
-    */
-   protected String parseJndiSuffix(final String jndiname,
-                                    final String defautSuffix)
-   {
-      // jndiSuffix is merely the name that the user has given the MDB.
-      // since the jndi name contains the message type I have to split
-      // at the "/" if there is no slash then I use the entire jndi name...
-      String jndiSuffix = "";
-
-      if (jndiname != null)
-      {
-         int indexOfSlash = jndiname.indexOf("/");
-         if (indexOfSlash != -1)
-         {
-            jndiSuffix = jndiname.substring(indexOfSlash + 1);
-         }
-         else
-         {
-            jndiSuffix = jndiname;
-         }
-      }
-      else
-      {
-         // if the jndi name from jboss.xml is null then lets use the ejbName
-         jndiSuffix = defautSuffix;
-      }
-
-      return jndiSuffix;
-   }
-
-   /**
-    * Return the JMSProviderAdapter that should be used.
-    *
-    * @return The JMSProviderAdapter to use.
-    */
-   protected JMSProviderAdapter getJMSProviderAdapter()
-           throws NamingException
-   {
-      Context context = getInitialContext();
-      //todo make this pluggable
-      String providerAdapterJNDI = config.getProviderAdapterJNDI();
-      try
-      {
-         log.debug("Looking up provider adapter: " + providerAdapterJNDI);
-         return (JMSProviderAdapter) context.lookup(providerAdapterJNDI);
-      }
-      finally
-      {
-         context.close();
-      }
-   }
-
-   /**
-    * Try to get a destination type by looking up the destination JNDI, or
-    * provide a default if there is not destinationJNDI or if it is not possible
-    * to lookup.
-    *
-    * @param ctx             The naming context to lookup destinations from.
-    * @param destinationJNDI The name to use when looking up destinations.
-    * @return The destination type, either derived from destinationJDNI or
-    *         DEFAULT_DESTINATION_TYPE
-    */
-   protected String getDestinationType(Context ctx, String destinationJNDI)
-   {
-      String destType = null;
-
-      if (destinationJNDI != null)
-      {
-         try
-         {
-            Destination dest = (Destination) ctx.lookup(destinationJNDI);
-            if (dest instanceof Topic)
-            {
-               destType = "javax.jms.Topic";
-            }
-            else if (dest instanceof Queue)
-            {
-               destType = "javax.jms.Queue";
-            }
-         }
-         catch (NamingException ex)
-         {
-            log.debug("Could not do heristic lookup of destination ", ex);
-         }
-
-      }
-      if (destType == null)
-      {
-         log.warn("Could not determine destination type, defaults to: " +
-                  DEFAULT_DESTINATION_TYPE);
-
-         destType = DEFAULT_DESTINATION_TYPE;
-      }
-
-      return destType;
-   }
-
-   private void setupDLQ(JMSProviderAdapter adapter) throws Exception
-   {
-      // Set up Dead Letter Queue handler
-      if (config.isUseDLQ())
-      {
-         dlqHandler = new DLQHandler(adapter, config);
-         dlqHandler.create();
-      }
-   }
-
-
-   private void populateActivationSpec()
-   {
       DefaultActivationSpecs defaultSpecs = (DefaultActivationSpecs) resolveAnnotation(DefaultActivationSpecs.class);
       if (defaultSpecs != null)
       {
@@ -836,335 +341,9 @@
       activationSpec.merge(md.activationConfig());
    }
 
-
-   public Object localInvoke(Method method, Object[] args) throws Throwable
-   {
-      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
-      ThreadLocalENCFactory.push(enc);
-      try
-      {
-         long hash = MethodHashing.calculateHash(method);
-         MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
-         if (info == null)
-         {
-            throw new RuntimeException("Could not resolve beanClass method from proxy call");
-         }
-         Interceptor[] aspects1 = info.interceptors;
-         EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects1);
-         nextInvocation.setAdvisor(this);
-         nextInvocation.setArguments(args);
-         return nextInvocation.invokeNext();
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(oldLoader);
-         ThreadLocalENCFactory.pop();
-      }
-   }
-
-   public InvocationResponse dynamicInvoke(Invocation invocation) throws Throwable
-   {
-      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
-      EJBContainerInvocation newSi = null;
-      ThreadLocalENCFactory.push(enc);
-      try
-      {
-         Thread.currentThread().setContextClassLoader(classloader);
-         MethodInvocation si = (MethodInvocation) invocation;
-         MethodInfo info = (MethodInfo) methodInterceptors.get(si.getMethodHash());
-         if (info == null)
-         {
-            throw new RuntimeException("Could not resolve beanClass method from proxy call");
-         }
-         Interceptor[] aspects = info.interceptors;
-         newSi = new EJBContainerInvocation(info, aspects);
-         newSi.setArguments(si.getArguments());
-         newSi.setMetaData(si.getMetaData());
-         newSi.setAdvisor(this);
-
-         InvocationResponse response = new InvocationResponse(newSi.invokeNext());
-         response.setContextInfo(newSi.getResponseContextInfo());
-         return response;
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(oldLoader);
-         ThreadLocalENCFactory.pop();
-      }
-
-   }
-
-   public TimerService getTimerService()
-   {
-      return timerService;
-   }
-
-   public void callTimeout(Timer timer) throws Exception
-   {
-      Method timeout = callbackHandler.getTimeoutCallback();
-      if (timeout == null) throw new EJBException("No method has been annotated with @Timeout");
-      Object[] args = {timer};
-      try
-      {
-         localInvoke(timeout, args);
-      }
-      catch (Throwable throwable)
-      {
-         if (throwable instanceof Exception) throw (Exception) throwable;
-         throw new RuntimeException(throwable);
-      }
-   }
-
-   /**
-    * Stop done from inside, we should not stop the exceptionListener in inner
-    * stop.
-    */
-   protected void innerStop()
-   {
-      try
-      {
-         if (connection != null)
-         {
-            connection.setExceptionListener(null);
-            log.debug("unset exception listener");
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Could not set ExceptionListener to null", e);
-      }
-
-      // Stop the connection
-      try
-      {
-         if (connection != null)
-         {
-            connection.stop();
-            log.debug("connection stopped");
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Could not stop JMS connection", e);
-      }
-   }
-
-
    public void stop() throws Exception
    {
+      super.stop();
       unregisterProducers();
-      EjbTimerUtil.removeTimerService(this);
-      // Silence the exception listener
-      if (exListener != null)
-      {
-         exListener.stop();
-      }
-
-      innerStop();
-
-      if (dlqHandler != null)
-      {
-         dlqHandler.stop();
-      }
-
    }
-
-   public void destroy() throws Exception
-   {
-
-      // close the connection consumer
-      try
-      {
-         for (ConnectionConsumer consumer : connectionConsumers.values())
-         {
-            consumer.close();
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Failed to close connection consumer", e);
-      }
-
-      // clear the server session pool (if it is clearable)
-      try
-      {
-         for (ServerSessionPool ssp : serverSessionPools.values())
-         {
-
-            if (ssp instanceof StdServerSessionPool)
-            {
-               StdServerSessionPool p = (StdServerSessionPool) ssp;
-               p.clear();
-            }
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Failed to clear session pool", e);
-      }
-
-      // close the connection
-      if (connection != null)
-      {
-         try
-         {
-            connection.close();
-            connection = null;
-         }
-         catch (Exception e)
-         {
-            log.error("Failed to close connection", e);
-         }
-      }
-
-
-      // Take down DLQ
-      try
-      {
-         if (dlqHandler != null)
-         {
-            dlqHandler.destroy();
-            dlqHandler = null;
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Failed to close the dlq handler", e);
-      }
-
-   }
-
-   /**
-    * An implementation of MessageListener that passes messages on to the
-    * container invoker.
-    */
-   class MessageListenerImpl
-           implements MessageListener
-   {
-      /**
-       * The container invoker.
-       */
-      ConsumerContainer invoker;
-      // = null;
-
-      /**
-       * Construct a <tt>MessageListenerImpl</tt> .
-       *
-       * @param invoker The container invoker. Must not be null.
-       */
-      MessageListenerImpl(final ConsumerContainer invoker)
-      {
-         // assert invoker != null;
-
-         this.invoker = invoker;
-      }
-
-      /**
-       * Process a message.
-       *
-       * @param message The message to process.
-       */
-      public void onMessage(final Message message)
-      {
-         // assert message != null;
-         if (log.isTraceEnabled())
-         {
-            log.trace("processing message: " + message);
-         }
-
-         // Invoke, shuld we catch any Exceptions??
-         try
-         {
-            Transaction tx = TxUtil.getTransactionManager().getTransaction();
-
-            // DLQHandling
-            if (config.isUseDLQ() && // Is Dead Letter Queue used at all
-                message.getJMSRedelivered() && // Was message resent
-                dlqHandler.handleRedeliveredMessage(message, tx)) //Did the DLQ handler take care of the message
-            {
-               // Message will be placed on Dead Letter Queue,
-               // if redelivered to many times
-               return;
-            }
-            Invocation invocation = (Invocation) ((ObjectMessage) message).getObject();
-            invocation.getMetaData().addMetaData(CONSUMER_MESSAGE, CONSUMER_MESSAGE, message, PayloadKey.TRANSIENT);
-            invoker.dynamicInvoke(invocation);
-
-         }
-         catch (Throwable e)
-         {
-            log.error("Exception in JMSCI message listener", e);
-         }
-      }
-   }
-
-   /**
-    * ExceptionListener for failover handling.
-    */
-   class ExceptionListenerImpl
-           implements ExceptionListener
-   {
-      ConsumerContainer invoker;
-      Thread currentThread;
-      boolean notStoped = true;
-
-      ExceptionListenerImpl(final ConsumerContainer invoker)
-      {
-         this.invoker = invoker;
-      }
-
-      /**
-       * #Description of the Method
-       *
-       * @param ex Description of Parameter
-       */
-      public void onException(JMSException ex)
-      {
-         currentThread = Thread.currentThread();
-
-         log.warn("JMS provider failure detected: ", ex);
-         boolean tryIt = true;
-         while (tryIt && notStoped)
-         {
-            log.info("Trying to reconnect to JMS provider");
-            try
-            {
-               try
-               {
-                  Thread.sleep(config.getReconnectInterval());
-               }
-               catch (InterruptedException ie)
-               {
-                  tryIt = false;
-                  return;
-               }
-
-               // Reboot container
-               invoker.innerStop();
-               invoker.destroy();
-               invoker.start();
-               tryIt = false;
-
-               log.info("Reconnected to JMS provider");
-            }
-            catch (Exception e)
-            {
-               log.error("Reconnect failed: JMS provider failure detected:", e);
-            }
-         }
-         currentThread = null;
-      }
-
-      void stop()
-      {
-         log.debug("Stop requested");
-
-         notStoped = false;
-         if (currentThread != null)
-         {
-            currentThread.interrupt();
-            log.debug("Current thread interrupted");
-         }
-      }
-   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/LocalProducerFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/LocalProducerFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/LocalProducerFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -71,7 +71,7 @@
    {
       super.start();
       try{
-         NonSerializableFactory.bind(ctx, jndiName + PROXY_FACTORY_NAME, this);
+         NonSerializableFactory.rebind(ctx, jndiName + PROXY_FACTORY_NAME, this);
       } catch (NamingException e)
       {
          NamingException namingException = new NamingException("Could not bind local producer factory with name " + factoryName + " into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/MDB.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -23,21 +23,18 @@
 
 import org.jboss.annotation.ejb.AcknowledgementMode;
 import org.jboss.annotation.ejb.DefaultActivationSpecs;
-import org.jboss.annotation.ejb.Durability;
 import org.jboss.annotation.ejb.ResourceAdapter;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.MethodInfo;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.util.MethodHashing;
 import org.jboss.deployment.DeploymentException;
-import org.jboss.ejb.txtimer.TimedObjectInvoker;
 import org.jboss.ejb3.*;
 import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
-import org.jboss.ejb3.tx.TxUtil;
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.ejb3.timerservice.TimerServiceFactory;
 import org.jboss.jms.ConnectionFactoryHelper;
-import org.jboss.jms.asf.ServerSessionPoolFactory;
-import org.jboss.jms.asf.StdServerSessionPool;
 import org.jboss.jms.jndi.JMSProviderAdapter;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ActivationConfigPropertyMetaData;
@@ -51,9 +48,7 @@
 import javax.management.ObjectName;
 import javax.naming.Context;
 import javax.naming.NamingException;
-import javax.transaction.Transaction;
 import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.*;
 
@@ -63,32 +58,12 @@
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$
  */
-public class MDB extends EJBContainer implements TimedObjectInvoker
+public class MDB extends MessagingContainer 
 {
    private static final Logger log = Logger.getLogger(MDB.class);
-
-   protected Method ON_MESSAGE;
-   protected TimerService timerService;
-   protected ActivationSpec activationSpec = new ActivationSpec();
-   protected boolean isContainerManagedTx;
-   protected AcknowledgementMode acknowledgeMode;
-   protected boolean isNotSupportedTx;
-   protected Connection connection;
-   protected ConnectionConsumer connectionConsumer;
-   protected ServerSessionPool serverSessionPool;
-   protected MDBConfig config;
-   protected ExceptionListenerImpl exListener;
-   protected DLQHandler dlqHandler;
+   
    protected Class messagingType = null;
-   protected JBossMessageEndpointFactory messageEndpointFactory;
-
    /**
-    * This is needed because API changed from JBoss 4.0.1sp1 to 4.0.2
-    * TODO remove this after 4.0.2 is out.
-    */
-   protected Method getServerSessionPool;
-
-   /**
     * Default destination type. Used when no message-driven-destination is given
     * in ejb-jar, and a lookup of destinationJNDI from jboss.xml is not
     * successfull. Default value: javax.jms.Topic.
@@ -98,24 +73,9 @@
    public MDB(String ejbName, AspectManager manager, ClassLoader cl, String beanClassName, Hashtable ctxProperties,
               InterceptorInfoRepository interceptorRepository, Ejb3Deployment deployment)
    {
-      super(Ejb3Module.BASE_EJB3_JMX_NAME + ",name=" + ejbName, manager, cl, beanClassName, ejbName, ctxProperties, interceptorRepository, deployment);
-      beanContextClass = MDBContext.class;
-      Method[] methods = ServerSessionPoolFactory.class.getMethods();
-      for (Method m : methods)
-      {
-         if (m.getName().equals("getServerSessionPool"))
-         {
-            getServerSessionPool = m;
-            break;
-         }
-      }
+      super(ejbName, manager, cl, beanClassName, ctxProperties, interceptorRepository, deployment);
    }
-
-   public void setMessageEndpointFactory(JBossMessageEndpointFactory messageEndpointFactory)
-   {
-      this.messageEndpointFactory = messageEndpointFactory;
-   }
-
+   
    public Class getMessagingType()
    {
       if (messagingType == null)
@@ -132,127 +92,40 @@
 
       return messagingType;
    }
-
-   public String getResourceAdaptorName()
+   
+   public MethodInfo getMethodInfo(Method method)
    {
-      ResourceAdapter annotation = (ResourceAdapter) resolveAnnotation(ResourceAdapter.class);
-      if (annotation == null) return null;
-      return annotation.value();
+      long hash = MethodHashing.calculateHash(method);
+      MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
+      return info;
    }
 
-   public String getDestination()
-   {
-      String result = null;
-      MessageDriven annotation = (MessageDriven) resolveAnnotation(MessageDriven.class);
-      for (ActivationConfigProperty property : annotation.activationConfig())
-      {
-         if (property.propertyName().equals("destination"))
-         {
-            return property.propertyValue();
-         }
-      }
-
-      return result;
-   }
-
    public Map getActivationConfigProperties()
    {
       HashMap result = new HashMap();
-      MessageDriven annotation = (MessageDriven) resolveAnnotation(MessageDriven.class);
-      for (ActivationConfigProperty property : annotation.activationConfig())
+      MessageDriven mdAnnotation = (MessageDriven) resolveAnnotation(MessageDriven.class);
+      for (ActivationConfigProperty property : mdAnnotation.activationConfig())
       {
-         if (!property.propertyName().equals("destination") &&
-                 !property.propertyName().equals("resourceAdaptorName") &&
-                 !property.propertyName().equals("messagingType"))
+         addActivationSpecProperty(result, property);
+      }
+      
+      DefaultActivationSpecs defaultSpecsAnnotation = (DefaultActivationSpecs)resolveAnnotation(DefaultActivationSpecs.class);
+      if (defaultSpecsAnnotation != null)
+      {
+         for (ActivationConfigProperty property : defaultSpecsAnnotation.value())
          {
-            ActivationConfigPropertyMetaData metaData = new ActivationConfigPropertyMetaData();
-            try
-            {
-               Field nameField = ActivationConfigPropertyMetaData.class.getDeclaredField("name");
-               nameField.setAccessible(true);
-               nameField.set(metaData, property.propertyName());
-               Field valueField = ActivationConfigPropertyMetaData.class.getDeclaredField("value");
-               valueField.setAccessible(true);
-               valueField.set(metaData, property.propertyValue());
-            }
-            catch (Exception e)
-            {
-               throw new RuntimeException(e);
-            }
-
-            /*
-             * Older versions don't have this
-             * TODO revert to this after we ditch 4.0.3SP1 as supported EJB3 platform
-            metaData.setName(property.propertyName());
-            metaData.setValue(property.propertyValue());
-            */
-            result.put(property.propertyName(), metaData);
+            addActivationSpecProperty(result, property);
          }
       }
-
+      
       return result;
    }
-
-   /**
-    * Initialize the container invoker. Sets up a connection, a server session
-    * pool and a connection consumer for the configured destination.
-    * <p/>
-    * Any JMSExceptions produced while initializing will be assumed to be
-    * caused due to JMS Provider failure.
-    *
-    * @throws Exception Failed to initalize.
-    */
+   
    public void start() throws Exception
    {
       super.start();
-      exListener = new ExceptionListenerImpl(this);
-
-      populateActivationSpec();
-
-      config = MDBConfig.createMDBConfig(activationSpec);
-
-      innerStart();
-
-      timerService = EjbTimerUtil.getTimerService(this, this);
-
-      startProxies();
    }
 
-   protected void innerStart() throws Exception
-   {
-      try
-      {
-         innerCreate();
-      }
-      catch (final JMSException e)
-      {
-         //
-         // start a thread up to handle recovering the connection. so we can
-         // attach to the jms resources once they become available
-         //
-         new Thread("EJB3 MDB Create Recovery Thread")
-         {
-            public void run()
-            {
-               exListener.onException(e);
-            }
-         }.start();
-         return;
-      }
-
-      if (dlqHandler != null)
-      {
-         dlqHandler.start();
-      }
-
-      if (connection != null)
-      {
-         connection.setExceptionListener(exListener);
-         connection.start();
-      }
-
-   }
-
    public ObjectName getJmxName()
    {
       ObjectName jmxName = null;
@@ -271,558 +144,9 @@
 
       return jmxName;
    }
-
-   protected void startProxies() throws Exception
+   
+   protected void populateActivationSpec()
    {
-      if (messageEndpointFactory != null)
-      {
-         messageEndpointFactory.start();
-      }
-   }
-
-   private void innerCreate() throws Exception
-   {
-      log.debug("Initializing");
-
-      MessageDriven messageDriven = (MessageDriven) resolveAnnotation(MessageDriven.class);
-
-      // Get the JMS provider
-      // todo get rid of server module dependency
-      JMSProviderAdapter adapter = getJMSProviderAdapter();
-      log.debug("Provider adapter: " + adapter);
-
-      setupDLQ(adapter);
-
-      // Is container managed?
-      TransactionManagement transactionManagement = (TransactionManagement) resolveAnnotation(TransactionManagement.class);
-      if (transactionManagement == null)
-         isContainerManagedTx = true;
-      else
-         isContainerManagedTx = transactionManagement.value() == TransactionManagementType.CONTAINER;
-      String ackMode = config.getAcknowledgeMode();
-      if (ackMode != null && (ackMode.equals("DUPS_OK_ACKNOWLEDGE")
-              || ackMode.equals(AcknowledgementMode.AUTO_ACKNOWLEDGE.name())
-              || ackMode.equals("Dups-ok-acknowledge")))
-      {
-         acknowledgeMode = AcknowledgementMode.DUPS_OK;
-      }
-      else
-      {
-         acknowledgeMode = AcknowledgementMode.AUTO_ACKNOWLEDGE;
-      }
-
-      TransactionAttribute trans = (TransactionAttribute) resolveAnnotation(getOnMessage(), TransactionAttribute.class);
-      TransactionAttributeType txType = trans == null ? TransactionAttributeType.REQUIRED : trans.value();
-
-      isNotSupportedTx = txType == TransactionAttributeType.NOT_SUPPORTED;
-
-      // Connect to the JNDI server and get a reference to root context
-      Context context = adapter.getInitialContext();
-      log.debug("context: " + context);
-
-      // if we can't get the root context then exit with an exception
-      if (context == null)
-      {
-         throw new RuntimeException("Failed to get the root context");
-      }
-
-      String destinationType = config.getDestinationType();
-
-      // Unfortunately the destination is optional, so if we do not have one
-      // here we have to look it up if we have a destinationJNDI, else give it
-      // a default.
-      if (destinationType == null)
-      {
-         log.warn("No message-driven-destination given; using; guessing type");
-         destinationType = getDestinationType(context, config.getDestination());
-      }
-
-      if ("javax.jms.Topic".equals(destinationType))
-      {
-         innerCreateTopic(context, adapter);
-
-      }
-      else if ("javax.jms.Queue".equals(destinationType))
-      {
-         innerCreateQueue(context, adapter);
-
-      }
-      else
-         throw new DeploymentException("Unknown destination-type " + destinationType);
-
-      log.debug("Initialized with config " + toString());
-
-      context.close();
-   }
-
-   private void innerCreateQueue(Context context, JMSProviderAdapter adapter)
-           throws Exception
-   {
-      log.debug("Got destination type Queue for " + ejbName);
-
-      // Get the JNDI suffix of the destination
-      String jndiSuffix = parseJndiSuffix(config.getDestination(), ejbName);
-      log.debug("jndiSuffix: " + jndiSuffix);
-
-      // create a queue connection
-      Object qFactory = context.lookup(adapter.getQueueFactoryRef());
-      QueueConnection qConnection = null;
-      try
-      {
-         qConnection = ConnectionFactoryHelper.createQueueConnection(qFactory, config.getUser(), config.getPassword());
-         connection = qConnection;
-      }
-      catch (ClassCastException e)
-      {
-         throw new DeploymentException("Expected a QueueConnection check your provider adaptor: "
-                 + adapter.getQueueFactoryRef());
-      }
-
-      // Set the optional client id
-      String clientId = config.getClientID();
-
-      log.debug("Using client id: " + clientId);
-      if (clientId != null && clientId.length() > 0)
-         connection.setClientID(clientId);
-
-      // lookup or create the destination queue
-      Queue queue = null;
-      try
-      {
-         // First we try the specified queue
-         if (config.getDestination() != null)
-            queue = (Queue) context.lookup(config.getDestination());
-      }
-      catch (NamingException e)
-      {
-         log.warn("Could not find the queue destination-jndi-name=" + config.getDestination());
-      }
-      catch (ClassCastException e)
-      {
-         throw new DeploymentException("Expected a Queue destination-jndi-name=" + config.getDestination());
-      }
-
-      // FIXME: This is not portable, only works for JBossMQ
-      if (queue == null)
-         queue = (Queue) createDestination(Queue.class,
-                 context,
-                 "queue/" + jndiSuffix,
-                 jndiSuffix);
-
-
-      if (queue != null)
-      {
-         // set up the server session pool
-         serverSessionPool = createSessionPool(queue,
-                 qConnection,
-                 true, // tx
-                 acknowledgeMode.ordinal(),
-                 new MessageListenerImpl(this));
-         log.debug("Server session pool: " + pool);
-
-         // create the connection consumer
-         connectionConsumer =
-                 qConnection.createConnectionConsumer(queue,
-                         config.getMessageSelector(),
-                         serverSessionPool,
-                         config.getMaxMessages());
-         log.debug("Connection consumer: " + connectionConsumer);
-      }
-   }
-
-   private void innerCreateTopic(Context context, JMSProviderAdapter adapter)
-           throws Exception
-   {
-      log.debug("Got destination type Topic for " + ejbName);
-
-      // Get the JNDI suffix of the destination
-      String jndiSuffix = parseJndiSuffix(config.getDestination(), ejbName);
-      log.debug("jndiSuffix: " + jndiSuffix);
-
-      // create a topic connection
-      Object factory = context.lookup(adapter.getTopicFactoryRef());
-      TopicConnection tConnection = null;
-      try
-      {
-         tConnection = ConnectionFactoryHelper.createTopicConnection(factory, config.getUser(), config.getPassword());
-         connection = tConnection;
-      }
-      catch (ClassCastException e)
-      {
-         throw new DeploymentException("Expected a TopicConnection check your provider adaptor: "
-                 + adapter.getTopicFactoryRef());
-      }
-
-      // Fix: ClientId must be set as the first method call after connection creation.
-      // Fix: ClientId is necessary for durable subscriptions.
-
-      String clientId = config.getClientID();
-
-      log.debug("Using client id: " + clientId);
-      if (clientId != null && clientId.length() > 0)
-         connection.setClientID(clientId);
-
-      // lookup or create the destination topic
-      Topic topic = null;
-      try
-      {
-         // First we try the specified topic
-         if (config.getDestination() != null)
-            topic = (Topic) context.lookup(config.getDestination());
-      }
-      catch (NamingException e)
-      {
-         log.warn("Could not find the topic destination-jndi-name=" + config.getDestination());
-      }
-      catch (ClassCastException e)
-      {
-         throw new DeploymentException("Expected a Topic destination-jndi-name=" + config.getDestination());
-      }
-
-      // FIXME: This is not portable, only works for JBossMQ
-      if (topic == null)
-         topic = (Topic) createDestination(Topic.class,
-                 context,
-                 "topic/" + jndiSuffix,
-                 jndiSuffix);
-      if (topic != null)
-      {
-         // set up the server session pool
-         serverSessionPool = createSessionPool(topic,
-                 tConnection,
-                 true, // tx
-                 acknowledgeMode.ordinal(),
-                 new MessageListenerImpl(this));
-
-         String durability = config.getDurability();
-         Durability subscriptionDurability;
-
-         if (durability != null && durability.equals("Durable"))
-         {
-            subscriptionDurability = Durability.DURABLE;
-         }
-         else
-         {
-            subscriptionDurability = Durability.NON_DURABLE;
-         }
-
-         // To be no-durable or durable
-         if (subscriptionDurability == Durability.NON_DURABLE)
-         {
-            // Create non durable
-            connectionConsumer =
-                    tConnection.createConnectionConsumer(topic,
-                            config.getMessageSelector(),
-                            serverSessionPool,
-                            config.getMaxMessages());
-         }
-         else
-         {
-            // Durable subscription
-            String durableName = config.getSubscriptionName();
-
-            connectionConsumer =
-                    tConnection.createDurableConnectionConsumer(topic,
-                            durableName,
-                            config.getMessageSelector(),
-                            serverSessionPool,
-                            config.getMaxMessages());
-         }
-         log.debug("Topic connectionConsumer set up");
-      }
-   }
-
-   /**
-    * Create a server session pool for the given connection.
-    *
-    * @param connection   The connection to use.
-    * @param minSession   The minumum number of sessions
-    * @param maxSession   The maximum number of sessions.
-    * @param keepAlive    The time to keep sessions alive
-    * @param isTransacted True if the sessions are transacted.
-    * @param ack          The session acknowledgement mode.
-    * @param listener     The message listener.
-    * @return A server session pool.
-    * @throws javax.jms.JMSException
-    * @throws NamingException        Description of Exception
-    */
-   protected ServerSessionPool
-           createSessionPool(final Destination dest,
-                             final Connection connection,
-                             final boolean isTransacted,
-                             int ack,
-                             final MessageListener listener)
-           throws NamingException, JMSException
-   {
-      ServerSessionPool pool;
-      Context context = EJB3Util.getInitialContext(initialContextProperties);
-
-      try
-      {
-         // first lookup the factory
-         log.debug("JNDI Hashtable: " + initialContextProperties);
-         ServerSessionPoolFactory factory = (ServerSessionPoolFactory)
-                 context.lookup(config.getServerSessionPoolFactoryJNDI());
-
-         // To work with JBoss 4.0.1SP1 and JBoss 4.0.2
-         // TODO remove this once JBoss 4.0.2 comes out
-         if (getServerSessionPool.getParameterTypes().length == 9)
-         {
-            // the create the pool
-            try
-            {
-               pool = (ServerSessionPool) getServerSessionPool.invoke(factory, dest, connection, config.getMinPoolSize(), config.getMaxPoolSize(), config.getKeepAlive(), isTransacted, ack, !isContainerManagedTx || isNotSupportedTx, listener);
-            }
-            catch (IllegalAccessException e)
-            {
-               throw new RuntimeException(e);
-            }
-            catch (InvocationTargetException e)
-            {
-               throw new RuntimeException(e);
-            }
-         }
-         else
-         {
-            // the create the pool
-            try
-            {
-               pool = (ServerSessionPool) getServerSessionPool.invoke(factory, connection, config.getMinPoolSize(), config.getMaxPoolSize(), config.getKeepAlive(), isTransacted, ack, !isContainerManagedTx || isNotSupportedTx, listener);
-            }
-            catch (IllegalAccessException e)
-            {
-               throw new RuntimeException(e);
-            }
-            catch (InvocationTargetException e)
-            {
-               throw new RuntimeException(e);
-            }
-         }
-      }
-      finally
-      {
-         context.close();
-      }
-
-      return pool;
-   }
-
-   /**
-    * Create and or lookup a JMS destination.
-    *
-    * @param type       Either javax.jms.Queue or javax.jms.Topic.
-    * @param ctx        The naming context to lookup destinations from.
-    * @param jndiName   The name to use when looking up destinations.
-    * @param jndiSuffix The name to use when creating destinations.
-    * @return The destination.
-    * @throws IllegalArgumentException Type is not Queue or Topic.
-    * @throws Exception                Description of Exception
-    */
-   protected Destination createDestination(final Class type,
-                                           final Context ctx,
-                                           final String jndiName,
-                                           final String jndiSuffix)
-           throws Exception
-   {
-      try
-      {
-         // first try to look it up
-         return (Destination) ctx.lookup(jndiName);
-      }
-      catch (NamingException e)
-      {
-         // is JMS?
-         if (getDestination() == null)
-         {
-            return null;
-         }
-         else
-         {
-            // if the lookup failes, the try to create it
-            log.warn("destination not found: " + jndiName + " reason: " + e);
-            log.warn("creating a new temporary destination: " + jndiName);
-
-            //
-            // jason: we should do away with this...
-            //
-            // attempt to create the destination (note, this is very
-            // very, very unportable).
-            //
-
-            MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
-
-            String methodName;
-            if (type == Topic.class)
-            {
-               methodName = "createTopic";
-            }
-            else if (type == Queue.class)
-            {
-               methodName = "createQueue";
-            }
-            else
-            {
-               // type was not a Topic or Queue, bad user
-               throw new IllegalArgumentException
-                       ("Expected javax.jms.Queue or javax.jms.Topic: " + type);
-            }
-
-            // invoke the server to create the destination
-            server.invoke(new ObjectName("jboss.mq:service=DestinationManager"),
-                    methodName,
-                    new Object[]{jndiSuffix},
-                    new String[]{"java.lang.String"});
-
-            // try to look it up again
-            return (Destination) ctx.lookup(jndiName);
-         }
-      }
-   }
-
-   /**
-    * Parse the JNDI suffix from the given JNDI name.
-    *
-    * @param jndiname     The JNDI name used to lookup the destination.
-    * @param defautSuffix Description of Parameter
-    * @return The parsed suffix or the defaultSuffix
-    */
-   protected String parseJndiSuffix(final String jndiname,
-                                    final String defautSuffix)
-   {
-      // jndiSuffix is merely the name that the user has given the MDB.
-      // since the jndi name contains the message type I have to split
-      // at the "/" if there is no slash then I use the entire jndi name...
-      String jndiSuffix = "";
-
-      if (jndiname != null)
-      {
-         int indexOfSlash = jndiname.indexOf("/");
-         if (indexOfSlash != -1)
-         {
-            jndiSuffix = jndiname.substring(indexOfSlash + 1);
-         }
-         else
-         {
-            jndiSuffix = jndiname;
-         }
-      }
-      else
-      {
-         // if the jndi name from jboss.xml is null then lets use the ejbName
-         jndiSuffix = defautSuffix;
-      }
-
-      return jndiSuffix;
-   }
-
-   /**
-    * Return the JMSProviderAdapter that should be used.
-    *
-    * @return The JMSProviderAdapter to use.
-    */
-   protected JMSProviderAdapter getJMSProviderAdapter()
-           throws NamingException
-   {
-      Context context = getInitialContext();
-      //todo make this pluggable
-      String providerAdapterJNDI = config.getProviderAdapterJNDI();
-      try
-      {
-         log.debug("Looking up provider adapter: " + providerAdapterJNDI);
-         return (JMSProviderAdapter) context.lookup(providerAdapterJNDI);
-      }
-      finally
-      {
-         context.close();
-      }
-   }
-
-   /**
-    * Try to get a destination type by looking up the destination JNDI, or
-    * provide a default if there is not destinationJNDI or if it is not possible
-    * to lookup.
-    *
-    * @param ctx             The naming context to lookup destinations from.
-    * @param destinationJNDI The name to use when looking up destinations.
-    * @return The destination type, either derived from destinationJDNI or
-    *         DEFAULT_DESTINATION_TYPE
-    */
-   protected String getDestinationType(Context ctx, String destinationJNDI)
-   {
-      String destType = null;
-
-      if (destinationJNDI != null)
-      {
-         try
-         {
-            Destination dest = (Destination) ctx.lookup(destinationJNDI);
-            if (dest instanceof javax.jms.Topic)
-            {
-               destType = "javax.jms.Topic";
-            }
-            else if (dest instanceof javax.jms.Queue)
-            {
-               destType = "javax.jms.Queue";
-            }
-         }
-         catch (NamingException ex)
-         {
-            log.debug("Could not do heristic lookup of destination ", ex);
-         }
-
-      }
-      if (destType == null)
-      {
-         log.warn("Could not determine destination type, defaults to: " +
-                 DEFAULT_DESTINATION_TYPE);
-
-         destType = DEFAULT_DESTINATION_TYPE;
-      }
-
-      return destType;
-   }
-
-   private void setupDLQ(JMSProviderAdapter adapter) throws Exception
-   {
-      // Set up Dead Letter Queue handler
-      if (config.isUseDLQ())
-      {
-         dlqHandler = new DLQHandler(adapter, config);
-         dlqHandler.create();
-      }
-   }
-
-   /**
-    * Initialize the ON_MESSAGE reference.
-    */
-   protected Method getOnMessage()
-   {
-      if (ON_MESSAGE != null) return ON_MESSAGE;
-      try
-      {
-         final Class arg = Message.class;
-         if (javax.jms.MessageListener.class.isAssignableFrom(clazz))
-         {
-            ON_MESSAGE = clazz.getMethod("onMessage", new Class[]{arg});
-         }
-         else
-         {
-            Class messagingTypeClass = getMessagingType();
-            Method[] methods = messagingTypeClass.getDeclaredMethods();
-            ON_MESSAGE = methods[0];
-         }
-      }
-      catch (Exception e)
-      {
-         e.printStackTrace();
-         throw new ExceptionInInitializerError(e);
-      }
-
-      return ON_MESSAGE;
-   }
-
-   private void populateActivationSpec()
-   {
       DefaultActivationSpecs defaultSpecs = (DefaultActivationSpecs) resolveAnnotation(DefaultActivationSpecs.class);
       if (defaultSpecs != null)
       {
@@ -833,326 +157,4 @@
 
       activationSpec.merge(md.activationConfig());
    }
-
-   public Object localInvoke(Method method, Object[] args) throws Throwable
-   {
-      MethodInfo info = getMethodInfo(method);
-      if (info == null)
-      {
-         throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
-      }
-      return localInvoke(info, args);
-
-   }
-
-   public MethodInfo getMethodInfo(Method method)
-   {
-      long hash = MethodHashing.calculateHash(method);
-      MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
-      return info;
-   }
-
-   public Object localInvoke(MethodInfo info, Object[] args) throws Throwable
-   {
-      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
-      ThreadLocalENCFactory.push(enc);
-      try
-      {
-         Interceptor[] aspects = info.interceptors;
-         EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects);
-         nextInvocation.setAdvisor(this);
-         nextInvocation.setArguments(args);
-         return nextInvocation.invokeNext();
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(oldLoader);
-         ThreadLocalENCFactory.pop();
-      }
-   }
-
-   public TimerService getTimerService()
-   {
-      return timerService;
-   }
-
-   public void callTimeout(Timer timer) throws Exception
-   {
-      Method timeout = callbackHandler.getTimeoutCallback();
-      if (timeout == null) throw new EJBException("No method has been annotated with @Timeout");
-      Object[] args = {timer};
-      try
-      {
-         localInvoke(timeout, args);
-      }
-      catch (Throwable throwable)
-      {
-         if (throwable instanceof Exception) throw (Exception) throwable;
-         throw new RuntimeException(throwable);
-      }
-   }
-
-   /**
-    * Stop done from inside, we should not stop the exceptionListener in inner
-    * stop.
-    */
-   protected void innerStop()
-   {
-      try
-      {
-         if (connection != null)
-         {
-            connection.setExceptionListener(null);
-            log.debug("unset exception listener");
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Could not set ExceptionListener to null", e);
-      }
-
-      // Stop the connection
-      try
-      {
-         if (connection != null)
-         {
-            connection.stop();
-            log.debug("connection stopped");
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Could not stop JMS connection", e);
-      }
-   }
-
-
-   public void stop() throws Exception
-   {
-      EjbTimerUtil.removeTimerService(this);
-      // Silence the exception listener
-      if (exListener != null)
-      {
-         exListener.stop();
-      }
-
-      innerStop();
-
-      if (dlqHandler != null)
-      {
-         dlqHandler.stop();
-      }
-
-      stopProxies();
-   }
-
-   protected void stopProxies() throws Exception
-   {
-      if (messageEndpointFactory != null)
-      {
-         messageEndpointFactory.stop();
-      }
-   }
-
-   public void innerDestroy() throws Exception
-   {
-
-      // close the connection consumer
-      try
-      {
-         if (connectionConsumer != null)
-         {
-            connectionConsumer.close();
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Failed to close connection consumer", e);
-      }
-
-      // clear the server session pool (if it is clearable)
-      try
-      {
-         if (serverSessionPool instanceof StdServerSessionPool)
-         {
-            StdServerSessionPool p = (StdServerSessionPool) serverSessionPool;
-            p.clear();
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Failed to clear session pool", e);
-      }
-
-      // close the connection
-      if (connection != null)
-      {
-         try
-         {
-            connection.close();
-            connection = null;
-         }
-         catch (Exception e)
-         {
-            log.error("Failed to close connection", e);
-         }
-      }
-
-      // Take down DLQ
-      try
-      {
-         if (dlqHandler != null)
-         {
-            dlqHandler.destroy();
-            dlqHandler = null;
-         }
-      }
-      catch (Exception e)
-      {
-         log.error("Failed to close the dlq handler", e);
-      }
-
-   }
-
-   public void destroy() throws Exception
-   {
-      innerDestroy();
-   }
-
-   /**
-    * An implementation of MessageListener that passes messages on to the
-    * container invoker.
-    */
-   class MessageListenerImpl
-           implements MessageListener
-   {
-      /**
-       * The container invoker.
-       */
-      MDB invoker;
-      // = null;
-
-      /**
-       * Construct a <tt>MessageListenerImpl</tt> .
-       *
-       * @param invoker The container invoker. Must not be null.
-       */
-      MessageListenerImpl(final MDB invoker)
-      {
-         // assert invoker != null;
-
-         this.invoker = invoker;
-      }
-
-      /**
-       * Process a message.
-       *
-       * @param message The message to process.
-       */
-      public void onMessage(final Message message)
-      {
-         // assert message != null;
-         if (log.isTraceEnabled())
-         {
-            log.trace("processing message: " + message);
-         }
-
-         // Invoke, shuld we catch any Exceptions??
-         try
-         {
-            Transaction tx = TxUtil.getTransactionManager().getTransaction();
-
-            // DLQHandling
-            if (config.isUseDLQ() && // Is Dead Letter Queue used at all
-                    message.getJMSRedelivered() && // Was message resent
-                    dlqHandler.handleRedeliveredMessage(message, tx)) //Did the DLQ handler take care of the message
-            {
-               // Message will be placed on Dead Letter Queue,
-               // if redelivered to many times
-               return;
-            }
-            invoker.localInvoke(ON_MESSAGE,
-                    new Object[]{message});
-
-         }
-         catch (RuntimeException e)
-         {
-            throw e;
-         }
-         catch (Throwable e)
-         {
-            log.error("Exception in JMSCI message listener", e);
-         }
-      }
-   }
-
-   /**
-    * ExceptionListener for failover handling.
-    */
-   class ExceptionListenerImpl
-           implements ExceptionListener
-   {
-      MDB invoker;
-      Thread currentThread;
-      boolean notStoped = true;
-
-      ExceptionListenerImpl(final MDB invoker)
-      {
-         this.invoker = invoker;
-      }
-
-      /**
-       * #Description of the Method
-       *
-       * @param ex Description of Parameter
-       */
-      public void onException(JMSException ex)
-      {
-         currentThread = Thread.currentThread();
-
-         log.warn("JMS provider failure detected: ", ex);
-         boolean tryIt = true;
-         while (tryIt && notStoped)
-         {
-            log.info("Trying to reconnect to JMS provider");
-            try
-            {
-               try
-               {
-                  Thread.sleep(config.getReconnectInterval());
-               }
-               catch (InterruptedException ie)
-               {
-                  tryIt = false;
-                  return;
-               }
-
-               // Reboot container
-               invoker.innerStop();
-               invoker.innerDestroy();
-               invoker.innerStart();
-               tryIt = false;
-
-               log.info("Reconnected to JMS provider");
-            }
-            catch (Exception e)
-            {
-               log.error("Reconnect failed: JMS provider failure detected:", e);
-            }
-         }
-         currentThread = null;
-      }
-
-      void stop()
-      {
-         log.debug("Stop requested");
-
-         notStoped = false;
-         if (currentThread != null)
-         {
-            currentThread.interrupt();
-            log.debug("Current thread interrupted");
-         }
-      }
-   }
 }

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,623 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.mdb;
+
+import org.jboss.annotation.ejb.ResourceAdapter;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.deployment.DeploymentException;
+import org.jboss.ejb3.*;
+import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
+import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.ejb3.timerservice.TimerServiceFactory;
+import org.jboss.jms.jndi.JMSProviderAdapter;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ActivationConfigPropertyMetaData;
+
+import javax.ejb.*;
+import javax.ejb.Timer;
+import javax.jms.*;
+import javax.jms.Queue;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.*;
+
+/**
+ * @version <tt>$Revision: 56518 $</tt>
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public abstract class MessagingContainer extends EJBContainer implements TimedObjectInvoker
+{
+   private static final Logger log = Logger.getLogger(MessagingContainer.class);
+   
+   protected TimerService timerService;
+   protected ActivationSpec activationSpec = new ActivationSpec();
+   protected JBossMessageEndpointFactory messageEndpointFactory;
+
+   /**
+    * Default destination type. Used when no message-driven-destination is given
+    * in ejb-jar, and a lookup of destinationJNDI from jboss.xml is not
+    * successfull. Default value: javax.jms.Topic.
+    */
+   protected final static String DEFAULT_DESTINATION_TYPE = "javax.jms.Topic";
+
+   public MessagingContainer(String ejbName, AspectManager manager, ClassLoader cl, String beanClassName, Hashtable ctxProperties,
+              InterceptorInfoRepository interceptorRepository, Ejb3Deployment deployment)
+   {
+      super(Ejb3Module.BASE_EJB3_JMX_NAME + ",name=" + ejbName, manager, cl, beanClassName, ejbName, ctxProperties, interceptorRepository, deployment);
+      
+      beanContextClass = MDBContext.class;
+      
+      messageEndpointFactory = new JBossMessageEndpointFactory();
+      messageEndpointFactory.setContainer(this);
+   }
+   
+   public abstract Class getMessagingType();
+   
+   public abstract Map getActivationConfigProperties();
+   
+   protected abstract void populateActivationSpec();
+   
+   public abstract MethodInfo getMethodInfo(Method method);
+
+   public void setMessageEndpointFactory(JBossMessageEndpointFactory messageEndpointFactory)
+   {
+      this.messageEndpointFactory = messageEndpointFactory;
+   }
+   
+   public String getResourceAdaptorName()
+   {
+      ResourceAdapter annotation = (ResourceAdapter) resolveAnnotation(ResourceAdapter.class);
+      if (annotation == null)
+         return JMS_ADAPTOR;
+      
+      return annotation.value();
+   }
+   
+   protected void addActivationSpecProperty(Map result, ActivationConfigProperty property)
+   {
+      if (!property.propertyName().equals("messagingType"))
+      {
+         ActivationConfigPropertyMetaData metaData = new ActivationConfigPropertyMetaData();
+         try
+         {
+            Field nameField = ActivationConfigPropertyMetaData.class.getDeclaredField("name");
+            nameField.setAccessible(true);
+            nameField.set(metaData, property.propertyName());
+            Field valueField = ActivationConfigPropertyMetaData.class.getDeclaredField("value");
+            valueField.setAccessible(true);
+            valueField.set(metaData, property.propertyValue());
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException(e);
+         }
+   
+         /*
+          * Older versions don't have this
+          * TODO revert to this after we ditch 4.0.3SP1 as supported EJB3 platform
+         metaData.setName(property.propertyName());
+         metaData.setValue(property.propertyValue());
+         */
+         result.put(property.propertyName(), metaData);
+      }
+   }
+
+   /**
+    * Initialize the container invoker. Sets up a connection, a server session
+    * pool and a connection consumer for the configured destination.
+    * <p/>
+    * Any JMSExceptions produced while initializing will be assumed to be
+    * caused due to JMS Provider failure.
+    *
+    * @throws Exception Failed to initalize.
+    */
+   public void start() throws Exception
+   {
+      super.start();
+
+      populateActivationSpec();
+         
+      innerStart();
+
+      timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
+
+      startProxies();
+      
+      TimerServiceFactory.getInstance().restoreTimerService(timerService);
+   }
+
+   protected void innerStart() throws Exception
+   {
+      log.debug("Initializing");
+
+      if (getResourceAdaptorName().equals(JMS_ADAPTOR))
+         jmsCreate();
+   }
+
+   public ObjectName getJmxName()
+   {
+      ObjectName jmxName = null;
+      String jndiName = ProxyFactoryHelper.getLocalJndiName(this);
+      // The name must be escaped since the jndiName may be arbitrary
+      String name = org.jboss.ejb.Container.BASE_EJB_CONTAINER_NAME + ",jndiName=" + jndiName;
+      try
+      {
+         jmxName = org.jboss.mx.util.ObjectNameConverter.convert(name);
+      }
+      catch (MalformedObjectNameException e)
+      {
+         e.printStackTrace();
+         throw new RuntimeException("Failed to create ObjectName, msg=" + e.getMessage());
+      }
+
+      return jmxName;
+   }
+
+   protected void startProxies() throws Exception
+   {
+      messageEndpointFactory.start();
+   }
+
+   /**
+    * Parse the JNDI suffix from the given JNDI name.
+    *
+    * @param jndiname     The JNDI name used to lookup the destination.
+    * @param defautSuffix Description of Parameter
+    * @return The parsed suffix or the defaultSuffix
+    */
+   protected String parseJndiSuffix(final String jndiname,
+                                    final String defautSuffix)
+   {
+      // jndiSuffix is merely the name that the user has given the MDB.
+      // since the jndi name contains the message type I have to split
+      // at the "/" if there is no slash then I use the entire jndi name...
+      String jndiSuffix = "";
+
+      if (jndiname != null)
+      {
+         int indexOfSlash = jndiname.indexOf("/");
+         if (indexOfSlash != -1)
+         {
+            jndiSuffix = jndiname.substring(indexOfSlash + 1);
+         }
+         else
+         {
+            jndiSuffix = jndiname;
+         }
+      }
+      else
+      {
+         // if the jndi name from jboss.xml is null then lets use the ejbName
+         jndiSuffix = defautSuffix;
+      }
+
+      return jndiSuffix;
+   }
+
+   public Object localInvoke(Method method, Object[] args) throws Throwable
+   {
+      MethodInfo info = getMethodInfo(method);
+      if (info == null)
+      {
+         throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
+      }
+      return localInvoke(info, args);
+
+   }
+
+   public Object localInvoke(MethodInfo info, Object[] args) throws Throwable
+   {     
+      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+      ThreadLocalENCFactory.push(enc);
+      try
+      {
+         Interceptor[] aspects = info.getInterceptors();
+         EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects);
+         nextInvocation.setAdvisor(this);
+         nextInvocation.setArguments(args);
+         return nextInvocation.invokeNext();
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(oldLoader);
+         ThreadLocalENCFactory.pop();
+      }
+   }
+
+   public TimerService getTimerService()
+   {
+      return timerService;
+   }
+
+   public TimerService getTimerService(Object pKey)
+   {
+      assert timerService != null : "Timer Service not yet initialized";
+      return timerService;
+   }
+   
+   public void callTimeout(Timer timer) throws Exception
+   {
+      Method timeout = callbackHandler.getTimeoutCallback();
+      if (timeout == null) throw new EJBException("No method has been annotated with @Timeout");
+      Object[] args = {timer};
+      try
+      {
+         localInvoke(timeout, args);
+      }
+      catch (Throwable throwable)
+      {
+         if (throwable instanceof Exception) throw (Exception) throwable;
+         throw new RuntimeException(throwable);
+      }
+   }
+
+
+   public void stop() throws Exception
+   {
+      if (timerService != null)
+      {
+         TimerServiceFactory.getInstance().removeTimerService(timerService);
+      }
+
+      stopProxies();
+   }
+
+   protected void stopProxies() throws Exception
+   {
+      messageEndpointFactory.stop();
+   }
+
+   public void destroy() throws Exception
+   {
+   }
+   
+   // ********* JMS Specific
+   protected static final String JMS_ADAPTOR = "jms-ra.rar";
+   protected static final String DESTINATION = "destination";
+   protected static final String DESTINATION_TYPE = "destinationType";
+   protected static final String PROVIDER_ADAPTER_JNDI = "providerAdapterJNDI";
+   protected static final String MAX_SESSION = "maxSession";
+   
+   public void initializePool() throws Exception
+   {
+     super.initializePool();
+     
+     String maxSession = getMaxSession();
+     if (maxSession != null)
+     {
+        pool.setMaxSize(Integer.parseInt(maxSession));
+     }
+   }
+   
+   protected String getProviderAdapterJNDI()
+   {
+      ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(PROVIDER_ADAPTER_JNDI);
+      if (property != null)
+         return property.getValue();
+      return "java:/DefaultJMSProvider";
+   }
+   
+   protected String getMaxSession()
+   {
+      ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(MAX_SESSION);
+      if (property != null)
+         return property.getValue();
+      return null;
+   }
+   
+   protected String getDestination()
+   {
+      ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(DESTINATION);
+      if (property != null)
+         return property.getValue();
+      return null;
+   }
+   
+   protected String getDestinationType()
+   {
+      ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(DESTINATION_TYPE);
+      if (property != null)
+         return property.getValue();
+      return null;
+   }
+
+   protected void jmsCreate() throws Exception
+   {
+      //    Get the JMS provider
+      // todo get rid of server module dependency
+      JMSProviderAdapter adapter = getJMSProviderAdapter();
+      log.debug("Provider adapter: " + adapter);
+  
+      // Connect to the JNDI server and get a reference to root context
+      Context context = adapter.getInitialContext();
+      log.debug("context: " + context);
+
+      // if we can't get the root context then exit with an exception
+      if (context == null)
+      {
+         throw new RuntimeException("Failed to get the root context");
+      }
+
+      // Unfortunately the destination is optional, so if we do not have one
+      // here we have to look it up if we have a destinationJNDI, else give it
+      // a default.
+      String destinationType = getDestinationType();
+      if (destinationType == null)
+      {
+         log.warn("No message-driven-destination given; using; guessing type");
+         destinationType = getDestinationType(context, getDestination());
+      }
+
+      if ("javax.jms.Topic".equals(destinationType))
+      {
+         innerCreateTopic(context);
+
+      }
+      else if ("javax.jms.Queue".equals(destinationType))
+      {
+         innerCreateQueue(context);
+
+      }
+      else
+         throw new DeploymentException("Unknown destination-type " + destinationType);
+
+      log.debug("Initialized with config " + toString());
+
+      context.close();
+   }
+   
+   protected void innerCreateQueue(Context context)
+           throws Exception
+   {
+      log.debug("Got destination type Queue for " + ejbName);
+
+      // Get the JNDI suffix of the destination
+      String jndiSuffix = parseJndiSuffix(getDestination(), ejbName);
+      log.debug("jndiSuffix: " + jndiSuffix);
+
+      // lookup or create the destination queue
+      Queue queue = null;
+      try
+      {
+         // First we try the specified queue
+         if (getDestination() != null)
+            queue = (Queue) context.lookup(getDestination());
+      }
+      catch (NamingException e)
+      {
+         log.warn("Could not find the queue destination-jndi-name=" + getDestination());
+      }
+      catch (ClassCastException e)
+      {
+         throw new DeploymentException("Expected a Queue destination-jndi-name=" + getDestination());
+      }
+
+      if (queue == null)
+         queue = (Queue) createDestination(Queue.class,
+                 context,
+                 "queue/" + jndiSuffix,
+                 jndiSuffix);
+   }
+
+   protected void innerCreateTopic(Context context)
+           throws Exception
+   {
+      log.debug("Got destination type Topic for " + ejbName);
+
+      // Get the JNDI suffix of the destination
+      String jndiSuffix = parseJndiSuffix(getDestination(), ejbName);
+      log.debug("jndiSuffix: " + jndiSuffix);
+
+      // lookup or create the destination topic
+      Topic topic = null;
+      try
+      {
+         // First we try the specified topic
+         if (getDestination() != null)
+            topic = (Topic) context.lookup(getDestination());
+      }
+      catch (NamingException e)
+      {
+         log.warn("Could not find the topic destination-jndi-name=" + getDestination());
+      }
+      catch (ClassCastException e)
+      {
+         throw new DeploymentException("Expected a Topic destination-jndi-name=" + getDestination());
+      }
+
+      if (topic == null)
+         topic = (Topic) createDestination(Topic.class,
+                 context,
+                 "topic/" + jndiSuffix,
+                 jndiSuffix);
+   }
+
+   /**
+    * Create and or lookup a JMS destination.
+    *
+    * @param type       Either javax.jms.Queue or javax.jms.Topic.
+    * @param ctx        The naming context to lookup destinations from.
+    * @param jndiName   The name to use when looking up destinations.
+    * @param jndiSuffix The name to use when creating destinations.
+    * @return The destination.
+    * @throws IllegalArgumentException Type is not Queue or Topic.
+    * @throws Exception                Description of Exception
+    */
+   protected Destination createDestination(final Class type,
+                                           final Context ctx,
+                                           final String jndiName,
+                                           final String jndiSuffix)
+           throws Exception
+   {
+      try
+      {
+         // first try to look it up
+         return (Destination) ctx.lookup(jndiName);
+      }
+      catch (NamingException e)
+      {
+         // is JMS?
+         if (getDestination() == null)
+         {
+            return null;
+         }
+         else
+         {
+            // if the lookup failes, the try to create it
+            log.warn("destination not found: " + jndiName + " reason: " + e);
+            log.warn("creating a new temporary destination: " + jndiName);
+            
+            createTemporaryDestination(type, jndiSuffix);
+       
+            // try to look it up again
+            return (Destination) ctx.lookup(jndiName);
+         }
+      }
+   }
+   
+   protected void createTemporaryDestination(Class type, String jndiSuffix) throws Exception
+   {
+      //
+      // jason: we should do away with this...
+      //
+      // attempt to create the destination (note, this is very
+      // very, very unportable).
+      //
+
+      // MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
+      
+      String methodName;
+      String destinationContext;
+      if (type == Topic.class)
+      {
+         destinationContext = "topic";
+         methodName = "createTopic";
+      }
+      else if (type == Queue.class)
+      {
+         destinationContext = "queue";
+         methodName = "createQueue";
+      }
+      else
+      {
+         // type was not a Topic or Queue, bad user
+         throw new IllegalArgumentException
+                 ("Expected javax.jms.Queue or javax.jms.Topic: " + type);
+      }
+      
+      ObjectName destinationManagerName = new ObjectName("jboss.mq:service=DestinationManager");
+      
+      KernelAbstraction kernel = KernelAbstractionFactory.getInstance();
+      // invoke the server to create the destination
+      Object result = kernel.invoke(destinationManagerName,
+              methodName,
+              new Object[]{jndiSuffix},
+              new String[]{"java.lang.String"});
+      
+      InitialContext jndiContext = InitialContextFactory.getInitialContext();
+      String binding = destinationContext + "/" + jndiSuffix;
+      try
+      {
+         jndiContext.lookup(binding);
+      }
+      catch (NamingException e)
+      {
+         jndiContext.rebind(binding, result);
+      }
+   }
+   
+   /**
+    * Return the JMSProviderAdapter that should be used.
+    *
+    * @return The JMSProviderAdapter to use.
+    */
+   protected JMSProviderAdapter getJMSProviderAdapter()
+           throws NamingException
+   {
+      Context context = getInitialContext();
+      //todo make this pluggable
+      String providerAdapterJNDI = getProviderAdapterJNDI();
+      try
+      {
+         log.debug("Looking up provider adapter: " + providerAdapterJNDI);
+     
+         return (JMSProviderAdapter) context.lookup(providerAdapterJNDI);
+      }
+      finally
+      {
+         context.close();
+      }
+   }
+
+   /**
+    * Try to get a destination type by looking up the destination JNDI, or
+    * provide a default if there is not destinationJNDI or if it is not possible
+    * to lookup.
+    *
+    * @param ctx             The naming context to lookup destinations from.
+    * @param destinationJNDI The name to use when looking up destinations.
+    * @return The destination type, either derived from destinationJDNI or
+    *         DEFAULT_DESTINATION_TYPE
+    */
+   protected String getDestinationType(Context ctx, String destinationJNDI)
+   {
+      String destType = null;
+
+      if (destinationJNDI != null)
+      {
+         try
+         {
+            Destination dest = (Destination) ctx.lookup(destinationJNDI);
+            if (dest instanceof javax.jms.Topic)
+            {
+               destType = "javax.jms.Topic";
+            }
+            else if (dest instanceof javax.jms.Queue)
+            {
+               destType = "javax.jms.Queue";
+            }
+         }
+         catch (NamingException ex)
+         {
+            log.debug("Could not do heristic lookup of destination ", ex);
+         }
+
+      }
+      if (destType == null)
+      {
+         log.warn("Could not determine destination type, defaults to: " +
+                 DEFAULT_DESTINATION_TYPE);
+
+         destType = DEFAULT_DESTINATION_TYPE;
+      }
+
+      return destType;
+   }
+}
\ No newline at end of file

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ProducerFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ProducerFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ProducerFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -109,6 +109,18 @@
       jndiName = producer.getName();
    }
 
+   public Object createHomeProxy()
+   {
+      throw new UnsupportedOperationException("producer can't have a home interface");
+   }
+   
+   public Object createProxy(Object id)
+   {
+      if(id != null)
+         throw new IllegalArgumentException("producer proxy must not have an id");
+      return createProxy();
+   }
+   
    public void setContainer(Container container)
    {
    }
@@ -124,7 +136,7 @@
      
       try
       {
-         Util.bind(baseCtx, atom, ref);
+         Util.rebind(baseCtx, atom, ref);
       } catch (NamingException e)
       {
          NamingException namingException = new NamingException("Could not bind producer factory into JNDI under jndiName: " + baseCtx.getNameInNamespace() + "/" + atom);

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ProducerManagerImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ProducerManagerImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/ProducerManagerImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -44,6 +44,7 @@
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.ejb3.EJB3Util;
+import org.jboss.logging.Logger;
 
 /**
  * comment
@@ -52,6 +53,8 @@
  */
 public class ProducerManagerImpl implements ProducerManager, Externalizable, Interceptor
 {
+   private static final Logger log = Logger.getLogger(ProducerManagerImpl.class);
+   
    private static final int PERSISTENT = javax.jms.DeliveryMode.PERSISTENT;
    private static final int NON_PERSISTENT = javax.jms.DeliveryMode.NON_PERSISTENT;
    

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/RemoteProducerFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/RemoteProducerFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/RemoteProducerFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -84,7 +84,7 @@
       Object factoryProxy = Remoting.createPojiProxy(jndiName + PROXY_FACTORY_NAME, interfaces, RemoteProxyFactory.DEFAULT_CLIENT_BINDING);
       try
       {
-         Util.bind(ctx, jndiName + PROXY_FACTORY_NAME, factoryProxy);
+         Util.rebind(ctx, jndiName + PROXY_FACTORY_NAME, factoryProxy);
       } catch (NamingException e)
       {
          NamingException namingException = new NamingException("Could not bind remote producer factory into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/inflow/JBossMessageEndpointFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -40,8 +40,9 @@
 
 import org.jboss.deployment.DeploymentException;
 import org.jboss.ejb3.Container;
+import org.jboss.ejb3.KernelAbstractionFactory;
 import org.jboss.ejb3.tx.TxUtil;
-import org.jboss.ejb3.mdb.MDB;
+import org.jboss.ejb3.mdb.MessagingContainer;
 import org.jboss.mx.util.JMXExceptionDecoder;
 import org.jboss.logging.Logger;
 
@@ -62,11 +63,8 @@
    protected boolean trace = log.isTraceEnabled();
    
    /** Our container */
-   protected MDB container;
+   protected MessagingContainer container;
    
-   /** Our meta data */
-//   protected MessageDrivenMetaData metaData;
-   
    /** The activation properties */
    protected HashMap properties = new HashMap();
    
@@ -86,8 +84,6 @@
 
    /** The next proxy id */
    protected SynchronizedInt nextProxyId = new SynchronizedInt(0);
-
-   protected MBeanServer server;
     
    // Static --------------------------------------------------------
    
@@ -118,7 +114,7 @@
     * 
     * @return the container
     */
-   public MDB getContainer()
+   public MessagingContainer getContainer()
    {
       return container;
    }
@@ -131,9 +127,9 @@
       
       if (trace)
          log.trace("createEndpoint " + this + " xaResource=" + resource);
-         
+          
       MessageEndpoint endpoint = createProxy(resource);
-      
+        
       if (trace)
          log.trace("Created endpoint " + endpoint + " from " + this);
 
@@ -184,8 +180,6 @@
    
    public void start() throws Exception
    {
-      // Lets take a reference to our metadata
- //     metaData = (MessageDrivenMetaData) container.getBeanMetaData();
       // Resolve the message listener
       resolveMessageListener();
       resolveResourceAdapterName();
@@ -214,7 +208,7 @@
     */
    public void setContainer(final Container container)
    {
-      this.container = (MDB) container;
+      this.container = (MessagingContainer) container;
    }
    
    // Object overrides ----------------------------------------------
@@ -262,7 +256,6 @@
    {
       try
       {
-         server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
          resourceAdapterObjectName = new ObjectName("jboss.jca:service=RARDeployment,name='" + resourceAdapterName + "'");
          // todo register with kernel and push dependencies to kernel
       }
@@ -271,19 +264,6 @@
          throw new RuntimeException(e);
       }
    }
-
-
-   /**
-    * Add activation config properties
-    * 
-    * @throws DeploymentException for any error
-    */
-   protected void augmentActivationConfigProperties() throws DeploymentException
-   {
-      String jndiName = container.getDestination();
-      if (jndiName != null)
-         properties.put("destination", jndiName);
-   }   
    
    /**
     * Create the activation spec
@@ -293,16 +273,16 @@
    protected void createActivationSpec() throws DeploymentException
    {
       properties = new HashMap(container.getActivationConfigProperties());
-      augmentActivationConfigProperties();
-      
+         
       Object[] params = new Object[] 
       {
          messagingTypeClass,
          properties.values()
       };
+    
       try
       {
-         activationSpec = (ActivationSpec) server.invoke(resourceAdapterObjectName, "createActivationSpec", params, createActivationSpecSig);
+         activationSpec = (ActivationSpec) KernelAbstractionFactory.getInstance().invoke(resourceAdapterObjectName, "createActivationSpec", params, createActivationSpecSig);
       }
       catch (Throwable t)
       {
@@ -318,11 +298,11 @@
     * @throws DeploymentException for any error
     */
    protected void activate() throws DeploymentException
-   {
+   {   
       Object[] params = new Object[] { this, activationSpec };
       try
       {
-         server.invoke(resourceAdapterObjectName, "endpointActivation", params, activationSig);
+         KernelAbstractionFactory.getInstance().invoke(resourceAdapterObjectName, "endpointActivation", params, activationSig);
       }
       catch (Throwable t)
       {
@@ -340,7 +320,7 @@
       Object[] params = new Object[] { this, activationSpec };
       try
       {
-         server.invoke(resourceAdapterObjectName, "endpointDeactivation", params, activationSig);
+         KernelAbstractionFactory.getInstance().invoke(resourceAdapterObjectName, "endpointDeactivation", params, activationSig);
       }
       catch (Throwable t)
       {

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/inflow/MessageInflowLocalProxy.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/inflow/MessageInflowLocalProxy.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/mdb/inflow/MessageInflowLocalProxy.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -34,6 +34,7 @@
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.aop.MethodInfo;
+import org.jboss.ejb3.mdb.MessagingContainer;
 import org.jboss.ejb3.mdb.MDB;
 import org.jboss.ejb3.tx.TxUtil;
 import org.jboss.logging.Logger;
@@ -84,11 +85,11 @@
    private XAResource resource;
    private MessageEndpointFactory messageEndpointFactory;
    
-   MDB mdb;
+   MessagingContainer container;
 
-   protected MessageInflowLocalProxy(MDB mdb)
+   protected MessageInflowLocalProxy(MessagingContainer container)
    {
-      this.mdb = mdb;
+      this.container = container;
    }
 
    public void setMessageEndpointFactory(MessageEndpointFactory messageEndpointFactory)
@@ -125,7 +126,7 @@
       }
       else if (method.getName().equals("beforeDelivery"))
       {
-         before(proxy, mdb, method, args);
+         before(proxy, container, method, args);
          return null;
       }
       else if (method.getName().equals("afterDelivery"))
@@ -134,12 +135,12 @@
          return null;
       }
       else
-         return delivery(proxy, mdb, method, args);
+         return delivery(proxy, container, method, args);
    }
 
    public String toString()
    {
-      return mdb.getEjbName().toString();
+      return container.getEjbName().toString();
    }
    
    // -----------------------------------------------------------
@@ -178,7 +179,7 @@
     * @param mi the invocation
     * @throws Throwable for any error
     */
-   protected void before(Object proxy, MDB container, Method method, Object[] args) throws Throwable
+   protected void before(Object proxy, MessagingContainer container, Method method, Object[] args) throws Throwable
    {
       // Called out of sequence
       if (oldClassLoader != null)
@@ -197,8 +198,8 @@
       try
       {
          // Is the delivery transacted?
-         MethodInfo methodInfo = mdb.getMethodInfo((Method)args[0]);
-         boolean isTransacted = messageEndpointFactory.isDeliveryTransacted(methodInfo.advisedMethod);
+         MethodInfo methodInfo = container.getMethodInfo((Method)args[0]);
+         boolean isTransacted = messageEndpointFactory.isDeliveryTransacted(methodInfo.getAdvisedMethod());
 
          startTransaction("beforeDelivery", proxy, container, method, args, isTransacted);
       }
@@ -239,7 +240,7 @@
     * @return the result of the delivery
     * @throws Throwable for any error
     */
-   protected Object delivery(Object proxy, MDB container, Method method, Object[] args) throws Throwable
+   protected Object delivery(Object proxy, MessagingContainer container, Method method, Object[] args) throws Throwable
    {
       // Have we already delivered a message?
       if (delivered)
@@ -254,14 +255,14 @@
 
       boolean commit = true;
       // Is the delivery transacted?
-      MethodInfo methodInfo = mdb.getMethodInfo(method);
+      MethodInfo methodInfo = container.getMethodInfo(method);
 
       try
       {
          // Check for starting a transaction
          if (oldClassLoader == null)
          {
-            boolean isTransacted = messageEndpointFactory.isDeliveryTransacted(methodInfo.advisedMethod);
+            boolean isTransacted = messageEndpointFactory.isDeliveryTransacted(methodInfo.getAdvisedMethod());
             startTransaction("delivery", proxy, container, method, args, isTransacted);
          }
          return container.localInvoke(methodInfo, args);
@@ -329,7 +330,7 @@
     * @param container the container
     * @throws Throwable for any error
     */
-   protected void startTransaction(String context, Object proxy, MDB container, Method m, Object[] args, boolean isTransacted) throws Throwable
+   protected void startTransaction(String context, Object proxy, MessagingContainer container, Method m, Object[] args, boolean isTransacted) throws Throwable
    { 
       Method method;
       
@@ -523,7 +524,7 @@
     *
     * @return the container
     */
-   protected org.jboss.ejb3.mdb.MDB getContainer(Invocation mi)
+   protected MessagingContainer getContainer(Invocation mi)
    {
       return getMessageEndpointFactory(mi).getContainer();
    }

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/.cvsignore
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/.cvsignore	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/.cvsignore	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1 @@
+Callback.java

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ActivationConfig.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ActivationConfig.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ActivationConfig.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,63 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.metamodel.descriptor.NameValuePair;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a activation-config element of the ejb-jar.xml deployment descriptor for
+ * the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45409 $</tt>
+ */
+public class ActivationConfig
+{
+   private static final Logger log = Logger.getLogger(ActivationConfig.class);
+
+   // ejb-jar.xml
+   private List properties = new ArrayList();
+
+   public List getActivationConfigProperties()
+   {
+      return properties;
+   }
+
+   public void addActivationConfigProperty(NameValuePair property)
+   {
+      properties.add(property);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append('[');
+      sb.append("activationConfigProperties=").append(properties);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationException.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationException.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationException.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,70 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.logging.Logger;
+
+/**
+ * Represents an <application-exception> element of the ejb-jar.xml deployment descriptor
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45409 $</tt>
+ */
+public class ApplicationException
+{
+   private static final Logger log = Logger.getLogger(ApplicationException.class);
+
+   private String clazz;
+   private boolean rollback;
+
+   public String getExceptionClass()
+   {
+      return clazz;
+   }
+   
+   public void setExceptionClass(String clazz)
+   {
+      this.clazz = clazz;
+   }
+   
+   public boolean getRollback()
+   {
+      return rollback;
+   }
+
+   public void setRollback(boolean rollback)
+   {
+      this.rollback = rollback;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("class=").append(clazz);
+      sb.append(", rollback=").append(rollback);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/AssemblyDescriptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/AssemblyDescriptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/AssemblyDescriptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,180 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import org.jboss.logging.Logger;
+
+import org.jboss.metamodel.descriptor.SecurityRole;
+
+/**
+ * Represents <assembly-descriptor> elements of the ejb-jar.xml deployment descriptor for the 1.4
+ * schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45409 $</tt>
+ */
+public class AssemblyDescriptor
+{
+   private static final Logger log = Logger.getLogger(AssemblyDescriptor.class);
+
+   private List securityRoles = new ArrayList();
+
+   private List methodPermissions = new ArrayList();
+
+   private List containerTransactions = new ArrayList();
+   
+   private HashMap<String, MessageDestination> messageDestinations = new HashMap();
+
+   private ExcludeList excludeList;
+
+   private List applicationExceptions = new ArrayList();
+
+   private InitList initList;
+
+   private List injects = new ArrayList();
+   
+   public Collection getMessageDestinations()
+   {
+      return messageDestinations.values();
+   }
+
+   public void addMessageDestination(MessageDestination messageDestination)
+   {
+      messageDestinations.put(messageDestination.getMessageDestinationName(), messageDestination);
+   }
+   
+   public MessageDestination findMessageDestination(String name)
+   {
+      return messageDestinations.get(name);
+   }
+
+   private List interceptorBindings = new ArrayList();
+
+   public InitList getInitList()
+   {
+      return initList;
+   }
+
+   public void setInitList(InitList initList)
+   {
+      this.initList = initList;
+   }
+
+   public ExcludeList getExcludeList()
+   {
+      return excludeList;
+   }
+
+   public void setExcludeList(ExcludeList excludeList)
+   {
+      this.excludeList = excludeList;
+   }
+   
+   public List getApplicationExceptions()
+   {
+      return applicationExceptions;
+   }
+
+   public void addApplicationException(ApplicationException applicationException)
+   {
+      applicationExceptions.add(applicationException);
+   }
+
+   public List getSecurityRoles()
+   {
+      return securityRoles;
+   }
+
+   public void setSecurityRoles(List securityRoles)
+   {
+      this.securityRoles = securityRoles;
+   }
+
+   public void addSecurityRole(SecurityRole securityRole)
+   {
+      securityRoles.add(securityRole);
+   }
+
+   public List<InterceptorBinding> getInterceptorBindings()
+   {
+      return interceptorBindings;
+   }
+
+   public void addInterceptorBinding(InterceptorBinding binding)
+   {
+      interceptorBindings.add(binding);
+   }
+
+   public List getInjects()
+   {
+      return injects;
+   }
+
+   public void addInject(Inject inject)
+   {
+      injects.add(inject);
+   }
+
+   public List getMethodPermissions()
+   {
+      return methodPermissions;
+   }
+
+   public void setMethodPermissions(List methodPermissions)
+   {
+      this.methodPermissions = methodPermissions;
+   }
+
+   public void addMethodPermission(MethodPermission methodPermission)
+   {
+      methodPermissions.add(methodPermission);
+   }
+
+   public List getContainerTransactions()
+   {
+      return containerTransactions;
+   }
+
+   public void setContainerTransactions(List containerTransactions)
+   {
+      this.containerTransactions = containerTransactions;
+   }
+
+   public void addContainerTransaction(ContainerTransaction containerTransaction)
+   {
+      containerTransactions.add(containerTransaction);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("securityRoles=").append(securityRoles);
+      sb.append(", applicationExceptions=").append(applicationExceptions);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CacheConfig.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CacheConfig.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CacheConfig.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,101 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+
+/**
+ * Represents an <cache-config> element of the jboss.xml deployment descriptor
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class CacheConfig
+{
+   private String cacheClass = null;
+   private String maxSize = null;
+   private String idleTimeoutSeconds = null;
+   private String name = null;
+   private String persistenceManager = null;
+
+   public String getPersistenceManager()
+   {
+      return persistenceManager;
+   }
+
+   public void setPersistenceManager(String persistenceManager)
+   {
+      this.persistenceManager = persistenceManager;
+   }
+   
+   public String getCacheClass()
+   {
+      return cacheClass;
+   }
+
+   public void setCacheClass(String cacheClass)
+   {
+      this.cacheClass = cacheClass;
+   }
+
+   public String getMaxSize()
+   {
+      return maxSize;
+   }
+
+   public void setMaxSize(String maxSize)
+   {
+      this.maxSize = maxSize;
+   }
+   
+   public String getIdleTimeoutSeconds()
+   {
+      return idleTimeoutSeconds;
+   }
+
+   public void setIdleTimeoutSeconds(String idleTimeoutSeconds)
+   {
+      this.idleTimeoutSeconds = idleTimeoutSeconds;
+   }
+   
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("cacheClass=").append(cacheClass);
+      sb.append(", maxSize=").append(maxSize);
+      sb.append(", idleTimeoutSeconds=").append(idleTimeoutSeconds);
+      sb.append(", name=").append(name);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ClusterConfig.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ClusterConfig.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ClusterConfig.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,67 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+
+/**
+ * Represents an <cluster-config> element of the jboss.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class ClusterConfig
+{
+   private String loadBalancePolicy = null;
+
+   private String partition = null;
+
+   public String getLoadBalancePolicy()
+   {
+      return loadBalancePolicy;
+   }
+
+   public void setLoadBalancePolicy(String loadBalancePolicy)
+   {
+      this.loadBalancePolicy = loadBalancePolicy;
+   }
+
+   public String getPartition()
+   {
+      return partition;
+   }
+
+   public void setPartition(String partition)
+   {
+      this.partition = partition;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("loadBalancePolicy=").append(loadBalancePolicy);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CmpField.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CmpField.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CmpField.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,54 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+/**
+ * Represents an cmp-field element of the ejb-jar.xml deployment descriptor for
+ * the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class CmpField
+{
+
+   private String fieldName;
+
+   public String getFieldName()
+   {
+      return fieldName;
+   }
+
+   public void setFieldName(String fieldName)
+   {
+      this.fieldName = fieldName;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("fieldName=").append(fieldName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CmrField.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CmrField.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CmrField.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,67 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+/**
+ * Represents an <cmr-field> element of the ejb-jar.xml deployment
+ * descriptor for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class CmrField
+{
+
+   private String cmrFieldName;
+
+   private String cmrFieldType;
+
+   public String getCmrFieldName()
+   {
+      return cmrFieldName;
+   }
+
+   public void setCmrFieldName(String cmrFieldName)
+   {
+      this.cmrFieldName = cmrFieldName;
+   }
+
+   public String getCmrFieldType()
+   {
+      return cmrFieldType;
+   }
+
+   public void setCmrFieldType(String cmrFieldType)
+   {
+      this.cmrFieldType = cmrFieldType;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("cmrFieldName=").append(cmrFieldName);
+      sb.append(",cmrFieldType=").append(cmrFieldType);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Consumer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Consumer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Consumer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,113 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import org.jboss.logging.Logger;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class Consumer extends EnterpriseBean
+{
+   private static final Logger log = Logger.getLogger(Consumer.class);
+   
+   private String destination = null;
+   private String destinationType = null;
+   private CurrentMessage currentMessage = null;
+   private MessageProperties messageProperties = null;
+   private List producers = new ArrayList();
+   private List localProducers = new ArrayList();
+   
+   public String getDestination()
+   {
+      return destination;
+   }
+   
+   public void setDestination(String destination)
+   {
+      this.destination = destination;
+   }
+   
+   public String getDestinationType()
+   {
+      return destinationType;
+   }
+   
+   public void setDestinationType(String destinationType)
+   {
+      this.destinationType = destinationType;
+   }
+   
+   public CurrentMessage getCurrentMessage()
+   {
+      return currentMessage;
+   }
+   
+   public void setCurrentMessage(CurrentMessage currentMessage)
+   {
+      this.currentMessage = currentMessage;
+   }
+   
+   public MessageProperties getMessageProperties()
+   {
+      return messageProperties;
+   }
+   
+   public void setMessageProperties(MessageProperties messageProperties)
+   {
+      this.messageProperties = messageProperties;
+   }
+   
+   public List getProducers()
+   {
+      return producers;
+   }
+   
+   public void addProducer(Producer producer)
+   {
+      producers.add(producer);
+   }
+   
+   public List getLocalProducers()
+   {
+      return localProducers;
+   }
+   
+   public void addLocalProducer(Producer producer)
+   {
+      localProducers.add(producer);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[Consumer:");
+      sb.append(super.toString());
+      sb.append(", destination=" + destination);
+      sb.append(", destinationType=" + destinationType);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ContainerTransaction.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ContainerTransaction.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ContainerTransaction.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,67 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+
+/**
+ * Represents an <container-transaction> element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class ContainerTransaction
+{
+
+   private String transAttribute;
+
+   private Method method;
+
+   public String getTransAttribute()
+   {
+      return transAttribute;
+   }
+
+   public void setTransAttribute(String transAttribute)
+   {
+      this.transAttribute = transAttribute;
+   }
+
+   public Method getMethod()
+   {
+      return method;
+   }
+
+   public void setMethod(Method method)
+   {
+      this.method = method;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbRelationName=").append(transAttribute);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CurrentMessage.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CurrentMessage.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/CurrentMessage.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,54 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class CurrentMessage
+{
+   private List methods = new ArrayList();
+
+   public List getMethods()
+   {
+      return methods;
+   }
+   
+   public void addMethod(Method method)
+   {
+      methods.add(method);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbName=").append(methods);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbJarDD.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbJarDD.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbJarDD.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,165 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import java.util.HashMap;
+
+import org.jboss.logging.Logger;
+
+
+/**
+ * Represents the ejb-jar.xml deployment descriptor for the 2.1 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class EjbJarDD
+{
+   private static final Logger log = Logger.getLogger(EjbJarDD.class);
+   
+   // ejb-jar.xml
+   private String version;
+
+   private String displayName;
+
+   private Relationships relationships;
+
+   private AssemblyDescriptor assemblyDescriptor;
+   
+   private Interceptors interceptors;
+
+   // jboss.xml
+   private String securityDomain;
+   
+   private String unauthenticatedPrincipal;
+
+   
+   private HashMap<String, ResourceManager> resourceManagers = new HashMap();
+
+   // both
+   private EnterpriseBeans enterpriseBeans;
+   
+   public void addResourceManager(ResourceManager manager)
+   {
+      resourceManagers.put(manager.getResourceName(), manager);
+   }
+   
+   public String resolveResourceManager(String resourceName)
+   {
+      ResourceManager manager = resourceManagers.get(resourceName);
+      if (manager != null)
+         return manager.getResourceJndiName();
+      
+      return null;
+   }
+
+   public String getSecurityDomain()
+   {
+      return securityDomain;
+   }
+
+   public void setSecurityDomain(String securityDomain)
+   {
+      this.securityDomain = securityDomain;
+   }
+   
+   public String getUnauthenticatedPrincipal()
+   {
+      return unauthenticatedPrincipal;
+   }
+
+   public void setUnauthenticatedPrincipal(String unauthenticatedPrincipal)
+   {
+      this.unauthenticatedPrincipal = unauthenticatedPrincipal;
+   }
+
+   public String getVersion()
+   {
+      return version;
+   }
+
+   public void setVersion(String version)
+   {
+      this.version = version;
+   }
+
+   public String getDisplayName()
+   {
+      return displayName;
+   }
+
+   public void setDisplayName(String displayName)
+   {
+      this.displayName = displayName;
+   }
+
+   public EnterpriseBeans getEnterpriseBeans()
+   {
+      return enterpriseBeans;
+   }
+
+   public void setEnterpriseBeans(EnterpriseBeans enterpriseBeans)
+   {
+      this.enterpriseBeans = enterpriseBeans;
+   }
+   
+   public Interceptors getInterceptors()
+   {
+      return interceptors;
+   }
+
+   public void setInterceptors(Interceptors interceptors)
+   {
+      this.interceptors = interceptors;
+   }
+
+   public Relationships getRelationships()
+   {
+      return relationships;
+   }
+
+   public void setRelationships(Relationships relationships)
+   {
+      this.relationships = relationships;
+   }
+
+   public AssemblyDescriptor getAssemblyDescriptor()
+   {
+      return assemblyDescriptor;
+   }
+
+   public void setAssemblyDescriptor(AssemblyDescriptor assemblyDescriptor)
+   {
+      this.assemblyDescriptor = assemblyDescriptor;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append('[');
+      sb.append("version=").append(version);
+      sb.append(",");
+      sb.append("displayName=").append(displayName);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbJarDDObjectFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbJarDDObjectFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbJarDDObjectFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,1620 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.management.ObjectName;
+import javax.persistence.PersistenceContextType;
+
+import org.jboss.ejb3.KernelAbstraction;
+import org.jboss.ejb3.KernelAbstractionFactory;
+import org.jboss.logging.Logger;
+import org.jboss.util.xml.JBossEntityResolver;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.xml.sax.Attributes;
+
+import org.jboss.metamodel.descriptor.DDObjectFactory;
+import org.jboss.metamodel.descriptor.EjbLocalRef;
+import org.jboss.metamodel.descriptor.EjbRef;
+import org.jboss.metamodel.descriptor.EnvEntry;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.PersistenceUnitRef;
+import org.jboss.metamodel.descriptor.NameValuePair;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+import org.jboss.metamodel.descriptor.RunAs;
+import org.jboss.metamodel.descriptor.WebServiceRef;
+import org.jboss.metamodel.descriptor.SecurityRole;
+import org.jboss.metamodel.descriptor.PersistenceContextRef;
+
+/**
+ * org.jboss.xb.binding.ObjectModelFactory implementation that accepts data
+ * chuncks from unmarshaller and assembles them into an EjbJarDD instance.
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 56531 $</tt>
+ */
+public class EjbJarDDObjectFactory extends DDObjectFactory
+{
+
+   private static final Logger log = Logger
+           .getLogger(EjbJarDDObjectFactory.class);
+
+   public static EjbJarDD parse(URL ddResource)
+      throws JBossXBException, IOException
+   {
+      ObjectModelFactory factory = null;
+      Unmarshaller unmarshaller = null;
+      EjbJarDD dd = null;
+
+      if (ddResource != null)
+      {
+         log.debug("found ejb-jar.xml " + ddResource);
+
+         factory = new EjbJarDDObjectFactory();
+         UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory
+               .newInstance();
+         unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, true);
+         unmarshaller = unmarshallerFactory.newUnmarshaller();
+         JBossEntityResolver entityResolver = new JBossEntityResolver();
+         unmarshaller.setEntityResolver(entityResolver);
+
+         dd = (EjbJarDD) unmarshaller.unmarshal(ddResource.openStream(),
+               factory, null);
+      }
+
+      return dd;
+   }
+
+   public Object newRoot(Object root, UnmarshallingContext navigator,
+                         String namespaceURI, String localName, Attributes attrs)
+   {
+
+      final EjbJarDD dd;
+      if (root == null)
+      {
+         root = dd = new EjbJarDD();
+      }
+      else
+      {
+         dd = (EjbJarDD) root;
+      }
+
+      if (attrs.getLength() > 0)
+      {
+         for (int i = 0; i < attrs.getLength(); ++i)
+         {
+            if (attrs.getLocalName(i).equals("version"))
+            {
+               dd.setVersion(attrs.getValue(i));
+            }
+         }
+      }
+
+      return root;
+   }
+
+   public Object completeRoot(Object root, UnmarshallingContext ctx,
+                              String uri, String name)
+   {
+      return root;
+   }
+
+   // Methods discovered by introspection
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(EjbJarDD dd, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("enterprise-beans"))
+      {
+         child = new EnterpriseBeans();
+      }
+      if (localName.equals("interceptors"))
+      {
+         child = new Interceptors();
+      }
+      else if (localName.equals("relationships"))
+      {
+         child = new Relationships();
+      }
+      else if (localName.equals("assembly-descriptor"))
+      {
+         child = new AssemblyDescriptor();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(EnterpriseBeans ejbs, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("session"))
+      {
+         child = new SessionEnterpriseBean();
+      }
+      else if (localName.equals("entity"))
+      {
+         child = new EntityEnterpriseBean();
+      }
+      else if (localName.equals("message-driven"))
+      {
+         child = new MessageDrivenBean();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   private Object newEjbChild(EnterpriseBean parent, String localName)
+   {
+      Object child = null;
+
+      if ((child = super.newEnvRefGroupChild(localName)) != null)
+         return child;
+      return child;
+   }
+
+
+   private Object newEjbHasInterceptorsChild(EnterpriseBean parent, String localName)
+   {
+      Object child = null;
+
+      if (localName.equals("around-invoke"))
+      {
+         child = new Method();
+      }
+      else if (localName.equals("post-construct"))
+      {
+         child = new Method();
+      }
+      else if (localName.equals("pre-destroy"))
+      {
+         child = new Method();
+      }
+      else if (localName.equals("post-activate"))
+      {
+         child = new Method();
+      }
+      else if (localName.equals("pre-passivate"))
+      {
+         child = new Method();
+      }
+      return child;
+   }
+
+   public Object newChild(MessageDrivenBean parent,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = newEjbChild(parent, localName);
+      if (child != null) return child;
+
+      child = newEjbHasInterceptorsChild(parent, localName);
+      if (child != null) return child;
+
+      if (localName.equals("message-driven-destination"))
+      {
+         child = new MessageDrivenDestination();
+      }
+      else if (localName.equals("activation-config"))
+      {
+         child = new ActivationConfig();
+      }
+
+      return child;
+   }
+
+   public Object newChild(ActivationConfig parent,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+     if (localName.equals("activation-config-property"))
+     {
+         child = new NameValuePair();
+     }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(SessionEnterpriseBean parent,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = newEjbChild(parent, localName);
+      if (child != null) return child;
+
+      child = newEjbHasInterceptorsChild(parent, localName);
+      if (child != null) return child;
+
+      if (localName.equals("security-identity"))
+      {
+         child = new SecurityIdentity();
+      }
+      else if (localName.equals("remove-method"))
+      {
+         RemoveMethod method = new RemoveMethod();
+         parent.addRemoveMethod(method);
+         child = method;
+      }
+      else if (localName.equals("init-method"))
+      {
+         InitMethod method = new InitMethod();
+         parent.addInitMethod(method);
+         child = method;
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(EntityEnterpriseBean parent,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      child = newEjbChild(parent, localName);
+      if (child == null)
+      {
+         if (localName.equals("cmp-field"))
+         {
+            child = new CmpField();
+         }
+         else if (localName.equals("query"))
+         {
+            child = new Query();
+         }
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(SecurityIdentity parent,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("run-as"))
+      {
+         child = new RunAs();
+      }
+      else if (localName.equals("use-caller-identity"))
+      {
+         parent.setUseCallerIdentity(true);
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(RemoveMethod parent,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("bean-method"))
+      {
+         parent.setBeanMethod(new Method());
+         child = parent.getBeanMethod();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(InitMethod parent,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("bean-method"))
+      {
+         parent.setBeanMethod(new Method());
+         child = parent.getBeanMethod();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(RemoveMethod dd, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("retain-if-exception"))
+      {
+         dd.setRetainIfException(Boolean.parseBoolean(getValue(localName, value)));
+      }
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(Relationships relationships,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("ejb-relation"))
+      {
+         child = new EjbRelation();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(EjbRelation relation, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("ejb-relationship-role"))
+      {
+         child = new EjbRelationshipRole();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(EjbRelationshipRole parent,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("cascade-delete"))
+      {
+         parent.setCascadeDelete(true);
+      }
+      else if (localName.equals("relationship-role-source"))
+      {
+         child = new RelationshipRoleSource();
+      }
+      else if (localName.equals("cmr-field"))
+      {
+         child = new CmrField();
+      }
+
+      return child;
+   }
+
+   public Object newChild(Interceptors interceptors,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("interceptor"))
+      {
+         return new Interceptor();
+      }
+
+      return child;
+   }
+
+   public Object newChild(Interceptor interceptor,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if ((child = this.newEnvRefGroupChild(localName)) != null)
+         return child;
+
+      if (localName.equals("around-invoke"))
+      {
+         return new Method();
+      }
+      else if (localName.equals("post-construct"))
+      {
+         return new Method();
+      }
+      else if (localName.equals("pre-destroy"))
+      {
+         return new Method();
+      }
+      else if (localName.equals("post-activate"))
+      {
+         return new Method();
+      }
+      else if (localName.equals("pre-passivate"))
+      {
+         return new Method();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(AssemblyDescriptor relationships,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("security-role"))
+      {
+         child = new SecurityRole();
+      }
+      else if (localName.equals("method-permission"))
+      {
+         child = new MethodPermission();
+      }
+      if (localName.equals("container-transaction"))
+      {
+         child = new ContainerTransaction();
+      }
+      else if (localName.equals("inject"))
+      {
+         child = new Inject();
+      }
+      else if (localName.equals("exclude-list"))
+      {
+         child = new ExcludeList();
+      }
+      else if (localName.equals("application-exception"))
+      {
+         child = new ApplicationException();
+      }
+      else if (localName.equals("interceptor-binding"))
+      {
+         child = new InterceptorBinding();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(Inject inject,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("method"))
+      {
+         child = new Method();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(MethodPermission permission,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("method"))
+      {
+         child = new Method();
+      }
+      else if (localName.equals("unchecked"))
+      {
+         permission.setUnchecked(true);
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(ExcludeList list,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("method"))
+      {
+         child = new Method();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(InitList list,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("method"))
+      {
+         child = new Method();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(ContainerTransaction transaction,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("method"))
+      {
+         child = new Method();
+      }
+
+      return child;
+   }
+
+   public Object newChild(Method method,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("method-params"))
+      {
+         method.setHasParameters();
+      }
+
+      return child;
+   }
+
+
+   public Object newChild(InterceptorBinding binding,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("interceptor-order"))
+      {
+         child = new InterceptorOrder();
+      }
+      else if (localName.equals("exclude-default-interceptors"))
+      {
+         child = new ExcludeDefaultInterceptors();
+      }
+      else if (localName.equals("exclude-class-interceptors"))
+      {
+         child = new ExcludeClassInterceptors();
+      }
+      else if (localName.equals("method-params"))
+      {
+         binding.setHasParameters();
+      }
+
+
+      return child;
+   }
+
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MessageDrivenBean parent, ActivationConfig config,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setActivationConfig(config);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MessageDrivenBean parent, EjbRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MessageDrivenBean parent, EjbLocalRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbLocalRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MessageDrivenBean parent, EnvEntry entry,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEnvEntry(entry);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MessageDrivenBean parent, ResourceEnvRef envRef,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceEnvRef(envRef);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MessageDrivenBean parent, ResourceRef envRef,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceRef(envRef);
+   }
+
+   public void addChild(MessageDrivenBean parent, WebServiceRef envRef,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addWebServiceRef(envRef);
+   }
+   
+   public void addChild(MessageDrivenBean parent, MessageDestinationRef ref,
+         UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMessageDestinationRef(ref);
+   }
+
+   public void addChild(ActivationConfig parent, NameValuePair property,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addActivationConfigProperty(property);
+   }
+
+   public void addChild(EjbJarDD parent, EnterpriseBeans ejbs,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setEnterpriseBeans(ejbs);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, EnterpriseBean ejb,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEnterpriseBean(ejb);
+   }
+
+   public void addChild(SessionEnterpriseBean parent, SecurityIdentity si,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setSecurityIdentity(si);
+   }
+
+   public void addChild(SecurityIdentity parent, RunAs runAs,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setRunAs(runAs);
+   }
+
+   public void addChild(SessionEnterpriseBean parent, EjbLocalRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbLocalRef(ref);
+   }
+
+   public void addChild(SessionEnterpriseBean parent, EjbRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbRef(ref);
+   }
+
+   public void addChild(SessionEnterpriseBean parent, PersistenceContextRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addPersistenceContextRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(SessionEnterpriseBean parent, PersistenceUnitRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addPersistenceUnitRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(SessionEnterpriseBean parent, MessageDestinationRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMessageDestinationRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(SessionEnterpriseBean parent, EnvEntry entry,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEnvEntry(entry);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(SessionEnterpriseBean parent, ResourceEnvRef envRef,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceEnvRef(envRef);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(SessionEnterpriseBean parent, ResourceRef envRef,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceRef(envRef);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(SessionEnterpriseBean parent, WebServiceRef envRef,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addWebServiceRef(envRef);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(SessionEnterpriseBean parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      if (localName.equals("around-invoke"))
+      {
+         parent.setAroundInvoke(method);
+      }
+      else if (localName.equals("post-construct"))
+      {
+         parent.setPostConstruct(method);
+      }
+      else if (localName.equals("pre-destroy"))
+      {
+         parent.setPreDestroy(method);
+      }
+      else if (localName.equals("post-activate"))
+      {
+         parent.setPostActivate(method);
+      }
+      else if (localName.equals("pre-passivate"))
+      {
+         parent.setPrePassivate(method);
+      }
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EntityEnterpriseBean parent, CmpField field,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addCmpField(field);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EntityEnterpriseBean parent, Query query,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addQuery(query);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EjbJarDD parent, Relationships relationships,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setRelationships(relationships);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Relationships parent, EjbRelation relation,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbRelation(relation);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EjbRelation parent, EjbRelationshipRole role,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbRelationshipRole(role);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EjbRelationshipRole parent,
+                        RelationshipRoleSource source, UnmarshallingContext navigator,
+                        String namespaceURI, String localName)
+   {
+      parent.setRelationshipRoleSource(source);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EjbRelationshipRole parent, CmrField field,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setCmrField(field);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EjbJarDD parent, AssemblyDescriptor descriptor,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setAssemblyDescriptor(descriptor);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(AssemblyDescriptor parent, SecurityRole role,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addSecurityRole(role);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(AssemblyDescriptor parent, MethodPermission permission,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMethodPermission(permission);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(AssemblyDescriptor parent, ExcludeList list,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setExcludeList(list);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(AssemblyDescriptor parent, ApplicationException exception,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addApplicationException(exception);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(AssemblyDescriptor parent, InitList list,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInitList(list);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(AssemblyDescriptor parent, Inject inject,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addInject(inject);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(AssemblyDescriptor parent, InterceptorBinding binding,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addInterceptorBinding(binding);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(ExcludeList parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMethod(method);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(InitList parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMethod(method);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MethodPermission parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMethod(method);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Inject parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMethod(method);
+   }
+
+   public void addChild(EjbJarDD parent, Interceptors interceptors,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInterceptors(interceptors);
+   }
+
+   public void addChild(Interceptors parent, Interceptor interceptor,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addInterceptor(interceptor);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Interceptor parent, EjbLocalRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbLocalRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Interceptor parent, EjbRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Interceptor parent, PersistenceContextRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addPersistenceContextRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Interceptor parent, PersistenceUnitRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addPersistenceUnitRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Interceptor parent, MessageDestinationRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMessageDestinationRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Interceptor parent, EnvEntry entry,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEnvEntry(entry);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Interceptor parent, ResourceEnvRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceEnvRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Interceptor parent, ResourceRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Interceptor parent, WebServiceRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addWebServiceRef(ref);
+   }
+
+   public void addChild(Interceptor parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      if (localName.equals("around-invoke"))
+      {
+         parent.setAroundInvoke(method);
+      }
+      else if (localName.equals("post-construct"))
+      {
+         parent.setPostConstruct(method);
+      }
+      else if (localName.equals("pre-destroy"))
+      {
+         parent.setPreDestroy(method);
+      }
+      else if (localName.equals("post-activate"))
+      {
+         parent.setPostActivate(method);
+      }
+      else if (localName.equals("pre-passivate"))
+      {
+         parent.setPrePassivate(method);
+      }
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(InterceptorBinding parent,
+                        InterceptorOrder order, UnmarshallingContext navigator,
+                        String namespaceURI, String localName)
+   {
+      parent.setOrderedInterceptorClasses(order);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(InterceptorBinding parent,
+                        ExcludeDefaultInterceptors exclude, UnmarshallingContext navigator,
+                        String namespaceURI, String localName)
+   {
+      parent.setExcludeDefaultInterceptors(true);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(InterceptorBinding parent,
+                        ExcludeClassInterceptors exclude, UnmarshallingContext navigator,
+                        String namespaceURI, String localName)
+   {
+      parent.setExcludeClassInterceptors(true);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(ContainerTransaction parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setMethod(method);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MessageDrivenBean parent, MessageDrivenDestination destination,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setMessageDrivenDestination(destination);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MessageDrivenBean parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      if (localName.equals("around-invoke"))
+      {
+         parent.setAroundInvoke(method);
+      }
+      else if (localName.equals("post-construct"))
+      {
+         parent.setPostConstruct(method);
+      }
+      else if (localName.equals("pre-destroy"))
+      {
+         parent.setPreDestroy(method);
+      }
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(AssemblyDescriptor parent,
+                        ContainerTransaction transaction, UnmarshallingContext navigator,
+                        String namespaceURI, String localName)
+   {
+      parent.addContainerTransaction(transaction);
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(EjbJarDD dd, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("display-name"))
+      {
+         dd.setDisplayName(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(NameValuePair property, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("activation-config-property-name"))
+      {
+         property.setName(getValue(localName, value));
+      }
+      else if (localName.equals("activation-config-property-value"))
+      {
+         property.setValue(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   private boolean isEjbParentName(EnterpriseBean ejb, String localName,
+                                   String value)
+   {
+      if (localName.equals("ejb-name"))
+      {
+         ejb.setEjbName(getValue(localName, value));
+         return true;
+      }
+      else if (localName.equals("home"))
+      {
+         ejb.setHome(getValue(localName, value));
+         return true;
+      }
+      else if (localName.equals("remote"))
+      {
+         ejb.setRemote(getValue(localName, value));
+         return true;
+      }
+      else if (localName.equals("local-home"))
+      {
+         ejb.setLocalHome(getValue(localName, value));
+         return true;
+      }
+      else if (localName.equals("local"))
+      {
+         ejb.setLocal(getValue(localName, value));
+         return true;
+      }
+      else if (localName.equals("ejb-class"))
+      {
+         ejb.setEjbClass(getValue(localName, value));
+         return true;
+      }
+
+      return false;
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(MessageDrivenBean ejb,
+                        UnmarshallingContext navigator, String namespaceURI, String localName,
+                        String value)
+   {
+      if (!isEjbParentName(ejb, localName, value))
+      {
+         if (localName.equals("acknowledge-mode"))
+         {
+            ejb.setAcknowledgeMode(getValue(localName, value));
+         }
+         else if (localName.equals("transaction-type"))
+         {
+            ejb.setTransactionType(getValue(localName, value));
+         }
+         else if (localName.equals("messaging-type"))
+         {
+            ejb.setMessagingType(getValue(localName, value));
+         }
+         else if (localName.equals("message-destination-type"))
+         {
+            MessageDrivenDestination destination = ejb.getMessageDrivenDestination();
+            if (destination == null)
+            {
+               destination = new MessageDrivenDestination();
+               ejb.setMessageDrivenDestination(destination);
+            }
+
+            destination.setDestinationType(getValue(localName, value));
+         }
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(MessageDrivenDestination destination,
+                        UnmarshallingContext navigator, String namespaceURI, String localName,
+                        String value)
+   {
+      if (localName.equals("destination-type"))
+      {
+         destination.setDestinationType(getValue(localName, value));
+      }
+      else if (localName.equals("subscription-durability"))
+      {
+         destination.setSubscriptionDurability(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(SessionEnterpriseBean ejb,
+                        UnmarshallingContext navigator, String namespaceURI, String localName,
+                        String value)
+   {
+      if (!isEjbParentName(ejb, localName, value))
+      {
+         if (localName.equals("session-type"))
+         {
+            ejb.setSessionType(getValue(localName, value));
+         }
+         else if (localName.equals("transaction-type"))
+         {
+            ejb.setTransactionManagementType(getValue(localName, value));
+         }
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(ApplicationException exception,
+                        UnmarshallingContext navigator, String namespaceURI, String localName,
+                        String value)
+   {
+      if (localName.equals("exception-class"))
+      {
+         exception.setExceptionClass(getValue(localName, value));
+      }
+      else if (localName.equals("rollback"))
+      {
+         exception.setRollback(Boolean.valueOf(getValue(localName, value)));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(EntityEnterpriseBean ejb,
+                        UnmarshallingContext navigator, String namespaceURI, String localName,
+                        String value)
+   {
+      if (!isEjbParentName(ejb, localName, value))
+      {
+         if (localName.equals("persistence-type"))
+         {
+            ejb.setPersistenceType(getValue(localName, value));
+         }
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(SecurityIdentity si, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("use-caller-identity"))
+      {
+         si.setUseCallerIdentity(true);
+      }
+   }
+
+   public void setValue(Interceptor interceptor, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("interceptor-class"))
+      {
+         interceptor.setInterceptorClass(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(EjbRelation relation, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("ejb-relation-name"))
+      {
+         relation.setEjbRelationName(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(EjbRelationshipRole role,
+                        UnmarshallingContext navigator, String namespaceURI, String localName,
+                        String value)
+   {
+      if (localName.equals("ejb-relationship-role-name"))
+      {
+         role.setEjbRelationshipRoleName(getValue(localName, value));
+      }
+      else if (localName.equals("multiplicity"))
+      {
+         role.setMultiplicity(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(RelationshipRoleSource source,
+                        UnmarshallingContext navigator, String namespaceURI, String localName,
+                        String value)
+   {
+      if (localName.equals("ejb-name"))
+      {
+         source.setEjbName(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(CmrField field, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("cmr-field-name"))
+      {
+         field.setCmrFieldName(getValue(localName, value));
+      }
+      else if (localName.equals("cmr-field-type"))
+      {
+         field.setCmrFieldType(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(SecurityRole role, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("role-name"))
+      {
+         role.setRoleName(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(MethodPermission permission,
+                        UnmarshallingContext navigator, String namespaceURI, String localName,
+                        String value)
+   {
+      if (localName.equals("role-name"))
+      {
+         permission.addRoleName(getValue(localName, value));
+      }
+      else if (localName.equals("unchecked"))
+      {
+         permission.setUnchecked(true);
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(ContainerTransaction transaction,
+                        UnmarshallingContext navigator, String namespaceURI, String localName,
+                        String value)
+   {
+      if (localName.equals("trans-attribute"))
+      {
+         transaction.setTransAttribute(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(Method method, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("ejb-name"))
+      {
+         method.setEjbName(getValue(localName, value));
+      }
+      else if (localName.equals("method-name"))
+      {
+         method.setMethodName(getValue(localName, value));
+      }
+      else if (localName.equals("method-param"))
+      {
+         method.addMethodParam(getValue(localName, value));
+      }
+      else if (localName.equals("lifecycle-callback-method"))
+      {
+         method.setMethodName(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(Inject inject, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("jndi-name"))
+      {
+         inject.setJndiName(getValue(localName, value));
+      }
+   }
+
+   public void setValue(InterceptorBinding binding, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("ejb-name"))
+      {
+         binding.setEjbName(getValue(localName, value));
+      }
+      else if (localName.equals("interceptor-class"))
+      {
+         binding.addInterceptorClass(getValue(localName, value));
+      }
+      else if (localName.equals("method-name"))
+      {
+         binding.setMethodName(getValue(localName, value));
+      }
+      else if (localName.equals("method-param"))
+      {
+         binding.addMethodParam(getValue(localName, value));
+      }
+      else if (localName.equals("exclude-default-interceptors"))
+      {
+         binding.setExcludeDefaultInterceptors(true);
+      }
+      else if (localName.equals("exclude-class-interceptors"))
+      {
+         binding.setExcludeClassInterceptors(true);
+      }
+   }
+
+   public void setValue(InterceptorOrder order, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("interceptor-class"))
+      {
+         order.addInterceptorClass(getValue(localName, value));
+      }
+   }
+   
+   protected String getValue(String name, String value)
+   {
+      if (value.startsWith("${") && value.endsWith("}"))
+      {
+         try
+         {
+            String propertyName = value.substring(2, value.length()-1);
+            ObjectName propertyServiceON = new ObjectName("jboss:type=Service,name=SystemProperties");
+            KernelAbstraction kernelAbstraction = KernelAbstractionFactory.getInstance();
+            String propertyValue = (String)kernelAbstraction.invoke(propertyServiceON, "get", new Object[]{propertyName}, new String[]{"java.lang.String"});
+            log.debug("Replaced ejb-jar.xml element " + name + " with value " + propertyValue);
+            return propertyValue;
+         }
+         catch (Exception e)
+         {
+            log.warn("Unable to look up property service for ejb-jar.xml element " + name + " with value " + value + ". Caused by " + e.getClass() + " " + e.getMessage());
+         }
+      }
+      
+      return value;
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbRelation.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbRelation.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbRelation.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,74 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents an ejb-relation element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class EjbRelation
+{
+
+   private String ejbRelationName = null;
+
+   private List ejbRelationshipRoles = new ArrayList();
+
+   public String getEjbRelationName()
+   {
+      return ejbRelationName;
+   }
+
+   public void setEjbRelationName(String ejbRelationName)
+   {
+      this.ejbRelationName = ejbRelationName;
+   }
+
+   public List getEjbRelationshipRoles()
+   {
+      return ejbRelationshipRoles;
+   }
+
+   public void setEjbRelationshipRoles(List ejbRelationshipRoles)
+   {
+      this.ejbRelationshipRoles = ejbRelationshipRoles;
+   }
+
+   public void addEjbRelationshipRole(EjbRelationshipRole role)
+   {
+      ejbRelationshipRoles.add(role);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbRelationName=").append(ejbRelationName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbRelationshipRole.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbRelationshipRole.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EjbRelationshipRole.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,120 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents an ejb-relationship-role element of the ejb-jar.xml deployment
+ * descriptor for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class EjbRelationshipRole
+{
+
+   private String ejbRelationshipRoleName;
+
+   private String multiplicity;
+
+   private boolean cascadeDelete = false;
+
+   private List ejbRelationshipRoles = new ArrayList();
+
+   private RelationshipRoleSource relationshipRoleSource;;
+
+   private CmrField cmrField;
+
+   public String getEjbRelationshipRoleName()
+   {
+      return ejbRelationshipRoleName;
+   }
+
+   public void setEjbRelationshipRoleName(String ejbRelationName)
+   {
+      this.ejbRelationshipRoleName = ejbRelationName;
+   }
+
+   public String getMultiplicity()
+   {
+      return multiplicity;
+   }
+
+   public void setMultiplicity(String multiplicity)
+   {
+      this.multiplicity = multiplicity;
+   }
+
+   public boolean isCascadeDelete()
+   {
+      return cascadeDelete;
+   }
+
+   public void setCascadeDelete(boolean cascadeDelete)
+   {
+      this.cascadeDelete = cascadeDelete;
+   }
+
+   public List getEjbRelationshipRoles()
+   {
+      return ejbRelationshipRoles;
+   }
+
+   public void setEjbRelationshipRoles(List ejbRelationshipRoles)
+   {
+      this.ejbRelationshipRoles = ejbRelationshipRoles;
+   }
+
+   public void addEjbRelationshipRole(EjbRelationshipRole role)
+   {
+      ejbRelationshipRoles.add(role);
+   }
+
+   public RelationshipRoleSource getRelationshipRoleSource()
+   {
+      return relationshipRoleSource;
+   }
+
+   public void setRelationshipRoleSource(RelationshipRoleSource relationshipRoleSource)
+   {
+      this.relationshipRoleSource = relationshipRoleSource;
+   }
+
+   public CmrField getCmrField()
+   {
+      return cmrField;
+   }
+
+   public void setCmrField(CmrField cmrField)
+   {
+      this.cmrField = cmrField;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("ejbRelationshipRoleName=").append(ejbRelationshipRoleName);
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBean.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBean.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,361 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collection;
+import java.util.HashSet;
+import javax.ejb.TransactionManagementType;
+import org.jboss.logging.Logger;
+
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+import org.jboss.metamodel.descriptor.InjectionTarget;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.PersistenceUnitRef;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+import org.jboss.metamodel.descriptor.PersistenceContextRef;
+
+/**
+ * Represents an EJB element of the ejb-jar.xml deployment descriptor for the
+ * 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 55512 $</tt>
+ */
+public abstract class EnterpriseBean
+   extends EnvironmentRefGroup implements Injectable
+{
+   private static final Logger log = Logger.getLogger(EnterpriseBean.class);
+
+   public static final String BEAN = "Bean";
+
+   public static final String CONTAINER = "Container";
+
+   // ejb-jar.xml
+   private String ejbName = null;
+
+   private String home = null;
+
+   private String remote = null;
+
+   private String localHome = null;
+
+   private String local = null;
+
+   private String ejbClass = null;
+
+   private List<RemoteBinding> remoteBindings = new ArrayList();
+
+   private SecurityIdentity securityIdentity;
+
+   protected TransactionManagementType tmType = null;
+
+   // jboss.xml
+   private String jndiName;
+
+   private String localJndiName;
+
+   private String securityDomain;
+
+   private boolean callByValue = false;
+
+   private String aopDomainName = null;
+
+   private MethodAttributes methodAttributes = null;
+
+   private Collection<String> dependencies = new HashSet<String>();
+
+   private Collection<InjectionTarget> ignoreDependencies = new HashSet<InjectionTarget>();
+   
+   private Collection<XmlAnnotation> xmlAnnotations = new HashSet<XmlAnnotation>();
+
+   private PoolConfig poolConfig = null;
+   
+   public void addXmlAnnotation(XmlAnnotation annotation)
+   {
+      xmlAnnotations.add(annotation);
+   }
+
+   public Collection<XmlAnnotation> getXmlAnnotations()
+   {
+      return xmlAnnotations;
+   }
+
+   public void setPoolConfig(PoolConfig poolConfig)
+   {
+      this.poolConfig = poolConfig;
+   }
+
+   public PoolConfig getPoolConfig()
+   {
+      return poolConfig;
+   }
+
+   public void addRemoteBinding(RemoteBinding binding)
+   {
+      remoteBindings.add(binding);
+   }
+
+   public List<RemoteBinding> getRemoteBindings()
+   {
+      return remoteBindings;
+   }
+
+   public void addDependency(String depends)
+   {
+      dependencies.add(depends);
+   }
+
+   public Collection<String> getDependencies()
+   {
+      return dependencies;
+   }
+
+   public void addIgnoreDependency(InjectionTarget ignore)
+   {
+      ignoreDependencies.add(ignore);
+   }
+
+   public Collection<InjectionTarget> getIgnoreDependencies()
+   {
+      return ignoreDependencies;
+   }
+
+   public void mergeMessageDestinationRef(MessageDestinationRef ref)
+   {
+      MessageDestinationRef tmpRef = (MessageDestinationRef)messageDestinationRefs.get(ref.getMessageDestinationRefName());
+      if (tmpRef != null)
+         tmpRef.merge(ref);
+   }
+
+   public void mergeResourceRef(ResourceRef ref)
+   {
+      ResourceRef tmpRef = (ResourceRef)resourceRefs.get(ref.getResRefName());
+      if (tmpRef != null)
+         tmpRef.merge(ref);
+   }
+
+   public void mergeResourceEnvRef(ResourceEnvRef ref)
+   {
+      ResourceEnvRef tmpRef = (ResourceEnvRef)resourceEnvRefs.get(ref.getResRefName());
+      if (tmpRef != null)
+         tmpRef.merge(ref);
+   }
+
+   public void setMethodAttributes(MethodAttributes methodAttributes)
+   {
+      this.methodAttributes = methodAttributes;
+   }
+
+   public MethodAttributes getMethodAttributes()
+   {
+      return methodAttributes;
+   }
+
+   public void setAopDomainName(String aopDomainName)
+   {
+      this.aopDomainName = aopDomainName;
+   }
+
+   public String getAopDomainName()
+   {
+      return aopDomainName;
+   }
+
+   public void setRunAsPrincipal(String principal)
+   {
+      if (securityIdentity != null)
+         securityIdentity.setRunAsPrincipal(principal);
+   }
+
+   public void setCallByValue(boolean callByValue)
+   {
+      this.callByValue = callByValue;
+   }
+
+   public boolean isCallByValue()
+   {
+      return callByValue;
+   }
+
+   public String getSecurityDomain()
+   {
+      return securityDomain;
+   }
+
+   public void setSecurityDomain(String securityDomain)
+   {
+      this.securityDomain = securityDomain;
+   }
+
+   public String getJndiName()
+   {
+      return jndiName;
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+
+   public String getLocalJndiName()
+   {
+      return localJndiName;
+   }
+
+   public void setLocalJndiName(String localJndiName)
+   {
+      this.localJndiName = localJndiName;
+   }
+
+   public TransactionManagementType getTransactionManagementType()
+   {
+      return tmType;
+   }
+
+   public void setTransactionManagementType(String transactionType)
+   {
+      if (transactionType.equals(BEAN))
+         tmType = TransactionManagementType.BEAN;
+      else if (transactionType.equals(CONTAINER))
+         tmType = TransactionManagementType.CONTAINER;
+   }
+
+   public boolean isSessionBean()
+   {
+      return this instanceof SessionEnterpriseBean;
+   }
+
+   public boolean isConsumer()
+   {
+      return this instanceof Consumer;
+   }
+
+   public boolean isEntityBean()
+   {
+      return this instanceof EntityEnterpriseBean;
+   }
+
+   public boolean isMessageDrivenBean()
+   {
+      return this instanceof MessageDrivenBean;
+   }
+
+   public boolean isService()
+   {
+      return this instanceof Service;
+   }
+
+   public String getEjbName()
+   {
+      return ejbName;
+   }
+
+   public void setEjbName(String ejbName)
+   {
+      this.ejbName = ejbName;
+   }
+
+   public String getHome()
+   {
+      return home;
+   }
+
+   public void setHome(String home)
+   {
+      this.home = home;
+   }
+
+   public String getRemote()
+   {
+      return remote;
+   }
+
+   public void setRemote(String remote)
+   {
+      this.remote = remote;
+   }
+
+   public String getLocalHome()
+   {
+      return localHome;
+   }
+
+   public void setLocalHome(String localHome)
+   {
+      this.localHome = localHome;
+   }
+
+   public String getLocal()
+   {
+      return local;
+   }
+
+   public void setLocal(String local)
+   {
+      this.local = local;
+   }
+
+   public String getEjbClass()
+   {
+      return ejbClass;
+   }
+
+   public void setEjbClass(String ejbClass)
+   {
+      this.ejbClass = ejbClass;
+   }
+
+   public SecurityIdentity getSecurityIdentity()
+   {
+      return securityIdentity;
+   }
+
+   public void setSecurityIdentity(SecurityIdentity securityIdentity)
+   {
+      this.securityIdentity = securityIdentity;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("ejbName=").append(ejbName);
+      sb.append(",remoteBindings=").append(remoteBindings);
+      sb.append(",jndiName=").append(jndiName);
+      sb.append(",local=").append(local);
+      sb.append(",remote=").append(remote);
+      sb.append(",home=").append(home);
+      sb.append(",localHome=").append(localHome);
+      sb.append(",ejbClass=").append(ejbClass);
+      sb.append(",ejbRefs=").append(ejbRefs);
+      sb.append(",ejbLocalRefs=").append(ejbLocalRefs);
+      sb.append(",resourceRefs=").append(resourceRefs);
+      sb.append(",resourceEnvRefs=").append(resourceEnvRefs);
+      sb.append(",methodAttributes=").append(methodAttributes);
+      sb.append(",aopDomainName=").append(aopDomainName);
+      sb.append(",dependencies=").append(dependencies);
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBeans.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBeans.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBeans.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,324 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import org.jboss.logging.Logger;
+
+import org.jboss.metamodel.descriptor.EjbLocalRef;
+import org.jboss.metamodel.descriptor.EjbRef;
+import org.jboss.metamodel.descriptor.InjectionTarget;
+import org.jboss.metamodel.descriptor.JndiRef;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+
+/**
+ * Represents EJB elements of the ejb-jar.xml deployment descriptor for the 1.4
+ * schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ *         ejbs.setCurrentEjbName(value); } else if
+ *         (localName.equals("jndi-name")){ ejbs.setJndiName(value);
+ * @version <tt>$Revision: 55512 $</tt>
+ */
+public class EnterpriseBeans
+{
+   private static final Logger log = Logger.getLogger(EnterpriseBeans.class);
+
+   private HashMap<String, EnterpriseBean> enterpriseBeans = new HashMap();
+
+   private EnterpriseBean currentEjb;
+   
+   public void setPoolConfig(PoolConfig config)
+   {
+      currentEjb.setPoolConfig(config);
+   }
+   
+   public void setDefaultActivationConfig(ActivationConfig config)
+   {
+      ((MessageDrivenBean)currentEjb).setDefaultActivationConfig(config);
+   }
+   
+   public void setCacheConfig(CacheConfig config)
+   {
+      ((SessionEnterpriseBean)currentEjb).setCacheConfig(config);
+   }
+   
+   public void setClustered(String clustered)
+   {
+      ((SessionEnterpriseBean)currentEjb).setClustered(clustered);
+   }
+   
+   public void setConcurrent(String concurrent)
+   {
+      ((SessionEnterpriseBean)currentEjb).setConcurrent(concurrent);
+   }
+   
+   public void addJndiRef(JndiRef ref)
+   {
+      currentEjb.addJndiRef(ref);
+   }
+   
+   public void addXmlAnnotation(XmlAnnotation xmlAnnotation)
+   {
+      currentEjb.addXmlAnnotation(xmlAnnotation);
+   }
+   
+   public void addRemoteBinding(RemoteBinding binding)
+   {
+      currentEjb.addRemoteBinding(binding);
+   }
+   
+   public void addIgnoreDependency(InjectionTarget ignore)
+   {
+      currentEjb.addIgnoreDependency(ignore);
+   }
+   
+   public void addResourceRef(ResourceRef ref)
+   {
+      currentEjb.mergeResourceRef(ref);
+   }
+   
+   public void addResourceEnvRef(ResourceEnvRef ref)
+   {
+      currentEjb.mergeResourceEnvRef(ref);
+   }
+   
+   public void addMessageDestinationRef(MessageDestinationRef ref)
+   {
+      currentEjb.mergeMessageDestinationRef(ref);
+   }
+   
+   public void setMethodAttributes(MethodAttributes attributes)
+   {
+      currentEjb.setMethodAttributes(attributes);
+   }
+
+   public void setCurrentEjbName(String currentEjbName, Class ejbClass)
+   {
+      currentEjb = createEjbByEjbName(currentEjbName, ejbClass);
+   }
+
+   public void addDependency(String depends)
+   {
+      currentEjb.addDependency(depends);
+   }
+
+   public void updateEjbRef(EjbRef ref)
+   {
+      currentEjb.updateEjbRef(ref);
+   }
+
+   public void updateEjbLocalRef(EjbLocalRef ref)
+   {
+      currentEjb.updateEjbLocalRef(ref);
+   }
+   
+   public void updateResourceRef(ResourceRef ref)
+   {
+      currentEjb.updateResourceRef(ref);
+   }
+   
+   public void updateResourceEnvRef(ResourceEnvRef ref)
+   {
+      currentEjb.updateResourceEnvRef(ref);
+   }
+   
+   public void updateMessageDestinationRef(MessageDestinationRef ref)
+   {
+      currentEjb.updateMessageDestinationRef(ref);
+   }
+   
+   public void setResourceAdapterName(String name)
+   {
+      ((MessageDrivenBean)currentEjb).setResourceAdaptorName(name);
+   }
+
+   public void setDestinationJndiName(String name)
+   {
+      ((MessageDrivenBean)currentEjb).setDestinationJndiName(name);
+   }
+
+   public void setMdbUser(String name)
+   {
+      ((MessageDrivenBean)currentEjb).setMdbUser(name);
+   }
+
+   public void setMdbPassword(String name)
+   {
+      ((MessageDrivenBean)currentEjb).setMdbPassword(name);
+   }
+   
+   public void setMdbSubscriptionId(String id)
+   {
+      ((MessageDrivenBean)currentEjb).setMdbSubscriptionId(id);
+   }
+
+   public void setAopDomainName(String aopDomainName)
+   {
+      currentEjb.setAopDomainName(aopDomainName);
+   }
+
+   public void setRunAsPrincipal(String principal)
+   {
+      currentEjb.setRunAsPrincipal(principal);
+   }
+
+   public void setClusterConfig(ClusterConfig config)
+   {
+      ((SessionEnterpriseBean)currentEjb).setClusterConfig(config);
+   }
+
+   public void setCallByValue(boolean callByValue)
+   {
+      currentEjb.setCallByValue(callByValue);
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      currentEjb.setJndiName(jndiName);
+   }
+
+   public void setSecurityDomain(String securityDomain)
+   {
+      currentEjb.setSecurityDomain(securityDomain);
+   }
+
+   public void setLocalJndiName(String jndiName)
+   {
+      currentEjb.setLocalJndiName(jndiName);
+   }
+
+   public EnterpriseBean createEjbByEjbName(String ejbName, Class ejbClass)
+   {
+      EnterpriseBean ejb = (EnterpriseBean) enterpriseBeans.get(ejbName);
+      if (ejb != null)
+         return ejb;
+      
+      try 
+      {
+         ejb = (EnterpriseBean)ejbClass.newInstance();
+         ejb.setEjbName(ejbName);
+         enterpriseBeans.put(ejbName, ejb);
+      }
+      catch (Exception e){}
+      
+      return ejb;
+   }
+   
+   public EnterpriseBean findEjbByEjbName(String ejbName)
+   {
+      return enterpriseBeans.get(ejbName);
+   }
+
+   public List<EnterpriseBean> findEjbsByClass(String className)
+   {
+      ArrayList<EnterpriseBean> result = new ArrayList<EnterpriseBean>();
+
+      Iterator ejbs = enterpriseBeans.values().iterator();
+      while (ejbs.hasNext())
+      {
+         EnterpriseBean ejb = (EnterpriseBean) ejbs.next();
+         String ejbClassName = ejb.getEjbClass();
+         if (ejbClassName != null && ejbClassName.equals(className))
+            result.add(ejb);
+      }
+      return result;
+   }
+
+   public EnterpriseBean findEjbByRemote(String remote)
+   {
+      Iterator ejbs = enterpriseBeans.values().iterator();
+      while (ejbs.hasNext())
+      {
+         EnterpriseBean ejb = (EnterpriseBean) ejbs.next();
+         if (ejb.getRemote() != null && ejb.getRemote().equals(remote))
+            return ejb;
+      }
+      return null;
+   }
+
+   public EnterpriseBean findEjbByLocal(String local)
+   {
+      Iterator ejbs = enterpriseBeans.values().iterator();
+      while (ejbs.hasNext())
+      {
+         EnterpriseBean ejb = (EnterpriseBean) ejbs.next();
+         if (ejb.getLocal() != null && ejb.getLocal().equals(local))
+            return ejb;
+      }
+      return null;
+   }
+
+   public Collection<EnterpriseBean> getEnterpriseBeans()
+   {
+      return enterpriseBeans.values();
+   }
+
+/*   public void setEnterpriseBeans(List enterpriseBeans)
+   {
+      this.enterpriseBeans = enterpriseBeans;
+   }*/
+
+   public void addEnterpriseBean(EnterpriseBean ejb)
+   {
+      enterpriseBeans.put(ejb.getEjbName(), ejb);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("enterpriseBeans=").append(enterpriseBeans);
+      sb.append("]");
+      return sb.toString();
+   }
+
+   public boolean equals(Object o)
+   {
+      if (this == o)
+         return true;
+      if (!(o instanceof EnterpriseBeans))
+         return false;
+
+      final EnterpriseBeans ejbs = (EnterpriseBeans) o;
+
+      if (enterpriseBeans != null ? !enterpriseBeans
+              .equals(ejbs.enterpriseBeans) : ejbs.enterpriseBeans != null)
+         return false;
+
+      return true;
+   }
+
+   public int hashCode()
+   {
+      int result;
+      result = (enterpriseBeans != null ? enterpriseBeans.hashCode() : 0);
+      // result = 29 * result + (version != null ? version.hashCode() : 0);
+      return result;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EntityEnterpriseBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EntityEnterpriseBean.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/EntityEnterpriseBean.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,93 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents an Entity EJB element of the ejb-jar.xml deployment descriptor for
+ * the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class EntityEnterpriseBean extends EnterpriseBean
+{
+
+   private String persistenceType;
+
+   private List cmpFields = new ArrayList();
+
+   private List queries = new ArrayList();
+
+   public String getPersistenceType()
+   {
+      return persistenceType;
+   }
+
+   public void setPersistenceType(String persistenceType)
+   {
+      this.persistenceType = persistenceType;
+   }
+
+   public List getCmpFields()
+   {
+      return cmpFields;
+   }
+
+   public void setCmpFields(List cmpFields)
+   {
+      this.cmpFields = cmpFields;
+   }
+
+   public void addCmpField(CmpField cmpField)
+   {
+      cmpFields.add(cmpField);
+   }
+
+   public List getQueries()
+   {
+      return queries;
+   }
+
+   public void setQueries(List queries)
+   {
+      this.queries = queries;
+   }
+
+   public void addQuery(Query query)
+   {
+      queries.add(query);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append('[');
+      sb.append(super.toString());
+      sb.append(",");
+      sb.append("persistenceType=").append(persistenceType);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeClassInterceptors.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeClassInterceptors.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeClassInterceptors.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 45242 $
+ */
+public class ExcludeClassInterceptors
+{
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeDefaultInterceptors.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeDefaultInterceptors.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeDefaultInterceptors.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 45242 $
+ */
+public class ExcludeDefaultInterceptors
+{
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeList.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeList.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ExcludeList.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,59 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.logging.Logger;
+
+/**
+ * Represents an <exlude-list> element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class ExcludeList
+{
+   private static final Logger log = Logger.getLogger(ExcludeList.class);
+
+   private List methods = new ArrayList();
+
+   public List getMethods()
+   {
+      return methods;
+   }
+
+   public void addMethod(Method method)
+   {
+      methods.add(method);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("methods=").append(methods);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InitList.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InitList.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InitList.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,59 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.logging.Logger;
+
+/**
+ * Represents an <init-list> element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class InitList
+{
+   private static final Logger log = Logger.getLogger(InitList.class);
+
+   private List methods = new ArrayList();
+
+   public List getMethods()
+   {
+      return methods;
+   }
+
+   public void addMethod(Method method)
+   {
+      methods.add(method);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("methods=").append(methods);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InitMethod.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InitMethod.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InitMethod.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,64 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+/**
+ * Represents an <init-method> element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class InitMethod
+{
+   private Method beanMethod;
+   private Method createMethod;
+
+   public Method getBeanMethod()
+   {
+      return beanMethod;
+   }
+
+   public void setBeanMethod(Method beanMethod)
+   {
+      this.beanMethod = beanMethod;
+   }
+
+   public Method getCreateMethod()
+   {
+      return createMethod;
+   }
+
+   public void setCreateMethod(Method createMethod)
+   {
+      this.createMethod = createMethod;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("method=").append(beanMethod);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Inject.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Inject.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Inject.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,70 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.logging.Logger;
+
+/**
+ * Represents an <inject> element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class Inject
+{
+   private static final Logger log = Logger.getLogger(Inject.class);
+
+   private List methods = new ArrayList();
+   private String jndiName;
+
+   public String getJndiName()
+   {
+      return jndiName;
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+
+   public List getMethods()
+   {
+      return methods;
+   }
+
+   public void addMethod(Method method)
+   {
+      methods.add(method);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("jndiName=").append(jndiName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Injectable.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Injectable.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Injectable.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.metamodel;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.metamodel.descriptor.EjbLocalRef;
+import org.jboss.metamodel.descriptor.EjbRef;
+import org.jboss.metamodel.descriptor.JndiRef;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.PersistenceUnitRef;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+import org.jboss.metamodel.descriptor.WebServiceRef;
+import org.jboss.metamodel.descriptor.PersistenceContextRef;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 46506 $
+ */
+public interface Injectable
+{
+
+   Collection<EjbLocalRef> getEjbLocalRefs();
+
+   Collection<EjbRef> getEjbRefs();
+
+   Collection<ResourceEnvRef> getResourceEnvRefs();
+
+   Collection<ResourceRef> getResourceRefs();
+
+   Collection<WebServiceRef> getWebServiceRefs();
+
+   Collection<MessageDestinationRef> getMessageDestinationRefs();
+
+   List<PersistenceUnitRef> getPersistenceUnitRefs();
+
+   List<PersistenceContextRef> getPersistenceContextRefs();
+
+   Collection<JndiRef> getJndiRefs();
+}
\ No newline at end of file

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Interceptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Interceptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Interceptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,133 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+import org.jboss.metamodel.descriptor.PersistenceUnitRef;
+import org.jboss.metamodel.descriptor.PersistenceContextRef;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 46509 $
+ */
+public class Interceptor
+   extends EnvironmentRefGroup implements Injectable
+{
+   String interceptorClass;
+   Method aroundInvoke;
+   Method postConstruct;
+   Method postActivate;
+   Method preDestroy;
+   Method prePassivate;
+
+   public Interceptor()
+   {
+   }
+
+   public Method getAroundInvoke()
+   {
+      return aroundInvoke;
+   }
+
+   public void setAroundInvoke(Method aroundInvoke)
+   {
+      this.aroundInvoke = aroundInvoke;
+   }
+
+   public String getInterceptorClass()
+   {
+      return interceptorClass;
+   }
+
+   public void setInterceptorClass(String interceptorClass)
+   {
+      this.interceptorClass = interceptorClass;
+   }
+
+   public Method getPostActivate()
+   {
+      return postActivate;
+   }
+
+   public void setPostActivate(Method postActivate)
+   {
+      this.postActivate = postActivate;
+   }
+
+   public Method getPostConstruct()
+   {
+      return postConstruct;
+   }
+
+   public void setPostConstruct(Method postConstruct)
+   {
+      this.postConstruct = postConstruct;
+   }
+
+   public Method getPreDestroy()
+   {
+      return preDestroy;
+   }
+
+   public void setPreDestroy(Method preDestroy)
+   {
+      this.preDestroy = preDestroy;
+   }
+
+   public Method getPrePassivate()
+   {
+      return prePassivate;
+   }
+
+   public void setPrePassivate(Method prePassivate)
+   {
+      this.prePassivate = prePassivate;
+   }
+
+   private List<PersistenceContextRef> persistenceContextRefs = new ArrayList<PersistenceContextRef>();
+   private List<PersistenceUnitRef> persistenceUnitRefs = new ArrayList<PersistenceUnitRef>();
+
+   public List<PersistenceContextRef> getPersistenceContextRefs()
+   {
+      return persistenceContextRefs;
+   }
+
+   public List<PersistenceUnitRef> getPersistenceUnitRefs()
+   {
+      return persistenceUnitRefs;
+   }
+
+   public void addPersistenceContextRef(PersistenceContextRef ref)
+   {
+      persistenceContextRefs.add(ref);
+   }
+
+   public void addPersistenceUnitRef(PersistenceUnitRef ref)
+   {
+      persistenceUnitRefs.add(ref);
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InterceptorBinding.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InterceptorBinding.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InterceptorBinding.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,96 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 45242 $
+ */
+public class InterceptorBinding extends Method
+{
+   Boolean ordered = null;
+   private ArrayList<String> interceptorClasses = new ArrayList<String>();
+   private boolean excludeDefaultInterceptors;
+   private boolean excludeClassInterceptors;
+   
+   public InterceptorBinding()
+   {
+      super();
+   }
+
+   public boolean getExcludeClassInterceptors()
+   {
+      return excludeClassInterceptors;
+   }
+
+   public void setExcludeClassInterceptors(boolean excludeClassInterceptors)
+   {
+      this.excludeClassInterceptors = excludeClassInterceptors;
+   }
+
+   public boolean getExcludeDefaultInterceptors()
+   {
+      return excludeDefaultInterceptors;
+   }
+
+   public void setExcludeDefaultInterceptors(boolean excludeDefaultInterceptors)
+   {
+      this.excludeDefaultInterceptors = excludeDefaultInterceptors;
+   }
+
+   public ArrayList<String> getInterceptorClasses()
+   {
+      return interceptorClasses;
+   }
+
+   public void addInterceptorClass(String interceptorClass)
+   {
+      if (ordered == null)
+      {
+         ordered = false;
+      }
+      if (ordered) throw new RuntimeException("Cannot have both interceptor-class and interceptor-order in interceptor-binding");
+      this.interceptorClasses.add(interceptorClass);
+   }
+
+   public void setOrderedInterceptorClasses(InterceptorOrder order)
+   {
+      if (ordered == null)
+      {
+         ordered = true;
+      }
+      if (!ordered) throw new RuntimeException("Cannot have both interceptor-class and interceptor-order in interceptor-binding");
+      this.interceptorClasses.addAll(order.getInterceptorClasses());
+   }
+
+   public boolean isOrdered()
+   {
+      if (ordered == null) return false;
+      return ordered;
+   }
+
+   
+   
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InterceptorOrder.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InterceptorOrder.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/InterceptorOrder.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 45242 $
+ */
+public class InterceptorOrder
+{
+   private ArrayList<String> interceptorClasses = new ArrayList<String>();
+
+   public InterceptorOrder()
+   {
+      // FIXME InterceptorOrder constructor
+      super();
+   }
+
+   public void addInterceptorClass(String interceptorClass)
+   {
+      this.interceptorClasses.add(interceptorClass);
+   }
+
+   public ArrayList<String> getInterceptorClasses()
+   {
+      return interceptorClasses;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Interceptors.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Interceptors.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Interceptors.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 45242 $
+ */
+public class Interceptors
+{
+   ArrayList<Interceptor> interceptors = new ArrayList<Interceptor>();
+   
+   public Interceptors()
+   {
+      // FIXME Interceptors constructor
+      super();
+   }
+   
+   public void addInterceptor(Interceptor interceptor)
+   {
+      interceptors.add(interceptor);
+   }
+
+   public ArrayList<Interceptor> getInterceptors()
+   {
+      return interceptors;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/JBossDDObjectFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/JBossDDObjectFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/JBossDDObjectFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,1120 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.management.ObjectName;
+
+import org.jboss.ejb3.KernelAbstraction;
+import org.jboss.ejb3.KernelAbstractionFactory;
+import org.jboss.logging.Logger;
+import org.jboss.util.xml.JBossEntityResolver;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.xml.sax.Attributes;
+
+import org.jboss.metamodel.descriptor.DDObjectFactory;
+import org.jboss.metamodel.descriptor.EjbLocalRef;
+import org.jboss.metamodel.descriptor.EjbRef;
+import org.jboss.metamodel.descriptor.EnvEntry;
+import org.jboss.metamodel.descriptor.InjectionTarget;
+import org.jboss.metamodel.descriptor.JndiRef;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.NameValuePair;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+import org.jboss.metamodel.descriptor.SecurityRole;
+
+/**
+ * Represents the jboss.xml deployment descriptor for the 2.1 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 56531 $</tt>
+ */
+public class JBossDDObjectFactory extends DDObjectFactory
+{
+   private static final Logger log = Logger
+           .getLogger(JBossDDObjectFactory.class);
+
+   private EjbJarDD dd;
+   private Class ejbClass;
+   
+   public static EjbJarDD parse(URL ddResource, EjbJarDD dd)
+      throws JBossXBException, IOException
+   {
+      ObjectModelFactory factory = null;
+      Unmarshaller unmarshaller = null;
+      
+      if (ddResource != null)
+      {
+         log.debug("found jboss.xml " + ddResource);
+      
+         if (dd == null)
+            dd = new EjbJarDD();
+         
+         factory = new JBossDDObjectFactory(dd);
+         UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory
+               .newInstance();
+         unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, true);
+         unmarshaller = unmarshallerFactory.newUnmarshaller();
+         JBossEntityResolver entityResolver = new JBossEntityResolver();
+         unmarshaller.setEntityResolver(entityResolver);
+      
+         dd = (EjbJarDD) unmarshaller.unmarshal(ddResource.openStream(),
+               factory, null);
+      }
+   
+      return dd;
+   }
+
+   public JBossDDObjectFactory(EjbJarDD dd)
+   {
+      super();
+      this.dd = dd;
+   }
+
+   /**
+    * Return the root.
+    */
+   public Object newRoot(Object root, UnmarshallingContext navigator,
+                         String namespaceURI, String localName, Attributes attrs)
+   {
+      return dd;
+   }
+
+   public Object completeRoot(Object root, UnmarshallingContext ctx,
+                              String uri, String name)
+   {
+      return root;
+   }
+
+   // Methods discovered by introspection
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(EjbJarDD dd, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("enterprise-beans"))
+      {
+         child = dd.getEnterpriseBeans();
+         if (child == null)
+         {
+            dd.setEnterpriseBeans(new EnterpriseBeans());
+            child = dd.getEnterpriseBeans();
+         }
+      }
+      else if (localName.equals("assembly-descriptor"))
+      {
+         child = dd.getAssemblyDescriptor();
+         if (child == null)
+         {
+            dd.setAssemblyDescriptor(new AssemblyDescriptor());
+            child = dd.getAssemblyDescriptor();
+         }
+      }
+      else if (localName.equals("resource-manager"))
+      {
+         child = new ResourceManager();
+      }
+
+      return child;
+   }
+   
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(Consumer consumer, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+      
+      if ((child = this.newEnvRefGroupChild(localName)) != null)
+            return child;
+      
+      if (localName.equals("current-message"))
+      {
+         child = new CurrentMessage();
+      }
+      else if (localName.equals("message-properties"))
+      {
+         child = new MessageProperties();
+      }
+      else if (localName.equals("producer"))
+      {
+         child = new Producer(false);
+      }
+      else if (localName.equals("local-producer"))
+      {
+         child = new Producer(true);
+      }
+      else if (localName.equals("annotation"))
+      {
+         child = new XmlAnnotation();
+      }
+      else if (localName.equals("ignore-dependency"))
+      {
+         child = new InjectionTarget();
+      }
+      else if (localName.equals("remote-binding"))
+      {
+         child = new RemoteBinding();
+      }
+      else if (localName.equals("pool-config"))
+      {
+         child = new PoolConfig();
+      }
+      
+      return child;
+   }
+   
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(Service service, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+      
+      if ((child = this.newEnvRefGroupChild(localName)) != null)
+            return child;
+      
+      if (localName.equals("ignore-dependency"))
+      {
+         child = new InjectionTarget();
+      }
+      else if (localName.equals("annotation"))
+      {
+         child = new XmlAnnotation();
+      }
+      else if (localName.equals("remote-binding"))
+      {
+         child = new RemoteBinding();
+      }
+
+      return child;
+   }
+   
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(CurrentMessage message, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+      
+      if (localName.equals("method"))
+      {
+         child = new Method();
+      }
+
+      return child;
+   }
+   
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(MessageProperties properties, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+      
+      if (localName.equals("method"))
+      {
+         child = new Method();
+      }
+
+      return child;
+   }
+   
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(MethodAttributes attributes, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+      
+      if (localName.equals("method"))
+      {
+         child = new Method();
+      }
+
+      return child;
+   }
+   
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(AssemblyDescriptor descriptor,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+      if (localName.equals("message-destination"))
+      {
+         child = new MessageDestination();
+      }
+
+      return child;
+   }
+
+   /**
+    * Called when parsing of a new element started.
+    */
+   public Object newChild(EnterpriseBeans ejbs, UnmarshallingContext navigator,
+                          String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = null;
+
+      if ((child = this.newEnvRefGroupChild(localName)) != null)
+      {
+         return child;
+      }
+      
+      if (localName.equals("session"))
+      {
+         ejbClass = SessionEnterpriseBean.class;
+         child = ejbs;
+      }
+      else if (localName.equals("message-driven"))
+      {
+         ejbClass = MessageDrivenBean.class;
+         child = ejbs;
+      }
+      else if (localName.equals("service"))
+      {
+         child = new Service();
+      }
+      else if (localName.equals("consumer"))
+      {
+         child = new Consumer();
+      }
+      else if (localName.equals("method-attributes"))
+      {
+         child = new MethodAttributes();
+      }
+      else if (localName.equals("annotation"))
+      {
+         child = new XmlAnnotation();
+      }
+      else if (localName.equals("ignore-dependency"))
+      {
+         child = new InjectionTarget();
+      }
+      else if (localName.equals("cluster-config"))
+      {
+         child = new ClusterConfig();
+      }
+      else if (localName.equals("remote-binding"))
+      {
+         child = new RemoteBinding();
+      }
+      else if (localName.equals("cache-config"))
+      {
+         child = new CacheConfig();
+      }
+      else if (localName.equals("pool-config"))
+      {
+         child = new PoolConfig();
+      }
+      else if (localName.equals("default-activation-config"))
+      {
+         child = new ActivationConfig();
+      }
+      
+      return child;
+   }
+   
+   public Object newChild(ActivationConfig parent,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      Object child = null;
+
+     if (localName.equals("default-activation-config-property"))
+     {
+         child = new NameValuePair();
+     }
+
+      return child;
+   }
+   
+   public Object newChild(XmlAnnotation parent,
+         UnmarshallingContext navigator, String namespaceURI, String localName,
+         Attributes attrs)
+   {
+      Object child = null;
+   
+      if (localName.equals("injection-target"))
+      {
+         child = new InjectionTarget();
+      }
+      else if (localName.equals("property"))
+      {
+         child = new NameValuePair();
+      }
+      
+      return child;
+   }
+   
+   public void addChild(XmlAnnotation parent, NameValuePair property,
+         UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addProperty(property);
+   }
+   
+   public void addChild(XmlAnnotation parent, InjectionTarget injectionTarget,
+         UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(injectionTarget);
+   }
+   
+   public void addChild(EnterpriseBeans parent, ActivationConfig config,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setDefaultActivationConfig(config);
+   }
+   
+   public void addChild(ActivationConfig parent, NameValuePair property,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addActivationConfigProperty(property);
+   }
+   
+   public void addChild(Consumer parent, Producer producer,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      if (producer.isLocal())
+         parent.addLocalProducer(producer);
+      else
+         parent.addProducer(producer);
+   }
+   
+   public void addChild(Consumer parent, RemoteBinding binding,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addRemoteBinding(binding);
+   }
+  
+   public void addChild(AssemblyDescriptor parent, MessageDestination destination,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMessageDestination(destination);
+   }
+   
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, CacheConfig config,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setCacheConfig(config);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, PoolConfig config,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setPoolConfig(config);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, MethodAttributes attributes,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setMethodAttributes(attributes);
+   }
+   
+   public void addChild(EnterpriseBeans parent, RemoteBinding binding,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addRemoteBinding(binding);
+   }
+   
+   public void addChild(EnterpriseBeans parent, InjectionTarget ignoreDependency,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addIgnoreDependency(ignoreDependency);
+   }
+   
+   public void addChild(EnterpriseBeans parent, XmlAnnotation xmlAnnotation,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addXmlAnnotation(xmlAnnotation);
+   }
+   
+   public void addChild(MethodAttributes parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMethod(method);
+   }
+   
+   public void addChild(Consumer parent, CurrentMessage message,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setCurrentMessage(message);
+   }
+   
+   public void addChild(Consumer parent, PoolConfig config,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setPoolConfig(config);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Consumer parent, MessageProperties message,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setMessageProperties(message);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(CurrentMessage parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMethod(method);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(MessageProperties parent, Method method,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addMethod(method);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, Service service,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEnterpriseBean(service);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Service parent, EjbRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Service parent, RemoteBinding binding,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addRemoteBinding(binding);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Service parent, EjbLocalRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbLocalRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Service parent, ResourceRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Service parent, JndiRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addJndiRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Service parent, ResourceEnvRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceEnvRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Consumer parent, EjbRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Consumer parent, EjbLocalRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEjbLocalRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Consumer parent, ResourceRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Consumer parent, JndiRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addJndiRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(Consumer parent, ResourceEnvRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceEnvRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, Consumer consumer,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEnterpriseBean(consumer);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, JndiRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addJndiRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EjbJarDD parent, ResourceManager manager,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addResourceManager(manager);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, EnterpriseBeans ejbs,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, EjbRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.updateEjbRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, EjbLocalRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.updateEjbLocalRef(ref);
+   }
+
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, ClusterConfig config,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setClusterConfig(config);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, ResourceRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.updateResourceRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, MessageDestinationRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.updateMessageDestinationRef(ref);
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(EnterpriseBeans parent, ResourceEnvRef ref,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.updateResourceEnvRef(ref);
+   }
+   
+   public void setValue(XmlAnnotation xmlAnnotation, UnmarshallingContext navigator,
+         String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("annotation-class"))
+      {
+         xmlAnnotation.setAnnotationClass(getValue(localName, value));
+      }
+      else if (localName.equals("annotation-implementation-class"))
+      {
+         xmlAnnotation.setAnnotationImplementationClass(getValue(localName, value));
+      }
+   }
+   
+   public void setValue(NameValuePair property, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("activation-config-property-name") || localName.equals("message-driven-config-property-name")  || localName.equals("property-name"))
+      {
+         property.setName(getValue(localName, value));
+      }
+      else if (localName.equals("activation-config-property-value") || localName.equals("message-driven-config-property-value") || localName.equals("property-value"))
+      {
+         property.setValue(getValue(localName, value));
+      }
+   }
+   
+   public void setValue(ResourceManager manager, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("res-name"))
+      {
+         manager.setResourceName(getValue(localName, value));
+      }
+      else if (localName.equals("res-jndi-name"))
+      {
+         manager.setResourceJndiName(getValue(localName, value));
+      }
+   }
+   
+   public void setValue(MessageDestination destination, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("message-destination-name"))
+      {
+         destination.setMessageDestinationName(getValue(localName, value));
+      }
+      else if (localName.equals("jndi-name"))
+      {
+         destination.setJndiName(getValue(localName, value));
+      }
+   }
+   
+   public void setValue(EnterpriseBeans ejbs, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("ejb-name"))
+      {
+         ejbs.setCurrentEjbName(value, ejbClass);
+      }
+      else if (localName.equals("jndi-name"))
+      {
+         ejbs.setJndiName(getValue(localName, value));
+      }
+      else if (localName.equals("local-jndi-name"))
+      {
+         ejbs.setLocalJndiName(getValue(localName, value));
+      }
+      else if (localName.equals("security-domain"))
+      {
+         ejbs.setSecurityDomain(getValue(localName, value));
+      }
+      else if (localName.equals("depends"))
+      {
+         ejbs.addDependency(getValue(localName, value));
+      }
+      else if (localName.equals("run-as-principal"))
+      {
+         ejbs.setRunAsPrincipal(getValue(localName, value));
+      }
+      else if (localName.equals("aop-domain-name"))
+      {
+         ejbs.setAopDomainName(getValue(localName, value));
+      }
+      else if (localName.equals("resource-adapter-name"))
+      {
+         ejbs.setResourceAdapterName(getValue(localName, value));
+      }
+      else if (localName.equals("destination-jndi-name"))
+      {
+         ejbs.setDestinationJndiName(getValue(localName, value));
+      }
+      else if (localName.equals("mdb-user"))
+      {
+         ejbs.setMdbUser(getValue(localName, value));
+      }
+      else if (localName.equals("mdb-passwd"))
+      {
+         ejbs.setMdbPassword(getValue(localName, value));
+      }
+      else if (localName.equals("mdb-subscription-id"))
+      {
+         ejbs.setMdbSubscriptionId(getValue(localName, value));
+      }
+      else if (localName.equals("clustered"))
+      {
+         ejbs.setClustered(getValue(localName, value));
+      }
+      else if (localName.equals("concurrent"))
+      {
+         ejbs.setConcurrent(getValue(localName, value));
+      }
+   }
+   
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(Service service, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("ejb-name"))
+      {
+         service.setEjbName(getValue(localName, value));
+      }
+      if (localName.equals("object-name"))
+      {
+         service.setObjectName(getValue(localName, value));
+      }
+      else if (localName.equals("ejb-class"))
+      {
+         service.setEjbClass(getValue(localName, value));
+      }
+      else if (localName.equals("local"))
+      {
+         service.setLocal(getValue(localName, value));
+      }
+      else if (localName.equals("remote"))
+      {
+         service.setRemote(getValue(localName, value));
+      }
+      else if (localName.equals("management"))
+      {
+         service.setManagement(getValue(localName, value));
+      }
+      else if (localName.equals("jndi-name"))
+      {
+         service.setJndiName(getValue(localName, value));
+      }
+      else if (localName.equals("local-jndi-name"))
+      {
+         service.setLocalJndiName(getValue(localName, value));
+      }
+      else if (localName.equals("security-domain"))
+      {
+         service.setSecurityDomain(getValue(localName, value));
+      }
+      else if (localName.equals("aop-domain-name"))
+      {
+         service.setAopDomainName(getValue(localName, value));
+      }
+      else if (localName.equals("depends"))
+      {
+         service.addDependency(getValue(localName, value));
+      }
+   }
+   
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(Consumer consumer, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("message-destination"))
+      {
+         consumer.setDestination(getValue(localName, value));
+      }
+      else if (localName.equals("message-destination-type"))
+      {
+         consumer.setDestinationType(getValue(localName, value));
+      }
+      else if (localName.equals("ejb-class"))
+      {
+         consumer.setEjbClass(getValue(localName, value));
+         consumer.setEjbName(getValue(localName, value));
+      }
+      else if (localName.equals("local"))
+      {
+         consumer.setLocal(getValue(localName, value));
+      }
+      else if (localName.equals("remote"))
+      {
+         consumer.setRemote(getValue(localName, value));
+      }
+      else if (localName.equals("jndi-name"))
+      {
+         consumer.setJndiName(getValue(localName, value));
+      }
+      else if (localName.equals("local-jndi-name"))
+      {
+         consumer.setLocalJndiName(getValue(localName, value));
+      }
+      else if (localName.equals("security-domain"))
+      {
+         consumer.setSecurityDomain(getValue(localName, value));
+      }
+      else if (localName.equals("run-as-principal"))
+      {
+         consumer.setRunAsPrincipal(getValue(localName, value));
+      }
+      else if (localName.equals("aop-domain-name"))
+      {
+         consumer.setAopDomainName(getValue(localName, value));
+      }
+      else if (localName.equals("depends"))
+      {
+         consumer.addDependency(getValue(localName, value));
+      }
+   }
+   
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(RemoteBinding binding, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("jndi-name"))
+      {
+         binding.setJndiName(getValue(localName, value));
+      }
+      else if (localName.equals("client-bind-url"))
+      {
+         binding.setClientBindUrl(getValue(localName, value));
+      }
+      else if (localName.equals("proxy-factory"))
+      {
+         binding.setProxyFactory(getValue(localName, value));
+      }
+      else if (localName.equals("interceptor-stack"))
+      {
+         binding.setInterceptorStack(getValue(localName, value));
+      }
+   }
+   
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(MessageProperties properties, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("delivery"))
+      {
+         properties.setDelivery(getValue(localName, value));
+      }
+      else if (localName.equals("class"))
+      {
+         properties.setClassName(getValue(localName, value));
+      }
+      else if (localName.equals("priority"))
+      {
+         properties.setPriority(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(ClusterConfig config, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("load-balance-policy"))
+      {
+         config.setLoadBalancePolicy(getValue(localName, value));
+      }
+      else if (localName.equals("partition-name"))
+      {
+         config.setPartition(getValue(localName, value));
+      }
+   }
+   
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(CacheConfig config, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("cache-class"))
+      {
+         config.setCacheClass(getValue(localName, value));
+      }
+      else if (localName.equals("cache-max-size"))
+      {
+         config.setMaxSize(getValue(localName, value));
+      }
+      else if (localName.equals("idle-timeout-seconds"))
+      {
+         config.setIdleTimeoutSeconds(getValue(localName, value));
+      }
+      else if (localName.equals("cache-name"))
+      {
+         config.setName(getValue(localName, value));
+      }
+      else if (localName.equals("persistence-manager"))
+      {
+         config.setPersistenceManager(getValue(localName, value));
+      }
+   }
+   
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(PoolConfig config, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("pool-class"))
+      {
+         config.setPoolClass(getValue(localName, value));
+      }
+      else if (localName.equals("pool-max-size"))
+      {
+         config.setMaxSize(getValue(localName, value));
+      }
+      else if (localName.equals("pool-timeout"))
+      {
+         config.setTimeout(getValue(localName, value));
+      }
+   }
+   
+   
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(Method method, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("method-name"))
+      {
+         method.setMethodName(getValue(localName, value));
+      }
+      else if (localName.equals("transaction-timeout"))
+      {
+         method.setTransactionTimeout(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(EjbJarDD dd, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("security-domain"))
+      {
+         dd.setSecurityDomain(getValue(localName, value));
+      }
+      else if (localName.equals("unauthenticated-principal"))
+      {
+         dd.setUnauthenticatedPrincipal(getValue(localName, value));
+      }
+   }
+   
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(Producer producer, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("class"))
+      {
+         producer.setClassName(getValue(localName, value));
+      }
+      else if (localName.equals("connection-factory"))
+      {
+         producer.setConnectionFactory(getValue(localName, value));
+      }
+   }
+   
+   protected String getValue(String name, String value)
+   {
+      if (value.startsWith("${") && value.endsWith("}"))
+      {
+         try
+         {
+            String propertyName = value.substring(2, value.length()-1);
+            ObjectName propertyServiceON = new ObjectName("jboss:type=Service,name=SystemProperties");
+            KernelAbstraction kernelAbstraction = KernelAbstractionFactory.getInstance();
+            String propertyValue = (String)kernelAbstraction.invoke(propertyServiceON, "get", new Object[]{propertyName}, new String[]{"java.lang.String"});
+            log.debug("Replaced jboss.xml element " + name + " with value " + propertyValue);
+            return propertyValue;
+         }
+         catch (Exception e)
+         {
+            log.warn("Unable to look up property service for jboss.xml element " + name + " with value " + value + ". Caused by " + e.getClass() + " " + e.getMessage());
+         }
+      }
+      
+      return value;
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDestination.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDestination.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDestination.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,71 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import org.jboss.logging.Logger;
+
+
+/**
+ * Represents a <message-destination> element of the jboss.xml deployment descriptor for the
+ * 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class MessageDestination
+{
+   private static final Logger log = Logger.getLogger(MessageDestination.class);
+   
+   private String messageDestinationName;
+   
+   private String jndiName;
+   
+   public String getJndiName()
+   {
+      return jndiName;
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+
+   public String getMessageDestinationName()
+   {
+      return messageDestinationName;
+   }
+
+   public void setMessageDestinationName(String messageDestinationName)
+   {
+      this.messageDestinationName = messageDestinationName;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[MessageDestination: ");
+      sb.append("messageDestinationName=").append(messageDestinationName);
+      sb.append(", jndiName=").append(jndiName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDrivenBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDrivenBean.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDrivenBean.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,224 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import javax.ejb.TransactionManagementType;
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a message-driven element of the ejb-jar.xml deployment descriptor for
+ * the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 46471 $</tt>
+ */
+public class MessageDrivenBean extends EnterpriseBean
+{
+   private static final Logger log = Logger.getLogger(MessageDrivenBean.class);
+
+   public static final String BEAN = "Bean";
+
+   public static final String CONTAINER = "Container";
+
+   // ejb-jar.xml
+   private String acknowledgeMode;
+
+   private String transactionType;
+   
+   private String messagingType;
+   
+   private String resourceAdaptorName;
+
+   private MessageDrivenDestination messageDrivenDestination;
+   
+   private ActivationConfig activationConfig;
+   private ActivationConfig defaultActivationConfig;
+   
+   private String destinationJndiName;
+   
+   private String mdbUser;
+   private String mdbPassword;
+   private String mdbSubscriptionId;
+
+   private Method aroundInvoke;
+   private Method postConstruct;
+   private Method postActivate;
+   private Method preDestroy;
+   private Method prePassivate;
+   
+   public ActivationConfig getDefaultActivationConfig()
+   {
+      return defaultActivationConfig;
+   }
+
+   public void setDefaultActivationConfig(ActivationConfig defaultActivationConfig)
+   {
+      this.defaultActivationConfig = defaultActivationConfig;
+   }
+   
+   public MessageDrivenDestination getMessageDrivenDestination()
+   {
+      return messageDrivenDestination;
+   }
+
+   public void setMessageDrivenDestination(MessageDrivenDestination messageDrivenDestination)
+   {
+      this.messageDrivenDestination = messageDrivenDestination;
+   }
+   
+   public ActivationConfig getActivationConfig()
+   {
+      return activationConfig;
+   }
+
+   public void setActivationConfig(ActivationConfig activationConfig)
+   {
+      this.activationConfig = activationConfig;
+   }
+   
+   public void setDestinationJndiName(String name)
+   {
+      destinationJndiName = name;
+   }
+   
+   public String getDestinationJndiName()
+   {
+      return destinationJndiName;
+   }
+
+   public String getAcknowledgeMode()
+   {
+      return acknowledgeMode;
+   }
+
+   public void setAcknowledgeMode(String acknowledgeMode)
+   {
+      this.acknowledgeMode = acknowledgeMode;
+   }
+   
+   public String getMessagingType()
+   {
+      return messagingType;
+   }
+
+   public void setMessagingType(String messagingType)
+   {
+      this.messagingType = messagingType;
+   }
+   
+   public String getResourceAdaptorName()
+   {
+      return resourceAdaptorName;
+   }
+
+   public void setResourceAdaptorName(String resourceAdaptorName)
+   {
+      this.resourceAdaptorName = resourceAdaptorName;
+   }
+
+   public String getTransactionType()
+   {
+      return transactionType;
+   }
+
+   public void setTransactionType(String transactionType)
+   {
+      if (transactionType.equals(BEAN))
+         tmType = TransactionManagementType.BEAN;
+      else if (transactionType.equals(CONTAINER))
+         tmType = TransactionManagementType.CONTAINER;
+      this.transactionType = transactionType;
+   }
+   
+   public String getMdbPassword()
+   {
+      return mdbPassword;
+   }
+
+   public void setMdbPassword(String mdbPassword)
+   {
+      this.mdbPassword = mdbPassword;
+   }
+
+   public String getMdbUser()
+   {
+      return mdbUser;
+   }
+
+   public void setMdbUser(String mdbUser)
+   {
+      this.mdbUser = mdbUser;
+   }
+   
+   public String getMdbSubscriptionId()
+   {
+      return mdbSubscriptionId;
+   }
+
+   public void setMdbSubscriptionId(String mdbSubscriptionId)
+   {
+      this.mdbSubscriptionId = mdbSubscriptionId;
+   }
+
+   public Method getAroundInvoke()
+   {
+      return aroundInvoke;
+   }
+
+   public void setAroundInvoke(Method aroundInvoke)
+   {
+      this.aroundInvoke = aroundInvoke;
+   }
+
+   public Method getPostConstruct()
+   {
+      return postConstruct;
+   }
+
+   public void setPostConstruct(Method postConstruct)
+   {
+      this.postConstruct = postConstruct;
+   }
+
+   public Method getPreDestroy()
+   {
+      return preDestroy;
+   }
+
+   public void setPreDestroy(Method preDestroy)
+   {
+      this.preDestroy = preDestroy;
+   }
+   
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[MessageDrivenBean:");
+      sb.append(super.toString());
+      sb.append(",");
+      sb.append("acknowledgeMode=").append(acknowledgeMode);
+      sb.append("destination=").append(messageDrivenDestination);
+      sb.append("messagingType=").append(messagingType);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDrivenDestination.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDrivenDestination.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageDrivenDestination.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,70 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a message-driven-destination element of the ejb-jar.xml deployment descriptor for
+ * the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class MessageDrivenDestination
+{
+   private static final Logger log = Logger.getLogger(MessageDrivenDestination.class);
+
+   // ejb-jar.xml
+   private String destinationType;
+
+   private String subscriptionDurability;
+
+   public String getDestinationType()
+   {
+      return destinationType;
+   }
+
+   public void setDestinationType(String destinationType)
+   {
+      this.destinationType = destinationType;
+   }
+
+   public String getSubscriptionDurability()
+   {
+      return subscriptionDurability;
+   }
+
+   public void setSubscriptionDurability(String subscriptionDurability)
+   {
+      this.subscriptionDurability = subscriptionDurability;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append('[');
+      sb.append("destinationType=").append(destinationType);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageProperties.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageProperties.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MessageProperties.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,90 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class MessageProperties
+{
+   private List methods = new ArrayList();
+   private String delivery;
+   private String priority;
+   private String className;
+
+   public List getMethods()
+   {
+      return methods;
+   }
+   
+   public void addMethod(Method method)
+   {
+      methods.add(method);
+   }
+   
+   public String getDelivery()
+   {
+      return delivery;
+   }
+   
+   public void setDelivery(String delivery)
+   {
+      this.delivery = delivery;
+   }
+   
+   public String getClassName()
+   {
+      return className;
+   }
+   
+   public void setClassName(String className)
+   {
+      this.className = className;
+   }
+   
+   public String getPriority()
+   {
+      return priority;
+   }
+   
+   public void setPriority(String priority)
+   {
+      this.priority = priority;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("className=").append(className);
+      sb.append(", priority=").append(priority);
+      sb.append(", delivery=").append(delivery);
+      sb.append(", methods=").append(methods);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Method.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Method.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Method.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,100 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents an <method> element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class Method
+{
+
+   private String ejbName = null;
+
+   private String methodName = null;
+   
+   private String transactionTimeout = null;
+
+   private List methodParams;
+
+   public String getTransactionTimeout()
+   {
+      return transactionTimeout;
+   }
+
+   public void setTransactionTimeout(String transactionTimeout)
+   {
+      this.transactionTimeout = transactionTimeout;
+   }
+   
+   public String getEjbName()
+   {
+      return ejbName;
+   }
+
+   public void setEjbName(String ejbName)
+   {
+      this.ejbName = ejbName;
+   }
+
+   public String getMethodName()
+   {
+      return methodName;
+   }
+
+   public void setMethodName(String methodName)
+   {
+      this.methodName = methodName;
+   }
+
+   public void setHasParameters()
+   {
+      methodParams = new ArrayList();
+   }
+   
+   public void addMethodParam(String methodParam)
+   {
+      methodParams.add(methodParam);
+   }
+
+   public List getMethodParams()
+   {
+      return methodParams;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbName=").append(ejbName);
+      sb.append(", methodName=").append(methodName);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MethodAttributes.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MethodAttributes.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MethodAttributes.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,59 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.logging.Logger;
+
+/**
+ * Represents an <method-attributes> element of the jboss.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class MethodAttributes
+{
+   private static final Logger log = Logger.getLogger(MethodAttributes.class);
+
+   private List<Method> methods = new ArrayList();
+
+   public List<Method> getMethods()
+   {
+      return methods;
+   }
+
+   public void addMethod(Method method)
+   {
+      methods.add(method);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("methods=").append(methods);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MethodPermission.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MethodPermission.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/MethodPermission.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,81 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.logging.Logger;
+
+/**
+ * Represents an <method-permission> element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class MethodPermission
+{
+   private static final Logger log = Logger.getLogger(MethodPermission.class);
+
+   private List roleNames = new ArrayList();
+   private boolean isUnchecked = false;
+   private List<Method> methods = new ArrayList();
+
+   public boolean isUnchecked()
+   {
+      return isUnchecked;
+   }
+
+   public void setUnchecked(boolean isUnchecked)
+   {
+      this.isUnchecked = isUnchecked;
+   }
+
+   public List getRoleNames()
+   {
+      return roleNames;
+   }
+
+   public void addRoleName(String roleName)
+   {
+      roleNames.add(roleName);
+   }
+
+   public List<Method> getMethods()
+   {
+      return methods;
+   }
+
+   public void addMethod(Method method)
+   {
+      methods.add(method);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("roleNames=").append(roleNames);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/PoolConfig.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/PoolConfig.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/PoolConfig.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,78 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+
+/**
+ * Represents an <pool-config> element of the jboss.xml deployment descriptor
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class PoolConfig
+{
+   private String poolClass = null;
+   private String maxSize = null;
+   private String timeout = null;
+   
+   public String getPoolClass()
+   {
+      return poolClass;
+   }
+
+   public void setPoolClass(String poolClass)
+   {
+      this.poolClass = poolClass;
+   }
+
+   public String getMaxSize()
+   {
+      return maxSize;
+   }
+
+   public void setMaxSize(String maxSize)
+   {
+      this.maxSize = maxSize;
+   }
+   
+   public String getTimeout()
+   {
+      return timeout;
+   }
+
+   public void setTimeout(String timeout)
+   {
+      this.timeout = timeout;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("poolClass=").append(poolClass);
+      sb.append(", maxSize=").append(maxSize);
+      sb.append(", timeout=").append(timeout);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Producer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Producer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Producer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,84 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a producer element of the jboss.xml deployment descriptor for
+ * the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class Producer
+{
+   private static final Logger log = Logger.getLogger(Producer.class);
+
+   // jboss.xml
+   private String className;
+   private String connectionFactory;
+   private boolean local = false;
+   
+   public Producer(boolean local)
+   {
+      this.local = local;
+   }
+   
+   public boolean isLocal()
+   {
+      return local;
+   }
+
+   public String getClassName()
+   {
+      return className;
+   }
+
+   public void setClassName(String className)
+   {
+      this.className = className;
+   }
+   
+   public String getConnectionFactory()
+   {
+      return connectionFactory;
+   }
+
+   public void setConnectionFactory(String connectionFactory)
+   {
+      this.connectionFactory = connectionFactory;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append('[');
+      sb.append("className=").append(className);
+      sb.append(", connectionFactory=").append(connectionFactory);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Query.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Query.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Query.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,66 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+/**
+ * Represents an query element of the ejb-jar.xml deployment descriptor for the
+ * 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class Query
+{
+
+   private String ejbQl;
+
+   private QueryMethod queryMethod;
+
+   public String getEjbQl()
+   {
+      return ejbQl;
+   }
+
+   public void setEjbQl(String ejbQl)
+   {
+      this.ejbQl = ejbQl;
+   }
+
+   public QueryMethod getQueryMethod()
+   {
+      return queryMethod;
+   }
+
+   public void setQueryMethod(QueryMethod queryMethod)
+   {
+      this.queryMethod = queryMethod;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbQl=").append(ejbQl);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/QueryMethod.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/QueryMethod.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/QueryMethod.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,73 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.List;
+
+/**
+ * Represents an query-method element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class QueryMethod
+{
+
+   private String methodName;
+
+   private List methodParams;
+
+   public String getMethodName()
+   {
+      return methodName;
+   }
+
+   public void setMethodName(String methodName)
+   {
+      this.methodName = methodName;
+   }
+
+   public List getMethodParams()
+   {
+      return methodParams;
+   }
+
+   public void setMethodParams(List methodParams)
+   {
+      this.methodParams = methodParams;
+   }
+
+   public void addMethodParam(String methodParam)
+   {
+      methodParams.add(methodParam);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("methodName=").append(methodName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RelationshipRoleSource.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RelationshipRoleSource.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RelationshipRoleSource.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,54 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+/**
+ * Represents an ejb-relationship-role element of the ejb-jar.xml deployment
+ * descriptor for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class RelationshipRoleSource
+{
+
+   private String ejbName;
+
+   public String getEjbName()
+   {
+      return ejbName;
+   }
+
+   public void setEjbName(String ejbName)
+   {
+      this.ejbName = ejbName;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbName=").append(ejbName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Relationships.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Relationships.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Relationships.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,62 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents <relationships> elements of the ejb-jar.xml deployment descriptor for the 1.4
+ * schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class Relationships
+{
+
+   private List ejbRelations = new ArrayList();
+
+   public List getEjbRelations()
+   {
+      return ejbRelations;
+   }
+
+   public void setEjbRelations(List ejbRelations)
+   {
+      this.ejbRelations = ejbRelations;
+   }
+
+   public void addEjbRelation(EjbRelation ejbRelation)
+   {
+      ejbRelations.add(ejbRelation);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbRelations=").append(ejbRelations);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoteBinding.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoteBinding.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoteBinding.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,92 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents an <remote-binding> element of the jboss.xml deployment descriptor
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class RemoteBinding
+{
+   private String jndiName = null;
+   private String proxyFactory = null;
+   private String clientBindUrl = null;
+   private String interceptorStack = null;
+
+   public String getJndiName()
+   {
+      return jndiName;
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+   
+   public String getProxyFactory()
+   {
+      return proxyFactory;
+   }
+
+   public void setProxyFactory(String proxyFactory)
+   {
+      this.proxyFactory = proxyFactory;
+   }
+
+   public String getClientBindUrl()
+   {
+      return clientBindUrl;
+   }
+
+   public void setClientBindUrl(String clientBindUrl)
+   {
+      this.clientBindUrl = clientBindUrl;
+   }
+
+   public String getInterceptorStack()
+   {
+      return interceptorStack;
+   }
+
+   public void setInterceptorStack(String interceptorStack)
+   {
+      this.interceptorStack = interceptorStack;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("jndiName=").append(jndiName);
+      sb.append(", proxyFactory=").append(proxyFactory);
+      sb.append(", interceptorStack=").append(interceptorStack);
+      sb.append(", clientBindUrl=").append(clientBindUrl);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoveList.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoveList.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoveList.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,59 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.logging.Logger;
+
+/**
+ * Represents an <remove-list> element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class RemoveList
+{
+   private static final Logger log = Logger.getLogger(RemoveList.class);
+
+   private List methods = new ArrayList();
+
+   public List getMethods()
+   {
+      return methods;
+   }
+
+   public void addMethod(Method method)
+   {
+      methods.add(method);
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("methods=").append(methods);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoveMethod.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoveMethod.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/RemoveMethod.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,66 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+/**
+ * Represents an <remove-list> element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class RemoveMethod
+{
+
+   private Method beanMethod;
+   private boolean retainIfException;
+
+   public Method getBeanMethod()
+   {
+      return beanMethod;
+   }
+
+   public void setBeanMethod(Method beanMethod)
+   {
+      this.beanMethod = beanMethod;
+   }
+
+   public boolean isRetainIfException()
+   {
+      return retainIfException;
+   }
+
+   public void setRetainIfException(boolean retainIfException)
+   {
+      this.retainIfException = retainIfException;
+   }
+
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("method=").append(beanMethod);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ResourceManager.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ResourceManager.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/ResourceManager.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+/**
+ * Represents a resource-manager element of the jboss.xml deployment descriptor for
+ * the 4.0 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class ResourceManager
+{
+   private String resourceName;
+   private String resourceJndiName;
+   
+   public String getResourceName()
+   {
+      return resourceName;
+   }
+   
+   public void setResourceName(String resourceName)
+   {
+      this.resourceName = resourceName;
+   }
+   
+   public String getResourceJndiName()
+   {
+      return resourceJndiName;
+   }
+   
+   public void setResourceJndiName(String resourceJndiName)
+   {
+      this.resourceJndiName = resourceJndiName;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/SecurityIdentity.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/SecurityIdentity.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/SecurityIdentity.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,92 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import org.jboss.metamodel.descriptor.RunAs;
+
+/**
+ * Represents a <security-identity> element of the ejb-jar.xml deployment descriptor for the
+ * 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45409 $</tt>
+ */
+public class SecurityIdentity
+{
+   private String id;
+
+   private boolean useCallerIdentity = false;
+
+   private RunAs runAs;
+
+   private String runAsPrincipal;
+
+   public String getId()
+   {
+      return id;
+   }
+
+   public void setId(String id)
+   {
+      this.id = id;
+   }
+
+   public boolean isUseCallerIdentity()
+   {
+      return useCallerIdentity;
+   }
+
+   public void setUseCallerIdentity(boolean useCallerIdentity)
+   {
+      this.useCallerIdentity = useCallerIdentity;
+   }
+
+   public RunAs getRunAs()
+   {
+      return runAs;
+   }
+
+   public void setRunAs(RunAs runAs)
+   {
+      this.runAs = runAs;
+   }
+
+   public String getRunAsPrincipal()
+   {
+      return runAsPrincipal;
+   }
+
+   public void setRunAsPrincipal(String runAsPrincipal)
+   {
+      this.runAsPrincipal = runAsPrincipal;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbName=").append(id);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Service.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Service.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/Service.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,67 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45242 $</tt>
+ */
+public class Service extends EnterpriseBean
+{
+   private static final Logger log = Logger.getLogger(Service.class);
+   
+   private String management = null;
+   private String objectName = null;
+   
+   public String getManagement()
+   {
+      return management;
+   }
+   
+   public void setManagement(String management)
+   {
+      this.management = management;
+   }
+   
+   public String getObjectName()
+   {
+      return objectName;
+   }
+   
+   public void setObjectName(String objectName)
+   {
+      this.objectName = objectName;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[Service:");
+      sb.append(super.toString());
+      sb.append(", management=" + management);
+      sb.append(", objectName=" + objectName);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/SessionEnterpriseBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/SessionEnterpriseBean.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/SessionEnterpriseBean.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,204 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.ejb3.metamodel;
+
+import java.util.List;
+import java.util.ArrayList;
+import org.jboss.logging.Logger;
+
+import org.jboss.metamodel.descriptor.PersistenceUnitRef;
+
+/**
+ * Represents a Session EJB element of the ejb-jar.xml deployment descriptor for
+ * the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45712 $</tt>
+ */
+public class SessionEnterpriseBean extends EnterpriseBean
+{
+   private static final Logger log = Logger
+           .getLogger(SessionEnterpriseBean.class);
+
+   public static final String STATELESS = "Stateless";
+
+   public static final String STATEFUL = "Stateful";
+
+   // ejb-jar.xml
+   private String sessionType = STATELESS;
+   private Method aroundInvoke;
+   private Method postConstruct;
+   private Method postActivate;
+   private Method preDestroy;
+   private Method prePassivate;
+   private List<RemoveMethod> removeMethods = new ArrayList<RemoveMethod>();
+   private List<InitMethod> initMethods = new ArrayList<InitMethod>();
+   
+   private String clustered = null;
+   private ClusterConfig clusterConfig = null;
+   private CacheConfig cacheConfig = null;
+   
+   private String concurrent = null;
+   
+   public CacheConfig getCacheConfig()
+   {
+      return cacheConfig;
+   }
+   
+   public void setCacheConfig(CacheConfig cacheConfig)
+   {
+      this.cacheConfig = cacheConfig;
+   }
+   
+   public String getConcurrent()
+   {
+      return concurrent;
+   }
+   
+   public void setConcurrent(String concurrent)
+   {
+      this.concurrent = concurrent;
+   }
+   
+   public String getClustered()
+   {
+      return clustered;
+   }
+   
+   public void setClustered(String clustered)
+   {
+      this.clustered = clustered;
+   }
+   
+   public ClusterConfig getClusterConfig()
+   {
+      return clusterConfig;
+   }
+   
+   public void setClusterConfig(ClusterConfig clusterConfig)
+   {
+      this.clusterConfig = clusterConfig;
+   }
+
+   public List<RemoveMethod> getRemoveMethods()
+   {
+      return removeMethods;
+   }
+   
+   public void addRemoveMethod(RemoveMethod method)
+   {
+      removeMethods.add(method);
+   }
+   
+   public List<InitMethod> getInitMethods()
+   {
+      return initMethods;
+   }
+   
+   public void addInitMethod(InitMethod method)
+   {
+      initMethods.add(method);
+   }
+
+   public boolean isStateless()
+   {
+      return sessionType.equals(STATELESS);
+   }
+
+   public boolean isStateful()
+   {
+      return sessionType.equals(STATEFUL);
+   }
+
+   public String getSessionType()
+   {
+      return sessionType;
+   }
+
+   public void setSessionType(String sessionType)
+   {
+      this.sessionType = sessionType;
+   }
+
+   public Method getAroundInvoke()
+   {
+      return aroundInvoke;
+   }
+
+   public void setAroundInvoke(Method aroundInvoke)
+   {
+      this.aroundInvoke = aroundInvoke;
+   }
+
+   public Method getPostActivate()
+   {
+      if (sessionType.equals(STATELESS)) return null;
+      return postActivate;
+   }
+
+   public void setPostActivate(Method postActivate)
+   {
+      this.postActivate = postActivate;
+   }
+
+   public Method getPostConstruct()
+   {
+      return postConstruct;
+   }
+
+   public void setPostConstruct(Method postConstruct)
+   {
+      this.postConstruct = postConstruct;
+   }
+
+   public Method getPreDestroy()
+   {
+      return preDestroy;
+   }
+
+   public void setPreDestroy(Method preDestroy)
+   {
+      this.preDestroy = preDestroy;
+   }
+
+   public Method getPrePassivate()
+   {
+      if (sessionType.equals(STATELESS)) return null;
+      return prePassivate;
+   }
+
+   public void setPrePassivate(Method prePassivate)
+   {
+      this.prePassivate = prePassivate;
+   }
+   
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append('[');
+      sb.append(super.toString());
+      sb.append(",");
+      sb.append("sessionType=").append(sessionType);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/XmlAnnotation.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/XmlAnnotation.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/metamodel/XmlAnnotation.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,93 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.jboss.metamodel.descriptor.InjectionTarget;
+import org.jboss.metamodel.descriptor.NameValuePair;
+
+
+/**
+ * Represents an <annotation> element of the jboss.xml deployment descriptor
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class XmlAnnotation
+{
+   private InjectionTarget injectionTarget = null;
+   private String annotationClass = null;
+   private String annotationImplementationClass = null;
+   private Collection<NameValuePair> properties = new HashSet<NameValuePair>();
+   
+   public Collection<NameValuePair> getProperties()
+   {
+      return properties;
+   }
+   
+   public void addProperty(NameValuePair property)
+   {
+      properties.add(property);
+   }
+
+   public String getAnnotationClass()
+   {
+      return annotationClass;
+   }
+
+   public void setAnnotationClass(String annotationClass)
+   {
+      this.annotationClass = annotationClass;
+   }
+   
+   public String getAnnotationImplementationClass()
+   {
+      return annotationImplementationClass;
+   }
+
+   public void setAnnotationImplementationClass(String annotationImplementationClass)
+   {
+      this.annotationImplementationClass = annotationImplementationClass;
+   }
+   
+   public InjectionTarget getInjectionTarget()
+   {
+      return injectionTarget;
+   }
+   
+   public void setInjectionTarget(InjectionTarget injectionTarget)
+   {
+      this.injectionTarget = injectionTarget;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("annotationClass=").append(annotationClass);
+      sb.append(", injectionTarget=").append(injectionTarget);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/BrainlessContext.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/BrainlessContext.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/BrainlessContext.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,183 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.naming;
+
+import javax.naming.*;
+import java.util.Hashtable;
+
+/**
+ * A naming context which can't do anything.
+ *
+ * @author carlo
+ */
+public class BrainlessContext implements Context
+{
+   public BrainlessContext()
+   {
+      super();
+   }
+
+   public Object lookup(Name name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public Object lookup(String name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void bind(Name name, Object obj) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void bind(String name, Object obj) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void rebind(Name name, Object obj) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void rebind(String name, Object obj) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void unbind(Name name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void unbind(String name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void rename(Name oldName, Name newName) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void rename(String oldName, String newName) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public NamingEnumeration<NameClassPair> list(String name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public NamingEnumeration<Binding> listBindings(String name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void destroySubcontext(Name name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void destroySubcontext(String name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public Context createSubcontext(Name name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public Context createSubcontext(String name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public Object lookupLink(Name name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public Object lookupLink(String name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public NameParser getNameParser(Name name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public NameParser getNameParser(String name) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public Name composeName(Name name, Name prefix) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public String composeName(String name, String prefix) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public Object addToEnvironment(String propName, Object propVal) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public Object removeFromEnvironment(String propName) throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public Hashtable<?, ?> getEnvironment() throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public void close() throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+
+   public String getNameInNamespace() throws NamingException
+   {
+      throw new OperationNotSupportedException();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/client/java/javaURLContextFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/client/java/javaURLContextFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/naming/client/java/javaURLContextFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.naming.client.java;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NameNotFoundException;
+import javax.naming.NameParser;
+import javax.naming.NamingException;
+import javax.naming.spi.ObjectFactory;
+
+import org.jboss.corba.ORBFactory;
+import org.jboss.ejb3.naming.BrainlessContext;
+import org.jboss.naming.client.java.HandleDelegateFactory;
+
+/**
+ * Creates objects for in the java:comp namespace.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class javaURLContextFactory implements ObjectFactory
+{
+
+   /* (non-Javadoc)
+    * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
+    */
+   public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
+         throws Exception
+   {
+      if(nameCtx == null)
+         nameCtx = new InitialContext(environment); 
+      final Context lookupCtx = nameCtx;
+      return new BrainlessContext() 
+      {
+         @Override
+         public Object lookup(Name name) throws NamingException
+         {
+            if (name.size() > 0 && "java:comp".equals(name.get(0)))
+            {
+               if (name.size() == 2 && "ORB".equals(name.get(1)))
+                  return ORBFactory.getORB();
+               else if (name.size() == 2 && "HandleDelegate".equals(name.get(1)))
+                  return HandleDelegateFactory.getHandleDelegateSingleton();
+            }
+            throw new NameNotFoundException(name.toString());
+         }
+         
+         @Override
+         public Object lookup(String name) throws NamingException
+         {
+            NameParser parser = lookupCtx.getNameParser("");
+            return lookup(parser.parse(name));
+         }
+      };
+   }
+
+}

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,17 +21,17 @@
   */
 package org.jboss.ejb3.remoting;
 
+import java.io.Serializable;
+import java.util.Map;
+
+import org.jboss.aop.Dispatcher;
 import org.jboss.aop.Advisor;
-import org.jboss.aop.Dispatcher;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.serial.io.MarshalledObjectForLocalCalls;
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.Ejb3Registry;
-import org.jboss.serial.io.MarshalledObjectForLocalCalls;
 
-import java.io.Serializable;
-import java.util.Map;
-
 /**
  * Comment
  *
@@ -42,7 +42,6 @@
 {
    public static final String IS_LOCAL = "IS_LOCAL";
    public static final String IS_LOCAL_EXCEPTION = "IS_LOCAL_EXCEPTION";
-
    public String getName()
    {
       return getClass().getName();
@@ -77,4 +76,5 @@
       }
       return invocation.invokeNext();
    }
+
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/Ejb3AuthenticationInterceptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/Ejb3AuthenticationInterceptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/Ejb3AuthenticationInterceptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -35,8 +35,10 @@
 import org.jboss.logging.Logger;
 
 import org.jboss.annotation.security.SecurityDomain;
+import org.jboss.aop.joinpoint.MethodInvocation;
 
 import org.jboss.aspects.security.AuthenticationInterceptor;
+import org.jboss.aspects.security.SecurityContext;
 import org.jboss.security.AuthenticationManager;
 import org.jboss.security.RealmMapping;
 import org.jboss.security.RunAsIdentity;
@@ -50,7 +52,7 @@
  * @version $Revision$
  */
 public class Ejb3AuthenticationInterceptor extends AuthenticationInterceptor
-{
+{ 
    private static final Logger log = Logger.getLogger(Ejb3AuthenticationInterceptor.class);
 
    private EJBContainer container;
@@ -68,5 +70,35 @@
       throw new EJBAccessException("Authentication failure", gse);
    }
 
+   public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable
+   {
+      MethodInvocation mi = (MethodInvocation)invocation;
+      SecurityDomain domain = (SecurityDomain)container.resolveAnnotation(SecurityDomain.class);
+      
+      if (domain != null && domain.unauthenticatedPrincipal() != null && domain.unauthenticatedPrincipal().length() != 0)
+      {
+         Principal principal = (Principal)invocation.getMetaData("security", "principal");
+         if (principal == null)
+            principal = SecurityAssociation.getPrincipal();
+           
+         if (principal == null)
+         {
+            invocation.getMetaData().addMetaData("security", "principal", new SimplePrincipal(domain.unauthenticatedPrincipal()));
+            
+            Object oldDomain = SecurityContext.getCurrentDomain().get();
+            
+            try
+            {
+               SecurityContext.getCurrentDomain().set(authenticationManager);
+               return invocation.invokeNext();
+            }
+            finally
+            {
+               SecurityContext.getCurrentDomain().set(oldDomain);
+            }
+         }
+      }
 
+      return super.invoke(invocation);
+   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,6 +21,7 @@
   */
 package org.jboss.ejb3.security;
 
+import java.lang.reflect.Method;
 import java.util.HashSet;
 import java.util.Set;
 import javax.annotation.security.DenyAll;
@@ -28,6 +29,9 @@
 import javax.annotation.security.RolesAllowed;
 import javax.ejb.EJBAccessException;
 import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.EJBContainer;
 import org.jboss.logging.Logger;
 import org.jboss.security.AnybodyPrincipal;
 import org.jboss.security.AuthenticationManager;
@@ -47,25 +51,29 @@
 {
    private static final Logger log = Logger.getLogger(RoleBasedAuthorizationInterceptor.class);
    
-   public RoleBasedAuthorizationInterceptor(AuthenticationManager manager, RealmMapping realmMapping)
+   private EJBContainer container;
+   
+   public RoleBasedAuthorizationInterceptor(AuthenticationManager manager, RealmMapping realmMapping, Container container)
    {
       super(manager, realmMapping);
+      this.container = (EJBContainer)container;
    }
 
    protected Set getRoleSet(Invocation invocation)
    {
-      HashSet set = new HashSet();
+      Method method = ((MethodInvocation)invocation).getActualMethod();
 
       Class[] classes = new Class[]{DenyAll.class, PermitAll.class, RolesAllowed.class};
 
-      Object annotation = invocation.resolveAnnotation(classes);
+      Object annotation = container.resolveAnnotation(method, classes);
       
       int classIndex = 0;
       while (annotation == null && classIndex < 3)
       {
-         annotation = invocation.resolveClassAnnotation(classes[classIndex++]);
+         annotation = container.resolveAnnotation(classes[classIndex++]);
       }
-      
+         
+      HashSet set = new HashSet();
       if (annotation != null)
       {
          if (annotation instanceof DenyAll)

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptorFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptorFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptorFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -41,9 +41,9 @@
    public Object createPerClass(Advisor advisor)
    {
       Object domain = null;
+      Container container = (Container)advisor;
       try
       {
-         Container container = (Container)advisor;
          InitialContext ctx = container.getInitialContext();
          org.jboss.annotation.security.SecurityDomain securityAnnotation = (org.jboss.annotation.security.SecurityDomain) advisor.resolveAnnotation(org.jboss.annotation.security.SecurityDomain.class);
          domain = ctx.lookup("java:/jaas/" + securityAnnotation.value());
@@ -55,7 +55,7 @@
       AuthenticationManager manager = (AuthenticationManager) domain;
       RealmMapping mapping = (RealmMapping) domain;
       if (manager == null) throw new RuntimeException("Unable to find Security Domain");
-      return new RoleBasedAuthorizationInterceptor(manager, mapping);
+      return new RoleBasedAuthorizationInterceptor(manager, mapping, container);
    }
 
    public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor)

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RunAsSecurityInterceptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RunAsSecurityInterceptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RunAsSecurityInterceptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -45,46 +45,22 @@
 public class RunAsSecurityInterceptor extends org.jboss.aspects.security.RunAsSecurityInterceptor
 {
    private static final Logger log = Logger.getLogger(RunAsSecurityInterceptor.class);
-   
-   public RunAsSecurityInterceptor(AuthenticationManager manager, RealmMapping realmMapping)
+   private RunAsIdentity runAsIdentity;
+
+   public RunAsSecurityInterceptor(AuthenticationManager manager, RealmMapping realmMapping, RunAsIdentity id)
    {
       super(manager, realmMapping);
+      this.runAsIdentity = id;
    }
-   
+
    protected RunAsIdentity getRunAsIdentity(Invocation invocation)
    {
-      RunAsIdentity runAsRole = null;
-      RunAs runAs = (RunAs) invocation.resolveClassAnnotation(RunAs.class);
-      if (runAs == null) return null;
-      Principal principal = SecurityAssociation.getPrincipal();
-      Set extraRoles = realmMapping.getUserRoles(principal);
-      if (extraRoles != null)
-      {
-         Iterator roles = extraRoles.iterator();
-         Set extraRoleNames = new HashSet();
-         while (roles.hasNext())
-         {
-            extraRoleNames.add( ((SimplePrincipal)roles.next()).getName());
-         }
-         if (principal == null)
-            runAsRole = new RunAsIdentity(runAs.value(), null, extraRoleNames);
-         else
-            runAsRole = new RunAsIdentity(runAs.value(), principal.getName(), extraRoleNames);
-      } else
-      {
-         runAsRole = new RunAsIdentity(runAs.value(), null);
-      }
-      
-      return runAsRole;
+      return runAsIdentity;
    }
-   
+
    public Object invoke(Invocation invocation) throws Throwable
    {
-      try 
-      {
-         return super.invoke(invocation);
-      } finally {
-      }
+      return super.invoke(invocation);
    }
 
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RunAsSecurityInterceptorFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RunAsSecurityInterceptorFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/security/RunAsSecurityInterceptorFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -23,30 +23,67 @@
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.annotation.security.RunAs;
+
 import org.jboss.aop.Advisor;
 import org.jboss.aop.InstanceAdvisor;
 import org.jboss.aop.advice.AspectFactory;
 import org.jboss.aop.joinpoint.Joinpoint;
+import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.logging.Logger;
 import org.jboss.security.AuthenticationManager;
 import org.jboss.security.RealmMapping;
+import org.jboss.security.RunAsIdentity;
+import org.jboss.security.SecurityAssociation;
 import org.jboss.ejb3.Container;
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.tx.NullInterceptor;
+import org.jboss.annotation.security.RunAsPrincipal;
 
+import java.security.Principal;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.HashSet;
+
 public class RunAsSecurityInterceptorFactory implements AspectFactory
 {
    private static final Logger log = Logger.getLogger(RunAsSecurityInterceptorFactory.class);
-   
+
    public Object createPerVM()
    {
       throw new RuntimeException("PER_VM not supported for this interceptor factory, only PER_CLASS");
    }
 
+
+   protected RunAsIdentity getRunAsIdentity(EJBContainer container)
+   {
+      RunAs runAs = (RunAs) container.resolveAnnotation(RunAs.class);
+      if (runAs == null) return null;
+      if (container.getXml() != null && container.getXml().getSecurityIdentity() != null)
+      {
+         if (container.getXml().getSecurityIdentity().isUseCallerIdentity()) return null;
+      }
+      RunAsPrincipal rap = (RunAsPrincipal) container.resolveAnnotation(RunAsPrincipal.class);
+      String runAsPrincipal = null;
+      if (rap != null) runAsPrincipal = rap.value();
+
+      HashSet extraRoles = new HashSet(); // todo get extra mapped roles.
+
+      return new RunAsIdentity(runAs.value(), runAsPrincipal, extraRoles);
+   }
+
+
    public Object createPerClass(Advisor advisor)
    {
       Object domain = null;
+      EJBContainer container = (EJBContainer)advisor;
+      RunAsIdentity runAsIdentity = getRunAsIdentity(container);
+      if (runAsIdentity == null)
+      {
+         return new NullInterceptor();
+      }
       try
       {
-         Container container = (Container)advisor;
          InitialContext ctx = container.getInitialContext();
          org.jboss.annotation.security.SecurityDomain securityAnnotation = (org.jboss.annotation.security.SecurityDomain) advisor.resolveAnnotation(org.jboss.annotation.security.SecurityDomain.class);
          domain = ctx.lookup("java:/jaas/" + securityAnnotation.value());
@@ -58,7 +95,7 @@
       AuthenticationManager manager = (AuthenticationManager) domain;
       RealmMapping mapping = (RealmMapping) domain;
       if (manager == null) throw new RuntimeException("Unable to find Security Domain");
-      return new RunAsSecurityInterceptor(manager, mapping);
+      return new RunAsSecurityInterceptor(manager, mapping, getRunAsIdentity(container));
    }
 
    public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor)

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/BaseServiceProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -45,6 +45,18 @@
    protected Container container;
    protected Advisor advisor;
 
+   public Object createHomeProxy()
+   {
+      throw new UnsupportedOperationException("service can't have a home interface");
+   }
+   
+   public Object createProxy(Object id)
+   {
+      if(id != null)
+         throw new IllegalArgumentException("service proxy must not have an id");
+      return createProxy();
+   }
+   
    public void start() throws Exception
    {
       initializeJndiName();
@@ -56,7 +68,7 @@
 
       try
       {
-         Util.bind(container.getInitialContext(), jndiName, createProxy());
+         Util.rebind(container.getInitialContext(), jndiName, createProxy());
       } catch (NamingException e)
       {
          NamingException namingException = new NamingException("Could not bind service proxy factory for EJB container with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName);

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -18,11 +18,15 @@
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/ 
+*/
 package org.jboss.ejb3.service;
 
 import java.lang.reflect.Method;
 import java.util.Hashtable;
+
+import javax.ejb.EJBException;
+import javax.ejb.Handle;
+import javax.ejb.Timer;
 import javax.ejb.TimerService;
 import javax.management.Attribute;
 import javax.management.AttributeList;
@@ -33,33 +37,38 @@
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.ReflectionException;
+
 import org.jboss.annotation.ejb.Management;
 import org.jboss.annotation.ejb.Service;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.MethodInfo;
 import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.annotation.AnnotationRepository;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.aop.util.MethodHashing;
 import org.jboss.aop.util.PayloadKey;
 import org.jboss.aspects.asynch.FutureHolder;
+import org.jboss.ejb.AllowedOperationsAssociation;
+import org.jboss.ejb.AllowedOperationsFlags;
 import org.jboss.ejb3.BeanContext;
 import org.jboss.ejb3.EJBContainerInvocation;
 import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.ProxyFactory;
 import org.jboss.ejb3.SessionContainer;
 import org.jboss.ejb3.ThreadLocalENCFactory;
 import org.jboss.ejb3.asynchronous.AsynchronousInterceptor;
-import org.jboss.ejb3.injection.Injector;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.ejb3.timerservice.TimerServiceFactory;
 import org.jboss.logging.Logger;
+import org.jboss.injection.Injector;
 
 /**
  * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
  * @version $Revision$
  */
-public class ServiceContainer extends SessionContainer
+public class ServiceContainer extends SessionContainer implements TimedObjectInvoker
 {
    ServiceMBeanDelegate delegate;
    Object singleton;
@@ -67,6 +76,7 @@
    BeanContext beanContext;
    MBeanServer mbeanServer;
    ObjectName delegateObjectName;
+   private TimerService timerService;
 
    private static final Logger log = Logger.getLogger(ServiceContainer.class);
 
@@ -78,17 +88,41 @@
       beanContextClass = ServiceBeanContext.class;
       this.mbeanServer = server;
    }
-   
-   public void setMbeanServer(MBeanServer server)
+
+   public void callTimeout(Timer timer) throws Exception
    {
-      this.mbeanServer = server;
+      Method timeout = callbackHandler.getTimeoutCallback();
+      if (timeout == null) throw new EJBException("No method has been annotated with @Timeout");
+      Object[] args = {timer};
+      AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsFlags.IN_EJB_TIMEOUT);
+      try
+      {
+         localInvoke(timeout, args);
+      }
+      catch(Throwable throwable)
+      {
+         if (throwable instanceof Exception) throw (Exception) throwable;
+         if(throwable instanceof Error) throw (Error) throwable;
+         throw new RuntimeException(throwable);
+      }
+      finally
+      {
+         AllowedOperationsAssociation.popInMethodFlag();
+      }
    }
 
+   protected Object createSession(Class initTypes[], Object initArgs[])
+   {
+//      if((initTypes != null && initTypes.length > 0) || (initArgs != null && initArgs.length > 0))
+//         throw new IllegalArgumentException("service bean create method must take no arguments");
+      throw new RuntimeException("NYI");
+   }
+
    public Object getSingleton()
    {
       return singleton;
    }
-   
+
    public void create() throws Exception
    {
       super.create();
@@ -98,28 +132,33 @@
    public void start() throws Exception
    {
       super.start();
-      
+
       try
-      {              
-         singleton = super.construct(); 
-                         
-         resolveInterceptorInjectors();
-         
+      {
+         singleton = super.construct();
+
          initBeanContext();
-         
+
+         // make sure the timer service is there before injection takes place
+         timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
+
          injectDependencies(beanContext);
+
+         registerManagementInterface();
          
-         registerManagementInterface();    
+         TimerServiceFactory.getInstance().restoreTimerService(timerService);
       }
       catch (Exception e)
       {
          e.printStackTrace();
          stop();
-      }     
+      }
    }
 
    public void stop() throws Exception
    {
+      if (timerService != null) TimerServiceFactory.getInstance().removeTimerService(timerService);
+
       super.stop();
 
       if (delegate != null)
@@ -128,7 +167,7 @@
       }
       injected = false;
    }
-   
+
    public void destroy() throws Exception
    {
       super.destroy();
@@ -141,9 +180,15 @@
 
    public TimerService getTimerService()
    {
-      throw new RuntimeException("TimerService not implemented for container");
+      return timerService;
    }
 
+   public TimerService getTimerService(Object pKey)
+   {
+      assert timerService != null : "Timer Service not yet initialized";
+      return timerService;
+   }
+   
    public void invokePostConstruct(BeanContext beanContext)
    {
       //Ignore
@@ -184,7 +229,7 @@
          {
             throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
          }
-         Interceptor[] aspects = info.interceptors;
+         Interceptor[] aspects = info.getInterceptors();
          EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects);
          nextInvocation.setAdvisor(this);
          nextInvocation.setArguments(args);
@@ -217,7 +262,7 @@
          {
             throw new RuntimeException("Could not resolve beanClass method from proxy call");
          }
-         Interceptor[] aspects = info.interceptors;
+         Interceptor[] aspects = info.getInterceptors();
          newSi = new EJBContainerInvocation(info, aspects);
          newSi.setArguments(si.getArguments());
          newSi.setMetaData(si.getMetaData());
@@ -243,7 +288,7 @@
          Thread.currentThread().setContextClassLoader(oldLoader);
       }
    }
-   
+
    protected void initBeanContext() throws RuntimeException
    {
       if (beanContext == null)
@@ -272,6 +317,7 @@
       }
    }
 
+   @Override
    protected EJBContainerInvocation populateInvocation(EJBContainerInvocation invocation)
    {
       invocation.setTargetObject(singleton);
@@ -286,11 +332,11 @@
          try
          {
             ThreadLocalENCFactory.push(enc);
-         for (int i = 0; i < injectors.length; i++)
-         {
-            injectors[i].inject(ctx);
+            for (Injector injector : injectors)
+            {
+               injector.inject(ctx);
+            }
          }
-         }
          finally
          {
             ThreadLocalENCFactory.pop();
@@ -329,6 +375,11 @@
       return delegate.invoke(actionName, params, signature);
    }
 
+   @Override
+   protected Object invokeEJBObjectMethod(ProxyFactory factory, Object id, MethodInfo info, Object[] args) throws Exception
+   {
+      throw new RuntimeException("NYI");
+   }
 
    public MBeanInfo getMBeanInfo()
    {
@@ -362,8 +413,11 @@
          if (intf != null)
          {
             if (mbeanServer == null)
+               mbeanServer = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
+
+            if (mbeanServer == null)
                throw new RuntimeException("There is a @Management interface on " + ejbName + " but the MBeanServer has not been initialized for it");
-            
+
             Service service = (Service)resolveAnnotation(Service.class);
 
             String objname = service.objectName();
@@ -371,11 +425,11 @@
                             new ObjectName(getObjectName().getCanonicalName() + ",type=ManagementInterface") : new ObjectName(service.objectName());
 
             delegate = new ServiceMBeanDelegate(mbeanServer, this, intf, delegateObjectName);
-            
+
             Object securityDomainAnnotation = resolveAnnotation(org.jboss.annotation.security.SecurityDomain.class);
-                    
+
             getDeployment().getKernelAbstraction().installMBean(delegateObjectName, getDependencyPolicy(), delegate);
-          
+
          }
       }
       catch (Exception e)
@@ -384,4 +438,8 @@
       }
    }
 
+   protected void removeHandle(Handle handle)
+   {
+      throw new RuntimeException("Don't do this");
+   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/service/ServiceRemoteProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -62,7 +62,7 @@
 
    public void start() throws Exception
    {
-      String clientBindUrl = binding.clientBindUrl();
+      String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
       super.start();
    }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/session/BaseSessionProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -48,6 +48,11 @@
    protected Container container;
    protected Advisor advisor;
   
+   public Object createHomeProxy()
+   {
+      throw new RuntimeException("NYI");
+   }
+   
    public void setContainer(Container container)
    {
       this.container = container;

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/BaseStatefulProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -73,7 +73,7 @@
       Reference ref = new Reference("java.lang.Object", refAddr, JndiProxyFactory.class.getName(), null);
       try 
       {
-         Util.bind(ctx, atom, ref);
+         Util.rebind(ctx, atom, ref);
       } catch (NamingException e)
       {
          NamingException namingException = new NamingException("Could not bind stateful proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + ctx.getNameInNamespace() + "/" + atom);

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -272,9 +272,6 @@
       {
          throw new RuntimeException(e);
       }
-
-      // Finally, remove myself
-      ((StatefulContainer)getContainer()).getCache().remove(id);
    }
 
    private void closeExtendedPCs()

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -82,7 +82,7 @@
 
    public void start() throws Exception
    {
-      String clientBindUrl = binding.clientBindUrl();
+      String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
       Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
       if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation.  Cannot deploy.");
@@ -103,10 +103,10 @@
       wrapper = new FamilyWrapper(proxyFamilyName, hatarget.getReplicants());
       super.start();
       Class[] interfaces = {ProxyFactory.class};
-      Object factoryProxy = Remoting.createPojiProxy(jndiName + PROXY_FACTORY_NAME, interfaces, binding.clientBindUrl());
+      Object factoryProxy = Remoting.createPojiProxy(jndiName + PROXY_FACTORY_NAME, interfaces, ProxyFactoryHelper.getClientBindUrl(binding));
       try
       {
-         Util.bind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
+         Util.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
       } catch (NamingException e)
       {
          NamingException namingException = new NamingException("Could not bind stateful cluster proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName + PROXY_FACTORY_NAME);
@@ -149,6 +149,11 @@
       }
    }
 
+   public Object createProxy(Object id)
+   {
+      throw new RuntimeException("NYI");
+   }
+   
    public void stop() throws Exception
    {
       super.stop();

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -32,8 +32,17 @@
 import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aop.util.MethodHashing;
 import org.jboss.aspects.asynch.FutureHolder;
-import org.jboss.ejb3.*;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.EJBContainerInvocation;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.ProxyFactory;
+import org.jboss.ejb3.ProxyFactoryHelper;
+import org.jboss.ejb3.ProxyUtils;
+import org.jboss.ejb3.SessionContainer;
+import org.jboss.ejb3.ThreadLocalENCFactory;
 import org.jboss.ejb3.cache.StatefulCache;
+import org.jboss.injection.Injector;
+import org.jboss.injection.JndiFieldInjector;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
 import org.jboss.ejb3.proxy.EJBMetaDataImpl;
 import org.jboss.ejb3.proxy.handle.HomeHandleImpl;
@@ -41,7 +50,16 @@
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
-import javax.ejb.*;
+import javax.ejb.EJBHome;
+import javax.ejb.EJBObject;
+import javax.ejb.Handle;
+import javax.ejb.Init;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remote;
+import javax.ejb.RemoteHome;
+import javax.ejb.TimerService;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.Hashtable;
 import java.util.Map;
@@ -160,24 +178,34 @@
                             + method.toString());
          }
 
-         if (info.unadvisedMethod != null && isHomeMethod(info.unadvisedMethod))
+         Method unadvisedMethod = info.getUnadvisedMethod();
+
+         if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
          {
             return invokeLocalHomeMethod(info, args);
          }
-         else if (info.unadvisedMethod != null
-                 && isEJBObjectMethod(info.unadvisedMethod))
+         else if (unadvisedMethod != null
+                 && isEJBObjectMethod(unadvisedMethod))
          {
             return invokeEJBLocalObjectMethod(id, info, args);
          }
 
-         Interceptor[] aspects = info.interceptors;
+         Interceptor[] aspects = info.getInterceptors();
          StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(
                  info, aspects, id);
          nextInvocation.setAdvisor(this);
          nextInvocation.setArguments(args);
 
          ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
-         return nextInvocation.invokeNext();
+         try
+         {
+            invokedMethod.push(new InvokedMethod(true, method));
+            return nextInvocation.invokeNext();
+         }
+         finally
+         {
+            invokedMethod.pop();
+         }
       }
       finally
       {
@@ -228,6 +256,11 @@
       }
    }
 
+   protected void destroySession(Object id)
+   {
+      getCache().remove(id);
+   }
+
    /**
     * This should be a remote invocation call
     *
@@ -251,17 +284,18 @@
          }
 
          InvocationResponse response = null;
-         if (info != null && info.unadvisedMethod != null && isHomeMethod(info.unadvisedMethod))
+         Method unadvisedMethod = info.getUnadvisedMethod();
+         if (info != null && unadvisedMethod != null && isHomeMethod(unadvisedMethod))
          {
             response = invokeHomeMethod(info, si);
          }
-         else if (info != null && info.unadvisedMethod != null && isEJBObjectMethod(info.unadvisedMethod))
+         else if (info != null && unadvisedMethod != null && isEJBObjectMethod(unadvisedMethod))
          {
             response = invokeEJBObjectMethod(info, si);
          }
          else
          {
-            Interceptor[] aspects = info.interceptors;
+            Interceptor[] aspects = info.getInterceptors();
             Object newId = null;
 
             if (si.getId() == null)
@@ -281,6 +315,7 @@
             Object rtn = null;
             try
             {
+               invokedMethod.push(new InvokedMethod(false, unadvisedMethod));
                rtn = newSi.invokeNext();
             }
             catch (Throwable throwable)
@@ -294,6 +329,10 @@
                response = marshallException(invocation, exception, responseContext);
                return response;
             }
+            finally
+            {
+               invokedMethod.pop();
+            }
 
             response = marshallResponse(invocation, rtn, newSi.getResponseContextInfo());
             if (newId != null) response.addAttachment(StatefulConstants.NEW_ID, newId);
@@ -311,13 +350,29 @@
 
    public TimerService getTimerService()
    {
-      throw new RuntimeException(
-              "Illegal operation.  StrictlyPooledSessionBean beans can't access TimerService");
+      throw new UnsupportedOperationException("stateful bean doesn't support TimerService (EJB3 18.2#2)");
    }
 
+   public TimerService getTimerService(Object pKey)
+   {
+      return getTimerService();
+   }
+   
    @Override
    public void invokePostActivate(BeanContext beanContext)
    {
+      for (Injector injector : injectors)
+      {
+         if (injector instanceof JndiFieldInjector)
+         {
+            Field field = ((JndiFieldInjector) injector).getField();
+            if (field.isAnnotationPresent(javax.ejb.EJB.class))
+            {
+               continue; // skip nested EJB injection since the local proxy will be (de)serialized correctly
+            }
+            injector.inject(beanContext);
+         }
+      }
       callbackHandler.postActivate(beanContext);
    }
 
@@ -475,27 +530,24 @@
    private Object invokeEJBLocalObjectMethod(Object id, MethodInfo info,
                                              Object[] args) throws Exception
    {
-      if (info.unadvisedMethod.getName().equals("remove"))
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if (unadvisedMethod.getName().equals("remove"))
       {
-         BeanContext ctx = getCache().get(id);
+         destroySession(id);
 
-         invokePreDestroy(ctx);
-
-         getCache().remove(id);
-
          return null;
       }
-      else if (info.unadvisedMethod.getName().equals("getEJBLocalHome"))
+      else if (unadvisedMethod.getName().equals("getEJBLocalHome"))
       {
          Object bean = getCache().get(id).getInstance();
 
          return bean;
       }
-      else if (info.unadvisedMethod.getName().equals("getPrimaryKey"))
+      else if (unadvisedMethod.getName().equals("getPrimaryKey"))
       {
          return id;
       }
-      else if (info.unadvisedMethod.getName().equals("isIdentical"))
+      else if (unadvisedMethod.getName().equals("isIdentical"))
       {
          EJBObject bean = (EJBObject) args[0];
 
@@ -514,15 +566,16 @@
    private Object invokeLocalHomeMethod(MethodInfo info, Object[] args)
            throws Exception
    {
-      if (info.unadvisedMethod.getName().equals("create"))
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if (unadvisedMethod.getName().equals("create"))
       {
          Class[] initParameterTypes =
                  {};
          Object[] initParameterValues =
                  {};
-         if (info.unadvisedMethod.getParameterTypes().length > 0)
+         if (unadvisedMethod.getParameterTypes().length > 0)
          {
-            initParameterTypes = info.unadvisedMethod.getParameterTypes();
+            initParameterTypes = unadvisedMethod.getParameterTypes();
             initParameterValues = args;
          }
 
@@ -538,16 +591,12 @@
 
          return proxy;
       }
-      else if (info.unadvisedMethod.getName().equals("remove"))
+      else if (unadvisedMethod.getName().equals("remove"))
       {
          StatefulHandleImpl handle = (StatefulHandleImpl) args[0];
 
-         BeanContext ctx = getCache().get(handle.id);
+         destroySession(handle.id);
 
-         invokePreDestroy(ctx);
-
-         getCache().remove(handle.id);
-
          return null;
       }
       else
@@ -559,15 +608,16 @@
    protected InvocationResponse invokeHomeMethod(MethodInfo info,
                                                  StatefulRemoteInvocation statefulInvocation) throws Throwable
    {
-      if (info.unadvisedMethod.getName().equals("create"))
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if (unadvisedMethod.getName().equals("create"))
       {
          Class[] initParameterTypes =
                  {};
          Object[] initParameterValues =
                  {};
-         if (info.unadvisedMethod.getParameterTypes().length > 0)
+         if (unadvisedMethod.getParameterTypes().length > 0)
          {
-            initParameterTypes = info.unadvisedMethod.getParameterTypes();
+            initParameterTypes = unadvisedMethod.getParameterTypes();
             initParameterValues = statefulInvocation.getArguments();
          }
 
@@ -599,22 +649,18 @@
                     newStatefulInvocation.getId());
          return response;
       }
-      else if (info.unadvisedMethod.getName().equals("remove"))
+      else if (unadvisedMethod.getName().equals("remove"))
       {
          StatefulHandleImpl handle = (StatefulHandleImpl) statefulInvocation
                  .getArguments()[0];
 
-         BeanContext ctx = getCache().get(handle.id);
+         destroySession(handle.id);
 
-         invokePreDestroy(ctx);
-
-         getCache().remove(handle.id);
-
          InvocationResponse response = new InvocationResponse(null);
          response.setContextInfo(statefulInvocation.getResponseContextInfo());
          return response;
       }
-      else if (info.unadvisedMethod.getName().equals("getEJBMetaData"))
+      else if (unadvisedMethod.getName().equals("getEJBMetaData"))
       {
          Class remote = null;
          Class home = null;
@@ -638,7 +684,7 @@
          InvocationResponse response = marshallResponse(statefulInvocation, metadata, null);
          return response;
       }
-      else if (info.unadvisedMethod.getName().equals("getHomeHandle"))
+      else if (unadvisedMethod.getName().equals("getHomeHandle"))
       {
          HomeHandleImpl homeHandle = null;
 
@@ -660,7 +706,8 @@
    protected InvocationResponse invokeEJBObjectMethod(MethodInfo info,
                                                       StatefulRemoteInvocation statefulInvocation) throws Throwable
    {
-      if (info.unadvisedMethod.getName().equals("getHandle"))
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if (unadvisedMethod.getName().equals("getHandle"))
       {
          StatefulContainerInvocation newStatefulInvocation = buildInvocation(
                  info, statefulInvocation);
@@ -673,18 +720,14 @@
          InvocationResponse response = marshallResponse(statefulInvocation, handle, null);
          return response;
       }
-      else if (info.unadvisedMethod.getName().equals("remove"))
+      else if (unadvisedMethod.getName().equals("remove"))
       {
-         BeanContext ctx = getCache().get(statefulInvocation.getId());
+         destroySession(statefulInvocation.getId());
 
-         invokePreDestroy(ctx);
-
-         getCache().remove(statefulInvocation.getId());
-
          InvocationResponse response = new InvocationResponse(null);
          return response;
       }
-      else if (info.unadvisedMethod.getName().equals("getEJBHome"))
+      else if (unadvisedMethod.getName().equals("getEJBHome"))
       {
          HomeHandleImpl homeHandle = null;
 
@@ -698,14 +741,14 @@
          InvocationResponse response = marshallResponse(statefulInvocation, ejbHome, null);
          return response;
       }
-      else if (info.unadvisedMethod.getName().equals("getPrimaryKey"))
+      else if (unadvisedMethod.getName().equals("getPrimaryKey"))
       {
          Object id = statefulInvocation.getId();
 
          InvocationResponse response = marshallResponse(statefulInvocation, id, null);
          return response;
       }
-      else if (info.unadvisedMethod.getName().equals("isIdentical"))
+      else if (unadvisedMethod.getName().equals("isIdentical"))
       {
          Object id = statefulInvocation.getId();
          EJBObject bean = (EJBObject) statefulInvocation.getArguments()[0];
@@ -728,7 +771,7 @@
                                                           Class[] initParameterTypes, Object[] initParameterValues)
    {
       StatefulContainerInvocation newStatefulInvocation = null;
-      Interceptor[] aspects = info.interceptors;
+      Interceptor[] aspects = info.getInterceptors();
       Object newId = null;
 
       StatefulBeanContext ctx = null;
@@ -752,7 +795,7 @@
                                                        StatefulRemoteInvocation statefulInvocation)
    {
       StatefulContainerInvocation newStatefulInvocation = null;
-      Interceptor[] aspects = info.interceptors;
+      Interceptor[] aspects = info.getInterceptors();
       Object newId = null;
       if (statefulInvocation.getId() == null)
       {
@@ -773,4 +816,66 @@
 
       return newStatefulInvocation;
    }
+
+   @Override
+   public Object getBusinessObject(BeanContext beanContext, Class businessInterface) throws IllegalStateException
+   {
+      StatefulBeanContext ctx = (StatefulBeanContext) beanContext;
+
+      boolean isRemote = false;
+      boolean found = false;
+      Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(this);
+      if (remoteInterfaces != null)
+      {
+         for (Class intf : remoteInterfaces)
+         {
+            if (intf.getName().equals(businessInterface.getName()))
+            {
+               isRemote = true;
+               found = true;
+               break;
+            }
+         }
+      }
+      if (found == false)
+      {
+         Class[] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(this);
+         if (localInterfaces != null)
+         {
+            for (Class intf : remoteInterfaces)
+            {
+               if (intf.getName().equals(businessInterface.getName()))
+               {
+                  found = true;
+                  break;
+               }
+            }
+
+         }
+      }
+      if (found == false) throw new IllegalStateException(businessInterface.getName() + " is not a business interface");
+
+      for (ProxyFactory factory : proxyDeployer.getProxyFactories())
+      {
+         if (isRemote && factory instanceof StatefulRemoteProxyFactory)
+         {
+            return ((StatefulRemoteProxyFactory) factory).createProxy(ctx.getId());
+         }
+         else if (!isRemote && factory instanceof StatefulLocalProxyFactory)
+         {
+            return ((StatefulLocalProxyFactory) factory).createProxy(ctx.getId());
+         }
+      }
+      throw new IllegalStateException("Unable to create proxy for getBusinessObject as a proxy factory was not found");
+   }
+
+   protected void removeHandle(Handle arg) throws Exception
+   {
+      /*
+      StatefulHandleImpl handle = (StatefulHandleImpl) arg;
+
+      destroySession(handle.id);
+      */
+      arg.getEJBObject().remove();
+   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -22,13 +22,15 @@
 package org.jboss.ejb3.stateful;
 
 import java.util.Iterator;
+import java.util.List;
 
 import java.rmi.RemoteException;
+
+import javax.ejb.ConcurrentAccessException;
 import javax.ejb.EJBException;
 import javax.ejb.ApplicationException;
 import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.dd.ApplicationExceptionList;
-import org.jboss.ejb3.dd.AssemblyDescriptor;
+import org.jboss.ejb3.metamodel.AssemblyDescriptor;
 import org.jboss.annotation.ejb.SerializedConcurrentAccess;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
@@ -68,7 +70,7 @@
       {
          synchronized (target)
          {
-            if (target.isInInvocation()) throw new EJBException("Application Error: no concurrent calls on stateful beans");
+            if (target.isInInvocation()) throw new ConcurrentAccessException("no concurrent calls on stateful bean '" + container.getName() + "' (EJB3 4.3.13)");
             target.setInInvocation(true);
          }
       }
@@ -103,7 +105,7 @@
       }
    }
    
-   public static boolean isApplicationException(Class exceptionClass, EJBContainer container)
+   public static boolean isApplicationException(Class<?> exceptionClass, EJBContainer container)
    {
       if (exceptionClass.isAnnotationPresent(ApplicationException.class))
          return true;
@@ -111,14 +113,14 @@
       AssemblyDescriptor assembly = container.getAssemblyDescriptor();
       if (assembly != null)
       {
-         ApplicationExceptionList exceptionList = assembly.getApplicationExceptionList();
-         if (exceptionList != null)
+         List exceptions = assembly.getApplicationExceptions();
+         if (exceptions.size() > 0)
          {
-            Iterator exceptionClasses = exceptionList.getClassList().iterator();
-            while (exceptionClasses.hasNext())
+            Iterator exceptionIterator = exceptions.iterator();
+            while (exceptionIterator.hasNext())
             {
-               String className = (String)exceptionClasses.next();
-               if (className.equals(exceptionClass.getName()))
+               org.jboss.ejb3.metamodel.ApplicationException exception = (org.jboss.ejb3.metamodel.ApplicationException)exceptionIterator.next();
+               if (exception.getExceptionClass().equals(exceptionClass.getName()))
                   return true;
             }
          }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -62,7 +62,7 @@
 
       try
       {
-         NonSerializableFactory.bind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, this);
+         NonSerializableFactory.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, this);
       }
       catch (NamingException e)
       {
@@ -77,7 +77,7 @@
          Class[] interfaces = {localHome.value()};
          Object homeProxy = java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(),
                                                                      interfaces, new StatefulLocalHomeProxy(container));
-         NonSerializableFactory.bind(container.getInitialContext(), jndiName + "Home", homeProxy);
+         NonSerializableFactory.rebind(container.getInitialContext(), jndiName + "Home", homeProxy);
       }
    }
 
@@ -119,6 +119,31 @@
       }
    }
 
+   public Object createProxy(Object id)
+   {
+      try
+      {
+         StatefulContainer sfsb = (StatefulContainer) container;
+         Object[] args = {new StatefulLocalProxy(container, id)};
+         return proxyConstructor.newInstance(args);
+      }
+      catch (InstantiationException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RuntimeException(e.getTargetException());  //To change body of catch statement use Options | File Templates.
+      }
+   }
    public Object createProxy(Class[] initTypes, Object[] initValues)
    {
       try

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -77,7 +77,7 @@
    public void init() throws Exception
    {
       super.init();
-      String clientBindUrl = binding.clientBindUrl();
+      String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
    }
 
@@ -87,10 +87,10 @@
 
       super.start();
       Class[] interfaces = {ProxyFactory.class};
-      Object factoryProxy = Remoting.createPojiProxy(jndiName + PROXY_FACTORY_NAME, interfaces, binding.clientBindUrl());
+      Object factoryProxy = Remoting.createPojiProxy(jndiName + PROXY_FACTORY_NAME, interfaces, ProxyFactoryHelper.getClientBindUrl(binding));
       try
       {
-         Util.bind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
+         Util.rebind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME, factoryProxy);
       }
       catch (NamingException e)
       {
@@ -105,7 +105,7 @@
       if (remoteHome != null)
       {
          Object homeProxy = createHomeProxy(remoteHome.value());
-         Util.bind(container.getInitialContext(), jndiName + "Home", homeProxy);
+         Util.rebind(container.getInitialContext(), jndiName + "Home", homeProxy);
       }
    }
 

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -42,12 +42,12 @@
 
    public Object createPerClass(Advisor advisor)
    {
-      throw new IllegalStateException("PER_VM NOT APPLICABLE");
+      throw new IllegalStateException("PER_CLASS NOT APPLICABLE");
    }
 
    public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor)
    {
-      throw new IllegalStateException("PER_VM NOT APPLICABLE");
+      throw new IllegalStateException("PER_INSTANCE NOT APPLICABLE");
    }
 
    public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
@@ -58,7 +58,7 @@
 
    public Object createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp)
    {
-      throw new IllegalStateException("PER_VM NOT APPLICABLE");
+      throw new IllegalStateException("PER_CLASS_JOINPOINT NOT APPLICABLE");
    }
 
    public String getName()

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -125,9 +125,7 @@
       {
          // Release it properly.
          StatefulBeanContext ctx = container.getCache().get(id);
-         container.getPool().remove(ctx);
-         // EJBTHREE-662
-//         container.getCache().remove(id);
+         container.getCache().remove(id);
       }
    }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/BaseStatelessProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,8 +21,16 @@
   */
 package org.jboss.ejb3.stateless;
 
+import java.io.Serializable;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyObject;
+
 import javax.naming.Context;
 import javax.naming.NamingException;
 
@@ -42,32 +50,184 @@
 {
    private static final Logger log = Logger.getLogger(BaseStatelessProxyFactory.class);
 
-   protected Class proxyClass;
-   protected Constructor proxyConstructor;
+//   protected Class proxyClass;
+//   protected Constructor proxyConstructor;
    protected Context proxyFactoryContext;
    protected String jndiName;
+   
+   private javassist.util.proxy.ProxyFactory proxyFactory;
+   private Class proxyClass;
+   private Constructor proxyConstructor;
+   
+   /**
+    * Adapt the JDK to cglib.
+    * 
+    * This is a named class because it implements both InvocationHandler and Serializable.
+    */
+   /* TODO: fix EJBTHREE-485 without cglib 
+   private static class CGLibInvocationHandlerAdapter implements net.sf.cglib.proxy.InvocationHandler, Serializable
+   {
+      private static final long serialVersionUID = 1L;
 
+      private InvocationHandler delegate;
+      
+      private CGLibInvocationHandlerAdapter(InvocationHandler delegate)
+      {
+         if(delegate == null)
+            throw new IllegalArgumentException("delegate must not be null");
+         this.delegate = delegate;
+      }
+      
+      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+      {
+         return delegate.invoke(proxy, method, args);
+      }
+      
+   }
+   */
+   
+   /**
+    * Adapt the InvocationHandler to MethodHandler.
+    * 
+    * This is a named class because it implements both MethodHandler and Serializable.
+    */
+   private static class MethodHandlerAdapter implements MethodHandler, Serializable
+   {
+      private static final long serialVersionUID = 1L;
+      
+      private InvocationHandler delegate;
+      
+      private MethodHandlerAdapter(InvocationHandler delegate)
+      {
+         if(delegate == null)
+            throw new IllegalArgumentException("delegate must not be null");
+         this.delegate = delegate;
+      }
+      
+      public Object invoke(Object self, Method thisMethod, Method process, Object[] args) throws Throwable
+      {
+         return delegate.invoke(self, thisMethod, args);
+      }         
+   }
+   
+   /**
+    * Hide the fact that I'm now using javassist.
+    * 
+    * @param handler    a JDK proxy InvocationHandler
+    * @return           a true proxy
+    */
+   protected Object constructProxy(final InvocationHandler handler)
+   {
+      try
+      {
+         /* plain jdk */
+         Object args[] = { handler };
+         Object proxy = proxyConstructor.newInstance(args);
+         
+         /* javassist */
+         /*
+         MethodHandler realHandler = new MethodHandlerAdapter(handler);
+//         ProxyObject proxy = (ProxyObject) proxyConstructor.newInstance((Object[]) null);
+//         proxy.setHandler(realHandler);
+         JavassistProxy proxy = (JavassistProxy) proxyConstructor.newInstance((Object[]) null);
+         proxy.setMethodHandler(realHandler);
+         JavassistProxy.pokeInterfaces(proxy, getInterfaces());
+         */
+         
+         /* cglib */
+         /*
+         Object args[] = { new CGLibInvocationHandlerAdapter(handler) };
+         Object proxy = proxyConstructor.newInstance(args);
+         */
+         
+         return proxy;
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (InstantiationException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RuntimeException(e.getTargetException());
+      }
+   }
+   
+   public final Object createProxy(Object id)
+   {
+      assert id == null : "stateless bean must not have an id";
+      return createProxy();
+   }
+   
    public void init() throws Exception
    {
       initializeJndiName();
       Class[] interfaces = getInterfaces();
+      
+      /* plain jdk */
       Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
       final Class[] constructorParams =
               {InvocationHandler.class};
       proxyConstructor = proxyClass.getConstructor(constructorParams);
+      
+      /* javassist */
+      /*
+      proxyFactory = new javassist.util.proxy.ProxyFactory()
+      {
+         @Override
+         protected ClassLoader getClassLoader()
+         {
+            return container.getBeanClass().getClassLoader();
+         }
+      };
+      proxyFactory.setInterfaces(interfaces);
+      proxyFactory.setSuperclass(JavassistProxy.class);
+      proxyClass = proxyFactory.createClass();
+      proxyConstructor = proxyClass.getConstructor((Class[]) null);
+      */
+      
+      /* cglib */
+      /*
+      proxyClass = net.sf.cglib.proxy.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
+      final Class[] constructorParams = {net.sf.cglib.proxy.InvocationHandler.class};
+      proxyConstructor = proxyClass.getConstructor(constructorParams);
+      */
    }
 
+   /* for debugging purposes * /
+   private static void describeClass(Class cls) {
+      System.err.println("class " + cls + " has the following:");
+      for(Class i : cls.getInterfaces()) {
+         System.err.println("  interface: " + i);
+      }
+      for(Method m : cls.getDeclaredMethods()) {
+         System.err.println("  method: " + m);
+      }
+      System.err.println("  classloader = " + cls.getClassLoader());
+      if(cls.getSuperclass() != null)
+         describeClass(cls.getSuperclass());
+   }
+   */
+   
    public void start() throws Exception
    {
       init();
 
       Object proxy = createProxy();
+      //describeClass(proxy.getClass());
       try
       {
-         Util.bind(container.getInitialContext(), jndiName, proxy);
+         Util.rebind(container.getInitialContext(), jndiName, proxy);
       } catch (NamingException e)
       {
-         NamingException namingException = new NamingException("Could not bind statless proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName);
+         NamingException namingException = new NamingException("Could not bind stateless proxy with ejb name " + container.getEjbName() + " into JNDI under jndiName: " + container.getInitialContext().getNameInNamespace() + "/" + jndiName);
          namingException.setRootCause(e);
          throw namingException;
       }

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/JavassistProxy.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/JavassistProxy.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/JavassistProxy.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,126 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.stateless;
+
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 46054 $
+ */
+public class JavassistProxy implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+   
+   private MethodHandler handler;
+   private Class interfaces[];
+   
+//   /**
+//    * Public because of classloading? 
+//    */
+//   public static class JavassistProxyReplacement extends JavassistProxy
+//   {
+//      public void setHandler(MethodHandler handler)
+//      {
+//         throw new RuntimeException("should never happen");
+//      }
+//   }
+//   
+   /**
+    * With this method you can directly poke interfaces into the
+    * proxy without setting of the method handler.
+    * 
+    * @param proxy
+    * @param interfaces
+    */
+   protected static void pokeInterfaces(JavassistProxy proxy, Class interfaces[]) {
+      proxy.interfaces = interfaces;
+   }
+   
+   private Object readResolve() throws ObjectStreamException
+   {
+      System.err.println("JavassistProxy.readResolve");
+      try {
+         ProxyFactory proxyFactory = new ProxyFactory() {
+            protected ClassLoader getClassLoader()
+            {
+               return Thread.currentThread().getContextClassLoader();
+            }
+         };
+         proxyFactory.setInterfaces(interfaces);
+         proxyFactory.setSuperclass(JavassistProxy.class);
+         Class proxyClass = proxyFactory.createClass();
+         Constructor proxyConstructor = proxyClass.getConstructor((Class[]) null);
+         JavassistProxy proxy = (JavassistProxy) proxyConstructor.newInstance((Object[]) null);
+         proxy.setMethodHandler(this.handler);
+         proxy.interfaces = this.interfaces;
+         return proxy;
+      }
+      catch (NoSuchMethodException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (InstantiationException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RuntimeException(e.getTargetException());
+      }
+   }
+   
+   protected void setInterfaces(Class interfaces[])
+   {
+      // TODO: check whether I get true interfaces
+      this.interfaces = interfaces;
+   }
+   
+   protected void setMethodHandler(MethodHandler handler)
+   {
+      // LOL
+      ((ProxyObject) this).setHandler(handler);
+      this.handler = handler;
+   }
+   
+   private Object writeReplace() throws ObjectStreamException
+   {
+      System.err.println("JavassistProxy.writeReplace");
+      JavassistProxy replacement = new JavassistProxyReplacement();
+      replacement.handler = this.handler;
+      replacement.interfaces = this.interfaces;
+      return replacement;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/JavassistProxyReplacement.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/JavassistProxyReplacement.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/JavassistProxyReplacement.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,33 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.stateless;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 46054 $
+ */
+public class JavassistProxyReplacement extends JavassistProxy
+{
+
+}

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessClusterProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -75,7 +75,7 @@
 
    public void start() throws Exception
    {
-      String clientBindUrl = binding.clientBindUrl();
+      String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
       Clustered clustered = (Clustered) advisor.resolveAnnotation(Clustered.class);
       if (clustered == null) throw new RuntimeException("Could not find @Clustered annotation.  Cannot deploy.");
@@ -106,7 +106,7 @@
 
    public Object createProxy()
    {
-      try
+//      try
       {
          Object containerId = container.getObjectName().getCanonicalName();
          String stackName = "ClusteredStatelessSessionClientInterceptors";
@@ -115,9 +115,13 @@
             stackName = binding.interceptorStack();
          }
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
+         /*
          Object[] args = {new StatelessClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null), wrapper, lbPolicy)};
          return proxyConstructor.newInstance(args);
+         */
+         return constructProxy(new StatelessClusteredProxy(containerId, stack.createInterceptors((Advisor) container, null), wrapper, lbPolicy));
       }
+      /*
       catch (InstantiationException e)
       {
          throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
@@ -134,6 +138,7 @@
       {
          throw new RuntimeException(e.getTargetException());  //To change body of catch statement use Options | File Templates.
       }
+      */
    }
 
    protected StatelessHandleImpl getHandle()

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -18,16 +18,10 @@
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/ 
+*/
 package org.jboss.ejb3.stateless;
 
 
-import java.lang.reflect.Method;
-import java.util.Hashtable;
-import java.util.Map;
-import javax.ejb.EJBException;
-import javax.ejb.Timer;
-import javax.ejb.TimerService;
 import org.jboss.annotation.ejb.LocalBinding;
 import org.jboss.annotation.ejb.RemoteBinding;
 import org.jboss.annotation.ejb.RemoteBindings;
@@ -41,18 +35,31 @@
 import org.jboss.aspects.asynch.FutureHolder;
 import org.jboss.ejb.AllowedOperationsAssociation;
 import org.jboss.ejb.AllowedOperationsFlags;
-import org.jboss.ejb.txtimer.TimedObjectInvoker;
 import org.jboss.ejb3.EJBContainerInvocation;
 import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.ejb3.EjbTimerUtil;
+import org.jboss.ejb3.ProxyFactoryHelper;
 import org.jboss.ejb3.ProxyUtils;
 import org.jboss.ejb3.SessionContainer;
+import org.jboss.ejb3.BeanContext;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.ejb3.timerservice.TimerServiceFactory;
 import org.jboss.logging.Logger;
 import org.jboss.proxy.ejb.handle.HomeHandleImpl;
 import org.jboss.proxy.ejb.handle.StatelessHandleImpl;
+import org.jboss.injection.EncInjector;
 
+import javax.ejb.EJBException;
+import javax.ejb.Handle;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.naming.NamingException;
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.HashMap;
 
+
 /**
  * Comment
  *
@@ -73,12 +80,24 @@
       beanContextClass = StatelessBeanContext.class;
    }
 
+   public Object createSession(Class initTypes[], Object initArgs[])
+   {
+      if((initTypes != null && initTypes.length > 0) || (initArgs != null && initArgs.length > 0))
+         throw new IllegalArgumentException("stateless bean create method must take no arguments (EJB3 4.5)");
+      // a stateless bean has no sessions
+      // TODO: pool stuff
+      return null;
+   }
+   
    public void start() throws Exception
    {
       try
       {
          super.start();
-         timerService = EjbTimerUtil.getTimerService(this, this);
+         //timerService = EjbTimerUtil.getTimerService(this, this);
+         timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
+         
+         TimerServiceFactory.getInstance().restoreTimerService(timerService);
       }
       catch (Exception e)
       {
@@ -96,7 +115,8 @@
 
    public void stop() throws Exception
    {
-      if (timerService != null) EjbTimerUtil.removeTimerService(this);
+      //if (timerService != null) EjbTimerUtil.removeTimerService(this);
+      if (timerService != null) TimerServiceFactory.getInstance().removeTimerService(timerService);
       super.stop();
    }
 
@@ -105,6 +125,12 @@
       return timerService;
    }
 
+   public TimerService getTimerService(Object pKey)
+   {
+      assert timerService != null : "Timer Service not yet initialized";
+      return timerService;
+   }
+   
    public void callTimeout(Timer timer) throws Exception
    {
       Method timeout = callbackHandler.getTimeoutCallback();
@@ -117,7 +143,7 @@
          try
          {
             MethodInfo info = (MethodInfo) methodInterceptors.get(callbackHandler.getTimeoutCalllbackHash());
-            Interceptor[] aspects = info.interceptors;
+            Interceptor[] aspects = info.getInterceptors();
             EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects);
             nextInvocation.setAdvisor(this);
             nextInvocation.setArguments(args);
@@ -164,18 +190,30 @@
             throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
          }
 
-         if (info.unadvisedMethod != null && isHomeMethod(info.unadvisedMethod))
+         Method unadvisedMethod = info.getUnadvisedMethod();
+
+
+         try
          {
-            return invokeLocalHomeMethod(info, args);
-         }
+            invokedMethod.push(new InvokedMethod(true, unadvisedMethod));
 
-         Interceptor[] aspects = info.interceptors;
-         EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects);
-         nextInvocation.setAdvisor(this);
-         nextInvocation.setArguments(args);
+            if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
+            {
+               return invokeLocalHomeMethod(info, args);
+            }
 
-         ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
-         return nextInvocation.invokeNext();
+            Interceptor[] aspects = info.getInterceptors();
+            EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects);
+            nextInvocation.setAdvisor(this);
+            nextInvocation.setArguments(args);
+
+            ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
+            return nextInvocation.invokeNext();
+         }
+         finally
+         {
+            invokedMethod.pop();
+         }
       }
       finally
       {
@@ -195,41 +233,50 @@
          {
             throw new RuntimeException("Could not resolve beanClass method from proxy call");
          }
-         
-         Map responseContext = null;
-         Object rtn = null;
-         if (info.unadvisedMethod != null && isHomeMethod(info.unadvisedMethod))
+
+         Method unadvisedMethod = info.getUnadvisedMethod();
+         try
          {
-            rtn = invokeHomeMethod(info, si);
-         }
-         else if (info != null && info.unadvisedMethod != null && isEJBObjectMethod(info.unadvisedMethod))
-         {
-            rtn = invokeEJBObjectMethod(info, si);
-         }
-         else
-         {
-
-            EJBContainerInvocation newSi = null;
-            Interceptor[] aspects = info.interceptors;
-
-            newSi = new EJBContainerInvocation(info, aspects);
-            newSi.setArguments(si.getArguments());
-            newSi.setMetaData(si.getMetaData());
-            newSi.setAdvisor(this);
-            try
+            invokedMethod.push(new InvokedMethod(false, unadvisedMethod));
+            Map responseContext = null;
+            Object rtn = null;
+            if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
             {
-               rtn = newSi.invokeNext();
-               responseContext = newSi.getResponseContextInfo();
+               rtn = invokeHomeMethod(info, si);
             }
-            catch (Throwable throwable)
+            else if (info != null && unadvisedMethod != null && isEJBObjectMethod(unadvisedMethod))
             {
-               responseContext = newSi.getResponseContextInfo();
-               return marshallException(invocation, throwable, responseContext);
+               rtn = invokeEJBObjectMethod(info, si);
             }
+            else
+            {
+
+               EJBContainerInvocation newSi = null;
+               Interceptor[] aspects = info.getInterceptors();
+
+               newSi = new EJBContainerInvocation(info, aspects);
+               newSi.setArguments(si.getArguments());
+               newSi.setMetaData(si.getMetaData());
+               newSi.setAdvisor(this);
+               try
+               {
+                  rtn = newSi.invokeNext();
+                  responseContext = newSi.getResponseContextInfo();
+               }
+               catch (Throwable throwable)
+               {
+                  responseContext = newSi.getResponseContextInfo();
+                  return marshallException(invocation, throwable, responseContext);
+               }
+            }
+
+            InvocationResponse response = marshallResponse(invocation, rtn, responseContext);
+            return response;
          }
-
-         InvocationResponse response = marshallResponse(invocation, rtn, responseContext);
-         return response;
+         finally
+         {
+            invokedMethod.pop();
+         }
       }
       finally
       {
@@ -240,7 +287,8 @@
 
    protected Object invokeEJBObjectMethod(MethodInfo info, MethodInvocation invocation) throws Throwable
    {
-      if (info.unadvisedMethod.getName().equals("getHandle"))
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if (unadvisedMethod.getName().equals("getHandle"))
       {
          StatelessHandleImpl handle = null;
          RemoteBinding remoteBindingAnnotation = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
@@ -249,11 +297,11 @@
 
          return handle;
       }
-      else if (info.unadvisedMethod.getName().equals("remove"))
+      else if (unadvisedMethod.getName().equals("remove"))
       {
          return null;
       }
-      else if (info.unadvisedMethod.getName().equals("getEJBHome"))
+      else if (unadvisedMethod.getName().equals("getEJBHome"))
       {
          HomeHandleImpl homeHandle = null;
 
@@ -263,11 +311,11 @@
 
          return homeHandle.getEJBHome();
       }
-      else if (info.unadvisedMethod.getName().equals("getPrimaryKey"))
+      else if (unadvisedMethod.getName().equals("getPrimaryKey"))
       {
          return null;
       }
-      else if (info.unadvisedMethod.getName().equals("isIdentical"))
+      else if (unadvisedMethod.getName().equals("isIdentical"))
       {
          return false;
       }
@@ -279,7 +327,8 @@
 
    private Object invokeLocalHomeMethod(MethodInfo info, Object[] args) throws Exception
    {
-      if (info.unadvisedMethod.getName().equals("create"))
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if (unadvisedMethod.getName().equals("create"))
       {
          LocalBinding binding = (LocalBinding) resolveAnnotation(LocalBinding.class);
 
@@ -299,7 +348,8 @@
 
    protected Object invokeHomeMethod(MethodInfo info, MethodInvocation invocation) throws Throwable
    {
-      if (info.unadvisedMethod.getName().equals("create"))
+      Method unadvisedMethod = info.getUnadvisedMethod();
+      if (unadvisedMethod.getName().equals("create"))
       {
          RemoteBinding binding = null;
 
@@ -321,4 +371,24 @@
          return null;
       }
    }
+
+   @Override
+   public Object getBusinessObject(BeanContext ctx, Class intf)
+   {
+      try
+      {
+         String jndiName = ProxyFactoryHelper.getJndiName(this, intf);
+         if (jndiName == null) throw new IllegalStateException("Cannot find BusinessObject for interface: " + intf.getName());
+         return getInitialContext().lookup(ProxyFactoryHelper.getJndiName(this, intf));
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException("failed to invoke getBusinessObject", e);
+      }
+   }
+
+   protected void removeHandle(Handle handle)
+   {
+      throw new RuntimeException("NYI");
+   }
 }

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessLocalProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -68,7 +68,7 @@
          Class[] interfaces = {localHome.value()};
          Object homeProxy = java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(),
                                                                      interfaces, new StatelessLocalProxy(container));
-         NonSerializableFactory.bind(container.getInitialContext(), jndiName + "Home", homeProxy);
+         NonSerializableFactory.rebind(container.getInitialContext(), jndiName + "Home", homeProxy);
       }
    }
 
@@ -87,6 +87,7 @@
 
    public Object createProxy()
    {
+      /*
       try
       {
          Object[] args = {new StatelessLocalProxy(container)};
@@ -108,6 +109,8 @@
       {
          throw new RuntimeException(e.getTargetException());  //To change body of catch statement use Options | File Templates.
       }
+      */
+      return constructProxy(new StatelessLocalProxy(container));
    }
 
    protected StatelessHandleImpl getHandle()

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -21,7 +21,6 @@
   */
 package org.jboss.ejb3.stateless;
 
-import java.lang.reflect.InvocationTargetException;
 import javax.ejb.RemoteHome;
 import javax.naming.NamingException;
 import org.jboss.annotation.ejb.RemoteBinding;
@@ -76,7 +75,7 @@
    public void init() throws Exception
    {
       super.init();
-      String clientBindUrl = binding.clientBindUrl();
+      String clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
       locator = new InvokerLocator(clientBindUrl);
    }
 
@@ -90,7 +89,7 @@
          Object homeProxy = createHomeProxy(remoteHome.value());
          try
          {
-            Util.bind(container.getInitialContext(), jndiName + "Home", homeProxy);
+            Util.rebind(container.getInitialContext(), jndiName + "Home", homeProxy);
          }
          catch (NamingException e)
          {
@@ -148,7 +147,7 @@
 
    public Object createProxy()
    {
-      try
+//      try
       {
          Object containerId = container.getObjectName().getCanonicalName();
          ;
@@ -160,9 +159,13 @@
          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
          StatelessRemoteProxy proxy = new StatelessRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator);
          setEjb21Objects(proxy);
+         /*
          Object[] args = {proxy};
          return proxyConstructor.newInstance(args);
+         */
+         return constructProxy(proxy);
       }
+      /*
       catch (InstantiationException e)
       {
          throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
@@ -179,6 +182,7 @@
       {
          throw new RuntimeException(e.getTargetException());  //To change body of catch statement use Options | File Templates.
       }
+      */
    }
 
 }

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/TimedObjectInvoker.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.timerservice;
+
+// $Id: TimedObjectInvoker.java,v 1.1 2006/06/07 09:26:15 wolfc Exp $
+
+import javax.ejb.Timer;
+
+/**
+ * An implementation can invoke the ejbTimeout method on a TimedObject.
+ *
+ * The TimedObjectInvoker has knowledge of the TimedObjectId, it
+ * knows which object to invoke.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @version $Revision: 1.1 $
+ * @since 07-Apr-2004
+ */
+public interface TimedObjectInvoker extends org.jboss.ejb.txtimer.TimedObjectInvoker
+{
+   /**
+    * Invokes the ejbTimeout method on the TimedObject with the given id.
+    *
+    * @param timer the Timer that is passed to ejbTimeout
+    */
+   void callTimeout(Timer timer) throws Exception;
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.timerservice;
+
+import javax.ejb.EJBException;
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class TimerServiceFactory
+{
+   private static TimerServiceFactory instance;
+   
+   private synchronized static TimerServiceFactory createInstance()
+   {
+      if(instance != null)
+         return instance;
+      
+      String factoryClass = "org.jboss.ejb3.timerservice.jboss.JBossTimerServiceFactory";
+      factoryClass = System.getProperty("org.jboss.ejb3.timerservice.factory", factoryClass);
+      
+      try
+      {
+         Class cls = Class.forName(factoryClass);
+         instance = (TimerServiceFactory) cls.newInstance();
+         
+         return instance;
+      }
+      catch(ClassNotFoundException e)
+      {
+         throw new EJBException(e);
+      }
+      catch(InstantiationException e)
+      {
+         throw new EJBException(e);
+      }
+      catch(IllegalAccessException e)
+      {
+         throw new EJBException(e);
+      }
+   }
+   
+   public abstract TimerService createTimerService(ObjectName objectName, TimedObjectInvoker invoker);
+   
+   public static TimerServiceFactory getInstance()
+   {
+      if(instance == null)
+      {
+         createInstance();
+      }
+      
+      return instance;
+   }
+   
+   public abstract void removeTimerService(TimerService timerService);
+   
+   /**
+    * Restores the timers held with the specified timer service.
+    * 
+    * @param timerService
+    */
+   public abstract void restoreTimerService(TimerService timerService);
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/JBossTimerServiceFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.timerservice.jboss;
+
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+
+import org.jboss.ejb.txtimer.EJBTimerService;
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.ejb3.timerservice.TimerServiceFactory;
+import org.jboss.logging.Logger;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.MBeanServerLocator;
+
+/**
+ * Factory to create timer services which use the JBoss EJB Timer Service.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class JBossTimerServiceFactory extends TimerServiceFactory
+{
+   private static Logger log = Logger.getLogger(JBossTimerServiceFactory.class);
+   
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.timerservice.TimerServiceFactory#createTimerService(javax.management.ObjectName, org.jboss.ejb3.timerservice.TimedObjectInvoker)
+    */
+   @Override
+   public TimerService createTimerService(ObjectName containerId, TimedObjectInvoker invoker)
+   {
+      TimerService timerService = null;
+      try
+      {
+         EJBTimerService service = getEJBTimerService();
+         TimerService delegate = service.createTimerService(containerId, null, invoker);
+         timerService = new TimerServiceFacade(containerId, delegate);
+      }
+      catch (Exception e)
+      {
+         //throw new EJBException("Could not create timer service", e);
+         if (log.isTraceEnabled())
+         {
+            log.trace("Unable to initialize timer service", e);
+         }
+         else
+         {
+            log.trace("Unable to initialize timer service");
+         }
+      }
+      return timerService;
+   }
+
+   protected EJBTimerService getEJBTimerService()
+   {
+      return (EJBTimerService) MBeanProxyExt.create(EJBTimerService.class, EJBTimerService.OBJECT_NAME, MBeanServerLocator.locateJBoss());
+   }
+   
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.timerservice.TimerServiceFactory#removeTimerService(javax.ejb.TimerService)
+    */
+   @Override
+   public void removeTimerService(TimerService timerService)
+   {
+      removeTimerService(((TimerServiceFacade) timerService).getContainerId());
+   }
+
+   protected void removeTimerService(ObjectName containerId)
+   {
+      try
+      {
+         EJBTimerService service = getEJBTimerService();
+         service.removeTimerService(containerId, true);
+      }
+      catch (Exception e)
+      {
+         //throw new EJBException("Could not remove timer service", e);
+         if (log.isTraceEnabled())
+         {
+            log.trace("Unable to initialize timer service", e);
+         }
+         else
+         {
+            log.trace("Unable to initialize timer service");
+         }
+      }
+   }
+   
+   public void restoreTimerService(TimerService aTimerService)
+   {
+      if (aTimerService == null)
+      {
+         log.warn("TIMER SERVICE IS NOT INSTALLED");
+         return;
+      }
+      TimerServiceFacade timerService = (TimerServiceFacade) aTimerService;
+      EJBContainer container = timerService.getContainer();
+      // FIXME: do not assume that a TimedObjectInvoker is an EJBContainer
+      ClassLoader loader = container.getClassloader();
+      
+      getEJBTimerService().restoreTimers(timerService.getContainerId(), loader);
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.timerservice.jboss;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.ejb.EJBException;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.Ejb3Registry;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class TimerServiceFacade implements TimerService
+{
+   private TimerService delegate;
+   
+   private ObjectName containerId;
+   
+   protected TimerServiceFacade(ObjectName containerId, TimerService delegate)
+   {
+      this.containerId = containerId;
+      this.delegate = delegate;
+   }
+
+   public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      return delegate.createTimer(initialExpiration, intervalDuration, info);
+   }
+
+   public Timer createTimer(Date expiration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      return delegate.createTimer(expiration, info);
+   }
+
+   public Timer createTimer(long initialDuration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      return delegate.createTimer(initialDuration, intervalDuration, info);
+   }
+
+   public Timer createTimer(long duration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      return delegate.createTimer(duration, info);
+   }
+
+   protected EJBContainer getContainer()
+   {
+      return (EJBContainer) Ejb3Registry.getContainer(getContainerId().getCanonicalName());
+   }
+   
+   protected ObjectName getContainerId()
+   {
+      return containerId;
+   }
+   
+   public Collection getTimers() throws IllegalStateException, EJBException
+   {
+      return delegate.getTimers();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/package.html
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/package.html	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/package.html	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1 @@
+This package forms the bridge between EJB3 and a timer service.
\ No newline at end of file

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/PersistentTimer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,96 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.timerservice.quartz;
+
+import java.io.Serializable;
+
+import javax.ejb.EJBException;
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.Timer;
+import javax.ejb.TimerHandle;
+import javax.management.ObjectName;
+
+import org.jboss.ejb3.Ejb3Registry;
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.logging.Logger;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+
+/**
+ * This class contains all the info for find a persistent timer.
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 56169 $
+ */
+public class PersistentTimer implements Serializable, TimerHandle
+{
+   private static final Logger log = Logger.getLogger(PersistentTimer.class);
+   
+   private static final long serialVersionUID = 1L;
+
+   //private String schedulerName;
+   //private String jobName;
+   //private String jobGroup;
+   private String triggerName;
+   private String triggerGroup;
+   private ObjectName objectName;
+   
+   private Serializable info;
+   
+   protected PersistentTimer(Trigger trigger, ObjectName objectName, Serializable info)
+   {
+      assert trigger != null;
+      assert objectName != null;
+      
+      this.triggerName = trigger.getName();
+      this.triggerGroup = trigger.getGroup();
+      this.objectName = objectName;
+      this.info = info;
+   }
+   
+   protected TimedObjectInvoker getTimedObjectInvoker()
+   {
+      // TODO: a hack to get back the container. This needs thinking.
+      TimedObjectInvoker invoker = (TimedObjectInvoker) Ejb3Registry.getContainer(objectName.getCanonicalName());
+      assert invoker != null;
+      return invoker;
+   }
+   
+   public Timer getTimer() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      // TODO: check state
+      try
+      {
+         Scheduler scheduler = QuartzTimerServiceFactory.getScheduler();
+         Trigger trigger = scheduler.getTrigger(triggerName, triggerGroup);
+         if(trigger == null)
+            throw new NoSuchObjectLocalException("can't find trigger '" + triggerName + "' in group '" + triggerGroup + "'");
+         return new TimerImpl(scheduler, trigger, info);
+      }
+      catch(SchedulerException e)
+      {
+         log.error("getTimer failed", e);
+         throw new EJBException(e);
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerJob.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerJob.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerJob.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,48 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.timerservice.quartz;
+
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 56169 $
+ */
+public class QuartzTimerJob implements Job
+{
+   public void execute(JobExecutionContext context) throws JobExecutionException
+   {
+      PersistentTimer timer = (PersistentTimer) context.getJobDetail().getJobDataMap().get("timer");
+      TimedObjectInvoker invoker = timer.getTimedObjectInvoker();
+      try {
+         invoker.callTimeout(timer.getTimer());
+      }
+      catch(Exception e) {
+         throw new JobExecutionException(e);
+      }
+   }  
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/QuartzTimerServiceFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,274 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.timerservice.quartz;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.ejb3.timerservice.TimerServiceFactory;
+import org.jboss.logging.Logger;
+import org.jboss.tm.TransactionManagerService;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.impl.StdSchedulerFactory;
+import org.quartz.utils.DBConnectionManager;
+import org.quartz.utils.JNDIConnectionProvider;
+
+/**
+ * Creates timer service objects for use in EJB3 containers. For this
+ * two methods are provided: createTimerService and removeTimerService.
+ * 
+ * The factory can be started and stopped within both an embedded and full stack.
+ * 
+ * For now only one scheduler is supported. Each bean container has its own
+ * job and trigger group within Quartz.
+ * 
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 56116 $
+ */
+public class QuartzTimerServiceFactory extends TimerServiceFactory
+{
+   @SuppressWarnings("unused")
+   private static final Logger log = Logger.getLogger(QuartzTimerServiceFactory.class);
+   
+   private TransactionManager tm;
+   
+   private static Scheduler scheduler;
+   
+   private Properties properties;
+   
+   /**
+    * Contains the sql statements to create the database schema.
+    */
+   private Properties sqlProperties;
+   
+   private void createSchema()
+   {
+      try
+      {
+         tm.begin();
+         try
+         {
+            Connection conn = getConnection();
+            try
+            {
+               boolean success = execute(conn, "CREATE_TABLE_JOB_DETAILS");
+               if(success)
+               {
+                  execute(conn, "CREATE_TABLE_JOB_LISTENERS");
+                  execute(conn, "CREATE_TABLE_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_SIMPLE_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_CRON_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_BLOB_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_TRIGGER_LISTENERS");
+                  execute(conn, "CREATE_TABLE_CALENDARS");
+                  execute(conn, "CREATE_TABLE_PAUSED_TRIGGER_GRPS");
+                  execute(conn, "CREATE_TABLE_FIRED_TRIGGERS");
+                  execute(conn, "CREATE_TABLE_SCHEDULER_STATE");
+                  execute(conn, "CREATE_TABLE_LOCKS");
+                  
+                  execute(conn, "INSERT_TRIGGER_ACCESS");
+                  execute(conn, "INSERT_JOB_ACCESS");
+                  execute(conn, "INSERT_CALENDAR_ACCESS");
+                  execute(conn, "INSERT_STATE_ACCESS");
+                  execute(conn, "INSERT_MISFIRE_ACCESS");
+               }
+            }
+            finally
+            {
+               conn.close();
+            }
+            tm.commit();
+         }
+         catch(SQLException e)
+         {
+            throw new RuntimeException(e);
+         }
+         catch (RollbackException e)
+         {
+            throw new RuntimeException(e);
+         }
+         catch (HeuristicMixedException e)
+         {
+            throw new RuntimeException(e);
+         }
+         catch (HeuristicRollbackException e)
+         {
+            throw new RuntimeException(e);
+         }
+         finally
+         {
+            if(tm.getStatus() == Status.STATUS_ACTIVE)
+               tm.rollback();
+         }
+      }
+      catch(SystemException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (NotSupportedException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   /**
+    * Create a TimerService for use in a bean container.
+    * 
+    * @param objectName the name of the bean container
+    * @param invoker    the invoker to call on timeouts
+    * @return           an EJB TimerService
+    */
+   public TimerService createTimerService(ObjectName objectName, TimedObjectInvoker invoker)
+   {
+      Scheduler scheduler = getScheduler();
+      if (scheduler == null) return null;
+      
+      return new TimerServiceImpl(scheduler, objectName, invoker);
+   }
+   
+   private boolean execute(Connection conn, String stmtName) throws SQLException
+   {
+      String sql = sqlProperties.getProperty(stmtName);
+      if(sql == null)
+         throw new IllegalStateException("No sql set for '" + stmtName + "'");
+      
+      PreparedStatement stmt = conn.prepareStatement(sql);
+      try
+      {
+         stmt.execute();
+         return true;
+      }
+      catch(SQLException e)
+      {
+         log.warn("sql failed: " + sql);
+         if(log.isDebugEnabled())
+            log.debug("sql failed: " + sql, e);
+         return false;
+      }
+      finally
+      {
+         stmt.close();
+      }
+   }
+   
+   private Connection getConnection() throws SQLException
+   {
+      return DBConnectionManager.getInstance().getConnection("myDS");
+   }
+   
+   /**
+    * @return   the scheduler for package use
+    */
+   protected static Scheduler getScheduler()
+   {
+      if(scheduler == null)
+      {
+         return null;
+         //throw new IllegalStateException("TimerServiceFactory hasn't been started yet");
+      }
+      
+      return scheduler;
+   }
+   
+   public void removeTimerService(TimerService aTimerService)
+   {
+      TimerServiceImpl timerService = (TimerServiceImpl) aTimerService;
+      timerService.shutdown();
+   }
+   
+   public void restoreTimerService(TimerService aTimerService)
+   {
+      // TODO: implement Quartz restore timer service
+   }
+   
+   public void setDataSource(String jndiName)
+   {
+      JNDIConnectionProvider connectionProvider = new JNDIConnectionProvider(jndiName, false);
+      // FIXME: remove hardcoding
+      DBConnectionManager.getInstance().addConnectionProvider("myDS", connectionProvider);
+   }
+   
+   public void setProperties(final Properties props)
+   {
+//      if(scheduler != null)
+//         throw new IllegalStateException("already started");
+      
+      // TODO: precondition the prop
+      properties = props;
+   }
+   
+   public void setSqlProperties(Properties props)
+   {
+      this.sqlProperties = props;
+   }
+   
+   public synchronized void start() throws Exception
+   {
+      if(scheduler != null)
+         throw new IllegalStateException("already started");
+      
+      log.debug("properties = " + properties);
+      
+      InitialContext ctx = new InitialContext();
+      tm = (TransactionManager) ctx.lookup(TransactionManagerService.JNDI_NAME);
+      
+      createSchema();
+      
+      // TODO: bind in JNDI, or is this done by the JMX bean?
+      SchedulerFactory factory;
+      if(properties == null)
+         factory = new StdSchedulerFactory();
+      else
+         factory = new StdSchedulerFactory(properties);
+      scheduler = factory.getScheduler();
+      // TODO: really start right away?
+      scheduler.start();
+   }
+   
+   public synchronized void stop() throws Exception
+   {
+      if(scheduler == null)
+         throw new IllegalStateException("already stopped");
+      
+      // TODO: unbind from JNDI
+      
+      // TODO: standby or shutdown?
+      scheduler.shutdown();
+      
+      scheduler = null;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,152 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.timerservice.quartz;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.ejb.EJBException;
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.Timer;
+import javax.ejb.TimerHandle;
+
+import org.jboss.logging.Logger;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+
+/**
+ * A view on an actual (persistent) timer.
+ * 
+ * This object must never be serializable (EJB3 18.4.1)
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 56169 $
+ */
+public class TimerImpl implements Timer
+{
+   private static final Logger log = Logger.getLogger(TimerImpl.class);
+   
+   private Scheduler scheduler;
+   private Trigger trigger;
+   private Serializable info;
+   
+   protected TimerImpl(Scheduler scheduler, Trigger trigger, Serializable info) {
+      assert scheduler != null;
+      assert trigger != null;
+      
+      this.scheduler = scheduler;
+      this.trigger = trigger;
+      this.info = info;
+   }
+   
+   protected void checkState()
+   {
+      // TODO: implement bean state checking to see if a call is allowed
+      
+      if(trigger.getNextFireTime() == null)
+         throw new NoSuchObjectLocalException("timer has expired");
+   }
+   
+   /**
+    * Cause the timer and all its associated expiration notifications to be cancelled.
+    * 
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public void cancel() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      checkState();
+      
+      try {
+         // TODO: call TimerServiceImpl.cancelTimer instead
+         scheduler.unscheduleJob(trigger.getName(), trigger.getGroup());
+      }
+      catch(SchedulerException e) {
+         log.error("cancel failed", e);
+         throw new EJBException(e.getMessage());
+      }
+   }
+
+   /**
+    * Get the number of milliseconds that will elapse before the next scheduled timer expiration.
+    * 
+    * @return   The number of milliseconds that will elapse before the next scheduled timer expiration.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public long getTimeRemaining() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      // leave all checks to getNextTimeout
+      return getNextTimeout().getTime() - System.currentTimeMillis();
+   }
+
+   /**
+    * Get the point in time at which the next timer expiration is scheduled to occur.
+    * 
+    * @return   The point in time at which the next timer expiration is scheduled to occur.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Date getNextTimeout() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      checkState();
+      
+      Date nextTimeout = trigger.getNextFireTime();
+      if(nextTimeout == null)
+         throw new IllegalStateException("trigger does not have a next fire time"); // TODO: proper EJB3 state check & exception
+      return nextTimeout;
+   }
+
+   /**
+    * Get the information associated with the timer at the time of creation.
+    * 
+    * @return   The Serializable object that was passed in at timer creation, or null if the info argument passed in at timer creation was null.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Serializable getInfo() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      checkState();
+      
+      return info;
+   }
+
+   /**
+    * Get a serializable handle to the timer. This handle can be used at a later time to re-obtain the timer reference.
+    * 
+    * @return   A serializable handle to the timer.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   NoSuchObjectLocalException  If invoked on a timer that has expired or has been cancelled. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public TimerHandle getHandle() throws IllegalStateException, NoSuchObjectLocalException, EJBException
+   {
+      checkState();
+      
+      return null; // FIXME: implement getHandle
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,233 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.timerservice.quartz;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.ejb.EJBException;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+
+import org.jboss.ejb3.timerservice.TimedObjectInvoker;
+import org.jboss.logging.Logger;
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+
+/**
+ * Implements the EJB3 Timer Service specification (EJB3 chapter 18).
+ * 
+ * Each bean container has its own job and trigger group.
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 56169 $
+ */
+public class TimerServiceImpl implements TimerService
+{
+   private static final Logger log = Logger.getLogger(TimerServiceImpl.class);
+   
+   private Scheduler scheduler;
+   private ObjectName objectName;
+   private String groupName;
+   private long jobNum = 0;
+   private long triggerNum = 0;
+   
+   protected TimerServiceImpl(Scheduler scheduler, ObjectName objectName, TimedObjectInvoker invoker) {
+      assert scheduler != null;
+      assert objectName != null;
+      assert invoker != null;
+      
+      this.scheduler = scheduler;
+      this.objectName = objectName;
+      this.groupName = objectName.getCanonicalName();
+   }
+   
+   protected Timer createTimer(Trigger trigger, Serializable info)
+   {
+      try {
+         String name = "myJob" + jobNum;
+         jobNum++;
+         
+         Class jobClass = QuartzTimerJob.class;
+         
+         Timer timer = new TimerImpl(scheduler, trigger, info);
+         
+         PersistentTimer persistentTimer = new PersistentTimer(trigger, objectName, info);
+         
+         JobDetail jobDetail = new JobDetail(name, groupName, jobClass);
+         jobDetail.getJobDataMap().put("timer", persistentTimer);
+         
+         scheduler.scheduleJob(jobDetail, trigger);
+         
+         return timer;
+      }
+      catch(SchedulerException e) {
+         // translate the exception, because the client might not have quartz
+         log.error("createTimer failed", e);
+         throw new EJBException(e.getMessage());
+      }
+      
+   }
+   
+   /**
+    * Create a single-action timer that expires after a specified duration.
+    * 
+    * @param    duration    The number of milliseconds that must elapse before the timer expires.
+    * @param    info        Application information to be delivered along with the timer expiration notification. This can be null.
+    * @return   The newly created Timer.
+    * @throws   IllegalArgumentException    If duration is negative.
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method.
+    * @throws   EJBException                If this method fails due to a system-level failure.
+    */
+   public Timer createTimer(long duration, Serializable info) throws IllegalArgumentException, IllegalStateException,
+         EJBException
+   {
+      if(duration < 0) throw new IllegalArgumentException("duration must not be negative");
+      // TODO: check state
+      
+      Date expiration = new Date(System.currentTimeMillis() + duration);
+      return createTimer(expiration, info);
+   }
+
+   /**
+    * Create an interval timer whose first expiration occurs after a specified duration, 
+    * and whose subsequent expirations occur after a specified interval.
+    * 
+    * @param    initialDuration     The number of milliseconds that must elapse before the first timer expiration notification.
+    * @param    intervalDuration    The number of milliseconds that must elapse between timer expiration notifications. Expiration notifications are scheduled relative to the time of the first expiration. If expiration is delayed(e.g. due to the interleaving of other method calls on the bean) two or more expiration notifications may occur in close succession to "catch up".
+    * @param    info                Application information to be delivered along with the timer expiration. This can be null.
+    * @return   The newly created Timer.
+    * @throws   IllegalArgumentException    If initialDuration is negative, or intervalDuration is negative. 
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Timer createTimer(long initialDuration, long intervalDuration, Serializable info)
+         throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      if(initialDuration < 0) throw new IllegalArgumentException("initialDuration must not be negative");
+      if(intervalDuration < 0) throw new IllegalArgumentException("intervalDuration must not be negative");
+      // TODO: check state
+      
+      Date initialExpiration = new Date(System.currentTimeMillis() + initialDuration);
+      
+      return createTimer(initialExpiration, intervalDuration, info);
+   }
+
+   /**
+    * Create a single-action timer that expires at a given point in time.
+    * 
+    * @param    expiration  The point in time at which the timer must expire.
+    * @param    info        Application information to be delivered along with the timer expiration notification. This can be null. 
+    * @return   The newly created Timer. 
+    * @throws   IllegalArgumentException    If expiration is null, or expiration.getTime() is negative. 
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Timer createTimer(Date expiration, Serializable info) throws IllegalArgumentException, IllegalStateException,
+         EJBException
+   {
+      if(expiration == null) throw new IllegalArgumentException("expiration must not be null");
+      if(expiration.getTime() < 0) throw new IllegalArgumentException("expiration.time must not be negative");
+      // TODO: check state
+      
+      String triggerName = "myTrigger" + triggerNum;
+      triggerNum++;
+      
+      Trigger trigger = new SimpleTrigger(triggerName, groupName, expiration);
+      
+      return createTimer(trigger, info);
+   }
+
+   /**
+    * Create an interval timer whose first expiration occurs at a given point in time and whose subsequent expirations occur after a specified interval.
+    * 
+    * @param    initialExpiration   The point in time at which the first timer expiration must occur.
+    * @param    intervalDuration    The number of milliseconds that must elapse between timer expiration notifications. Expiration notifications are scheduled relative to the time of the first expiration. If expiration is delayed(e.g. due to the interleaving of other method calls on the bean) two or more expiration notifications may occur in close succession to "catch up".
+    * @param    info                Application information to be delivered along with the timer expiration notification. This can be null. 
+    * @return   The newly created Timer. 
+    * @throws   IllegalArgumentException    If initialExpiration is null, or initialExpiration.getTime() is negative, or intervalDuration is negative. 
+    * @throws   IllegalStateException       If this method is invoked while the instance is in a state that does not allow access to this method. 
+    * @throws   EJBException                If this method could not complete due to a system-level failure.
+    */
+   public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info)
+         throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      if(initialExpiration == null) throw new IllegalArgumentException("initialExpiration must not be null");
+      if(initialExpiration.getTime() < 0) throw new IllegalArgumentException("initialExpiration.time must not be negative");
+      if(intervalDuration < 0) throw new IllegalArgumentException("intervalDuration must not be negative");
+      // TODO: check state
+      
+      String triggerName = "myTrigger" + triggerNum;
+      triggerNum++;
+      Date endTime = null;
+      
+      Trigger trigger = new SimpleTrigger(triggerName, groupName, initialExpiration, endTime, SimpleTrigger.REPEAT_INDEFINITELY, intervalDuration);
+      
+      return createTimer(trigger, info);
+   }
+
+   protected Scheduler getScheduler()
+   {
+      return scheduler;
+   }
+
+   /**
+    * Get all the active timers associated with this bean.
+    * 
+    * @return   A collection of javax.ejb.Timer objects.
+    * @throws   IllegalStateException   If this method is invoked while the instance is in a state that does not allow access to this method.
+    * @throws   EJBException            If this method could not complete due to a system-level failure.
+    */
+   public Collection getTimers() throws IllegalStateException, EJBException
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   protected void shutdown()
+   {
+      log.info("shutting down " + this);
+      try
+      {
+         String triggerNames[] = scheduler.getTriggerNames(groupName);
+         for(String triggerName : triggerNames)
+            scheduler.unscheduleJob(triggerName, groupName);
+         String jobNames[] = scheduler.getJobNames(groupName);
+         for(String jobName : jobNames)
+            scheduler.deleteJob(jobName, groupName);
+      }
+      catch(SchedulerException e)
+      {
+         log.error("shutdown failed", e);
+         // TODO: ignore?
+      }
+   }
+   
+   public String toString()
+   {
+      return "Timer Service " + objectName;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerService.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerService.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerService.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,114 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.timerservice.quartz.jmx;
+
+import java.util.Properties;
+
+import javax.management.ObjectName;
+
+import org.jboss.ejb3.timerservice.quartz.QuartzTimerServiceFactory;
+import org.jboss.system.ServiceMBeanSupport;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 56169 $
+ */
+public class EJB3TimerService extends ServiceMBeanSupport
+   implements EJB3TimerServiceMBean
+{
+   private QuartzTimerServiceFactory delegate;
+   private ObjectName dataSource;
+   
+   public EJB3TimerService()
+   {
+      delegate = new QuartzTimerServiceFactory();
+   }
+   
+   @Override
+   protected void createService() throws Exception
+   {
+      super.createService();
+   }
+
+   @Override
+   protected void destroyService() throws Exception
+   {
+      //this.delegate.shutdown();
+      super.destroyService();
+   }
+   
+   /**
+    * @jmx:managed-attribute
+    * 
+    * @return   the object name of the data source to use
+    */
+   public ObjectName getDataSource()
+   {
+      return dataSource;
+   }
+   
+   /**
+    * @jmx:managed-attribute
+    */
+   public void setDataSource(ObjectName dataSource)
+   {
+      this.dataSource = dataSource;
+   }
+   
+   /**
+    * @jmx:managed-attribute
+    * 
+    * @param props
+    */
+   public void setProperties(final Properties props)
+   {
+      delegate.setProperties(props);
+   }
+   
+   /**
+    * @jmx:managed-attribute
+    * 
+    * @param props
+    */
+   public void setSqlProperties(Properties props)
+   {
+      delegate.setSqlProperties(props);
+   }
+   
+   @Override
+   protected void startService() throws Exception
+   {
+      super.startService();
+      String jndiName = (String) server.getAttribute(dataSource, "BindName");
+      delegate.setDataSource(jndiName);
+      delegate.start();
+   }
+   
+   @Override
+   protected void stopService() throws Exception
+   {
+      delegate.stop();
+      super.stopService();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerServiceMBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerServiceMBean.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/jmx/EJB3TimerServiceMBean.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,47 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.timerservice.quartz.jmx;
+
+import java.util.Properties;
+
+import javax.management.ObjectName;
+
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.system.ServiceMBean;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
+ * @version $Revision: 56169 $
+ */
+public interface EJB3TimerServiceMBean extends ServiceMBean
+{
+    /** The default object name */
+    ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss.ejb:service=EJB3TimerService");
+    
+    void setDataSource(ObjectName dataSource);
+    
+    void setProperties(final Properties props);
+    
+    void setSqlProperties(Properties props);
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/package.html
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/package.html	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/package.html	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,17 @@
+<head>
+	<body>
+		This package provides the EJB Timer Service to the EJB3 stack.
+		<p/>
+		It replaces the org.jboss.ejb.txtimer package.
+		<p/>
+		The Jboss EJB3 Timer Service package depends on:
+		<ul>
+			<li>EJB3 API</li>
+			<li>Quartz</li>
+			<li>JTA</li>
+		</ul>
+		<p/>
+		Note that almost all exceptions are caught and rethrown as EJBExceptions, thus
+		making sure that no Quartz API is exposed either compile time or run time.
+	</body>
+</head>
\ No newline at end of file

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/Ejb3TxPolicy.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/Ejb3TxPolicy.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/Ejb3TxPolicy.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -23,6 +23,7 @@
 
 import java.rmi.RemoteException;
 import java.util.Iterator;
+import java.util.List;
 
 import javax.ejb.ApplicationException;
 import javax.ejb.EJBException;
@@ -33,8 +34,7 @@
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.dd.ApplicationExceptionList;
-import org.jboss.ejb3.dd.AssemblyDescriptor;
+import org.jboss.ejb3.metamodel.AssemblyDescriptor;
 import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.ejb3.stateful.StatefulContainerInvocation;
 
@@ -105,18 +105,15 @@
       
       if (assembly != null)
       {
-         ApplicationExceptionList exceptionList = assembly.getApplicationExceptionList();
-         if (exceptionList != null)
+         List exceptions = assembly.getApplicationExceptions();
+         if (exceptions.size() > 0)
          {
-            Iterator exceptionClasses = exceptionList.getClassList().iterator();
-            Iterator rollbacks = exceptionList.getRollbackList().iterator();
-            while (exceptionClasses.hasNext())
+            Iterator exceptionIterator = exceptions.iterator();
+            while (exceptionIterator.hasNext())
             {
-               String className = (String)exceptionClasses.next();
-               Boolean rollback = (Boolean)rollbacks.next();
-         
-               if (className.equals(exceptionClass.getName()))
-                  return new ApplicationExceptionImpl(rollback);
+               org.jboss.ejb3.metamodel.ApplicationException exception = (org.jboss.ejb3.metamodel.ApplicationException)exceptionIterator.next();
+               if (exception.getExceptionClass().equals(exceptionClass.getName()))
+                  return new ApplicationExceptionImpl(exception.getRollback());
             }
          }
          

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -31,6 +31,7 @@
 import org.jboss.aop.joinpoint.MethodJoinpoint;
 import org.jboss.aspects.tx.TxInterceptor;
 import org.jboss.logging.Logger;
+import org.jboss.tm.TransactionManagerLocator;
 import org.jboss.tm.TxManager;
 import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.ejb3.stateless.StatelessContainer;

Modified: branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -23,6 +23,8 @@
 
 import javax.ejb.TransactionManagement;
 import javax.ejb.TransactionManagementType;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import javax.transaction.TransactionManager;
 import org.jboss.aop.Advisor;
 import org.jboss.tm.TxManager;
@@ -35,9 +37,19 @@
  */
 public class TxUtil
 {
-   public static TransactionManager getTransactionManager()
+   public static TransactionManager getTransactionManager() throws RuntimeException
    {
-      return TxManager.getInstance();
+      try
+      {
+         //return TxManager.getInstance();
+         InitialContext jndiContext = new InitialContext();
+         TransactionManager tm = (TransactionManager)jndiContext.lookup("java:TransactionManager");
+         return tm;
+      } 
+      catch (NamingException e)
+      {
+         throw new RuntimeException("Unable to lookup TransactionManager", e);
+      }
    }
 
    public static TransactionManagementType getTransactionManagementType(Advisor c)

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsFieldInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsFieldInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsFieldInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,82 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.Field;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.mx.util.MBeanProxyExt;
+
+/**
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @version $Revision: 46510 $
+ */
+public class DependsFieldInjector implements Injector
+{
+   Field field;
+   ObjectName on;
+
+   public DependsFieldInjector(Field field, ObjectName on)
+   {
+      this.field = field;
+      this.on = on;
+      field.setAccessible(true);
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      Object instance = ctx.getInstance();
+      inject(instance);
+   }
+
+   public void inject(Object instance)
+   {
+      Class clazz = field.getType();
+      Object value = null;
+
+      if (clazz == ObjectName.class)
+      {
+         value = on;
+      }
+      else
+      {
+         MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);
+         value = MBeanProxyExt.create(clazz, on, server);
+      }
+
+      try
+      {
+         field.set(instance, value);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public Class getInjectionClass()
+   {
+      return field.getType();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,103 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.AccessibleObject;
+import java.util.Map;
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
+
+import org.jboss.annotation.ejb.Depends;
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+
+/**
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @version $Revision: 55144 $
+ */
+public class DependsHandler implements InjectionHandler
+{
+   private static final Logger log = Logger.getLogger(DependsHandler.class);
+
+   public void loadXml(EnvironmentRefGroup xml, InjectionContainer container)
+   {
+   }
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      Depends dep = container.getAnnotation(Depends.class, method.getDeclaringClass(), method);
+      if (dep != null)
+      {
+         if (!method.getName().startsWith("set"))
+            throw new RuntimeException("@EJB can only be used with a set method: " + method);
+         String[] names = dep.value();
+         if (names.length != 1)
+            throw new RuntimeException("@Depends on a field can only take one object name: " + method);
+         ObjectName on = null;
+         try
+         {
+            on = new ObjectName(names[0]);
+         }
+         catch (MalformedObjectNameException e)
+         {
+            throw new RuntimeException(e);
+         }
+         injectors.put(method, new DependsMethodInjector(method, on));
+         container.getDependencyPolicy().addDependency(names[0]);
+      }
+   }
+
+   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      Depends dep = container.getAnnotation(Depends.class, field.getDeclaringClass(), field);
+      if (dep != null)
+      {
+         String[] names = dep.value();
+         if (names.length != 1)
+            throw new RuntimeException("@Depends on a field can only take one object name: " + field);
+         ObjectName on = null;
+         try
+         {
+            on = new ObjectName(names[0]);
+         }
+         catch (MalformedObjectNameException e)
+         {
+            throw new RuntimeException(e);
+         }
+         injectors.put(field, new DependsFieldInjector(field, on));
+         container.getDependencyPolicy().addDependency(names[0]);
+      }
+   }
+
+   public void handleClassAnnotations(Class clazz, InjectionContainer container)
+   {
+      Depends dep = (Depends)container.getAnnotation(Depends.class, clazz);
+      if (dep == null) return;
+      for (String dependency : dep.value())
+      {
+         container.getDependencyPolicy().addDependency(dependency);
+      }
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsMethodInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsMethodInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/DependsMethodInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,87 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.mx.util.MBeanProxyExt;
+
+/**
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @version $Revision: 46510 $
+ */
+public class DependsMethodInjector implements Injector
+{
+   Method method;
+   ObjectName on;
+
+   public DependsMethodInjector(Method method, ObjectName on)
+   {
+      this.method = method;
+      this.on = on;
+      method.setAccessible(true);
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      Object instance = ctx.getInstance();
+      inject(instance);
+   }
+
+   public void inject(Object instance)
+   {
+      Class clazz = method.getParameterTypes()[0];
+      Object value = null;
+
+      if (clazz == ObjectName.class)
+      {
+         value = on;
+      }
+      else
+      {
+         MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);
+         value = MBeanProxyExt.create(clazz, on, server);
+      }
+
+      try
+      {
+         method.invoke(instance, value);
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public Class getInjectionClass()
+   {
+      return method.getParameterTypes()[0];
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBContextFieldInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBContextFieldInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBContextFieldInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,69 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.Field;
+import org.jboss.ejb3.BeanContext;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class EJBContextFieldInjector implements Injector, PojoInjector
+{
+   private Field field;
+
+   public EJBContextFieldInjector(Field field)
+   {
+      this.field = field;
+      field.setAccessible(true);
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      inject(ctx, ctx.getInstance());
+   }
+   
+   public void inject(BeanContext ctx, Object instance)
+   {
+      try
+      {
+         field.set(instance, ctx.getEJBContext());
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public void inject(Object instance)
+   {
+      throw new RuntimeException("Illegal operation");
+   }
+
+   public Class getInjectionClass()
+   {
+      return field.getType();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBContextMethodInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBContextMethodInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBContextMethodInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,81 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import org.jboss.ejb3.BeanContext;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class EJBContextMethodInjector implements Injector, PojoInjector
+{
+   private Method setMethod;
+
+   public EJBContextMethodInjector(Method setMethod)
+   {
+      this.setMethod = setMethod;
+      setMethod.setAccessible(true);
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      inject(ctx, ctx.getInstance());
+   }
+   
+   public void inject(BeanContext ctx, Object instance)
+   {
+
+      Object[] args = {ctx.getEJBContext()};
+      try
+      {
+         setMethod.invoke(instance, args);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RuntimeException("Failed in setting EntityManager on setter method: " + setMethod.toString());
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RuntimeException(e.getCause());  //To change body of catch statement use Options | File Templates.
+      }
+   }
+
+   public void inject(Object instance)
+   {
+      throw new RuntimeException("Illegal operation");
+   }
+
+  
+   public Class getInjectionClass()
+   {
+      return setMethod.getParameterTypes()[0];
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EJBHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,407 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import org.jboss.annotation.IgnoreDependency;
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.BaseEjbRef;
+import org.jboss.metamodel.descriptor.EjbLocalRef;
+import org.jboss.metamodel.descriptor.EjbRef;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+
+import javax.ejb.EJB;
+import javax.ejb.EJBs;
+import javax.naming.NameNotFoundException;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Searches bean class for all @Inject and create Injectors
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56489 $
+ */
+public class EJBHandler implements InjectionHandler
+{
+   private static final Logger log = Logger.getLogger(EJBHandler.class);
+
+   protected void addDependency(String refName, EJBContainer refcon, InjectionContainer container)
+   {
+      // Do not depend on myself
+      if(!container.equals(refcon))
+         container.getDependencyPolicy().addDependency(refcon.getObjectName().getCanonicalName());
+   }
+
+   public void loadXml(EnvironmentRefGroup xml, InjectionContainer container)
+   {
+      if (xml != null)
+      {
+         if (xml.getEjbLocalRefs() != null) loadEjbLocalXml(xml.getEjbLocalRefs(), container);
+         if (xml.getEjbRefs() != null) loadEjbRefXml(xml.getEjbRefs(), container);
+      }
+   }
+
+   protected void loadEjbLocalXml(Collection<EjbLocalRef> refs, InjectionContainer container)
+   {
+      for (EjbLocalRef ref : refs)
+      {
+         String interfaceName = ref.getLocal();
+         String errorType = "<ejb-local-ref>";
+
+         ejbRefXml(ref, interfaceName, container, errorType);
+      }
+   }
+
+   protected void loadEjbRefXml(Collection<EjbRef> refs, InjectionContainer container)
+   {
+      for (EjbRef ref : refs)
+      {
+         String interfaceName = ref.getRemote();
+         String errorType = "<ejb-ref>";
+
+         ejbRefXml(ref, interfaceName, container, errorType);
+      }
+   }
+
+   protected void ejbRefXml(BaseEjbRef ref, String interfaceName, InjectionContainer container, String errorType)
+   {
+      String encName = "env/" + ref.getEjbRefName();
+      InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
+      if (container.getEncInjectors().containsKey(encName))
+         return;
+
+      String mappedName = ref.getMappedName();
+      if (mappedName != null && mappedName.equals("")) mappedName = null;
+
+      String link = ref.getEjbLink();
+      if (link != null && link.trim().equals("")) link = null;
+
+      Class refClass = null;
+
+      if (interfaceName != null)
+      {
+         try
+         {
+            refClass = container.getClassloader().loadClass(interfaceName);
+         }
+         catch (ClassNotFoundException e)
+         {
+            throw new RuntimeException("could not find " + errorType + "'s local interface " + interfaceName + " in " + container.getDeploymentDescriptorType() + " of " + container.getIdentifier());
+         }
+      }
+      
+      //----- injectors
+
+      if (mappedName == null && refClass == null && link == null)
+      {
+         // must be jboss.xml only with @EJB used to define reference.  jboss.xml used to tag for ignore dependency
+         // i think it is ok to assume this because the ejb-jar.xml schema should handle any missing elements
+      }
+      else
+      {
+         ejbRefEncInjector(mappedName, encName, refClass, link, errorType, container);
+         if (ref.isIgnoreDependency())
+         {
+            log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+            return;
+         }
+
+         ejbRefDependency(link, container, refClass, errorType, encName);
+      }
+   }
+
+   protected void ejbRefDependency(String link, InjectionContainer container, Class refClass, String errorType, String encName)
+   {
+      EJBContainer refcon = null;
+
+      if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class))) refClass = null;
+
+      if (refClass != null)
+      {
+         if (link != null && !link.trim().equals(""))
+         {
+            refcon = (EJBContainer) container.resolveEjbContainer(link, refClass);
+            if (refcon == null)
+            {
+               String msg = "IGNORING DEPENDENCY: unable to find " + errorType + " of interface " + refClass.getName() + " and ejbLink of " + link + " in  " + container.getDeploymentDescriptorType() + " of " + container.getIdentifier() + " it might not be deployed yet";
+               log.warn(msg);
+            }
+         }
+         else
+         {
+            try
+            {
+               refcon = (EJBContainer) container.resolveEjbContainer(refClass);
+               if (refcon == null)
+               {
+                  String msg = "IGNORING DEPENDENCY: unable to find " + errorType + " from interface only " + refClass.getName() + " in " + container.getDeploymentDescriptorType() + " of " + container.getIdentifier();
+                  log.warn(msg);
+               }
+            }
+            catch (NameNotFoundException e)
+            {
+               String msg = "IGNORING DEPENDENCY: unable to find " + errorType + " from interface only " + refClass.getName() + " in " + container.getDeploymentDescriptorType() + " of " + container.getIdentifier() + e.getMessage();
+               log.warn(msg);
+            }
+         }
+      }
+      else
+      {
+         String msg = "IGNORING DEPENDENCY: unable to resolve dependency of EJB, there is too little information";
+         log.warn(msg);
+      }
+
+      if (refcon != null)
+      {
+         addDependency(encName, refcon, container);
+      }
+   }
+
+   protected void ejbRefEncInjector(String mappedName, String encName, Class refClass, String link, String errorType, InjectionContainer container)
+   {
+      if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class))) refClass = null;
+      if (mappedName != null && mappedName.trim().equals("")) mappedName = null;
+
+      EncInjector injector = null;
+
+      if (mappedName == null)
+      {
+         injector = new EjbEncInjector(encName, refClass, link, errorType);
+      }
+      else
+      {
+         injector = new EjbEncInjector(encName, mappedName, errorType);
+      }
+
+      container.getEncInjectors().put(encName, injector);
+   }
+
+   public static EJBContainer getEjbContainer(EJB ref, InjectionContainer container, Class memberType)
+   {
+      EJBContainer rtn = null;
+
+      if (ref.mappedName() != null && !"".equals(ref.mappedName()))
+      {
+         return null;
+      }
+
+      if (ref.beanName().equals("") && memberType == null)
+         throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB.  Please fill out the beanName and/or businessInterface attributes");
+
+      Class businessInterface = memberType;
+      if (!ref.beanInterface().getName().equals(Object.class.getName()))
+      {
+         businessInterface = ref.beanInterface();
+      }
+
+      if (ref.beanName().equals(""))
+      {
+         try
+         {
+            rtn = (EJBContainer) container.resolveEjbContainer(businessInterface);
+         }
+         catch (NameNotFoundException e)
+         {
+            log.warn("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ") " + e.getMessage());
+         }
+      }
+      else
+      {
+         rtn = (EJBContainer) container.resolveEjbContainer(ref.beanName(), businessInterface);
+      }
+
+      return rtn;
+   }
+
+   public static String getJndiName(EJB ref, InjectionContainer container, Class memberType)
+   {
+      String jndiName;
+
+      if (ref.mappedName() != null && !"".equals(ref.mappedName()))
+      {
+         return ref.mappedName();
+      }
+
+      if (ref.beanName().equals("") && memberType == null)
+         throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB.  Please fill out the beanName and/or businessInterface attributes");
+
+      Class businessInterface = memberType;
+      if (!ref.beanInterface().getName().equals(Object.class.getName()))
+      {
+         businessInterface = ref.beanInterface();
+      }
+
+      if (ref.beanName().equals(""))
+      {
+         try
+         {
+            jndiName = container.getEjbJndiName(businessInterface);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ") " + e.getMessage());
+         }
+         if (jndiName == null)
+         {
+            throw new RuntimeException("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ")");
+         }
+      }
+      else
+      {
+         jndiName = container.getEjbJndiName(ref.beanName(), businessInterface);
+         if (jndiName == null)
+         {
+            throw new RuntimeException("For EJB " + container.getIdentifier() + "could not find jndi binding based on beanName and business interface for @EJB(" + ref.beanName() + ", " + businessInterface.getName() + ")");
+         }
+      }
+
+      return jndiName;
+   }
+
+   public void handleClassAnnotations(Class clazz, InjectionContainer container)
+   {
+      EJBs ref = container.getAnnotation(EJBs.class, clazz);
+      if (ref != null)
+      {
+         EJB[] ejbs = ref.value();
+
+         for (EJB ejb : ejbs)
+         {
+            handleClassAnnotation(ejb, clazz, container);
+         }
+      }
+      EJB ejbref = container.getAnnotation(EJB.class, clazz);
+      if (ejbref != null) handleClassAnnotation(ejbref, clazz, container);
+   }
+
+   protected void handleClassAnnotation(EJB ejb, Class clazz, InjectionContainer container)
+   {
+      String encName = ejb.name();
+      if (encName == null || encName.equals(""))
+      {
+         throw new RuntimeException("JBoss requires the name of the @EJB in the @EJBs: " + clazz);
+      }
+      encName = "env/" + encName;
+
+      if (container.getEncInjectors().containsKey(encName)) return;
+      ejbRefEncInjector(ejb.mappedName(), encName, ejb.beanInterface(), ejb.beanName(), "@EJB", container);
+
+      // handle dependencies
+
+      if (isIgnoreDependency(container, ejb))
+         log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+      else
+         ejbRefDependency(ejb.beanName(), container, ejb.beanInterface(), "@EJB", encName);
+   }
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      
+      EJB ref = method.getAnnotation(EJB.class);
+      if (ref != null)
+      {
+         if (!method.getName().startsWith("set"))
+            throw new RuntimeException("@EJB can only be used with a set method: " + method);
+         String encName = ref.name();
+         if (encName == null || encName.equals(""))
+         {
+            encName = InjectionUtil.getEncName(method);
+         }
+         else
+         {
+            encName = "env/" + encName;
+         }
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            ejbRefEncInjector(ref.mappedName(), encName, method.getParameterTypes()[0], ref.beanName(), "@EJB", container);
+            
+            if (container.getAnnotation(IgnoreDependency.class, method) == null)
+            {
+               if (isIgnoreDependency(container, ref))
+                  log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+               else
+                  ejbRefDependency(ref.beanName(), container, method.getParameterTypes()[0], "@EJB", encName);
+            }
+         }
+
+         injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
+      }
+   }
+
+   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      EJB ref = field.getAnnotation(EJB.class);
+      if (ref != null)
+      {
+         String encName = ref.name();
+         if (encName == null || encName.equals(""))
+         {
+            encName = InjectionUtil.getEncName(field);
+         }
+         else
+         {
+            encName = "env/" + encName;
+         }
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            if (container.getAnnotation(IgnoreDependency.class, field) == null)
+            {
+               if (isIgnoreDependency(container, ref))
+                  log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+               else
+                  ejbRefDependency(ref.beanName(), container, field.getType(), "@EJB", encName);
+            }
+            ejbRefEncInjector(ref.mappedName(), encName, field.getType(), ref.beanName(), "@EJB", container);
+         }
+         injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
+
+      }
+   }
+
+   protected boolean isIgnoreDependency(InjectionContainer container, EJB ref)
+   {
+      EnvironmentRefGroup refGroup =  (EnvironmentRefGroup)container.getEnvironmentRefGroup();
+      
+      if (refGroup != null)
+      {
+         Iterator<EjbRef> ejbRefs = refGroup.getEjbRefs().iterator();
+         while (ejbRefs.hasNext())
+         {
+            EjbRef ejbRef = ejbRefs.next();
+            if (ejbRef.getEjbRefName().equals(ref.name()))
+            {
+               if (ejbRef.isIgnoreDependency())
+                  return true;
+               else
+                  return false;
+            }
+         }
+      }
+      
+      return false;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EjbEncInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EjbEncInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EjbEncInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,102 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.injection;
+
+import org.jboss.logging.Logger;
+import org.jboss.naming.Util;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.LinkRef;
+import javax.naming.NamingException;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56518 $
+ */
+public class EjbEncInjector implements EncInjector
+{
+   private static final Logger log = Logger.getLogger(EjbEncInjector.class);
+   
+   private String ejbLink;
+   private Class refClass;
+   private String jndiName;
+   private String error;
+   private String encName;
+
+   public EjbEncInjector(String name, String mappedName, String error)
+   {
+      this.jndiName = mappedName;
+      this.error = error;
+      this.encName = name;
+   }
+
+   public EjbEncInjector(String name, Class refClass, String ejbLink, String error)
+   {
+      this.refClass = refClass;
+      String refClassName = refClass == null ? "NULL" : refClass.getName();
+      this.ejbLink = ejbLink;
+      this.error = error;
+      this.encName = name;
+      if (refClass == null && ejbLink == null) throw new RuntimeException("cannot have null refClass and ejbLink for encName: " + name);
+   }
+
+
+   public void inject(InjectionContainer container)
+   {
+      if (jndiName == null || jndiName.equals(""))
+      {
+         if (ejbLink != null && !"".equals(ejbLink))
+         {
+            jndiName = container.getEjbJndiName(ejbLink, refClass);
+         }
+         else
+         {
+            try
+            {
+               if (refClass != null)
+               {
+                  jndiName = container.getEjbJndiName(refClass);
+               }
+               else
+               {
+                  throw new RuntimeException("searching for @EJB" + encName + " has null refClass and null ejbLink.");
+               }
+            }
+            catch (NameNotFoundException e)
+            {
+               throw new RuntimeException("could not resolve global JNDI name for " + error + " for container " + container.getIdentifier() + ": reference class: " + refClass.getName() + " ejbLink: " + ejbLink + " " + e.getMessage());
+            }
+         }
+      }
+      try
+      {
+         if (jndiName == null) throw new RuntimeException("Failed to populate ENC: " + encName + " global jndi name was null");
+         Util.rebind(container.getEnc(), encName, new LinkRef(jndiName));
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException("could not bind enc name '" +  encName + "' for " + error + " for container " + container.getIdentifier() + ": reference class: " + refClass.getName() + " ejbLink: " + ejbLink + " " + e.getMessage());
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EncInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EncInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EncInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.injection;
+
+/**
+ * Responsible for populating ENC
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public interface EncInjector
+{
+   void inject(InjectionContainer container);
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EntityManagerFactoryFieldInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EntityManagerFactoryFieldInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EntityManagerFactoryFieldInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,78 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.Field;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class EntityManagerFactoryFieldInjector implements Injector, PojoInjector
+{
+   private static final Logger log = Logger.getLogger(EntityManagerFactoryFieldInjector.class);
+   private Field field;
+   private Object factory;
+
+   public EntityManagerFactoryFieldInjector(Field field, Object factory)
+   {
+      this.field = field;
+      this.field.setAccessible(true);
+      this.factory = factory;
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      inject(ctx, ctx.getInstance());
+   }
+   
+   public void inject(BeanContext ctx, Object instance)
+   {
+      inject(instance);
+   }
+
+   public void inject(Object instance)
+   {
+      try
+      {
+         field.set(instance, factory);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RuntimeException("Failed in setting EntityManager on setter field: " + field.toString());
+      }
+   }
+
+   public Class getInjectionClass()
+   {
+      return field.getType();
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EntityManagerFactoryMethodInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EntityManagerFactoryMethodInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EntityManagerFactoryMethodInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,83 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class EntityManagerFactoryMethodInjector implements Injector, PojoInjector
+{
+   private static final Logger log = Logger.getLogger(EntityManagerFactoryMethodInjector.class);
+   private Method setMethod;
+   private Object factory;
+
+   public EntityManagerFactoryMethodInjector(Method setMethod, Object factory)
+   {
+      this.setMethod = setMethod;
+      setMethod.setAccessible(true);
+      this.factory = factory;
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      inject(ctx, ctx.getInstance());
+   }
+   
+   public void inject(BeanContext ctx, Object instance)
+   {
+      inject(instance);
+   }
+
+   public void inject(Object instance)
+   {
+      try
+      {
+         Object[] args = {factory};
+         setMethod.invoke(instance, args);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RuntimeException("Failed in setting EntityManager on setter method: " + setMethod.toString());
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RuntimeException(e.getCause());  //To change body of catch statement use Options | File Templates.
+      }
+   }
+
+   public Class getInjectionClass()
+   {
+      return setMethod.getParameterTypes()[0];
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EnvEntryEncInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EnvEntryEncInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/EnvEntryEncInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,120 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.injection;
+
+import org.jboss.logging.Logger;
+import org.jboss.naming.Util;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56518 $
+ */
+public class EnvEntryEncInjector implements EncInjector
+{
+   private static final Logger log = Logger.getLogger(EnvEntryEncInjector.class);
+
+   private String name;
+   private String entryType;
+   private String value;
+
+
+   public EnvEntryEncInjector(String encName, String entryType, String value)
+   {
+      this.name = encName;
+      this.entryType = entryType;
+      this.value = value;
+   }
+
+   public void inject(InjectionContainer container)
+   {
+      try
+      {
+         Util.rebind(container.getEnc(),
+                 name,
+                 getEnvEntryValue());
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Invalid <env-entry> name: " + name, e);
+      }
+   }
+
+
+   protected Object getEnvEntryValue() throws ClassNotFoundException
+   {
+      Class type = Thread.currentThread().getContextClassLoader().loadClass(entryType);
+      if (type == String.class)
+      {
+         return value;
+      }
+      else if (type == Integer.class)
+      {
+         return new Integer(value);
+      }
+      else if (type == Long.class)
+      {
+         return new Long(value);
+      }
+      else if (type == Double.class)
+      {
+         return new Double(value);
+      }
+      else if (type == Float.class)
+      {
+         return new Float(value);
+      }
+      else if (type == Byte.class)
+      {
+         return new Byte(value);
+      }
+      else if (type == Character.class)
+      {
+         String input = value;
+         if (input == null || input.length() == 0)
+         {
+            return new Character((char) 0);
+         }
+         else
+         {
+            if (input.length() > 1)
+               // TODO: Add deployment context
+               log.warn("Warning character env-entry is too long: binding="
+                       + name + " value=" + input);
+            return new Character(input.charAt(0));
+         }
+      }
+      else if (type == Short.class)
+      {
+         return new Short(value);
+      }
+      else if (type == Boolean.class)
+      {
+         return new Boolean(value);
+      }
+      else
+      {
+         return value;
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ExtendedPersistenceContextInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ExtendedPersistenceContextInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ExtendedPersistenceContextInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,72 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import javax.persistence.EntityManager;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class ExtendedPersistenceContextInjector implements Injector, PojoInjector
+{
+   protected static final Logger log = Logger.getLogger(ExtendedPersistenceContextInjector.class);
+   protected ManagedEntityManagerFactory factory;
+
+   protected ExtendedPersistenceContextInjector(ManagedEntityManagerFactory factory)
+   {
+      this.factory = factory;
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      inject(ctx, ctx.getInstance());
+   }
+
+   public void inject(BeanContext beanContext, Object instance)
+   {
+      StatefulBeanContext ctx = (StatefulBeanContext)beanContext;
+      EntityManager pc = ctx.getExtendedPersistenceContext(factory.getKernelName());
+      if (pc == null)
+      {
+         pc = factory.createEntityManager();
+         ctx.addExtendedPersistenceContext(factory.getKernelName(), pc);
+      }
+   }
+
+   public void inject(Object instance)
+   {
+      throw new RuntimeException("Illegal operation");
+   }
+
+   public Class getInjectionClass()
+   {
+      return null;
+   }
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionContainer.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionContainer.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionContainer.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,119 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.injection;
+
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.DependencyPolicy;
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import java.util.Map;
+import java.util.List;
+import java.lang.reflect.Method;
+import java.lang.reflect.Field;
+import java.lang.reflect.AccessibleObject;
+
+/**
+ * This is the container that manages all injections.  Could be an EJB Container
+ * or a WAR.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56037 $
+ */
+public interface InjectionContainer
+{
+   /**
+    * Some identifier that can be used in error messages
+    *
+    * @return
+    */
+   String getIdentifier();
+
+   /**
+    * For error messages
+    *
+    * @return  ejb-jar.xml, web.xml, etc..
+    */
+   String getDeploymentDescriptorType();
+
+   ClassLoader getClassloader();
+
+   Map<String, EncInjector> getEncInjectors();
+   Map<String, Map<AccessibleObject, Injector>> getEncInjections();
+
+   // EncInjectors/Handlers may need to add extra instance injectors
+   List<Injector> getInjectors();
+
+   Context getEnc();
+   Context getEncEnv();
+
+
+   PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException;
+
+   Container resolveEjbContainer(String link, Class businessIntf);
+   Container resolveEjbContainer(Class businessIntf) throws NameNotFoundException;
+   String getEjbJndiName(Class businessInterface) throws NameNotFoundException;
+   String getEjbJndiName(String link, Class businessInterface);
+
+   /**
+    * If class has container overridable annotations, this method will
+    * discover those overriden annotations.
+    *
+    * @param annotationType
+    * @param clazz
+    * @return
+    */
+   <T> T getAnnotation(Class<T> annotationType, Class clazz);
+   
+   /**
+    * If class has container overridable annotations, this method will
+    * discover those overriden annotations.
+
+    * @param annotationType
+    * @param clazz
+    * @param method
+    * @return
+    */
+   <T> T getAnnotation(Class<T> annotationType, Class clazz, Method method);
+   
+   <T> T getAnnotation(Class<T> annotationType, Method method);
+
+   /**
+    * If class has container overridable annotations, this method will
+    * discover those overriden annotations.
+
+    * @param annotationType
+    * @param clazz
+    * @param field
+    * @return
+    */
+   <T> T getAnnotation(Class<T> annotationType, Class clazz, Field field);
+   
+   <T> T getAnnotation(Class<T> annotationType, Field field);
+
+   DependencyPolicy getDependencyPolicy();
+   
+   EnvironmentRefGroup getEnvironmentRefGroup();
+   
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.injection;
+
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public interface InjectionHandler
+{
+   public void loadXml(EnvironmentRefGroup xml, InjectionContainer container);
+   public void handleClassAnnotations(Class clazz, InjectionContainer container);
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors);
+   public void handleFieldAnnotations(Field Field, InjectionContainer container, Map<AccessibleObject, Injector> injectors);
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionUtil.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionUtil.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/InjectionUtil.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,291 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.InjectionTarget;
+import org.jboss.metamodel.descriptor.Ref;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56046 $
+ */
+public class InjectionUtil
+{
+   private static final Logger log = Logger
+           .getLogger(InjectionUtil.class);
+
+
+   /**
+    * This method will take a set of XML loaded injectors and collapse them based on spec inheritance rules
+    * It will remove injectors that should not be used in the injection of the base component class.
+    *
+    * @param visitedMethods
+    * @param clazz
+    * @param xmlDefinedInjectors
+    * @param classInjectors
+    */
+   public static void collapseXmlMethodInjectors(Set<String> visitedMethods, Class clazz, Map<String, Map<AccessibleObject, Injector>> xmlDefinedInjectors, Map<AccessibleObject, Injector> classInjectors)
+   {
+      if (clazz == null || clazz.equals(Object.class))
+      {
+         return;
+      }
+      Map<AccessibleObject, Injector> xmlInjectors = xmlDefinedInjectors.get(clazz.getName());
+      if (xmlInjectors != null)
+      {
+         Method[] methods = clazz.getDeclaredMethods();
+         for (Method method : methods)
+         {
+            if (method.getParameterTypes().length != 1) continue;
+
+            if (!Modifier.isPrivate(method.getModifiers()))
+            {
+               if (visitedMethods.contains(method.getName()))
+               {
+                  xmlInjectors.remove(method); // if not private then it has been overriden
+                  continue;
+               }
+               visitedMethods.add(method.getName());
+            }
+         }
+         classInjectors.putAll(xmlInjectors);
+      }
+      // recursion needs to come last as the method could be overriden and we don't want the overriding method to be ignored
+      collapseXmlMethodInjectors(visitedMethods, clazz.getSuperclass(), xmlDefinedInjectors, classInjectors);
+   }
+
+   public static void processMethodAnnotations(InjectionContainer container, Collection<InjectionHandler> handlers, Set<String> visitedMethods, Class clazz, Map<AccessibleObject, Injector> classInjectors)
+   {
+      if (clazz == null || clazz.equals(Object.class))
+      {
+         return;
+      }
+      Method[] methods = clazz.getDeclaredMethods();
+      for (Method method : methods)
+      {
+         if (method.getParameterTypes().length != 1) continue;
+
+         if (!Modifier.isPrivate(method.getModifiers()))
+         {
+            if (visitedMethods.contains(method.getName()))
+            {
+               continue;
+            }
+            visitedMethods.add(method.getName());
+         }
+        
+         if (handlers != null)
+         {
+            for (InjectionHandler handler : handlers)
+            {
+               handler.handleMethodAnnotations(method, container, classInjectors);
+            }
+         }
+      }
+      // recursion needs to come last as the method could be overriden and we don't want the overriding method to be ignored
+      processMethodAnnotations(container, handlers, visitedMethods, clazz.getSuperclass(), classInjectors);
+   }
+
+   public static void processFieldAnnotations(InjectionContainer container, Collection<InjectionHandler> handlers, Class clazz, Map<AccessibleObject, Injector> classInjectors)
+   {
+      if (clazz == null || clazz.equals(Object.class))
+      {
+         return;
+      }
+ 
+      if (handlers != null)
+      {
+         Field[] fields = clazz.getDeclaredFields();
+         for (Field field : fields)
+         {
+            for (InjectionHandler handler : handlers)
+            {
+               handler.handleFieldAnnotations(field, container, classInjectors);
+            }
+         }
+      }
+      
+      // recursion needs to come last as the method could be overriden and we don't want the overriding method to be ignored
+      processFieldAnnotations(container, handlers, clazz.getSuperclass(), classInjectors);
+   }
+
+   public static void processClassAnnotations(InjectionContainer container, Collection<InjectionHandler> handlers, Class clazz)
+   {
+      if (clazz == null || clazz.equals(Object.class))
+      {
+         return;
+      }
+    
+      if (handlers != null)
+      {
+         for (InjectionHandler handler : handlers)
+         {
+            handler.handleClassAnnotations(clazz, container);
+         }
+      }
+      
+      // recursion needs to come last as the method could be overriden and we don't want the overriding method to be ignored
+      processClassAnnotations(container, handlers, clazz.getSuperclass());
+   }
+
+   public static Map<AccessibleObject, Injector> processAnnotations(InjectionContainer container, Collection<InjectionHandler> handlers, Class clazz)
+   {
+      Map<AccessibleObject, Injector> classInjectors = new HashMap<AccessibleObject, Injector>();
+      HashSet<String> visitedMethods = new HashSet<String>();
+      collapseXmlMethodInjectors(visitedMethods, clazz, container.getEncInjections(), classInjectors);
+
+      processClassAnnotations(container, handlers, clazz);
+      visitedMethods = new HashSet<String>();
+      processMethodAnnotations(container, handlers, visitedMethods, clazz, classInjectors);
+      processFieldAnnotations(container, handlers, clazz, classInjectors);
+      return classInjectors;
+   }
+
+   public static AccessibleObject findInjectionTarget(ClassLoader loader, InjectionTarget target)
+   {
+      Class clazz = null;
+      try
+      {
+         clazz = loader.loadClass(target.getTargetClass());
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new RuntimeException("<injection-target> class: " + target.getTargetClass() + " was not found nin deployment");
+      }
+
+      for (Field field : clazz.getDeclaredFields())
+      {
+         if (target.getTargetName().equals(field.getName())) return field;
+      }
+
+      for (java.lang.reflect.Method method : clazz.getDeclaredMethods())
+      {
+         if (method.getName().equals(target.getTargetName())) return method;
+      }
+
+      throw new RuntimeException("<injection-target> could not be found: " + target.getTargetClass() + "." + target.getTargetName());
+
+   }
+
+   public static String getEncName(Method method)
+   {
+      String encName = method.getName().substring(3);
+      if (encName.length() > 1)
+      {
+         encName = encName.substring(0, 1).toLowerCase() + encName.substring(1);
+      }
+      else
+      {
+         encName = encName.toLowerCase();
+      }
+
+      encName = "env/" + method.getDeclaringClass().getName() + "/" + encName;
+      return encName;
+   }
+
+   public static String getEncName(Field field)
+   {
+      return "env/" + field.getDeclaringClass().getName() + "/" + field.getName();
+   }
+
+   public static Object getAnnotation(Class annotation, EJBContainer container, Class annotatedClass, boolean isContainer)
+   {
+      if (isContainer)
+      {
+         return container.resolveAnnotation(annotation);
+      }
+      else
+      {
+         return annotatedClass.getAnnotation(annotation);
+      }
+   }
+
+   public static Object getAnnotation(Class annotation, EJBContainer container, Method method, boolean isContainer)
+   {
+      if (isContainer)
+      {
+         return container.resolveAnnotation(method, annotation);
+      }
+      else
+      {
+         return method.getAnnotation(annotation);
+      }
+   }
+
+   public static Object getAnnotation(Class annotation, EJBContainer container, Field field, boolean isContainer)
+   {
+      if (isContainer)
+      {
+         return container.resolveAnnotation(field, annotation);
+      }
+      else
+      {
+         return field.getAnnotation(annotation);
+      }
+   }
+
+   public static Class injectionTarget(String encName, Ref ref, InjectionContainer container, Map<String, Map<AccessibleObject, Injector>> classInjectors)
+   {
+      if (ref.getInjectionTarget() != null)
+      {
+         Class injectionType;
+         // todo, get injection target class
+         AccessibleObject ao = findInjectionTarget(container.getClassloader(), ref.getInjectionTarget());
+         Map<AccessibleObject, Injector> injectors = classInjectors.get(ref.getInjectionTarget().getTargetClass());
+         if (injectors == null)
+         {
+            injectors = new HashMap<AccessibleObject, Injector>();
+            classInjectors.put(ref.getInjectionTarget().getTargetClass().trim(), injectors);
+         }
+         if (ao instanceof Field)
+         {
+            injectionType = ((Field) ao).getType();
+            injectors.put(ao, new JndiFieldInjector((Field) ao, encName, container.getEnc()));
+         }
+         else
+         {
+            injectionType = ((Method) ao).getParameterTypes()[0];
+            injectors.put(ao, new JndiMethodInjector((Method) ao, encName, container.getEnc()));
+         }
+         return injectionType;
+      }
+      else
+      {
+         return null;
+      }
+
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/Injector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/Injector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/Injector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,39 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import org.jboss.ejb3.BeanContext;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public interface Injector
+{
+   void inject(BeanContext ctx);
+
+   void inject(Object instance);
+   
+   Class getInjectionClass();
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiFieldInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,142 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.Field;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.jboss.logging.Logger;
+
+import org.jboss.ejb3.BeanContext;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56038 $
+ */
+public class JndiFieldInjector implements Injector, PojoInjector
+{
+   private static final Logger log = Logger.getLogger(JndiFieldInjector.class);
+   
+   private Field field;
+   private String jndiName;
+   private Context ctx;
+
+   public JndiFieldInjector(Field field, String jndiName, Context ctx)
+   {
+      this.field = field;
+      this.field.setAccessible(true);
+      this.jndiName = jndiName;
+      this.ctx = ctx;
+   }
+
+   public JndiFieldInjector(Field field, Context ctx)
+   {
+      this(field, field.getName(), ctx);
+   }
+
+   public void inject(BeanContext bctx)
+   {
+      inject(bctx, bctx.getInstance());
+   }
+
+   public Class getInjectionClass()
+   {
+      return field.getType();
+   }
+
+   public Field getField()
+   {
+      return field;
+   }
+
+   protected Object lookup(String jndiName, Class field)
+   {
+      Object dependency = null;
+
+      try
+      {
+         dependency = ctx.lookup(jndiName);
+
+         if (dependency instanceof javax.xml.rpc.Service && !field.isAssignableFrom(javax.xml.rpc.Service.class))
+         {
+            javax.xml.rpc.Service service = (javax.xml.rpc.Service)dependency;
+            dependency = service.getPort(field);
+         }
+      }
+      catch (NamingException e)
+      {
+         e.printStackTrace();
+         throw new RuntimeException("Unable to inject jndi dependency: " + jndiName + " into field " + field, e);
+      }
+      catch (javax.xml.rpc.ServiceException e)
+      {
+         e.printStackTrace();
+         throw new RuntimeException("Unable to inject jndi webservice dependency: " + jndiName + " into field " + field, e);
+      }
+      
+      return dependency;
+   }
+   
+   public void inject(BeanContext bctx, Object instance)
+   {
+      inject(instance);
+   }
+
+   public void inject(Object instance)
+   {
+      
+      Object dependency = lookup(jndiName, field.getType());
+ //     log.info("!! inject jndiName " + jndiName + " " + field.getType() + " " + dependency);
+      
+      try
+      {
+ //        log.info("!!! inject " + instance + " " + field.getType() + " " + dependency.getClass());
+ //        Class[] interfacs = dependency.getClass().getInterfaces();
+ //        for (Class interfac : interfacs)
+ //           log.info("!! interface " + interfac);
+         field.set(instance, dependency);
+      }
+      catch (IllegalArgumentException e)
+      {
+         String type = "UNKNOWN";
+         String interfaces = "";
+         if (dependency != null)
+         {
+ //           log.info("!!! inject failed " + instance + " " + field.getType() + " " + dependency.getClass());
+ //           Class[] interfacs = dependency.getClass().getInterfaces();
+ //           for (Class interfac : interfacs)
+ //              log.info("!! interface " + interfac);
+            type = dependency.getClass().getName();
+            Class[] intfs = dependency.getClass().getInterfaces();
+            for (Class intf : intfs) interfaces += ", " + intf.getName();
+         }
+         throw new RuntimeException("Non matching type for inject of field: " + field + " for type: " + type + " of jndiName " + jndiName + "\nintfs: " + interfaces, e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiInjectHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiInjectHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiInjectHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,96 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import org.jboss.annotation.JndiInject;
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+import org.jboss.metamodel.descriptor.JndiRef;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * Searches bean class for all @Inject and create Injectors
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 55144 $
+ */
+public class JndiInjectHandler implements InjectionHandler
+{
+   private static final Logger log = Logger.getLogger(JndiInjectHandler.class);
+   
+   public void loadXml(EnvironmentRefGroup xml, InjectionContainer container)
+   {
+      if (xml == null) return;
+      if (xml.getJndiRefs() == null) return;
+      for (JndiRef ref : xml.getJndiRefs())
+      {
+         if (ref.getMappedName() == null || ref.getMappedName().equals(""))
+            throw new RuntimeException("mapped-name is required for " + ref.getJndiRefName() + " of container " + container.getIdentifier());
+
+         String encName = "env/" + ref.getJndiRefName();
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.getMappedName(), "jndi ref"));
+         }
+         InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
+      }
+   }
+
+   public void handleClassAnnotations(Class clazz, InjectionContainer container)
+   {
+      // complete
+   }
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      JndiInject ref = method.getAnnotation(JndiInject.class);
+      if (ref != null)
+      {
+         if (!method.getName().startsWith("set"))
+            throw new RuntimeException("@EJB can only be used with a set method: " + method);
+         String encName = InjectionUtil.getEncName(method);
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.jndiName(), "@JndiInject"));
+         }
+         injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
+      }
+   }
+   
+   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      JndiInject ref = field.getAnnotation(JndiInject.class);
+      if (ref != null)
+      {
+         String encName = InjectionUtil.getEncName(field);
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.jndiName(), "@JndiInject"));
+         }
+         injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiMethodInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiMethodInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/JndiMethodInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,120 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class JndiMethodInjector implements Injector, PojoInjector
+{
+   private static final Logger log = Logger.getLogger(JndiMethodInjector.class);
+   
+   private Method setMethod;
+   private String jndiName;
+   private Context ctx;
+
+   public JndiMethodInjector(Method setMethod, String jndiName, Context ctx)
+   {
+      this.setMethod = setMethod;
+      setMethod.setAccessible(true);
+      this.jndiName = jndiName;
+      this.ctx = ctx;
+   }
+
+   public void inject(BeanContext bctx)
+   {
+      inject(bctx, bctx.getInstance());
+   }
+   
+   public Class getInjectionClass()
+   {
+      return setMethod.getParameterTypes()[0];
+   }
+   
+   protected Object lookup(String jndiName, Class param)
+   {
+      Object dependency = null;
+      
+      try
+      {
+         dependency = ctx.lookup(jndiName);
+            
+         if (dependency instanceof javax.xml.rpc.Service && !param.isAssignableFrom(javax.xml.rpc.Service.class))
+         {
+            javax.xml.rpc.Service service = (javax.xml.rpc.Service)dependency;
+            dependency = service.getPort(param);
+         }
+      }
+      catch (NamingException e)
+      {
+         e.printStackTrace();
+         throw new RuntimeException("Unable to @Inject jndi dependency: " + jndiName + " into method " + setMethod, e);
+      }
+      catch (javax.xml.rpc.ServiceException e)
+      {
+         e.printStackTrace();
+         throw new RuntimeException("Unable to @Inject webservice jndi dependency: " + jndiName + " into method " + setMethod, e);
+      }
+      
+      return dependency;
+   }
+   
+   public void inject(BeanContext bctx, Object instance)
+   {
+      inject(instance);
+   }
+
+   public void inject(Object instance)
+   {
+      Object dependency = lookup(jndiName, setMethod.getParameterTypes()[0]);
+
+      Object[] args = {dependency};
+      try
+      {
+         setMethod.invoke(instance, args);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalArgumentException e)
+      {
+         String type = "UNKNOWN";
+         if (dependency != null) type = dependency.getClass().getName();
+         throw new RuntimeException("Non matching type for @Inject of setter: " + setMethod + " for type: " + type, e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RuntimeException(e.getCause());  //To change body of catch statement use Options | File Templates.
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/LinkRefEncInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/LinkRefEncInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/LinkRefEncInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.injection;
+
+import org.jboss.naming.Util;
+
+import javax.naming.LinkRef;
+import javax.naming.NamingException;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56518 $
+ */
+public class LinkRefEncInjector implements EncInjector
+{
+   private String jndiName;
+   private String error;
+   private String encName;
+
+   public LinkRefEncInjector(String name, String mappedName, String error)
+   {
+      this.jndiName = mappedName;
+      this.error = error;
+      this.encName = name;
+   }
+
+   public void inject(InjectionContainer container)
+   {
+      try
+      {
+         Util.rebind(container.getEnc(), encName, new LinkRef(jndiName));
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException(new StringBuilder().append("could not bind enc name '").append(encName).append("' for ").append(error).append(" for container ").append(container.getIdentifier()).append(e.getMessage()).toString());
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PcEncInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PcEncInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PcEncInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,123 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.injection;
+
+import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
+import org.jboss.ejb3.entity.ExtendedEntityManager;
+import org.jboss.ejb3.entity.ExtendedHibernateSession;
+import org.jboss.ejb3.entity.TransactionScopedEntityManager;
+import org.jboss.ejb3.entity.TransactionScopedHibernateSession;
+import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.naming.Util;
+
+import javax.persistence.PersistenceContextType;
+import javax.persistence.EntityManager;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56518 $
+ */
+public class PcEncInjector implements EncInjector
+{
+   private String encName;
+   private String unitName;
+   private PersistenceContextType type;
+   private Class injectionType;
+   private String error;
+
+   public PcEncInjector(String encName, String unitName, PersistenceContextType type, Class injectionType, String error)
+   {
+      this.encName = encName;
+      this.unitName = unitName;
+      this.type = type;
+      this.injectionType = injectionType;
+      this.error = error;
+   }
+
+   public void inject(InjectionContainer container)
+   {
+      String error1 = error;
+      ManagedEntityManagerFactory factory = null;
+      try
+      {
+         factory = PersistenceUnitHandler.getManagedEntityManagerFactory(
+                 container, unitName);
+      }
+      catch (NameNotFoundException e)
+      {
+         error1 += " " + e.getMessage();
+      }
+      if (factory == null)
+      {
+         throw new RuntimeException(error1);
+      }
+      if (type == PersistenceContextType.EXTENDED)
+      {
+         if (!(container instanceof StatefulContainer))
+            throw new RuntimeException("It is illegal to inject an EXTENDED PC into something other than a SFSB");
+         container.getInjectors().add(0, new ExtendedPersistenceContextInjector(factory));
+         Object extendedPc = null;
+         if (injectionType == null
+                 || injectionType.getName().equals(EntityManager.class.getName()))
+         {
+            extendedPc = new ExtendedEntityManager(factory.getKernelName());
+         }
+         else
+         {
+            extendedPc = new ExtendedHibernateSession(factory.getKernelName());
+         }
+         try
+         {
+            Util.rebind(container.getEnc(), encName, extendedPc);
+         }
+         catch (NamingException e)
+         {
+            throw new RuntimeException(error1, e);
+         }
+      }
+      else
+      {
+         Object entityManager = null;
+         if (injectionType == null
+                 || injectionType.getName().equals(EntityManager.class.getName()))
+         {
+            entityManager = new TransactionScopedEntityManager(factory);
+         }
+         else
+         {
+            entityManager = new TransactionScopedHibernateSession(factory);
+         }
+         try
+         {
+            Util.rebind(container.getEnc(), encName, entityManager);
+         }
+         catch (NamingException e)
+         {
+            throw new RuntimeException(error1, e);
+         }
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PersistenceContextHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PersistenceContextHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PersistenceContextHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection;
+
+import org.jboss.metamodel.descriptor.PersistenceContextRef;
+import org.jboss.logging.Logger;
+import org.jboss.annotation.IgnoreDependency;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+
+import javax.naming.NameNotFoundException;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.persistence.PersistenceContexts;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * Searches bean class for all
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 55144 $
+ * @Inject and create Injectors
+ */
+public class PersistenceContextHandler implements InjectionHandler
+{
+   private static final Logger log = Logger
+           .getLogger(PersistenceContextHandler.class);
+
+   public void loadXml(EnvironmentRefGroup xml, InjectionContainer container)
+   {
+      if (xml == null) return;
+      if (xml.getPersistenceContextRefs() == null) return;
+      for (PersistenceContextRef ref : xml.getPersistenceContextRefs())
+      {
+         String encName = "env/" + ref.getRefName();
+         // we add injection target no matter what.  enc injection might be overridden but
+         // XML injection cannot be overriden
+         Class injectionType = InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
+
+         if (container.getEncInjectors().containsKey(encName))
+            continue;
+         // add it to list of
+         String error = "unable to load <persistence-context-ref> for unitName: "
+                 + ref.getUnitName() + " <ref-name>: " + ref.getRefName();
+         PersistenceContextType type = ref.getPersistenceContextType();
+         String unitName = ref.getUnitName();
+         container.getEncInjectors().put(encName, new PcEncInjector(encName, unitName, type, injectionType, error));
+         try
+         {
+            PersistenceUnitHandler.addPUDependency(ref.getUnitName(), container);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("Illegal <persistence-context-ref> of " + ref.getRefName() + " :" + e.getMessage());
+         }
+      }
+   }
+
+   public void handleClassAnnotations(Class clazz, InjectionContainer container)
+   {
+      PersistenceContexts resources = container.getAnnotation(PersistenceContexts.class, clazz);
+      if (resources != null)
+      {
+         for (PersistenceContext ref : resources.value())
+         {
+            loadPersistenceContextClassAnnotation(ref, container, clazz);
+         }
+      }
+      PersistenceContext pc = container.getAnnotation(PersistenceContext.class, clazz);
+
+      if (pc != null)
+      {
+         loadPersistenceContextClassAnnotation(pc, container, clazz);
+      }
+
+   }
+
+   private static void loadPersistenceContextClassAnnotation(
+           PersistenceContext ref, InjectionContainer container, Class clazz)
+   {
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         throw new RuntimeException(
+                 "JBoss requires name() for class level @PersistenceContext");
+      }
+      encName = "env/" + ref.name();
+      if (container.getEncInjectors().containsKey(encName)) return;
+
+      String error = "Unable to load class-level @PersistenceContext("
+              + ref.unitName() + ") on " + container.getIdentifier();
+      container.getEncInjectors().put(encName, new PcEncInjector(encName, ref.unitName(), ref.type(), null, error));
+      try
+      {
+         PersistenceUnitHandler.addPUDependency(ref.unitName(), container);
+      }
+      catch (NameNotFoundException e)
+      {
+         throw new RuntimeException("Illegal @PersistenceUnit on " + clazz.getName() + " of unitname " + ref.unitName() + " :" + e.getMessage());
+      }
+   }
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      PersistenceContext ref = method.getAnnotation(PersistenceContext.class);
+      if (ref == null) return;
+      if (!method.getName().startsWith("set"))
+         throw new RuntimeException("@PersistenceUnit can only be used with a set method: " + method);
+
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(method);
+      }
+      else
+      {
+         encName = "env/" + ref.name();
+      }
+      if (!container.getEncInjectors().containsKey(encName))
+      {
+         try
+         {
+            if (!method.isAnnotationPresent(IgnoreDependency.class)) PersistenceUnitHandler.addPUDependency(ref.unitName(), container);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("Illegal @PersistenceUnit on " + method + " :" + e.getMessage());
+         }
+         String error = "@PersistenceContext(name='" + encName
+                 + "',unitName='" + ref.unitName() + "') on EJB: "
+                 + container.getIdentifier() + " failed to inject on method "
+                 + method.toString();
+         container.getEncInjectors().put(encName, new PcEncInjector(encName, ref.unitName(), ref.type(), method.getParameterTypes()[0], error));
+      }
+      injectors.put(method, new JndiMethodInjector(method,
+              encName, container.getEnc()));
+   }
+
+   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      PersistenceContext ref = field.getAnnotation(PersistenceContext.class);
+      if (ref == null) return;
+
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(field);
+      }
+      else
+      {
+         encName = "env/" + ref.name();
+      }
+      if (!container.getEncInjectors().containsKey(encName))
+      {
+         try
+         {
+            if (!field.isAnnotationPresent(IgnoreDependency.class)) PersistenceUnitHandler.addPUDependency(ref.unitName(), container);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("Illegal @PersistenceUnit on " + field + " :" + e.getMessage());
+         }
+         String error = "@PersistenceContext(name='" + encName
+                 + "',unitName='" + ref.unitName() + "') on EJB: "
+                 + container.getIdentifier() + " failed to inject on field "
+                 + field.toString();
+         container.getEncInjectors().put(encName, new PcEncInjector(encName, ref.unitName(), ref.type(), field.getType(), error));
+      }
+      injectors.put(field, new JndiFieldInjector(field,
+              encName, container.getEnc()));
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PersistenceUnitHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PersistenceUnitHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PersistenceUnitHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,252 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import org.hibernate.SessionFactory;
+import org.jboss.annotation.IgnoreDependency;
+import org.jboss.ejb3.entity.InjectedEntityManagerFactory;
+import org.jboss.ejb3.entity.InjectedSessionFactory;
+import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+import org.jboss.metamodel.descriptor.PersistenceUnitRef;
+
+import javax.naming.NameNotFoundException;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+import javax.persistence.PersistenceUnits;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * Searches bean class for all @Inject and create Injectors
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 55144 $
+ */
+public class PersistenceUnitHandler implements InjectionHandler
+{
+   private static final Logger log = Logger
+           .getLogger(PersistenceContextHandler.class);
+
+   public void loadXml(EnvironmentRefGroup xml, InjectionContainer container)
+   {
+      if (xml == null) return;
+      if (xml.getPersistenceUnitRefs() == null) return;
+
+      for (PersistenceUnitRef ref : xml.getPersistenceUnitRefs())
+      {
+         String encName = "env/" + ref.getRefName();
+         // we add injection target no matter what.  enc injection might be overridden but
+         // XML injection cannot be overriden
+         Class injectionType = InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
+         if (container.getEncInjectors().containsKey(encName))
+            return;
+         container.getEncInjectors().put(encName, new PuEncInjector(encName, injectionType, ref.getUnitName(), "<persistence-unit-ref>"));
+         try
+         {
+            addPUDependency(ref.getUnitName(), container);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("Illegal <persistence-unit-ref> of " + ref.getRefName() + " :" + e.getMessage());
+         }
+      }
+   }
+
+
+   public void handleClassAnnotations(Class clazz, InjectionContainer container)
+   {
+      PersistenceUnits resources = container.getAnnotation(
+              PersistenceUnits.class, clazz);
+      if (resources != null)
+      {
+         for (PersistenceUnit ref : resources.value())
+         {
+            handleClassAnnotation(ref, container, clazz);
+         }
+      }
+      PersistenceUnit pu = container.getAnnotation(PersistenceUnit.class, clazz);
+      if (pu != null)
+      {
+         handleClassAnnotation(pu, container, clazz);
+      }
+   }
+
+   private static void handleClassAnnotation(PersistenceUnit ref, InjectionContainer container, Class clazz)
+   {
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         throw new RuntimeException("JBoss requires name() for class level @PersistenceUnit");
+      }
+      encName = "env/" + encName;
+      if (container.getEncInjectors().containsKey(encName)) return;
+      container.getEncInjectors().put(encName, new PuEncInjector(encName, null, ref.unitName(), "@PersistenceUnit"));
+      try
+      {
+         addPUDependency(ref.unitName(), container);
+      }
+      catch (NameNotFoundException e)
+      {
+         throw new RuntimeException("Illegal @PersistenceUnit on " + clazz.getName() + " of unitname " + ref.unitName() + " :" + e.getMessage());
+      }
+   }
+
+   public static void addPUDependency(String unitName, InjectionContainer container) throws NameNotFoundException
+   {
+      PersistenceUnitDeployment deployment = null;
+      // look in EAR first
+      deployment = container.getPersistenceUnitDeployment(unitName);
+      if (deployment != null)
+      {
+         container.getDependencyPolicy().addDependency(deployment.getKernelName());
+         return;
+      }
+      // probably not deployed yet.
+      // todo not sure if we should do this in JBoss 5
+      container.getDependencyPolicy().addDependency(PersistenceUnitDeployment.getDefaultKernelName(unitName));
+   }
+
+   public static ManagedEntityManagerFactory getManagedEntityManagerFactory(InjectionContainer container, String unitName)
+           throws NameNotFoundException
+   {
+      ManagedEntityManagerFactory factory;
+      PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
+      if (deployment != null)
+      {
+         factory = deployment.getManagedFactory();
+      }
+      else
+      {
+         throw new NameNotFoundException("Unable to find persistence unit: " + unitName + " for deployment: " + container.getIdentifier());
+      }
+      return factory;
+   }
+
+
+   public static EntityManagerFactory getEntityManagerFactory(PersistenceUnit ref, InjectionContainer container) throws NameNotFoundException
+   {
+      return getEntityManagerFactory(ref.unitName(), container);
+   }
+
+   public static Object getFactory(Class type, String unitName, InjectionContainer container) throws NameNotFoundException
+   {
+      if (type != null && type.getName().equals(SessionFactory.class.getName()))
+         return getSessionFactory(unitName, container);
+      return getEntityManagerFactory(unitName, container);
+   }
+
+   public static EntityManagerFactory getEntityManagerFactory(String unitName, InjectionContainer container) throws NameNotFoundException
+   {
+      ManagedEntityManagerFactory managedFactory;
+      PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
+      if (deployment != null)
+      {
+         managedFactory = deployment.getManagedFactory();
+      }
+      else
+      {
+         return null;
+      }
+      return new InjectedEntityManagerFactory(managedFactory);
+   }
+
+
+   private static SessionFactory getSessionFactory(String ref, InjectionContainer container) throws NameNotFoundException
+   {
+      ManagedEntityManagerFactory managedFactory;
+      PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(ref);
+      if (deployment != null)
+      {
+         managedFactory = deployment.getManagedFactory();
+      }
+      else
+      {
+         return null;
+      }
+      return new InjectedSessionFactory(managedFactory);
+   }
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      PersistenceUnit ref = method.getAnnotation(PersistenceUnit.class);
+      if (ref == null) return;
+      if (!method.getName().startsWith("set"))
+         throw new RuntimeException("@PersistenceUnit can only be used with a set method: " + method);
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(method);
+      }
+      else
+      {
+         encName = "env/" + encName;
+      }
+      if (!container.getEncInjectors().containsKey(encName))
+      {
+         container.getEncInjectors().put(encName, new PuEncInjector(encName, method.getParameterTypes()[0], ref.unitName(), "@PersistenceUnit"));
+         try
+         {
+            if (!method.isAnnotationPresent(IgnoreDependency.class)) addPUDependency(ref.unitName(), container);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("Illegal @PersistenceUnit on " + method + " :" + e.getMessage());
+         }
+      }
+
+      injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
+   }
+
+   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      PersistenceUnit ref = field.getAnnotation(PersistenceUnit.class);
+      if (ref == null) return;
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(field);
+      }
+      else
+      {
+         encName = "env/" + encName;
+      }
+      if (!container.getEncInjectors().containsKey(encName))
+      {
+         container.getEncInjectors().put(encName, new PuEncInjector(encName, field.getType(), ref.unitName(), "@PersistenceUnit"));
+         try
+         {
+            if (!field.isAnnotationPresent(IgnoreDependency.class)) addPUDependency(ref.unitName(), container);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("Illegal @PersistenceUnit on " + field + " :" + e.getMessage());
+         }
+      }
+
+      injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PojoInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PojoInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PojoInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.injection;
+
+import org.jboss.ejb3.BeanContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 46510 $
+ */
+public interface PojoInjector
+{
+   void inject(BeanContext ctx, Object instance);
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PuEncInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PuEncInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/PuEncInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,74 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.injection;
+
+import org.jboss.naming.Util;
+
+import javax.naming.NameNotFoundException;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56518 $
+ */
+public class PuEncInjector implements EncInjector
+{
+   private String encName;
+   private Class injectionType;
+   private String unitName;
+   private String error;
+
+   public PuEncInjector(String encName, Class injectionType, String unitName, String error)
+   {
+      this.encName = encName;
+      this.injectionType = injectionType;
+      this.error = error;
+      this.unitName = unitName;
+   }
+
+   public void inject(InjectionContainer container)
+   {
+      Object factory = null;
+      try
+      {
+         factory = PersistenceUnitHandler.getFactory(injectionType, unitName, container);
+      }
+      catch (NameNotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+      if (factory == null)
+      {
+         throw new RuntimeException("Failed to locate " + error + " of unit name: " + unitName + " for " + container.getIdentifier());
+      }
+
+      try
+      {
+         Util.rebind(container.getEnc(), encName, factory);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Failed to bind " + error + " of unit name: " + unitName + " ref-name" + encName + " for container " + container.getIdentifier(), e);
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ResourceHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ResourceHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ResourceHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,312 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import org.jboss.ejb3.Container;
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.EnvEntry;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+
+import javax.annotation.Resource;
+import javax.annotation.Resources;
+import javax.ejb.EJBContext;
+import javax.ejb.TimerService;
+import javax.transaction.UserTransaction;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Map;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 56236 $
+ */
+public class ResourceHandler implements InjectionHandler
+{
+   private static final Logger log = Logger.getLogger(ResourceHandler.class);
+
+   private static void loadEnvEntry(InjectionContainer container, Collection<EnvEntry> envEntries)
+   {
+      for (EnvEntry envEntry : envEntries)
+      {
+         String encName = "env/" + envEntry.getEnvEntryName();
+         InjectionUtil.injectionTarget(encName, envEntry, container, container.getEncInjections());
+         if (container.getEncInjectors().containsKey(encName)) continue;
+         container.getEncInjectors().put(encName, new EnvEntryEncInjector(encName, envEntry.getEnvEntryType(), envEntry.getEnvEntryValue()));
+      }
+   }
+
+   private static void loadXmlResourceRefs(InjectionContainer container, Collection<ResourceRef> refs)
+   {
+      for (ResourceRef envRef : refs)
+      {
+         String encName = "env/" + envRef.getResRefName();
+         if (container.getEncInjectors().containsKey(encName)) continue;
+         if (envRef.getMappedName() == null || envRef.getMappedName().equals(""))
+         {
+            if (envRef.getResUrl() != null)
+            {
+               try
+               {
+                  container.getEncInjectors().put(encName, new ValueEncInjector(encName, new URL(envRef.getResUrl().trim()), "<resource-ref>"));
+               }
+               catch (MalformedURLException e)
+               {
+                  throw new RuntimeException(e);
+               }
+            }
+            else
+            {
+               throw new RuntimeException("mapped-name is required for " + envRef.getResRefName() + " of deployment " + container.getIdentifier());
+            }
+         }
+         container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, envRef.getMappedName(), "<resource-ref>"));
+         InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
+      }
+   }
+
+   private static void loadXmlResourceEnvRefs(InjectionContainer container, Collection<ResourceEnvRef> refs)
+   {
+      for (ResourceEnvRef envRef : refs)
+      {
+         String encName = "env/" + envRef.getResRefName();
+         if (container.getEncInjectors().containsKey(encName)) continue;
+         if (envRef.getMappedName() == null || envRef.getMappedName().equals(""))
+         {
+            throw new RuntimeException("mapped-name is required for " + envRef.getResRefName() + " of deployment " + container.getIdentifier());
+         }
+         container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, envRef.getMappedName(), "<resource-ref>"));
+         InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
+      }
+   }
+
+   private static void loadXmlMessageDestinationRefs(InjectionContainer container, Collection<MessageDestinationRef> refs)
+   {
+      for (MessageDestinationRef envRef : refs)
+      {
+         String encName = "env/" + envRef.getMessageDestinationRefName();
+         if (container.getEncInjectors().containsKey(encName)) continue;
+         if (envRef.getMappedName() == null || envRef.getMappedName().equals(""))
+         {
+            // Look for a message-destination-link
+            String link = envRef.getMessageDestinationLink();
+            if( link != null )
+            {
+               // TODO: Resolve the link...
+            }
+            throw new RuntimeException("mapped-name is required for " + envRef.getMessageDestinationRefName() + " of deployment " + container.getIdentifier());
+         }
+         container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, envRef.getMappedName(), "<message-destination-ref>"));
+         InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
+      }
+   }
+
+   public void loadXml(EnvironmentRefGroup xml, InjectionContainer container)
+   {
+      if (xml == null) return;
+      if (xml.getMessageDestinationRefs() != null) loadXmlMessageDestinationRefs(container, xml.getMessageDestinationRefs());
+      if (xml.getResourceEnvRefs() != null) loadXmlResourceEnvRefs(container, xml.getResourceEnvRefs());
+      if (xml.getResourceRefs() != null) loadXmlResourceRefs(container, xml.getResourceRefs());
+      if (xml.getEnvEntries() != null) loadEnvEntry(container, xml.getEnvEntries());
+   }
+
+   public void handleClassAnnotations(Class clazz, InjectionContainer container)
+   {
+      Resources resources = container.getAnnotation(Resources.class, clazz);
+      if (resources != null)
+      {
+      for (Resource ref : resources.value())
+      {
+         handleClassAnnotation(ref, container, clazz);
+      }
+      }
+      Resource res = container.getAnnotation(Resource.class, clazz);
+      if (res != null) handleClassAnnotation(res, container, clazz);
+   }
+
+   private void handleClassAnnotation(Resource ref, InjectionContainer container, Class clazz)
+   {
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         throw new RuntimeException("JBoss requires name() for class level @Resource");
+      }
+      encName = "env/" + ref.name();
+      if (container.getEncInjectors().containsKey(encName)) return;
+
+      String mappedName = ref.mappedName();
+      if (mappedName == null || mappedName.equals(""))
+      {
+         throw new RuntimeException("You did not specify a @Resource.mappedName() on " + clazz.getName() + " and there is no binding for that enc name in XML");
+      }
+      container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@Resource"));
+   }
+
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      Resource ref = method.getAnnotation(Resource.class);
+      if (ref == null) return;
+
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(method);
+      }
+      else
+      {
+         encName = "env/" + encName;
+      }
+
+      method.setAccessible(true);
+
+      if (!method.getName().startsWith("set"))
+         throw new RuntimeException("@Resource can only be used with a set method: " + method);
+      if (method.getParameterTypes().length != 1)
+         throw new RuntimeException("@Resource can only be used with a set method of one parameter: " + method);
+
+      Class type = method.getParameterTypes()[0];
+      if (!ref.type().equals(Object.class))
+      {
+         type = ref.type();
+      }
+      if (type.equals(UserTransaction.class))
+      {
+         injectors.put(method, new UserTransactionMethodInjector(method, container));
+      }
+      else if (type.equals(TimerService.class))
+      {
+         injectors.put(method, new TimerServiceMethodInjector(method, (Container) container)); // only EJBs
+      }
+      else if (EJBContext.class.isAssignableFrom(type))
+      {
+         injectors.put(method, new EJBContextMethodInjector(method));
+      }
+      else if (type.equals(String.class)
+              || type.equals(Character.class)
+              || type.equals(Byte.class)
+              || type.equals(Short.class)
+              || type.equals(Integer.class)
+              || type.equals(Long.class)
+              || type.equals(Boolean.class)
+              || type.equals(Double.class)
+              || type.equals(Float.class)
+              || type.isPrimitive()
+              )
+      {
+
+         // don't add an injector if no XML <env-entry is present as there will be no value to inject
+         if (container.getEncInjectors().containsKey(encName))
+         {
+            injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
+         }
+      }
+      else
+      {
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            String mappedName = ref.mappedName();
+            if (mappedName == null || mappedName.equals(""))
+            {
+              throw new RuntimeException("You did not specify a @Resource.mappedName() on " + method + " and there is no binding for that enc name in XML");
+            }
+            container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@Resource"));
+         }
+         injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
+      }
+   }
+   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      Resource ref = field.getAnnotation(Resource.class);
+      if (ref == null) return;
+
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(field);
+      }
+      else
+      {
+         encName = "env/" + encName;
+      }
+
+      field.setAccessible(true);
+
+      Class type = field.getType();
+      if (!ref.type().equals(Object.class))
+      {
+         type = ref.type();
+      }
+      if (type.equals(UserTransaction.class))
+      {
+         injectors.put(field, new UserTransactionFieldInjector(field, container));
+      }
+      else if (type.equals(TimerService.class))
+      {
+         injectors.put(field, new TimerServiceFieldInjector(field, (Container) container)); // only EJBs
+      }
+      else if (EJBContext.class.isAssignableFrom(type))
+      {
+         injectors.put(field, new EJBContextFieldInjector(field));
+      }
+      else if (type.equals(String.class)
+              || type.equals(Character.class)
+              || type.equals(Byte.class)
+              || type.equals(Short.class)
+              || type.equals(Integer.class)
+              || type.equals(Long.class)
+              || type.equals(Boolean.class)
+              || type.equals(Double.class)
+              || type.equals(Float.class)
+              || type.isPrimitive()
+              )
+      {
+
+         // don't add an injector if no XML <env-entry is present as there will be no value to inject
+         if (container.getEncInjectors().containsKey(encName))
+         {
+            injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
+         }
+      }
+      else
+      {
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            String mappedName = ref.mappedName();
+            if (mappedName == null || mappedName.equals(""))
+            {
+              throw new RuntimeException("You did not specify a @Resource.mappedName() on " + field + " and there is no binding for that enc name in XML");
+            }
+            container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@Resource"));
+         }
+         injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
+      }
+   }
+
+
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/TimerServiceFieldInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/TimerServiceFieldInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/TimerServiceFieldInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,71 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.Field;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.Container;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class TimerServiceFieldInjector implements Injector
+{
+   private Field field;
+   private Container container;
+
+   public TimerServiceFieldInjector(Field field, Container container)
+   {
+      this.field = field;
+      this.field.setAccessible(true);
+      this.container = container;
+   }
+
+   public void inject(Object instance)
+   {
+      throw new RuntimeException("SHOULD NOT BE INVOKED");
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      try
+      {
+         field.set(ctx.getInstance(), container.getTimerService());
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RuntimeException("Failed in setting EntityManager on setter field: " + field.toString());
+      }
+   }
+   
+   public Class getInjectionClass()
+   {
+      return field.getType();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/TimerServiceMethodInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/TimerServiceMethodInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/TimerServiceMethodInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,78 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.Container;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class TimerServiceMethodInjector implements Injector
+{
+   private Method setMethod;
+   private Container container;
+
+   public TimerServiceMethodInjector(Method setMethod, Container container)
+   {
+      this.setMethod = setMethod;
+      setMethod.setAccessible(true);
+      this.container = container;
+   }
+
+   public void inject(Object instance)
+   {
+      throw new RuntimeException("SHOULD NOT BE INVOKED");
+   }
+
+   public void inject(BeanContext ctx)
+   {
+
+      Object[] args = {container.getTimerService()};
+      try
+      {
+         setMethod.invoke(ctx.getInstance(), args);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RuntimeException("Failed in setting EntityManager on setter method: " + setMethod.toString());
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RuntimeException(e.getCause());  //To change body of catch statement use Options | File Templates.
+      }
+   }
+   
+   public Class getInjectionClass()
+   {
+      return setMethod.getParameterTypes()[0];
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/UserTransactionFieldInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/UserTransactionFieldInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/UserTransactionFieldInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,82 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.Field;
+import javax.ejb.TransactionManagementType;
+import javax.transaction.UserTransaction;
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.tx.TxUtil;
+import org.jboss.ejb3.tx.UserTransactionImpl;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class UserTransactionFieldInjector implements Injector
+{
+   private Field field;
+
+   public UserTransactionFieldInjector(Field field, InjectionContainer container)
+   {
+      if (container instanceof Container)
+      {
+         TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) container));
+         if (type != TransactionManagementType.BEAN)
+            throw new IllegalStateException("Container " + ((Container) container).getEjbName() + ": it is illegal to inject UserTransaction into a CMT bean");
+      }
+      this.field = field;
+      this.field.setAccessible(true);
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      Object instance = ctx.getInstance();
+      inject(instance);
+   }
+
+   public void inject(Object instance)
+   {
+      UserTransaction ut = new UserTransactionImpl();
+      try
+      {
+         field.set(instance, ut);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RuntimeException("Failed in setting EntityManager on setter field: " + field.toString());
+      }
+   }
+
+   public Class getInjectionClass()
+   {
+      return field.getType();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/UserTransactionMethodInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/UserTransactionMethodInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/UserTransactionMethodInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,89 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.tx.TxUtil;
+import org.jboss.ejb3.tx.UserTransactionImpl;
+
+import javax.ejb.TransactionManagementType;
+import javax.transaction.UserTransaction;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class UserTransactionMethodInjector implements Injector
+{
+   private Method setMethod;
+
+   public UserTransactionMethodInjector(Method setMethod, InjectionContainer container)
+   {
+      if (container instanceof Container)
+      {
+         TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) container));
+         if (type != TransactionManagementType.BEAN)
+            throw new IllegalStateException("Container " + ((Container) container).getEjbName() + ": it is illegal to inject UserTransaction into a CMT bean");
+      }
+      this.setMethod = setMethod;
+      setMethod.setAccessible(true);
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      Object instance = ctx.getInstance();
+      inject(instance);
+   }
+
+   public void inject(Object instance)
+   {
+      UserTransaction ut = new UserTransactionImpl();
+      Object[] args = {ut};
+      try
+      {
+         setMethod.invoke(instance, args);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RuntimeException("Failed in setting EntityManager on setter method: " + setMethod.toString());
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RuntimeException(e.getCause());  //To change body of catch statement use Options | File Templates.
+      }
+   }
+
+   public Class getInjectionClass()
+   {
+      return setMethod.getParameterTypes()[0];
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ValueEncInjector.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ValueEncInjector.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/ValueEncInjector.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.injection;
+
+import org.jboss.naming.Util;
+
+import javax.naming.LinkRef;
+import javax.naming.NamingException;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46510 $
+ */
+public class ValueEncInjector implements EncInjector
+{
+   private Object obj;
+   private String encName;
+   private String error;
+
+   public ValueEncInjector(String name, Object obj, String error)
+   {
+      this.obj = obj;
+      this.encName = name;
+      this.error = error;
+   }
+
+   public void inject(InjectionContainer container)
+   {
+      try
+      {
+         Util.rebind(container.getEnc(), encName, obj);
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException(new StringBuilder().append("could not bind enc name '").append(encName).append("' for ").append(error).append(" for container ").append(container.getIdentifier()).append(e.getMessage()).toString());
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/injection/WebServiceHandler.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/injection/WebServiceHandler.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/injection/WebServiceHandler.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,122 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.injection;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.jboss.metamodel.descriptor.WebServiceRef;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 55144 $</tt>
+ */
+public class WebServiceHandler implements InjectionHandler
+{
+   private static final Logger log = Logger.getLogger(WebServiceHandler.class);
+
+   public void loadXml(EnvironmentRefGroup xml, InjectionContainer container)
+   {
+      if (xml == null) return;
+      if (xml.getWebServiceRefs() == null) return;
+      for (WebServiceRef wsRef : xml.getWebServiceRefs())
+      {
+         if (wsRef.getMappedName() == null || wsRef.getMappedName().equals(""))
+            throw new RuntimeException("mapped-name is required for <service-ref> " + wsRef.getServiceRefName() + " of " + container.getIdentifier());
+
+         String encName = "env/" + wsRef.getServiceRefName();
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, wsRef.getMappedName(), "jndi ref"));
+         }
+         InjectionUtil.injectionTarget(encName, wsRef, container, container.getEncInjections());
+      }
+   }
+
+   public void handleClassAnnotations(Class clazz, InjectionContainer container)
+   {
+      javax.xml.ws.WebServiceRef ref = container.getAnnotation(javax.xml.ws.WebServiceRef.class, clazz);
+      if (ref == null) return;
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         throw new RuntimeException("JBoss requires name() for class level @WebServiceRef");
+      }
+      encName = "env/" + ref.name();
+      if (container.getEncInjectors().containsKey(encName)) return;
+
+      String mappedName = ref.mappedName();
+      if (mappedName == null || mappedName.equals(""))
+      {
+         throw new RuntimeException("You did not specify a @WebServiceRef.mappedName() on " + clazz.getName() + " and there is no binding for that enc name in XML");
+      }
+      container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@WebServiceRef"));
+   }
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      javax.xml.ws.WebServiceRef ref = method.getAnnotation(javax.xml.ws.WebServiceRef.class);
+      if (ref == null) return;
+      if (!method.getName().startsWith("set"))
+         throw new RuntimeException("@ javax.xml.ws.WebServiceRef can only be used with a set method: " + method);
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(method);
+      }
+      else
+      {
+         encName = "env/" + encName;
+      }
+      if (!container.getEncInjectors().containsKey(encName))
+      {
+         container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@ javax.xml.ws.WebServiceRef"));
+      }
+
+      injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
+   }
+
+   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      javax.xml.ws.WebServiceRef ref = field.getAnnotation(javax.xml.ws.WebServiceRef.class);
+      if (ref == null) return;
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(field);
+      }
+      else
+      {
+         encName = "env/" + encName;
+      }
+      if (!container.getEncInjectors().containsKey(encName))
+      {
+         container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, ref.mappedName(), "@ javax.xml.ws.WebServiceRef"));
+      }
+
+      injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/BaseEjbRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/BaseEjbRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/BaseEjbRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,76 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metamodel.descriptor;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46506 $
+ */
+public class BaseEjbRef extends Ref
+{
+   protected String ejbRefName;
+   protected String ejbRefType;
+   private String ejbLink;
+   protected String mappedName;
+
+   public String getMappedName()
+   {
+      return mappedName;
+   }
+
+   public void setMappedName(String mappedName)
+   {
+      this.mappedName = mappedName;
+   }
+
+   public String getEjbRefName()
+   {
+      return ejbRefName;
+   }
+
+   public void setEjbRefName(String ejbRefName)
+   {
+      this.ejbRefName = ejbRefName;
+   }
+
+   public String getEjbRefType()
+   {
+      return ejbRefType;
+   }
+
+   public void setEjbRefType(String ejbRefType)
+   {
+      this.ejbRefType = ejbRefType;
+   }
+
+   public String getEjbLink()
+   {
+      return ejbLink;
+   }
+
+   public void setEjbLink(String ejbLink)
+   {
+      this.ejbLink = ejbLink;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/DDObjectFactory.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/DDObjectFactory.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/DDObjectFactory.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,583 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.EjbLocalRef;
+import org.jboss.metamodel.descriptor.EjbRef;
+import org.jboss.metamodel.descriptor.EnvEntry;
+import org.jboss.metamodel.descriptor.InjectionTarget;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+import org.jboss.metamodel.descriptor.SecurityRole;
+import org.xml.sax.Attributes;
+
+import javax.persistence.PersistenceContextType;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 56531 $</tt>
+ */
+public abstract class DDObjectFactory implements ObjectModelFactory
+{
+   private static final Logger log = Logger
+   .getLogger(DDObjectFactory.class);
+
+   public Object newChild(PersistenceUnitRef ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public Object newChild(PersistenceContextRef ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public Object newChild(EnvEntry ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public Object newChild(EjbRef ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public Object newChild(EjbLocalRef ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public Object newChild(ResourceRef ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public Object newChild(ResourceEnvRef ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public Object newChild(MessageDestinationRef ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public Object newChild(WebServiceRef ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public Object newChild(JndiRef ref,
+                          UnmarshallingContext navigator, String namespaceURI, String localName,
+                          Attributes attrs)
+   {
+      return newRefChild(ref, localName);
+   }
+
+   public void addChild(PersistenceUnitRef parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void addChild(PersistenceContextRef parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void addChild(EnvEntry parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void addChild(EjbRef parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void addChild(EjbLocalRef parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void addChild(ResourceRef parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void addChild(ResourceEnvRef parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void addChild(MessageDestinationRef parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void addChild(WebServiceRef parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void addChild(JndiRef parent, InjectionTarget target,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(target);
+   }
+
+   public void setValue(EjbLocalRef ref, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("ejb-ref-name"))
+      {
+         ref.setEjbRefName(getValue(localName, value));
+      }
+      else if (localName.equals("ejb-ref-type"))
+      {
+         ref.setEjbRefType(getValue(localName, value));
+      }
+      else if (localName.equals("local-home"))
+      {
+         ref.setLocalHome(getValue(localName, value));
+      }
+      else if (localName.equals("local"))
+      {
+         ref.setLocal(getValue(localName, value));
+      }
+      else if (localName.equals("ejb-link"))
+      {
+         ref.setEjbLink(getValue(localName, value));
+      }
+      else if (localName.equals("mapped-name") || localName.equals("local-jndi-name") || localName.equals("jndi-name"))
+      {
+         ref.setMappedName(getValue(localName, value));
+      }
+      else if (localName.equals("ignore-dependency"))
+      {
+         ref.setIgnoreDependency(true);
+      }
+   }
+
+   public void setValue(EjbRef ref, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("ejb-ref-name"))
+      {
+         ref.setEjbRefName(getValue(localName, value));
+      }
+      else if (localName.equals("ejb-ref-type"))
+      {
+         ref.setEjbRefType(getValue(localName, value));
+      }
+      else if (localName.equals("home"))
+      {
+         ref.setHome(getValue(localName, value));
+      }
+      else if (localName.equals("remote"))
+      {
+         ref.setRemote(getValue(localName, value));
+      }
+      else if (localName.equals("ejb-link"))
+      {
+         ref.setEjbLink(getValue(localName, value));
+      }
+      else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
+      {
+         ref.setMappedName(getValue(localName, value));
+      }
+      else if (localName.equals("ignore-dependency"))
+      {
+         ref.setIgnoreDependency(true);
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(InjectionTarget target, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("injection-target-class"))
+      {
+         target.setTargetClass(getValue(localName, value));
+      }
+      else if (localName.equals("injection-target-name"))
+      {
+         target.setTargetName(getValue(localName, value));
+      }
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(MessageDestinationRef ref, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("description"))
+      {
+         ref.setDescription(getValue(localName, value));
+      }
+      else if (localName.equals("message-destination-ref-name"))
+      {
+         ref.setMessageDestinationRefName(getValue(localName, value));
+      }
+      else if (localName.equals("message-destination-type"))
+      {
+         ref.setMessageDestinationType(getValue(localName, value));
+      }
+      else if (localName.equals("message-destination-usage"))
+      {
+         ref.setMessageDestinationUsage(getValue(localName, value));
+      }
+      else if (localName.equals("message-destination-link"))
+      {
+         ref.setMessageDestinationLink(getValue(localName, value));
+      }
+      else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
+      {
+         ref.setMappedName(getValue(localName, value));
+      }
+   }
+
+   public void setValue(EnvEntry entry, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("description"))
+      {
+         entry.setDescription(getValue(localName, value));
+      }
+      else if (localName.equals("env-entry-name"))
+      {
+         entry.setEnvEntryName(getValue(localName, value));
+      }
+      else if (localName.equals("env-entry-type"))
+      {
+         entry.setEnvEntryType(getValue(localName, value));
+      }
+      else if (localName.equals("env-entry-value"))
+      {
+         entry.setEnvEntryValue(getValue(localName, value));
+      }
+   }
+
+   public void setValue(ResourceEnvRef envRef, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("res-ref-name")
+              || localName.equals("resource-env-ref-name"))
+      {
+         envRef.setResRefName(getValue(localName, value));
+      }
+      else if (localName.equals("res-type")
+              || localName.equals("resource-env-ref-type"))
+      {
+         envRef.setResType(getValue(localName, value));
+      }
+      else if (localName.equals("res-auth"))
+      {
+         envRef.setResAuth(getValue(localName, value));
+      }
+      else if (localName.equals("res-sharing-scope"))
+      {
+         envRef.setResSharingScope(getValue(localName, value));
+      }
+      else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
+      {
+         envRef.setMappedName(getValue(localName, value));
+      }
+   }
+
+   public void setValue(ResourceRef ref, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("res-ref-name")
+              || localName.equals("resource-env-ref-name"))
+      {
+         ref.setResRefName(getValue(localName, value));
+      }
+      else if (localName.equals("res-type")
+              || localName.equals("resource-env-ref-type"))
+      {
+         ref.setResType(getValue(localName, value));
+      }
+      else if (localName.equals("res-auth"))
+      {
+         ref.setResAuth(getValue(localName, value));
+      }
+      else if (localName.equals("res-sharing-scope"))
+      {
+         ref.setResSharingScope(getValue(localName, value));
+      }
+      else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
+      {
+         ref.setMappedName(getValue(localName, value));
+         ref.setJndiName(getValue(localName, value));
+      }
+      else if (localName.equals("res-url"))
+      {
+         ref.setResUrl(getValue(localName, value));
+      }
+      else if (localName.equals("resource-name"))
+      {
+         ref.setResourceName(getValue(localName, value));
+         ref.setMappedName(getValue(localName, value));
+      }
+   }
+
+   public void setValue(WebServiceRef ref, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("service-ref-name"))
+      {
+         ref.setServiceRefName(getValue(localName, value));
+      }
+      else if (localName.equals("service-res-type"))
+      {
+         ref.setResType(getValue(localName, value));
+      }
+      else if (localName.equals("service-interface"))
+      {
+         ref.setServiceInterface(getValue(localName, value));
+      }
+      else if (localName.equals("wsdl-file"))
+      {
+         ref.setWsdlFile(getValue(localName, value));
+      }
+      else if (localName.equals("jaxrpc-mapping-file"))
+      {
+         ref.setJaxRpcMappingFile(getValue(localName, value));
+      }
+      else if (localName.equals("mapped-name"))
+      {
+         ref.setMappedName(getValue(localName, value));
+      }
+   }
+
+   public void setValue(SecurityRole role, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("role-name"))
+      {
+         role.setRoleName(getValue(localName, value));
+      }
+   }
+
+   public void setValue(JndiRef ref, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("mapped-name"))
+      {
+         ref.setMappedName(getValue(localName, value));
+      }
+      else if (localName.equals("jndi-ref-name"))
+      {
+         ref.setJndiRefName(getValue(localName, value));
+      }
+   }
+
+   public void setValue(RunAs runAs, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("role-name"))
+      {
+         runAs.setRoleName(getValue(localName, value));
+      }
+   }
+
+   public void setValue(SecurityRoleRef ref, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("role-name"))
+      {
+         ref.setRoleName(getValue(localName, value));
+      }
+      else if (localName.equals("role-link"))
+      {
+         ref.setRoleLink(getValue(localName, value));
+      }
+   }
+
+   public void setValue(Listener listener, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("listener-class"))
+      {
+         listener.setListenerClass(getValue(localName, value));
+      }
+   }
+
+   public void setValue(MessageDestination destination, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("message-destination-name"))
+      {
+         destination.setMessageDestinationName(getValue(localName, value));
+      }
+      else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
+      {
+         destination.setMappedName(getValue(localName, value));
+      }
+   }
+
+   public void setValue(PersistenceUnitRef ref, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("persistence-unit-ref-name"))
+      {
+         ref.setRefName(getValue(localName, value));
+      }
+      else if (localName.equals("persistence-unit-name"))
+      {
+         ref.setUnitName(getValue(localName, value));
+      }
+      else
+      {
+         throw new RuntimeException("INVALID element<" + localName + "> in <persistence-unit-ref>");
+      }
+   }
+
+   protected Object newEnvRefGroupChild(String localName)
+   {
+      Object child = null;
+
+      if (localName.equals("ejb-local-ref"))
+      {
+         child = new EjbLocalRef();
+      }
+      else if (localName.equals("ejb-ref"))
+      {
+         child = new EjbRef();
+      }
+      else if (localName.equals("resource-ref"))
+      {
+         child = new ResourceRef();
+      }
+      else if (localName.equals("resource-env-ref"))
+      {
+         child = new ResourceEnvRef();
+      }
+      else if (localName.equals("env-entry"))
+      {
+         child = new EnvEntry();
+      }
+      else if (localName.equals("message-destination-ref"))
+      {
+         child = new MessageDestinationRef();
+      }
+      else if (localName.equals("service-ref"))
+      {
+         child = new WebServiceRef();
+      }
+      else if (localName.equals("jndi-ref"))
+      {
+         child = new JndiRef();
+      }
+      else if (localName.equals("persistence-unit-ref"))
+      {
+         child = new PersistenceUnitRef();
+      }
+      else if (localName.equals("persistence-context-ref"))
+      {
+         child = new PersistenceContextRef();
+      }
+
+      return child;
+   }
+
+   protected Object newRefChild(Ref ref, String localName)
+   {
+      Object child = null;
+
+      if (localName.equals("ignore-dependency"))
+      {
+         ref.setIgnoreDependency(true);
+      }
+      else if (localName.equals("injection-target"))
+      {
+         InjectionTarget target = new InjectionTarget();
+         child = target;
+      }
+
+      return child;
+   }
+
+   public void setValue(PersistenceContextRef ref, UnmarshallingContext navigator,
+                        String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("persistence-context-ref-name"))
+      {
+         ref.setRefName(getValue(localName, value));
+      }
+      else if (localName.equals("persistence-unit-name"))
+      {
+         ref.setUnitName(getValue(localName, value));
+      }
+      else if(localName.equals("persistence-context-type"))
+      {
+         if (value.toLowerCase().equals("transaction"))
+         {
+            ref.setPersistenceContextType(PersistenceContextType.TRANSACTION);
+         }
+         else
+         {
+            ref.setPersistenceContextType(PersistenceContextType.EXTENDED);
+         }
+      }
+   }
+   
+   protected String getValue(String name, String value)
+   {
+      return value;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EjbLocalRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EjbLocalRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EjbLocalRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,65 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+/**
+ * Represents an ejb-local-ref element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 46506 $</tt>
+ */
+public class EjbLocalRef extends BaseEjbRef
+{
+   private String localHome;
+
+   private String local;
+
+   public String getLocalHome()
+   {
+      return localHome;
+   }
+
+   public void setLocalHome(String localHome)
+   {
+      this.localHome = localHome;
+   }
+
+   public String getLocal()
+   {
+      return local;
+   }
+
+   public void setLocal(String local)
+   {
+      this.local = local;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbRefName=").append(ejbRefName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EjbRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EjbRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EjbRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,69 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+/**
+ * Represents an ejb-ref element of the ejb-jar.xml deployment descriptor for
+ * the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 46506 $</tt>
+ */
+public class EjbRef extends BaseEjbRef
+{
+
+   private String home;
+   
+   private String remote;
+
+   public String getHome()
+   {
+      return home;
+   }
+
+   public void setHome(String home)
+   {
+      this.home = home;
+   }
+
+   public String getRemote()
+   {
+      return remote;
+   }
+
+   public void setRemote(String remote)
+   {
+      this.remote = remote;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("ejbRefName=").append(ejbRefName);
+      sb.append(", ejbRefType=").append(ejbRefType);
+      sb.append(", remote=").append(remote);
+      sb.append(", jndiName=").append(mappedName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EnvEntry.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EnvEntry.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EnvEntry.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,91 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+/**
+ * Represents an env-entry element of the ejb-jar.xml deployment descriptor for
+ * the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45240 $</tt>
+ */
+public class EnvEntry extends Ref
+{
+   private String description;
+
+   private String envEntryName;
+
+   private String envEntryType;
+
+   private String envEntryValue;
+
+   public String getDescription()
+   {
+      return description;
+   }
+
+   public void setDescription(String description)
+   {
+      this.description = description;
+   }
+
+   public String getEnvEntryName()
+   {
+      return envEntryName;
+   }
+
+   public void setEnvEntryName(String envEntryName)
+   {
+      this.envEntryName = envEntryName;
+   }
+
+   public String getEnvEntryType()
+   {
+      return envEntryType;
+   }
+
+   public void setEnvEntryType(String envEntryType)
+   {
+      this.envEntryType = envEntryType;
+   }
+
+   public String getEnvEntryValue()
+   {
+      return envEntryValue;
+   }
+
+   public void setEnvEntryValue(String envEntryValue)
+   {
+      this.envEntryValue = envEntryValue;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("envEntryName=").append(envEntryName);
+      sb.append(",envEntryType=").append(envEntryType);
+      sb.append(",envEntryValue=").append(envEntryValue);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EnvironmentRefGroup.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EnvironmentRefGroup.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/EnvironmentRefGroup.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,249 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.metamodel.descriptor;
+
+import java.util.HashMap;
+import java.util.Collection;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.logging.Logger;
+
+import org.jboss.metamodel.descriptor.EjbLocalRef;
+import org.jboss.metamodel.descriptor.EjbRef;
+import org.jboss.metamodel.descriptor.EnvEntry;
+import org.jboss.metamodel.descriptor.JndiRef;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+import org.jboss.metamodel.descriptor.WebServiceRef;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 56237 $</tt>
+ */
+public abstract class EnvironmentRefGroup
+{
+   private static final Logger log = Logger.getLogger(EnvironmentRefGroup.class);
+
+   protected HashMap<String, EjbLocalRef> ejbLocalRefs = new HashMap<String, EjbLocalRef>();
+   protected HashMap<String, EjbRef> ejbRefs = new HashMap<String, EjbRef>();
+   protected HashMap<String, EnvEntry> envEntries = new HashMap<String, EnvEntry>();
+   protected HashMap<String, ResourceEnvRef> resourceEnvRefs = new HashMap<String, ResourceEnvRef>();
+   protected HashMap<String, ResourceRef> resourceRefs = new HashMap<String, ResourceRef>();
+   protected HashMap<String, MessageDestinationRef> messageDestinationRefs = new HashMap<String, MessageDestinationRef>();
+   /** An index of MessageDestinationRef keyed by message-destination-link values */
+   protected HashMap<String, MessageDestinationRef> messageDestinationRefsByLink = new HashMap<String, MessageDestinationRef>();
+   protected HashMap<String, WebServiceRef> webServiceRefs = new HashMap<String, WebServiceRef>();
+   protected HashMap<String, JndiRef> jndiRefs = new HashMap<String, JndiRef>();
+   protected List<PersistenceContextRef> persistenceContextRefs = new ArrayList<PersistenceContextRef>();
+   protected List<PersistenceUnitRef> persistenceUnitRefs = new ArrayList<PersistenceUnitRef>();
+
+   public Collection<MessageDestinationRef> getMessageDestinationRefs()
+   {
+      return messageDestinationRefs.values();
+   }
+
+   public void addMessageDestinationRef(MessageDestinationRef ref)
+   {
+      log.debug("addMessageDestinationRef, "+ref);
+      messageDestinationRefs.put(ref.getMessageDestinationRefName(), ref);
+      String link = ref.getMessageDestinationLink();
+      if( link != null )
+      {
+         messageDestinationRefsByLink.put(link, ref);
+      }
+   }
+
+   public Collection<EjbLocalRef> getEjbLocalRefs()
+   {
+      return ejbLocalRefs.values();
+   }
+
+   public void addEjbLocalRef(EjbLocalRef ref)
+   {
+      ejbLocalRefs.put(ref.getEjbRefName(), ref);
+   }
+
+   public Collection<EjbRef> getEjbRefs()
+   {
+      return ejbRefs.values();
+   }
+
+   public void addEjbRef(EjbRef ref)
+   {
+      ejbRefs.put(ref.getEjbRefName(), ref);
+   }
+  
+   public Collection<EnvEntry> getEnvEntries()
+   {
+      return envEntries.values();
+   }
+
+   public void addEnvEntry(EnvEntry entry)
+   {
+      envEntries.put(entry.getEnvEntryName(), entry);
+   }
+
+   public Collection<ResourceEnvRef> getResourceEnvRefs()
+   {
+      return resourceEnvRefs.values();
+   }
+
+   public void addResourceEnvRef(ResourceEnvRef envRef)
+   {
+      resourceEnvRefs.put(envRef.getResRefName(), envRef);
+   }
+   
+   public Collection<ResourceRef> getResourceRefs()
+   {
+      return resourceRefs.values();
+   }
+
+   public void addResourceRef(ResourceRef ref)
+   {
+      resourceRefs.put(ref.getResRefName(), ref);
+   }
+   
+   public Collection<JndiRef> getJndiRefs()
+   {
+      return jndiRefs.values();
+   }
+
+   public void addJndiRef(JndiRef ref)
+   {
+      jndiRefs.put(ref.getJndiRefName(), ref);
+   }
+   
+   public Collection<WebServiceRef> getWebServiceRefs()
+   {
+      return webServiceRefs.values();
+   }
+
+   public void addWebServiceRef(WebServiceRef ref)
+   {
+      webServiceRefs.put(ref.getServiceRefName(), ref);
+   }
+   
+   public void updateEjbRef(EjbRef updatedRef)
+   {
+      EjbRef ref = (EjbRef)ejbRefs.get(updatedRef.getEjbRefName());
+      if (ref != null)
+      {
+         ref.setMappedName(updatedRef.getMappedName());
+         ref.setIgnoreDependency(updatedRef.isIgnoreDependency());
+      }
+      else
+      {
+         ejbRefs.put(updatedRef.getEjbRefName(), updatedRef);
+      }
+   }
+
+   public void updateEjbLocalRef(EjbLocalRef updatedRef)
+   {
+      EjbLocalRef ref = (EjbLocalRef)ejbLocalRefs.get(updatedRef.getEjbRefName());
+      if (ref != null)
+      {
+         ref.setMappedName(updatedRef.getMappedName());
+         ref.setIgnoreDependency(updatedRef.isIgnoreDependency());
+      }
+      else
+      {
+         ejbLocalRefs.put(updatedRef.getEjbRefName(), updatedRef);
+      }
+   }
+   
+   public void updateResourceRef(ResourceRef updatedRef)
+   {
+      ResourceRef ref = (ResourceRef)resourceRefs.get(updatedRef.getResRefName());
+      if (ref != null)
+      {
+         ref.setMappedName(updatedRef.getMappedName());
+         ref.setResUrl(updatedRef.getResUrl());
+         ref.setResourceName(updatedRef.getResourceName());
+      }
+      else
+      {
+         resourceRefs.put(updatedRef.getResRefName(), updatedRef);
+      }
+   }
+   
+   public void updateResourceEnvRef(ResourceEnvRef updatedRef)
+   {
+      ResourceEnvRef ref = (ResourceEnvRef)resourceEnvRefs.get(updatedRef.getResRefName());
+      if (ref != null)
+      {
+         ref.setMappedName(updatedRef.getMappedName());
+      }
+      else
+      {
+         resourceEnvRefs.put(updatedRef.getResRefName(), updatedRef);
+      }
+   }
+   
+   public void updateMessageDestinationRef(MessageDestinationRef updatedRef)
+   {
+      log.debug("updateMessageDestinationRef, "+updatedRef);
+      MessageDestinationRef ref = (MessageDestinationRef)messageDestinationRefs.get(updatedRef.getMessageDestinationRefName());
+      if (ref != null)
+      {
+         ref.setMappedName(updatedRef.getMappedName());
+      }
+      else
+      {
+         messageDestinationRefs.put(updatedRef.getMessageDestinationRefName(), updatedRef);
+         ref = updatedRef;
+      }
+   }
+ 
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      return sb.toString();
+   }
+
+   public List<PersistenceContextRef> getPersistenceContextRefs()
+   {
+      return persistenceContextRefs;
+   }
+
+   public List<PersistenceUnitRef> getPersistenceUnitRefs()
+   {
+      return persistenceUnitRefs;
+   }
+
+   public void addPersistenceContextRef(PersistenceContextRef ref)
+   {
+      persistenceContextRefs.add(ref);
+   }
+
+   public void addPersistenceUnitRef(PersistenceUnitRef ref)
+   {
+      persistenceUnitRefs.add(ref);
+   }
+
+   public MessageDestinationRef getMessageDestinationRefForLink(String link)
+   {
+      MessageDestinationRef ref = messageDestinationRefsByLink.get(link);
+      return ref;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/InjectionTarget.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/InjectionTarget.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/InjectionTarget.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,64 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 45240 $
+ */
+public class InjectionTarget
+{
+   private String targetClass;
+   private String targetName;
+
+   public String getTargetClass()
+   {
+      return targetClass;
+   }
+
+   public void setTargetClass(String targetClass)
+   {
+      this.targetClass = targetClass;
+   }
+
+   public String getTargetName()
+   {
+      return targetName;
+   }
+
+   public void setTargetName(String targetName)
+   {
+      this.targetName = targetName;
+   }
+   
+   public String toString()
+   {
+      StringBuffer buffer = new StringBuffer(100);
+      buffer.append("[InjectionTarget:targetClass=" + targetClass);
+      buffer.append(", targetName=" + targetName);
+      buffer.append("]");
+      
+      return buffer.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/JndiRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/JndiRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/JndiRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,70 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.logging.Logger;
+
+import org.jboss.metamodel.descriptor.InjectionTarget;
+
+/**
+ * Represents a <jndi-ref> element of the jboss.xml deployment descriptor
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45249 $</tt>
+ */
+public class JndiRef extends Ref
+{
+   private static final Logger log = Logger.getLogger(JndiRef.class);
+   
+   private String jndiRefName;
+   
+   private String mappedName;
+   
+   public String getJndiRefName()
+   {
+      return jndiRefName;
+   }
+
+   public void setJndiRefName(String jndiRefName)
+   {
+      this.jndiRefName = jndiRefName;
+   }
+
+   public String getMappedName()
+   {
+      return mappedName;
+   }
+
+   public void setMappedName(String mappedName)
+   {
+      this.mappedName = mappedName;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[" + this.getClass().getName() + ": ");
+      sb.append("mappedName=").append(mappedName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/Listener.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/Listener.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/Listener.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a <listener> element of the deployment descriptor
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45409 $</tt>
+ */
+public class Listener
+{
+   private static final Logger log = Logger.getLogger(Listener.class);
+   
+   protected String clazz;
+   
+   public String getListenerClass()
+   {
+      return clazz;
+   }
+   
+   public void setListenerClass(String clazz)
+   {
+      this.clazz = clazz;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/MessageDestination.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/MessageDestination.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/MessageDestination.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,71 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.logging.Logger;
+
+
+/**
+ * Represents a <message-destination> element of the web.xml deployment descriptor for the
+ * 2.5 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45409 $</tt>
+ */
+public class MessageDestination
+{
+   private static final Logger log = Logger.getLogger(MessageDestination.class);
+
+   private String messageDestinationName;
+
+   private String mappedName;
+
+   public String getMappedName()
+   {     
+      return mappedName;
+   }
+
+   public void setMappedName(String mappedName)
+   {
+      this.mappedName = mappedName;
+   }
+   
+   public String getMessageDestinationName()
+   {
+      return messageDestinationName;
+   }
+
+   public void setMessageDestinationName(String messageDestinationName)
+   {
+      this.messageDestinationName = messageDestinationName;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("messageDestinationRefName=").append(messageDestinationName);
+      sb.append(", mappedName=").append(mappedName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/MessageDestinationRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/MessageDestinationRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/MessageDestinationRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,145 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.logging.Logger;
+
+
+/**
+ * Represents a <message-destination-ref> element of the ejb-jar.xml deployment descriptor for the
+ * 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 56237 $</tt>
+ */
+public class MessageDestinationRef extends Ref
+{
+   private static final Logger log = Logger.getLogger(MessageDestinationRef.class);
+   
+   private String description;
+
+   private String messageDestinationRefName;
+
+   private String messageDestinationType;
+
+   private String messageDestinationUsage;
+
+   private String messageDestinationLink;
+
+   private String mappedName;
+   
+   private String jndiName;
+   
+   public String getJndiName()
+   {
+      return jndiName;
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+
+   public String getMappedName()
+   {     
+      return mappedName;
+   }
+
+   public void setMappedName(String mappedName)
+   {
+      this.mappedName = mappedName;
+   }
+
+   public String getDescription()
+   {
+      return description;
+   }
+
+   public void setDescription(String description)
+   {
+      this.description = description;
+   }
+
+   public String getMessageDestinationRefName()
+   {
+      return messageDestinationRefName;
+   }
+
+   public void setMessageDestinationRefName(String messageDestinationRefName)
+   {
+      this.messageDestinationRefName = messageDestinationRefName;
+   }
+
+   public String getMessageDestinationType()
+   {
+      return messageDestinationType;
+   }
+
+   public void setMessageDestinationType(String messageDestinationType)
+   {
+      this.messageDestinationType = messageDestinationType;
+   }
+
+   public String getMessageDestinationUsage()
+   {
+      return messageDestinationUsage;
+   }
+
+   public void setMessageDestinationUsage(String messageDestinationUsage)
+   {
+      this.messageDestinationUsage = messageDestinationUsage;
+   }
+
+   public String getMessageDestinationLink()
+   {
+      return messageDestinationLink;
+   }
+
+   public void setMessageDestinationLink(String messageDestinationLink)
+   {
+      this.messageDestinationLink = messageDestinationLink;
+   }
+   
+   public void merge(MessageDestinationRef ref)
+   {
+      if (ref.getJndiName() != null)
+      {
+         this.setJndiName(ref.getJndiName());
+         
+         setMappedName(ref.getJndiName());
+      }
+   }
+
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("messageDestinationRefName=").append(messageDestinationRefName);
+      sb.append(", messageDestinationType=").append(messageDestinationType);
+      sb.append(", messageDestinationLink=").append(messageDestinationLink);
+      sb.append(", messageDestinationUsage=").append(messageDestinationUsage);
+      sb.append(", mappedName=").append(mappedName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/NameValuePair.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/NameValuePair.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/NameValuePair.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,66 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45409 $</tt>
+ */
+public class NameValuePair
+{
+   private static final Logger log = Logger.getLogger(NameValuePair.class);
+
+   private String name;
+   private String value;
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+   
+   public String getValue()
+   {
+      return value;
+   }
+
+   public void setValue(String value)
+   {
+      this.value = value;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append('[');
+      sb.append("name=").append(name);
+      sb.append(", value=").append(value);
+      sb.append(']');
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/PersistenceContextRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/PersistenceContextRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/PersistenceContextRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metamodel.descriptor;
+
+import javax.persistence.PersistenceContextType;
+
+import org.jboss.metamodel.descriptor.Ref;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46506 $
+ */
+public class PersistenceContextRef extends Ref
+{
+   private String refName;
+   private String unitName;
+   private PersistenceContextType persistenceContextType;
+
+   public String getRefName()
+   {
+      return refName;
+   }
+
+   public void setRefName(String refName)
+   {
+      this.refName = refName;
+   }
+
+   public String getUnitName()
+   {
+      return unitName;
+   }
+
+   public void setUnitName(String unitName)
+   {
+      this.unitName = unitName;
+   }
+
+   public PersistenceContextType getPersistenceContextType()
+   {
+      return persistenceContextType;
+   }
+
+   public void setPersistenceContextType(PersistenceContextType persistenceContextType)
+   {
+      this.persistenceContextType = persistenceContextType;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/PersistenceUnitRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/PersistenceUnitRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/PersistenceUnitRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,67 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.metamodel.descriptor.Ref;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 45712 $
+ */
+public class PersistenceUnitRef extends Ref
+{
+   private String refName;
+   private String unitName;
+
+   public String getRefName()
+   {
+      return refName;
+   }
+
+   public void setRefName(String refName)
+   {
+      this.refName = refName;
+   }
+
+   public String getUnitName()
+   {
+      return unitName;
+   }
+
+   public void setUnitName(String unitName)
+   {
+      this.unitName = unitName;
+   }
+   
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[" + this.getClass().getName() + ": ");
+      sb.append("refName=").append(refName);
+      sb.append(", unitName=").append(unitName);
+      sb.append(", unitName=").append(unitName);
+      sb.append(", " + super.toString());
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/Ref.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/Ref.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/Ref.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,61 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45790 $</tt>
+ */
+public abstract class Ref
+{
+   protected InjectionTarget injectionTarget;
+   private boolean ignoreDependency;
+
+   public InjectionTarget getInjectionTarget()
+   {
+      return injectionTarget;
+   }
+
+   public void setInjectionTarget(InjectionTarget injectionTarget)
+   {
+      this.injectionTarget = injectionTarget;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append(", injectionTarget=").append(injectionTarget);
+      sb.append("]");
+      return sb.toString();
+   }
+
+   public boolean isIgnoreDependency()
+   {
+      return ignoreDependency;
+   }
+
+   public void setIgnoreDependency(boolean ignoreDependency)
+   {
+      this.ignoreDependency = ignoreDependency;
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/ResourceEnvRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/ResourceEnvRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/ResourceEnvRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,167 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a <resource-env-ref> element of the ejb-jar.xml deployment descriptor for the
+ * 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45240 $</tt>
+ */
+public class ResourceEnvRef extends Ref
+{
+   private static final Logger log = Logger.getLogger(ResourceEnvRef.class);
+   
+   private String resRefName;
+
+   private String resType;
+
+   private String resAuth;
+
+   private String resSharingScope;
+
+   private String mappedName;
+   
+   private String jndiName;
+   
+   private String resourceName;
+   
+   public String getResourceName()
+   {
+      return resourceName;
+   }
+
+   public void setResourceName(String resourceName)
+   {
+      this.resourceName = resourceName;
+   }
+   
+   public String getJndiName()
+   {
+      return jndiName;
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      this.jndiName = jndiName;
+      this.mappedName = jndiName;
+   }
+
+   public String getMappedName()
+   {
+      return mappedName;
+   }
+
+   public void setMappedName(String mappedName)
+   {
+      this.mappedName = mappedName;
+   }
+
+   public String getResRefName()
+   {
+      return resRefName;
+   }
+
+   public void setResRefName(String resRefName)
+   {
+      this.resRefName = resRefName;
+   }
+
+   public String getResType()
+   {
+      return resType;
+   }
+
+   public void setResType(String resType)
+   {
+      this.resType = resType;
+   }
+
+   public String getResAuth()
+   {
+      return resAuth;
+   }
+
+   public void setResAuth(String resAuth)
+   {
+      this.resAuth = resAuth;
+   }
+
+   public String getAuthorizationType()
+   {
+      return resAuth;
+   }
+
+   public String getResSharingScope()
+   {
+      return resSharingScope;
+   }
+
+   public void setResSharingScope(String resSharingScope)
+   {
+      this.resSharingScope = resSharingScope;
+   }
+
+   public boolean isShareable()
+   {
+      if (resSharingScope == null || resSharingScope.equals("Shareable"))
+         return true;
+      else
+         return false;
+   }
+   
+   public void merge(ResourceEnvRef ref)
+   {
+      if (ref.getJndiName() != null)
+      {
+         this.setJndiName(ref.getJndiName());
+         
+         setMappedName(ref.getJndiName());
+      }
+      
+      if (ref.getResourceName() != null)
+      {
+         this.setResourceName(ref.getResourceName());
+         
+         String mappedName = ref.getResourceName();
+         if (mappedName.startsWith("java:"))
+            this.setMappedName(ref.getResourceName());
+         else
+            this.setMappedName("java:" + ref.getResourceName());
+      }
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[ResourceEnvRef:");
+      sb.append("resRefName=").append(resRefName);
+      sb.append(",resType=").append(resType);
+      sb.append(",jndiName=").append(jndiName);
+      sb.append(",mappedName=").append(mappedName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/ResourceRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/ResourceRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/ResourceRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,188 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a <resource-ref> element of the ejb-jar.xml deployment descriptor for the
+ * 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45249 $</tt>
+ */
+public class ResourceRef extends Ref
+{
+   private static final Logger log = Logger.getLogger(ResourceRef.class);
+   
+   private String resRefName;
+
+   private String resType;
+
+   private String resAuth;
+
+   private String resSharingScope;
+
+   private String mappedName;
+   
+   private String jndiName;
+   
+   private String resourceName;
+   
+   private String resUrl;
+   
+   public String getResUrl()
+   {
+      return resUrl;
+   }
+
+   public void setResUrl(String resUrl)
+   {
+      this.resUrl = resUrl;
+   }
+   
+   public String getResourceName()
+   {
+      return resourceName;
+   }
+
+   public void setResourceName(String resourceName)
+   {
+      this.resourceName = resourceName;
+   }
+   
+   public String getJndiName()
+   {
+      return jndiName;
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+
+   public String getMappedName()
+   {
+      return mappedName;
+   }
+
+   public void setMappedName(String mappedName)
+   {
+      this.mappedName = mappedName;
+   }
+
+   public String getResRefName()
+   {
+      return resRefName;
+   }
+
+   public void setResRefName(String resRefName)
+   {
+      this.resRefName = resRefName;
+   }
+
+   public String getResType()
+   {
+      return resType;
+   }
+
+   public void setResType(String resType)
+   {
+      this.resType = resType;
+   }
+
+   public String getResAuth()
+   {
+      return resAuth;
+   }
+
+   public void setResAuth(String resAuth)
+   {
+      this.resAuth = resAuth;
+   }
+
+   public String getAuthorizationType()
+   {
+      return resAuth;
+ /*     if (resAuth == null || resAuth.equals("Container"))
+         return AuthenticationType.CONTAINER;
+      else
+         return AuthenticationType.APPLICATION;*/
+   }
+
+   public String getResSharingScope()
+   {
+      return resSharingScope;
+   }
+
+   public void setResSharingScope(String resSharingScope)
+   {
+      this.resSharingScope = resSharingScope;
+   }
+
+   public boolean isShareable()
+   {
+      if (resSharingScope == null || resSharingScope.equals("Shareable"))
+         return true;
+      else
+         return false;
+   }
+   
+   public void merge(ResourceRef ref)
+   {
+      if (ref.getJndiName() != null)
+      {
+         this.setJndiName(ref.getJndiName());
+         
+         String mappedName = ref.getJndiName();
+         if (mappedName.startsWith("java:"))
+            this.setMappedName(ref.getJndiName());
+         else
+            this.setMappedName("java:" + ref.getJndiName());
+      }
+      
+      if (ref.getResourceName() != null)
+      {
+         this.setResourceName(ref.getResourceName());
+         
+         String mappedName = ref.getResourceName();
+         if (mappedName.startsWith("java:"))
+            this.setMappedName(ref.getResourceName());
+         else
+            this.setMappedName("java:" + ref.getResourceName());
+      }
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[" + this.getClass().getName() + ": ");
+      sb.append("resRefName=").append(resRefName);
+      sb.append(", jndiName=").append(jndiName);
+      sb.append(", resourceName=").append(resourceName);
+      sb.append(", resType=").append(resType);
+      sb.append(", mappedName=").append(mappedName);
+      sb.append(", injectionTarget=").append(injectionTarget);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/RunAs.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/RunAs.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/RunAs.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,56 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents a <run-as> element
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45409 $</tt>
+ */
+public class RunAs
+{
+   private static final Logger log = Logger.getLogger(RunAs.class);
+   
+   private String roleName;
+    
+   public String getRoleName()
+   {
+      return roleName;
+   }
+
+   public void setRoleName(String roleName)
+   {
+      this.roleName = roleName;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[" + this.getClass().getName() + ": ");
+      sb.append("roleName=").append(roleName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/SecurityRole.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/SecurityRole.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/SecurityRole.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,54 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+
+/**
+ * Represents an security-role element of the ejb-jar.xml deployment descriptor
+ * for the 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45417 $</tt>
+ */
+public class SecurityRole
+{
+   private String roleName = null;
+
+   public String getRoleName()
+   {
+      return roleName;
+   }
+
+   public void setRoleName(String roleName)
+   {
+      this.roleName = roleName;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("roleName=").append(roleName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/SecurityRoleRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/SecurityRoleRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/SecurityRoleRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,64 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+
+/**
+ * Represents an <security-role-ref> 
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45409 $</tt>
+ */
+public class SecurityRoleRef
+{
+   protected String roleName = null;
+   protected String roleLink = null;
+
+   public String getRoleName()
+   {
+      return roleName;
+   }
+
+   public void setRoleName(String roleName)
+   {
+      this.roleName = roleName;
+   }
+   
+   public String getRoleLink()
+   {
+      return roleLink;
+   }
+
+   public void setRoleLink(String roleLink)
+   {
+      this.roleLink = roleLink;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("roleName=").append(roleName);
+      sb.append("]");
+      return sb.toString();
+   }
+}

Added: branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/WebServiceRef.java
===================================================================
--- branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/WebServiceRef.java	2006-09-08 02:17:45 UTC (rev 56619)
+++ branches/Branch_4_0/ejb3/src/main/org/jboss/metamodel/descriptor/WebServiceRef.java	2006-09-08 02:18:23 UTC (rev 56620)
@@ -0,0 +1,135 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.metamodel.descriptor;
+
+import org.jboss.logging.Logger;
+
+import org.jboss.metamodel.descriptor.Ref;
+
+/**
+ * Represents a <resource-ref> element of the ejb-jar.xml deployment descriptor for the
+ * 1.4 schema
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision: 45249 $</tt>
+ */
+public class WebServiceRef extends Ref
+{
+   private static final Logger log = Logger.getLogger(WebServiceRef.class);
+   
+   private String serviceRefName;
+
+   private String resType;
+
+   private String serviceInterface;
+
+   private String wsdlFile;
+
+   private String mappedName;
+   
+   private String jndiName;
+   
+   private String jaxRpcMappingFile;
+   
+   public String getJaxRpcMappingFile()
+   {
+      return jaxRpcMappingFile;
+   }
+
+   public void setJaxRpcMappingFile(String jaxRpcMappingFile)
+   {
+      this.jaxRpcMappingFile = jaxRpcMappingFile;
+   }
+   
+   public String getJndiName()
+   {
+      return jndiName;
+   }
+
+   public void setJndiName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+
+   public String getMappedName()
+   {
+      return mappedName;
+   }
+
+   public void setMappedName(String mappedName)
+   {
+      this.mappedName = mappedName;
+   }
+
+   public String getServiceRefName()
+   {
+      return serviceRefName;
+   }
+
+   public void setServiceRefName(String serviceRefName)
+   {
+      this.serviceRefName = serviceRefName;
+   }
+
+   public String getResType()
+   {
+      return resType;
+   }
+
+   public void setResType(String resType)
+   {
+      this.resType = resType;
+   }
+
+   public String getServiceInterface()
+   {
+      return serviceInterface;
+   }
+
+   public void setServiceInterface(String serviceInterface)
+   {
+      this.serviceInterface = serviceInterface;
+   }
+
+   public String getWsdlFile()
+   {
+      return wsdlFile;
+   }
+
+   public void setWsdlFile(String wsdlFile)
+   {
+      this.wsdlFile = wsdlFile;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[" + this.getClass().getName() + ": ");
+      sb.append("serviceRefName=").append(serviceRefName);
+      sb.append(", jndiName=").append(jndiName);
+      sb.append(", jaxRpcMappingFile=").append(jaxRpcMappingFile);
+      sb.append(", resType=").append(resType);
+      sb.append(", mappedName=").append(mappedName);
+      sb.append("]");
+      return sb.toString();
+   }
+}




More information about the jboss-cvs-commits mailing list