org.inria.ns.reflex.xml.translet
Class TemplateTemplates

java.lang.Object
  extended by org.inria.ns.reflex.xml.translet.AbstractTemplateTemplates
      extended by org.inria.ns.reflex.xml.translet.TemplateTemplates
All Implemented Interfaces:
Templates

public class TemplateTemplates
extends AbstractTemplateTemplates

As its name suggests, this class is just a template and doesn't have to be used directly (it will fail if you try to).

Its purpose is for getting its byte code, BCELifying it, changing its name and package to a custom namespaced class name, and change the hard-coded translet name ("org.acme.translet.Example") to a custom one.

The BCELified version of this class (TemplateTemplatesCreator) is used as a Templates generator, that takes as an argument the translet class name to wrap and the class name of the Templates to expose.

Overview

The objective is to have a class able to generate another class which is equivalent to THIS template class, the differences being the name (and package) of the target class, and the underlying translet class that it is supposed to use (edit the Java source of this class for more info).

We could write a BCEL program from scratch for that purpose or let the BCELifier write a squeleton for us, that we have just to correct manually so that the creator will be able to create the expected template with a custom name and a custom translet.

Code update

The code of this class is written, but is subject to updates/corrections like any other class.

If the Java source code of this class had to be modified, do the following:

  1. java -cp libext/bcel-n.n.jar:reflex-n.n.n.jar org.apache.bcel.util.BCELifier org.inria.ns.reflex.xml.translet.TemplateTemplates > TemplateTemplatesCreator.java

    Note that it's important to specify the BCEL library FIRST in the classpath as reflex-n.n.n.jar refers to xsltc.jar that contains only a subset of the BCEL library.

  2. Move the generated file TemplateTemplatesCreator.java in this package, that is to say: src/java/org/inria/ns/reflex/xml/translet/
  3. So far, we have a creator that is supposed to create exactly the same class as TemplateTemplates. Not so useful, let's customize it.
  4. Edit the Java source code of TemplateTemplatesCreator:
    1. create 3 private fields:
        private String myJavaName;
        private String myClassName;
        private String myTransletName;
    2. update the constructor:
        public TemplateTemplatesCreator(String myJavaName, String myClassName,  String myTransletName) {
                this.myJavaName = myJavaName;
                this.myClassName = myClassName;
                this.myTransletName = myTransletName;
    3. replace all hard-coded references with the given fields:
      "org.inria.ns.reflex.xml.translet.TemplateTemplates" with this.myClassName
      "TemplateTemplates.java" with this.myJavaName
      "org.acme.translet.Example" with this.myTransletName
    4. delete the main() method and replace with:
        public static void newClass( File workDir, String myJavaName, String myClassName, String myTransletName ) throws Exception {
          TemplateTemplatesCreator creator = new TemplateTemplatesCreator( myJavaName, myClassName, myTransletName );
          creator.create(new FileOutputStream( new File( workDir, myClassName.replace('.', '/') + ".class")));
        }
    5. Add this comment at the top:
      Do not update: this class has been generated.
       (AT)see TemplateTemplates
  5. Recompile org.inria.ns.reflex.xml.translet.TemplateTemplatesCreator
  6. Now, we have a creator that is supposed to create a custom templates.

The TemplateTemplatesCreator is used from the Compiler to generate a class that extends AbstractTemplateTemplates which itself implements Templates, the actual implementation of the Templates being the XSLTC templates that wraps the translet. The Compiler will put in the JAR our custom templates.

Author:
Philippe Poulard
See Also:
TemplateTemplatesCreator, Templates, AbstractTemplateTemplates, TemplatesImpl, Translet

Constructor Summary
TemplateTemplates()
          Create a new Templates, that can be used like when using JAXP.
 
Method Summary
static TemplateTemplates newInstance()
          Return the singleton of the underlying Templates.
 
Methods inherited from class org.inria.ns.reflex.xml.translet.AbstractTemplateTemplates
getOutputProperties, newTransformer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplateTemplates

public TemplateTemplates()
Create a new Templates, that can be used like when using JAXP.

DO NOT instanciate THIS CLASS, it's a template designed to create other templates classes.

Method Detail

newInstance

public static TemplateTemplates newInstance()
Return the singleton of the underlying Templates.

Returns:
The singleton.