KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > sqlstore > ExtentCollection


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 in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
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 Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ExtentCollection.java
26  *
27  * Created on April 6, 2000
28  */

29
30 package com.sun.jdo.spi.persistence.support.sqlstore;
31
32 import com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException;
33 import com.sun.jdo.api.persistence.support.JDOUserException;
34 import com.sun.jdo.spi.persistence.utility.I18NHelper;
35 import com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager;
36 import com.sun.jdo.api.persistence.model.Model;
37
38 import java.util.Collection JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.ResourceBundle JavaDoc;
41
42 /**
43  *
44  * @author Michael Bouschen
45  * @version 0.1
46  */

47 public class ExtentCollection
48         implements Collection JavaDoc {
49     /**
50      * The PersistenceManager getExtent is called from
51      */

52     protected PersistenceManager pm;
53
54     /**
55      * This extent collection reperesents the extent of persistenceCapableClass.
56      */

57     protected Class JavaDoc persistenceCapableClass;
58
59     /**
60      * I18N message handler
61      */

62     private final static ResourceBundle JavaDoc messages = I18NHelper.loadBundle(
63            ExtentCollection.class);
64
65     /**
66      *
67      * @param persistenceCapableClass Class of instances
68      * @param subclasses whether to include instances of subclasses
69      */

70     public ExtentCollection(PersistenceManager pm, Class JavaDoc persistenceCapableClass, boolean subclasses) {
71         this.pm = pm;
72         this.persistenceCapableClass = persistenceCapableClass;
73
74         // check persistenceCapableClass parameter being null
75
if (persistenceCapableClass == null)
76             throw new JDOUserException(
77                     I18NHelper.getMessage(messages, "jdo.extentcollection.constructor.invalidclass", "null"));// NOI18N
78
// check persistence-capable
79
if (Model.RUNTIME.getMappingClass(persistenceCapableClass.getName(),
80                 persistenceCapableClass.getClassLoader()) == null)
81             throw new JDOUserException(
82                     I18NHelper.getMessage(messages, "jdo.extentcollection.constructor.nonpc", // NOI18N
83
persistenceCapableClass.getName()));
84
85         // subclasses == true is not yet supported
86
if (subclasses)
87             throw new JDOUnsupportedOptionException(
88                     I18NHelper.getMessage(messages, "jdo.extentcollection.constructor.subclasses"));// NOI18N
89
}
90
91     /**
92      *
93      */

94     public Class JavaDoc getPersistenceCapableClass() {
95         return persistenceCapableClass;
96     }
97
98     /**
99      *
100      */

101     public int size() {
102         throw new JDOUnsupportedOptionException(
103                 I18NHelper.getMessage(messages, "jdo.extentcollection.methodnotsupported", "size"));// NOI18N
104
}
105
106     /**
107      *
108      */

109     public boolean isEmpty() {
110         throw new JDOUnsupportedOptionException(
111                 I18NHelper.getMessage(messages, "jdo.extentcollection.methodnotsupported", "isEmpty"));// NOI18N
112
}
113
114     /**
115      *
116      */

117     public boolean contains(Object JavaDoc o) {
118         throw new JDOUnsupportedOptionException(
119                 I18NHelper.getMessage(messages, "jdo.extentcollection.methodnotsupported", "contains"));// NOI18N
120
}
121
122     /**
123      *
124      */

125     public Iterator JavaDoc iterator() {
126         RetrieveDesc rd = pm.getRetrieveDesc(persistenceCapableClass);
127         return ((Collection JavaDoc)pm.retrieve(rd)).iterator();
128     }
129
130     /**
131      *
132      */

133     public Object JavaDoc[] toArray() {
134         throw new JDOUnsupportedOptionException(
135                 I18NHelper.getMessage(messages, "jdo.extentcollection.methodnotsupported", "toArray"));// NOI18N
136
}
137
138     /**
139      *
140      */

141     public Object JavaDoc[] toArray(Object JavaDoc a[]) {
142         throw new JDOUnsupportedOptionException(
143                 I18NHelper.getMessage(messages, "jdo.extentcollection.methodnotsupported", "toArray"));// NOI18N
144
}
145
146     /**
147      * Extent collection is unmodifiable => throw UnsupportedOperationException
148      */

149     public boolean add(Object JavaDoc o) {
150         throw new UnsupportedOperationException JavaDoc(
151                 I18NHelper.getMessage(messages, "jdo.extentcollection.illegalmodification", // NOI18N
152
persistenceCapableClass.getName()));
153     }
154
155     /**
156      * Extent collection is unmodifiable => throw UnsupportedOperationException
157      */

158     public boolean remove(Object JavaDoc o) {
159         throw new UnsupportedOperationException JavaDoc(
160                 I18NHelper.getMessage(messages, "jdo.extentcollection.illegalmodification", // NOI18N
161
persistenceCapableClass.getName()));
162     }
163
164     /**
165      *
166      */

167     public boolean containsAll(Collection JavaDoc c) {
168         throw new JDOUnsupportedOptionException(
169                 I18NHelper.getMessage(messages, "jdo.extentcollection.methodnotsupported", "containsAll"));// NOI18N
170
}
171
172     /**
173      * Extent collection is unmodifiable => throw UnsupportedOperationException
174      */

175     public boolean addAll(Collection JavaDoc c) {
176         throw new UnsupportedOperationException JavaDoc(
177                 I18NHelper.getMessage(messages, "jdo.extentcollection.illegalmodification", // NOI18N
178
persistenceCapableClass.getName()));
179     }
180
181     /**
182      * Extent collection is unmodifiable => throw UnsupportedOperationException
183      */

184     public boolean removeAll(Collection JavaDoc c) {
185         throw new UnsupportedOperationException JavaDoc(
186                 I18NHelper.getMessage(messages, "jdo.extentcollection.illegalmodification", // NOI18N
187
persistenceCapableClass.getName()));
188     }
189
190     /**
191      * Extent collection is unmodifiable => throw UnsupportedOperationException
192      */

193     public boolean retainAll(Collection JavaDoc c) {
194         throw new UnsupportedOperationException JavaDoc(
195                 I18NHelper.getMessage(messages, "jdo.extentcollection.illegalmodification", // NOI18N
196
persistenceCapableClass.getName()));
197     }
198
199     /**
200      * Extent collection is unmodifiable => throw UnsupportedOperationException
201      */

202     public void clear() {
203         throw new UnsupportedOperationException JavaDoc(
204                 I18NHelper.getMessage(messages, "jdo.extentcollection.illegalmodification", // NOI18N
205
persistenceCapableClass.getName()));
206     }
207
208     /**
209      * Two extent collections are equal, iff the names of their persistence capable class are equal
210      */

211     public boolean equals(Object JavaDoc o) {
212         if (o == this)
213             return true;
214         if (o instanceof ExtentCollection) {
215             String JavaDoc otherClassName = ((ExtentCollection) o).persistenceCapableClass.getName();
216             return persistenceCapableClass.getName().equals(otherClassName);
217         }
218         return false;
219     }
220
221     /**
222      * The hashCode is mapped to the hashCode of the name of the extent collection's persistence capable class
223      */

224     public int hashCode() {
225         return persistenceCapableClass.getName().hashCode();
226     }
227 }
228
Popular Tags