001: /*
002: * ReportColumn.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 workbench.db.ColumnIdentifier;
015: import workbench.util.SqlUtil;
016: import workbench.util.StrBuffer;
017: import workbench.util.StringUtil;
018:
019: /**
020: *
021: * @author support@sql-workbench.net
022: */
023: public class ReportColumn {
024: public static final String TAG_COLUMN_DEFINITION = "column-def";
025: public static final String TAG_COLUMN_NAME = "column-name";
026: public static final String TAG_COLUMN_DBMS_TYPE = "dbms-data-type";
027: public static final String TAG_COLUMN_JAVA_TYPE_NAME = "java-sql-type-name";
028: public static final String TAG_COLUMN_JAVA_TYPE = "java-sql-type";
029: public static final String TAG_COLUMN_JAVA_CLASS = "java-class";
030:
031: public static final String TAG_COLUMN_SIZE = "dbms-data-size";
032: public static final String TAG_COLUMN_DIGITS = "dbms-data-digits";
033: public static final String TAG_COLUMN_POSITION = "dbms-position";
034: public static final String TAG_COLUMN_DEFAULT = "default-value";
035: public static final String TAG_COLUMN_NULLABLE = "nullable";
036: public static final String TAG_COLUMN_PK = "primary-key";
037: public static final String TAG_COLUMN_COMMENT = "comment";
038:
039: private ColumnReference fk;
040: private ColumnIdentifier column;
041: private TagWriter tagWriter = new TagWriter();
042: private boolean isRealColumn = true;
043: private boolean isReferenced = false;
044:
045: public ReportColumn(ColumnIdentifier col) {
046: this .column = col;
047: }
048:
049: public ColumnIdentifier getColumn() {
050: return this .column;
051: }
052:
053: public ColumnReference getForeignKey() {
054: return this .fk;
055: }
056:
057: public void setIsReferenced(boolean flag) {
058: isReferenced = flag;
059: }
060:
061: public boolean isReferenced() {
062: return isReferenced;
063: }
064:
065: public void setForeignKeyReference(ColumnReference ref) {
066: this .fk = ref;
067: if (this .fk != null) {
068: this .fk.setNamespace(this .tagWriter.getNamespace());
069: }
070: }
071:
072: public void appendXml(StrBuffer result, StrBuffer indent) {
073: appendXml(result, indent, true);
074: }
075:
076: public void appendXml(StrBuffer result, StrBuffer indent,
077: boolean includePosition) {
078: StrBuffer myindent = new StrBuffer(indent);
079:
080: myindent.append(" ");
081: tagWriter.appendOpenTag(result, indent, TAG_COLUMN_DEFINITION,
082: "name", StringUtil.trimQuotes(this .column
083: .getColumnName()));
084: result.append('\n');
085:
086: if (includePosition)
087: tagWriter.appendTag(result, myindent, TAG_COLUMN_POSITION,
088: this .column.getPosition());
089: tagWriter.appendTag(result, myindent, TAG_COLUMN_NAME,
090: this .column.getColumnName());
091: tagWriter.appendTag(result, myindent, TAG_COLUMN_DBMS_TYPE,
092: this .column.getDbmsType());
093: if (isRealColumn)
094: tagWriter.appendTag(result, myindent, TAG_COLUMN_PK,
095: this .column.isPkColumn());
096: if (isRealColumn)
097: tagWriter.appendTag(result, myindent, TAG_COLUMN_NULLABLE,
098: this .column.isNullable());
099: if (isRealColumn)
100: tagWriter.appendTag(result, myindent, TAG_COLUMN_DEFAULT,
101: this .column.getDefaultValue(), true);
102: tagWriter.appendTag(result, myindent, TAG_COLUMN_SIZE,
103: this .column.getColumnSize());
104: tagWriter.appendTag(result, myindent, TAG_COLUMN_DIGITS,
105: this .column.getDecimalDigits());
106: tagWriter.appendTag(result, myindent, TAG_COLUMN_JAVA_TYPE,
107: this .column.getDataType());
108: tagWriter.appendTag(result, myindent,
109: TAG_COLUMN_JAVA_TYPE_NAME, SqlUtil
110: .getTypeName(this .column.getDataType()));
111: tagWriter.appendTag(result, myindent, TAG_COLUMN_COMMENT,
112: this .column.getComment(), true);
113:
114: if (this .fk != null) {
115: result.append(fk.getXml(myindent));
116: }
117: tagWriter.appendCloseTag(result, indent, TAG_COLUMN_DEFINITION);
118: return;
119: }
120:
121: public void setNamespace(String namespace) {
122: this .tagWriter.setNamespace(namespace);
123: if (this .fk != null) {
124: this .fk.setNamespace(namespace);
125: }
126: }
127:
128: public void setRealColumn(boolean flag) {
129: this .isRealColumn = flag;
130: }
131:
132: public String toString() {
133: return column.toString();
134: }
135: }
|