KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > reflect > valueholder > ValueHolderDescriptorFactory


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 package org.apache.cayenne.reflect.valueholder;
20
21 import java.util.List JavaDoc;
22
23 import org.apache.cayenne.ValueHolder;
24 import org.apache.cayenne.map.ObjRelationship;
25 import org.apache.cayenne.reflect.Accessor;
26 import org.apache.cayenne.reflect.ClassDescriptor;
27 import org.apache.cayenne.reflect.ClassDescriptorFactory;
28 import org.apache.cayenne.reflect.ClassDescriptorMap;
29 import org.apache.cayenne.reflect.ListProperty;
30 import org.apache.cayenne.reflect.PersistentDescriptor;
31 import org.apache.cayenne.reflect.PersistentDescriptorFactory;
32 import org.apache.cayenne.reflect.Property;
33
34 /**
35  * A {@link ClassDescriptorFactory} for Persistent objects that implement relationship
36  * faulting via {@link ValueHolder}.
37  *
38  * @since 3.0
39  * @author Andrus Adamchik
40  */

41 public class ValueHolderDescriptorFactory extends PersistentDescriptorFactory {
42
43     public ValueHolderDescriptorFactory(ClassDescriptorMap descriptorMap) {
44         super(descriptorMap);
45     }
46
47     protected void createToManyProperty(
48             PersistentDescriptor descriptor,
49             ObjRelationship relationship) {
50
51         ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship
52                 .getTargetEntityName());
53         String JavaDoc reverseName = relationship.getReverseRelationshipName();
54
55         Accessor accessor = createAccessor(descriptor, relationship.getName(), List JavaDoc.class);
56         descriptor.addDeclaredProperty(new ListProperty(
57                 descriptor,
58                 targetDescriptor,
59                 accessor,
60                 reverseName));
61     }
62
63     protected void createToOneProperty(
64             PersistentDescriptor descriptor,
65             ObjRelationship relationship) {
66         ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship
67                 .getTargetEntityName());
68         String JavaDoc reverseName = relationship.getReverseRelationshipName();
69
70         Accessor accessor = createAccessor(
71                 descriptor,
72                 relationship.getName(),
73                 ValueHolder.class);
74         Property property = new ValueHolderProperty(
75                 descriptor,
76                 targetDescriptor,
77                 accessor,
78                 reverseName);
79
80         descriptor.addDeclaredProperty(property);
81     }
82 }
83
Popular Tags