KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > descriptors > copying > AbstractCopyPolicy


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.descriptors.copying;
23
24 import oracle.toplink.essentials.exceptions.*;
25 import oracle.toplink.essentials.sessions.*;
26 import oracle.toplink.essentials.descriptors.ClassDescriptor;
27 import oracle.toplink.essentials.queryframework.ObjectLevelReadQuery;
28 import oracle.toplink.essentials.queryframework.ObjectBuildingQuery;
29
30 /**
31  * <p><b>Purpose</b>: Allows customization of how an object is cloned.
32  * This class defines common behavoir that allows a subclass to be used
33  * and set on a descriptor to provide a special cloning routine for how an object
34  * is cloned in a unit of work.
35  */

36 public abstract class AbstractCopyPolicy implements CopyPolicy {
37     protected ClassDescriptor descriptor;
38
39     public AbstractCopyPolicy() {
40         super();
41     }
42
43     public abstract Object JavaDoc buildClone(Object JavaDoc domainObject, Session session) throws DescriptorException;
44
45     /**
46      * By default use the buildClone.
47      */

48     public Object JavaDoc buildWorkingCopyClone(Object JavaDoc domainObject, Session session) throws DescriptorException {
49         return buildClone(domainObject, session);
50     }
51
52     /**
53      * Create a new instance, unless a workingCopyClone method is specified, then build a new instance and clone it.
54      */

55     public Object JavaDoc buildWorkingCopyCloneFromRow(Record row, ObjectLevelReadQuery query) throws DescriptorException {
56         return this.buildWorkingCopyCloneFromRow(row, (ObjectBuildingQuery)query);
57     }
58
59     /**
60      * By default create a new instance.
61      */

62     public Object JavaDoc buildWorkingCopyCloneFromRow(Record row, ObjectBuildingQuery query) throws DescriptorException {
63         return getDescriptor().getObjectBuilder().buildNewInstance();
64     }
65
66     /**
67      * INTERNAL:
68      * Clones the CopyPolicy
69      */

70     public Object JavaDoc clone() {
71         try {
72             // clones itself
73
return super.clone();
74         } catch (Exception JavaDoc exception) {
75         }
76         return null;
77     }
78
79     /**
80      * Return the descriptor.
81      */

82     protected ClassDescriptor getDescriptor() {
83         return descriptor;
84     }
85
86     /**
87      * Do nothing by default.
88      */

89     public void initialize(Session session) throws DescriptorException {
90         // Do nothing by default.
91
}
92
93     /**
94      * Set the descriptor.
95      */

96     public void setDescriptor(ClassDescriptor descriptor) {
97         this.descriptor = descriptor;
98     }
99
100     /**
101      * Return if a new instance is created or a clone.
102      */

103     public abstract boolean buildsNewInstance();
104 }
105
Popular Tags