001: /*
002: * ReportProcedure.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 workbench.db.NoConfigException;
017: import workbench.db.ProcedureDefinition;
018: import workbench.db.WbConnection;
019: import workbench.util.StrBuffer;
020:
021: /**
022: *
023: * @author support@sql-workbench.net
024: */
025: public class ReportProcedure {
026: // <editor-fold defaultstate="collapsed" desc=" Variables ">
027: public static final String TAG_PROC_DEF = "proc-def";
028: public static final String TAG_PROC_NAME = "proc-name";
029: public static final String TAG_PROC_CATALOG = "proc-catalog";
030: public static final String TAG_PROC_SCHEMA = "proc-schema";
031: public static final String TAG_PROC_TYPE = "proc-type";
032: public static final String TAG_PROC_SOURCE = "proc-source";
033:
034: private ProcedureDefinition procDef;
035: private WbConnection dbConn;
036: private TagWriter tagWriter = new TagWriter();
037: private StrBuffer indent = new StrBuffer(" ");
038: private StrBuffer indent2 = new StrBuffer(" ");
039:
040: // </editor-fold>
041:
042: public ReportProcedure(ProcedureDefinition def, WbConnection conn) {
043: this .procDef = def;
044: this .dbConn = conn;
045: }
046:
047: public CharSequence getSource() {
048: if (this .procDef == null)
049: return null;
050: if (this .procDef.getSource() == null) {
051: try {
052: this .dbConn.getMetadata().readProcedureSource(
053: this .procDef);
054: } catch (NoConfigException e) {
055: procDef.setSource("n/a");
056: }
057: }
058: return this .procDef.getSource();
059: }
060:
061: public void writeXml(Writer out) throws IOException {
062: StrBuffer xml = getXml();
063: xml.writeTo(out);
064: }
065:
066: public String getProcedureName() {
067: return procDef.getProcedureName();
068: }
069:
070: public void setIndent(StrBuffer ind) {
071: this .indent = ind;
072: this .indent2 = new StrBuffer(indent);
073: this .indent2.append(" ");
074: }
075:
076: public StrBuffer getXml() {
077: return getXml(true);
078: }
079:
080: public StrBuffer getXml(boolean includeSource) {
081: StrBuffer result = new StrBuffer(500);
082: tagWriter.appendOpenTag(result, indent, TAG_PROC_DEF);
083: result.append('\n');
084: tagWriter.appendTag(result, indent2, TAG_PROC_CATALOG, procDef
085: .getCatalog());
086: tagWriter.appendTag(result, indent2, TAG_PROC_SCHEMA, procDef
087: .getSchema());
088: tagWriter.appendTag(result, indent2, TAG_PROC_NAME, procDef
089: .getProcedureName());
090: tagWriter.appendTag(result, indent2, TAG_PROC_TYPE, procDef
091: .getObjectType(), "jdbcResultType", Integer
092: .toString(procDef.getResultType()));
093: if (includeSource) {
094: tagWriter.appendTag(result, indent2, TAG_PROC_SOURCE,
095: getSource(), true);
096: //result.append('\n');
097: }
098: tagWriter.appendCloseTag(result, indent, TAG_PROC_DEF);
099: return result;
100: }
101: }
|