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  /*** MetaDataSourceDescriptor is the descriptor for MetaDataSourceDescriptorEntity 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 MetaDataSourceDescriptor extends AbstractMetaEntityDescriptor
34  {
35      // Constants ---------------------------------------------------------------
36      
37      /*** The singleton instance for the MetaDataSourceDescriptor entity descriptor.
38       * Access it as MetaDataSourceDescriptor.instance anywhere in the code.
39       */
40      public final static MetaDataSourceDescriptor 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 Version field (index=3) has the data type STRING(20).
58       * Version is a required field.
59       */
60      public final static IFieldDescriptor Version;
61      
62      /*** The ReadOnly field (index=4) has the data type BOOLEAN.
63       * ReadOnly is a required field.
64       */
65      public final static IFieldDescriptor ReadOnly;
66      
67      
68      // Static methods ----------------------------------------------------------
69      static
70      {
71          String className = MetaDataSourceDescriptor.class.getName();
72          
73          // Create all field descriptors that are part of the entity descriptor.
74          IFieldDescriptor[] fields = new IFieldDescriptor[5];
75          
76          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);
77          fields[1] = CodeName = createFieldDescriptor("CodeName", "CodeName", "Code Name", className, DataType.STRING, 50, IFieldDescriptor.REQUIRED | IFieldDescriptor.NAME_FIELD, null);
78          fields[2] = DisplayName = createFieldDescriptor("DisplayName", "DisplayName", "Display Name", className, DataType.STRING, 50, IFieldDescriptor.REQUIRED | IFieldDescriptor.OVERVIEW_FIELD, null);
79          fields[3] = Version = createFieldDescriptor("Version", "Version", "Version", className, DataType.STRING, 20, IFieldDescriptor.REQUIRED | IFieldDescriptor.OVERVIEW_FIELD, null);
80          fields[4] = ReadOnly = createFieldDescriptor("ReadOnly", "ReadOnly", "Read Only", className, DataType.BOOLEAN, 1, IFieldDescriptor.REQUIRED, null);
81          
82          // Create all relation objects to related entity descriptors.
83          IEntityRelation[] relations = new IEntityRelation[1];
84          IFieldRelation[] fieldRelations;
85  
86          fieldRelations = new IFieldRelation[1];
87          fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaEntityDescriptor", "DataSource", "org.caleigo.core.meta.MetaDataSourceDescriptor", "SourceName");
88          relations[0] = createEntityRelation(fieldRelations, "MetaEntityDescriptorMetaDataSource", "Data Source", "Entity Descriptors");
89          
90          // Create the entity descriptor.
91          instance = new MetaDataSourceDescriptor(fields, relations);
92      }
93      
94      /*** Creates a new MetaDataSourceDescriptorEntity with default values set
95       */
96      public static MetaDataSourceDescriptorEntity create()
97      {
98          return (MetaDataSourceDescriptorEntity)instance.createEntity();
99      }
100     
101     /*** Creates a new MetaDataSourceDescriptorEntity, setting any field values 
102      * avaivlable from the provided IDataProvider.
103      */
104     public static MetaDataSourceDescriptorEntity create(IDataProvider propertySource)
105     {
106         return (MetaDataSourceDescriptorEntity)instance.createEntity(propertySource);
107     }
108     
109     /*** Loads a single MetaDataSourceDescriptorEntity instance identified by
110      * by the provided identity field values from the default data source. 
111      * Returns null if no entity could be identified by field values.
112      */
113     public static MetaDataSourceDescriptorEntity load(String aSourceName)
114     {
115         return load(Qualifier.create(SourceName, new String(aSourceName)));
116     }
117         
118     /*** Loads a single MetaDataSourceDescriptorEntity instance identified by
119      * by the provided identity-qualifier from the default data source. 
120      * Returns null if no entity could be identified by the provided qualifier.
121      */
122     public static MetaDataSourceDescriptorEntity load(Qualifier identityQualifier)
123     {
124         if(instance.getDataSourceDescriptor().getDefaultDataSource()==null)
125             throw new DataServiceNotFoundException("No default data source has been set for: " + instance.getDataSourceDescriptor().getCodeName());
126         return (MetaDataSourceDescriptorEntity)instance.getDataSourceDescriptor().getDefaultDataSource().loadEntity(instance, identityQualifier);
127     }
128     
129     // Constructors ------------------------------------------------------------
130     
131     /*** Private access to avoid missuse.
132      */
133     private MetaDataSourceDescriptor(IFieldDescriptor[] fields, IEntityRelation[] relations) 
134     {
135         super("MetaDataSourceDescriptor", "MetaDataSourceDescriptor", "Data Source", "org.caleigo.core.meta.MetaDataSourceDescriptorEntity", "org.caleigo.core.meta.Meta", MASTER_ENTITY, fields, relations);
136         this.setFlags(SELECTABLE | CREATABLE | EDITABLE);
137         this.setCacheTime(72000);
138     }
139 }