Source Code Cross Referenced for XMLTransporter.java in  » J2EE » Sofia » com » salmonllc » xml » 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 » J2EE » Sofia » com.salmonllc.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.xml;
002:
003:        /////////////////////////
004:        //$Archive: /SOFIA/SourceCode/com/salmonllc/xml/XMLTransporter.java $
005:        //$Author: Dan $ 
006:        //$Revision: 26 $ 
007:        //$Modtime: 6/11/03 4:30p $ 
008:        /////////////////////////
009:        import com.salmonllc.sql.*;
010:
011:        /**
012:         * XML Transporter is used to transport data to and from data store as XML documents based on datastore.dtd file.
013:         * Datastore.dtd file is a representation of java.sql.ResultSet class.
014:         */
015:        public class XMLTransporter {
016:            static String _sComments = null;
017:
018:            /**
019:             * XMLTransporter constructor comment.
020:             */
021:            public XMLTransporter() {
022:                super ();
023:                _sComments = null;
024:            }
025:
026:            private static String getBooleanValue(boolean bvalue) {
027:                if (bvalue)
028:                    return "true";
029:                return "false";
030:            }
031:
032:            /**
033:             * Insert the method's description here.
034:             * Creation date: (7/19/2002 3:07:02 PM)
035:             * @return java.lang.String
036:             */
037:            public static String getComments() {
038:                return _sComments;
039:            }
040:
041:            /**
042:             * Creation date: (8/1/01 11:09:17 AM)
043:             * @return int
044:             * @param strDataType java.lang.String
045:             */
046:            public static int mapDataType(String strDataType) {
047:
048:                if (strDataType == null)
049:                    return 0;
050:                else if (strDataType.equalsIgnoreCase("String"))
051:                    return DataStore.DATATYPE_STRING;
052:                else if (strDataType.equalsIgnoreCase("Integer"))
053:                    return DataStore.DATATYPE_INT;
054:                else if (strDataType.equalsIgnoreCase("Datetime"))
055:                    return DataStore.DATATYPE_DATETIME;
056:                else if (strDataType.equalsIgnoreCase("double"))
057:                    return DataStore.DATATYPE_DOUBLE;
058:                else if (strDataType.equalsIgnoreCase("bytearray"))
059:                    return DataStore.DATATYPE_BYTEARRAY;
060:                else if (strDataType.equalsIgnoreCase("short"))
061:                    return DataStore.DATATYPE_SHORT;
062:                else if (strDataType.equalsIgnoreCase("long"))
063:                    return DataStore.DATATYPE_LONG;
064:                else if (strDataType.equalsIgnoreCase("float"))
065:                    return DataStore.DATATYPE_FLOAT;
066:                else if (strDataType.equalsIgnoreCase("date"))
067:                    return DataStore.DATATYPE_DATE;
068:                else if (strDataType.equalsIgnoreCase("time"))
069:                    return DataStore.DATATYPE_TIME;
070:
071:                return 99;
072:                /*
073:                DATATYPE_STRING = 0;
074:                DATATYPE_INT = 1;
075:                DATATYPE_DATETIME = 2;
076:                public static final int DATATYPE_DOUBLE = 3;
077:                public static final int DATATYPE_BYTEARRAY = 4;
078:                public static final int DATATYPE_SHORT = 5;
079:                public static final int DATATYPE_LONG = 6;
080:                public static final int DATATYPE_FLOAT = 7;
081:                public static final int DATATYPE_DATE = 8;
082:                public static final int DATATYPE_TIME = 9;
083:                protected static final int DATATYPE_ANY = 99;
084:                 */
085:            }
086:
087:            /**
088:             * Insert the method's description here.
089:             * Creation date: (7/19/2002 3:07:02 PM)
090:             * @return java.lang.String
091:             */
092:            public static void setComments(String sComments) {
093:                _sComments = sComments;
094:            }
095:
096:            /**
097:             * This method is used to export the datastore as a XML file. This uses datastore.dtd file as XMl schema.
098:             * * Creation date: (8/7/01 5:11:31 PM)
099:             * @param pw  - This is the printwriter where the XML file should be exported
100:             * @param _ds - Datastore to export as XML.
101:             */
102:            public static void xmlExport(java.io.PrintWriter pw, DataStore _ds)
103:                    throws java.sql.SQLException {
104:                try {
105:                    String TAB = "      ";
106:                    pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
107:                    pw.println("");
108:                    pw.println("<!DOCTYPE ResultSet SYSTEM \"datastore.dtd\">");
109:
110:                    pw.println("<resultset>");
111:
112:                    // Printing the Meta Data
113:                    // ------------------------
114:                    pw.println("<resultsetmetadata>");
115:                    String columnMetaData = "";
116:                    for (int i = 0; i < _ds.getColumnCount(); i++) {
117:                        columnMetaData = "";
118:                        columnMetaData += TAB + "<columnmetadata ";
119:
120:                        String table = _ds.getColumnTableName(i);
121:
122:                        String cName = _ds.getColumnName(i);
123:                        if (cName == null)
124:                            cName = "Column" + i;
125:
126:                        if (cName != null && (cName.indexOf(".") != -1)) {
127:                            if (table == null)
128:                                table = cName.substring(0, cName.indexOf("."));
129:
130:                            cName = cName.substring(cName.indexOf(".") + 1);
131:                        }
132:
133:                        columnMetaData += " component=\"" + cName + "\"";
134:                        columnMetaData += " columnname=\"" + cName + "\"";
135:                        columnMetaData += " caption=\"" + cName + "\"";
136:
137:                        if (table == null)
138:                            table = "defaultTable";
139:
140:                        columnMetaData += " tablename=\"" + table + "\"";
141:                        columnMetaData += " columntype=\"";
142:                        int colType = _ds.getColumnDataType(i);
143:                        switch (colType) {
144:                        case DataStore.DATATYPE_STRING:
145:                            columnMetaData += "String";
146:                            break;
147:                        case DataStore.DATATYPE_DATE:
148:                            columnMetaData += "Date";
149:                            break;
150:                        case DataStore.DATATYPE_DATETIME:
151:                            columnMetaData += "DateTime";
152:                            break;
153:                        case DataStore.DATATYPE_TIME:
154:                            columnMetaData += "Time";
155:                            break;
156:                        case DataStore.DATATYPE_SHORT:
157:                            columnMetaData += "Short";
158:                            break;
159:                        case DataStore.DATATYPE_INT:
160:                            columnMetaData += "Integer";
161:                            break;
162:                        case DataStore.DATATYPE_LONG:
163:                            columnMetaData += "Long";
164:                            break;
165:                        case DataStore.DATATYPE_FLOAT:
166:                            columnMetaData += "Float";
167:                            break;
168:                        case DataStore.DATATYPE_DOUBLE:
169:                            columnMetaData += "Double";
170:                            break;
171:                        case DataStore.DATATYPE_BYTEARRAY:
172:                            columnMetaData += "ByteArray";
173:                            break;
174:                        }
175:                        columnMetaData += "\"";
176:                        columnMetaData += " primarykey=\""
177:                                + _ds.isColumnPrimaryKey(i) + "\"";
178:
179:                        if (_ds.getColumnFormat(i) != null)
180:                            columnMetaData += " format=\""
181:                                    + _ds.getColumnFormat(i) + "\"";
182:
183:                        if (_ds.getColumnInternalName(i) != null)
184:                            columnMetaData += " internalname=\""
185:                                    + _ds.getColumnInternalName(i) + "\"";
186:
187:                        columnMetaData += "> </columnmetadata>";
188:
189:                        pw.println(columnMetaData);
190:                    }
191:                    pw.println("</resultsetmetadata>");
192:
193:                    // Printing the Data
194:                    // -----------------------
195:                    pw.println("<resultsetdata>");
196:                    String row = "";
197:                    for (int r = 0; r < _ds.getRowCount(); r++) {
198:                        row = "";
199:                        DataStoreRow dsRow = _ds.getDataStoreRow(r,
200:                                DataStoreBuffer.BUFFER_STANDARD);
201:                        DSDataRow dRow = dsRow.getDSDataRow();
202:                        row += TAB + "<row>";
203:                        for (int c = 0; c < _ds.getColumnCount(); c++) {
204:                            if (dRow.getData(c) != null) {
205:                                String table = _ds.getColumnTableName(c);
206:
207:                                String cName = _ds.getColumnName(c);
208:                                if (cName == null)
209:                                    cName = "column" + c;
210:
211:                                if (cName != null && (cName.indexOf(".") != -1)) {
212:                                    if (table == null)
213:                                        table = cName.substring(0, cName
214:                                                .indexOf("."));
215:
216:                                    cName = cName
217:                                            .substring(cName.indexOf(".") + 1);
218:                                }
219:
220:                                row += "\n" + TAB + "<column " + " table=\""
221:                                        + table + "\"" + " name=\"" + cName
222:                                        + "\"" + " value=\""
223:                                        + _ds.getFormattedString(r, c)
224:                                        + "\" />";
225:                            }
226:                        }
227:                        row += "</row>";
228:                        pw.println(row);
229:                    }
230:                    pw.println("</resultsetdata>");
231:
232:                    pw.println("</resultset>");
233:
234:                    pw.flush();
235:                    pw.close();
236:                } catch (com.salmonllc.sql.DataStoreException eIO) {
237:                    System.out.println("Cant export DataStore to xmlFile. : "
238:                            + eIO);
239:                }
240:            }
241:
242:            /**
243:             * Method to export datastore as a XML file.
244:             * Creation date: (8/7/01 5:11:31 PM)
245:             * @param xmlFileName java.lang.String
246:             *
247:             */
248:            public static void xmlExport(String xmlFileName, DataStore _ds)
249:                    throws java.sql.SQLException {
250:                try {
251:                    java.io.File fileExport = new java.io.File(xmlFileName);
252:                    java.io.FileOutputStream os = new java.io.FileOutputStream(
253:                            fileExport);
254:                    java.io.PrintWriter pw = new java.io.PrintWriter(os);
255:
256:                    xmlExport(pw, _ds);
257:                    os.close();
258:                } catch (java.io.IOException eIO) {
259:                    System.out.println("Cant export DataStore to xmlFile. : "
260:                            + eIO);
261:                }
262:            }
263:
264:            /**
265:             * This methid used to export the data from datastore as Metadata for other datastores.
266:             * Creation date: (8/7/01 5:11:31 PM)
267:             * @param xmlFileName java.lang.String
268:             *
269:             */
270:            public static void xmlExportDataASMetaData(java.io.PrintWriter pw,
271:                    DataStore _ds) throws java.sql.SQLException {
272:                try {
273:                    String TAB = "      ";
274:                    pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
275:                    pw.println("");
276:                    pw.println("<!DOCTYPE ResultSet SYSTEM \"datastore.dtd\">");
277:
278:                    pw.println("<resultset>");
279:
280:                    // Printing the Meta Data
281:                    // ------------------------
282:                    pw.println("<resultsetmetadata>");
283:                    String columnMetaData = "";
284:                    for (int r = 0; r < _ds.getRowCount(); r++) {
285:                        // 1 Row of Data is One Column MetaData for other listForms
286:                        columnMetaData = "";
287:                        columnMetaData += TAB + "<columnmetadata ";
288:
289:                        DataStoreRow dsRow = _ds.getDataStoreRow(r,
290:                                DataStoreBuffer.BUFFER_STANDARD);
291:                        DSDataRow dRow = dsRow.getDSDataRow();
292:
293:                        for (int c = 0; c < _ds.getColumnCount(); c++) {
294:                            int colType = _ds.getColumnDataType(c);
295:                            if (dRow.getData(c) != null) {
296:                                String cName = _ds.getColumnName(c);
297:                                if (cName == null)
298:                                    cName = "Column" + c;
299:
300:                                if (cName != null && (cName.indexOf(".") != -1)) {
301:                                    cName = cName
302:                                            .substring(cName.indexOf(".") + 1);
303:                                }
304:
305:                                String value = _ds.getFormattedString(r, c);
306:                                if (colType == DataStore.DATATYPE_INT
307:                                        && value.equalsIgnoreCase("0"))
308:                                    value = "false";
309:                                if (colType == DataStore.DATATYPE_INT
310:                                        && value.equalsIgnoreCase("1"))
311:                                    value = "true";
312:
313:                                columnMetaData += "\n" + TAB + TAB + cName
314:                                        + "=" + "\"" + value + "\" ";
315:                            }
316:                        }
317:                        columnMetaData += ">\n" + TAB + TAB
318:                                + "</columnmetadata>\n";
319:                        pw.println(columnMetaData);
320:                    }
321:
322:                    pw.println("</resultsetmetadata>");
323:
324:                    pw.println("</resultset>");
325:
326:                    pw.flush();
327:                    pw.close();
328:
329:                } catch (com.salmonllc.sql.DataStoreException eIO) {
330:                    System.out.println("Cant export DataStore to xmlFile. : "
331:                            + eIO);
332:                }
333:            }
334:
335:            /**
336:             * This method is used to export the datastore as a XML file. This uses datastore.dtd file as XMl schema.
337:             * * Creation date: (8/7/01 5:11:31 PM)
338:             * @param pw  - This is the printwriter where the XML file should be exported
339:             * @param _ds - Datastore to export as XML.
340:             */
341:            public static void xmlExportResultSet(java.io.PrintWriter pw,
342:                    DataStore _ds) throws java.sql.SQLException {
343:                try {
344:                    String TAB = "      ";
345:                    pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
346:                    pw.println("");
347:                    pw.println("<!DOCTYPE ResultSet SYSTEM \"datastore.dtd\">");
348:
349:                    //Use comments to pass values, keys that are not part of datastore.
350:                    String sComments = getComments();
351:                    if (sComments != null)
352:                        pw.println(sComments);
353:
354:                    pw.println("<resultset>");
355:
356:                    // Writing the mandatory tag But we will just ignore it while processing the import
357:                    pw
358:                            .println("<!-- Dont remove this TAG is used for XMl processing -->");
359:                    pw.println("<resultsetmetadata> </resultsetmetadata>");
360:
361:                    // Printing the Data
362:                    // -----------------------
363:                    pw.println("<resultsetdata>");
364:                    String row = "";
365:                    for (int r = 0; r < _ds.getRowCount(); r++) {
366:                        row = "";
367:                        DataStoreRow dsRow = _ds.getDataStoreRow(r,
368:                                DataStoreBuffer.BUFFER_STANDARD);
369:                        DSDataRow dRow = dsRow.getDSDataRow();
370:                        row += TAB + "<row>";
371:                        for (int c = 0; c < _ds.getColumnCount(); c++) {
372:                            if (dRow.getData(c) != null) {
373:                                String table = _ds.getColumnTableName(c);
374:
375:                                String cName = _ds.getColumnName(c);
376:                                if (cName == null)
377:                                    cName = "column" + c;
378:
379:                                if (cName != null && (cName.indexOf(".") != -1)) {
380:                                    if (table == null)
381:                                        table = cName.substring(0, cName
382:                                                .indexOf("."));
383:
384:                                    cName = cName
385:                                            .substring(cName.indexOf(".") + 1);
386:                                }
387:
388:                                row += "\n" + TAB + "<column " + " table=\""
389:                                        + table + "\"" + " name=\"" + cName
390:                                        + "\"" + " value=\""
391:                                        + _ds.getFormattedString(r, c)
392:                                        + "\" />";
393:                            }
394:                        }
395:                        row += "</row>";
396:                        pw.println(row);
397:                    }
398:                    pw.println("</resultsetdata>");
399:
400:                    pw.println("</resultset>");
401:
402:                    pw.flush();
403:                    pw.close();
404:                } catch (com.salmonllc.sql.DataStoreException eIO) {
405:                    System.out.println("Cant export DataStore to xmlFile. : "
406:                            + eIO);
407:                }
408:            }
409:
410:            /**
411:             * This method is used to export the datastore as a XML file. This uses datastore.dtd file as XMl schema.
412:             * * Creation date: (8/7/01 5:11:31 PM)
413:             * @param pw  - This is the printwriter where the XML file should be exported
414:             * @param _ds - Datastore to export as XML.
415:             */
416:            public static void xmlExportResultSetMetaData(
417:                    java.io.PrintWriter pw, DataStore _ds)
418:                    throws java.sql.SQLException {
419:                try {
420:                    String TAB = "      ";
421:                    pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
422:                    pw.println("");
423:                    pw.println("<!DOCTYPE ResultSet SYSTEM \"datastore.dtd\">");
424:
425:                    pw.println("<resultset>");
426:
427:                    // Printing the Meta Data
428:                    // ------------------------
429:                    pw.println("<resultsetmetadata>");
430:                    String columnMetaData = "";
431:                    for (int i = 0; i < _ds.getColumnCount(); i++) {
432:                        columnMetaData = "";
433:                        columnMetaData += TAB + "<columnmetadata ";
434:
435:                        String table = _ds.getColumnTableName(i);
436:
437:                        String cName = _ds.getColumnName(i);
438:                        if (cName == null)
439:                            cName = "Column" + i;
440:
441:                        if (cName != null && (cName.indexOf(".") != -1)) {
442:                            if (table == null)
443:                                table = cName.substring(0, cName.indexOf("."));
444:
445:                            cName = cName.substring(cName.indexOf(".") + 1);
446:                        }
447:
448:                        columnMetaData += " component=\"" + cName + "\"";
449:                        columnMetaData += " columnname=\"" + cName + "\"";
450:                        columnMetaData += " caption=\"" + cName + "\"";
451:
452:                        if (table == null)
453:                            table = "defaultTable";
454:
455:                        columnMetaData += " tablename=\"" + table + "\"";
456:                        columnMetaData += " columntype=\"";
457:                        int colType = _ds.getColumnDataType(i);
458:                        switch (colType) {
459:                        case DataStore.DATATYPE_STRING:
460:                            columnMetaData += "String";
461:                            break;
462:                        case DataStore.DATATYPE_DATE:
463:                            columnMetaData += "Date";
464:                            break;
465:                        case DataStore.DATATYPE_DATETIME:
466:                            columnMetaData += "DateTime";
467:                            break;
468:                        case DataStore.DATATYPE_TIME:
469:                            columnMetaData += "Time";
470:                            break;
471:                        case DataStore.DATATYPE_SHORT:
472:                            columnMetaData += "Short";
473:                            break;
474:                        case DataStore.DATATYPE_INT:
475:                            columnMetaData += "Integer";
476:                            break;
477:                        case DataStore.DATATYPE_LONG:
478:                            columnMetaData += "Long";
479:                            break;
480:                        case DataStore.DATATYPE_FLOAT:
481:                            columnMetaData += "Float";
482:                            break;
483:                        case DataStore.DATATYPE_DOUBLE:
484:                            columnMetaData += "Double";
485:                            break;
486:                        case DataStore.DATATYPE_BYTEARRAY:
487:                            columnMetaData += "ByteArray";
488:                            break;
489:                        }
490:                        columnMetaData += "\"";
491:                        columnMetaData += " primarykey=\""
492:                                + _ds.isColumnPrimaryKey(i) + "\"";
493:
494:                        if (_ds.getColumnFormat(i) != null)
495:                            columnMetaData += " format=\""
496:                                    + _ds.getColumnFormat(i) + "\"";
497:
498:                        if (_ds.getColumnInternalName(i) != null)
499:                            columnMetaData += " internalname=\""
500:                                    + _ds.getColumnInternalName(i) + "\"";
501:
502:                        columnMetaData += "> </columnmetadata>";
503:
504:                        pw.println(columnMetaData);
505:                    }
506:                    pw.println("</resultsetmetadata>");
507:
508:                    pw
509:                            .println("<!-- Dont remove this TAG is used for XML processing -->");
510:                    pw.println("<resultsetdata> </resultsetdata>");
511:
512:                    pw.println("</resultset>");
513:
514:                    pw.flush();
515:                    pw.close();
516:                } catch (com.salmonllc.sql.DataStoreException eIO) {
517:                    System.out.println("Cant export DataStore to xmlFile. : "
518:                            + eIO);
519:                }
520:            }
521:
522:            /**
523:             * xmlImport imports the XML file based on datastore.dtd to specified Datastore.
524:             * Creation date: (8/7/01 5:11:31 PM)
525:             * @param xmlFileName java.lang.String
526:             * @param _ds
527:             */
528:            public static DataStore xmlImport(String xmlFileName, DataStore _ds) {
529:                try {
530:
531:                    XMLStoreParser.parseFile(xmlFileName);
532:
533:                    XMLDataStore xds = XMLStoreParser.getDataStore();
534:
535:                    if (_ds != null) {
536:                        ResultSetMetaData rsm = xds.getRsm();
537:
538:                        if (rsm != null) {
539:                            for (int i = 0; i < rsm.getMetaData().size(); i++) {
540:                                // Create the column descriptors
541:                                ColumnMetaData cmd = (ColumnMetaData) rsm
542:                                        .getMetaData().elementAt(i);
543:
544:                                String table = cmd.getTable();
545:                                String column = cmd.getColumnName();
546:                                String caption = cmd.getCaption();
547:                                String format = cmd.getFormat();
548:                                int type = mapDataType(cmd.getColumnType());
549:
550:                                // If existing dont overwrite the data
551:                                // ... need to discuss  if we should do a forceful import too
552:                                if (_ds.getColumnIndex(table + "." + column) == -1) {
553:                                    if (cmd.isPrimaryKey()) {
554:                                        _ds.addColumn(table, column, type,
555:                                                true, true, caption);
556:                                    } else {
557:                                        _ds.addColumn(table, column, type,
558:                                                false, true, caption);
559:                                    }
560:                                    if (format != null)
561:                                        _ds.setFormat(column, format);
562:                                }
563:                            }
564:                        } // if rsm != null
565:
566:                        // If result data
567:                        ResultSetData rsd = xds.getRsData();
568:                        if (rsd != null) {
569:                            if (rsd.getRows() != null) {
570:                                for (int r = 0; r < rsd.getRows().size(); r++) {
571:                                    Row rowHash = (Row) rsd.getRows()
572:                                            .elementAt(r);
573:                                    _ds.importRow(rowHash);
574:                                }
575:                            }
576:                        }
577:                    } else {
578:                        throw new Exception("Datastore not initiallized.");
579:                    }
580:                } catch (Exception e) {
581:                    System.out.println(e + " : " + e.getMessage());
582:                }
583:
584:                return _ds;
585:            }
586:
587:            /**
588:             * This methid used to import the metadata to a datastore
589:             * Creation date: (8/7/01 5:11:31 PM)
590:             * @param xmlFileName java.lang.String
591:             * @param _ds java.lang.String
592:             */
593:            public static DataStore xmlImportMetaDataAsData(String xmlFileName,
594:                    DataStore _ds) {
595:                return XMLTransporter.xmlImportMetaDataAsData(xmlFileName, _ds,
596:                        "listform", true);
597:            }
598:
599:            /**
600:             * This methid used to import the metadata to a datastore
601:             * Creation date: (8/7/01 5:11:31 PM)
602:             * @param xmlFileName java.lang.String
603:             * @param _ds java.lang.String
604:             */
605:            public static DataStore xmlImportMetaDataAsData(String xmlFileName,
606:                    DataStore _ds, String tablename, boolean toUpdate) {
607:                try {
608:
609:                    XMLStoreParser.parseFile(xmlFileName);
610:
611:                    XMLDataStore xds = XMLStoreParser.getDataStore();
612:
613:                    if (_ds != null) {
614:                        ResultSetMetaData rsm = xds.getRsm();
615:
616:                        if (rsm != null) {
617:                            String tableNameTFC = "";
618:                            for (int i = 0; i < rsm.getMetaData().size(); i++) {
619:                                // Create a Row out of ColumnMetaData
620:                                // Create the column descriptors
621:                                ColumnMetaData cmd = (ColumnMetaData) rsm
622:                                        .getMetaData().elementAt(i);
623:
624:                                if (tablename != null && !tablename.equals("")) {
625:                                    tableNameTFC = tablename + ".";
626:                                } else {
627:                                    tableNameTFC = "";
628:                                    tablename = "";
629:                                }
630:
631:                                Row row = new Row();
632:                                row.put(tableNameTFC + "component", new Column(
633:                                        tablename, "component", cmd
634:                                                .getComponent()));
635:                                row.put(tableNameTFC + "componenttype",
636:                                        new Column(tablename, "componenttype",
637:                                                cmd.getComponentType()));
638:                                row.put(tableNameTFC + "internalname",
639:                                        new Column(tablename, "internalname",
640:                                                cmd.getInternalName()));
641:
642:                                row.put(tableNameTFC + "columnname",
643:                                        new Column(tablename, "columnname", cmd
644:                                                .getColumnName()));
645:                                row.put(tableNameTFC + "columntype",
646:                                        new Column(tablename, "columntype", cmd
647:                                                .getColumnType()));
648:                                row
649:                                        .put(tableNameTFC + "tablename",
650:                                                new Column(tablename,
651:                                                        "tablename", cmd
652:                                                                .getTable()));
653:                                row.put(tableNameTFC + "schemaname",
654:                                        new Column(tablename, "schemaname", cmd
655:                                                .getSchema()));
656:                                row.put(tableNameTFC + "isbucket", new Column(
657:                                        tablename, "isbucket",
658:                                        getBooleanValue(cmd.isBucket())));
659:
660:                                row.put(tableNameTFC + "nullable", new Column(
661:                                        tablename, "nullable",
662:                                        getBooleanValue(cmd.isNullable())));
663:                                row.put(tableNameTFC + "primarykey",
664:                                        new Column(tablename, "primarykey",
665:                                                getBooleanValue(cmd
666:                                                        .isPrimaryKey())));
667:                                row.put(tableNameTFC + "updateable",
668:                                        new Column(tablename, "updateable",
669:                                                getBooleanValue(cmd
670:                                                        .isUpdateable())));
671:
672:                                row
673:                                        .put(tableNameTFC + "caption",
674:                                                new Column(tablename,
675:                                                        "caption", cmd
676:                                                                .getCaption()));
677:                                row.put(tableNameTFC + "searchdisplay",
678:                                        new Column(tablename, "searchdisplay",
679:                                                getBooleanValue(cmd
680:                                                        .isSearchDisplay())));
681:                                row.put(tableNameTFC + "listdisplay",
682:                                        new Column(tablename, "listdisplay",
683:                                                getBooleanValue(cmd
684:                                                        .isListDisplay())));
685:                                row.put(tableNameTFC + "detaildisplay",
686:                                        new Column(tablename, "detaildisplay",
687:                                                getBooleanValue(cmd
688:                                                        .isDetailDisplay())));
689:
690:                                row.put(tableNameTFC + "precedence",
691:                                        new Column(tablename, "precedence",
692:                                                getBooleanValue(cmd
693:                                                        .isPrecedence())));
694:                                row.put(tableNameTFC + "exactmatch",
695:                                        new Column(tablename, "exactmatch",
696:                                                getBooleanValue(cmd
697:                                                        .isExactMatch())));
698:                                row.put(tableNameTFC + "leadingwildcard",
699:                                        new Column(tablename,
700:                                                "leadingwildcard",
701:                                                getBooleanValue(cmd
702:                                                        .isLeadingWildCard())));
703:                                row.put(tableNameTFC + "casesensitive",
704:                                        new Column(tablename, "casesensitive",
705:                                                getBooleanValue(cmd
706:                                                        .isCaseSensitive())));
707:                                row.put(tableNameTFC + "mandatory ",
708:                                        new Column(tablename, "mandatory ",
709:                                                getBooleanValue(cmd
710:                                                        .isMandatory())));
711:
712:                                row.put(tableNameTFC + "locked", new Column(
713:                                        tablename, "locked",
714:                                        getBooleanValue(cmd.isLocked())));
715:                                row.put(tableNameTFC + "format", new Column(
716:                                        tablename, "format", cmd.getFormat()));
717:                                row.put(tableNameTFC + "href", new Column(
718:                                        tablename, "href", cmd.getHref()));
719:                                row.put(tableNameTFC + "advancesearch",
720:                                        new Column(tablename, "advancesearch",
721:                                                getBooleanValue(cmd
722:                                                        .isAdvanceSearch())));
723:                                row.put(tableNameTFC + "readonly", new Column(
724:                                        tablename, "readonly",
725:                                        getBooleanValue(cmd.isReadOnly())));
726:                                row.put(tableNameTFC + "defaultvalue",
727:                                        new Column(tablename, "defaultvalue",
728:                                                cmd.getDefaultValue()));
729:                                row.put(tableNameTFC + "samerow", new Column(
730:                                        tablename, "samerow",
731:                                        getBooleanValue(cmd.isSameRow())));
732:                                row.put(tableNameTFC + "imageFile", new Column(
733:                                        tablename, "imageFile", cmd
734:                                                .getImageFile()));
735:                                //                          row.put(tableNameTFC + "jointo", new Column(tablename, "jointo", cmd.ImageFile()));
736:
737:                                _ds.importRow(row);
738:                            }
739:                            _ds
740:                                    .setPrimaryKey(tableNameTFC + "columnname",
741:                                            true);
742:
743:                            if (toUpdate)
744:                                _ds.update();
745:                        } // if rsm != null
746:                    } else {
747:                        throw new Exception("Datastore not initiallized.");
748:                    }
749:                } catch (Exception e) {
750:                    System.out.println(e + " : " + e.getMessage());
751:                }
752:
753:                return _ds;
754:            }
755:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.