You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Carlos Delfino Carvalho Pinheiro <co...@carlosdelfino.eti.br> on 2007/09/05 21:39:30 UTC

Same properties but different instance of one service

On Tapestry-JPA I have Two services, 

JPAManager (old EntityManagerFactoryManager)
JPASource (old EntityManagerFactorySource)

Both services can are build many times with different arguments, and You
properties need accessed in different other services, but of same manner.

If I have one build for JPASource and other for JPAManager, for example, I
can use build method like this to get "entityManager" property :

	public static EntityManagerFactory build(JPASource
p_emFactorySource,
			PropertyShadowBuilder p_propertyShadowBuilder) {
		return p_propertyShadowBuilder.build(p_emFactorySource,
"entityManager",
				EntityManager.class);
	}

But, I have two or more service of type JPASource and JPAManager, and all I
need get "entityManagerFactory" and "entityManager", so I have make one
property shadow for each property shadow like this:

	Public static JPASource
buildAuthenticationJPASource(@Value(""unitWorkAuthentication")String
p_unitWork){
		Return new JPASourceImpl(p_unitWork);
      }

	Public static JPAManager
buildAuthenticationJPAManager(@InjectService("AutheticationJPASource")
JPASource p_factory){
		Return new jPAManagerImpl(p_factory);
	}

	Public static JPASource
buildCommunitJPASource(@Value(""unitWorkComunit")String p_unitWork){
		Return new JPASourceImpl(p_unitWork);
      }


	Public static JPAManager
buildCommunitJPAManager(@InjectService("CommunitJPASource") JPASource
p_factory){
		Return new jPAManagerImpl(p_factory);
	}

      /**
       * property shadow for entityManagerFactory 
       */
	public static EntityManagerFactory build(JPASource p_JPASource,
			PropertyShadowBuilder p_propertyShadowBuilder) {
		return p_propertyShadowBuilder.build(p_JPASource,
"entityManagerFactory",
				EntityManagerFactory.class);
	}

      /**
       * property shadow for entityManager 
       */
	public static EntityManagerFactory build(JPAManager p_jpaManager,
			PropertyShadowBuilder p_propertyShadowBuilder) {
		return p_propertyShadowBuilder.build(p_jpaManager,
"entityManager",
				EntityManager.class);
	}

But with this I get the error:

.
.
.
Caused by: java.lang.RuntimeException: Error invoking service builder method
net.java.pdtec.sociedadeArtificial.services.UserRegistrationModule.buildUser
Initializer(PasswordEncoder, SaltSource, EntityManager) (at
UserRegistrationModule.java:48) (for service 'UserInitializer'): Exception
constructing service 'EntityManager': Error invoking service builder method
org.apache.tapestry.jpa.JPAModule.build(EntityManagerFactoryManager,
PropertyShadowBuilder) (at JPAModule.java:45) (for service 'EntityManager'):
Service interface org.apache.tapestry.jpa.EntityManagerFactoryManager is
matched by 2 services: AuthenticationEntityManager, CommunitEntityManager.
Automatic dependency resolution requires that exactly one service implement
the interface.
	at
org.apache.tapestry.ioc.internal.ServiceBuilderMethodInvoker.createObject(Se
rviceBuilderMethodInvoker.java:87)
	at
org.apache.tapestry.ioc.internal.SingletonServiceLifecycle.createService(Sin
gletonServiceLifecycle.java:31)
	at
org.apache.tapestry.ioc.internal.LifecycleWrappedServiceCreator.createObject
(LifecycleWrappedServiceCreator.java:54)
	at
org.apache.tapestry.ioc.internal.InterceptorStackBuilder.createObject(Interc
eptorStackBuilder.java:54)
	at
org.apache.tapestry.ioc.internal.RecursiveServiceCreationCheckWrapper.create
Object(RecursiveServiceCreationCheckWrapper.java:60)
	at
org.apache.tapestry.ioc.internal.services.JustInTimeObjectCreator.createObje
ct(JustInTimeObjectCreator.java:61)
	... 98 more
Caused by: java.lang.RuntimeException: Exception constructing service
'EntityManager': Error invoking service builder method
org.apache.tapestry.jpa.JPAModule.build(EntityManagerFactoryManager,
PropertyShadowBuilder) (at JPAModule.java:45) (for service 'EntityManager'):
Service interface org.apache.tapestry.jpa.EntityManagerFactoryManager is
matched by 2 services: AuthenticationEntityManager, CommunitEntityManager.
Automatic dependency resolution requires that exactly one service implement
the interface.
	at
org.apache.tapestry.ioc.internal.services.JustInTimeObjectCreator.createObje
ct(JustInTimeObjectCreator.java:69)
	at
$EntityManager_114d6e0246b._delegate($EntityManager_114d6e0246b.java)
	at
$EntityManager_114d6e0246b.createNamedQuery($EntityManager_114d6e0246b.java)
	at
net.java.pdtec.sociedadeArtificial.services.internal.UserInitializerImpl.not
ExistUser(UserInitializerImpl.java:71)
	at
net.java.pdtec.sociedadeArtificial.services.internal.UserInitializerImpl.cre
ateIfNeedAnonymous(UserInitializerImpl.java:88)
	at
net.java.pdtec.sociedadeArtificial.services.internal.UserInitializerImpl.<in
it>(UserInitializerImpl.java:48)
	at
net.java.pdtec.sociedadeArtificial.services.UserRegistrationModule.buildUser
Initializer(UserRegistrationModule.java:48)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.apache.tapestry.ioc.internal.ServiceBuilderMethodInvoker.createObject(Se
rviceBuilderMethodInvoker.java:75)
	... 103 more
Caused by: java.lang.RuntimeException: Error invoking service builder method
org.apache.tapestry.jpa.JPAModule.build(EntityManagerFactoryManager,
PropertyShadowBuilder) (at JPAModule.java:45) (for service 'EntityManager'):
Service interface org.apache.tapestry.jpa.EntityManagerFactoryManager is
matched by 2 services: AuthenticationEntityManager, CommunitEntityManager.
Automatic dependency resolution requires that exactly one service implement
the interface.
	at
org.apache.tapestry.ioc.internal.ServiceBuilderMethodInvoker.createObject(Se
rviceBuilderMethodInvoker.java:87)
	at
org.apache.tapestry.ioc.internal.SingletonServiceLifecycle.createService(Sin
gletonServiceLifecycle.java:31)
	at
org.apache.tapestry.ioc.internal.LifecycleWrappedServiceCreator.createObject
(LifecycleWrappedServiceCreator.java:54)
	at
org.apache.tapestry.ioc.internal.InterceptorStackBuilder.createObject(Interc
eptorStackBuilder.java:54)
	at
org.apache.tapestry.ioc.internal.RecursiveServiceCreationCheckWrapper.create
Object(RecursiveServiceCreationCheckWrapper.java:60)
	at
org.apache.tapestry.ioc.internal.services.JustInTimeObjectCreator.createObje
ct(JustInTimeObjectCreator.java:61)
	... 114 more
Caused by: java.lang.RuntimeException: Service interface
org.apache.tapestry.jpa.EntityManagerFactoryManager is matched by 2
services: AuthenticationEntityManager, CommunitEntityManager.  Automatic
dependency resolution requires that exactly one service implement the
interface.
	at
org.apache.tapestry.ioc.internal.RegistryImpl.getService(RegistryImpl.java:4
59)
	at
org.apache.tapestry.ioc.services.TapestryIOCModule$2.provide(TapestryIOCModu
le.java:132)
	at
$ObjectProvider_114d6e0244c.provide($ObjectProvider_114d6e0244c.java)
	at
$ObjectProvider_114d6e02446.provide($ObjectProvider_114d6e02446.java)
	at
org.apache.tapestry.ioc.internal.RegistryImpl.getObject(RegistryImpl.java:55
0)
	at
org.apache.tapestry.ioc.internal.RegistryImpl.getObject(RegistryImpl.java:55
7)
	at
org.apache.tapestry.ioc.internal.ObjectLocatorImpl.getObject(ObjectLocatorIm
pl.java:50)
	at
org.apache.tapestry.ioc.internal.util.InternalUtils.calculateParameterValue(
InternalUtils.java:217)
	at
org.apache.tapestry.ioc.internal.util.InternalUtils.calculateParameters(Inte
rnalUtils.java:248)
	at
org.apache.tapestry.ioc.internal.util.InternalUtils.calculateParametersForMe
thod(InternalUtils.java:226)
	at
org.apache.tapestry.ioc.internal.ServiceBuilderMethodInvoker.createObject(Se
rviceBuilderMethodInvoker.java:68)
	... 119 more
.
.
.

I understand with the solution is create multiples property shadows one for
each service instance, but I think have one more simples manner and more
expert for make this. 

Tanks
--
�~^.^~�~^.^~�~^.^~�~^.^~�~^.^~�~^.^~�
Carlos Delfino -  
Consultoria e Gest�o de Projetos no Terceiro Setor
http://www.linkedin.com/in/carlosdelfino 
�~^.^~�~^.^~�~^.^~�~^.^~�~^.^~�~^.^~