KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > queryframework > ListContainerPolicy


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.internal.queryframework;
23
24 import java.util.List JavaDoc;
25 import oracle.toplink.essentials.internal.sessions.ObjectChangeSet;
26 import oracle.toplink.essentials.internal.sessions.CollectionChangeRecord;
27
28 /**
29  * <p><b>Purpose</b>: A ListContainerPolicy is ContainerPolicy whose container class
30  * implements the List interface. This signifies that the collection has order
31  * <p>
32  * <p><b>Responsibilities</b>:
33  * Provide the functionality to operate on an instance of a List.
34  *
35  * @see ContainerPolicy
36  * @see CollectionContainerPolicy
37  */

38 public class ListContainerPolicy extends CollectionContainerPolicy {
39     /**
40      * INTERNAL:
41      * Construct a new policy.
42      */

43     public ListContainerPolicy() {
44         super();
45     }
46
47     /**
48      * INTERNAL:
49      * Construct a new policy for the specified class.
50      */

51     public ListContainerPolicy(Class JavaDoc containerClass) {
52         super(containerClass);
53     }
54     
55     /**
56      * INTERNAL:
57      * Construct a new policy for the specified class name.
58      */

59     public ListContainerPolicy(String JavaDoc containerClassName) {
60         super(containerClassName);
61     }
62
63     /**
64      * INTERNAL:
65      * Returns true if the collection has order.
66      */

67     public boolean hasOrder() {
68         return true;
69     }
70     
71     /**
72      * INTERNAL:
73      * Returns true if this is a ListContainerPolicy.
74      */

75     public boolean isListPolicy() {
76         return true;
77     }
78     
79     /**
80      * INTERNAL:
81      * Validate the container type.
82      */

83     public boolean isValidContainer(Object JavaDoc container) {
84         // PERF: Use instanceof which is inlined, not isAssignable which is very inefficent.
85
return container instanceof List JavaDoc;
86     }
87
88     /**
89      * This method is used to bridge the behaviour between Attribute Change
90      * Tracking and deferred change tracking with respect to adding the same
91      * instance multiple times. Each containerplicy type will implement specific
92      * behaviour for the collection type it is wrapping. These methods are only
93      * valid for collections containing object references.
94      */

95     public void recordAddToCollectionInChangeRecord(ObjectChangeSet changeSetToAdd, CollectionChangeRecord collectionChangeRecord){
96         if (collectionChangeRecord.getRemoveObjectList().containsKey(changeSetToAdd)) {
97             collectionChangeRecord.getRemoveObjectList().remove(changeSetToAdd);
98         } else {
99             if (collectionChangeRecord.getAddObjectList().contains(changeSetToAdd)) {
100                 collectionChangeRecord.getAddOverFlow().add(changeSetToAdd);
101             } else {
102                 collectionChangeRecord.getAddObjectList().put(changeSetToAdd, changeSetToAdd);
103             }
104         }
105     }
106     
107     /**
108      * This method is used to bridge the behaviour between Attribute Change
109      * Tracking and deferred change tracking with respect to adding the same
110      * instance multiple times. Each container policy type will implement
111      * specific behaviour for the collection type it is wrapping. These methods
112      * are only valid for collections containing object references.
113      */

114     public void recordRemoveFromCollectionInChangeRecord(ObjectChangeSet changeSetToRemove, CollectionChangeRecord collectionChangeRecord){
115         if (collectionChangeRecord.getAddObjectList().containsKey(changeSetToRemove)) {
116             if (collectionChangeRecord.getAddOverFlow().contains(changeSetToRemove)){
117                 collectionChangeRecord.getAddOverFlow().remove(changeSetToRemove);
118             } else {
119                 collectionChangeRecord.getAddObjectList().remove(changeSetToRemove);
120             }
121         } else {
122             collectionChangeRecord.getRemoveObjectList().put(changeSetToRemove, changeSetToRemove);
123         }
124     }
125 }
126
Popular Tags