Source Code Cross Referenced for IdentityMetaData.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:            ...
018:         **********************************************************************/package org.jpox.metadata;
019:
020:        import java.util.ArrayList;
021:        import java.util.List;
022:
023:        import org.jpox.util.StringUtils;
024:
025:        /**
026:         * Meta-Data for the datastore-identity of a class.
027:         * When used in ORM systems defines the column(s) that the identity is mapped to.
028:         * Also defines the generation strategy for the identity values.
029:         *
030:         * @since 1.1
031:         * @version $Revision: 1.18 $
032:         */
033:        public class IdentityMetaData extends MetaData implements 
034:                ColumnMetaDataContainer {
035:            /** column name value.  */
036:            protected String columnName;
037:
038:            /** strategy tag value. */
039:            protected IdentityStrategy strategy = null;
040:
041:            /** sequence tag value. */
042:            protected String sequence;
043:
044:            /** the columns */
045:            final List columns = new ArrayList();
046:
047:            /** Name of a value generator if the user wants to override the default JPOX generator. */
048:            protected String valueGeneratorName;
049:
050:            // -------------------------------------------------------------------------
051:            // Fields below here are not represented in the output MetaData. They are
052:            // for use internally in the operation of the JDO system. The majority are
053:            // for convenience to save iterating through the fields since the fields
054:            // are fixed once initialised.
055:
056:            /** Metadata for columns. */
057:            protected ColumnMetaData[] columnMetaData;
058:
059:            /**
060:             * Constructor 
061:             * @param parent parent AbstractClassMetaData instance
062:             * @param columnName Name of the column
063:             * @param strategy strategy
064:             * @param sequence sequence name
065:             */
066:            public IdentityMetaData(AbstractClassMetaData parent,
067:                    final String columnName, final String strategy,
068:                    final String sequence) {
069:                super (parent);
070:
071:                if (strategy != null
072:                        && IdentityStrategy.getIdentityStrategy(strategy) == null) {
073:                    throw new RuntimeException(LOCALISER.msg("044157"));
074:                }
075:
076:                this .columnName = (StringUtils.isWhitespace(columnName) ? null
077:                        : columnName);
078:                this .sequence = (StringUtils.isWhitespace(sequence) ? null
079:                        : sequence);
080:                if (this .sequence != null && strategy == null) {
081:                    // JDO2 Section 18.6.1. No strategy, but sequence defined means use "sequence"
082:                    this .strategy = IdentityStrategy.SEQUENCE;
083:                } else {
084:                    this .strategy = IdentityStrategy
085:                            .getIdentityStrategy(strategy);
086:                }
087:            }
088:
089:            /**
090:             * Method to initialise all internal convenience arrays needed.
091:             */
092:            public void initialise() {
093:                // Cater for user specifying column name, or columns
094:                if (columns.size() == 0 && columnName != null) {
095:                    columnMetaData = new ColumnMetaData[1];
096:                    columnMetaData[0] = new ColumnMetaData(this , columnName);
097:                } else {
098:                    columnMetaData = new ColumnMetaData[columns.size()];
099:                    for (int i = 0; i < columnMetaData.length; i++) {
100:                        columnMetaData[i] = (ColumnMetaData) columns.get(i);
101:                        columnMetaData[i].initialise();
102:                    }
103:                }
104:
105:                setInitialised();
106:            }
107:
108:            // -------------------------------- Mutators -------------------------------
109:
110:            /**
111:             * Add a new ColumnMetaData element
112:             * @param colmd The ColumnMetaData to add
113:             */
114:            public void addColumn(ColumnMetaData colmd) {
115:                columns.add(colmd);
116:                colmd.parent = this ;
117:                columnMetaData = new ColumnMetaData[columns.size()];
118:                for (int i = 0; i < columnMetaData.length; i++) {
119:                    columnMetaData[i] = (ColumnMetaData) columns.get(i);
120:                }
121:            }
122:
123:            /**
124:             * Mutator for the name of the value generator to use for this strategy.
125:             * @param generator Name of value generator
126:             */
127:            public void setValueGeneratorName(String generator) {
128:                if (StringUtils.isWhitespace(generator)) {
129:                    valueGeneratorName = null;
130:                } else {
131:                    this .valueGeneratorName = generator;
132:                }
133:            }
134:
135:            // -------------------------------- Accessors ------------------------------
136:
137:            /**
138:             * Accessor for columnMetaData
139:             * @return Returns the columnMetaData.
140:             */
141:            public final ColumnMetaData[] getColumnMetaData() {
142:                return columnMetaData;
143:            }
144:
145:            /**
146:             * Accessor for the column name.
147:             * @return column name
148:             */
149:            public String getColumnName() {
150:                return columnName;
151:            }
152:
153:            /**
154:             * Accessor for the strategy tag value
155:             * @return strategy tag value
156:             */
157:            public IdentityStrategy getValueStrategy() {
158:                return strategy;
159:            }
160:
161:            /**
162:             * Accessor for the sequence name
163:             * @return sequence name
164:             */
165:            public String getSequence() {
166:                return sequence;
167:            }
168:
169:            /**
170:             * Name of a (user-provided) value generator to override the default JPOX generator for this strategy.
171:             * @return Name of user provided value generator
172:             */
173:            public String getValueGeneratorName() {
174:                return valueGeneratorName;
175:            }
176:
177:            // ------------------------------ Utilities --------------------------------
178:
179:            /**
180:             * Returns a string representation of the object using a prefix
181:             * @param prefix prefix string
182:             * @param indent indent string
183:             * @return a string representation of the object.
184:             */
185:            public String toString(String prefix, String indent) {
186:                StringBuffer sb = new StringBuffer();
187:                if (strategy != null) {
188:                    sb.append(prefix)
189:                            .append(
190:                                    "<datastore-identity strategy=\""
191:                                            + strategy + "\"");
192:                } else {
193:                    sb.append(prefix).append("<datastore-identity");
194:                }
195:
196:                if (columnName != null) {
197:                    sb.append("\n").append(prefix).append(
198:                            "        column=\"" + columnName + "\"");
199:                }
200:                if (sequence != null) {
201:                    sb.append("\n").append(prefix).append(
202:                            "        sequence=\"" + sequence + "\"");
203:                }
204:
205:                if ((columnMetaData != null && columnMetaData.length > 0)
206:                        || getNoOfExtensions() > 0) {
207:                    sb.append(">\n");
208:
209:                    // Add columns
210:                    if (columnMetaData != null) {
211:                        for (int i = 0; i < columnMetaData.length; i++) {
212:                            sb.append(columnMetaData[i].toString(prefix
213:                                    + indent, indent));
214:                        }
215:                    }
216:
217:                    // Add extensions
218:                    sb.append(super .toString(prefix + indent, indent));
219:
220:                    sb.append(prefix).append("</datastore-identity>\n");
221:                } else {
222:                    sb.append("/>\n");
223:                }
224:
225:                return sb.toString();
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.