Author: hardy.ferentschik
Date: 2009-07-08 11:00:18 -0400 (Wed, 08 Jul 2009)
New Revision: 17051
Modified:
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java
Log:
added support for embeddable
Modified:
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
===================================================================
---
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-07-08
14:38:54 UTC (rev 17050)
+++
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-07-08
15:00:18 UTC (rev 17051)
@@ -150,8 +150,14 @@
if ( mappings == null ) {
return;
}
+
+ parseEntities( mappings );
+ parseEmbeddable( mappings );
+ }
+
+ private void parseEntities(EntityMappings mappings) {
+ String packageName = mappings.getPackage();
Collection<Entity> entities = mappings.getEntity();
- String packageName = mappings.getPackage();
for ( Entity entity : entities ) {
String fullyQualifiedClassName = packageName + "." + entity.getClazz();
Elements utils = processingEnv.getElementUtils();
@@ -169,6 +175,26 @@
}
}
+ private void parseEmbeddable(EntityMappings mappings) {
+ String packageName = mappings.getPackage();
+ Collection<org.hibernate.jpa.metamodel.xml.jaxb.Embeddable> embeddables =
mappings.getEmbeddable();
+ for ( org.hibernate.jpa.metamodel.xml.jaxb.Embeddable embeddable : embeddables ) {
+ String fullyQualifiedClassName = packageName + "." + embeddable.getClazz();
+ Elements utils = processingEnv.getElementUtils();
+ XmlMetaEntity metaEntity = new XmlMetaEntity(
+ embeddable, packageName, utils.getTypeElement( fullyQualifiedClassName )
+ );
+
+ if ( metaEntities.containsKey( fullyQualifiedClassName ) ) {
+ processingEnv.getMessager().printMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " was already processed once. Skipping second
occurance."
+ );
+ }
+ metaEntities.put( fullyQualifiedClassName, metaEntity );
+ }
+ }
+
private void handleRootElementAnnotationMirrors(final Element element) {
List<? extends AnnotationMirror> annotationMirrors = element
Modified:
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java
===================================================================
---
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java 2009-07-08
14:38:54 UTC (rev 17050)
+++
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java 2009-07-08
15:00:18 UTC (rev 17051)
@@ -37,6 +37,8 @@
import org.hibernate.jpa.metamodel.xml.jaxb.Id;
import org.hibernate.jpa.metamodel.xml.jaxb.ManyToOne;
import org.hibernate.jpa.metamodel.xml.jaxb.OneToMany;
+import org.hibernate.jpa.metamodel.xml.jaxb.Embeddable;
+import org.hibernate.jpa.metamodel.xml.jaxb.EmbeddableAttributes;
/**
* @author Hardy Ferentschik
@@ -52,7 +54,7 @@
COLLECTIONS.put( "java.util.Map",
"javax.persistence.metamodel.MapAttribute" );
}
- final private Entity ormEntity;
+ final private String clazzName;
final private String packageName;
@@ -63,7 +65,7 @@
private TypeElement element;
public XmlMetaEntity(Entity ormEntity, String packageName, TypeElement element) {
- this.ormEntity = ormEntity;
+ this.clazzName = ormEntity.getClazz();
this.packageName = packageName;
importContext = new ImportContextImpl( getPackageName() );
this.element = element;
@@ -96,8 +98,40 @@
}
}
+ public XmlMetaEntity(Embeddable embeddable, String packageName, TypeElement element) {
+ this.clazzName = embeddable.getClazz();
+ this.packageName = packageName;
+ importContext = new ImportContextImpl( getPackageName() );
+ this.element = element;
+ EmbeddableAttributes attributes = embeddable.getAttributes();
+
+ XmlMetaSingleAttribute attribute;
+ for ( Basic basic : attributes.getBasic() ) {
+ attribute = new XmlMetaSingleAttribute( this, basic.getName(), getType(
basic.getName() ) );
+ members.add( attribute );
+ }
+
+ for ( ManyToOne manyToOne : attributes.getManyToOne() ) {
+ attribute = new XmlMetaSingleAttribute( this, manyToOne.getName(), getType(
manyToOne.getName() ) );
+ members.add( attribute );
+ }
+
+ XmlMetaCollection metaCollection;
+ for ( OneToMany oneToMany : attributes.getOneToMany() ) {
+ String[] types = getCollectionType( oneToMany.getName() );
+ metaCollection = new XmlMetaCollection( this, oneToMany.getName(), types[0], types[1]
);
+ members.add( metaCollection );
+ }
+
+ for ( ElementCollection collection : attributes.getElementCollection() ) {
+ String[] types = getCollectionType( collection.getName() );
+ metaCollection = new XmlMetaCollection( this, collection.getName(), types[0], types[1]
);
+ members.add( metaCollection );
+ }
+ }
+
public String getSimpleName() {
- return ormEntity.getClazz();
+ return clazzName;
}
public String getQualifiedName() {
Show replies by date