001 package org.apache.ojb.broker.core.proxy;
002
003 /* Copyright 2003-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import java.util.Collection;
019 import java.util.List;
020 import java.util.ListIterator;
021
022 import org.apache.ojb.broker.PBKey;
023 import org.apache.ojb.broker.PersistenceBrokerException;
024 import org.apache.ojb.broker.query.Query;
025 import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
026
027 /**
028 * A placeHolder for a whole list to support deferred loading of
029 * relationships. The complete relationship is loaded on request.
030 *
031 * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
032 * @version $Id: ListProxyDefaultImpl.java,v 1.1 2007-08-24 22:17:32 ewestfal Exp $
033 */
034 public class ListProxyDefaultImpl extends CollectionProxyDefaultImpl implements List
035 {
036
037 /**
038 * Constructor for ListProxy.
039 * @param aKey
040 * @param aQuery
041 */
042 public ListProxyDefaultImpl(PBKey aKey, Query aQuery)
043 {
044 this(aKey, RemovalAwareCollection.class, aQuery);
045 }
046
047 /**
048 * Constructor for ListProxy.
049 * @param aKey
050 * @param aCollClass
051 * @param aQuery
052 */
053 public ListProxyDefaultImpl(PBKey aKey, Class aCollClass, Query aQuery)
054 {
055 super(aKey, aCollClass, aQuery);
056 }
057
058 /**
059 * @see java.util.List#addAll(int, java.util.Collection)
060 */
061 public boolean addAll(int index, Collection c)
062 {
063 return getListData().addAll(index, c);
064 }
065
066 /**
067 * @see java.util.List#get(int)
068 */
069 public Object get(int index)
070 {
071 return getListData().get(index);
072 }
073
074 /**
075 * @see java.util.List#set(int, java.lang.Object)
076 */
077 public Object set(int index, Object element)
078 {
079 return getListData().set(index, element);
080 }
081
082 /**
083 * @see java.util.List#add(int, java.lang.Object)
084 */
085 public void add(int index, Object element)
086 {
087 getListData().add(index, element);
088 }
089
090 /**
091 * @see java.util.List#remove(int)
092 */
093 public Object remove(int index)
094 {
095 return getListData().remove(index);
096 }
097
098 /**
099 * @see java.util.List#indexOf(java.lang.Object)
100 */
101 public int indexOf(Object o)
102 {
103 return getListData().indexOf(o);
104 }
105
106 /**
107 * @see java.util.List#lastIndexOf(java.lang.Object)
108 */
109 public int lastIndexOf(Object o)
110 {
111 return getListData().lastIndexOf(o);
112 }
113
114 /**
115 * @see java.util.List#listIterator()
116 */
117 public ListIterator listIterator()
118 {
119 return getListData().listIterator();
120 }
121
122 /**
123 * @see java.util.List#listIterator(int)
124 */
125 public ListIterator listIterator(int index)
126 {
127 return getListData().listIterator(index);
128 }
129
130 /**
131 * @see java.util.List#subList(int, int)
132 */
133 public List subList(int fromIndex, int toIndex)
134 {
135 return getListData().subList(fromIndex, toIndex);
136 }
137
138 protected List getListData()
139 {
140 return (List) super.getData();
141 }
142
143 /**
144 * @see org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl#loadData()
145 */
146 protected Collection loadData() throws PersistenceBrokerException
147 {
148 Collection result = super.loadData();
149
150 if (result instanceof List)
151 {
152 return result;
153 }
154 else
155 {
156 throw new PersistenceBrokerException("loaded data does not implement java.util.List");
157 }
158
159 }
160
161 }