KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > metadata > SpeedoFetchGroup


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  */

25 package org.objectweb.speedo.metadata;
26
27 import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.HashSet JavaDoc;
32
33
34 /**
35  * @author Y.Bersihand
36  */

37 public class SpeedoFetchGroup extends SpeedoElement {
38     
39     public static final String JavaDoc FG_AT = "@";
40     public static final String JavaDoc FG_SHARP = "#";
41     public static final String JavaDoc FG_DOT = ".";
42     public static final String JavaDoc FG_KEY = "#key";
43     public static final String JavaDoc FG_VALUE = "#value";
44     public static final String JavaDoc FG_ELEMENT = "#element";
45     public static final String JavaDoc FG_SLASH = "/";
46     
47     public static final byte NOTHING_DEFINED = 0;
48     public static final byte DEPTH_DEFINED = 1;
49     public static final byte FG_DEFINED = 2;
50     
51     /**
52      * The name of the fetch group.
53      */

54     public String JavaDoc name;
55     
56     /**
57      * The list of nested fetchgroups.
58      */

59     protected Map JavaDoc jdoFetchGroups = new HashMap JavaDoc();
60
61     /**
62      * The list of fields declared to be in this fetch group.
63      */

64     protected Map JavaDoc jdoFields = new HashMap JavaDoc();
65
66     /**
67      * Recursive fetch group references are controlled by the depth attribute. A
68      * depth of 0 (the default) will fetch the whole graph of instances
69      * reachable from this field.
70      */

71     public int depth = 0;
72
73     /**
74      * The post-load attribute on the fetch-group element indicates whether the
75      * jdoPost-Load callback will be made when the fetch group is loaded. It
76      * defaults to false, for all fetch groups except the default fetch group,
77      * on which it defaults to true.
78      */

79     public boolean postLoad;
80  
81     /**
82      * @return Return the depth.
83      */

84     public int getDepth(){
85        return depth;
86     }
87
88     /**
89      * @return Returns the name of the fetchgroup
90      */

91     public String JavaDoc getName(){
92         return name;
93     }
94
95     /**
96      * @return Returns the postLoad.
97      */

98     public boolean getPostLoad() {
99         return postLoad;
100     }
101
102     /**
103      * @return Return the map of fields.
104      */

105     public Map JavaDoc getFields(){
106         return jdoFields;
107     }
108     
109     /**
110      * @return Returns the map of nested fetch groups
111      */

112     public Map JavaDoc getNestedFetchGroups() {
113         return jdoFetchGroups;
114     }
115
116     /**
117      * Add a new FetchGroupMetaData
118      * @param fetchGroup is the group to add
119      */

120     public void addFetchGroup(Object JavaDoc fetchGroup) {
121         SpeedoFetchGroup speedoFetchGroup = (SpeedoFetchGroup) fetchGroup;
122         jdoFetchGroups.put(speedoFetchGroup.name, speedoFetchGroup);
123     }
124
125     /**
126      * Add a new SpeedoField
127      * @param field is the field to add
128      */

129     public void addField(Object JavaDoc field) {
130         SpeedoField speedoField = (SpeedoField) field;
131         jdoFields.put(speedoField.name, speedoField);
132     }
133     
134     /**
135      * @return the set of the names of the fields to load with this fetchgroup
136      */

137     public Set JavaDoc getFieldsToLoad(){
138         Set JavaDoc fieldsToLoad = new HashSet JavaDoc();
139         //add all the fields present in the jdoFields
140
fieldsToLoad.addAll(jdoFields.keySet());
141         //recursive call on all the nested fetch groups
142
Set JavaDoc fg = jdoFetchGroups.entrySet();
143         Iterator JavaDoc it = fg.iterator();
144         while(it.hasNext()){
145             SpeedoFetchGroup sfg = (SpeedoFetchGroup) it.next();
146             fieldsToLoad.addAll(sfg.jdoFields.keySet());
147         }
148         return fieldsToLoad;
149     }
150     
151     public String JavaDoc toString(){
152         String JavaDoc s = "\n fetchgroup name: " + name +
153                     ", postload: " + postLoad +
154                     ", depth: " + depth;
155         s += ", \t fields:[";
156         Iterator JavaDoc it = jdoFields.values().iterator();
157         while (it.hasNext()) {
158             s = s + "\t" + it.next().toString();
159         }
160         s += "], \t nestedFetchGroups:[";
161         Iterator JavaDoc it2 = jdoFetchGroups.values().iterator();
162         while (it2.hasNext()) {
163             s += "\t" + it2.next().toString();
164         }
165         s += "]";
166         return s;
167     }
168 }
169
Popular Tags