Interface with setDestination(Destination) ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Interface with setDestination(Destination) ?

cmarchand
Is there an interface (or an abstract class) that defines the void
setDestination(Destination) method ?

Trying to develop my own Java transform Step, that is between a
XslTransform and another Destination, I am forced to manipulate Object
and to cast them to XslTransform, or to my objects... and it's dirty !

Christophe

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interface with setDestination(Destination) ?

Michael Kay
Sorry, I don't think I understand clearly enough what you are trying to do or why it is difficult.

Michael Kay
Saxonica


> On 20 Apr 2016, at 21:28, Christophe Marchand <[hidden email]> wrote:
>
> Is there an interface (or an abstract class) that defines the void
> setDestination(Destination) method ?
>
> Trying to develop my own Java transform Step, that is between a
> XslTransform and another Destination, I am forced to manipulate Object
> and to cast them to XslTransform, or to my objects... and it's dirty !
>
> Christophe
>
> ------------------------------------------------------------------------------
> Find and fix application performance issues faster with Applications Manager
> Applications Manager provides deep performance insights into multiple tiers of
> your business applications. It resolves application problems quickly and
> reduces your MTTR. Get your free trial!
> https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 



------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Interface with setDestination(Destination) ?

cmarchand

 

 

I construct XSLT pipelines :

xsl1.setDestination(xsl2);
xsl2.setDestination(xsl3);
xsl3.setDestination(processor.newSerializer());
xsl1.transform();

 

Now, I've developped a Java class, which implements Destination, and has a setDestination(Destination) method, as the XsltTransformer has.

I want to insert this class between xsl2 and xsl3 :

xsl1.setDestination(xsl2);
xsl2.setDestination(javaStep);
javaStep.setDestination(xsl3);
xsl3.setDestination(processor.newSerializer());
xsl1.transform();

 

No problem.

 

Now, I have an XML model to describe the pipe :

<xs:sequence>
   <xs:element name="xslt" type="cfg:TXslt" />
   <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="xslt" type="cfg:TXslt"/>
      <xs:element name="java" type="cfg:TJava"/>
   </xs:choice>
   <xs:choice>
      <xs:element name="tee" type="cfg:TTee" />
      <xs:element name="output" type="cfg:TOutput"/>
   </xs:choice>
</xs:sequence>

 

Now, when I construct my pipe while reading the model, I have to process differently the XsltTransform and the StepJava, because both classes do not share a common interface that defines the setDestination method. And it produces ugly code :

XsltTransformer first = null;
Iterator<ParametrableStep> it = pipe.getXslts();
Object previousTransformer = null;
while(it.hasNext()) {
   ParametrableStep step = it.next();
   if(step instanceof Xslt) {
      Xslt xsl = (Xslt)step;
      XsltTransformer currentTransformer = getXsltTransformer(xsl.getHref(), parameters);
      if(first==null) {
         first = currentTransformer;
      }
      if(previousTransformer!=null) {
         if(previousTransformer instanceof XsltTransformer) {
            ((XsltTransformer)previousTransformer).setDestination(currentTransformer);
         } else if(previousTransformer instanceof StepJava) {
            ((StepJava)previousTransformer).setDestination(currentTransformer);
         }
      }
      previousTransformer = currentTransformer;
   } else if(step instanceof JavaStep) {
      JavaStep javaStep = (JavaStep)step;
      try {
         StepJava stepJava = javaStep.getStepClass().newInstance();
         if(previousTransformer!=null) {
            if(previousTransformer instanceof XsltTransformer) {
               ((XsltTransformer)previousTransformer).setDestination(stepJava);
            } else if(previousTransformer instanceof StepJava) {
               ((StepJava)previousTransformer).setDestination(stepJava);
            }
         }
         previousTransformer = stepJava;
      } catch (InstantiationException | IllegalAccessException ex) {
         throw new InvalidSyntaxException(ex);
      }
   }
}

 

If I had a HasDestination interface, I could define first and currentTransformer as HasDestination, and my code will be much more clean...

Ok, I can factorise the if ... instanceof ... chunks in a beautiful method...

 

Best regards,

Christophe

 

Le 2016-04-20 23:56, Michael Kay a écrit :

Sorry, I don't think I understand clearly enough what you are trying to do or why it is difficult.

Michael Kay
Saxonica


On 20 Apr 2016, at 21:28, Christophe Marchand <[hidden email]> wrote:

Is there an interface (or an abstract class) that defines the void
setDestination(Destination) method ?

Trying to develop my own Java transform Step, that is between a
XslTransform and another Destination, I am forced to manipulate Object
and to cast them to XslTransform, or to my objects... and it's dirty !

Christophe

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help



------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...