KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > reflect > ListProperty


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.reflect;
21
22 import org.apache.cayenne.Fault;
23 import org.apache.cayenne.Persistent;
24 import org.apache.cayenne.ValueHolder;
25 import org.apache.cayenne.util.PersistentObjectList;
26
27 /**
28  * Provides access to a property implemented as a List Field.
29  *
30  * @since 1.2
31  * @author Andrus Adamchik
32  */

33 public class ListProperty extends BaseToManyProperty {
34
35     public ListProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor,
36             Accessor accessor, String JavaDoc reverseName) {
37         super(owner, targetDescriptor, accessor, reverseName);
38     }
39
40     /**
41      * Creates a List for an object. Expects an object to be an instance of Persistent.
42      */

43     protected ValueHolder createCollectionValueHolder(Object JavaDoc object)
44             throws PropertyException {
45         if (!(object instanceof Persistent)) {
46
47             throw new PropertyException(
48                     "ValueHolders for non-persistent objects are not supported.",
49                     this,
50                     object);
51         }
52
53         return new PersistentObjectList((Persistent) object, getName());
54     }
55
56     public boolean isFault(Object JavaDoc object) {
57         Object JavaDoc target = accessor.getValue(object);
58         return target == null
59                 || target instanceof Fault
60                 || ((ValueHolder) target).isFault();
61     }
62
63     public void invalidate(Object JavaDoc object) {
64         ValueHolder list = (ValueHolder) readPropertyDirectly(object);
65         if(list != null) {
66             list.invalidate();
67         }
68     }
69 }
70
Popular Tags