001: /*
002: * $Id: DynamicViewEntity.java,v 1.3 2003/11/25 06:05:36 jonesde Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: */
024: package org.ofbiz.entity.model;
025:
026: import java.util.ArrayList;
027: import java.util.HashMap;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Map;
031:
032: import org.ofbiz.entity.GenericDelegator;
033: import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasMember;
034: import org.ofbiz.entity.model.ModelViewEntity.ModelAlias;
035: import org.ofbiz.entity.model.ModelViewEntity.ModelAliasAll;
036: import org.ofbiz.entity.model.ModelViewEntity.ModelMemberEntity;
037: import org.ofbiz.entity.model.ModelViewEntity.ModelViewLink;
038:
039: /**
040: * This class is used for declaring Dynamic View Entities, to be used and thrown away.
041: * A special method exists on the GenericDelegator to accept a DynamicViewEntity instead
042: * of an entity-name.
043: *
044: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
045: * @version $Revision: 1.3 $
046: * @since 3.0
047: */
048: public class DynamicViewEntity {
049: public static final String module = DynamicViewEntity.class
050: .getName();
051:
052: /** The entity-name of the Entity */
053: protected String entityName = "DynamicViewEntity";
054:
055: /** The package-name of the Entity */
056: protected String packageName = "org.ofbiz.dynamicview";
057:
058: /** The default-resource-name of the Entity, used with the getResource call to check for a value in a resource bundle */
059: protected String defaultResourceName = "";
060:
061: /** The title for documentation purposes */
062: protected String title = "";
063:
064: /** Contains member-entity alias name definitions: key is alias, value is ModelMemberEntity */
065: protected Map memberModelMemberEntities = new HashMap();
066:
067: /** List of alias-alls which act as a shortcut for easily pulling over member entity fields */
068: protected List aliasAlls = new ArrayList();
069:
070: /** List of aliases with information in addition to what is in the standard field list */
071: protected List aliases = new ArrayList();
072:
073: /** List of view links to define how entities are connected (or "joined") */
074: protected List viewLinks = new ArrayList();
075:
076: /** relations defining relationships between this entity and other entities */
077: protected List relations = new ArrayList();
078:
079: public DynamicViewEntity() {
080: }
081:
082: public ModelViewEntity makeModelViewEntity(
083: GenericDelegator delegator) {
084: ModelViewEntity modelViewEntity = new ModelViewEntity(this ,
085: delegator.getModelReader());
086: return modelViewEntity;
087: }
088:
089: public String getOneRealEntityName() {
090: // return first entity name for memberModelMemberEntities Map
091: if (this .memberModelMemberEntities.size() == 0) {
092: return null;
093: }
094:
095: ModelMemberEntity modelMemberEntity = (ModelMemberEntity) ((Map.Entry) this .memberModelMemberEntities
096: .entrySet().iterator().next()).getValue();
097: return modelMemberEntity.getEntityName();
098: }
099:
100: /** Getter for property entityName.
101: * @return Value of property entityName.
102: *
103: */
104: public String getEntityName() {
105: return entityName;
106: }
107:
108: /** Setter for property entityName.
109: * @param entityName New value of property entityName.
110: *
111: */
112: public void setEntityName(String entityName) {
113: this .entityName = entityName;
114: }
115:
116: /** Getter for property packageName.
117: * @return Value of property packageName.
118: *
119: */
120: public String getPackageName() {
121: return packageName;
122: }
123:
124: /** Setter for property packageName.
125: * @param packageName New value of property packageName.
126: *
127: */
128: public void setPackageName(String packageName) {
129: this .packageName = packageName;
130: }
131:
132: /** Getter for property defaultResourceName.
133: * @return Value of property defaultResourceName.
134: *
135: */
136: public String getDefaultResourceName() {
137: return defaultResourceName;
138: }
139:
140: /** Setter for property defaultResourceName.
141: * @param defaultResourceName New value of property defaultResourceName.
142: *
143: */
144: public void setDefaultResourceName(String defaultResourceName) {
145: this .defaultResourceName = defaultResourceName;
146: }
147:
148: /** Getter for property title.
149: * @return Value of property title.
150: *
151: */
152: public String getTitle() {
153: return title;
154: }
155:
156: /** Setter for property title.
157: * @param title New value of property title.
158: *
159: */
160: public void setTitle(String title) {
161: this .title = title;
162: }
163:
164: public void addMemberEntity(String entityAlias, String entityName) {
165: ModelMemberEntity modelMemberEntity = new ModelMemberEntity(
166: entityAlias, entityName);
167: this .memberModelMemberEntities.put(entityAlias,
168: modelMemberEntity);
169: }
170:
171: public Iterator getModelMemberEntitiesEntryIter() {
172: return this .memberModelMemberEntities.entrySet().iterator();
173: }
174:
175: public void addAliasAll(String entityAlias, String prefix) {
176: ModelAliasAll aliasAll = new ModelAliasAll(entityAlias, prefix);
177: this .aliasAlls.add(aliasAll);
178: }
179:
180: public void addAllAliasAllsToList(List addList) {
181: addList.addAll(this .aliasAlls);
182: }
183:
184: public void addAlias(String entityAlias, String name) {
185: this .addAlias(entityAlias, name, null, null, null, null, null);
186: }
187:
188: /** Add an alias, full detail. All parameters can be null except entityAlias and name. */
189: public void addAlias(String entityAlias, String name, String field,
190: String colAlias, Boolean primKey, Boolean groupBy,
191: String function) {
192: addAlias(entityAlias, name, field, colAlias, primKey, groupBy,
193: function, null);
194: }
195:
196: public void addAlias(String entityAlias, String name, String field,
197: String colAlias, Boolean primKey, Boolean groupBy,
198: String function, ComplexAliasMember complexAliasMember) {
199: if (entityAlias == null && complexAliasMember == null) {
200: throw new IllegalArgumentException(
201: "entityAlias cannot be null if this is not a complex alias in call to DynamicViewEntity.addAlias");
202: }
203: if (name == null) {
204: throw new IllegalArgumentException(
205: "name cannot be null in call to DynamicViewEntity.addAlias");
206: }
207:
208: ModelAlias alias = new ModelAlias(entityAlias, name, field,
209: colAlias, primKey, groupBy, function);
210: if (complexAliasMember != null) {
211: alias.setComplexAliasMember(complexAliasMember);
212: }
213: this .aliases.add(alias);
214: }
215:
216: public void addAllAliasesToList(List addList) {
217: addList.addAll(this .aliases);
218: }
219:
220: public void addViewLink(String entityAlias, String relEntityAlias,
221: Boolean relOptional, List modelKeyMaps) {
222: ModelViewLink modelViewLink = new ModelViewLink(entityAlias,
223: relEntityAlias, relOptional, modelKeyMaps);
224: this .viewLinks.add(modelViewLink);
225: }
226:
227: public void addAllViewLinksToList(List addList) {
228: addList.addAll(this .viewLinks);
229: }
230:
231: public void addRelation(String type, String title,
232: String relEntityName, List modelKeyMaps) {
233: ModelRelation relation = new ModelRelation(type, title,
234: relEntityName, null, modelKeyMaps);
235: this .relations.add(relation);
236: }
237:
238: public void addAllRelationsToList(List addList) {
239: addList.addAll(this.relations);
240: }
241: }
|