001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: ContentDataUser.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.cmf.dam;
009:
010: /**
011: * By extending this class it's possible to provide the logic that should be
012: * executed by methods that allow interaction with content data.
013: * <p>This class has both a default constructor and one that can take a data
014: * object. This can be handy when using it as an extending anonymous inner
015: * class when you need to use variables inside the inner class that are
016: * cumbersome to change to <code>final</code> in the enclosing class.
017: *
018: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
019: * @version $Revision: 3634 $
020: * @since 1.0
021: */
022: import com.uwyn.rife.tools.ExceptionUtils;
023: import com.uwyn.rife.tools.InnerClassException;
024: import java.util.logging.Logger;
025:
026: public abstract class ContentDataUser<ResultType, DataType> implements
027: Cloneable {
028: protected DataType mData = null;
029:
030: /**
031: * Creates a new instance.
032: *
033: * @since 1.0
034: */
035: public ContentDataUser() {
036: }
037:
038: /**
039: * Creates a new instance with a data object.
040: *
041: * @since 1.0
042: */
043: public ContentDataUser(DataType data) {
044: mData = data;
045: }
046:
047: /**
048: * Retrieves the data object that was provided through the constructor.
049: *
050: * @return this intance's data object
051: * @since 1.0
052: */
053: public DataType getData() {
054: return mData;
055: }
056:
057: /**
058: * Calling this method makes it possible to throw a checked exception from
059: * within this class.
060: * <p>To catch it you should surround the using method with a
061: * <code>try-catch</code> block that catching
062: * <code>InnerClassException</code>. The original exception is then
063: * available through <code>getCause()</code> and can for example be
064: * rethrown.
065: *
066: * @exception InnerClassException when a checked exception needs to be
067: * thrown from within this class and caught outside the caller.
068: * @since 1.0
069: */
070: public void throwException(Exception exception)
071: throws InnerClassException {
072: throw new InnerClassException(exception);
073: }
074:
075: /**
076: * Should be implemented by all extending classes.
077: *
078: * @since 1.0
079: */
080: public abstract ResultType useContentData(Object contentData)
081: throws InnerClassException;
082:
083: /**
084: * Simply clones the instance with the default clone method since this
085: * class contains no member variables.
086: *
087: * @since 1.0
088: */
089: public ContentDataUser<ResultType, DataType> clone() {
090: try {
091: return (ContentDataUser<ResultType, DataType>) super
092: .clone();
093: } catch (CloneNotSupportedException e) {
094: ///CLOVER:OFF
095: // this should never happen
096: Logger.getLogger("com.uwyn.rife.cmf").severe(
097: ExceptionUtils.getExceptionStackTrace(e));
098: return null;
099: ///CLOVER:ON
100: }
101: }
102: }
|