TemplateParser service override

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

TemplateParser service override

Ric 2000
Hi all,

I'am new to that list, but not to Tapestry :-)

Nevertheless I face problems to override one of the Tapestry 5.4.3 internal
services, the TemplateParser.

The normal overriding with mapped config and override annotation leads to
errors.

Background is, that I want to use a customized SaxTemplateParser in order
to use an own namespace.
This is to be able to hide the Tapestry version info in the xsd declaration
of our tml files.

Can give me advice how to do it correctly?

Thanks in advance.

Kind Regards, Eric
Reply | Threaded
Open this post in threaded view
|

Re: TemplateParser service override

Mats Andersson-2
Hi Eric,

What is the error you are getting? You should be able to either override
or decorate the internal service. I guess it could be a problem with
your implementation of the service, but hard to say without knowing.

Kind Regards
Mats

On 2019-04-24 11:59, Ric 2000 wrote:

> Hi all,
>
> I'am new to that list, but not to Tapestry :-)
>
> Nevertheless I face problems to override one of the Tapestry 5.4.3 internal
> services, the TemplateParser.
>
> The normal overriding with mapped config and override annotation leads to
> errors.
>
> Background is, that I want to use a customized SaxTemplateParser in order
> to use an own namespace.
> This is to be able to hide the Tapestry version info in the xsd declaration
> of our tml files.
>
> Can give me advice how to do it correctly?
>
> Thanks in advance.
>
> Kind Regards, Eric
>
--
---------------------- Mats Andersson | Ronsoft AB | +46(0)73 368 79 82

Reply | Threaded
Open this post in threaded view
|

Re: TemplateParser service override

Ric 2000
Hi Mats,

OK thanks.
I will reproduce and let you know.

Kind Regards, Eric

On Wednesday, April 24, 2019, Mats Andersson <[hidden email]>
wrote:
> Hi Eric,
>
> What is the error you are getting? You should be able to either override
or decorate the internal service. I guess it could be a problem with your
implementation of the service, but hard to say without knowing.

>
> Kind Regards
> Mats
>
> On 2019-04-24 11:59, Ric 2000 wrote:
>>
>> Hi all,
>>
>> I'am new to that list, but not to Tapestry :-)
>>
>> Nevertheless I face problems to override one of the Tapestry 5.4.3
internal
>> services, the TemplateParser.
>>
>> The normal overriding with mapped config and override annotation leads to
>> errors.
>>
>> Background is, that I want to use a customized SaxTemplateParser in order
>> to use an own namespace.
>> This is to be able to hide the Tapestry version info in the xsd
declaration

>> of our tml files.
>>
>> Can give me advice how to do it correctly?
>>
>> Thanks in advance.
>>
>> Kind Regards, Eric
>>
> --
> ---------------------- Mats Andersson | Ronsoft AB | +46(0)73 368 79 82
>
>
Reply | Threaded
Open this post in threaded view
|

Re: TemplateParser service override

Ric 2000
In reply to this post by Mats Andersson-2
Hi,
here is the stacktrace:

Caused by: java.lang.IllegalStateException: Construction of service
'ServiceOverride' has failed due to recursion: the service depends on
itself in some way. Please check
org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map) (at
ServiceOverrideImpl.java:31) via
org.apache.tapestry5.ioc.modules.TapestryIOCModule.bind(ServiceBinder) (at
TapestryIOCModule.java:52) for references to another service that is itself
dependent on service 'ServiceOverride'.

               at
org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:53)

               at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:47)

               at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:82)

And this my override method in my filter module:

@Contribute(ServiceOverride.class)

      public void contributeAliasOverrides(MappedConfiguration<Class<?>,
Object> serviceOverrides, Map<String, URL> configuration,

                   @Symbol(SymbolConstants.COMPRESS_WHITESPACE) boolean
defaultCompressWhitespace, OperationTracker tracker) {



            serviceOverrides.add(TemplateParser.class,

                          new MspTemplateParser(configuration,
defaultCompressWhitespace, tracker));

      }

Regards, Eric

