FileDocCategorySizeDatePackage
ConstructorNode.javaAPI DocGlassfish v2 API6525Tue May 22 16:54:36 BST 2007oracle.toplink.essentials.internal.parsing

ConstructorNode

public class ConstructorNode extends Node
INTERNAL

Purpose: Represent a constructor node (NEW)

Responsibilities:

  • Generate the correct expression for a constructor

Fields Summary
private String
className
The name of the constructor class.
public List
constructorItems
The list of constructor call argument nodes
Constructors Summary
public ConstructorNode(String className)
Return a new ConstructorNode


             
       
        this.className = className;
    
Methods Summary
public voidaddConstructorItem(java.lang.Object theNode)
INTERNAL Add an Order By Item to this node

        constructorItems.add(theNode);
    
public voidapplyToQuery(oracle.toplink.essentials.queryframework.ObjectLevelReadQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext context)
INTERNAL Apply this node to the passed query

        if (theQuery instanceof ReportQuery) {
            SelectGenerationContext selectContext = (SelectGenerationContext)context;
            ReportQuery reportQuery = (ReportQuery)theQuery;
            reportQuery.beginAddingConstructorArguments(
                getConstructorClass(context.getParseTreeContext()));
            for (Iterator i = constructorItems.iterator(); i.hasNext();) {
                Node node = (Node)i.next();
                if (selectingRelationshipField(node, context)) {
                    selectContext.useOuterJoins();
                }
                node.applyToQuery(reportQuery, context);
                selectContext.dontUseOuterJoins();
            }
            reportQuery.endAddingToConstructorItem();
        }
    
public java.lang.StringgetAsString()
INTERNAL Get the string representation of this node.

        StringBuffer repr = new StringBuffer();
        repr.append("NEW ").append(className);
        repr.append("(");
        for (Iterator i = constructorItems.iterator(); i.hasNext();) {
            Node node = (Node)i.next();
            repr.append(node.getAsString());
            if (i.hasNext()) {
                repr.append(", ");
            }
        }
        repr.append(")");
        return repr.toString();
    
private java.lang.ClassgetConstructorClass(oracle.toplink.essentials.internal.parsing.ParseTreeContext context)
Check the specifid constructor class and return its class instance.

exception
EJBQLException if the specified constructor class could not be found.

        Object type = getType();
        if (type == null) {
            throw EJBQLException.constructorClassNotFound(
                context.getQueryInfo(), getLine(), getColumn(), className);
        }
        return (Class)type;
    
public java.util.ListgetConstructorItems()
INTERNAL Get the list of constructor items of this node.

        return this.constructorItems;
    
public booleanisConstructorNode()
INTERNAL Is this node a ConstructorNode

        return true;
    
private booleanselectingRelationshipField(oracle.toplink.essentials.internal.parsing.Node node, oracle.toplink.essentials.internal.parsing.GenerationContext context)
INTERNAL

        if ((node == null) || !node.isDotNode()) {
            return false;
        }
        return !((DotNode)node).endsWithDirectToField(context);
    
public voidsetConstructorItems(java.util.List items)
INTERNAL Set the list of constructor items of this node.

        this.constructorItems = items;
    
public voidvalidate(oracle.toplink.essentials.internal.parsing.ParseTreeContext context)
INTERNAL Validate node and calculate its type.

        for (Iterator i = constructorItems.iterator(); i.hasNext();) {
            Node item = (Node)i.next();
            item.validate(context);
        }

        // Resolve constructor class
        TypeHelper typeHelper = context.getTypeHelper();
        Object type = typeHelper.resolveTypeName(className);
        if (type == null) {
            String name = className;
            // check for inner classes
            int index = name.lastIndexOf('.");
            if (index != -1) {
                name = name.substring(0, index) + '$" + name.substring(index+1);
                type = typeHelper.resolveTypeName(name);
            }
        }
        setType(type);