1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.threads;
18
19 import org.apache.commons.jelly.JellyTagException;
20 import org.apache.commons.jelly.TagSupport;
21 import org.apache.commons.jelly.XMLOutput;
22
23 /***
24 * Base class for tags that will "use" mutexes.
25 *
26 * @author <a href="mailto:jason@jhorman.org">Jason Horman</a>
27 */
28
29 public abstract class UseMutexTag extends TagSupport {
30 /*** The mutex to use in some way. */
31 private Object mutex = null;
32
33 /*** Calls useMutex after checking to make sure that <i>setMutex</i> was called */
34 public void doTag(XMLOutput output) throws JellyTagException {
35
36 if (mutex == null) {
37 throw new JellyTagException("no mutex set");
38 }
39
40 useMutex(mutex, output);
41 }
42
43 /*** Implement this method to do something with the mutex */
44 protected abstract void useMutex(Object mutex, XMLOutput output) throws JellyTagException;
45
46 /*** Get the mutex */
47 public Object getMutex() {
48 return mutex;
49 }
50
51 /*** Set the mutex. Any object can be used as a mutex. */
52 public void setMutex(Object mutex) {
53 this.mutex = mutex;
54 }
55 }