Source Code Cross Referenced for DiscriminatorMetaData.java in  » Database-ORM » JPOX » org » jpox » 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 » JPOX » org.jpox.metadata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************
002:        Copyright (c) 2004 Andy Jefferson and others. All rights reserved. 
003:        Licensed under the Apache License, Version 2.0 (the "License");
004:        you may not use this file except in compliance with the License.
005:        You may obtain a copy of the License at
006:
007:            http://www.apache.org/licenses/LICENSE-2.0
008:
009:        Unless required by applicable law or agreed to in writing, software
010:        distributed under the License is distributed on an "AS IS" BASIS,
011:        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        See the License for the specific language governing permissions and
013:        limitations under the License. 
014:         
015:
016:        Contributors:
017:        2004 Andy Jefferson - added initialise() method
018:            ...
019:         **********************************************************************/package org.jpox.metadata;
020:
021:        import org.jpox.util.JPOXLogger;
022:        import org.jpox.util.StringUtils;
023:
024:        /**
025:         * Representation of a discriminator in an inheritance strategy.
026:         * 
027:         * @since 1.1
028:         * @version $Revision: 1.21 $
029:         */
030:        public class DiscriminatorMetaData extends MetaData {
031:            /** strategy tag value. */
032:            protected DiscriminatorStrategy strategy = null;
033:
034:            /** Column name of discriminator */
035:            protected String columnName = null;
036:
037:            /** Value for discriminator column */
038:            protected String value = null;
039:
040:            /** Discriminator column */
041:            protected ColumnMetaData columnMetaData = null;
042:
043:            /** Whether the discriminator is indexed or not and whether it is unique */
044:            protected IndexedValue indexed = null;
045:
046:            /** Definition of any indexing of the discriminator column. */
047:            protected IndexMetaData indexMetaData;
048:
049:            /**
050:             * Constructor.
051:             * @param parent parent InheritanceMetaData instance
052:             * @param columnName Name of the column
053:             * @param value Value for discriminator column
054:             * @param strategy The strategy
055:             * @param indexed The indexed tag
056:             */
057:            public DiscriminatorMetaData(InheritanceMetaData parent,
058:                    final String columnName, final String value,
059:                    final String strategy, final String indexed) {
060:                super (parent);
061:
062:                this .columnName = (StringUtils.isWhitespace(columnName) ? null
063:                        : columnName);
064:                this .strategy = DiscriminatorStrategy
065:                        .getDiscriminatorStrategy(strategy);
066:                if (value != null && strategy == null) {
067:                    // Default to value strategy if a value is specified
068:                    this .strategy = DiscriminatorStrategy.VALUE_MAP;
069:                } else if (strategy == null) {
070:                    // Default to class strategy if no value is specified
071:                    this .strategy = DiscriminatorStrategy.CLASS_NAME;
072:                }
073:                this .indexed = IndexedValue.getIndexedValue(indexed);
074:                if (StringUtils.isWhitespace(value)) {
075:                    if (this .strategy == DiscriminatorStrategy.VALUE_MAP) {
076:                        String className = ((AbstractClassMetaData) parent
077:                                .getParent()).getFullClassName();
078:                        JPOXLogger.METADATA.warn(LOCALISER.msg("044103",
079:                                className));
080:                        this .value = className;
081:                    } else {
082:                        this .value = null;
083:                    }
084:                } else {
085:                    this .value = value;
086:                }
087:            }
088:
089:            /**
090:             * Constructor.
091:             * @param parent parent InheritanceMetaData instance
092:             * @param dmd DiscriminatorMetaData
093:             */
094:            public DiscriminatorMetaData(InheritanceMetaData parent,
095:                    final DiscriminatorMetaData dmd) {
096:                super (parent);
097:
098:                this .columnName = dmd.columnName;
099:                this .value = dmd.value;
100:                this .strategy = dmd.strategy;
101:                this .indexed = dmd.indexed;
102:                columnMetaData = new ColumnMetaData(this , dmd.columnMetaData);
103:                if (dmd.indexMetaData != null) {
104:                    indexMetaData = new IndexMetaData(dmd.indexMetaData);
105:                }
106:            }
107:
108:            /**
109:             * Initialisation method. This should be called AFTER using the populate
110:             * method if you are going to use populate. It creates the internal
111:             * convenience arrays etc needed for normal operation.
112:             */
113:            public void initialise() {
114:                // Interpret the "indexed" value to create our IndexMetaData where it wasn't specified that way
115:                if (indexMetaData == null && columnMetaData != null
116:                        && indexed != null && indexed != IndexedValue.FALSE) {
117:                    indexMetaData = new IndexMetaData(null, null,
118:                            (indexed == IndexedValue.UNIQUE) ? "true" : "false");
119:                    // Note we only support a single column discriminator here
120:                    indexMetaData.addColumn(columnMetaData);
121:                }
122:                if (indexMetaData != null) {
123:                    indexMetaData.initialise();
124:                }
125:
126:                if (columnMetaData == null && columnName != null) {
127:                    columnMetaData = new ColumnMetaData(this , columnName);
128:                    columnMetaData.initialise();
129:                }
130:
131:                setInitialised();
132:            }
133:
134:            // --------------------------- Accessors/Mutators ---------------------------
135:
136:            /**
137:             * Accessor for column MetaData.
138:             * @return Returns the column MetaData.
139:             */
140:            public ColumnMetaData getColumnMetaData() {
141:                return columnMetaData;
142:            }
143:
144:            /**
145:             * Mutator for column MetaData.
146:             * @param columnMetaData The column MetaData to set.
147:             */
148:            public void setColumnMetaData(ColumnMetaData columnMetaData) {
149:                this .columnMetaData = columnMetaData;
150:                this .columnMetaData.parent = this ;
151:            }
152:
153:            /**
154:             * Accessor for indexMetaData
155:             * @return Returns the indexMetaData.
156:             */
157:            public final IndexMetaData getIndexMetaData() {
158:                return indexMetaData;
159:            }
160:
161:            /**
162:             * Mutator for the index MetaData 
163:             * @param indexMetaData The indexMetaData to set.
164:             */
165:            public final void setIndexMetaData(IndexMetaData indexMetaData) {
166:                this .indexMetaData = indexMetaData;
167:            }
168:
169:            /**
170:             * Accessor for value.
171:             * @return Returns the value.
172:             */
173:            public String getValue() {
174:                return value;
175:            }
176:
177:            /**
178:             * Accessor for columnName.
179:             * @return Returns the columnName.
180:             */
181:            public String getColumnName() {
182:                // Return the column variant if specified, otherwise the name field
183:                if (columnMetaData != null && columnMetaData.getName() != null) {
184:                    return columnMetaData.getName();
185:                }
186:                return columnName;
187:            }
188:
189:            /**
190:             * Accessor for strategy.
191:             * @return Returns the strategy.
192:             */
193:            public final DiscriminatorStrategy getStrategy() {
194:                return strategy;
195:            }
196:
197:            /**
198:             * Accessor for indexed value.
199:             * @return Returns the indexed value.
200:             */
201:            public final IndexedValue getIndexedValue() {
202:                return indexed;
203:            }
204:
205:            /**
206:             * Mutator for columnName.
207:             * @param columnName The columnName to set.
208:             */
209:            public void setColumnName(String columnName) {
210:                this .columnName = columnName;
211:            }
212:
213:            //  ----------------------------- Utilities ---------------------------------
214:
215:            /**
216:             * Returns a string representation of the object using a prefix
217:             * @param prefix prefix string
218:             * @param indent indent string
219:             * @return a string representation of the object.
220:             */
221:            public String toString(String prefix, String indent) {
222:                StringBuffer sb = new StringBuffer();
223:                sb.append(prefix).append("<discriminator");
224:                if (strategy != null) {
225:                    sb.append(" strategy=\"" + strategy.toString() + "\"");
226:                }
227:                if (columnName != null && columnMetaData == null) {
228:                    sb.append(" column=\"" + columnName + "\"");
229:                }
230:                if (value != null) {
231:                    sb.append(" value=\"" + value + "\"");
232:                }
233:                if (indexed != null) {
234:                    sb.append(" indexed=\"" + indexed.toString() + "\"");
235:                }
236:                sb.append(">\n");
237:
238:                // Column MetaData
239:                if (columnMetaData != null) {
240:                    sb.append(columnMetaData.toString(prefix + indent, indent));
241:                }
242:
243:                // Add index
244:                if (indexMetaData != null) {
245:                    sb.append(indexMetaData.toString(prefix + indent, indent));
246:                }
247:
248:                // Add extensions
249:                sb.append(super .toString(prefix + indent, indent));
250:
251:                sb.append(prefix).append("</discriminator>\n");
252:
253:                return sb.toString();
254:            }
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.