KickJava   Java API By Example, From Geeks To Geeks.

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


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
25 import oracle.toplink.essentials.internal.localization.ExceptionLocalization;
26 import oracle.toplink.essentials.sessions.DatabaseRecord;
27
28 /**
29  * <p><b>Purpose</b>:
30  * Concrete class to represent the FieldResult structure as defined by
31  * the EJB 3.0 Persistence specification. This class is a subcompent of the
32  * EntityResult.
33  *
34  * @see EntityResult
35  * @author Gordon Yorke
36  * @since TopLink Java Essentials
37  */

38
39 public class FieldResult {
40     /** Stores the name of the bean attribute */
41     protected String JavaDoc attributeName;
42     /** Stores passed in field name split on the '.' character */
43     protected String JavaDoc[] multipleFieldIdentifiers;
44     /** FieldResult now can contain multiple FieldResults in a collection if an attribute has multiple fields */
45     java.util.Vector JavaDoc fieldResults;
46     
47     /** Stores the Columns name from the result set that contains the attribute value */
48     protected String JavaDoc columnName;
49     
50     public FieldResult(String JavaDoc attributeName, String JavaDoc column){
51         this.columnName = column;
52         if (attributeName == null || this.columnName == null){
53             throw new IllegalArgumentException JavaDoc(ExceptionLocalization.buildMessage("null_values_for_field_result"));
54         }
55         multipleFieldIdentifiers = attributeName.split("\\.",0);
56         this.attributeName = multipleFieldIdentifiers[0];
57     }
58     
59     public String JavaDoc getAttributeName(){
60         return this.attributeName;
61     }
62     
63     public String JavaDoc getColumnName(){
64         return this.columnName;
65     }
66     
67     /**
68      * INTERNAL:
69      * This method is a convience method for extracting values from Results
70      */

71     public Object JavaDoc getValueFromRecord(DatabaseRecord record){
72         return record.get(this.columnName);
73     }
74     
75     /**
76      * INTERNAL:
77      */

78     public java.util.Vector JavaDoc getFieldResults(){
79         return fieldResults;
80     }
81     
82     /**
83      * INTERNAL:
84      */

85     public String JavaDoc[] getMultipleFieldIdentifiers(){
86         return multipleFieldIdentifiers;
87     }
88     
89     /**
90      * INTERNAL:
91      * This method is used to support mapping multiple fields, fields are
92      * concatenated/added to one fieldResult.
93      */

94     public void add(FieldResult newFieldResult){
95       if( fieldResults ==null){
96           fieldResults = new java.util.Vector JavaDoc();
97           fieldResults.add(this);
98       }
99       fieldResults.add(newFieldResult);
100     }
101     
102 }
103
Popular Tags