View Javadoc

1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
19   */
20  
21  package org.onemind.commons.relabean;
22  
23  import java.util.Collection;
24  import org.onemind.commons.java.datastructure.ClassSet;
25  import org.onemind.commons.java.datastructure.InheritableValueMap;
26  /***
27   * Describes a relational bean model as to what is primitive type and what is bean type and the name mapping for each bean class
28   * 
29   * @author TiongHiang Lee (thlee@onemindsoft.org)
30   * @version $Id: RelationalBeanModelDescriptor.java,v 1.2 2004/08/26 16:28:58 thlee Exp $ $Name:  $
31   */
32  public class RelationalBeanModelDescriptor
33  {
34  
35      /*** the model name * */
36      private String _modelName;
37  
38      /*** the primitive types * */
39      private ClassSet _primitiveTypes = new ClassSet();
40  
41      /*** the stop class * */
42      private InheritableValueMap _stopClasses = new InheritableValueMap();
43  
44      /***
45       * {@inheritDoc}
46       */
47      public RelationalBeanModelDescriptor(String name)
48      {
49          _modelName = name;
50          _primitiveTypes.add(Number.class);
51          _primitiveTypes.add(Boolean.class);
52          _primitiveTypes.add(Character.class);
53          _primitiveTypes.add(String.class);
54          _stopClasses.put(Object.class, Object.class);
55      }
56  
57      /***
58       * Returns the model name
59       * 
60       * @return the model name
61       */
62      public String getModelName()
63      {
64          return _modelName;
65      }
66  
67      /***
68       * set the model name
69       * 
70       * @param modelName the model name
71       */
72      public void setModelName(String modelName)
73      {
74          _modelName = modelName;
75      }
76  
77      /***
78       * return whether a class is primitive type
79       * 
80       * @param c the class
81       * @return true if the class is primitive type
82       */
83      public boolean isPrimitiveType(Class c)
84      {
85          return _primitiveTypes.isSubclassOfClasses(c);
86      }
87  
88      /***
89       * Whether a class is primitive types
90       * 
91       * @return the name mappings
92       */
93      public Collection getPrimitiveTypes()
94      {
95          return _primitiveTypes.getClasses();
96      }
97  
98      /***
99       * Add class c as primitive type
100      * 
101      * @param c the primitive type
102      */
103     public void addPrimitiveTypes(Class c)
104     {
105         _primitiveTypes.add(c);
106     }
107 
108     /***
109      * Get a stop class for particular class
110      * 
111      * @param c the class
112      * @return the stop class
113      */
114     public Class getStopClass(Class c)
115     {
116         return (Class) _stopClasses.resolve(c);
117     }
118 
119     /***
120      * Set the stop class for particular class
121      * 
122      * @param c the class
123      * @param stopClass the stop class
124      */
125     public void setStopClass(Class c, Class stopClass)
126     {
127         _stopClasses.put(c, stopClass);
128     }
129 }