Source Code Cross Referenced for ReportView.java in  » Database-Client » SQL-Workbench » workbench » db » report » 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 Client » SQL Workbench » workbench.db.report 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ReportView.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.db.report;
013:
014:        import java.io.IOException;
015:        import java.io.Writer;
016:        import java.sql.SQLException;
017:        import java.util.Collection;
018:        import java.util.List;
019:
020:        import workbench.db.ColumnIdentifier;
021:        import workbench.db.TableIdentifier;
022:        import workbench.db.WbConnection;
023:        import workbench.util.StrBuffer;
024:        import java.util.Collections;
025:        import workbench.db.IndexDefinition;
026:        import workbench.util.StringUtil;
027:
028:        /**
029:         * A class to hold information about a database view that 
030:         * will eventually be stored in an XML report. 
031:         * It uses a {@link workbench.db.TableIdentifier} to store the 
032:         * view's name, and {@link workbench.db.ColumnIdentifier} to 
033:         * store the view's columns.
034:         *
035:         * @author  support@sql-workbench.net
036:         */
037:        public class ReportView {
038:            public static final String TAG_VIEW_DEF = "view-def";
039:            public static final String TAG_VIEW_NAME = "view-name";
040:            public static final String TAG_VIEW_CATALOG = "view-catalog";
041:            public static final String TAG_VIEW_SCHEMA = "view-schema";
042:            public static final String TAG_VIEW_COMMENT = "view-comment";
043:            public static final String TAG_VIEW_SOURCE = "view-source";
044:
045:            private TableIdentifier view;
046:            private ReportColumn[] columns;
047:            private String viewComment;
048:            private TagWriter tagWriter = new TagWriter();
049:            private IndexReporter index;
050:
051:            /** The schema name to be used in the generated XML */
052:            private String schemaNameToUse = null;
053:
054:            private String namespace = null;
055:            private CharSequence viewSource;
056:
057:            public ReportView(TableIdentifier tbl) {
058:                this (tbl, (String) null);
059:            }
060:
061:            public ReportView(TableIdentifier tbl, String nspace) {
062:                this .view = tbl;
063:                this .namespace = nspace;
064:                tagWriter.setNamespace(this .namespace);
065:            }
066:
067:            /**
068:             * Initialize this ReportView.
069:             * This will read the following information for the table: 
070:             * <ul>
071:             *	<li>columns for the table using {@link workbench.db.DbMetadata#getTableColumns(workbench.db.TableIdentifier)}</li>
072:             *  <li>the comments for the view using {@link workbench.db.DbMetadata#getTableComment(workbench.db.TableIdentifier)}</li>
073:             *  <li>the source for the view using{@link workbench.db.DbMetadata#getViewSource(workbench.db.TableIdentifier)}</li>
074:             *</ul>
075:             */
076:            public ReportView(TableIdentifier tbl, WbConnection conn,
077:                    boolean includeIndex, String nspace) throws SQLException {
078:                this .view = tbl;
079:                this .namespace = nspace;
080:
081:                if (tbl.getSchema() == null) {
082:                    // This is important for e.g. Oracle. Otherwise the table definition 
083:                    // will contain multiple columns if a table exists more then once in 
084:                    // different schemas with the same name
085:                    tbl.setSchema(conn.getMetadata().getSchemaToUse());
086:                }
087:                List<ColumnIdentifier> cols = conn.getMetadata()
088:                        .getTableColumns(tbl);
089:                Collections.sort(cols);
090:
091:                this .viewComment = conn.getMetadata()
092:                        .getTableComment(this .view);
093:                String schema = this .view.getSchema();
094:                if (schema == null || schema.length() == 0) {
095:                    schema = conn.getMetadata().getSchemaToUse();
096:                    if (schema != null)
097:                        this .view.setSchema(schema);
098:                }
099:                this .viewSource = conn.getMetadata().getViewSource(tbl);
100:                if (viewSource == null)
101:                    viewSource = StringUtil.EMPTY_STRING;
102:                this .setColumns(cols);
103:                this .tagWriter.setNamespace(namespace);
104:                if (includeIndex) {
105:                    this .index = new IndexReporter(tbl, conn);
106:                    this .index.setNamespace(namespace);
107:                }
108:            }
109:
110:            /**
111:             * Return the list of IndexDefinitions for this view
112:             * @return defined indexes, maybe null
113:             */
114:            public Collection<IndexDefinition> getIndexList() {
115:                if (this .index == null)
116:                    return null;
117:                return this .index.getIndexList();
118:            }
119:
120:            /**
121:             * Define the columns that belong to this table
122:             */
123:            public void setColumns(List<ColumnIdentifier> cols) {
124:                if (cols == null)
125:                    return;
126:                int numCols = cols.size();
127:                this .columns = new ReportColumn[numCols];
128:                int i = 0;
129:                for (ColumnIdentifier column : cols) {
130:                    this .columns[i] = new ReportColumn(column);
131:                    this .columns[i].setNamespace(this .namespace);
132:                    this .columns[i].setRealColumn(false);
133:                    i++;
134:                }
135:            }
136:
137:            public void setSchemaNameToUse(String name) {
138:                this .schemaNameToUse = name;
139:            }
140:
141:            public void writeXml(Writer out) throws IOException {
142:                StrBuffer line = this .getXml();
143:                line.writeTo(out);
144:            }
145:
146:            public StrBuffer getXml() {
147:                return getXml(new StrBuffer("  "));
148:            }
149:
150:            public TableIdentifier getView() {
151:                return this .view;
152:            }
153:
154:            public String getViewComment() {
155:                return this .viewComment;
156:            }
157:
158:            public CharSequence getViewSource() {
159:                return this .viewSource;
160:            }
161:
162:            public void appendTableNameXml(StrBuffer toAppend, StrBuffer indent) {
163:                tagWriter.appendTag(toAppend, indent, TAG_VIEW_CATALOG,
164:                        this .view.getCatalog());
165:                tagWriter.appendTag(toAppend, indent, TAG_VIEW_SCHEMA,
166:                        (this .schemaNameToUse == null ? this .view.getSchema()
167:                                : this .schemaNameToUse));
168:                tagWriter.appendTag(toAppend, indent, TAG_VIEW_NAME, this .view
169:                        .getTableName());
170:            }
171:
172:            public StrBuffer getXml(StrBuffer indent) {
173:                return getXml(indent, true);
174:            }
175:
176:            /**
177:             * Return an XML representation of this view information.
178:             * The columns will be listed alphabetically not in the order
179:             * they were retrieved from the database.
180:             */
181:            public StrBuffer getXml(StrBuffer indent, boolean includeIndex) {
182:                StrBuffer line = new StrBuffer(this .viewSource.length() + 200);
183:                StrBuffer colindent = new StrBuffer(indent);
184:                colindent.append(indent);
185:
186:                tagWriter.appendOpenTag(line, indent, TAG_VIEW_DEF, "name",
187:                        this .view.getTableName());
188:                line.append('\n');
189:                appendTableNameXml(line, colindent);
190:                tagWriter.appendTag(line, colindent, TAG_VIEW_COMMENT,
191:                        this .viewComment, true);
192:                int cols = this .columns.length;
193:                for (int i = 0; i < cols; i++) {
194:                    this .columns[i].appendXml(line, colindent);
195:                }
196:                writeSourceTag(tagWriter, line, colindent, viewSource);
197:                if (includeIndex && this .index != null)
198:                    this .index.appendXml(line, colindent);
199:                tagWriter.appendCloseTag(line, indent, TAG_VIEW_DEF);
200:                return line;
201:            }
202:
203:            public static final void writeSourceTag(TagWriter tagWriter,
204:                    StrBuffer target, StrBuffer indent, CharSequence source) {
205:                if (source == null)
206:                    return;
207:                tagWriter.appendOpenTag(target, indent, TAG_VIEW_SOURCE);
208:                target.append(TagWriter.CDATA_START);
209:                target.append(source);
210:                target.append(TagWriter.CDATA_END);
211:                target.append('\n');
212:                tagWriter.appendCloseTag(target, indent, TAG_VIEW_SOURCE);
213:
214:            }
215:
216:            /**
217:             * The namespace to be used for the XML representation
218:             */
219:            public void setNamespace(String namespace) {
220:                this.tagWriter.setNamespace(namespace);
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.