On Wednesday, April 24, 2019, Mats Andersson <[hidden email]>
wrote:
> Hi Eric,
>
> What is the error you are getting? You should be able to either override
or decorate the internal service. I guess it could be a problem with your
implementation of the service, but hard to say without knowing.

>
> Kind Regards
> Mats
>
> On 2019-04-24 11:59, Ric 2000 wrote:
>>
>> Hi all,
>>
>> I'am new to that list, but not to Tapestry :-)
>>
>> Nevertheless I face problems to override one of the Tapestry 5.4.3
internal
>> services, the TemplateParser.
>>
>> The normal overriding with mapped config and override annotation leads to
>> errors.
>>
>> Background is, that I want to use a customized SaxTemplateParser in order
>> to use an own namespace.
>> This is to be able to hide the Tapestry version info in the xsd
declaration

>> of our tml files.
>>
>> Can give me advice how to do it correctly?
>>
>> Thanks in advance.
>>
>> Kind Regards, Eric
>>
> --
> ---------------------- Mats Andersson | Ronsoft AB | +46(0)73 368 79 82
>
>
Reply | Threaded
Open this post in threaded view
|

TemplateParser service override

Ric 2000
In reply to this post by Mats Andersson-2
Hi,
here is the stacktrace:

Caused by: java.lang.IllegalStateException: Construction of service
'ServiceOverride' has failed due to recursion: the service depends on
itself in some way. Please check
org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map) (at
ServiceOverrideImpl.java:31) via
org.apache.tapestry5.ioc.modules.TapestryIOCModule.bind(ServiceBinder) (at
TapestryIOCModule.java:52) for references to another service that is itself
dependent on service 'ServiceOverride'.

               at
org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:53)

               at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:47)

               at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:82)

On Wednesday, April 24, 2019, Mats Andersson <[hidden email]>
wrote:
> Hi Eric,
>
> What is the error you are getting? You should be able to either override
or decorate the internal service. I guess it could be a problem with your
implementation of the service, but hard to say without knowing.

>
> Kind Regards
> Mats
>
> On 2019-04-24 11:59, Ric 2000 wrote:
>>
>> Hi all,
>>
>> I'am new to that list, but not to Tapestry :-)
>>
>> Nevertheless I face problems to override one of the Tapestry 5.4.3
internal
>> services, the TemplateParser.
>>
>> The normal overriding with mapped config and override annotation leads to
>> errors.
>>
>> Background is, that I want to use a customized SaxTemplateParser in order
>> to use an own namespace.
>> This is to be able to hide the Tapestry version info in the xsd
declaration

>> of our tml files.
>>
>> Can give me advice how to do it correctly?
>>
>> Thanks in advance.
>>
>> Kind Regards, Eric
>>
> --
> ---------------------- Mats Andersson | Ronsoft AB | +46(0)73 368 79 82
>
>
Reply | Threaded
Open this post in threaded view
|

Re: TemplateParser service override

Mats Andersson-2
In reply to this post by Ric 2000
I think either of these should do it. First is overriding the existing
service, second is decorating it, having the option to forward the call
to the original

   public static void
contributeServiceOverride(MappedConfiguration<Class,Object>
configuration, final Logger log)
   {
     configuration.add(TemplateParser.class, new TemplateParser() {
       @Override
       public ComponentTemplate parseTemplate(Resource resource) {
         // Handle all parsing here
       }

       @Override
       public Map<String, URL> getDTDURLMappings() {
          // TODO
       }
     });
   }

   public TemplateParser decorateTemplateParser(TemplateParser original,
final Logger log) {
     return new TemplateParser() {
       @Override
       public ComponentTemplate parseTemplate(Resource resource) {

         // Handle parsing, or leave to the original below
         return original.parseTemplate(resource);
       }

       @Override
       public Map<String, URL> getDTDURLMappings() {
         // Handle, or leave it to the original
         return original.getDTDURLMappings();
       }
     };
   }


// Mats



On 2019-04-25 15:14, Ric 2000 wrote:

