KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > reflect > generic > DataObjectToOneProperty


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.generic;
21
22 import org.apache.cayenne.Fault;
23 import org.apache.cayenne.map.ObjRelationship;
24 import org.apache.cayenne.reflect.ArcProperty;
25 import org.apache.cayenne.reflect.ClassDescriptor;
26 import org.apache.cayenne.reflect.PropertyException;
27 import org.apache.cayenne.reflect.PropertyVisitor;
28 import org.apache.cayenne.reflect.ToOneProperty;
29
30 /**
31  * An ArcProperty for accessing to-one relationships.
32  *
33  * @since 3.0
34  * @author Andrus Adamchik
35  */

36 class DataObjectToOneProperty extends DataObjectBaseProperty implements ToOneProperty {
37
38     protected ObjRelationship relationship;
39     protected String JavaDoc reverseName;
40     protected ClassDescriptor targetDescriptor;
41
42     DataObjectToOneProperty(ObjRelationship relationship, ClassDescriptor targetDescriptor) {
43         this.relationship = relationship;
44         this.targetDescriptor = targetDescriptor;
45         this.reverseName = relationship.getReverseRelationshipName();
46     }
47
48     public ArcProperty getComplimentaryReverseArc() {
49         return reverseName != null ? (ArcProperty) targetDescriptor
50                 .getProperty(reverseName) : null;
51     }
52
53     public ClassDescriptor getTargetDescriptor() {
54         return targetDescriptor;
55     }
56
57     public String JavaDoc getName() {
58         return relationship.getName();
59     }
60
61     public ObjRelationship getRelationship() {
62         return relationship;
63     }
64
65     public void injectValueHolder(Object JavaDoc object) throws PropertyException {
66     }
67
68     public void setTarget(Object JavaDoc source, Object JavaDoc target, boolean setReverse) {
69         try {
70             toDataObject(source).setToOneTarget(
71                     getName(),
72                     toDataObject(target),
73                     setReverse);
74         }
75         catch (Throwable JavaDoc th) {
76             throw new PropertyException("Error setting to-one DataObject property: "
77                     + getName(), this, source, th);
78         }
79     }
80
81     public boolean visit(PropertyVisitor visitor) {
82         return visitor.visitToOne(this);
83     }
84
85     public boolean isFault(Object JavaDoc object) {
86         return readPropertyDirectly(object) instanceof Fault;
87     }
88
89     public void invalidate(Object JavaDoc object) {
90         writePropertyDirectly(object, null, Fault.getToOneFault());
91     }
92 }
93
Popular Tags