Source Code Cross Referenced for Schema.java in  » Project-Management » borg » net » sf » borg » model » db » file » mdb » 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 » Project Management » borg » net.sf.borg.model.db.file.mdb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        This file is part of BORG.
003:         
004:            BORG is free software; you can redistribute it and/or modify
005:            it under the terms of the GNU General Public License as published by
006:            the Free Software Foundation; either version 2 of the License, or
007:            (at your option) any later version.
008:         
009:            BORG 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
012:            GNU General Public License for more details.
013:         
014:            You should have received a copy of the GNU General Public License
015:            along with BORG; if not, write to the Free Software
016:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         
018:        Copyright 2003 by Mike Berger
019:         */
020:        /*
021:         * Schema.java
022:         *
023:         * Created on December 31, 2003, 11:29 AM
024:         */
025:
026:        package net.sf.borg.model.db.file.mdb;
027:
028:        import java.util.Date;
029:        import java.util.HashMap;
030:        import java.util.Map;
031:        import java.util.Vector;
032:
033:        import net.sf.borg.common.VMap;
034:        import net.sf.borg.common.XTree;
035:
036:        /**
037:         *
038:         * @author  mbb
039:         */
040:
041:        // Class Schema keeps a mapping of field names to types
042:        // It is used by class Row to determine the Class for conversion
043:        // of field data to and from String
044:        // It is used by genMDBObject to generate KeyedBean and FileBeanAdapter classes
045:        public class Schema {
046:            // ---------------------------------------------------------------------------
047:            // SCHEMA
048:            // ---------------------------------------------------------------------------
049:
050:            // the mapping of type names to java classes
051:            // these are the types supported by SMDB
052:            static private HashMap typeMap_;
053:            static {
054:                typeMap_ = new HashMap();
055:                typeMap_.put("String", java.lang.String.class);
056:                typeMap_.put("Integer", java.lang.Integer.class);
057:                typeMap_.put("Date", Date.class);
058:                typeMap_.put("StringVector", Vector.class);
059:            };
060:
061:            // VMap is pretty much a Java Map. It holds the schema's
062:            // fieldname to type mapping
063:            private VMap map_;
064:
065:            private boolean init_ = false;
066:
067:            // gets the type of a given field
068:            public String getType(String field) throws Exception {
069:                String t = (String) map_.get(field);
070:                if (t == null)
071:                    throw new Exception("Field: " + field
072:                            + " not found in schema");
073:                return (t);
074:            }
075:
076:            // gets the class used to represent a given field
077:            public Class getClass(String field) throws Exception {
078:                return ((Class) typeMap_.get(getType(field)));
079:            }
080:
081:            // get the nth field name in the schema
082:            public String getField(int n) {
083:                if (n > map_.size())
084:                    return null;
085:
086:                Object o[] = map_.entrySet().toArray();
087:                Map.Entry me = (Map.Entry) o[n - 1];
088:
089:                return ((String) me.getKey());
090:            }
091:
092:            // get the number of fields in the schema
093:            public int numCols() {
094:                return (map_.size());
095:            }
096:
097:            public Schema() {
098:                map_ = new VMap();
099:            }
100:
101:            // add a field to the schema of a given type
102:            // error if the schema is already used by a DB - cannot change
103:            // the schema read from an active DB. you can add to schemas
104:            // that have yet to be written out to a DB
105:            // this is because all of the active Row objects from a DB will
106:            // be using the same schema object
107:            public void add(String field, String type) throws Exception {
108:                if (init_ == true)
109:                    throw new Exception("In-use Schema cannot be changed");
110:                map_.put(field, type);
111:            }
112:
113:            // output schema as text (to be stored in DB in a SCHEMA system Row)
114:            public String toString() {
115:
116:                return (map_.passivate());
117:            }
118:
119:            // init a schema from its text form 
120:            public void set(String txt) throws Exception {
121:                init_ = true;
122:                map_.activate(txt);
123:            }
124:
125:            // this reads a schema from a URL in **XML**
126:            public void setFromXML(XTree xt) throws Exception {
127:
128:                for (int i = 1;; i++) {
129:                    XTree field = xt.child("field", i);
130:                    if (!field.exists())
131:                        break;
132:
133:                    XTree name = field.child("name");
134:                    if (!name.exists())
135:                        throw new Exception(
136:                                "Cannot parse Schema XML - field found with no name");
137:                    XTree type = field.child("type");
138:                    if (!type.exists())
139:                        throw new Exception("Cannot parse Schema XML - field "
140:                                + name.value() + " found with no type");
141:                    add(name.value(), type.value());
142:                    //System.out.println(name.value() + "--" + type.value() );
143:                }
144:            }
145:
146:        }
ww___w.j_a_va__2__s_._c___o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.