KickJava   Java API By Example, From Geeks To Geeks.

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


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.generic;
20
21 import org.apache.cayenne.DataObject;
22 import org.apache.cayenne.map.ObjAttribute;
23 import org.apache.cayenne.map.ObjEntity;
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.PersistentDescriptor;
30 import org.apache.cayenne.reflect.PersistentDescriptorFactory;
31 import org.apache.cayenne.reflect.PropertyException;
32
33 /**
34  * A {@link ClassDescriptorFactory} that creates descriptors for classes implementing
35  * {@link DataObject}.
36  *
37  * @since 3.0
38  * @author Andrus Adamchik
39  */

40 public class DataObjectDescriptorFactory extends PersistentDescriptorFactory {
41
42     public DataObjectDescriptorFactory(ClassDescriptorMap descriptorMap) {
43         super(descriptorMap);
44     }
45
46     protected ClassDescriptor getDescriptor(ObjEntity entity, Class JavaDoc entityClass) {
47         if (!DataObject.class.isAssignableFrom(entityClass)) {
48             return null;
49         }
50
51         return super.getDescriptor(entity, entityClass);
52     }
53
54     protected PersistentDescriptor createDescriptor() {
55         return new DataObjectDescriptor();
56     }
57
58     protected void createAttributeProperty(
59             PersistentDescriptor descriptor,
60             ObjAttribute attribute) {
61         descriptor.addDeclaredProperty(new DataObjectAttributeProperty(attribute));
62     }
63
64     protected void createToManyProperty(
65             PersistentDescriptor descriptor,
66             ObjRelationship relationship) {
67
68         ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship
69                 .getTargetEntityName());
70         descriptor.addDeclaredProperty(new DataObjectToManyProperty(
71                 relationship,
72                 targetDescriptor));
73     }
74
75     protected void createToOneProperty(
76             PersistentDescriptor descriptor,
77             ObjRelationship relationship) {
78
79         ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship
80                 .getTargetEntityName());
81         descriptor.addDeclaredProperty(new DataObjectToOneProperty(
82                 relationship,
83                 targetDescriptor));
84     }
85
86     protected Accessor createAccessor(
87             PersistentDescriptor descriptor,
88             String JavaDoc propertyName,
89             Class JavaDoc propertyType) throws PropertyException {
90         return new DataObjectAccessor(propertyName);
91     }
92 }
93
Popular Tags