Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.enhydra.xml.xmlc.dom.generic
Class BuildMethodMappings  view BuildMethodMappings download BuildMethodMappings.java

java.lang.Object
  extended byorg.enhydra.xml.xmlc.dom.generic.BuildMethodMappings

final class BuildMethodMappings
extends java.lang.Object

Class to calculate which elements are to have build methods created for them based on trying to optimize the amount of code (create-cost) in each build methods without overflowing the maximum create-cost.

The advantage of this object determining where build methods are created in a seperate traversal from creating the build methods is that the determination is best down from the bottom up, which creating the methods is done top-down. The seperation also keeps the code cleaner and easier to understand. The cost is building an intermediate table.


Nested Class Summary
private  class BuildMethodMappings.Record
          Node record.
 
Field Summary
static int BUILD_METHOD_CALL_CREATE_COST
          Create-cost to call a build-method.
static int CREATE_ELEMENT_NODE_CREATE_COST
          Create-cost to create an element node.
private  int fMaxCreateCostPerBuildMethod
          Maximum creation-cost that a single build method can handle.
private  java.util.HashMap fNodeRecordTable
           
private  java.util.ArrayList fTmpElementSort
          Temporary table used for sorting child elements.
 
Constructor Summary
BuildMethodMappings(int maxCreateCostPerBuildMethod, org.w3c.dom.Document document)
          Constructor.
 
Method Summary
private  void adjustElementBuild(BuildMethodMappings.Record rec)
          Move element children into other build methods until the cost of this element is below the maximum.
private  void adjustElementRecord(BuildMethodMappings.Record rec)
          Adjust an element record, if nececssary, to keep it from overflowing the maximum build method create-cost.
private  BuildMethodMappings.Record calculateElementCosts(org.w3c.dom.Node element)
          Calculate the costs of an element and its element's attributes.
private  BuildMethodMappings.Record calculateTreeCosts(org.w3c.dom.Node node)
          Traverse the tree, calculating costs and determining where build methods should be created.
 int getMethodTotalCost(org.w3c.dom.Node node)
          Get the method total cost of a node.
 int getMinMethodCost(org.w3c.dom.Node node)
          Get the minimum method cost of a node.
static int getNodeTypeCost(org.w3c.dom.Node node)
          Get the cost of creating a single node based on its type.
private  BuildMethodMappings.Record getRecord(org.w3c.dom.Node node)
          Get a record.
 int getTreeTotalCost(org.w3c.dom.Node node)
          Get the tree total cost of a node.
 boolean isMethodRoot(org.w3c.dom.Node element)
          Should a new method be created at the root of this element.
private  void moveChildIntoMethod(BuildMethodMappings.Record parent, BuildMethodMappings.Record child)
          Convert a child to being build in another element, if this will reduce the cost of building the parent.
private  void sumRecords(BuildMethodMappings.Record nodeRec, BuildMethodMappings.Record childRec)
          Sum a record with one of its children.
 java.lang.String toString(org.w3c.dom.Node node)
          Get a string repersentation of an entry for debugging.
 boolean useChainedChildrenMethods(org.w3c.dom.Node node)
          Should the children be created in a chained method?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUILD_METHOD_CALL_CREATE_COST

public static final int BUILD_METHOD_CALL_CREATE_COST
Create-cost to call a build-method.

See Also:
Constant Field Values

CREATE_ELEMENT_NODE_CREATE_COST

public static final int CREATE_ELEMENT_NODE_CREATE_COST
Create-cost to create an element node. Slightly higher due to possibility of initializing access methods.

See Also:
Constant Field Values

fMaxCreateCostPerBuildMethod

private int fMaxCreateCostPerBuildMethod
Maximum creation-cost that a single build method can handle.


fNodeRecordTable

private java.util.HashMap fNodeRecordTable

fTmpElementSort

private java.util.ArrayList fTmpElementSort
Temporary table used for sorting child elements. This table never used recursively, so one can be reused for efficient.

Constructor Detail

BuildMethodMappings

public BuildMethodMappings(int maxCreateCostPerBuildMethod,
                           org.w3c.dom.Document document)
Constructor.

Method Detail

getNodeTypeCost

public static int getNodeTypeCost(org.w3c.dom.Node node)
Get the cost of creating a single node based on its type. This does not provide cumulative costs, its based on type only.


getRecord

private BuildMethodMappings.Record getRecord(org.w3c.dom.Node node)
Get a record.


moveChildIntoMethod

private void moveChildIntoMethod(BuildMethodMappings.Record parent,
                                 BuildMethodMappings.Record child)
Convert a child to being build in another element, if this will reduce the cost of building the parent. Adjust the size of the parent.


adjustElementBuild

private void adjustElementBuild(BuildMethodMappings.Record rec)
Move element children into other build methods until the cost of this element is below the maximum. Sorting to move largest first results in fewer methods being created.


adjustElementRecord

private void adjustElementRecord(BuildMethodMappings.Record rec)
Adjust an element record, if nececssary, to keep it from overflowing the maximum build method create-cost. This must be called *before* the parent record is created.


sumRecords

private void sumRecords(BuildMethodMappings.Record nodeRec,
                        BuildMethodMappings.Record childRec)
Sum a record with one of its children.


calculateElementCosts

private BuildMethodMappings.Record calculateElementCosts(org.w3c.dom.Node element)
Calculate the costs of an element and its element's attributes.


calculateTreeCosts

private BuildMethodMappings.Record calculateTreeCosts(org.w3c.dom.Node node)
Traverse the tree, calculating costs and determining where build methods should be created. This builds the table of node records.


isMethodRoot

public boolean isMethodRoot(org.w3c.dom.Node element)
Should a new method be created at the root of this element.


useChainedChildrenMethods

public boolean useChainedChildrenMethods(org.w3c.dom.Node node)
Should the children be created in a chained method?


getMinMethodCost

public int getMinMethodCost(org.w3c.dom.Node node)
Get the minimum method cost of a node.


getMethodTotalCost

public int getMethodTotalCost(org.w3c.dom.Node node)
Get the method total cost of a node.


getTreeTotalCost

public int getTreeTotalCost(org.w3c.dom.Node node)
Get the tree total cost of a node.


toString

public java.lang.String toString(org.w3c.dom.Node node)
Get a string repersentation of an entry for debugging.