01: /*
02: * ProcDiff.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db.diff;
13:
14: import workbench.db.report.ReportProcedure;
15: import workbench.db.report.TagWriter;
16: import workbench.util.StrBuffer;
17:
18: /**
19: *
20: * @author support@sql-workbench.net
21: */
22: public class ProcDiff {
23: public static final String TAG_CREATE_PROC = "create-proc";
24: public static final String TAG_UPDATE_PROC = "update-proc";
25:
26: private ReportProcedure reference;
27: private ReportProcedure target;
28: private TagWriter writer;
29: private StrBuffer indent;
30:
31: public ProcDiff(ReportProcedure ref, ReportProcedure tar) {
32: reference = ref;
33: target = tar;
34: }
35:
36: public StrBuffer getMigrateTargetXml() {
37: StrBuffer result = new StrBuffer(500);
38: if (this .writer == null)
39: this .writer = new TagWriter();
40:
41: boolean isDifferent = true;
42: String tagToUse = TAG_CREATE_PROC;
43:
44: CharSequence refSource = reference.getSource();
45: CharSequence targetSource = target.getSource();
46:
47: if (targetSource != null) {
48: isDifferent = !refSource.equals(targetSource);
49: tagToUse = TAG_UPDATE_PROC;
50: }
51:
52: StrBuffer myIndent = new StrBuffer(indent);
53: myIndent.append(" ");
54: if (isDifferent) {
55: writer.appendOpenTag(result, this .indent, tagToUse);
56: result.append('\n');
57: reference.setIndent(myIndent);
58: result.append(reference.getXml());
59: writer.appendCloseTag(result, this .indent, tagToUse);
60: }
61: return result;
62: }
63:
64: /**
65: * Set the {@link workbench.db.report.TagWriter} to
66: * be used for writing the XML tags
67: */
68: public void setTagWriter(TagWriter tagWriter) {
69: this .writer = tagWriter;
70: }
71:
72: /**
73: * Set an indent for generating the XML
74: */
75: public void setIndent(String ind) {
76: if (ind == null)
77: this .indent = null;
78: this .indent = new StrBuffer(ind);
79: }
80:
81: /**
82: * Set an indent for generating the XML
83: */
84: public void setIndent(StrBuffer ind) {
85: this.indent = ind;
86: }
87:
88: }
|