> Hi,
> here is the stacktrace:
>
> Caused by: java.lang.IllegalStateException: Construction of service
> 'ServiceOverride' has failed due to recursion: the service depends on
> itself in some way. Please check
> org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map) (at
> ServiceOverrideImpl.java:31) via
> org.apache.tapestry5.ioc.modules.TapestryIOCModule.bind(ServiceBinder) (at
> TapestryIOCModule.java:52) for references to another service that is itself
> dependent on service 'ServiceOverride'.
>
>                 at
> org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:53)
>
>                 at
> org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:47)
>
>                 at
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:82)
>
> And this my override method in my filter module:
>
> @Contribute(ServiceOverride.class)
>
>        public void contributeAliasOverrides(MappedConfiguration<Class<?>,
> Object> serviceOverrides, Map<String, URL> configuration,
>
>                     @Symbol(SymbolConstants.COMPRESS_WHITESPACE) boolean
> defaultCompressWhitespace, OperationTracker tracker) {
>
>
>
>              serviceOverrides.add(TemplateParser.class,
>
>                            new MspTemplateParser(configuration,
> defaultCompressWhitespace, tracker));
>
>        }
>
> Regards, Eric
>
> On Wednesday, April 24, 2019, Mats Andersson <[hidden email]>
> wrote:
>> Hi Eric,
>>
>> What is the error you are getting? You should be able to either override
> or decorate the internal service. I guess it could be a problem with your
> implementation of the service, but hard to say without knowing.
>> Kind Regards
>> Mats
>>
>> On 2019-04-24 11:59, Ric 2000 wrote:
>>> Hi all,
>>>
>>> I'am new to that list, but not to Tapestry :-)
>>>
>>> Nevertheless I face problems to override one of the Tapestry 5.4.3
> internal
>>> services, the TemplateParser.
>>>
>>> The normal overriding with mapped config and override annotation leads to
>>> errors.
>>>
>>> Background is, that I want to use a customized SaxTemplateParser in order
>>> to use an own namespace.
>>> This is to be able to hide the Tapestry version info in the xsd
> declaration
>>> of our tml files.
>>>
>>> Can give me advice how to do it correctly?
>>>
>>> Thanks in advance.
>>>
>>> Kind Regards, Eric
>>>
>> --
>> ---------------------- Mats Andersson | Ronsoft AB | +46(0)73 368 79 82
>>
>>
--
---------------------- Mats Andersson | Ronsoft AB | +46(0)73 368 79 82


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: TemplateParser service override

Cezary Biernacki
In reply to this post by Ric 2000
Hi,
The problem you encountered is caused by attempting to pass "Map<String,
URL> configuration" to the contribute method. Unfortunately, as far as I
know, Tapestry does not provide an easy way to access to a service
configuration from its decorators or overrides.

The simplest solution in your case can be to avoid using contributed
mapping and hard-code any mappings from DTDs to resources in your class.
You can copy any existing mappings from
org.apache.tapestry5.modules.TapestryModule#contributeTemplateParser() if
you want.

On the other hand, if you really need to use actual contributions to
TemplateParser, it is possible to do that via
ServiceConfigurationListenerHub:


    private Map rememberedConfiguration;

    @Contribute(ServiceConfigurationListenerHub.class)
    public void
addListenerForTemplateParser(OrderedConfiguration<ServiceConfigurationListener>
configuration) {
        configuration.add("trackTemplateParser", new
ServiceConfigurationListener() {
            @Override
            public void onOrderedConfiguration(final ServiceDef serviceDef,
final List configuration) {
                // nothing
            }

            @Override
            public void onUnorderedConfiguration(final ServiceDef
serviceDef, final Collection configuration) {
                // nothing
            }

            @Override
            public void onMappedConfiguration(final ServiceDef serviceDef,
final Map configuration) {
                if
(serviceDef.getServiceId().equalsIgnoreCase("TemplateParser")) {
                    rememberedConfiguration = configuration;
                }
            }
        });
    }

    @Decorate(serviceInterface = TemplateParser.class)
    public TemplateParser replaceTemplateParser(
            @Symbol(SymbolConstants.COMPRESS_WHITESPACE) boolean
defaultCompressWhitespace,
            OperationTracker tracker
    ) {
        if (rememberedConfiguration == null) {
            throw new NullPointerException("Missing TemplateParser
configuration");
        }

        return new MspTemplateParser(rememberedConfiguration,
defaultCompressWhitespace, tracker);
    }


Note: instead using a service override, I need to use a decorator to
trigger creation of the default TemplateParser so its configuration can be
observed by the listener.

If there is a simpler solution, I would be happy to know :-)

