If you remove the *@Inject* annotation and keep the *@Symbol* annotation, I
think it should work as you would like it to.

On Tue, Jan 3, 2012 at 8:00 PM, Howard Lewis Ship <hls...@gmail.com> wrote:

> It is not possible.
>
> However, you can initialize a symbol with another symbol's value:
>
> configuration.add("my.new.symbol", "${some.other.symbol}")
>
> Tapestry does a good job of detecting and reporting any unintentional
> cycles you might create this way.
>
> On Tue, Jan 3, 2012 at 7:59 AM, Borut Bolčina <borut.bolc...@gmail.com>
> wrote:
> > Hi,
> >
> > I would still like an advice on the approach on how to initialize custom
> > symbol provider with tapestry provided symbol. The code below ends in
> > IllegalStateException
> >
> > Construction of service 'SymbolSource' has failed due to recursion: the
> > service depends on itself in some way.
> >
> >
> > The code from AppModule:
> >
> >    public RESTSymbolProvider buildRESTSymbolProvider(Logger logger,
> > @Inject @Symbol(SymbolConstants.EXECUTION_MODE) String executionMode) {
> >        return new RESTSymbolProvider(logger, executionMode);
> >    }
> >
> >    public void
> contributeSymbolSource(OrderedConfiguration<SymbolProvider>
> > providers, Logger logger,
> >            @InjectService("RESTSymbolProvider") SymbolProvider
> > restSymbolProvider) {
> >        providers.add("myAppConfiguration", restSymbolProvider);
> >    }
> >
> > Thanks for any input,
> > borut
> >
> > 2011/12/30 Borut Bolčina <borut.bolc...@gmail.com>
> >
> >> Hello,
> >>
> >> I am in a process of writting my own SymbolProvider (the configuration
> for
> >> my app will come from REST service) and I am facing a dilemma. The
> >> contribution looks like:
> >>
> >>     public void
> >> contributeSymbolSource(OrderedConfiguration<SymbolProvider> providers,
> >> Logger logger) {
> >>         providers.add("myAppConfiguration", new
> RESTSymbolProvider(logger,
> >> "development"), "after:SystemProperties", "before:ApplicationDefaults");
> >>     }
> >>
> >> You can see I hardcoded the string "development". I want to replace this
> >> string with another symbol
> >>
> >> @Symbol(SymbolConstants.EXECUTION_MODE) String executionMode
> >>
> >> As I need this symbol in another method (sendEmailMessage) in the
> >> AppModule I naively tried like this and failed:
> >>
> >> public class AppModule {
> >>
> >>     private String *executionMode*;
> >>
> >>     public AppModule(@Symbol(SymbolConstants.EXECUTION_MODE) String
> >> executionMode) {
> >>         this.executionMode = executionMode;
> >>     }
> >>
> >>     @Startup
> >>     public void sendEmailMessage(Logger logger) {
> >>         if ("development".equals(*executionMode*)) {
> >>             logger.info(MarkerFactory.getMarker("EDITORS"),
> "DEVELOPMENT
> >> Starting najdi-web");
> >>         } else {
> >>             logger.info(MarkerFactory.getMarker("EDITORS"), "PRODUCTION
> >> Starting najdi-web");
> >>         }
> >>     }
> >>
> >>     public void
> >> contributeSymbolSource(OrderedConfiguration<SymbolProvider> providers,
> >> Logger logger) {
> >>         providers.add("myAppConfiguration", new
> RESTSymbolProvider(logger,
> >> *executionMode*), "after:SystemProperties",
> "before:ApplicationDefaults");
> >>     }
> >> ...
> >> }
> >>
> >>
> >> Fails with:
> >>
> >> [2011/12/30 14:59:04.537] ERROR [o.a.t.i.Registry:log]: Construction of
> >> service 'SymbolSource' has failed due to recursion: the service depends
> on
> >> itself in some way. Please check
> >> org.apache.tapestry5.ioc.internal.services.SymbolSourceImpl(List) (at
> >> SymbolSourceImpl.java:198) via
> >> org.apache.tapestry5.ioc.services.TapestryIOCModule.bind(ServiceBinder)
> (at
> >> TapestryIOCModule.java:49) for references to another service that is
> itself
> >> dependent on service 'SymbolSource'.
> >> [2011/12/30 14:59:04.538] ERROR [o.a.t.i.Registry:log]: Operations
> trace:
> >> [2011/12/30 14:59:04.539] ERROR [o.a.t.i.Registry:log]: [ 1] Realizing
> >> service ServletApplicationInitializer
> >> [2011/12/30 14:59:04.539] ERROR [o.a.t.i.Registry:log]: [ 2]
> Instantiating
> >> service ServletApplicationInitializer implementation via
> >>
> org.apache.tapestry5.services.TapestryModule.buildServletApplicationInitializer(Logger,
> >> List, ApplicationInitializer) (at TapestryModule.java:1395)
> >> [2011/12/30 14:59:04.540] ERROR [o.a.t.i.Registry:log]: [ 3]
> Constructing
> >> module class org.apache.tapestry5.services.TapestryModule
> >> [2011/12/30 14:59:04.540] ERROR [o.a.t.i.Registry:log]: [ 4] Determining
> >> injection value for parameter #1
> >> (org.apache.tapestry5.ioc.services.PipelineBuilder)
> >> [2011/12/30 14:59:04.541] ERROR [o.a.t.i.Registry:log]: [ 5] Resolving
> >> object of type org.apache.tapestry5.ioc.services.PipelineBuilder using
> >> MasterObjectProvider
> >> [2011/12/30 14:59:04.541] ERROR [o.a.t.i.Registry:log]: [ 6] Realizing
> >> service ServiceOverride
> >> [2011/12/30 14:59:04.542] ERROR [o.a.t.i.Registry:log]: [ 7]
> Instantiating
> >> service ServiceOverride implementation via
> >> org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map) (at
> >> ServiceOverrideImpl.java:31) via
> >> org.apache.tapestry5.ioc.services.TapestryIOCModule.bind(ServiceBinder)
> (at
> >> TapestryIOCModule.java:49)
> >> [2011/12/30 14:59:04.542] ERROR [o.a.t.i.Registry:log]: [ 8] Creating
> plan
> >> to instantiate
> >> org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl via
> public
> >>
> org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(java.util.Map)
> >> [2011/12/30 14:59:04.543] ERROR [o.a.t.i.Registry:log]: [ 9] Determining
> >> injection value for parameter #1 (java.util.Map)
> >> [2011/12/30 14:59:04.544] ERROR [o.a.t.i.Registry:log]: [10] Collecting
> >> mapped configuration for service ServiceOverride
> >> [2011/12/30 14:59:04.544] ERROR [o.a.t.i.Registry:log]: [11] Invoking
> >>
> org.apache.tapestry5.services.TapestryModule.productionModeOverrides(MappedConfiguration,
> >> boolean) (at TapestryModule.java:2871)
> >> [2011/12/30 14:59:04.545] ERROR [o.a.t.i.Registry:log]: [12] Determining
> >> injection value for parameter #2 (boolean)
> >> [2011/12/30 14:59:04.545] ERROR [o.a.t.i.Registry:log]: [13] Resolving
> >> object of type boolean using MasterObjectProvider
> >> [2011/12/30 14:59:04.546] ERROR [o.a.t.i.Registry:log]: [14] Realizing
> >> service SymbolSource
> >> [2011/12/30 14:59:04.546] ERROR [o.a.t.i.Registry:log]: [15]
> Instantiating
> >> service SymbolSource implementation via
> >> org.apache.tapestry5.ioc.internal.services.SymbolSourceImpl(List) (at
> >> SymbolSourceImpl.java:198) via
> >> org.apache.tapestry5.ioc.services.TapestryIOCModule.bind(ServiceBinder)
> (at
> >> TapestryIOCModule.java:49)
> >> [2011/12/30 14:59:04.547] ERROR [o.a.t.i.Registry:log]: [16] Creating
> plan
> >> to instantiate
> org.apache.tapestry5.ioc.internal.services.SymbolSourceImpl
> >> via public
> >>
> org.apache.tapestry5.ioc.internal.services.SymbolSourceImpl(java.util.List)
> >> [2011/12/30 14:59:04.547] ERROR [o.a.t.i.Registry:log]: [17] Determining
> >> injection value for parameter #1 (java.util.List)
> >> [2011/12/30 14:59:04.548] ERROR [o.a.t.i.Registry:log]: [18] Collecting
> >> ordered configuration for service SymbolSource
> >> [2011/12/30 14:59:04.548] ERROR [o.a.t.i.Registry:log]: [19] Invoking
> >>
> si.najdi.web.services.AppModule.contributeSymbolSource(OrderedConfiguration,
> >> Logger) (at AppModule.java:40)
> >> [2011/12/30 14:59:04.549] ERROR [o.a.t.i.Registry:log]: [20]
> Constructing
> >> module class si.najdi.web.services.AppModule
> >> [2011/12/30 14:59:04.550] ERROR [o.a.t.i.Registry:log]: [21] Determining
> >> injection value for parameter #1 (java.lang.String)
> >> [2011/12/30 14:59:04.550] ERROR [o.a.t.i.Registry:log]: [22] Resolving
> >> object of type java.lang.String using MasterObjectProvider
> >> [2011/12/30 14:59:04.551] ERROR [o.a.t.i.Registry:log]: [23] Realizing
> >> service SymbolSource
> >> [2011/12/30 14:59:04.569] ERROR [o.a.t.i.s.T.SymbolSource:createObject]:
> >> Construction of service SymbolSource failed: Unable to instantiate class
> >> si.najdi.web.services.AppModule as a module: Exception constructing
> service
> >> 'SymbolSource': Construction of service 'SymbolSource' has failed due to
> >> recursion: the service depends on itself in some way. Please check
> >> org.apache.tapestry5.ioc.internal.services.SymbolSourceImpl(List) (at
> >> SymbolSourceImpl.java:198) via
> >> org.apache.tapestry5.ioc.services.TapestryIOCModule.bind(ServiceBinder)
> (at
> >> TapestryIOCModule.java:49) for references to another service that is
> itself
> >> dependent on service 'SymbolSource'.
> >> java.lang.RuntimeException: Unable to instantiate class
> >> si.najdi.web.services.AppModule as a module: Exception constructing
> service
> >> 'SymbolSource': Construction of service 'SymbolSource' has failed due to
> >> recursion: the service depends on itself in some way. Please check
> >> org.apache.tapestry5.ioc.internal.services.SymbolSourceImpl(List) (at
> >> SymbolSourceImpl.java:198) via
> >> org.apache.tapestry5.ioc.services.TapestryIOCModule.bind(ServiceBinder)
> (at
> >> TapestryIOCModule.java:49) for references to another service that is
> itself
> >> dependent on service 'SymbolSource'.
> >>
> >> Am I facing multiple problems here?
> >>
> >> Regards,
> >> borut
> >>
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


-- 
*Regards,*
*Muhammad Gelbana
Java Developer*

Reply via email to