1 21 package oracle.toplink.essentials.internal.parsing; 23 24 import java.util.*; 26 27 import oracle.toplink.essentials.exceptions.EJBQLException; 28 import oracle.toplink.essentials.queryframework.ObjectLevelReadQuery; 29 import oracle.toplink.essentials.queryframework.ReportQuery; 30 31 38 public class ConstructorNode extends Node { 39 40 41 private String className = null; 42 43 44 public List constructorItems = new ArrayList(); 45 46 49 public ConstructorNode(String className) { 50 this.className = className; 51 } 52 53 57 public void applyToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) { 58 if (theQuery instanceof ReportQuery) { 59 SelectGenerationContext selectContext = (SelectGenerationContext)context; 60 ReportQuery reportQuery = (ReportQuery)theQuery; 61 reportQuery.beginAddingConstructorArguments(getConstructorClass()); 62 for (Iterator i = constructorItems.iterator(); i.hasNext();) { 63 Node node = (Node)i.next(); 64 if (selectingRelationshipField(node, context)) { 65 selectContext.useOuterJoins(); 66 } 67 node.applyToQuery(reportQuery, context); 68 selectContext.dontUseOuterJoins(); 69 } 70 reportQuery.endAddingToConstructorItem(); 71 } 72 } 73 74 78 public void validate(ParseTreeContext context) { 79 for (Iterator i = constructorItems.iterator(); i.hasNext();) { 80 Node item = (Node)i.next(); 81 item.validate(context); 82 } 83 84 TypeHelper typeHelper = context.getTypeHelper(); 86 Object type = typeHelper.resolveTypeName(className); 87 if (type == null) { 88 String name = className; 89 int index = name.lastIndexOf('.'); 91 if (index != -1) { 92 name = name.substring(0, index) + '$' + name.substring(index+1); 93 type = typeHelper.resolveTypeName(name); 94 } 95 } 96 setType(type); 97 } 98 99 103 public boolean isConstructorNode() { 104 return true; 105 } 106 107 111 public void addConstructorItem(Object theNode) { 112 constructorItems.add(theNode); 113 } 114 115 119 public void setConstructorItems(List items) { 120 this.constructorItems = items; 121 } 122 123 127 public List getConstructorItems() { 128 return this.constructorItems; 129 } 130 131 136 private Class getConstructorClass() { 137 Object type = getType(); 138 if (type == null) { 139 throw EJBQLException.constructorClassNotFound(className); 140 } 141 return (Class )type; 142 } 143 144 147 private boolean selectingRelationshipField(Node node, GenerationContext context) { 148 if ((node == null) || !node.isDotNode()) { 149 return false; 150 } 151 return !((DotNode)node).endsWithDirectToField(context); 152 } 153 154 158 public String getAsString() { 159 StringBuffer repr = new StringBuffer (); 160 repr.append("NEW ").append(className); 161 repr.append("("); 162 for (Iterator i = constructorItems.iterator(); i.hasNext();) { 163 Node node = (Node)i.next(); 164 repr.append(node.getAsString()); 165 if (i.hasNext()) { 166 repr.append(", "); 167 } 168 } 169 repr.append(")"); 170 return repr.toString(); 171 } 172 } 173 | Popular Tags |