KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > cfg > EmbeddableIntrospector


1 /*
2  * Copyright (c) 1998-2006 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  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Rodrigo Westrupp
28  */

29
30 package com.caucho.amber.cfg;
31
32 import com.caucho.amber.manager.AmberPersistenceUnit;
33 import com.caucho.amber.type.EmbeddableType;
34 import com.caucho.bytecode.JAnnotation;
35 import com.caucho.bytecode.JClass;
36 import com.caucho.config.ConfigException;
37 import com.caucho.util.L10N;
38
39 import java.sql.SQLException JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43 /**
44  * Configuration for an embeddable type
45  */

46 public class EmbeddableIntrospector extends BaseConfigIntrospector {
47   private static final L10N L = new L10N(EmbeddableIntrospector.class);
48   private static final Logger JavaDoc log
49     = Logger.getLogger(EmbeddableIntrospector.class.getName());
50
51   HashMap JavaDoc<String JavaDoc, EmbeddableType> _embeddableMap
52     = new HashMap JavaDoc<String JavaDoc, EmbeddableType>();
53
54   /**
55    * Creates the introspector.
56    */

57   public EmbeddableIntrospector(AmberPersistenceUnit persistenceUnit)
58   {
59     super(persistenceUnit);
60   }
61
62   /**
63    * Returns true for embeddable type.
64    */

65   public boolean isEmbeddable(JClass type)
66   {
67     getInternalEmbeddableConfig(type);
68     JAnnotation embeddableAnn = _annotationCfg.getAnnotation();
69     EmbeddableConfig embeddableConfig = _annotationCfg.getEmbeddableConfig();
70
71     return (! _annotationCfg.isNull());
72   }
73
74   /**
75    * Introspects.
76    */

77   public EmbeddableType introspect(JClass type)
78     throws ConfigException, SQLException JavaDoc
79   {
80     getInternalEmbeddableConfig(type);
81     JAnnotation embeddableAnn = _annotationCfg.getAnnotation();
82     EmbeddableConfig embeddableConfig = _annotationCfg.getEmbeddableConfig();
83
84     String JavaDoc typeName = type.getName();
85
86     EmbeddableType embeddableType = _embeddableMap.get(typeName);
87
88     if (embeddableType != null)
89       return embeddableType;
90
91     try {
92       embeddableType = _persistenceUnit.createEmbeddable(typeName, type);
93       _embeddableMap.put(typeName, embeddableType);
94
95       boolean isField = isField(type, embeddableConfig, true);
96
97       if (isField)
98         embeddableType.setFieldAccess(true);
99
100       // XXX: jpa/0u21
101
JAnnotation ann = type.getAnnotation(javax.persistence.Embeddable.class);
102
103       if (ann == null) {
104         isField = true;
105         embeddableType.setIdClass(true);
106         _persistenceUnit.getAmberContainer().addEmbeddable(typeName,
107                                                              embeddableType);
108       }
109
110       embeddableType.setInstanceClassName(type.getName() +
111                                           "__ResinExt");
112       embeddableType.setEnhanced(true);
113
114       if (isField)
115         introspectFields(_persistenceUnit, embeddableType, null,
116                          type, embeddableConfig, true);
117       else
118         introspectMethods(_persistenceUnit, embeddableType, null,
119                           type, embeddableConfig);
120
121     } catch (ConfigException e) {
122       embeddableType.setConfigException(e);
123
124       throw e;
125     } catch (RuntimeException JavaDoc e) {
126       embeddableType.setConfigException(e);
127
128       throw e;
129     }
130
131     return embeddableType;
132   }
133 }
134
Popular Tags