Source Code Cross Referenced for SpeedoDiscriminator.java in  » Database-ORM » Speedo_1.4.5 » org » objectweb » speedo » metadata » 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 » Database ORM » Speedo_1.4.5 » org.objectweb.speedo.metadata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (C) 2001-2005 France Telecom R&D
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */package org.objectweb.speedo.metadata;
018:
019:        import org.objectweb.speedo.api.SpeedoRuntimeException;
020:
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.List;
024:
025:        /**
026:         * In case of filtered of vertical mapping, a discriminator permits to 
027:         * distinguish the classes of persistent instances. This class defines a 
028:         * disciminator used for the inheritance mapping. A discriminator is 
029:         * characterized by its strategy and the columns or field composing the 
030:         * discriminator.
031:         * 
032:         * @see org.objectweb.speedo.metadata.SpeedoInheritance
033:         * @see org.objectweb.speedo.metadata.SpeedoField
034:         * @see org.objectweb.speedo.metadata.SpeedoColumn
035:         *
036:         * @author S.Chassande-Barrioz
037:         */
038:        public class SpeedoDiscriminator extends SpeedoElement {
039:
040:            private static final long serialVersionUID = -80022949706114184L;
041:
042:            public final static int STRATEGY_UNKNOWN = -1;
043:            /**
044:             * strategy without discriminator 
045:             */
046:            public final static int STRATEGY_NONE = 0;
047:
048:            /**
049:             * strategy of discriminator based on couples (class , value). To each value
050:             * corresponds only one value and to each concrete class corresponds an 
051:             * unique value. Each classes has to defines its value.
052:             */
053:            public final static int STRATEGY_MAP_VALUE = 1;
054:
055:            /**
056:             * This strategy of discriminator is a specialization of the 
057:             * STRATEGY_MAP_VALUE strategy. With this strategy the value associated to
058:             * each persistent and concrete class is the class name.
059:             */
060:            public final static int STRATEGY_CLASS_NAME = 2;
061:
062:            /**
063:             * The list of strategy names used for the parsing and the printing.
064:             */
065:            private final static String[] STRATEGY_NAMES = { "none",
066:                    "value-map", "class-name" };
067:
068:            /**
069:             * @param s is a strategy
070:             * @return string representation of the strategy. If the strategy is not
071:             * recongnized a null value is returned.
072:             */
073:            public final static String strategy2str(int s) {
074:                if (-1 < s && s < STRATEGY_NAMES.length) {
075:                    return STRATEGY_NAMES[s];
076:                } else {
077:                    return null;
078:                }
079:            }
080:
081:            /**
082:             * Parses a string representation of a strategy.
083:             * @param strategyName is a representation of a strategy
084:             * @return the strategy corrresponding to the strategy name. If the strategy is not
085:             * recongnized STRATEGY_UNKNOWN is returned.
086:             */
087:            public final static int parseStrategy(String strategyName) {
088:                for (int i = 0; i < STRATEGY_NAMES.length; i++) {
089:                    if (STRATEGY_NAMES[i].equals(strategyName)) {
090:                        return i;
091:                    }
092:                }
093:                return STRATEGY_UNKNOWN;
094:            }
095:
096:            /**
097:             * In case of filtered of vertical mapping, a discriminator permits to 
098:             * distinguish the classes of persistent instances. This field defines the
099:             * strategy of the discriminator. The default value is 
100:             * #STRATEGY_NONE, corresponding to the case of there is no
101:             * discriminator. Possible values are defined as constant in this class: 
102:             * @see #STRATEGY_NONE 
103:             * @see #STRATEGY_MAP_VALUE 
104:             * @see #STRATEGY_CLASS_NAME 
105:             */
106:            public int strategy = STRATEGY_NONE;
107:
108:            /**
109:             * If discriminatorStrategy equals to #STRATEGY_NONE this field has no sense.
110:             * Otherwise this field defines the columns of fields composing the 
111:             * discriminator. Elements of this list can be SpeedoField or
112:             * SpeedoNoFieldColumn instances.
113:             * @see SpeedoColumn
114:             * @see SpeedoField
115:             * @see SpeedoNoFieldColumn
116:             * @see SpeedoInheritance#discriminator
117:             * @see SpeedoInheritance#discriminatorValues
118:             */
119:            public List elements;
120:
121:            public String expression;
122:
123:            /**
124:             * @return a boolean value indicating if the strategy is not NONE and if 
125:             * there is elements composing the discriminator.
126:             */
127:            public boolean hasDiscriminator() {
128:                return strategy != STRATEGY_NONE
129:                        && (elements != null && 0 < elements.size() || expression != null);
130:            }
131:
132:            /**
133:             * @return boolean value indicating if there is a discriminator composed
134:             * of fields.
135:             */
136:            public boolean basedOnFieldsOnly() {
137:                if (!hasDiscriminator()) {
138:                    return false;
139:                }
140:                for (Iterator iter = elements.iterator(); iter.hasNext();) {
141:                    if (!(iter.next() instanceof  SpeedoField)) {
142:                        return false;
143:                    }
144:                }
145:                return true;
146:            }
147:
148:            /**
149:             * @return boolean value indicating if there is a discriminator composed
150:             * of columns only.
151:             */
152:            public boolean basedOnColumnsOnly() {
153:                if (!hasDiscriminator()) {
154:                    return false;
155:                }
156:                for (Iterator iter = elements.iterator(); iter.hasNext();) {
157:                    if (!(iter.next() instanceof  SpeedoColumn)) {
158:                        return false;
159:                    }
160:                }
161:                return true;
162:            }
163:
164:            public boolean basedOnFieldsAndColumns() {
165:                if (!hasDiscriminator()) {
166:                    return false;
167:                }
168:                boolean field = false;
169:                boolean column = false;
170:                for (Iterator iter = elements.iterator(); iter.hasNext()
171:                        & (!field | !column);) {
172:                    if (iter.next() instanceof  SpeedoField) {
173:                        field = true;
174:                    } else if (iter.next() instanceof  SpeedoColumn) {
175:                        column = true;
176:                    }
177:                }
178:                return field & column;
179:            }
180:
181:            public void setDiscriminatorValue(Object value,
182:                    SpeedoInheritance si, SpeedoElement elem) {
183:                if (!elements.contains(elem)) {
184:                    throw new SpeedoRuntimeException(
185:                            elem
186:                                    + " has not been defined as discriminator part for the class "
187:                                    + si.clazz.getFQName());
188:                }
189:                if (si.discriminatorValues == null) {
190:                    si.discriminatorValues = new HashMap();
191:                }
192:                si.discriminatorValues.put(elem, value);
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.