Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ProxyArtifact.java @ 89:d348fe1fd822
More javadoc (fixes small glitches, too).
artifacts/trunk@845 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 26 Mar 2010 16:16:32 +0000 |
parents | b2e0cb83631c |
children | 68285f7bc476 |
comparison
equal
deleted
inserted
replaced
88:69c84cf7c5d7 | 89:d348fe1fd822 |
---|---|
9 | 9 |
10 import java.io.IOException; | 10 import java.io.IOException; |
11 import java.io.OutputStream; | 11 import java.io.OutputStream; |
12 | 12 |
13 /** | 13 /** |
14 * The proxy artifact is a wrapper around another artifact. It simply forwards | |
15 * the interface calls to this underlaying artifact. | |
16 * The reason for using proxy artifacts is enable the workflow to exchange | |
17 * artifacts at any time by something else without losing the concrete | |
18 * artifact. From the outside it always looks like there is only one | |
19 * distinct artifact.<br> | |
20 * | |
21 * An inner artifact is able to replace itself by indirectly hand over | |
22 * the replacement via the call context to the proxy artifact.<br> | |
23 * To do so the proxied artifact has to call | |
24 * <code>callContext.getContextValue(EPLACE_PROXY, replacement);</code>. | |
25 * After the current call (describe, feed, advance and out) of the proxied | |
26 * artifact is finished the proxy artifact replaces the former proxied artifact | |
27 * with the replacement. | |
28 * | |
14 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | 29 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
15 */ | 30 */ |
16 public class ProxyArtifact | 31 public class ProxyArtifact |
17 extends DefaultArtifact | 32 extends DefaultArtifact |
18 { | 33 { |
34 /** | |
35 * Key to signal that the proxied artifact should be replaced. | |
36 */ | |
19 public static final Object REPLACE_PROXY = new Object(); | 37 public static final Object REPLACE_PROXY = new Object(); |
20 | 38 |
21 private static Logger logger = Logger.getLogger(ProxyArtifact.class); | 39 private static Logger logger = Logger.getLogger(ProxyArtifact.class); |
22 | 40 |
41 /** | |
42 * The proxied artifact. | |
43 */ | |
23 protected Artifact proxied; | 44 protected Artifact proxied; |
24 | 45 |
46 /** | |
47 * Default constructor. | |
48 */ | |
25 public ProxyArtifact() { | 49 public ProxyArtifact() { |
26 } | 50 } |
27 | 51 |
52 /** | |
53 * Constructor to create a new proxy artifact around a given artifact. | |
54 * @param proxied The artifact to be proxied. | |
55 */ | |
28 public ProxyArtifact(Artifact proxied) { | 56 public ProxyArtifact(Artifact proxied) { |
29 this.proxied = proxied; | 57 this.proxied = proxied; |
30 } | 58 } |
31 | 59 |
60 /** | |
61 * The currently proxied artifact. | |
62 * @return The proxied artifact. | |
63 */ | |
32 public Artifact getProxied() { | 64 public Artifact getProxied() { |
33 return proxied; | 65 return proxied; |
34 } | 66 } |
35 | 67 |
68 /** | |
69 * Explicitly set the proxied artifacts. | |
70 * @param proxied | |
71 */ | |
36 public void setProxied(Artifact proxied) { | 72 public void setProxied(Artifact proxied) { |
37 this.proxied = proxied; | 73 this.proxied = proxied; |
38 } | 74 } |
39 | 75 |
76 @Override | |
40 public void setIdentifier(String identifier) { | 77 public void setIdentifier(String identifier) { |
41 this.identifier = identifier; | 78 this.identifier = identifier; |
42 | 79 |
43 if (proxied != null) | 80 if (proxied != null) |
44 proxied.setIdentifier(identifier); | 81 proxied.setIdentifier(identifier); |
45 } | 82 } |
46 | 83 |
84 /** | |
85 * Method to check if the current proxied artifact should be replaced | |
86 * by a new one coming from the call context. | |
87 * @param callContext | |
88 */ | |
47 protected void checkReplacement(CallContext callContext) { | 89 protected void checkReplacement(CallContext callContext) { |
48 Object replacement = callContext.getContextValue(REPLACE_PROXY); | 90 Object replacement = callContext.getContextValue(REPLACE_PROXY); |
49 if (replacement instanceof Artifact) { | 91 if (replacement instanceof Artifact) { |
50 setProxied((Artifact)replacement); | 92 setProxied((Artifact)replacement); |
51 } | 93 } |
52 } | 94 } |
53 | 95 |
96 @Override | |
54 public String hash() { | 97 public String hash() { |
55 return proxied != null | 98 return proxied != null |
56 ? proxied.hash() | 99 ? proxied.hash() |
57 : super.hash(); | 100 : super.hash(); |
58 } | 101 } |
59 | 102 |
103 @Override | |
60 public Document describe(Document data, CallContext context) { | 104 public Document describe(Document data, CallContext context) { |
61 try { | 105 try { |
62 return proxied != null | 106 return proxied != null |
63 ? proxied.describe(data, context) | 107 ? proxied.describe(data, context) |
64 : super.describe(data, context); | 108 : super.describe(data, context); |
66 finally { | 110 finally { |
67 checkReplacement(context); | 111 checkReplacement(context); |
68 } | 112 } |
69 } | 113 } |
70 | 114 |
115 @Override | |
71 public Document advance(Document target, CallContext context) { | 116 public Document advance(Document target, CallContext context) { |
72 try { | 117 try { |
73 return proxied != null | 118 return proxied != null |
74 ? proxied.advance(target, context) | 119 ? proxied.advance(target, context) |
75 : super.advance(target, context); | 120 : super.advance(target, context); |
77 finally { | 122 finally { |
78 checkReplacement(context); | 123 checkReplacement(context); |
79 } | 124 } |
80 } | 125 } |
81 | 126 |
127 @Override | |
82 public Document feed(Document target, CallContext context) { | 128 public Document feed(Document target, CallContext context) { |
83 try { | 129 try { |
84 return proxied != null | 130 return proxied != null |
85 ? proxied.feed(target, context) | 131 ? proxied.feed(target, context) |
86 : super.feed(target, context); | 132 : super.feed(target, context); |
88 finally { | 134 finally { |
89 checkReplacement(context); | 135 checkReplacement(context); |
90 } | 136 } |
91 } | 137 } |
92 | 138 |
139 @Override | |
93 public void out( | 140 public void out( |
94 Document format, | 141 Document format, |
95 OutputStream out, | 142 OutputStream out, |
96 CallContext context | 143 CallContext context |
97 ) | 144 ) |
108 finally { | 155 finally { |
109 checkReplacement(context); | 156 checkReplacement(context); |
110 } | 157 } |
111 } | 158 } |
112 | 159 |
160 @Override | |
113 public void endOfLife(Object context) { | 161 public void endOfLife(Object context) { |
114 if (proxied != null) { | 162 if (proxied != null) { |
115 proxied.endOfLife(context); | 163 proxied.endOfLife(context); |
116 } | 164 } |
117 else { | 165 else { |
118 super.endOfLife(context); | 166 super.endOfLife(context); |
119 } | 167 } |
120 } | 168 } |
121 | 169 |
170 @Override | |
122 public void cleanup(Object context) { | 171 public void cleanup(Object context) { |
123 if (proxied != null) | 172 if (proxied != null) |
124 proxied.cleanup(context); | 173 proxied.cleanup(context); |
125 else | 174 else |
126 super.cleanup(context); | 175 super.cleanup(context); |
127 } | 176 } |
128 } | 177 } |
129 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: | 178 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |