KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > metadata > fieldaccess > AnonymousPersistentFieldHelper


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

17
18 import java.util.Iterator JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import org.apache.ojb.broker.metadata.AnonymousFieldDescriptor;
23 import org.apache.ojb.broker.metadata.ClassDescriptor;
24 import org.apache.ojb.broker.metadata.CollectionDescriptor;
25 import org.apache.ojb.broker.metadata.DescriptorRepository;
26 import org.apache.ojb.broker.metadata.FieldDescriptor;
27 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
28
29 /**
30  * Helper class for anonymous fields.
31  *
32  * @author Houar TINE
33  * @version $Id: AnonymousPersistentFieldHelper.java,v 1.7.2.2 2004/12/23 22:03:25 brj Exp $
34  */

35 public class AnonymousPersistentFieldHelper
36 {
37     public static void computeInheritedPersistentFields(final DescriptorRepository repository)
38     {
39         Map JavaDoc descriptorTable = repository.getDescriptorTable();
40         final String JavaDoc OBJECT = Object JavaDoc.class.getName();
41         for (Iterator JavaDoc iter = descriptorTable.entrySet().iterator(); iter.hasNext();)
42         {
43             Map.Entry JavaDoc me = (Map.Entry JavaDoc) iter.next();
44             ClassDescriptor cld = (ClassDescriptor) me.getValue();
45             String JavaDoc baseClass = cld.getBaseClass();
46             if (null != baseClass)
47             {
48                 Vector JavaDoc inheritedFields = new Vector JavaDoc();
49                 do
50                 {
51                     ClassDescriptor baseCld = repository.getDescriptorFor(baseClass);
52                     FieldDescriptor[] baseFields = baseCld.getFieldDescriptions();
53                     for (int i = baseFields.length - 1; i >= 0; i--)
54                     {
55                         FieldDescriptor f = baseFields[i];
56                         if (!(f instanceof AnonymousFieldDescriptor))
57                         {
58                             inheritedFields.add(f.getPersistentField());
59                         }
60                     }
61                     Vector JavaDoc ords = baseCld.getObjectReferenceDescriptors();
62                     for (int i = ords.size() - 1; i >= 0; i--)
63                     {
64                         ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) ords.get(i);
65                         PersistentField pf = ord.getPersistentField();
66                         if (!(pf instanceof AnonymousPersistentFieldForInheritance))
67                         {
68                             inheritedFields.add(pf);
69                         }
70                     }
71                     Vector JavaDoc cds = baseCld.getCollectionDescriptors();
72                     for (int i = cds.size() - 1; i >= 0; i--)
73                     {
74                         CollectionDescriptor cd = (CollectionDescriptor) cds.get(i);
75                         inheritedFields.add(cd.getPersistentField());
76                     }
77                     baseClass = baseCld.getBaseClass();
78                 }
79                 while ((null != baseClass) && !(baseClass.equals(OBJECT)));
80                 cld.setSuperPersistentFieldDescriptors(inheritedFields);
81             }
82         }
83     }
84 }
85
Popular Tags