KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > hibernate > HibernateField


1 /*
2  * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.amber.hibernate;
30
31 import com.caucho.bytecode.JMethod;
32 import com.caucho.bytecode.JClass;
33
34 import com.caucho.util.L10N;
35
36 import com.caucho.config.ConfigException;
37
38 import com.caucho.amber.type.Type;
39 import com.caucho.amber.type.EntityType;
40
41 import com.caucho.amber.field.AbstractField;
42
43 /**
44  * configuration for an entity
45  */

46 public class HibernateField {
47   private static final L10N L = new L10N(HibernateField.class);
48
49   private EntityType _type;
50   private AbstractField _field;
51   
52   private Type _resultType;
53
54   HibernateField(EntityType type)
55   {
56     _type = type;
57   }
58
59   protected void setField(AbstractField field)
60   {
61     _field = field;
62   }
63
64   public void setName(String name)
65     throws ConfigException
66   {
67     _field.setName(name);
68   }
69
70   public void setType(String type)
71     throws ConfigException
72   {
73     _resultType = _type.getAmberManager().createType(type);
74   }
75
76   public Type getType()
77   {
78     return _resultType;
79   }
80
81   EntityType getOwnerType()
82   {
83     return _type;
84   }
85
86   public void init()
87     throws ConfigException
88   {
89     /*
90     if (_field.getName() == null) {
91       throw new ConfigException(L.l("'name' missing for property. Properties need a name attribute."));
92     }
93     */

94     
95     if (_resultType == null) {
96       JMethod method = _field.getGetterMethod();
97       if (method != null) {
98     JClass resultClass = method.getReturnType();
99     _resultType = _type.getAmberManager().createType(resultClass);
100       }
101       else {
102     _resultType = _type.getAmberManager().createType("string");
103       }
104     }
105   }
106 }
107
Popular Tags