Best regards,
Cezary


On Thu, Apr 25, 2019 at 3:14 PM Ric 2000 <[hidden email]> wrote:

> Hi,
> here is the stacktrace:
>
> Caused by: java.lang.IllegalStateException: Construction of service
> 'ServiceOverride' has failed due to recursion: the service depends on
> itself in some way. Please check
> org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map) (at
> ServiceOverrideImpl.java:31) via
> org.apache.tapestry5.ioc.modules.TapestryIOCModule.bind(ServiceBinder) (at
> TapestryIOCModule.java:52) for references to another service that is itself
> dependent on service 'ServiceOverride'.
>
>                at
>
> org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:53)
>
>                at
>
> org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:47)
>
>                at
>
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:82)
>
> And this my override method in my filter module:
>
> @Contribute(ServiceOverride.class)
>
>       public void contributeAliasOverrides(MappedConfiguration<Class<?>,
> Object> serviceOverrides, Map<String, URL> configuration,
>
>                    @Symbol(SymbolConstants.COMPRESS_WHITESPACE) boolean
> defaultCompressWhitespace, OperationTracker tracker) {
>
>
>
>             serviceOverrides.add(TemplateParser.class,
>
>                           new MspTemplateParser(configuration,
> defaultCompressWhitespace, tracker));
>
>       }
>
> Regards, Eric
>
> On Wednesday, April 24, 2019, Mats Andersson <[hidden email]>
> wrote:
> > Hi Eric,
> >
> > What is the error you are getting? You should be able to either override
> or decorate the internal service. I guess it could be a problem with your
> implementation of the service, but hard to say without knowing.
> >
> > Kind Regards
> > Mats
> >
> > On 2019-04-24 11:59, Ric 2000 wrote:
> >>
> >> Hi all,
> >>
> >> I'am new to that list, but not to Tapestry :-)
> >>
> >> Nevertheless I face problems to override one of the Tapestry 5.4.3
> internal
> >> services, the TemplateParser.
> >>
> >> The normal overriding with mapped config and override annotation leads
> to
> >> errors.
> >>
> >> Background is, that I want to use a customized SaxTemplateParser in
> order
> >> to use an own namespace.
> >> This is to be able to hide the Tapestry version info in the xsd
> declaration
> >> of our tml files.
> >>
> >> Can give me advice how to do it correctly?
> >>
> >> Thanks in advance.
> >>
> >> Kind Regards, Eric
> >>
> > --
> > ---------------------- Mats Andersson | Ronsoft AB | +46(0)73 368 79 82
> >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: TemplateParser service override

Ric 2000
Hi all,

thanks for your replies, which I will try one by one.
Meanwhile I started also wirh decoration of the service...

Greetings, Eric

On Friday, April 26, 2019, Cezary Biernacki <[hidden email]> wrote:

