1 /*
2 * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3 * the spring framework, http://el4j.sf.net
4 * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5 * 1000 Lausanne, Switzerland, http://www.elca.ch
6 *
7 * EL4J is published under the GNU Lesser General Public License (LGPL)
8 * Version 2.1. See http://www.gnu.org/licenses/
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * For alternative licensing, please contact info@elca.ch
16 */
17 package ch.elca.el4j.util.objectwrapper.impl;
18
19 import ch.elca.el4j.util.objectwrapper.ObjectWrapper;
20 import ch.elca.el4j.util.objectwrapper.ObjectWrapperRTException;
21
22 /**
23 * Base class of wrapper implementations. ObjectWrapper.wrap calls setTarget to pass the target object then create(),
24 * which the implementation must override. If create returns false an ObjectWrapperRTException is thrown from wrap.
25 * <p>
26 * The abstract wrapper implementations are created as prototypes and passed to ObjectWrapper, which clones them
27 * whenever one is needed.
28 *
29 * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/hibernate/src/main/java/ch/elca/el4j/util/objectwrapper/impl/AbstractWrapper.java $
30 *
31 * @author David Bernhard (DBD)
32 */
33 public abstract class AbstractWrapper implements Cloneable {
34
35 /** The target object. */
36 protected Object m_target;
37
38 /** The ObjectWrapper object. Allows one wrapped to require another. */
39 protected ObjectWrapper m_wrapper;
40
41 /**
42 * Setter for ObjectWrapper.
43 * @param wrapper The new ObjectWrapper to set.
44 */
45 public void setWrapper(ObjectWrapper wrapper) {
46 m_wrapper = wrapper;
47 }
48
49 /**
50 * Set the target object.
51 * @param target The target object.
52 */
53 public void setTarget(Object target) {
54 if (m_target != null) {
55 throw new IllegalStateException("Cannot reset target.");
56 }
57 m_target = target;
58 }
59
60 /**
61 * Override this in implementations to instantiate an object. A successful return indicates
62 * creation succeeded.
63 * @throws ObjectWrapperRTException If creation failed.
64 */
65 public abstract void create() throws ObjectWrapperRTException;
66
67 /** {@inheritDoc} */
68 @Override
69 public Object clone() throws CloneNotSupportedException {
70 return super.clone();
71 }
72
73
74 }