org.enhydra.xml.xmlc.dom.generic
Class BuildMethodMappings

java.lang.Object
  |
  +--org.enhydra.xml.xmlc.dom.generic.BuildMethodMappings

final class BuildMethodMappings
extends Object

Class to calculate which node 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.

Build methods are normally rooted at a subtree. Costs are adjusted by moving the creation of children into sub-build methods. This leaves just the cost of calling the build method. If the build cost is till too high after moving all children into build methods, the methods are chained together to handle creating the children.

Note that the tree is a bit more comple than just the child nodes. Elements have attributes and DocumentTypes have lists of nodes. Collectively, these are refered to as contained nodes.

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, while 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.


Field Summary
static int BUILD_METHOD_CALL_CREATE_COST
          Create-cost to call a build-method.
static int CREATE_ELEMENT_CREATE_COST
          Create-cost to create an element node.
static int CREATE_NODE_CREATE_COST
          Create-cost to create other nodes.
 
Constructor Summary
BuildMethodMappings(int maxCreateCostPerBuildMethod, Document document)
          Constructor.
 
Method Summary
(package private)  boolean canBeMethodRoot(Node node)
          Policy control: Determine if a node can be the root of a build method.
 int getCreateCost(Node node)
          Get the create cost of a node in it's method.
 int getNodeTypeCost(Node node)
          Policy control: Get the cost of creating a single node based on its type.
 boolean isMethodRoot(Node node)
          Should a new method be created at the root of this node.
 String toString(Node node)
          Get a string repersentation of an entry for debugging.
 boolean useChainedChildrenMethods(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.

CREATE_ELEMENT_CREATE_COST

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

CREATE_NODE_CREATE_COST

public static final int CREATE_NODE_CREATE_COST
Create-cost to create other nodes.
Constructor Detail

BuildMethodMappings

public BuildMethodMappings(int maxCreateCostPerBuildMethod,
                           Document document)
Constructor.
Method Detail

canBeMethodRoot

boolean canBeMethodRoot(Node node)
Policy control: Determine if a node can be the root of a build method. Change the logic here maybe useful in getting better packing.

getNodeTypeCost

public int getNodeTypeCost(Node node)
Policy control: Get the cost of creating a single node based on its type. This does not provide cumulative costs, its based on type only.

isMethodRoot

public boolean isMethodRoot(Node node)
Should a new method be created at the root of this node.

useChainedChildrenMethods

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

getCreateCost

public int getCreateCost(Node node)
Get the create cost of a node in it's method.

toString

public String toString(Node node)
Get a string repersentation of an entry for debugging.


Copyright © 1999-2002 enhydra.org (Mark Diekhans, David Li, Richard Kunze). All Rights reserved.