Source Code Cross Referenced for ModelRelation.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » entity » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » SourceTap CRM » org.ofbiz.entity.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ModelRelation.java,v 1.3 2004/01/19 19:26:52 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.*;
027:        import org.w3c.dom.*;
028:
029:        import org.ofbiz.base.util.*;
030:
031:        /**
032:         * Generic Entity - Relation model class
033:         *
034:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
035:         * @version    $Revision: 1.3 $
036:         * @since      2.0
037:         */
038:        public class ModelRelation {
039:
040:            /** the title, gives a name/description to the relation */
041:            protected String title;
042:
043:            /** the type: either "one" or "many" or "one-nofk" */
044:            protected String type;
045:
046:            /** the name of the related entity */
047:            protected String relEntityName;
048:
049:            /** the name to use for a database foreign key, if applies */
050:            protected String fkName;
051:
052:            /** keyMaps defining how to lookup the relatedTable using columns from this table */
053:            protected List keyMaps = new ArrayList();
054:
055:            /** the main entity of this relation */
056:            protected ModelEntity mainEntity = null;
057:
058:            /** Default Constructor */
059:            public ModelRelation() {
060:                title = "";
061:                type = "";
062:                relEntityName = "";
063:                fkName = "";
064:            }
065:
066:            /** Default Constructor */
067:            public ModelRelation(String type, String title,
068:                    String relEntityName, String fkName, List keyMaps) {
069:                this .title = title;
070:                if (title == null)
071:                    title = "";
072:                this .type = type;
073:                this .relEntityName = relEntityName;
074:                this .fkName = fkName;
075:                this .keyMaps.addAll(keyMaps);
076:            }
077:
078:            /** XML Constructor */
079:            public ModelRelation(ModelEntity mainEntity, Element relationElement) {
080:                this .mainEntity = mainEntity;
081:
082:                this .type = UtilXml.checkEmpty(relationElement
083:                        .getAttribute("type"));
084:                this .title = UtilXml.checkEmpty(relationElement
085:                        .getAttribute("title"));
086:                this .relEntityName = UtilXml.checkEmpty(relationElement
087:                        .getAttribute("rel-entity-name"));
088:                this .fkName = UtilXml.checkEmpty(relationElement
089:                        .getAttribute("fk-name"));
090:
091:                NodeList keyMapList = relationElement
092:                        .getElementsByTagName("key-map");
093:                for (int i = 0; i < keyMapList.getLength(); i++) {
094:                    Element keyMapElement = (Element) keyMapList.item(i);
095:
096:                    if (keyMapElement.getParentNode() == relationElement) {
097:                        ModelKeyMap keyMap = new ModelKeyMap(keyMapElement);
098:
099:                        if (keyMap != null) {
100:                            this .keyMaps.add(keyMap);
101:                        }
102:                    }
103:                }
104:            }
105:
106:            /** the title, gives a name/description to the relation */
107:            public String getTitle() {
108:                if (this .title == null) {
109:                    this .title = "";
110:                }
111:                return this .title;
112:            }
113:
114:            public void setTitle(String title) {
115:                if (title == null) {
116:                    this .title = "";
117:                } else {
118:                    this .title = title;
119:                }
120:            }
121:
122:            /** the type: either "one" or "many" or "one-nofk" */
123:            public String getType() {
124:                return this .type;
125:            }
126:
127:            public void setType(String type) {
128:                this .type = type;
129:            }
130:
131:            /** the name of the related entity */
132:            public String getRelEntityName() {
133:                return this .relEntityName;
134:            }
135:
136:            public void setRelEntityName(String relEntityName) {
137:                this .relEntityName = relEntityName;
138:            }
139:
140:            public String getFkName() {
141:                return this .fkName;
142:            }
143:
144:            public void setFkName(String fkName) {
145:                this .fkName = fkName;
146:            }
147:
148:            /** the main entity of this relation */
149:            public ModelEntity getMainEntity() {
150:                return this .mainEntity;
151:            }
152:
153:            public void setMainEntity(ModelEntity mainEntity) {
154:                this .mainEntity = mainEntity;
155:            }
156:
157:            /** keyMaps defining how to lookup the relatedTable using columns from this table */
158:            public Iterator getKeyMapsIterator() {
159:                return this .keyMaps.iterator();
160:            }
161:
162:            public int getKeyMapsSize() {
163:                return this .keyMaps.size();
164:            }
165:
166:            public ModelKeyMap getKeyMap(int index) {
167:                return (ModelKeyMap) this .keyMaps.get(index);
168:            }
169:
170:            public void addKeyMap(ModelKeyMap keyMap) {
171:                this .keyMaps.add(keyMap);
172:            }
173:
174:            public ModelKeyMap removeKeyMap(int index) {
175:                return (ModelKeyMap) this .keyMaps.remove(index);
176:            }
177:
178:            /** Find a KeyMap with the specified fieldName */
179:            public ModelKeyMap findKeyMap(String fieldName) {
180:                for (int i = 0; i < keyMaps.size(); i++) {
181:                    ModelKeyMap keyMap = (ModelKeyMap) keyMaps.get(i);
182:
183:                    if (keyMap.fieldName.equals(fieldName))
184:                        return keyMap;
185:                }
186:                return null;
187:            }
188:
189:            /** Find a KeyMap with the specified relFieldName */
190:            public ModelKeyMap findKeyMapByRelated(String relFieldName) {
191:                for (int i = 0; i < keyMaps.size(); i++) {
192:                    ModelKeyMap keyMap = (ModelKeyMap) keyMaps.get(i);
193:
194:                    if (keyMap.relFieldName.equals(relFieldName))
195:                        return keyMap;
196:                }
197:                return null;
198:            }
199:
200:            public String keyMapString(String separator, String afterLast) {
201:                String returnString = "";
202:
203:                if (keyMaps.size() < 1) {
204:                    return "";
205:                }
206:
207:                int i = 0;
208:
209:                for (; i < keyMaps.size() - 1; i++) {
210:                    returnString = returnString
211:                            + ((ModelKeyMap) keyMaps.get(i)).fieldName
212:                            + separator;
213:                }
214:                returnString = returnString
215:                        + ((ModelKeyMap) keyMaps.get(i)).fieldName + afterLast;
216:                return returnString;
217:            }
218:
219:            public String keyMapUpperString(String separator, String afterLast) {
220:                if (keyMaps.size() < 1)
221:                    return "";
222:
223:                StringBuffer returnString = new StringBuffer(
224:                        keyMaps.size() * 10);
225:                int i = 0;
226:                while (true) {
227:                    ModelKeyMap kmap = (ModelKeyMap) keyMaps.get(i);
228:                    returnString.append(ModelUtil
229:                            .upperFirstChar(kmap.fieldName));
230:
231:                    i++;
232:                    if (i >= keyMaps.size()) {
233:                        returnString.append(afterLast);
234:                        break;
235:                    }
236:
237:                    returnString.append(separator);
238:                }
239:
240:                return returnString.toString();
241:            }
242:
243:            public String keyMapRelatedUpperString(String separator,
244:                    String afterLast) {
245:                if (keyMaps.size() < 1)
246:                    return "";
247:
248:                StringBuffer returnString = new StringBuffer(
249:                        keyMaps.size() * 10);
250:                int i = 0;
251:                while (true) {
252:                    ModelKeyMap kmap = (ModelKeyMap) keyMaps.get(i);
253:                    returnString.append(ModelUtil
254:                            .upperFirstChar(kmap.relFieldName));
255:
256:                    i++;
257:                    if (i >= keyMaps.size()) {
258:                        returnString.append(afterLast);
259:                        break;
260:                    }
261:
262:                    returnString.append(separator);
263:                }
264:
265:                return returnString.toString();
266:            }
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.