FileDocCategorySizeDatePackage
ConstructorNode.javaAPI DocHibernate 3.2.54768Tue Jul 12 15:27:30 BST 2005org.hibernate.hql.ast.tree

ConstructorNode

public class ConstructorNode extends SelectExpressionList implements SelectExpression
Represents a constructor (new) in a SELECT.
author
josh Sep 24, 2004 6:46:08 PM

Fields Summary
private Constructor
constructor
private org.hibernate.type.Type[]
constructorArgumentTypes
private boolean
isMap
private boolean
isList
Constructors Summary
Methods Summary
public java.lang.StringgetAlias()

		throw new UnsupportedOperationException("constructor may not be aliased");
	
public java.lang.String[]getAliases()

		SelectExpression[] selectExpressions = collectSelectExpressions();
		String[] aliases = new String[selectExpressions.length] ;
		for ( int i=0; i<selectExpressions.length; i++ ) {
			String alias = selectExpressions[i].getAlias();
			aliases[i] = alias==null ? Integer.toString(i) : alias;
		}
		return aliases;
	
public java.lang.reflect.ConstructorgetConstructor()

		return constructor;
	
public java.util.ListgetConstructorArgumentTypeList()

		return Arrays.asList( constructorArgumentTypes );
	
public org.hibernate.type.TypegetDataType()

deprecated
(tell clover to ignore this method)

/*
		// Return the type of the object created by the constructor.
		AST firstChild = getFirstChild();
		String text = firstChild.getText();
		if ( firstChild.getType() == SqlTokenTypes.DOT ) {
			DotNode dot = ( DotNode ) firstChild;
			text = dot.getPath();
		}
		return getSessionFactoryHelper().requireEntityType( text );
*/
		throw new UnsupportedOperationException( "getDataType() is not supported by ConstructorNode!" );
	
protected antlr.collections.ASTgetFirstSelectExpression()

		// Collect the select expressions, skip the first child because it is the class name.
		return getFirstChild().getNextSibling();
	
public FromElementgetFromElement()

		return null;
	
public booleanisConstructor()

		return true;
	
public booleanisList()

		return isList;
	
public booleanisMap()

		return isMap;
	
public booleanisReturnableEntity()

		return false;
	
public booleanisScalar()

		// Constructors are always considered scalar results.
		return true;
	
public voidprepare()

		constructorArgumentTypes = resolveConstructorArgumentTypes();
		String path = ( ( PathNode ) getFirstChild() ).getPath();
		if ( "map".equals( path.toLowerCase() ) ) {
			isMap = true;
		}
		else if ( "list".equals( path.toLowerCase() ) ) {
			isList = true;
		}
		else {
			constructor = resolveConstructor(path);
		}
	
private java.lang.reflect.ConstructorresolveConstructor(java.lang.String path)

		String importedClassName = getSessionFactoryHelper().getImportedClassName( path );
		String className = StringHelper.isEmpty( importedClassName ) ? path : importedClassName;
		if ( className == null ) {
			throw new SemanticException( "Unable to locate class [" + path + "]" );
		}
		try {
			Class holderClass = ReflectHelper.classForName( className );
			return ReflectHelper.getConstructor( holderClass, constructorArgumentTypes );
		}
		catch ( ClassNotFoundException e ) {
			throw new DetailedSemanticException( "Unable to locate class [" + className + "]", e );
		}
		catch ( PropertyNotFoundException e ) {
			// this is the exception returned by ReflectHelper.getConstructor() if it cannot
			// locate an appropriate constructor
			throw new DetailedSemanticException( "Unable to locate appropriate constructor on class [" + className + "]", e );
		}
	
private org.hibernate.type.Type[]resolveConstructorArgumentTypes()

		SelectExpression[] argumentExpressions = collectSelectExpressions();
		if ( argumentExpressions == null ) {
			// return an empty Type array
			return new Type[]{};
		}

		Type[] types = new Type[argumentExpressions.length];
		for ( int x = 0; x < argumentExpressions.length; x++ ) {
			types[x] = argumentExpressions[x].getDataType();
		}
		return types;
	
public voidsetAlias(java.lang.String alias)

		throw new UnsupportedOperationException("constructor may not be aliased");
	
public voidsetScalarColumnText(int i)

		SelectExpression[] selectExpressions = collectSelectExpressions();
		// Invoke setScalarColumnText on each constructor argument.
		for ( int j = 0; j < selectExpressions.length; j++ ) {
			SelectExpression selectExpression = selectExpressions[j];
			selectExpression.setScalarColumnText( j );
		}