> Hi,
> The problem you encountered is caused by attempting to pass "Map<String,
> URL> configuration" to the contribute method. Unfortunately, as far as I
> know, Tapestry does not provide an easy way to access to a service
> configuration from its decorators or overrides.
>
> The simplest solution in your case can be to avoid using contributed
> mapping and hard-code any mappings from DTDs to resources in your class.
> You can copy any existing mappings from
> org.apache.tapestry5.modules.TapestryModule#contributeTemplateParser() if
> you want.
>
> On the other hand, if you really need to use actual contributions to
> TemplateParser, it is possible to do that via
> ServiceConfigurationListenerHub:
>
>
>     private Map rememberedConfiguration;
>
>     @Contribute(ServiceConfigurationListenerHub.class)
>     public void
>
addListenerForTemplateParser(OrderedConfiguration<ServiceConfigurationListener>
> configuration) {
>         configuration.add("trackTemplateParser", new
> ServiceConfigurationListener() {
>             @Override
>             public void onOrderedConfiguration(final ServiceDef
serviceDef,

> final List configuration) {
>                 // nothing
>             }
>
>             @Override
>             public void onUnorderedConfiguration(final ServiceDef
> serviceDef, final Collection configuration) {
>                 // nothing
>             }
>
>             @Override
>             public void onMappedConfiguration(final ServiceDef serviceDef,
> final Map configuration) {
>                 if
> (serviceDef.getServiceId().equalsIgnoreCase("TemplateParser")) {
>                     rememberedConfiguration = configuration;
>                 }
>             }
>         });
>     }
>
>     @Decorate(serviceInterface = TemplateParser.class)
>     public TemplateParser replaceTemplateParser(
>             @Symbol(SymbolConstants.COMPRESS_WHITESPACE) boolean
> defaultCompressWhitespace,
>             OperationTracker tracker
>     ) {
>         if (rememberedConfiguration == null) {
>             throw new NullPointerException("Missing TemplateParser
> configuration");
>         }
>
>         return new MspTemplateParser(rememberedConfiguration,
> defaultCompressWhitespace, tracker);
>     }
>
>
> Note: instead using a service override, I need to use a decorator to
> trigger creation of the default TemplateParser so its configuration can be
> observed by the listener.
>
> If there is a simpler solution, I would be happy to know :-)
>
> Best regards,
> Cezary
>
>
> On Thu, Apr 25, 2019 at 3:14 PM Ric 2000 <[hidden email]> wrote:
>
>> Hi,
>> here is the stacktrace:
>>
>> Caused by: java.lang.IllegalStateException: Construction of service
>> 'ServiceOverride' has failed due to recursion: the service depends on
>> itself in some way. Please check
>> org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map) (at
>> ServiceOverrideImpl.java:31) via
>> org.apache.tapestry5.ioc.modules.TapestryIOCModule.bind(ServiceBinder)
(at
>> TapestryIOCModule.java:52) for references to another service that is
itself
>> dependent on service 'ServiceOverride'.
>>
>>                at
>>
>>
org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:53)
>>
>>                at
>>
>>
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:47)
>>
>>                at
>>
>>
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:82)

>>
>> And this my override method in my filter module:
>>
>> @Contribute(ServiceOverride.class)
>>
>>       public void contributeAliasOverrides(MappedConfiguration<Class<?>,
>> Object> serviceOverrides, Map<String, URL> configuration,
>>
>>                    @Symbol(SymbolConstants.COMPRESS_WHITESPACE) boolean
>> defaultCompressWhitespace, OperationTracker tracker) {
>>
>>
>>
>>             serviceOverrides.add(TemplateParser.class,
>>
>>                           new MspTemplateParser(configuration,
>> defaultCompressWhitespace, tracker));
>>
>>       }
>>
>> Regards, Eric
>>
>> On Wednesday, April 24, 2019, Mats Andersson <[hidden email]>
>> wrote:
>> > Hi Eric,
>> >
>> > What is the error you are getting? You should be able to either
override

>> or decorate the internal service. I guess it could be a problem with your
>> implementation of the service, but hard to say without knowing.
>> >
>> > Kind Regards
>> > Mats
>> >
>> > On 2019-04-24 11:59, Ric 2000 wrote:
>> >>
>> >> Hi all,
>> >>
>> >> I'am new to that list, but not to Tapestry :-)
>> >>
>> >> Nevertheless I face problems to override one of the Tapestry 5.4.3
>> internal
>> >> services, the TemplateParser.
>> >>
>> >> The normal overriding with mapped config and override annotation leads
>> to
>> >> errors.
>> >>
>> >> Background is, that I want to use a customized SaxTemplateParser in
>> order
>> >> to use an own namespace.
>> >> This is to be able to hide the Tapestry version info in the xsd
>> declaration
>> >> of our tml files.
>> >>
>> >> Can give me advice how to do it correctly?
>> >>
>> >> Thanks in advance.
>> >>
>> >> Kind Regards, Eric
>> >>
>> > --
>> > ---------------------- Mats Andersson | Ronsoft AB | +46(0)73 368 79 82
>> >
>> >
>>
>