Source Code Cross Referenced for DatabaseImpl.java in  » Database-DBMS » Ozone-1.1 » org » ozoneDB » xml » cli » 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 DBMS » Ozone 1.1 » org.ozoneDB.xml.cli 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // You can redistribute this software and/or modify it under the terms of
002:        // the Ozone Library License version 1 published by ozone-db.org.
003:        //
004:        // The original code and portions created by SMB are
005:        // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006:        //
007:        // $Id: DatabaseImpl.java,v 1.1 2001/12/18 11:03:24 per_nyfelt Exp $
008:
009:        package org.ozoneDB.xml.cli;
010:
011:        import java.util.StringTokenizer;
012:
013:        import org.xmldb.api.DatabaseManager;
014:        import org.xmldb.api.base.Collection;
015:        import org.xmldb.api.base.Configurable;
016:        import org.xmldb.api.base.Database;
017:        import org.xmldb.api.base.ErrorCodes;
018:        import org.xmldb.api.base.XMLDBException;
019:
020:        import org.ozoneDB.ExternalDatabase;
021:
022:        /**
023:         *
024:         * @author <a href="http://www.smb-tec.com">SMB</a>
025:         * @version $Revision: 1.1 $
026:         */
027:        public class DatabaseImpl extends AbstractConfigurable implements 
028:                Database {
029:
030:            //
031:            // constants
032:            //
033:
034:            private static String DB_HOST = "DB_HOST";
035:            private static String DB_NAME = "DB_NAME";
036:            private static String DB_PORT = "DB_PORT";
037:            private static String COL_NAME = "COL_NAME";
038:
039:            public static String CONFORMANCE_LEVEL = "0";
040:            public static String DATABASE_NAME = "ozoneXML";
041:
042:            // automatically register the database when the class is loaded 
043:            static {
044:                try {
045:                    org.xmldb.api.DatabaseManager
046:                            .registerDatabase(new DatabaseImpl());
047:                } catch (Exception e) {
048:                    e.printStackTrace();
049:                }
050:            }
051:
052:            /**
053:             * Zero-argument constructor.
054:             */
055:            public DatabaseImpl() {
056:                super ();
057:            }
058:
059:            /**
060:             */
061:            public String getName() throws XMLDBException {
062:                return DATABASE_NAME;
063:            }
064:
065:            /**
066:             */
067:            public Collection getCollection(String uri) throws XMLDBException {
068:                // we don't know how to handle this uri
069:                if (!acceptsURI(uri))
070:                    throw new XMLDBException(ErrorCodes.INVALID_URI,
071:                            "INVALID_URI");
072:
073:                Collection collection = null;
074:                try {
075:                    ExternalDatabase db = null;
076:                    StringBuffer ozoneDB = new StringBuffer();
077:                    if (getProperty(DB_HOST) == null)
078:                        ozoneDB.append("ozonedb:local:").append(
079:                                getProperty(DB_NAME));
080:                    else
081:                        ozoneDB.append("ozonedb:remote://").append(
082:                                getProperty(DB_HOST)).append(":").append(
083:                                getProperty(DB_PORT));
084:
085:                    System.out
086:                            .println("DatabaseImpl.getCollection() - Remote DB: "
087:                                    + getProperty(DB_HOST)
088:                                    + " "
089:                                    + getProperty(DB_PORT));
090:                    System.out
091:                            .println("DatabaseImpl.getCollection() - Local DB: "
092:                                    + getProperty(DB_NAME));
093:                    System.out
094:                            .println("DatabaseImpl.getCollection() - Load Collection: "
095:                                    + getProperty(COL_NAME));
096:
097:                    db = ExternalDatabase.openDatabase(ozoneDB.toString());
098:                    if (db == null)
099:                        throw new XMLDBException(ErrorCodes.INVALID_DATABASE,
100:                                "INVALID_DATABASE");
101:
102:                    db.reloadClasses();
103:
104:                    collection = CollectionImpl.forName(db,
105:                            getProperty(COL_NAME));
106:
107:                    if (collection == null)
108:                        throw new XMLDBException(ErrorCodes.INVALID_COLLECTION,
109:                                "INVALID_COLLECTION");
110:
111:                } catch (XMLDBException e) {
112:                    // re-throw this exception
113:                    throw e;
114:                } catch (Exception e) {
115:                    // encapsulate all other exceptions
116:                    throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e
117:                            .toString());
118:                }
119:                return collection;
120:            }
121:
122:            /**
123:             */
124:            public boolean acceptsURI(String uri) throws XMLDBException {
125:                return parseURI(uri);
126:            }
127:
128:            /**
129:             */
130:            public String getConformanceLevel() throws XMLDBException {
131:                return CONFORMANCE_LEVEL;
132:            }
133:
134:            /**
135:             * NON API CONFORM EXTENSION!
136:             */
137:            //    public Collection createRootCollection( String uri, String collectionName )
138:            //        throws XMLDBException {
139:            //        // we don't know how to handle this uri
140:            //        if ( !acceptsURI( uri ) )
141:            //            throw new XMLDBException( ErrorCodes.INVALID_URI, "INVALID_URI" );
142:            //        return null;
143:            //    }
144:            private boolean parseURI(String uri) {
145:                StringTokenizer tokenizer = new StringTokenizer(uri, ":/?",
146:                        true);
147:                boolean found = false;
148:                boolean remote = true;
149:                StringBuffer coll = new StringBuffer();
150:                StringBuffer database = new StringBuffer();
151:                int state = -1;
152:                for (int count = 0; tokenizer.hasMoreTokens(); count++) {
153:                    String token = tokenizer.nextToken();
154:                    if (count == 0) {
155:                        if (!token.equals("xmldb"))
156:                            return false;
157:                    } else if (count <= 3) {
158:                        if ((count % 2) == 1 && token.equals(":"))
159:                            ; // ignore this token
160:                        else if ((count % 2) == 0) {
161:                            if (token.equals("ozonexml"))
162:                                found = true;
163:                        }
164:                    } else if (count > 3) {
165:                        if (count == 4 && !token.equals("/"))
166:                            return false; // malformatted uri
167:                        else if (count == 4)
168:                            ;
169:                        else if (count == 5 && token.equals("/"))
170:                            remote = true; // ok, remote datebase
171:                        else if (count == 5) {
172:                            remote = false; // ok, local database
173:                            database.append("/");
174:                            database.append(token);
175:                        } else if (count == 6 && remote)
176:                            setProperty(DB_HOST, token); // remote host found
177:                        else if (count == 6)
178:                            database.append(token);
179:                        else if (count == 7 && remote && token.equals(":"))
180:                            ;
181:                        else if (count == 7)
182:                            database.append(token);
183:                        else if (count == 8 && remote)
184:                            setProperty(DB_PORT, token); // remote port found
185:                        else if (count == 8)
186:                            database.append(token);
187:                        else if (count == 9 && token.equals("?"))
188:                            ;
189:                        else if (count == 9)
190:                            database.append(token);
191:                        else if (token.equals("?"))
192:                            ;
193:                        else
194:                            coll.append(token);
195:                    }
196:                }
197:
198:                if (!remote)
199:                    if (database.length() > 0)
200:                        setProperty(DB_NAME, database.toString());
201:                    else
202:                        return false;
203:
204:                if (coll.length() > 0)
205:                    setProperty(COL_NAME, coll.toString());
206:
207:                return true;
208:            }
209:
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.