KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > model > DynamicViewEntity


1 /*
2  * $Id: DynamicViewEntity.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.entity.model;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import org.ofbiz.entity.GenericDelegator;
33 import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasMember;
34 import org.ofbiz.entity.model.ModelViewEntity.ModelAlias;
35 import org.ofbiz.entity.model.ModelViewEntity.ModelAliasAll;
36 import org.ofbiz.entity.model.ModelViewEntity.ModelMemberEntity;
37 import org.ofbiz.entity.model.ModelViewEntity.ModelViewLink;
38 /**
39  * This class is used for declaring Dynamic View Entities, to be used and thrown away.
40  * A special method exists on the GenericDelegator to accept a DynamicViewEntity instead
41  * of an entity-name.
42  *
43  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
44  * @version $Rev: 5462 $
45  * @since 3.0
46  */

47 public class DynamicViewEntity {
48     public static final String JavaDoc module = DynamicViewEntity.class.getName();
49
50     /** The entity-name of the Entity */
51     protected String JavaDoc entityName = "DynamicViewEntity";
52
53     /** The package-name of the Entity */
54     protected String JavaDoc packageName = "org.ofbiz.dynamicview";
55
56     /** The default-resource-name of the Entity, used with the getResource call to check for a value in a resource bundle */
57     protected String JavaDoc defaultResourceName = "";
58
59     /** The title for documentation purposes */
60     protected String JavaDoc title = "";
61
62     /** Contains member-entity alias name definitions: key is alias, value is ModelMemberEntity */
63     protected Map JavaDoc memberModelMemberEntities = new HashMap JavaDoc();
64     
65     /** List of alias-alls which act as a shortcut for easily pulling over member entity fields */
66     protected List JavaDoc aliasAlls = new ArrayList JavaDoc();
67
68     /** List of aliases with information in addition to what is in the standard field list */
69     protected List JavaDoc aliases = new ArrayList JavaDoc();
70
71     /** List of view links to define how entities are connected (or "joined") */
72     protected List JavaDoc viewLinks = new ArrayList JavaDoc();
73     
74     /** relations defining relationships between this entity and other entities */
75     protected List JavaDoc relations = new ArrayList JavaDoc();
76     
77     public DynamicViewEntity() {
78     }
79     
80     public ModelViewEntity makeModelViewEntity(GenericDelegator delegator) {
81         ModelViewEntity modelViewEntity = new ModelViewEntity(this, delegator.getModelReader());
82         return modelViewEntity;
83     }
84     
85     public String JavaDoc getOneRealEntityName() {
86         // return first entity name for memberModelMemberEntities Map
87
if (this.memberModelMemberEntities.size() == 0) {
88             return null;
89         }
90         
91         ModelMemberEntity modelMemberEntity = (ModelMemberEntity) ((Map.Entry JavaDoc) this.memberModelMemberEntities.entrySet().iterator().next()).getValue();
92         return modelMemberEntity.getEntityName();
93     }
94     
95     /** Getter for property entityName.
96      * @return Value of property entityName.
97      *
98      */

99     public String JavaDoc getEntityName() {
100         return entityName;
101     }
102     
103     /** Setter for property entityName.
104      * @param entityName New value of property entityName.
105      *
106      */

107     public void setEntityName(String JavaDoc entityName) {
108         this.entityName = entityName;
109     }
110     
111     /** Getter for property packageName.
112      * @return Value of property packageName.
113      *
114      */

115     public String JavaDoc getPackageName() {
116         return packageName;
117     }
118     
119     /** Setter for property packageName.
120      * @param packageName New value of property packageName.
121      *
122      */

123     public void setPackageName(String JavaDoc packageName) {
124         this.packageName = packageName;
125     }
126     
127     /** Getter for property defaultResourceName.
128      * @return Value of property defaultResourceName.
129      *
130      */

131     public String JavaDoc getDefaultResourceName() {
132         return defaultResourceName;
133     }
134     
135     /** Setter for property defaultResourceName.
136      * @param defaultResourceName New value of property defaultResourceName.
137      *
138      */

139     public void setDefaultResourceName(String JavaDoc defaultResourceName) {
140         this.defaultResourceName = defaultResourceName;
141     }
142     
143     /** Getter for property title.
144      * @return Value of property title.
145      *
146      */

147     public String JavaDoc getTitle() {
148         return title;
149     }
150     
151     /** Setter for property title.
152      * @param title New value of property title.
153      *
154      */

155     public void setTitle(String JavaDoc title) {
156         this.title = title;
157     }
158
159     public void addMemberEntity(String JavaDoc entityAlias, String JavaDoc entityName) {
160         ModelMemberEntity modelMemberEntity = new ModelMemberEntity(entityAlias, entityName);
161         this.memberModelMemberEntities.put(entityAlias, modelMemberEntity);
162     }
163     
164     public Iterator JavaDoc getModelMemberEntitiesEntryIter() {
165         return this.memberModelMemberEntities.entrySet().iterator();
166     }
167     
168     public void addAliasAll(String JavaDoc entityAlias, String JavaDoc prefix) {
169         ModelAliasAll aliasAll = new ModelAliasAll(entityAlias, prefix);
170         this.aliasAlls.add(aliasAll);
171     }
172     
173     public void addAllAliasAllsToList(List JavaDoc addList) {
174         addList.addAll(this.aliasAlls);
175     }
176     
177     public void addAlias(String JavaDoc entityAlias, String JavaDoc name) {
178         this.addAlias(entityAlias, name, null, null, null, null, null);
179     }
180
181     /** Add an alias, full detail. All parameters can be null except entityAlias and name. */
182     public void addAlias(String JavaDoc entityAlias, String JavaDoc name, String JavaDoc field, String JavaDoc colAlias, Boolean JavaDoc primKey, Boolean JavaDoc groupBy, String JavaDoc function) {
183         addAlias(entityAlias, name, field, colAlias, primKey, groupBy, function, null);
184     }
185     
186     public void addAlias(String JavaDoc entityAlias, String JavaDoc name, String JavaDoc field, String JavaDoc colAlias, Boolean JavaDoc primKey, Boolean JavaDoc groupBy, String JavaDoc function, ComplexAliasMember complexAliasMember) {
187         if (entityAlias == null && complexAliasMember == null) {
188             throw new IllegalArgumentException JavaDoc("entityAlias cannot be null if this is not a complex alias in call to DynamicViewEntity.addAlias");
189         }
190         if (name == null) {
191             throw new IllegalArgumentException JavaDoc("name cannot be null in call to DynamicViewEntity.addAlias");
192         }
193         
194         ModelAlias alias = new ModelAlias(entityAlias, name, field, colAlias, primKey, groupBy, function);
195         if (complexAliasMember != null) {
196             alias.setComplexAliasMember(complexAliasMember);
197         }
198         this.aliases.add(alias);
199     }
200     
201     public void addAllAliasesToList(List JavaDoc addList) {
202         addList.addAll(this.aliases);
203     }
204     
205     public void addViewLink(String JavaDoc entityAlias, String JavaDoc relEntityAlias, Boolean JavaDoc relOptional, List JavaDoc modelKeyMaps) {
206         ModelViewLink modelViewLink = new ModelViewLink(entityAlias, relEntityAlias, relOptional, modelKeyMaps);
207         this.viewLinks.add(modelViewLink);
208     }
209     
210     public void addAllViewLinksToList(List JavaDoc addList) {
211         addList.addAll(this.viewLinks);
212     }
213     
214     public void addRelation(String JavaDoc type, String JavaDoc title, String JavaDoc relEntityName, List JavaDoc modelKeyMaps) {
215         ModelRelation relation = new ModelRelation(type, title, relEntityName, null, modelKeyMaps);
216         this.relations.add(relation);
217     }
218     
219     public void addAllRelationsToList(List JavaDoc addList) {
220         addList.addAll(this.relations);
221     }
222 }
223
Popular Tags