View Javadoc

1   /* (c) Copyright 2003 Caleigo AB, All rights reserved. 
2    * 
3    * This library is free software; you can redistribute it and/or
4    * modify it under the terms of the GNU Lesser General Public
5    * License as published by the Free Software Foundation; either
6    * version 2.1 of the License, or (at your option) any later version.
7    * 
8    * This library is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   * Lesser General Public License for more details.
12   * 
13   * You should have received a copy of the GNU Lesser General Public
14   * License along with this library; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   *  
17   */
18  
19  package org.caleigo.core.meta;
20  
21  
22  import org.caleigo.core.*;
23  import org.caleigo.toolkit.log.Log;
24  
25  
26  
27  /***
28   *
29   * @author  Mattias Hagstrand
30   * @version 1.0
31   */
32  /* 
33  *
34  * WHEN        WHO               WHY & WHAT
35  * ------------------------------------------------------------------------------
36  * 2002-03-25  Mattias Hagstrand    Creation
37  */
38  class CustomFieldDescriptor extends FieldDescriptor
39  {
40      // Data members ------------------------------------------------------------
41      private IEntityDescriptor mEntityDescriptor;
42  
43  //    protected static HashMap sRegisteredFieldDescriptors = new HashMap();
44  
45      // Constructors ------------------------------------------------------------
46      public CustomFieldDescriptor(String codeName, String sourceName, String displayName, DataType dataType, int length, int flags, Object defValue)
47      {
48          super(codeName, sourceName, displayName, null, dataType, length, flags, defValue);
49  //        sRegisteredFieldDescriptors.remove(codeName);
50  //        sRegisteredFieldDescriptors.put(codeName, this);
51      }
52  
53      // Superclass overrides ----------------------------------------------------
54      public IEntityDescriptor getEntityDescriptor()
55      {
56          return mEntityDescriptor;
57      }
58  
59      // Action methods ----------------------------------------------------------
60      public void setEntityDescriptor(IEntityDescriptor entityDescriptor)
61      {
62          mEntityDescriptor = entityDescriptor;
63      }
64      
65      // Action methods ----------------------------------------------------------
66      protected Object writeReplace() throws java.io.ObjectStreamException
67      {
68        return new Dezerializer(
69              this.getEntityDescriptor().getDataSourceDescriptor().getCodeName(),
70              this.getEntityDescriptor().getCodeName(),
71              this.getCodeName());
72      }
73      
74      
75      // Nested classes ----------------------------------------------------------
76      protected static class Dezerializer implements java.io.Serializable
77      {
78          // Data members --------------------------------------------------------
79          protected String mDataSourceDescriptorCodeName;
80          protected String mEntityDescriptorCodeName;
81          protected String mCodeName;
82                  
83          // Constructors --------------------------------------------------------
84          public Dezerializer(String dataSourceDescriptorCodeName, String entityDescriptorCodeName, String codeName)
85          {
86              mDataSourceDescriptorCodeName = dataSourceDescriptorCodeName;
87              mEntityDescriptorCodeName = entityDescriptorCodeName;
88              mCodeName = codeName;
89          }
90          
91          // Action methods ------------------------------------------------------
92          protected Object readResolve() throws java.io.ObjectStreamException
93          {
94  //            return CustomFieldDescriptor.sRegisteredFieldDescriptors.get(mCodeName);
95  
96              CustomDataSourceDescriptor dataSourceDescriptor = CustomDataSourceDescriptor.getRegisteredCustomDataSourceDescriptor(mDataSourceDescriptorCodeName);
97              
98              if (dataSourceDescriptor != null)
99              {
100                 IEntityDescriptor entityDescriptor = dataSourceDescriptor.getEntityDescriptor(mEntityDescriptorCodeName);
101                 if (entityDescriptor != null)
102                 {
103                     IFieldDescriptor fieldDescriptor = entityDescriptor.getFieldDescriptor(mCodeName);
104                     if (fieldDescriptor != null)
105                         return fieldDescriptor;
106                     else
107                     {
108                         Log.printError(this, "CustomFieldDescriptor with code name " + mCodeName + " not found");
109                         throw new java.io.InvalidObjectException("CustomFieldDescriptor with code name " + mCodeName + " not found");
110                     }
111                 }
112                 else
113                 {
114                     Log.printError(this, "CustomEntityDescriptor with code name " + mEntityDescriptorCodeName + " not found");
115                     throw new java.io.InvalidObjectException("CustomEntityDescriptor with code name " + mEntityDescriptorCodeName + " not found");
116                 }
117             }
118             else
119             {
120                 Log.printError(this, "CustomDataSourceDescriptor with code name " + mDataSourceDescriptorCodeName + " not found");
121                 throw new java.io.InvalidObjectException("CustomDataSourceDescriptor with code name " + mDataSourceDescriptorCodeName + " not found");
122             }
123         }
124     }  
125 
126 }