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  package org.caleigo.core.meta;
19  
20  import org.caleigo.core.*;
21  import org.caleigo.core.exception.*;
22  
23  
24  /*** MetaEntityDescriptor is the descriptor for MetaEntityDescriptorEntity objects.
25  *
26  * @author dennis
27  * @version 1.0.0
28  *//*
29  * WHEN    WHO                WHY & WHAT 
30  * ------------------------------------------------------------------------------
31  * 030627  dennis    Creation
32  */
33  public class MetaEntityDescriptor extends AbstractMetaEntityDescriptor
34  {
35      // Constants ---------------------------------------------------------------
36      
37      /*** The singleton instance for the MetaEntityDescriptor entity descriptor.
38       * Access it as MetaEntityDescriptor.instance anywhere in the code.
39       */
40      public final static MetaEntityDescriptor instance;    
41      
42      /*** The SourceName field (index=0) has the data type STRING(50).
43       * SourceName is a required identity field.
44       */
45      public final static IFieldDescriptor SourceName;
46      
47      /*** The CodeName field (index=1) has the data type STRING(50).
48       * CodeName is a required field.
49       */
50      public final static IFieldDescriptor CodeName;
51      
52      /*** The DisplayName field (index=2) has the data type STRING(50).
53       * DisplayName is a required field.
54       */
55      public final static IFieldDescriptor DisplayName;
56      
57      /*** The EntityType field (index=3) has the data type INTEGER.
58       * EntityType is a required field.
59       */
60      public final static IFieldDescriptor EntityType;
61      
62      /*** The SizeType field (index=4) has the data type INTEGER.
63       * SizeType is a required field.
64       */
65      public final static IFieldDescriptor SizeType;
66      
67      /*** The CacheTime field (index=5) has the data type INTEGER.
68       * CacheTime is a required field.
69       */
70      public final static IFieldDescriptor CacheTime;
71      
72      /*** The Creatable field (index=6) has the data type BOOLEAN.
73       * Creatable is a required field.
74       */
75      public final static IFieldDescriptor Creatable;
76      
77      /*** The Editable field (index=7) has the data type BOOLEAN.
78       * Editable is a required field.
79       */
80      public final static IFieldDescriptor Editable;
81      
82      /*** The Deletable field (index=8) has the data type BOOLEAN.
83       * Deletable is a required field.
84       */
85      public final static IFieldDescriptor Deletable;
86      
87      /*** The DataSource field (index=9) has the data type STRING(50).
88       * DataSource is a required field.
89       */
90      public final static IFieldDescriptor DataSource;
91      
92      
93      // Static methods ----------------------------------------------------------
94      static
95      {
96          String className = MetaEntityDescriptor.class.getName();
97          
98          // Create all field descriptors that are part of the entity descriptor.
99          IFieldDescriptor[] fields = new IFieldDescriptor[10];
100         
101         fields[0] = SourceName = createFieldDescriptor("SourceName", "SourceName", "Source Name", className, DataType.STRING, 50, IFieldDescriptor.IDENTITY_FIELD | IFieldDescriptor.REQUIRED | IFieldDescriptor.INDEXED | IFieldDescriptor.OVERVIEW_FIELD | IFieldDescriptor.READ_ONLY_FIELD, null);
102         fields[1] = CodeName = createFieldDescriptor("CodeName", "CodeName", "Code Name", className, DataType.STRING, 50, IFieldDescriptor.REQUIRED | IFieldDescriptor.NAME_FIELD, null);
103         fields[2] = DisplayName = createFieldDescriptor("DisplayName", "DisplayName", "Display Name", className, DataType.STRING, 50, IFieldDescriptor.REQUIRED, null);
104         fields[3] = EntityType = createFieldDescriptor("EntityType", "EntityType", "Entity Type", className, DataType.INTEGER, 10, IFieldDescriptor.REQUIRED | IFieldDescriptor.OVERVIEW_FIELD, null);
105         fields[4] = SizeType = createFieldDescriptor("SizeType", "SizeType", "Size Type", className, DataType.INTEGER, 10, IFieldDescriptor.REQUIRED, null);
106         fields[5] = CacheTime = createFieldDescriptor("CacheTime", "CacheTime", "Cache Time", className, DataType.INTEGER, 10, IFieldDescriptor.REQUIRED, null);
107         fields[6] = Creatable = createFieldDescriptor("Creatable", "Creatable", "Creatable", className, DataType.BOOLEAN, 1, IFieldDescriptor.REQUIRED, null);
108         fields[7] = Editable = createFieldDescriptor("Editable", "Editable", "Editable", className, DataType.BOOLEAN, 1, IFieldDescriptor.REQUIRED, null);
109         fields[8] = Deletable = createFieldDescriptor("Deletable", "Deletable", "Deletable", className, DataType.BOOLEAN, 1, IFieldDescriptor.REQUIRED, null);
110         fields[9] = DataSource = createFieldDescriptor("DataSource", "DataSource", "Data Source", className, DataType.STRING, 50, IFieldDescriptor.REQUIRED | IFieldDescriptor.READ_ONLY_FIELD, null);
111         
112         // Create all relation objects to related entity descriptors.
113         IEntityRelation[] relations = new IEntityRelation[6];
114         IFieldRelation[] fieldRelations;
115 
116         fieldRelations = new IFieldRelation[1];
117         fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaEntityDescriptor", "DataSource", "org.caleigo.core.meta.MetaDataSourceDescriptor", "SourceName");
118         relations[0] = createEntityRelation(fieldRelations, "MetaEntityDescriptorMetaDataSourceDescriptor", "Data Source", "Entity Descriptors");
119 
120         fieldRelations = new IFieldRelation[1];
121         fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaEntityDescriptor", "EntityType", "org.caleigo.core.meta.MetaEntityType", "ID");
122         relations[1] = createEntityRelation(fieldRelations, "MetaEntityDescriptorMetaEntityType", "Entity Type", "Entity Descriptors");
123 
124         fieldRelations = new IFieldRelation[1];
125         fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaEntityDescriptor", "SizeType", "org.caleigo.core.meta.MetaSizeType", "ID");
126         relations[2] = createEntityRelation(fieldRelations, "MetaEntityDescriptorMetaSizeType", "Size Type", "Entity Descriptors");
127 
128         fieldRelations = new IFieldRelation[1];
129         fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaEntityRelation", "ReferenceEntity", "org.caleigo.core.meta.MetaEntityDescriptor", "SourceName");
130         relations[3] = createEntityRelation(fieldRelations, "MetaEntityRelationMetaEntityDescripto", "Reference Descriptor", "Foreign Relations");
131 
132         fieldRelations = new IFieldRelation[1];
133         fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaEntityRelation", "TargetEntity", "org.caleigo.core.meta.MetaEntityDescriptor", "SourceName");
134         relations[4] = createEntityRelation(fieldRelations, "MetaEntityRelationMetaEntityDescriptor1", "Target Descriptor", "Target Relations");
135 
136         fieldRelations = new IFieldRelation[1];
137         fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaFieldDescriptor", "Entity", "org.caleigo.core.meta.MetaEntityDescriptor", "SourceName");
138         relations[5] = createEntityRelation(fieldRelations, "MetaFieldDescriptorMetaEntityDescriptor", "Entity Descriptor", "Field Descriptors");
139         
140         // Create the entity descriptor.
141         instance = new MetaEntityDescriptor(fields, relations);
142     }
143     
144     /*** Creates a new MetaEntityDescriptorEntity with default values set
145      */
146     public static MetaEntityDescriptorEntity create()
147     {
148         return (MetaEntityDescriptorEntity)instance.createEntity();
149     }
150     
151     /*** Creates a new MetaEntityDescriptorEntity, setting any field values 
152      * avaivlable from the provided IDataProvider.
153      */
154     public static MetaEntityDescriptorEntity create(IDataProvider propertySource)
155     {
156         return (MetaEntityDescriptorEntity)instance.createEntity(propertySource);
157     }
158     
159     /*** Loads a single MetaEntityDescriptorEntity instance identified by
160      * by the provided identity field values from the default data source. 
161      * Returns null if no entity could be identified by field values.
162      */
163     public static MetaEntityDescriptorEntity load(String aSourceName)
164     {
165         return load(Qualifier.create(SourceName, new String(aSourceName)));
166     }
167         
168     /*** Loads a single MetaEntityDescriptorEntity instance identified by
169      * by the provided identity-qualifier from the default data source. 
170      * Returns null if no entity could be identified by the provided qualifier.
171      */
172     public static MetaEntityDescriptorEntity load(Qualifier identityQualifier)
173     {
174         if(instance.getDataSourceDescriptor().getDefaultDataSource()==null)
175             throw new DataServiceNotFoundException("No default data source has been set for: " + instance.getDataSourceDescriptor().getCodeName());
176         return (MetaEntityDescriptorEntity)instance.getDataSourceDescriptor().getDefaultDataSource().loadEntity(instance, identityQualifier);
177     }
178     
179     // Constructors ------------------------------------------------------------
180     
181     /*** Private access to avoid missuse.
182      */
183     private MetaEntityDescriptor(IFieldDescriptor[] fields, IEntityRelation[] relations) 
184     {
185         super("MetaEntityDescriptor", "MetaEntityDescriptor", "Entity Descriptor", "org.caleigo.core.meta.MetaEntityDescriptorEntity", "org.caleigo.core.meta.Meta", MASTER_ENTITY, fields, relations);
186         this.setFlags(LISTABLE | CREATABLE | EDITABLE);
187         this.setCacheTime(72000);
188     }
189 }