sugar4xml
Class InstanceBuilder

java.lang.Object
  extended by sugar4j.Sugar4j<InstanceBuilder>
      extended by sugar4xml.InstanceBuilder
All Implemented Interfaces:
Creator, JavaLang, JavaUtil

public class InstanceBuilder
extends Sugar4j<InstanceBuilder>

Given an existing xml, creates a Sugar4Xml subclass that writes that very xml again.

A super class may be set using setSuperClass(Class), this has the effect that the created class extends from that class instead of Sugar4Xml and element-creation calls are handled differently.
Given this sample xml data:

 <schema xmlns="http://www.w3.org/2001/XMLSchema">
   <complexType name="Car">
     <attribute type="string" required="true" name="brand"/>
   </complexType>
 </schema>
 
Without a super class assigned, the output is:
 element("schema", xmlns, "http://www.w3.org/2001/XMLSchema");
 {
   element("complexType", "name", "Car");
   {
       element("attribute", "type", "string", "required", true, "name", "brand").end();
   }
   end();
 }
 end();
 
 

With the Xsd super class set (generated using Schema2Package, like XHtml):

 schema(xmlns, "http://www.w3.org/2001/XMLSchema");
 {
   complexType(name, "Car");
   {
       attribute(type, "string", required, true, name, "brand").end();
   }
   end();
 }
 end();
 
 
With a super class set, all element and attribute names are left unquoted, thus they will referr to methods/constants of the super class, giving some static type checking. less string literals and less code to write.

The super class is expected to be previously created from Schema2Package.

Version:
$Id: InstanceBuilder.java,v 1.12 2008/02/13 23:27:12 krizzdewizz Exp $
Author:
krizzdewizz
See Also:
Schema2Package

Constructor Summary
InstanceBuilder(String classss, Reader xml, String description)
          Constructs a new instance builder.
 
Method Summary
 void doCreate()
          Creates the 'sugar'.
 Class<?> getSuperClass()
          Returns the class of which this class will extend.
 void setSuperClass(Class<?> superClass)
          Sets the class of which this class will extend.
 

Constructor Detail

InstanceBuilder

public InstanceBuilder(String classss,
                       Reader xml,
                       String description)
Constructs a new instance builder.

Parameters:
classss - The full qualified class of the generated java class.
xml - The existing 'template' xml
description - A brief description for the generated javadoc comments
Method Detail

doCreate

public void doCreate()
Description copied from interface: Creator
Creates the 'sugar'.


getSuperClass

public Class<?> getSuperClass()
Returns the class of which this class will extend.

Returns:
Class

setSuperClass

public void setSuperClass(Class<?> superClass)
Sets the class of which this class will extend.

Parameters:
superClass -
Throws:
ClassCastException - if the superClass is not a subclass of Sugar4Xml