KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > queryframework > ConstructorReportItem


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.queryframework;
23
24 import java.util.Vector JavaDoc;
25 import java.util.List JavaDoc;
26 import oracle.toplink.essentials.exceptions.QueryException;
27 import oracle.toplink.essentials.expressions.Expression;
28 import oracle.toplink.essentials.internal.queryframework.ReportItem;
29
30
31 /**
32  * <b>Purpose</b>: An item specifying a class constructor method to be used in a ReportQuery's returned results.
33  * Example:
34  * ConstructorReportItem citem = new ConstructorReportItem("Employee");
35  * citem.setResultType(Employee.class);
36  * citem.addAttribute("firstName", employees.get("firstName"));
37  * query.addConstructorReportItem(citem);
38  *
39  * when executed will return a collection of ReportQueryResults that contain Employee objects created using
40  * the new Employee(firstname) method.
41  *
42  * @author Chris Delahunt
43  * @since TopLink Essentials
44  */

45 public class ConstructorReportItem extends ReportItem {
46
47     protected Class JavaDoc[] constructorArgTypes;
48     protected List JavaDoc constructorMappings;
49     public List JavaDoc reportItems;
50     
51     public ConstructorReportItem() {
52     }
53     
54   /**
55    * Method to add an expression to be used to return the parameter that is then passed into the constructor method.
56    * Similar to ReportQuery's addAttribute method, but a name is not needed
57    * @param name - string used to look up this result in the ReportQueryResult
58    */

59     public ConstructorReportItem(String JavaDoc name) {
60         super(name,null);
61     }
62     
63   /**
64    * Method to add an expression to be used to return the parameter that is then passed into the constructor method.
65    * Similar to ReportQuery's addAttribute method, but a name is not needed
66    * @param attributeExpression
67    */

68     public void addAttribute( Expression attributeExpression) {
69         ReportItem item = new ReportItem(getName()+getReportItems().size(), attributeExpression);
70         getReportItems().add(item);
71     }
72     
73     public void addAttribute(String JavaDoc attributeName, Expression attributeExpression, List JavaDoc joinedExpressions) {
74         ReportItem item = new ReportItem(attributeName, attributeExpression);
75         item.getJoinedAttributeManager().setJoinedAttributeExpressions_(joinedExpressions);
76         getReportItems().add(item);
77     }
78     
79     public void addItem(ReportItem item) {
80         getReportItems().add(item);
81     }
82     
83     public Class JavaDoc[] getConstructorArgTypes(){
84         return constructorArgTypes;
85     }
86
87     public List JavaDoc getConstructorMappings(){
88         return constructorMappings;
89     }
90
91     public List JavaDoc getReportItems(){
92         if (reportItems==null){
93             reportItems=new Vector JavaDoc();
94         }
95         return reportItems;
96     }
97
98     /**
99      * INTERNAL:
100      * Looks up mapping for attribute during preExecute of ReportQuery
101      */

102     public void initialize(ReportQuery query) throws QueryException {
103         int size= getReportItems().size();
104         List JavaDoc mappings = new Vector JavaDoc();
105         for (int i=0;i<size;i++){
106             ReportItem item = (ReportItem)reportItems.get(i);
107             item.initialize(query);
108             mappings.add(item.getMapping());
109         }
110         setConstructorMappings(mappings);
111     }
112     
113     public boolean isContructorItem(){
114         return true;
115     }
116
117     public void setConstructorArgTypes(Class JavaDoc[] constructorArgTypes){
118         this.constructorArgTypes = constructorArgTypes;
119     }
120     
121     public void setConstructorMappings(List JavaDoc constructorMappings){
122         this.constructorMappings = constructorMappings;
123     }
124     
125     public void setReportItems(List JavaDoc reportItems){
126         this.reportItems = reportItems;
127     }
128     
129     public String JavaDoc toString() {
130         String JavaDoc string = "ConstructorReportItem(" + getName() + " -> [";
131         //don't use getReportItems to avoid creating collection.
132
if (reportItems!=null){
133             int size=reportItems.size();
134             for(int i=0;i<size;i++){
135                 string =string + reportItems.get(i).toString();
136             }
137         }
138         return string +"])";
139     }
140     
141 }
142
Popular Tags