1 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 ; 40 import java.util.HashMap ; 41 import java.util.logging.Logger ; 42 43 46 public class EmbeddableIntrospector extends BaseConfigIntrospector { 47 private static final L10N L = new L10N(EmbeddableIntrospector.class); 48 private static final Logger log 49 = Logger.getLogger(EmbeddableIntrospector.class.getName()); 50 51 HashMap <String , EmbeddableType> _embeddableMap 52 = new HashMap <String , EmbeddableType>(); 53 54 57 public EmbeddableIntrospector(AmberPersistenceUnit persistenceUnit) 58 { 59 super(persistenceUnit); 60 } 61 62 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 77 public EmbeddableType introspect(JClass type) 78 throws ConfigException, SQLException 79 { 80 getInternalEmbeddableConfig(type); 81 JAnnotation embeddableAnn = _annotationCfg.getAnnotation(); 82 EmbeddableConfig embeddableConfig = _annotationCfg.getEmbeddableConfig(); 83 84 String 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 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 e) { 126 embeddableType.setConfigException(e); 127 128 throw e; 129 } 130 131 return embeddableType; 132 } 133 } 134 | Popular Tags |