[hibernate-commits] Hibernate SVN: r17075 - in jpamodelgen/trunk: src/main/java/org/hibernate and 8 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Jul 10 13:52:05 EDT 2009


Author: hardy.ferentschik
Date: 2009-07-10 13:52:04 -0400 (Fri, 10 Jul 2009)
New Revision: 17075

Added:
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaCollection.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaEntity.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaSingleAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ImportContext.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ImportContextImpl.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaCollection.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaEntity.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaMap.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaSingleAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaCollection.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaSingleAttribute.java
Removed:
   jpamodelgen/trunk/src/main/java/org/hibernate/jpa/
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/ClassWriter.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/Context.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaCollection.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaEntity.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaSingleAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/ImportContext.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/ImportContextImpl.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/JPAMetaModelEntityProcessor.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/TypeUtils.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaCollection.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaEntity.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaMap.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaSingleAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaAttribute.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaCollection.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaEntity.java
   jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaSingleAttribute.java
Modified:
   jpamodelgen/trunk/pom.xml
   jpamodelgen/trunk/src/main/resources/META-INF/services/javax.annotation.processing.Processor
   jpamodelgen/trunk/src/test/java/test/QueryTest.java
Log:
package name refactoring

Modified: jpamodelgen/trunk/pom.xml
===================================================================
--- jpamodelgen/trunk/pom.xml	2009-07-10 17:36:23 UTC (rev 17074)
+++ jpamodelgen/trunk/pom.xml	2009-07-10 17:52:04 UTC (rev 17075)
@@ -117,7 +117,7 @@
                     </execution>
                 </executions>
                 <configuration>
-                    <packageName>org.hibernate.jpa.metamodel.xml.jaxb</packageName>
+                    <packageName>org.hibernate.jpamodelgen.xml.jaxb</packageName>
                     <outputDirectory>${basedir}/target/generated-sources</outputDirectory>
                     <extension>true</extension>
                 </configuration>

Copied: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen (from rev 17073, jpamodelgen/trunk/src/main/java/org/hibernate/jpa)

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,123 @@
+package org.hibernate.jpamodelgen;
+
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.List;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.FilerException;
+import javax.annotation.Generated;
+import javax.tools.FileObject;
+import javax.tools.Diagnostic;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ClassWriter {
+	
+	public static void writeFile(IMetaEntity entity, ProcessingEnvironment processingEnv, Context context) {
+		try {
+			String metaModelPackage = entity.getPackageName();
+
+			StringBuffer body = generateBody( entity, context );
+
+			FileObject fo = processingEnv.getFiler().createSourceFile(
+					metaModelPackage + "." + entity.getSimpleName() + "_"
+			);
+			OutputStream os = fo.openOutputStream();
+			PrintWriter pw = new PrintWriter( os );
+
+			pw.println( "package " + metaModelPackage + ";" );
+
+			pw.println();
+
+			pw.println( entity.generateImports() );
+
+			pw.println( body );
+
+			pw.flush();
+			pw.close();
+
+		}
+		catch ( FilerException filerEx ) {
+			processingEnv.getMessager().printMessage(
+					Diagnostic.Kind.ERROR,
+					"Problem with Processing Environment Filer: "
+							+ filerEx.getMessage()
+			);
+		}
+		catch ( IOException ioEx ) {
+			processingEnv.getMessager().printMessage(
+					Diagnostic.Kind.ERROR,
+					"Problem opening file to write MetaModel for " + entity.getSimpleName()
+							+ ioEx.getMessage()
+			);
+		}
+	}
+
+	/**
+	 * Generate everything after import statements.
+	 *
+	 * @param entity The meta entity for which to write the body
+	 *
+	 * @return body content
+	 */
+	private static StringBuffer generateBody(IMetaEntity entity, Context context) {
+
+		StringWriter sw = new StringWriter();
+		PrintWriter pw = null;
+		try {
+
+			pw = new PrintWriter( sw );
+
+			pw.println( "@" + entity.importType( Generated.class.getName() ) + "(\"JPA MetaModel for " + entity.getQualifiedName() + "\")" );
+
+			pw.println( "@" + entity.importType( "javax.persistence.metamodel.StaticMetamodel" ) + "(" + entity.getSimpleName() + ".class)" );
+
+
+
+			printClassDeclaration( entity, pw, context );
+
+			pw.println();
+
+			List<IMetaAttribute> members = entity.getMembers();
+
+			for ( IMetaAttribute metaMember : members ) {
+				pw.println( "	" + metaMember.getDeclarationString() );
+			}
+			pw.println();
+			pw.println( "}" );
+			return sw.getBuffer();
+		}
+		finally {
+			if ( pw != null ) {
+				pw.close();
+			}
+		}
+	}
+
+	private static void printClassDeclaration(IMetaEntity entity, PrintWriter pw, Context context) {
+		pw.print( "public abstract class " + entity.getSimpleName() + "_" );
+
+		final TypeMirror superClass = entity.getTypeElement().getSuperclass();
+		//superclass of Object is of NoType which returns some other kind
+		String superclassDeclaration = "";
+		if (superClass.getKind() == TypeKind.DECLARED ) {
+			//F..king Ch...t Have those people used their horrible APIs even once?
+			final Element superClassElement = ( ( DeclaredType ) superClass ).asElement();
+			String superClassName = ( ( TypeElement ) superClassElement ).getQualifiedName().toString();
+			if ( context.getMetaEntitiesToProcess().containsKey( superClassName )
+					|| context.getMetaSuperclassAndEmbeddableToProcess().containsKey( superClassName ) ) {
+				pw.print( " extends " + superClassName + "_"  );
+			}
+		}
+
+		pw.println( " {" );
+	}
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,85 @@
+package org.hibernate.jpamodelgen;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import javax.lang.model.element.TypeElement;
+import javax.persistence.AccessType;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.tools.Diagnostic;
+
+import org.hibernate.jpamodelgen.annotation.MetaEntity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Context {
+	//used to cache access types
+	private Map<TypeElement, AccessTypeHolder> accessTypes = new HashMap<TypeElement, AccessTypeHolder>();
+	private Set<String> elementsAlreadyProcessed = new HashSet<String>();
+	private ProcessingEnvironment pe;
+	private final Map<String, IMetaEntity> metaEntitiesToProcess = new HashMap<String, IMetaEntity>();
+	private final Map<String, IMetaEntity> metaSuperclassAndEmbeddableToProcess = new HashMap<String, IMetaEntity>();
+
+	private static class AccessTypeHolder {
+		public AccessType elementAccessType;
+		public AccessType hierarchyAccessType;
+	}
+
+	public Context(ProcessingEnvironment pe) {
+		this.pe = pe;
+	}
+
+	public Map<String, IMetaEntity> getMetaEntitiesToProcess() {
+		return metaEntitiesToProcess;
+	}
+
+	public Map<String, IMetaEntity> getMetaSuperclassAndEmbeddableToProcess() {
+		return metaSuperclassAndEmbeddableToProcess;
+	}
+
+	public void addAccessType(TypeElement element, AccessType accessType) {
+		AccessTypeHolder typeHolder = accessTypes.get( element );
+		if ( typeHolder == null ) {
+			typeHolder = new AccessTypeHolder();
+			accessTypes.put( element, typeHolder );
+		}
+		typeHolder.elementAccessType = accessType;
+	}
+
+	public void addAccessTypeForHierarchy(TypeElement element, AccessType accessType) {
+		AccessTypeHolder typeHolder = accessTypes.get( element );
+		if ( typeHolder == null ) {
+			typeHolder = new AccessTypeHolder();
+			accessTypes.put( element, typeHolder );
+		}
+		typeHolder.hierarchyAccessType = accessType;
+	}
+
+	public AccessType getAccessType(TypeElement element) {
+		final AccessTypeHolder typeHolder = accessTypes.get( element );
+		return typeHolder != null ? typeHolder.elementAccessType : null;
+	}
+
+	public AccessType getDefaultAccessTypeForHerarchy(TypeElement element) {
+		final AccessTypeHolder typeHolder = accessTypes.get( element );
+		return typeHolder != null ? typeHolder.hierarchyAccessType : null;
+	}
+
+	public Set<String> getElementsAlreadyProcessed() {
+		return elementsAlreadyProcessed;
+	}
+
+	//only process Embeddable or Superclass
+	//does not work for Entity (risk of circularity)
+	public void processElement(TypeElement element, AccessType defaultAccessTypeForHierarchy) {
+		if ( elementsAlreadyProcessed.contains( element.getQualifiedName().toString() ) ) {
+			pe.getMessager().printMessage( Diagnostic.Kind.WARNING, "Element already processed (ignoring): " + element );
+			return;
+		}
+
+		ClassWriter.writeFile( new MetaEntity( pe, element, this, defaultAccessTypeForHierarchy ), pe, this );
+		elementsAlreadyProcessed.add( element.getQualifiedName().toString() );
+	}
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaAttribute.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,31 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface IMetaAttribute {
+    String getDeclarationString();
+
+    String getMetaType();
+
+    String getPropertyName();
+
+   String getTypeDeclaration(); 
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaCollection.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaCollection.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaCollection.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,26 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen;
+
+import org.hibernate.jpamodelgen.IMetaAttribute;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface IMetaCollection extends IMetaAttribute {
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaEntity.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaEntity.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,45 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen;
+
+import javax.lang.model.element.Name;
+import javax.lang.model.element.TypeElement;
+import java.util.List;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface IMetaEntity extends ImportContext {
+    String getSimpleName();
+
+    String getQualifiedName();
+
+    String getPackageName();
+
+    List<IMetaAttribute> getMembers();
+
+    String generateImports();
+
+    String importType(String fqcn);
+
+    String staticImport(String fqcn, String member);
+
+    String importType(Name qualifiedName);
+
+	TypeElement getTypeElement();
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaSingleAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaSingleAttribute.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/IMetaSingleAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,24 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface IMetaSingleAttribute extends IMetaAttribute {
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ImportContext.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ImportContext.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ImportContext.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,23 @@
+package org.hibernate.jpamodelgen;
+
+public interface ImportContext {
+
+	/**
+	 * Add fqcn to the import list. Returns fqcn as needed in source code.
+	 * Attempts to handle fqcn with array and generics references.
+	 * 
+	 * e.g.
+	 * java.util.Collection<org.marvel.Hulk> imports java.util.Collection and returns Collection
+	 * org.marvel.Hulk[] imports org.marvel.Hulk and returns Hulk
+	 * 
+	 * 
+	 * @param fqcn
+	 * @return import string
+	 */
+	public abstract String importType(String fqcn);
+
+	public abstract String staticImport(String fqcn, String member);
+	
+	public abstract String generateImports();
+
+}
\ No newline at end of file

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ImportContextImpl.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ImportContextImpl.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ImportContextImpl.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,162 @@
+package org.hibernate.jpamodelgen;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+
+
+public class ImportContextImpl implements ImportContext {
+
+	Set<String> imports = new TreeSet<String>();
+	Set<String> staticImports = new TreeSet<String>();
+	Map<String, String> simpleNames = new HashMap<String, String>();
+	
+	String basePackage = "";
+
+	private static final Map<String, String> PRIMITIVES = new HashMap<String, String>();
+	static {
+		PRIMITIVES.put( "char", "Character" );
+
+		PRIMITIVES.put( "byte", "Byte" );
+		PRIMITIVES.put( "short", "Short" );
+		PRIMITIVES.put( "int", "Integer" );
+		PRIMITIVES.put( "long", "Long" );
+
+		PRIMITIVES.put( "boolean", "Boolean" );
+
+		PRIMITIVES.put( "float", "Float" );
+		PRIMITIVES.put( "double", "Double" );
+
+	}
+
+	public ImportContextImpl(String basePackage) {
+		this.basePackage = basePackage;
+	}
+
+	/**
+	 * Add fqcn to the import list. Returns fqcn as needed in source code.
+	 * Attempts to handle fqcn with array and generics references.
+	 * 
+	 * e.g.
+	 * java.util.Collection<org.marvel.Hulk> imports java.util.Collection and returns Collection
+	 * org.marvel.Hulk[] imports org.marvel.Hulk and returns Hulk
+	 * 
+	 * 
+	 * @param fqcn
+	 * @return import string
+	 */
+	public String importType(String fqcn) {
+		String result = fqcn;		
+		
+		//if(fqcn==null) return "/** (null) **/"; 
+		
+		String additionalTypePart = null;
+		if(fqcn.indexOf('<')>=0) {
+			additionalTypePart = result.substring(fqcn.indexOf('<'));
+			result = result.substring(0,fqcn.indexOf('<'));
+			fqcn = result;
+		} else if(fqcn.indexOf('[')>=0) {
+			additionalTypePart = result.substring(fqcn.indexOf('['));
+			result = result.substring(0,fqcn.indexOf('['));
+			fqcn = result;
+		}
+		
+		String pureFqcn = fqcn.replace( '$', '.' );
+		
+		boolean canBeSimple = true;
+		
+		
+		String simpleName = unqualify(fqcn);
+		if(simpleNames.containsKey(simpleName)) {
+			String existingFqcn = simpleNames.get(simpleName);
+			if(existingFqcn.equals(pureFqcn)) {
+				canBeSimple = true;
+			} else {
+				canBeSimple = false;
+			}
+		} else {
+			canBeSimple = true;
+			simpleNames.put(simpleName, pureFqcn);
+			imports.add( pureFqcn );
+		}
+		
+		
+		if ( inSamePackage(fqcn) || (imports.contains( pureFqcn ) && canBeSimple) ) {
+			result = unqualify( result ); // dequalify
+		} else if ( inJavaLang( fqcn ) ) {
+			result = result.substring( "java.lang.".length() );
+		}
+
+		if(additionalTypePart!=null) {
+			result = result + additionalTypePart;
+		} 
+		
+		result = result.replace( '$', '.' );
+		return result;		
+	}
+	
+	public String staticImport(String fqcn, String member) {
+		String local = fqcn + "." + member;
+		imports.add(local);
+		staticImports.add(local);
+		
+		if(member.equals("*")) {
+			return "";
+		} else {
+			return member;
+		}
+	}
+	
+	private boolean inDefaultPackage(String className) {
+		return className.indexOf( "." ) < 0;
+	}
+
+	private boolean isPrimitive(String className) {
+		return PRIMITIVES.containsKey( className );
+	}
+
+	private boolean inSamePackage(String className) {
+		String other = qualifier( className );
+		return other == basePackage
+				|| (other != null && other.equals( basePackage ) );
+	}
+
+	private boolean inJavaLang(String className) {
+		return "java.lang".equals( qualifier( className ) );
+	}
+
+	public String generateImports() {
+		StringBuffer buf = new StringBuffer();
+		
+		for ( Iterator<String> imps = imports.iterator(); imps.hasNext(); ) {
+				String next = imps.next();
+				if(isPrimitive(next) || inDefaultPackage(next) || inJavaLang(next) || inSamePackage(next)) {
+					// dont add automatically "imported" stuff
+				} else {
+					if(staticImports.contains(next)) {
+						buf.append("import static " + next + ";\r\n");
+					} else {
+						buf.append("import " + next + ";\r\n");
+					}
+				}
+		}
+		
+		if(buf.indexOf( "$" )>=0) {
+			return buf.toString();
+		}
+		return buf.toString();            
+	}
+	
+	public static String unqualify(String qualifiedName) {
+		int loc = qualifiedName.lastIndexOf(".");
+		return ( loc < 0 ) ? qualifiedName : qualifiedName.substring( qualifiedName.lastIndexOf(".") + 1 );
+	}
+
+	public static String qualifier(String qualifiedName) {
+		int loc = qualifiedName.lastIndexOf(".");
+		return ( loc < 0 ) ? "" : qualifiedName.substring( 0, loc );
+	}
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,426 @@
+// $Id$
+package org.hibernate.jpamodelgen;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import static javax.lang.model.SourceVersion.RELEASE_6;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.Elements;
+import javax.persistence.AccessType;
+import javax.persistence.Embeddable;
+import javax.persistence.MappedSuperclass;
+import javax.tools.Diagnostic;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import org.xml.sax.SAXException;
+
+import org.hibernate.jpamodelgen.annotation.MetaEntity;
+import org.hibernate.jpamodelgen.xml.XmlMetaEntity;
+import org.hibernate.jpamodelgen.xml.jaxb.Entity;
+import org.hibernate.jpamodelgen.xml.jaxb.EntityMappings;
+import org.hibernate.jpamodelgen.xml.jaxb.ObjectFactory;
+import org.hibernate.jpamodelgen.xml.jaxb.Persistence;
+import org.hibernate.jpamodelgen.xml.jaxb.PersistenceUnitDefaults;
+import org.hibernate.jpamodelgen.xml.jaxb.PersistenceUnitMetadata;
+
+/**
+ * Main annotation processor.
+ *
+ * @author Max Andersen
+ * @author Hardy Ferentschik
+ */
+//@SupportedAnnotationTypes("javax.persistence.Entity")
+ at SupportedAnnotationTypes("*")
+ at SupportedSourceVersion(RELEASE_6)
+// TODO Extract all the XML parsing into a separate class
+public class JPAMetaModelEntityProcessor extends AbstractProcessor {
+
+	private static final String PATH_SEPARATOR = "/";
+	private static final String PERSISTENCE_XML = "/META-INF/persistence.xml";
+	private static final String ORM_XML = "/META-INF/orm.xml";
+	private static final Boolean ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS = Boolean.FALSE;
+	private static final String ENTITY_ANN = javax.persistence.Entity.class.getName();
+	private static final String MAPPED_SUPERCLASS_ANN = MappedSuperclass.class.getName();
+	private static final String EMBEDDABLE_ANN = Embeddable.class.getName();
+	private static final AccessType DEFAULT_XML_ACCESS_TYPE = AccessType.PROPERTY;
+	private static final String PERSISTENCE_XML_XSD = "persistence_2_0.xsd";
+	private static final String ORM_XSD = "orm_2_0.xsd";
+
+	private boolean xmlProcessed = false;
+	private Context context;
+
+	public void init(ProcessingEnvironment env) {
+		super.init( env );
+		context = new Context( env );
+		processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Init Processor " + this );
+	}
+
+	@Override
+	public boolean process(final Set<? extends TypeElement> annotations,
+						   final RoundEnvironment roundEnvironment) {
+
+		if ( roundEnvironment.processingOver() ) {
+			processingEnv.getMessager()
+					.printMessage( Diagnostic.Kind.NOTE, "Last processing round." );
+
+			createMetaModelClasses();
+
+			processingEnv.getMessager()
+					.printMessage( Diagnostic.Kind.NOTE, "Finished processing" );
+			return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
+		}
+
+		if ( !xmlProcessed ) {
+			parsePersistenceXml();
+		}
+
+		if ( !hostJPAAnnotations( annotations ) ) {
+			processingEnv.getMessager()
+					.printMessage( Diagnostic.Kind.NOTE, "Current processing round does not contain entities" );
+			return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
+		}
+
+		Set<? extends Element> elements = roundEnvironment.getRootElements();
+		for ( Element element : elements ) {
+			processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Processing " + element.toString() );
+			handleRootElementAnnotationMirrors( element );
+		}
+
+		return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
+	}
+
+	private void createMetaModelClasses() {
+		for ( IMetaEntity entity : context.getMetaEntitiesToProcess().values() ) {
+			processingEnv.getMessager()
+					.printMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
+			ClassWriter.writeFile( entity, processingEnv, context );
+		}
+
+		//process left over, in most cases is empty
+		for ( String className : context.getElementsAlreadyProcessed() ) {
+			context.getMetaSuperclassAndEmbeddableToProcess().remove( className );
+		}
+
+		for ( IMetaEntity entity : context.getMetaSuperclassAndEmbeddableToProcess().values() ) {
+			processingEnv.getMessager()
+					.printMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
+			ClassWriter.writeFile( entity, processingEnv, context );
+		}
+	}
+
+	private boolean hostJPAAnnotations(Set<? extends TypeElement> annotations) {
+		for ( TypeElement type : annotations ) {
+			final String typeName = type.getQualifiedName().toString();
+			if ( typeName.equals( ENTITY_ANN ) ) {
+				return true;
+			}
+			else if ( typeName.equals( EMBEDDABLE_ANN ) ) {
+				return true;
+			}
+			else if ( typeName.equals( MAPPED_SUPERCLASS_ANN ) ) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	private void parsePersistenceXml() {
+		Persistence persistence = parseXml( PERSISTENCE_XML, Persistence.class, PERSISTENCE_XML_XSD );
+		if ( persistence != null )
+		{
+			List<Persistence.PersistenceUnit> persistenceUnits = persistence.getPersistenceUnit();
+			for ( Persistence.PersistenceUnit unit : persistenceUnits ) {
+				List<String> mappingFiles = unit.getMappingFile();
+				for ( String mappingFile : mappingFiles ) {
+					parsingOrmXml( mappingFile );
+				}
+			}
+		}
+		parsingOrmXml( ORM_XML ); // /META-INF/orm.xml is implicit
+		xmlProcessed = true;
+	}
+
+	private void parsingOrmXml(String resource) {
+		EntityMappings mappings = parseXml( resource, EntityMappings.class, ORM_XSD );
+		if ( mappings == null ) {
+			return;
+		}
+
+		AccessType accessType = determineGlobalAccessType( mappings );
+
+		parseEntities( mappings, accessType );
+		parseEmbeddable( mappings, accessType );
+		parseMappedSuperClass( mappings, accessType );
+	}
+
+	private AccessType determineGlobalAccessType(EntityMappings mappings) {
+		AccessType accessType = DEFAULT_XML_ACCESS_TYPE;
+
+		if ( mappings.getAccess() != null ) {
+			accessType = mapXmlAccessTypeToJpaAccessType( mappings.getAccess() );
+			return accessType; // no need to check persistence unit default
+		}
+
+		PersistenceUnitMetadata meta = mappings.getPersistenceUnitMetadata();
+		if ( meta != null ) {
+			PersistenceUnitDefaults persistenceUnitDefaults = meta.getPersistenceUnitDefaults();
+			if ( persistenceUnitDefaults != null ) {
+				org.hibernate.jpamodelgen.xml.jaxb.AccessType xmlAccessType = persistenceUnitDefaults.getAccess();
+				if ( xmlAccessType != null ) {
+					accessType = mapXmlAccessTypeToJpaAccessType( xmlAccessType );
+				}
+			}
+		}
+		return accessType;
+	}
+
+	private AccessType mapXmlAccessTypeToJpaAccessType(org.hibernate.jpamodelgen.xml.jaxb.AccessType xmlAccessType) {
+		switch ( xmlAccessType ) {
+			case FIELD: {
+				return AccessType.FIELD;
+			}
+			case PROPERTY: {
+				return AccessType.PROPERTY;
+			}
+		}
+		return null;
+	}
+
+	private void parseEntities(EntityMappings mappings, AccessType accessType) {
+		String packageName = mappings.getPackage();
+		Collection<Entity> entities = mappings.getEntity();
+		for ( Entity entity : entities ) {
+			String fullyQualifiedClassName = packageName + "." + entity.getClazz();
+
+			if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
+				processingEnv.getMessager().printMessage(
+						Diagnostic.Kind.WARNING,
+						fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
+				);
+				continue;
+			}
+
+			XmlMetaEntity metaEntity = new XmlMetaEntity(
+					entity, packageName, getXmlMappedType( fullyQualifiedClassName )
+			);
+
+			if ( context.getMetaEntitiesToProcess().containsKey( fullyQualifiedClassName ) ) {
+				processingEnv.getMessager().printMessage(
+						Diagnostic.Kind.WARNING,
+						fullyQualifiedClassName + " was already processed once. Skipping second occurance."
+				);
+			}
+			context.getMetaEntitiesToProcess().put( fullyQualifiedClassName, metaEntity );
+		}
+	}
+
+	private boolean xmlMappedTypeExists(String fullyQualifiedClassName) {
+		Elements utils = processingEnv.getElementUtils();
+		return utils.getTypeElement( fullyQualifiedClassName ) != null;
+	}
+
+	private TypeElement getXmlMappedType(String fullyQualifiedClassName) {
+		Elements utils = processingEnv.getElementUtils();
+		return utils.getTypeElement( fullyQualifiedClassName );
+	}
+
+	private void parseEmbeddable(EntityMappings mappings, AccessType accessType) {
+		String packageName = mappings.getPackage();
+		Collection<org.hibernate.jpamodelgen.xml.jaxb.Embeddable> embeddables = mappings.getEmbeddable();
+		for ( org.hibernate.jpamodelgen.xml.jaxb.Embeddable embeddable : embeddables ) {
+			String fullyQualifiedClassName = packageName + "." + embeddable.getClazz();
+
+			if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
+				processingEnv.getMessager().printMessage(
+						Diagnostic.Kind.WARNING,
+						fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
+				);
+				continue;
+			}
+
+			XmlMetaEntity metaEntity = new XmlMetaEntity(
+					embeddable, packageName, getXmlMappedType( fullyQualifiedClassName )
+			);
+
+			if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
+				processingEnv.getMessager().printMessage(
+						Diagnostic.Kind.WARNING,
+						fullyQualifiedClassName + " was already processed once. Skipping second occurance."
+				);
+			}
+			context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
+		}
+	}
+
+	private void parseMappedSuperClass(EntityMappings mappings, AccessType accessType) {
+		String packageName = mappings.getPackage();
+		Collection<org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass> mappedSuperClasses = mappings.getMappedSuperclass();
+		for ( org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass mappedSuperClass : mappedSuperClasses ) {
+			String fullyQualifiedClassName = packageName + "." + mappedSuperClass.getClazz();
+
+			if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
+				processingEnv.getMessager().printMessage(
+						Diagnostic.Kind.WARNING,
+						fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
+				);
+				continue;
+			}
+
+			XmlMetaEntity metaEntity = new XmlMetaEntity(
+					mappedSuperClass, packageName, getXmlMappedType( fullyQualifiedClassName )
+			);
+
+			if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
+				processingEnv.getMessager().printMessage(
+						Diagnostic.Kind.WARNING,
+						fullyQualifiedClassName + " was already processed once. Skipping second occurance."
+				);
+			}
+			context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
+		}
+	}
+
+	private void handleRootElementAnnotationMirrors(final Element element) {
+
+		List<? extends AnnotationMirror> annotationMirrors = element
+				.getAnnotationMirrors();
+
+		for ( AnnotationMirror mirror : annotationMirrors ) {
+			final String annotationType = mirror.getAnnotationType().toString();
+
+			if ( element.getKind() == ElementKind.CLASS ) {
+				if ( annotationType.equals( ENTITY_ANN ) ) {
+					MetaEntity metaEntity = new MetaEntity( processingEnv, ( TypeElement ) element, context );
+					// TODO instead of just adding the entity we have to do some merging.
+					context.getMetaEntitiesToProcess().put( metaEntity.getQualifiedName(), metaEntity );
+				}
+				else if ( annotationType.equals( MAPPED_SUPERCLASS_ANN )
+						|| annotationType.equals( EMBEDDABLE_ANN ) ) {
+					MetaEntity metaEntity = new MetaEntity( processingEnv, ( TypeElement ) element, context );
+
+					// TODO instead of just adding the entity we have to do some merging.
+					context.getMetaSuperclassAndEmbeddableToProcess().put( metaEntity.getQualifiedName(), metaEntity );
+				}
+			}
+		}
+	}
+
+	private InputStream getInputStreamForResource(String resource) {
+		String pkg = getPackage( resource );
+		String name = getRelativeName( resource );
+		processingEnv.getMessager()
+				.printMessage( Diagnostic.Kind.NOTE, "Reading resource " + resource );
+		InputStream ormStream;
+		try {
+			FileObject fileObject = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
+			ormStream = fileObject.openInputStream();
+		}
+		catch ( IOException e1 ) {
+			processingEnv.getMessager()
+					.printMessage(
+							Diagnostic.Kind.WARNING,
+							"Could not load " + resource + " using processingEnv.getFiler().getResource(). Using classpath..."
+					);
+
+			// TODO
+			// unfortunately, the Filer.getResource API seems not to be able to load from /META-INF. One gets a
+			// FilerException with the message with "Illegal name /META-INF". This means that we have to revert to
+			// using the classpath. This might mean that we find a persistence.xml which is 'part of another jar.
+			// Not sure what else we can do here
+			ormStream = this.getClass().getResourceAsStream( resource );
+		}
+		return ormStream;
+	}
+
+	/**
+	 * Tries to open the specified xml file and return an instance of the specified class using JAXB.
+	 *
+	 * @param resource the xml file name
+	 * @param clazz The type of jaxb node to return
+	 * @param schemaName The schema to validate against (can be {@code null});
+	 *
+	 * @return The top level jaxb instance contained in the xml file or {@code null} in case the file could not be found.
+	 */
+	private <T> T parseXml(String resource, Class<T> clazz, String schemaName) {
+
+		InputStream stream = getInputStreamForResource( resource );
+
+		if ( stream == null ) {
+			processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, resource + " not found." );
+			return null;
+		}
+		try {
+			JAXBContext jc = JAXBContext.newInstance( ObjectFactory.class );
+			Unmarshaller unmarshaller = jc.createUnmarshaller();
+			if ( schemaName != null ) {
+				unmarshaller.setSchema( getSchema( schemaName ) );
+			}
+			return clazz.cast( unmarshaller.unmarshal( stream ) );
+		}
+		catch ( JAXBException e ) {
+			String message = "Error unmarshalling " + resource + " with exception :\n " + e;
+			processingEnv.getMessager().printMessage( Diagnostic.Kind.WARNING, message );
+			return null;
+		}
+		catch ( Exception e ) {
+			String message = "Error reading " + resource + " with exception :\n " + e;
+			processingEnv.getMessager().printMessage( Diagnostic.Kind.WARNING, message );
+			return null;
+		}
+	}
+
+	private String getPackage(String resourceName) {
+		if ( !resourceName.contains( PATH_SEPARATOR ) ) {
+			return "";
+		}
+		else {
+			return resourceName.substring( 0, resourceName.lastIndexOf( PATH_SEPARATOR ) );
+		}
+	}
+
+	private String getRelativeName(String resourceName) {
+		if ( !resourceName.contains( PATH_SEPARATOR ) ) {
+			return resourceName;
+		}
+		else {
+			return resourceName.substring( resourceName.lastIndexOf( PATH_SEPARATOR ) + 1 );
+		}
+	}
+
+	private Schema getSchema(String schemaName) {
+		Schema schema = null;
+		URL schemaUrl = this.getClass().getClassLoader().getResource( schemaName );
+		if ( schemaUrl == null ) {
+		  return schema;
+		}
+		
+		SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
+		try {
+			schema = sf.newSchema( schemaUrl );
+		}
+		catch ( SAXException e ) {
+			processingEnv.getMessager().printMessage(
+					Diagnostic.Kind.WARNING, "Unable to create schema for " + schemaName + ": " + e.getMessage()
+			);
+		}
+		return schema;
+	}
+}


Property changes on: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,51 @@
+package org.hibernate.jpamodelgen;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.Element;
+
+public class TypeUtils {
+
+	private static final Map<String, String> PRIMITIVES = new HashMap<String, String>();
+	static {
+		PRIMITIVES.put( "char", "Character" );
+
+		PRIMITIVES.put( "byte", "Byte" );
+		PRIMITIVES.put( "short", "Short" );
+		PRIMITIVES.put( "int", "Integer" );
+		PRIMITIVES.put( "long", "Long" );
+
+		PRIMITIVES.put( "boolean", "Boolean" );
+
+		PRIMITIVES.put( "float", "Float" );
+		PRIMITIVES.put( "double", "Double" );
+
+	}
+	
+	static public String toTypeString(TypeMirror type) {
+		if(type.getKind().isPrimitive()) {
+			return PRIMITIVES.get(type.toString());
+		}
+	
+		return type.toString();
+	}
+
+	static public TypeElement getSuperclass(TypeElement element) {
+		final TypeMirror superClass = element.getSuperclass();
+		//superclass of Object is of NoType which returns some other kind
+		String superclassDeclaration = "";
+		if (superClass.getKind() == TypeKind.DECLARED ) {
+			//F..king Ch...t Have those people used their horrible APIs even once?
+			final Element superClassElement = ( ( DeclaredType ) superClass ).asElement();
+			return ( TypeElement ) superClassElement;
+		}
+		else {
+			return null;
+		}
+	}
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttribute.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,51 @@
+package org.hibernate.jpamodelgen.annotation;
+
+import org.hibernate.jpamodelgen.IMetaAttribute;
+
+import java.beans.Introspector;
+
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+
+public abstract class MetaAttribute implements IMetaAttribute {
+
+	final protected Element element;
+	final protected MetaEntity parent;
+	final protected ProcessingEnvironment pe;
+	private final String type;
+
+	public MetaAttribute(MetaEntity parent, Element element, String type) {
+		this.element = element;
+		this.parent = parent;
+		this.type = type;
+		this.pe = parent.pe;
+	}
+
+	public String getDeclarationString() {
+		return "public static volatile " + parent.importType(getMetaType()) + "<" + parent.importType(parent.getQualifiedName()) + ", " + parent.importType(getTypeDeclaration()) + "> " + getPropertyName() + ";";  
+	}
+
+	public String getPropertyName() {
+		if(element.getKind()==ElementKind.FIELD) {
+			return element.getSimpleName().toString();
+		} else if (element.getKind()==ElementKind.METHOD) {
+			
+			String name = element.getSimpleName().toString();
+			if(name.startsWith("get")) {
+				return pe.getElementUtils().getName(Introspector.decapitalize(name.substring("get".length()))).toString();
+			} else if(name.startsWith("is")) {
+				return (pe.getElementUtils().getName(Introspector.decapitalize(name.substring("is".length())))).toString();
+			}
+			return pe.getElementUtils().getName(Introspector.decapitalize(name)).toString();
+		} else {
+			return pe.getElementUtils().getName(element.getSimpleName() + "/* " + element.getKind() + " */").toString();
+		}
+	}
+
+	abstract public String getMetaType();
+
+	public String getTypeDeclaration() {
+		return type;		
+	}
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaCollection.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaCollection.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaCollection.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,24 @@
+package org.hibernate.jpamodelgen.annotation;
+
+import org.hibernate.jpamodelgen.IMetaCollection;
+
+import javax.lang.model.element.Element;
+
+
+public class MetaCollection extends MetaAttribute implements IMetaCollection {
+
+	private String collectionType; 
+	
+
+	public MetaCollection(MetaEntity parent, Element element, String collectionType, String elementType) {
+		super(parent, element, elementType);
+		this.collectionType = collectionType;		
+	}
+
+	@Override
+	public String getMetaType() {		
+		return collectionType;
+	}
+
+	
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaEntity.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaEntity.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,410 @@
+package org.hibernate.jpamodelgen.annotation;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.ExecutableType;
+import javax.lang.model.type.PrimitiveType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.util.ElementFilter;
+import javax.lang.model.util.SimpleTypeVisitor6;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Id;
+import javax.persistence.AccessType;
+import javax.persistence.Entity;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Transient;
+import javax.persistence.Embedded;
+import javax.persistence.Embeddable;
+import javax.persistence.Access;
+import javax.persistence.ElementCollection;
+import javax.tools.Diagnostic.Kind;
+import javax.tools.Diagnostic;
+
+import org.hibernate.jpamodelgen.IMetaEntity;
+import org.hibernate.jpamodelgen.IMetaAttribute;
+import org.hibernate.jpamodelgen.ImportContext;
+import org.hibernate.jpamodelgen.ImportContextImpl;
+import org.hibernate.jpamodelgen.TypeUtils;
+import org.hibernate.jpamodelgen.Context;
+
+public class MetaEntity implements IMetaEntity {
+
+	final TypeElement element;
+	final protected ProcessingEnvironment pe;
+
+	final ImportContext importContext;
+	private Context context;
+	//used to propagate the access type of the root entity over to subclasses, superclasses and embeddable
+	private AccessType defaultAccessTypeForHierarchy;
+	private AccessType defaultAccessTypeForElement;
+
+	public MetaEntity(ProcessingEnvironment pe, TypeElement element, Context context) {
+		this.element = element;
+		this.pe = pe;
+		importContext = new ImportContextImpl( getPackageName() );
+		this.context = context;
+	}
+
+	public MetaEntity(ProcessingEnvironment pe, TypeElement element, Context context, AccessType accessType) {
+		this(pe, element, context);
+		this.defaultAccessTypeForHierarchy = accessType;
+	}
+
+	public String getSimpleName() {
+		return element.getSimpleName().toString();
+	}
+
+	public Element getOriginalElement() {
+		return element;
+	}
+
+	public String getQualifiedName() {
+		return element.getQualifiedName().toString();
+	}
+
+	public String getPackageName() {
+		PackageElement packageOf = pe.getElementUtils().getPackageOf( element );
+		return pe.getElementUtils().getName( packageOf.getQualifiedName() ).toString();
+	}
+
+	public List<IMetaAttribute> getMembers() {
+		List<IMetaAttribute> membersFound = new ArrayList<IMetaAttribute>();
+		final AccessType elementAccessType = getAccessTypeForElement();
+
+		List<? extends Element> fieldsOfClass = ElementFilter.fieldsIn( element.getEnclosedElements() );
+		addPersistentMembers( membersFound, elementAccessType, fieldsOfClass, AccessType.FIELD );
+
+		List<? extends Element> methodsOfClass = ElementFilter.methodsIn( element.getEnclosedElements() );
+		addPersistentMembers( membersFound, elementAccessType, methodsOfClass, AccessType.PROPERTY );
+
+		//process superclasses
+		for(TypeElement superclass = TypeUtils.getSuperclass(element) ;
+			superclass != null ;
+			superclass = TypeUtils.getSuperclass( superclass ) ) {
+			if ( superclass.getAnnotation( Entity.class ) != null ) {
+				break; //will be handled or has been handled already
+			}
+			else if ( superclass.getAnnotation( MappedSuperclass.class ) != null ) {
+				//FIXME use the class defalut access type
+				context.processElement( superclass, defaultAccessTypeForHierarchy );
+			}
+		}
+
+		//this is valid to not have properties (ie subentities)
+//		if ( membersFound.size() == 0 ) {
+//			pe.getMessager().printMessage( Kind.WARNING, "No properties found on " + element, element );
+//		}
+		return membersFound;
+	}
+
+	private void addPersistentMembers(
+			List<IMetaAttribute> membersFound,
+			AccessType elementAccessType,
+			List<? extends Element> membersOfClass,
+			AccessType membersKind) {
+		pe.getMessager()
+					.printMessage( Kind.NOTE, "Scanning " + membersOfClass.size() + " " + membersKind + " for " + element.toString() );
+		AccessType explicitAccessType;
+		if (elementAccessType == membersKind) {
+			//all membersKind considered
+			explicitAccessType = null;
+		}
+		else {
+			//use membersKind only if marked with @Access(membersKind)
+			explicitAccessType = membersKind;
+		}
+		for ( Element memberOfClass : membersOfClass ) {
+
+			MetaAttribute result = memberOfClass.asType().accept( new TypeVisitor( this, explicitAccessType ),
+					memberOfClass
+			);
+			if ( result != null ) {
+				membersFound.add( result );
+			}
+//EBE not sure why?
+//			else {
+//				pe.getMessager().printMessage( Kind.WARNING, "Could not find valid info for JPA property", mymember );
+//			}
+		}
+	}
+
+	private AccessType getAccessTypeForElement() {
+
+		//get local strategy
+		AccessType accessType = getAccessTypeForClass(element);
+		if (accessType == null) {
+			accessType = this.defaultAccessTypeForHierarchy;
+		}
+		if (accessType == null) {
+			//we dont' know
+			//if an enity go up
+			//
+			//superclasses alre always treated after their entities
+			//and their access type are discovered
+			//FIXME is it really true if only the superclass is changed
+			TypeElement superClass = element;
+			do {
+				superClass = TypeUtils.getSuperclass( superClass );
+				if (superClass != null) {
+					if ( superClass.getAnnotation( Entity.class ) != null
+							|| superClass.getAnnotation( MappedSuperclass.class ) != null ) {
+						//FIXME make it work for XML
+						AccessType superClassAccessType = getAccessTypeForClass(superClass);
+						//we've reach the root entity and resolved Ids
+						if ( superClassAccessType != null && defaultAccessTypeForHierarchy != null) {
+							break; //we've found it
+						}
+					}
+					else {
+						break; //neither @Entity nor @MappedSuperclass
+					}
+				}
+			}
+			while ( superClass != null );
+		}
+
+		if ( accessType == null ) {
+			accessType = AccessType.PROPERTY; //default to property
+			this.defaultAccessTypeForElement = accessType;
+		}
+		//this is a subclass so caching is OK
+		//this.defaultAccessTypeForHierarchy = accessType;
+		context.addAccessType( this.element, accessType );
+		this.defaultAccessTypeForElement = accessType;
+		return accessType;
+	}
+
+	private AccessType getAccessTypeForClass(TypeElement searchedElement) {
+		pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "check class" + searchedElement );
+		AccessType accessType = context.getAccessType( searchedElement );
+
+		if (defaultAccessTypeForHierarchy == null) {
+			this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy( searchedElement );
+		}
+		if ( accessType != null ) {
+			pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "Found in cache" + searchedElement + ":" + accessType );
+			return accessType;
+		}
+
+		/**
+		 * when forcing access type, we can only override the defaultAccessTypeForHierarchy
+		 * if we are the entity root (identified by having @Id or @EmbeddedId
+		 */
+		final Access accessAnn = searchedElement.getAnnotation( Access.class );
+		AccessType forcedAccessType = accessAnn != null ? accessAnn.value() : null;
+		if ( forcedAccessType != null) {
+			pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + forcedAccessType );
+			context.addAccessType( searchedElement, forcedAccessType );
+		}
+
+		//continue nevertheless to check if we are root and if defaultAccessTypeForHierarchy
+		//should be overridden
+		if ( forcedAccessType == null || defaultAccessTypeForHierarchy == null) {
+			List<? extends Element> myMembers = searchedElement.getEnclosedElements();
+			for ( Element subElement : myMembers ) {
+				List<? extends AnnotationMirror> entityAnnotations =
+						pe.getElementUtils().getAllAnnotationMirrors( subElement );
+
+				for ( Object entityAnnotation : entityAnnotations ) {
+					AnnotationMirror annotationMirror = ( AnnotationMirror ) entityAnnotation;
+
+					final String annotationType = annotationMirror.getAnnotationType().toString();
+
+					//FIXME consider XML
+					if ( annotationType.equals( Id.class.getName() )
+							|| annotationType.equals( EmbeddedId.class.getName() ) ) {
+						pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "Found id on" + searchedElement );
+						final ElementKind kind = subElement.getKind();
+						if ( kind == ElementKind.FIELD || kind == ElementKind.METHOD ) {
+							accessType = kind == ElementKind.FIELD ? AccessType.FIELD : AccessType.PROPERTY;
+							//FIXME enlever in niveau
+							if (defaultAccessTypeForHierarchy == null) {
+								this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy( searchedElement );
+								//we've discovered the class hierarchy, let's cache it
+								if ( defaultAccessTypeForHierarchy == null ) {
+									this.defaultAccessTypeForHierarchy = accessType;
+									context.addAccessTypeForHierarchy( searchedElement, defaultAccessTypeForHierarchy );
+									//FIXME should we add
+									//context.addAccessTypeForHierarchy( element, defaultAccessTypeForHierarchy );
+								}
+							}
+							if ( forcedAccessType == null) {
+								context.addAccessType( searchedElement, accessType );
+								pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + accessType );
+								return accessType;
+							}
+							else {
+								return forcedAccessType;
+							}
+						}
+					}
+				}
+			}
+		}
+		return forcedAccessType;
+	}
+
+	@Override
+	public String toString() {
+		final StringBuilder sb = new StringBuilder();
+		sb.append( "MetaEntity" );
+		sb.append( "{element=" ).append( element );
+		sb.append( '}' );
+		return sb.toString();
+	}
+
+	static Map<String, String> COLLECTIONS = new HashMap<String, String>();
+
+	static {
+		COLLECTIONS.put( "java.util.Collection", "javax.persistence.metamodel.CollectionAttribute" );
+		COLLECTIONS.put( "java.util.Set", "javax.persistence.metamodel.SetAttribute" );
+		COLLECTIONS.put( "java.util.List", "javax.persistence.metamodel.ListAttribute" );
+		COLLECTIONS.put( "java.util.Map", "javax.persistence.metamodel.MapAttribute" );
+	}
+
+	class TypeVisitor extends SimpleTypeVisitor6<MetaAttribute, Element> {
+
+		MetaEntity parent;
+		//if null, process all members as implicit
+		//if not null, only process members marked as @Access(explicitAccessType)
+		private AccessType explicitAccessType;
+
+		TypeVisitor(MetaEntity parent, AccessType explicitAccessType) {
+			this.parent = parent;
+			this.explicitAccessType = explicitAccessType;
+		}
+
+		@Override
+		protected MetaAttribute defaultAction(TypeMirror e, Element p) {
+			return super.defaultAction( e, p );
+		}
+
+		@Override
+		public MetaAttribute visitPrimitive(PrimitiveType t, Element element) {
+			if ( isPersistent( element ) ) {
+				return new MetaSingleAttribute( parent, element, TypeUtils.toTypeString( t ) );
+			}
+			else {
+				return null;
+			}
+		}
+
+		private boolean isPersistent(Element element) {
+			//FIXME consider XML
+			boolean correctAccessType = false;
+			if (this.explicitAccessType == null) {
+				correctAccessType = true;
+			}
+			else {
+				final Access accessAnn = element.getAnnotation( Access.class );
+				if ( accessAnn != null && explicitAccessType.equals( accessAnn.value() ) ) {
+					correctAccessType = true;
+				}
+			}
+			return correctAccessType
+					&& element.getAnnotation( Transient.class ) == null
+					&& !element.getModifiers().contains( Modifier.TRANSIENT )
+					&& !element.getModifiers().contains( Modifier.STATIC );
+
+		}
+
+
+		@Override
+		public MetaAttribute visitDeclared(DeclaredType t, Element element) {
+			//FIXME consider XML
+			if ( isPersistent( element ) ) {
+				TypeElement returnedElement = ( TypeElement ) pe.getTypeUtils().asElement( t );
+				String collection = COLLECTIONS.get( returnedElement.getQualifiedName().toString() ); // WARNING: .toString() is necessary here since Name equals does not compare to String
+
+				if ( collection != null ) {
+					//collection of element
+					if ( element.getAnnotation( ElementCollection.class ) != null ) {
+						final TypeMirror collectionType = t.getTypeArguments().get( 0 );
+						final TypeElement collectionElement = ( TypeElement ) pe.getTypeUtils().asElement( collectionType );
+						this.parent.context.processElement( collectionElement,
+								this.parent.defaultAccessTypeForElement );
+					}
+					if ( collection.equals( "javax.persistence.metamodel.MapAttribute" ) ) {
+						return new MetaMap( parent, element, collection, getKeyType( t ), getElementType( t ) );
+					}
+					else {
+						return new MetaCollection( parent, element, collection, getElementType( t ) );
+					}
+				}
+				else {
+					//FIXME Consider XML
+					if ( element.getAnnotation( Embedded.class ) != null
+							|| returnedElement.getAnnotation( Embeddable.class ) != null ) {
+						this.parent.context.processElement( returnedElement, 
+								this.parent.defaultAccessTypeForElement );
+					}
+					return new MetaSingleAttribute( parent, element, returnedElement.getQualifiedName().toString() );
+				}
+			}
+			else {
+				return null;
+			}
+		}
+
+
+		@Override
+		public MetaAttribute visitExecutable(ExecutableType t, Element p) {
+			String string = p.getSimpleName().toString();
+
+			// TODO: implement proper property get/is/boolean detection
+			if ( string.startsWith( "get" ) || string.startsWith( "is" ) ) {
+				TypeMirror returnType = t.getReturnType();
+
+				return returnType.accept( this, p );
+			}
+			else {
+				return null;
+			}
+		}
+	}
+
+	public String generateImports() {
+		return importContext.generateImports();
+	}
+
+	public String importType(String fqcn) {
+		return importContext.importType( fqcn );
+	}
+
+	public String staticImport(String fqcn, String member) {
+		return importContext.staticImport( fqcn, member );
+	}
+
+	public String importType(Name qualifiedName) {
+		return importType( qualifiedName.toString() );
+	}
+
+	public TypeElement getTypeElement() {
+		return element;
+	}
+
+	private String getKeyType(DeclaredType t) {
+		return t.getTypeArguments().get( 0 ).toString();
+	}
+
+
+	private String getElementType(DeclaredType declaredType) {
+		if ( declaredType.getTypeArguments().size() == 1 ) {
+			return declaredType.getTypeArguments().get( 0 ).toString();
+		}
+		else {
+			return declaredType.getTypeArguments().get( 1 ).toString();
+		}
+	}
+}


Property changes on: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaEntity.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaMap.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaMap.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaMap.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,19 @@
+package org.hibernate.jpamodelgen.annotation;
+
+import javax.lang.model.element.Element;
+
+public class MetaMap extends MetaCollection {
+
+	private final String keyType;
+
+	public MetaMap(MetaEntity parent, Element element, String collectionType,
+			String keyType, String elementType) {
+		super(parent, element, collectionType, elementType);
+		this.keyType = keyType;		
+	}
+	
+	public String getDeclarationString() {
+		return "public static volatile " + parent.importType(getMetaType()) + "<" + parent.importType(parent.getQualifiedName()) + ", " + parent.importType(keyType) + ", " + parent.importType(getTypeDeclaration()) + "> " + getPropertyName() + ";";  
+	}
+
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaSingleAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaSingleAttribute.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/MetaSingleAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,18 @@
+package org.hibernate.jpamodelgen.annotation;
+
+import org.hibernate.jpamodelgen.IMetaSingleAttribute;
+
+import javax.lang.model.element.Element;
+
+public class MetaSingleAttribute extends MetaAttribute implements IMetaSingleAttribute {
+
+	public MetaSingleAttribute(MetaEntity parent, Element element, String type) {
+		super(parent, element, type);
+	}
+
+	@Override
+	public String getMetaType() {
+		return "javax.persistence.metamodel.SingularAttribute";
+	}
+
+}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/ClassWriter.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/ClassWriter.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/ClassWriter.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,123 +0,0 @@
-package org.hibernate.jpa.metamodel.ap;
-
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.List;
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.annotation.processing.FilerException;
-import javax.annotation.Generated;
-import javax.tools.FileObject;
-import javax.tools.Diagnostic;
-import javax.lang.model.type.TypeMirror;
-import javax.lang.model.type.TypeKind;
-import javax.lang.model.type.DeclaredType;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.TypeElement;
-
-/**
- * @author Emmanuel Bernard
- */
-public class ClassWriter {
-	
-	public static void writeFile(IMetaEntity entity, ProcessingEnvironment processingEnv, Context context) {
-		try {
-			String metaModelPackage = entity.getPackageName();
-
-			StringBuffer body = generateBody( entity, context );
-
-			FileObject fo = processingEnv.getFiler().createSourceFile(
-					metaModelPackage + "." + entity.getSimpleName() + "_"
-			);
-			OutputStream os = fo.openOutputStream();
-			PrintWriter pw = new PrintWriter( os );
-
-			pw.println( "package " + metaModelPackage + ";" );
-
-			pw.println();
-
-			pw.println( entity.generateImports() );
-
-			pw.println( body );
-
-			pw.flush();
-			pw.close();
-
-		}
-		catch ( FilerException filerEx ) {
-			processingEnv.getMessager().printMessage(
-					Diagnostic.Kind.ERROR,
-					"Problem with Processing Environment Filer: "
-							+ filerEx.getMessage()
-			);
-		}
-		catch ( IOException ioEx ) {
-			processingEnv.getMessager().printMessage(
-					Diagnostic.Kind.ERROR,
-					"Problem opening file to write MetaModel for " + entity.getSimpleName()
-							+ ioEx.getMessage()
-			);
-		}
-	}
-
-	/**
-	 * Generate everything after import statements.
-	 *
-	 * @param entity The meta entity for which to write the body
-	 *
-	 * @return body content
-	 */
-	private static StringBuffer generateBody(IMetaEntity entity, Context context) {
-
-		StringWriter sw = new StringWriter();
-		PrintWriter pw = null;
-		try {
-
-			pw = new PrintWriter( sw );
-
-			pw.println( "@" + entity.importType( Generated.class.getName() ) + "(\"JPA MetaModel for " + entity.getQualifiedName() + "\")" );
-
-			pw.println( "@" + entity.importType( "javax.persistence.metamodel.StaticMetamodel" ) + "(" + entity.getSimpleName() + ".class)" );
-
-
-
-			printClassDeclaration( entity, pw, context );
-
-			pw.println();
-
-			List<IMetaAttribute> members = entity.getMembers();
-
-			for ( IMetaAttribute metaMember : members ) {
-				pw.println( "	" + metaMember.getDeclarationString() );
-			}
-			pw.println();
-			pw.println( "}" );
-			return sw.getBuffer();
-		}
-		finally {
-			if ( pw != null ) {
-				pw.close();
-			}
-		}
-	}
-
-	private static void printClassDeclaration(IMetaEntity entity, PrintWriter pw, Context context) {
-		pw.print( "public abstract class " + entity.getSimpleName() + "_" );
-
-		final TypeMirror superClass = entity.getTypeElement().getSuperclass();
-		//superclass of Object is of NoType which returns some other kind
-		String superclassDeclaration = "";
-		if (superClass.getKind() == TypeKind.DECLARED ) {
-			//F..king Ch...t Have those people used their horrible APIs even once?
-			final Element superClassElement = ( ( DeclaredType ) superClass ).asElement();
-			String superClassName = ( ( TypeElement ) superClassElement ).getQualifiedName().toString();
-			if ( context.getMetaEntitiesToProcess().containsKey( superClassName )
-					|| context.getMetaSuperclassAndEmbeddableToProcess().containsKey( superClassName ) ) {
-				pw.print( " extends " + superClassName + "_"  );
-			}
-		}
-
-		pw.println( " {" );
-	}
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/Context.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/Context.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/Context.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,85 +0,0 @@
-package org.hibernate.jpa.metamodel.ap;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.HashSet;
-import javax.lang.model.element.TypeElement;
-import javax.persistence.AccessType;
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.tools.Diagnostic;
-
-import org.hibernate.jpa.metamodel.ap.annotation.MetaEntity;
-
-/**
- * @author Emmanuel Bernard
- */
-public class Context {
-	//used to cache access types
-	private Map<TypeElement, AccessTypeHolder> accessTypes = new HashMap<TypeElement, AccessTypeHolder>();
-	private Set<String> elementsAlreadyProcessed = new HashSet<String>();
-	private ProcessingEnvironment pe;
-	private final Map<String, IMetaEntity> metaEntitiesToProcess = new HashMap<String, IMetaEntity>();
-	private final Map<String, IMetaEntity> metaSuperclassAndEmbeddableToProcess = new HashMap<String, IMetaEntity>();
-
-	private static class AccessTypeHolder {
-		public AccessType elementAccessType;
-		public AccessType hierarchyAccessType;
-	}
-
-	public Context(ProcessingEnvironment pe) {
-		this.pe = pe;
-	}
-
-	public Map<String, IMetaEntity> getMetaEntitiesToProcess() {
-		return metaEntitiesToProcess;
-	}
-
-	public Map<String, IMetaEntity> getMetaSuperclassAndEmbeddableToProcess() {
-		return metaSuperclassAndEmbeddableToProcess;
-	}
-
-	public void addAccessType(TypeElement element, AccessType accessType) {
-		AccessTypeHolder typeHolder = accessTypes.get( element );
-		if ( typeHolder == null ) {
-			typeHolder = new AccessTypeHolder();
-			accessTypes.put( element, typeHolder );
-		}
-		typeHolder.elementAccessType = accessType;
-	}
-
-	public void addAccessTypeForHierarchy(TypeElement element, AccessType accessType) {
-		AccessTypeHolder typeHolder = accessTypes.get( element );
-		if ( typeHolder == null ) {
-			typeHolder = new AccessTypeHolder();
-			accessTypes.put( element, typeHolder );
-		}
-		typeHolder.hierarchyAccessType = accessType;
-	}
-
-	public AccessType getAccessType(TypeElement element) {
-		final AccessTypeHolder typeHolder = accessTypes.get( element );
-		return typeHolder != null ? typeHolder.elementAccessType : null;
-	}
-
-	public AccessType getDefaultAccessTypeForHerarchy(TypeElement element) {
-		final AccessTypeHolder typeHolder = accessTypes.get( element );
-		return typeHolder != null ? typeHolder.hierarchyAccessType : null;
-	}
-
-	public Set<String> getElementsAlreadyProcessed() {
-		return elementsAlreadyProcessed;
-	}
-
-	//only process Embeddable or Superclass
-	//does not work for Entity (risk of circularity)
-	public void processElement(TypeElement element, AccessType defaultAccessTypeForHierarchy) {
-		if ( elementsAlreadyProcessed.contains( element.getQualifiedName().toString() ) ) {
-			pe.getMessager().printMessage( Diagnostic.Kind.WARNING, "Element already processed (ignoring): " + element );
-			return;
-		}
-
-		ClassWriter.writeFile( new MetaEntity( pe, element, this, defaultAccessTypeForHierarchy ), pe, this );
-		elementsAlreadyProcessed.add( element.getQualifiedName().toString() );
-	}
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/IMetaAttribute.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,31 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.jpa.metamodel.ap;
-
-/**
- * @author Hardy Ferentschik
- */
-public interface IMetaAttribute {
-    String getDeclarationString();
-
-    String getMetaType();
-
-    String getPropertyName();
-
-   String getTypeDeclaration(); 
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaCollection.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/IMetaCollection.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaCollection.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,26 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.jpa.metamodel.ap;
-
-import org.hibernate.jpa.metamodel.ap.IMetaAttribute;
-
-/**
- * @author Hardy Ferentschik
- */
-public interface IMetaCollection extends IMetaAttribute {
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/IMetaEntity.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaEntity.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,45 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.jpa.metamodel.ap;
-
-import javax.lang.model.element.Name;
-import javax.lang.model.element.TypeElement;
-import java.util.List;
-
-/**
- * @author Hardy Ferentschik
- */
-public interface IMetaEntity extends ImportContext {
-    String getSimpleName();
-
-    String getQualifiedName();
-
-    String getPackageName();
-
-    List<IMetaAttribute> getMembers();
-
-    String generateImports();
-
-    String importType(String fqcn);
-
-    String staticImport(String fqcn, String member);
-
-    String importType(Name qualifiedName);
-
-	TypeElement getTypeElement();
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaSingleAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/IMetaSingleAttribute.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/IMetaSingleAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,24 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.jpa.metamodel.ap;
-
-/**
- * @author Hardy Ferentschik
- */
-public interface IMetaSingleAttribute extends IMetaAttribute {
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/ImportContext.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/ImportContext.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/ImportContext.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,23 +0,0 @@
-package org.hibernate.jpa.metamodel.ap;
-
-public interface ImportContext {
-
-	/**
-	 * Add fqcn to the import list. Returns fqcn as needed in source code.
-	 * Attempts to handle fqcn with array and generics references.
-	 * 
-	 * e.g.
-	 * java.util.Collection<org.marvel.Hulk> imports java.util.Collection and returns Collection
-	 * org.marvel.Hulk[] imports org.marvel.Hulk and returns Hulk
-	 * 
-	 * 
-	 * @param fqcn
-	 * @return import string
-	 */
-	public abstract String importType(String fqcn);
-
-	public abstract String staticImport(String fqcn, String member);
-	
-	public abstract String generateImports();
-
-}
\ No newline at end of file

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/ImportContextImpl.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/ImportContextImpl.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/ImportContextImpl.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,162 +0,0 @@
-package org.hibernate.jpa.metamodel.ap;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-
-
-public class ImportContextImpl implements ImportContext {
-
-	Set<String> imports = new TreeSet<String>();
-	Set<String> staticImports = new TreeSet<String>();
-	Map<String, String> simpleNames = new HashMap<String, String>();
-	
-	String basePackage = "";
-
-	private static final Map<String, String> PRIMITIVES = new HashMap<String, String>();
-	static {
-		PRIMITIVES.put( "char", "Character" );
-
-		PRIMITIVES.put( "byte", "Byte" );
-		PRIMITIVES.put( "short", "Short" );
-		PRIMITIVES.put( "int", "Integer" );
-		PRIMITIVES.put( "long", "Long" );
-
-		PRIMITIVES.put( "boolean", "Boolean" );
-
-		PRIMITIVES.put( "float", "Float" );
-		PRIMITIVES.put( "double", "Double" );
-
-	}
-
-	public ImportContextImpl(String basePackage) {
-		this.basePackage = basePackage;
-	}
-
-	/**
-	 * Add fqcn to the import list. Returns fqcn as needed in source code.
-	 * Attempts to handle fqcn with array and generics references.
-	 * 
-	 * e.g.
-	 * java.util.Collection<org.marvel.Hulk> imports java.util.Collection and returns Collection
-	 * org.marvel.Hulk[] imports org.marvel.Hulk and returns Hulk
-	 * 
-	 * 
-	 * @param fqcn
-	 * @return import string
-	 */
-	public String importType(String fqcn) {
-		String result = fqcn;		
-		
-		//if(fqcn==null) return "/** (null) **/"; 
-		
-		String additionalTypePart = null;
-		if(fqcn.indexOf('<')>=0) {
-			additionalTypePart = result.substring(fqcn.indexOf('<'));
-			result = result.substring(0,fqcn.indexOf('<'));
-			fqcn = result;
-		} else if(fqcn.indexOf('[')>=0) {
-			additionalTypePart = result.substring(fqcn.indexOf('['));
-			result = result.substring(0,fqcn.indexOf('['));
-			fqcn = result;
-		}
-		
-		String pureFqcn = fqcn.replace( '$', '.' );
-		
-		boolean canBeSimple = true;
-		
-		
-		String simpleName = unqualify(fqcn);
-		if(simpleNames.containsKey(simpleName)) {
-			String existingFqcn = simpleNames.get(simpleName);
-			if(existingFqcn.equals(pureFqcn)) {
-				canBeSimple = true;
-			} else {
-				canBeSimple = false;
-			}
-		} else {
-			canBeSimple = true;
-			simpleNames.put(simpleName, pureFqcn);
-			imports.add( pureFqcn );
-		}
-		
-		
-		if ( inSamePackage(fqcn) || (imports.contains( pureFqcn ) && canBeSimple) ) {
-			result = unqualify( result ); // dequalify
-		} else if ( inJavaLang( fqcn ) ) {
-			result = result.substring( "java.lang.".length() );
-		}
-
-		if(additionalTypePart!=null) {
-			result = result + additionalTypePart;
-		} 
-		
-		result = result.replace( '$', '.' );
-		return result;		
-	}
-	
-	public String staticImport(String fqcn, String member) {
-		String local = fqcn + "." + member;
-		imports.add(local);
-		staticImports.add(local);
-		
-		if(member.equals("*")) {
-			return "";
-		} else {
-			return member;
-		}
-	}
-	
-	private boolean inDefaultPackage(String className) {
-		return className.indexOf( "." ) < 0;
-	}
-
-	private boolean isPrimitive(String className) {
-		return PRIMITIVES.containsKey( className );
-	}
-
-	private boolean inSamePackage(String className) {
-		String other = qualifier( className );
-		return other == basePackage
-				|| (other != null && other.equals( basePackage ) );
-	}
-
-	private boolean inJavaLang(String className) {
-		return "java.lang".equals( qualifier( className ) );
-	}
-
-	public String generateImports() {
-		StringBuffer buf = new StringBuffer();
-		
-		for ( Iterator<String> imps = imports.iterator(); imps.hasNext(); ) {
-				String next = imps.next();
-				if(isPrimitive(next) || inDefaultPackage(next) || inJavaLang(next) || inSamePackage(next)) {
-					// dont add automatically "imported" stuff
-				} else {
-					if(staticImports.contains(next)) {
-						buf.append("import static " + next + ";\r\n");
-					} else {
-						buf.append("import " + next + ";\r\n");
-					}
-				}
-		}
-		
-		if(buf.indexOf( "$" )>=0) {
-			return buf.toString();
-		}
-		return buf.toString();            
-	}
-	
-	public static String unqualify(String qualifiedName) {
-		int loc = qualifiedName.lastIndexOf(".");
-		return ( loc < 0 ) ? qualifiedName : qualifiedName.substring( qualifiedName.lastIndexOf(".") + 1 );
-	}
-
-	public static String qualifier(String qualifiedName) {
-		int loc = qualifiedName.lastIndexOf(".");
-		return ( loc < 0 ) ? "" : qualifiedName.substring( 0, loc );
-	}
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/JPAMetaModelEntityProcessor.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,426 +0,0 @@
-// $Id$
-package org.hibernate.jpa.metamodel.ap;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import javax.annotation.processing.AbstractProcessor;
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.annotation.processing.SupportedSourceVersion;
-import static javax.lang.model.SourceVersion.RELEASE_6;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.util.Elements;
-import javax.persistence.AccessType;
-import javax.persistence.Embeddable;
-import javax.persistence.MappedSuperclass;
-import javax.tools.Diagnostic;
-import javax.tools.FileObject;
-import javax.tools.StandardLocation;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-
-import org.xml.sax.SAXException;
-
-import org.hibernate.jpa.metamodel.ap.annotation.MetaEntity;
-import org.hibernate.jpa.metamodel.ap.xml.XmlMetaEntity;
-import org.hibernate.jpa.metamodel.xml.jaxb.Entity;
-import org.hibernate.jpa.metamodel.xml.jaxb.EntityMappings;
-import org.hibernate.jpa.metamodel.xml.jaxb.ObjectFactory;
-import org.hibernate.jpa.metamodel.xml.jaxb.Persistence;
-import org.hibernate.jpa.metamodel.xml.jaxb.PersistenceUnitDefaults;
-import org.hibernate.jpa.metamodel.xml.jaxb.PersistenceUnitMetadata;
-
-/**
- * Main annotation processor.
- *
- * @author Max Andersen
- * @author Hardy Ferentschik
- */
-//@SupportedAnnotationTypes("javax.persistence.Entity")
- at SupportedAnnotationTypes("*")
- at SupportedSourceVersion(RELEASE_6)
-// TODO Extract all the XML parsing into a separate class
-public class JPAMetaModelEntityProcessor extends AbstractProcessor {
-
-	private static final String PATH_SEPARATOR = "/";
-	private static final String PERSISTENCE_XML = "/META-INF/persistence.xml";
-	private static final String ORM_XML = "/META-INF/orm.xml";
-	private static final Boolean ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS = Boolean.FALSE;
-	private static final String ENTITY_ANN = javax.persistence.Entity.class.getName();
-	private static final String MAPPED_SUPERCLASS_ANN = MappedSuperclass.class.getName();
-	private static final String EMBEDDABLE_ANN = Embeddable.class.getName();
-	private static final AccessType DEFAULT_XML_ACCESS_TYPE = AccessType.PROPERTY;
-	private static final String PERSISTENCE_XML_XSD = "persistence_2_0.xsd";
-	private static final String ORM_XSD = "orm_2_0.xsd";
-
-	private boolean xmlProcessed = false;
-	private Context context;
-
-	public void init(ProcessingEnvironment env) {
-		super.init( env );
-		context = new Context( env );
-		processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Init Processor " + this );
-	}
-
-	@Override
-	public boolean process(final Set<? extends TypeElement> annotations,
-						   final RoundEnvironment roundEnvironment) {
-
-		if ( roundEnvironment.processingOver() ) {
-			processingEnv.getMessager()
-					.printMessage( Diagnostic.Kind.NOTE, "Last processing round." );
-
-			createMetaModelClasses();
-
-			processingEnv.getMessager()
-					.printMessage( Diagnostic.Kind.NOTE, "Finished processing" );
-			return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
-		}
-
-		if ( !xmlProcessed ) {
-			parsePersistenceXml();
-		}
-
-		if ( !hostJPAAnnotations( annotations ) ) {
-			processingEnv.getMessager()
-					.printMessage( Diagnostic.Kind.NOTE, "Current processing round does not contain entities" );
-			return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
-		}
-
-		Set<? extends Element> elements = roundEnvironment.getRootElements();
-		for ( Element element : elements ) {
-			processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Processing " + element.toString() );
-			handleRootElementAnnotationMirrors( element );
-		}
-
-		return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
-	}
-
-	private void createMetaModelClasses() {
-		for ( IMetaEntity entity : context.getMetaEntitiesToProcess().values() ) {
-			processingEnv.getMessager()
-					.printMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
-			ClassWriter.writeFile( entity, processingEnv, context );
-		}
-
-		//process left over, in most cases is empty
-		for ( String className : context.getElementsAlreadyProcessed() ) {
-			context.getMetaSuperclassAndEmbeddableToProcess().remove( className );
-		}
-
-		for ( IMetaEntity entity : context.getMetaSuperclassAndEmbeddableToProcess().values() ) {
-			processingEnv.getMessager()
-					.printMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
-			ClassWriter.writeFile( entity, processingEnv, context );
-		}
-	}
-
-	private boolean hostJPAAnnotations(Set<? extends TypeElement> annotations) {
-		for ( TypeElement type : annotations ) {
-			final String typeName = type.getQualifiedName().toString();
-			if ( typeName.equals( ENTITY_ANN ) ) {
-				return true;
-			}
-			else if ( typeName.equals( EMBEDDABLE_ANN ) ) {
-				return true;
-			}
-			else if ( typeName.equals( MAPPED_SUPERCLASS_ANN ) ) {
-				return true;
-			}
-		}
-		return false;
-	}
-
-	private void parsePersistenceXml() {
-		Persistence persistence = parseXml( PERSISTENCE_XML, Persistence.class, PERSISTENCE_XML_XSD );
-		if ( persistence != null )
-		{
-			List<Persistence.PersistenceUnit> persistenceUnits = persistence.getPersistenceUnit();
-			for ( Persistence.PersistenceUnit unit : persistenceUnits ) {
-				List<String> mappingFiles = unit.getMappingFile();
-				for ( String mappingFile : mappingFiles ) {
-					parsingOrmXml( mappingFile );
-				}
-			}
-		}
-		parsingOrmXml( ORM_XML ); // /META-INF/orm.xml is implicit
-		xmlProcessed = true;
-	}
-
-	private void parsingOrmXml(String resource) {
-		EntityMappings mappings = parseXml( resource, EntityMappings.class, ORM_XSD );
-		if ( mappings == null ) {
-			return;
-		}
-
-		AccessType accessType = determineGlobalAccessType( mappings );
-
-		parseEntities( mappings, accessType );
-		parseEmbeddable( mappings, accessType );
-		parseMappedSuperClass( mappings, accessType );
-	}
-
-	private AccessType determineGlobalAccessType(EntityMappings mappings) {
-		AccessType accessType = DEFAULT_XML_ACCESS_TYPE;
-
-		if ( mappings.getAccess() != null ) {
-			accessType = mapXmlAccessTypeToJpaAccessType( mappings.getAccess() );
-			return accessType; // no need to check persistence unit default
-		}
-
-		PersistenceUnitMetadata meta = mappings.getPersistenceUnitMetadata();
-		if ( meta != null ) {
-			PersistenceUnitDefaults persistenceUnitDefaults = meta.getPersistenceUnitDefaults();
-			if ( persistenceUnitDefaults != null ) {
-				org.hibernate.jpa.metamodel.xml.jaxb.AccessType xmlAccessType = persistenceUnitDefaults.getAccess();
-				if ( xmlAccessType != null ) {
-					accessType = mapXmlAccessTypeToJpaAccessType( xmlAccessType );
-				}
-			}
-		}
-		return accessType;
-	}
-
-	private AccessType mapXmlAccessTypeToJpaAccessType(org.hibernate.jpa.metamodel.xml.jaxb.AccessType xmlAccessType) {
-		switch ( xmlAccessType ) {
-			case FIELD: {
-				return AccessType.FIELD;
-			}
-			case PROPERTY: {
-				return AccessType.PROPERTY;
-			}
-		}
-		return null;
-	}
-
-	private void parseEntities(EntityMappings mappings, AccessType accessType) {
-		String packageName = mappings.getPackage();
-		Collection<Entity> entities = mappings.getEntity();
-		for ( Entity entity : entities ) {
-			String fullyQualifiedClassName = packageName + "." + entity.getClazz();
-
-			if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
-				processingEnv.getMessager().printMessage(
-						Diagnostic.Kind.WARNING,
-						fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
-				);
-				continue;
-			}
-
-			XmlMetaEntity metaEntity = new XmlMetaEntity(
-					entity, packageName, getXmlMappedType( fullyQualifiedClassName )
-			);
-
-			if ( context.getMetaEntitiesToProcess().containsKey( fullyQualifiedClassName ) ) {
-				processingEnv.getMessager().printMessage(
-						Diagnostic.Kind.WARNING,
-						fullyQualifiedClassName + " was already processed once. Skipping second occurance."
-				);
-			}
-			context.getMetaEntitiesToProcess().put( fullyQualifiedClassName, metaEntity );
-		}
-	}
-
-	private boolean xmlMappedTypeExists(String fullyQualifiedClassName) {
-		Elements utils = processingEnv.getElementUtils();
-		return utils.getTypeElement( fullyQualifiedClassName ) != null;
-	}
-
-	private TypeElement getXmlMappedType(String fullyQualifiedClassName) {
-		Elements utils = processingEnv.getElementUtils();
-		return utils.getTypeElement( fullyQualifiedClassName );
-	}
-
-	private void parseEmbeddable(EntityMappings mappings, AccessType accessType) {
-		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();
-
-			if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
-				processingEnv.getMessager().printMessage(
-						Diagnostic.Kind.WARNING,
-						fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
-				);
-				continue;
-			}
-
-			XmlMetaEntity metaEntity = new XmlMetaEntity(
-					embeddable, packageName, getXmlMappedType( fullyQualifiedClassName )
-			);
-
-			if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
-				processingEnv.getMessager().printMessage(
-						Diagnostic.Kind.WARNING,
-						fullyQualifiedClassName + " was already processed once. Skipping second occurance."
-				);
-			}
-			context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
-		}
-	}
-
-	private void parseMappedSuperClass(EntityMappings mappings, AccessType accessType) {
-		String packageName = mappings.getPackage();
-		Collection<org.hibernate.jpa.metamodel.xml.jaxb.MappedSuperclass> mappedSuperClasses = mappings.getMappedSuperclass();
-		for ( org.hibernate.jpa.metamodel.xml.jaxb.MappedSuperclass mappedSuperClass : mappedSuperClasses ) {
-			String fullyQualifiedClassName = packageName + "." + mappedSuperClass.getClazz();
-
-			if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
-				processingEnv.getMessager().printMessage(
-						Diagnostic.Kind.WARNING,
-						fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
-				);
-				continue;
-			}
-
-			XmlMetaEntity metaEntity = new XmlMetaEntity(
-					mappedSuperClass, packageName, getXmlMappedType( fullyQualifiedClassName )
-			);
-
-			if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
-				processingEnv.getMessager().printMessage(
-						Diagnostic.Kind.WARNING,
-						fullyQualifiedClassName + " was already processed once. Skipping second occurance."
-				);
-			}
-			context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
-		}
-	}
-
-	private void handleRootElementAnnotationMirrors(final Element element) {
-
-		List<? extends AnnotationMirror> annotationMirrors = element
-				.getAnnotationMirrors();
-
-		for ( AnnotationMirror mirror : annotationMirrors ) {
-			final String annotationType = mirror.getAnnotationType().toString();
-
-			if ( element.getKind() == ElementKind.CLASS ) {
-				if ( annotationType.equals( ENTITY_ANN ) ) {
-					MetaEntity metaEntity = new MetaEntity( processingEnv, ( TypeElement ) element, context );
-					// TODO instead of just adding the entity we have to do some merging.
-					context.getMetaEntitiesToProcess().put( metaEntity.getQualifiedName(), metaEntity );
-				}
-				else if ( annotationType.equals( MAPPED_SUPERCLASS_ANN )
-						|| annotationType.equals( EMBEDDABLE_ANN ) ) {
-					MetaEntity metaEntity = new MetaEntity( processingEnv, ( TypeElement ) element, context );
-
-					// TODO instead of just adding the entity we have to do some merging.
-					context.getMetaSuperclassAndEmbeddableToProcess().put( metaEntity.getQualifiedName(), metaEntity );
-				}
-			}
-		}
-	}
-
-	private InputStream getInputStreamForResource(String resource) {
-		String pkg = getPackage( resource );
-		String name = getRelativeName( resource );
-		processingEnv.getMessager()
-				.printMessage( Diagnostic.Kind.NOTE, "Reading resource " + resource );
-		InputStream ormStream;
-		try {
-			FileObject fileObject = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
-			ormStream = fileObject.openInputStream();
-		}
-		catch ( IOException e1 ) {
-			processingEnv.getMessager()
-					.printMessage(
-							Diagnostic.Kind.WARNING,
-							"Could not load " + resource + " using processingEnv.getFiler().getResource(). Using classpath..."
-					);
-
-			// TODO
-			// unfortunately, the Filer.getResource API seems not to be able to load from /META-INF. One gets a
-			// FilerException with the message with "Illegal name /META-INF". This means that we have to revert to
-			// using the classpath. This might mean that we find a persistence.xml which is 'part of another jar.
-			// Not sure what else we can do here
-			ormStream = this.getClass().getResourceAsStream( resource );
-		}
-		return ormStream;
-	}
-
-	/**
-	 * Tries to open the specified xml file and return an instance of the specified class using JAXB.
-	 *
-	 * @param resource the xml file name
-	 * @param clazz The type of jaxb node to return
-	 * @param schemaName The schema to validate against (can be {@code null});
-	 *
-	 * @return The top level jaxb instance contained in the xml file or {@code null} in case the file could not be found.
-	 */
-	private <T> T parseXml(String resource, Class<T> clazz, String schemaName) {
-
-		InputStream stream = getInputStreamForResource( resource );
-
-		if ( stream == null ) {
-			processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, resource + " not found." );
-			return null;
-		}
-		try {
-			JAXBContext jc = JAXBContext.newInstance( ObjectFactory.class );
-			Unmarshaller unmarshaller = jc.createUnmarshaller();
-			if ( schemaName != null ) {
-				unmarshaller.setSchema( getSchema( schemaName ) );
-			}
-			return clazz.cast( unmarshaller.unmarshal( stream ) );
-		}
-		catch ( JAXBException e ) {
-			String message = "Error unmarshalling " + resource + " with exception :\n " + e;
-			processingEnv.getMessager().printMessage( Diagnostic.Kind.WARNING, message );
-			return null;
-		}
-		catch ( Exception e ) {
-			String message = "Error reading " + resource + " with exception :\n " + e;
-			processingEnv.getMessager().printMessage( Diagnostic.Kind.WARNING, message );
-			return null;
-		}
-	}
-
-	private String getPackage(String resourceName) {
-		if ( !resourceName.contains( PATH_SEPARATOR ) ) {
-			return "";
-		}
-		else {
-			return resourceName.substring( 0, resourceName.lastIndexOf( PATH_SEPARATOR ) );
-		}
-	}
-
-	private String getRelativeName(String resourceName) {
-		if ( !resourceName.contains( PATH_SEPARATOR ) ) {
-			return resourceName;
-		}
-		else {
-			return resourceName.substring( resourceName.lastIndexOf( PATH_SEPARATOR ) + 1 );
-		}
-	}
-
-	private Schema getSchema(String schemaName) {
-		Schema schema = null;
-		URL schemaUrl = this.getClass().getClassLoader().getResource( schemaName );
-		if ( schemaUrl == null ) {
-		  return schema;
-		}
-		
-		SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
-		try {
-			schema = sf.newSchema( schemaUrl );
-		}
-		catch ( SAXException e ) {
-			processingEnv.getMessager().printMessage(
-					Diagnostic.Kind.WARNING, "Unable to create schema for " + schemaName + ": " + e.getMessage()
-			);
-		}
-		return schema;
-	}
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/TypeUtils.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/TypeUtils.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/TypeUtils.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,51 +0,0 @@
-package org.hibernate.jpa.metamodel.ap;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.lang.model.type.TypeMirror;
-import javax.lang.model.type.TypeKind;
-import javax.lang.model.type.DeclaredType;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.element.Element;
-
-public class TypeUtils {
-
-	private static final Map<String, String> PRIMITIVES = new HashMap<String, String>();
-	static {
-		PRIMITIVES.put( "char", "Character" );
-
-		PRIMITIVES.put( "byte", "Byte" );
-		PRIMITIVES.put( "short", "Short" );
-		PRIMITIVES.put( "int", "Integer" );
-		PRIMITIVES.put( "long", "Long" );
-
-		PRIMITIVES.put( "boolean", "Boolean" );
-
-		PRIMITIVES.put( "float", "Float" );
-		PRIMITIVES.put( "double", "Double" );
-
-	}
-	
-	static public String toTypeString(TypeMirror type) {
-		if(type.getKind().isPrimitive()) {
-			return PRIMITIVES.get(type.toString());
-		}
-	
-		return type.toString();
-	}
-
-	static public TypeElement getSuperclass(TypeElement element) {
-		final TypeMirror superClass = element.getSuperclass();
-		//superclass of Object is of NoType which returns some other kind
-		String superclassDeclaration = "";
-		if (superClass.getKind() == TypeKind.DECLARED ) {
-			//F..king Ch...t Have those people used their horrible APIs even once?
-			final Element superClassElement = ( ( DeclaredType ) superClass ).asElement();
-			return ( TypeElement ) superClassElement;
-		}
-		else {
-			return null;
-		}
-	}
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/annotation/MetaAttribute.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,51 +0,0 @@
-package org.hibernate.jpa.metamodel.ap.annotation;
-
-import org.hibernate.jpa.metamodel.ap.IMetaAttribute;
-
-import java.beans.Introspector;
-
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-
-public abstract class MetaAttribute implements IMetaAttribute {
-
-	final protected Element element;
-	final protected MetaEntity parent;
-	final protected ProcessingEnvironment pe;
-	private final String type;
-
-	public MetaAttribute(MetaEntity parent, Element element, String type) {
-		this.element = element;
-		this.parent = parent;
-		this.type = type;
-		this.pe = parent.pe;
-	}
-
-	public String getDeclarationString() {
-		return "public static volatile " + parent.importType(getMetaType()) + "<" + parent.importType(parent.getQualifiedName()) + ", " + parent.importType(getTypeDeclaration()) + "> " + getPropertyName() + ";";  
-	}
-
-	public String getPropertyName() {
-		if(element.getKind()==ElementKind.FIELD) {
-			return element.getSimpleName().toString();
-		} else if (element.getKind()==ElementKind.METHOD) {
-			
-			String name = element.getSimpleName().toString();
-			if(name.startsWith("get")) {
-				return pe.getElementUtils().getName(Introspector.decapitalize(name.substring("get".length()))).toString();
-			} else if(name.startsWith("is")) {
-				return (pe.getElementUtils().getName(Introspector.decapitalize(name.substring("is".length())))).toString();
-			}
-			return pe.getElementUtils().getName(Introspector.decapitalize(name)).toString();
-		} else {
-			return pe.getElementUtils().getName(element.getSimpleName() + "/* " + element.getKind() + " */").toString();
-		}
-	}
-
-	abstract public String getMetaType();
-
-	public String getTypeDeclaration() {
-		return type;		
-	}
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaCollection.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/annotation/MetaCollection.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaCollection.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,24 +0,0 @@
-package org.hibernate.jpa.metamodel.ap.annotation;
-
-import org.hibernate.jpa.metamodel.ap.IMetaCollection;
-
-import javax.lang.model.element.Element;
-
-
-public class MetaCollection extends MetaAttribute implements IMetaCollection {
-
-	private String collectionType; 
-	
-
-	public MetaCollection(MetaEntity parent, Element element, String collectionType, String elementType) {
-		super(parent, element, elementType);
-		this.collectionType = collectionType;		
-	}
-
-	@Override
-	public String getMetaType() {		
-		return collectionType;
-	}
-
-	
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/annotation/MetaEntity.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaEntity.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,410 +0,0 @@
-package org.hibernate.jpa.metamodel.ap.annotation;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.Name;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.element.Modifier;
-import javax.lang.model.type.DeclaredType;
-import javax.lang.model.type.ExecutableType;
-import javax.lang.model.type.PrimitiveType;
-import javax.lang.model.type.TypeMirror;
-import javax.lang.model.util.ElementFilter;
-import javax.lang.model.util.SimpleTypeVisitor6;
-import javax.persistence.EmbeddedId;
-import javax.persistence.Id;
-import javax.persistence.AccessType;
-import javax.persistence.Entity;
-import javax.persistence.MappedSuperclass;
-import javax.persistence.Transient;
-import javax.persistence.Embedded;
-import javax.persistence.Embeddable;
-import javax.persistence.Access;
-import javax.persistence.ElementCollection;
-import javax.tools.Diagnostic.Kind;
-import javax.tools.Diagnostic;
-
-import org.hibernate.jpa.metamodel.ap.IMetaEntity;
-import org.hibernate.jpa.metamodel.ap.IMetaAttribute;
-import org.hibernate.jpa.metamodel.ap.ImportContext;
-import org.hibernate.jpa.metamodel.ap.ImportContextImpl;
-import org.hibernate.jpa.metamodel.ap.TypeUtils;
-import org.hibernate.jpa.metamodel.ap.Context;
-
-public class MetaEntity implements IMetaEntity {
-
-	final TypeElement element;
-	final protected ProcessingEnvironment pe;
-
-	final ImportContext importContext;
-	private Context context;
-	//used to propagate the access type of the root entity over to subclasses, superclasses and embeddable
-	private AccessType defaultAccessTypeForHierarchy;
-	private AccessType defaultAccessTypeForElement;
-
-	public MetaEntity(ProcessingEnvironment pe, TypeElement element, Context context) {
-		this.element = element;
-		this.pe = pe;
-		importContext = new ImportContextImpl( getPackageName() );
-		this.context = context;
-	}
-
-	public MetaEntity(ProcessingEnvironment pe, TypeElement element, Context context, AccessType accessType) {
-		this(pe, element, context);
-		this.defaultAccessTypeForHierarchy = accessType;
-	}
-
-	public String getSimpleName() {
-		return element.getSimpleName().toString();
-	}
-
-	public Element getOriginalElement() {
-		return element;
-	}
-
-	public String getQualifiedName() {
-		return element.getQualifiedName().toString();
-	}
-
-	public String getPackageName() {
-		PackageElement packageOf = pe.getElementUtils().getPackageOf( element );
-		return pe.getElementUtils().getName( packageOf.getQualifiedName() ).toString();
-	}
-
-	public List<IMetaAttribute> getMembers() {
-		List<IMetaAttribute> membersFound = new ArrayList<IMetaAttribute>();
-		final AccessType elementAccessType = getAccessTypeForElement();
-
-		List<? extends Element> fieldsOfClass = ElementFilter.fieldsIn( element.getEnclosedElements() );
-		addPersistentMembers( membersFound, elementAccessType, fieldsOfClass, AccessType.FIELD );
-
-		List<? extends Element> methodsOfClass = ElementFilter.methodsIn( element.getEnclosedElements() );
-		addPersistentMembers( membersFound, elementAccessType, methodsOfClass, AccessType.PROPERTY );
-
-		//process superclasses
-		for(TypeElement superclass = TypeUtils.getSuperclass(element) ;
-			superclass != null ;
-			superclass = TypeUtils.getSuperclass( superclass ) ) {
-			if ( superclass.getAnnotation( Entity.class ) != null ) {
-				break; //will be handled or has been handled already
-			}
-			else if ( superclass.getAnnotation( MappedSuperclass.class ) != null ) {
-				//FIXME use the class defalut access type
-				context.processElement( superclass, defaultAccessTypeForHierarchy );
-			}
-		}
-
-		//this is valid to not have properties (ie subentities)
-//		if ( membersFound.size() == 0 ) {
-//			pe.getMessager().printMessage( Kind.WARNING, "No properties found on " + element, element );
-//		}
-		return membersFound;
-	}
-
-	private void addPersistentMembers(
-			List<IMetaAttribute> membersFound,
-			AccessType elementAccessType,
-			List<? extends Element> membersOfClass,
-			AccessType membersKind) {
-		pe.getMessager()
-					.printMessage( Kind.NOTE, "Scanning " + membersOfClass.size() + " " + membersKind + " for " + element.toString() );
-		AccessType explicitAccessType;
-		if (elementAccessType == membersKind) {
-			//all membersKind considered
-			explicitAccessType = null;
-		}
-		else {
-			//use membersKind only if marked with @Access(membersKind)
-			explicitAccessType = membersKind;
-		}
-		for ( Element memberOfClass : membersOfClass ) {
-
-			MetaAttribute result = memberOfClass.asType().accept( new TypeVisitor( this, explicitAccessType ),
-					memberOfClass
-			);
-			if ( result != null ) {
-				membersFound.add( result );
-			}
-//EBE not sure why?
-//			else {
-//				pe.getMessager().printMessage( Kind.WARNING, "Could not find valid info for JPA property", mymember );
-//			}
-		}
-	}
-
-	private AccessType getAccessTypeForElement() {
-
-		//get local strategy
-		AccessType accessType = getAccessTypeForClass(element);
-		if (accessType == null) {
-			accessType = this.defaultAccessTypeForHierarchy;
-		}
-		if (accessType == null) {
-			//we dont' know
-			//if an enity go up
-			//
-			//superclasses alre always treated after their entities
-			//and their access type are discovered
-			//FIXME is it really true if only the superclass is changed
-			TypeElement superClass = element;
-			do {
-				superClass = TypeUtils.getSuperclass( superClass );
-				if (superClass != null) {
-					if ( superClass.getAnnotation( Entity.class ) != null
-							|| superClass.getAnnotation( MappedSuperclass.class ) != null ) {
-						//FIXME make it work for XML
-						AccessType superClassAccessType = getAccessTypeForClass(superClass);
-						//we've reach the root entity and resolved Ids
-						if ( superClassAccessType != null && defaultAccessTypeForHierarchy != null) {
-							break; //we've found it
-						}
-					}
-					else {
-						break; //neither @Entity nor @MappedSuperclass
-					}
-				}
-			}
-			while ( superClass != null );
-		}
-
-		if ( accessType == null ) {
-			accessType = AccessType.PROPERTY; //default to property
-			this.defaultAccessTypeForElement = accessType;
-		}
-		//this is a subclass so caching is OK
-		//this.defaultAccessTypeForHierarchy = accessType;
-		context.addAccessType( this.element, accessType );
-		this.defaultAccessTypeForElement = accessType;
-		return accessType;
-	}
-
-	private AccessType getAccessTypeForClass(TypeElement searchedElement) {
-		pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "check class" + searchedElement );
-		AccessType accessType = context.getAccessType( searchedElement );
-
-		if (defaultAccessTypeForHierarchy == null) {
-			this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy( searchedElement );
-		}
-		if ( accessType != null ) {
-			pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "Found in cache" + searchedElement + ":" + accessType );
-			return accessType;
-		}
-
-		/**
-		 * when forcing access type, we can only override the defaultAccessTypeForHierarchy
-		 * if we are the entity root (identified by having @Id or @EmbeddedId
-		 */
-		final Access accessAnn = searchedElement.getAnnotation( Access.class );
-		AccessType forcedAccessType = accessAnn != null ? accessAnn.value() : null;
-		if ( forcedAccessType != null) {
-			pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + forcedAccessType );
-			context.addAccessType( searchedElement, forcedAccessType );
-		}
-
-		//continue nevertheless to check if we are root and if defaultAccessTypeForHierarchy
-		//should be overridden
-		if ( forcedAccessType == null || defaultAccessTypeForHierarchy == null) {
-			List<? extends Element> myMembers = searchedElement.getEnclosedElements();
-			for ( Element subElement : myMembers ) {
-				List<? extends AnnotationMirror> entityAnnotations =
-						pe.getElementUtils().getAllAnnotationMirrors( subElement );
-
-				for ( Object entityAnnotation : entityAnnotations ) {
-					AnnotationMirror annotationMirror = ( AnnotationMirror ) entityAnnotation;
-
-					final String annotationType = annotationMirror.getAnnotationType().toString();
-
-					//FIXME consider XML
-					if ( annotationType.equals( Id.class.getName() )
-							|| annotationType.equals( EmbeddedId.class.getName() ) ) {
-						pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "Found id on" + searchedElement );
-						final ElementKind kind = subElement.getKind();
-						if ( kind == ElementKind.FIELD || kind == ElementKind.METHOD ) {
-							accessType = kind == ElementKind.FIELD ? AccessType.FIELD : AccessType.PROPERTY;
-							//FIXME enlever in niveau
-							if (defaultAccessTypeForHierarchy == null) {
-								this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy( searchedElement );
-								//we've discovered the class hierarchy, let's cache it
-								if ( defaultAccessTypeForHierarchy == null ) {
-									this.defaultAccessTypeForHierarchy = accessType;
-									context.addAccessTypeForHierarchy( searchedElement, defaultAccessTypeForHierarchy );
-									//FIXME should we add
-									//context.addAccessTypeForHierarchy( element, defaultAccessTypeForHierarchy );
-								}
-							}
-							if ( forcedAccessType == null) {
-								context.addAccessType( searchedElement, accessType );
-								pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + accessType );
-								return accessType;
-							}
-							else {
-								return forcedAccessType;
-							}
-						}
-					}
-				}
-			}
-		}
-		return forcedAccessType;
-	}
-
-	@Override
-	public String toString() {
-		final StringBuilder sb = new StringBuilder();
-		sb.append( "MetaEntity" );
-		sb.append( "{element=" ).append( element );
-		sb.append( '}' );
-		return sb.toString();
-	}
-
-	static Map<String, String> COLLECTIONS = new HashMap<String, String>();
-
-	static {
-		COLLECTIONS.put( "java.util.Collection", "javax.persistence.metamodel.CollectionAttribute" );
-		COLLECTIONS.put( "java.util.Set", "javax.persistence.metamodel.SetAttribute" );
-		COLLECTIONS.put( "java.util.List", "javax.persistence.metamodel.ListAttribute" );
-		COLLECTIONS.put( "java.util.Map", "javax.persistence.metamodel.MapAttribute" );
-	}
-
-	class TypeVisitor extends SimpleTypeVisitor6<MetaAttribute, Element> {
-
-		MetaEntity parent;
-		//if null, process all members as implicit
-		//if not null, only process members marked as @Access(explicitAccessType)
-		private AccessType explicitAccessType;
-
-		TypeVisitor(MetaEntity parent, AccessType explicitAccessType) {
-			this.parent = parent;
-			this.explicitAccessType = explicitAccessType;
-		}
-
-		@Override
-		protected MetaAttribute defaultAction(TypeMirror e, Element p) {
-			return super.defaultAction( e, p );
-		}
-
-		@Override
-		public MetaAttribute visitPrimitive(PrimitiveType t, Element element) {
-			if ( isPersistent( element ) ) {
-				return new MetaSingleAttribute( parent, element, TypeUtils.toTypeString( t ) );
-			}
-			else {
-				return null;
-			}
-		}
-
-		private boolean isPersistent(Element element) {
-			//FIXME consider XML
-			boolean correctAccessType = false;
-			if (this.explicitAccessType == null) {
-				correctAccessType = true;
-			}
-			else {
-				final Access accessAnn = element.getAnnotation( Access.class );
-				if ( accessAnn != null && explicitAccessType.equals( accessAnn.value() ) ) {
-					correctAccessType = true;
-				}
-			}
-			return correctAccessType
-					&& element.getAnnotation( Transient.class ) == null
-					&& !element.getModifiers().contains( Modifier.TRANSIENT )
-					&& !element.getModifiers().contains( Modifier.STATIC );
-
-		}
-
-
-		@Override
-		public MetaAttribute visitDeclared(DeclaredType t, Element element) {
-			//FIXME consider XML
-			if ( isPersistent( element ) ) {
-				TypeElement returnedElement = ( TypeElement ) pe.getTypeUtils().asElement( t );
-				String collection = COLLECTIONS.get( returnedElement.getQualifiedName().toString() ); // WARNING: .toString() is necessary here since Name equals does not compare to String
-
-				if ( collection != null ) {
-					//collection of element
-					if ( element.getAnnotation( ElementCollection.class ) != null ) {
-						final TypeMirror collectionType = t.getTypeArguments().get( 0 );
-						final TypeElement collectionElement = ( TypeElement ) pe.getTypeUtils().asElement( collectionType );
-						this.parent.context.processElement( collectionElement,
-								this.parent.defaultAccessTypeForElement );
-					}
-					if ( collection.equals( "javax.persistence.metamodel.MapAttribute" ) ) {
-						return new MetaMap( parent, element, collection, getKeyType( t ), getElementType( t ) );
-					}
-					else {
-						return new MetaCollection( parent, element, collection, getElementType( t ) );
-					}
-				}
-				else {
-					//FIXME Consider XML
-					if ( element.getAnnotation( Embedded.class ) != null
-							|| returnedElement.getAnnotation( Embeddable.class ) != null ) {
-						this.parent.context.processElement( returnedElement, 
-								this.parent.defaultAccessTypeForElement );
-					}
-					return new MetaSingleAttribute( parent, element, returnedElement.getQualifiedName().toString() );
-				}
-			}
-			else {
-				return null;
-			}
-		}
-
-
-		@Override
-		public MetaAttribute visitExecutable(ExecutableType t, Element p) {
-			String string = p.getSimpleName().toString();
-
-			// TODO: implement proper property get/is/boolean detection
-			if ( string.startsWith( "get" ) || string.startsWith( "is" ) ) {
-				TypeMirror returnType = t.getReturnType();
-
-				return returnType.accept( this, p );
-			}
-			else {
-				return null;
-			}
-		}
-	}
-
-	public String generateImports() {
-		return importContext.generateImports();
-	}
-
-	public String importType(String fqcn) {
-		return importContext.importType( fqcn );
-	}
-
-	public String staticImport(String fqcn, String member) {
-		return importContext.staticImport( fqcn, member );
-	}
-
-	public String importType(Name qualifiedName) {
-		return importType( qualifiedName.toString() );
-	}
-
-	public TypeElement getTypeElement() {
-		return element;
-	}
-
-	private String getKeyType(DeclaredType t) {
-		return t.getTypeArguments().get( 0 ).toString();
-	}
-
-
-	private String getElementType(DeclaredType declaredType) {
-		if ( declaredType.getTypeArguments().size() == 1 ) {
-			return declaredType.getTypeArguments().get( 0 ).toString();
-		}
-		else {
-			return declaredType.getTypeArguments().get( 1 ).toString();
-		}
-	}
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaMap.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/annotation/MetaMap.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaMap.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,19 +0,0 @@
-package org.hibernate.jpa.metamodel.ap.annotation;
-
-import javax.lang.model.element.Element;
-
-public class MetaMap extends MetaCollection {
-
-	private final String keyType;
-
-	public MetaMap(MetaEntity parent, Element element, String collectionType,
-			String keyType, String elementType) {
-		super(parent, element, collectionType, elementType);
-		this.keyType = keyType;		
-	}
-	
-	public String getDeclarationString() {
-		return "public static volatile " + parent.importType(getMetaType()) + "<" + parent.importType(parent.getQualifiedName()) + ", " + parent.importType(keyType) + ", " + parent.importType(getTypeDeclaration()) + "> " + getPropertyName() + ";";  
-	}
-
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaSingleAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/annotation/MetaSingleAttribute.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/annotation/MetaSingleAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,18 +0,0 @@
-package org.hibernate.jpa.metamodel.ap.annotation;
-
-import org.hibernate.jpa.metamodel.ap.IMetaSingleAttribute;
-
-import javax.lang.model.element.Element;
-
-public class MetaSingleAttribute extends MetaAttribute implements IMetaSingleAttribute {
-
-	public MetaSingleAttribute(MetaEntity parent, Element element, String type) {
-		super(parent, element, type);
-	}
-
-	@Override
-	public String getMetaType() {
-		return "javax.persistence.metamodel.SingularAttribute";
-	}
-
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaAttribute.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,55 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.jpa.metamodel.ap.xml;
-
-import org.hibernate.jpa.metamodel.ap.IMetaAttribute;
-
-/**
- * @author Hardy Ferentschik
- */
-public abstract class XmlMetaAttribute implements IMetaAttribute {
-
-    private XmlMetaEntity parentEntity;
-
-    private String propertyName;
-
-    private String type;
-
-    XmlMetaAttribute(XmlMetaEntity parent, String propertyName, String type) {
-        this.parentEntity = parent;
-        this.propertyName = propertyName;
-        this.type = type;
-    }
-
-
-	@Override
-    public String getDeclarationString() {
-        return "public static volatile " + parentEntity.importType(getMetaType()) + "<" + parentEntity.importType(parentEntity.getQualifiedName()) + ", " + parentEntity.importType(getTypeDeclaration()) + "> " + getPropertyName() + ";";
-    }
-
-    public String getPropertyName() {
-        return propertyName;
-    }
-
-    public String getTypeDeclaration() {
-		return type;
-	}
-
-    @Override
-    abstract public String getMetaType();
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaCollection.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaCollection.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaCollection.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,38 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.jpa.metamodel.ap.xml;
-
-import org.hibernate.jpa.metamodel.ap.IMetaCollection;
-
-/**
- * @author Hardy Ferentschik
- */
-public class XmlMetaCollection extends XmlMetaAttribute implements IMetaCollection {
-
-    String collectionType;
-
-    public XmlMetaCollection(XmlMetaEntity parent, String propertyName, String type, String collectionType) {
-        super(parent, propertyName, type);
-        this.collectionType = collectionType;
-    }
-
-    @Override
-	public String getMetaType() {
-		return collectionType;
-	}
-}
\ No newline at end of file

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaEntity.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,255 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.jpa.metamodel.ap.xml;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.Name;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.type.DeclaredType;
-
-import org.hibernate.jpa.metamodel.ap.IMetaAttribute;
-import org.hibernate.jpa.metamodel.ap.IMetaEntity;
-import org.hibernate.jpa.metamodel.ap.ImportContext;
-import org.hibernate.jpa.metamodel.ap.ImportContextImpl;
-import org.hibernate.jpa.metamodel.xml.jaxb.Attributes;
-import org.hibernate.jpa.metamodel.xml.jaxb.Basic;
-import org.hibernate.jpa.metamodel.xml.jaxb.ElementCollection;
-import org.hibernate.jpa.metamodel.xml.jaxb.Embeddable;
-import org.hibernate.jpa.metamodel.xml.jaxb.EmbeddableAttributes;
-import org.hibernate.jpa.metamodel.xml.jaxb.Entity;
-import org.hibernate.jpa.metamodel.xml.jaxb.Id;
-import org.hibernate.jpa.metamodel.xml.jaxb.ManyToOne;
-import org.hibernate.jpa.metamodel.xml.jaxb.MappedSuperclass;
-import org.hibernate.jpa.metamodel.xml.jaxb.OneToMany;
-import org.hibernate.jpa.metamodel.xml.jaxb.OneToOne;
-
-/**
- * @author Hardy Ferentschik
- */
-public class XmlMetaEntity implements IMetaEntity {
-
-	static Map<String, String> COLLECTIONS = new HashMap<String, String>();
-
-	static {
-		COLLECTIONS.put( "java.util.Collection", "javax.persistence.metamodel.CollectionAttribute" );
-		COLLECTIONS.put( "java.util.Set", "javax.persistence.metamodel.SetAttribute" );
-		COLLECTIONS.put( "java.util.List", "javax.persistence.metamodel.ListAttribute" );
-		COLLECTIONS.put( "java.util.Map", "javax.persistence.metamodel.MapAttribute" );
-	}
-
-	final private String clazzName;
-
-	final private String packageName;
-
-	final private ImportContext importContext;
-
-	final private List<IMetaAttribute> members = new ArrayList<IMetaAttribute>();
-
-	private TypeElement element;
-
-	public XmlMetaEntity(Entity ormEntity, String packageName, TypeElement element) {
-		this.clazzName = ormEntity.getClazz();
-		this.packageName = packageName;
-		importContext = new ImportContextImpl( getPackageName() );
-		this.element = element;
-		Attributes attributes = ormEntity.getAttributes();
-
-		parseAttributes( attributes );
-	}
-
-	public XmlMetaEntity(MappedSuperclass mappedSuperclass, String packageName, TypeElement element) {
-		this.clazzName = mappedSuperclass.getClazz();
-		this.packageName = packageName;
-		importContext = new ImportContextImpl( getPackageName() );
-		this.element = element;
-		Attributes attributes = mappedSuperclass.getAttributes();
-
-		parseAttributes( attributes );
-	}
-
-	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 );
-		}
-
-		for ( OneToOne oneToOne : attributes.getOneToOne() ) {
-			attribute = new XmlMetaSingleAttribute( this, oneToOne.getName(), getType( oneToOne.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 clazzName;
-	}
-
-	public String getQualifiedName() {
-		return packageName + "." + getSimpleName();
-	}
-
-	public String getPackageName() {
-		return packageName;
-	}
-
-	public List<IMetaAttribute> getMembers() {
-		return members;
-	}
-
-	public String generateImports() {
-		return importContext.generateImports();
-	}
-
-	public String importType(String fqcn) {
-		return importContext.importType( fqcn );
-	}
-
-	public String staticImport(String fqcn, String member) {
-		return importContext.staticImport( fqcn, member );
-	}
-
-	public String importType(Name qualifiedName) {
-		return importType( qualifiedName.toString() );
-	}
-
-	public TypeElement getTypeElement() {
-		return element;
-	}
-
-	private String[] getCollectionType(String propertyName) {
-		String types[] = new String[2];
-		for ( Element elem : element.getEnclosedElements() ) {
-			if ( elem.getSimpleName().toString().equals( propertyName ) ) {
-				DeclaredType type = ( ( DeclaredType ) elem.asType() );
-				types[0] = type.getTypeArguments().get( 0 ).toString();
-				types[1] = COLLECTIONS.get( type.asElement().toString() );
-			}
-		}
-		return types;
-	}
-
-	private String getType(String propertyName) {
-		String typeName = null;
-		for ( Element elem : element.getEnclosedElements() ) {
-			if ( elem.getSimpleName().toString().equals( propertyName ) ) {
-				switch ( elem.asType().getKind() ) {
-					case INT: {
-						typeName = "java.lang.Integer";
-						break;
-					}
-					case LONG: {
-						typeName = "java.lang.Long";
-						break;
-					}
-					case BOOLEAN: {
-						typeName = "java.lang.Boolean";
-						break;
-					}
-					case DECLARED: {
-						typeName = elem.asType().toString();
-						break;
-					}
-					case TYPEVAR: {
-						typeName = elem.asType().toString();
-						break;
-					}
-				}
-				break;
-			}
-		}
-		return typeName;
-	}
-
-	@Override
-	public String toString() {
-		final StringBuilder sb = new StringBuilder();
-		sb.append( "XmlMetaEntity" );
-		sb.append( "{type=" ).append( element );
-		sb.append( '}' );
-		return sb.toString();
-	}
-
-	private void parseAttributes(Attributes attributes) {
-		XmlMetaSingleAttribute attribute;
-
-		if ( !attributes.getId().isEmpty() ) {
-			// TODO what do we do if there are more than one id nodes?
-			Id id = attributes.getId().get( 0 );
-			attribute = new XmlMetaSingleAttribute(
-					this, id.getName(), getType( id.getName() )
-			);
-			members.add( 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 );
-		}
-
-		for ( OneToOne oneToOne : attributes.getOneToOne() ) {
-			attribute = new XmlMetaSingleAttribute( this, oneToOne.getName(), getType( oneToOne.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 );
-		}
-	}
-}

Deleted: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaSingleAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaSingleAttribute.java	2009-07-10 17:33:21 UTC (rev 17073)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/metamodel/ap/xml/XmlMetaSingleAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1,35 +0,0 @@
-// $Id:$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.jpa.metamodel.ap.xml;
-
-import org.hibernate.jpa.metamodel.ap.IMetaSingleAttribute;
-
-/**
- * @author Hardy Ferentschik
- */
-public class XmlMetaSingleAttribute extends XmlMetaAttribute implements IMetaSingleAttribute {
-
-    public XmlMetaSingleAttribute(XmlMetaEntity parent, String propertyName, String type) {
-        super(parent, propertyName, type);
-    }
-
-	@Override
-    public String getMetaType() {
-        return "javax.persistence.metamodel.SingularAttribute";
-    }
-}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaAttribute.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,55 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen.xml;
+
+import org.hibernate.jpamodelgen.IMetaAttribute;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public abstract class XmlMetaAttribute implements IMetaAttribute {
+
+    private XmlMetaEntity parentEntity;
+
+    private String propertyName;
+
+    private String type;
+
+    XmlMetaAttribute(XmlMetaEntity parent, String propertyName, String type) {
+        this.parentEntity = parent;
+        this.propertyName = propertyName;
+        this.type = type;
+    }
+
+
+	@Override
+    public String getDeclarationString() {
+        return "public static volatile " + parentEntity.importType(getMetaType()) + "<" + parentEntity.importType(parentEntity.getQualifiedName()) + ", " + parentEntity.importType(getTypeDeclaration()) + "> " + getPropertyName() + ";";
+    }
+
+    public String getPropertyName() {
+        return propertyName;
+    }
+
+    public String getTypeDeclaration() {
+		return type;
+	}
+
+    @Override
+    abstract public String getMetaType();
+}

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaCollection.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaCollection.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaCollection.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,38 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen.xml;
+
+import org.hibernate.jpamodelgen.IMetaCollection;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class XmlMetaCollection extends XmlMetaAttribute implements IMetaCollection {
+
+    String collectionType;
+
+    public XmlMetaCollection(XmlMetaEntity parent, String propertyName, String type, String collectionType) {
+        super(parent, propertyName, type);
+        this.collectionType = collectionType;
+    }
+
+    @Override
+	public String getMetaType() {
+		return collectionType;
+	}
+}
\ No newline at end of file

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,255 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen.xml;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.DeclaredType;
+
+import org.hibernate.jpamodelgen.IMetaAttribute;
+import org.hibernate.jpamodelgen.ImportContextImpl;
+import org.hibernate.jpamodelgen.IMetaEntity;
+import org.hibernate.jpamodelgen.ImportContext;
+import org.hibernate.jpamodelgen.xml.jaxb.Attributes;
+import org.hibernate.jpamodelgen.xml.jaxb.Basic;
+import org.hibernate.jpamodelgen.xml.jaxb.ElementCollection;
+import org.hibernate.jpamodelgen.xml.jaxb.Embeddable;
+import org.hibernate.jpamodelgen.xml.jaxb.EmbeddableAttributes;
+import org.hibernate.jpamodelgen.xml.jaxb.Entity;
+import org.hibernate.jpamodelgen.xml.jaxb.Id;
+import org.hibernate.jpamodelgen.xml.jaxb.ManyToOne;
+import org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass;
+import org.hibernate.jpamodelgen.xml.jaxb.OneToMany;
+import org.hibernate.jpamodelgen.xml.jaxb.OneToOne;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class XmlMetaEntity implements IMetaEntity {
+
+	static Map<String, String> COLLECTIONS = new HashMap<String, String>();
+
+	static {
+		COLLECTIONS.put( "java.util.Collection", "javax.persistence.metamodel.CollectionAttribute" );
+		COLLECTIONS.put( "java.util.Set", "javax.persistence.metamodel.SetAttribute" );
+		COLLECTIONS.put( "java.util.List", "javax.persistence.metamodel.ListAttribute" );
+		COLLECTIONS.put( "java.util.Map", "javax.persistence.metamodel.MapAttribute" );
+	}
+
+	final private String clazzName;
+
+	final private String packageName;
+
+	final private ImportContext importContext;
+
+	final private List<IMetaAttribute> members = new ArrayList<IMetaAttribute>();
+
+	private TypeElement element;
+
+	public XmlMetaEntity(Entity ormEntity, String packageName, TypeElement element) {
+		this.clazzName = ormEntity.getClazz();
+		this.packageName = packageName;
+		importContext = new ImportContextImpl( getPackageName() );
+		this.element = element;
+		Attributes attributes = ormEntity.getAttributes();
+
+		parseAttributes( attributes );
+	}
+
+	public XmlMetaEntity(MappedSuperclass mappedSuperclass, String packageName, TypeElement element) {
+		this.clazzName = mappedSuperclass.getClazz();
+		this.packageName = packageName;
+		importContext = new ImportContextImpl( getPackageName() );
+		this.element = element;
+		Attributes attributes = mappedSuperclass.getAttributes();
+
+		parseAttributes( attributes );
+	}
+
+	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 );
+		}
+
+		for ( OneToOne oneToOne : attributes.getOneToOne() ) {
+			attribute = new XmlMetaSingleAttribute( this, oneToOne.getName(), getType( oneToOne.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 clazzName;
+	}
+
+	public String getQualifiedName() {
+		return packageName + "." + getSimpleName();
+	}
+
+	public String getPackageName() {
+		return packageName;
+	}
+
+	public List<IMetaAttribute> getMembers() {
+		return members;
+	}
+
+	public String generateImports() {
+		return importContext.generateImports();
+	}
+
+	public String importType(String fqcn) {
+		return importContext.importType( fqcn );
+	}
+
+	public String staticImport(String fqcn, String member) {
+		return importContext.staticImport( fqcn, member );
+	}
+
+	public String importType(Name qualifiedName) {
+		return importType( qualifiedName.toString() );
+	}
+
+	public TypeElement getTypeElement() {
+		return element;
+	}
+
+	private String[] getCollectionType(String propertyName) {
+		String types[] = new String[2];
+		for ( Element elem : element.getEnclosedElements() ) {
+			if ( elem.getSimpleName().toString().equals( propertyName ) ) {
+				DeclaredType type = ( ( DeclaredType ) elem.asType() );
+				types[0] = type.getTypeArguments().get( 0 ).toString();
+				types[1] = COLLECTIONS.get( type.asElement().toString() );
+			}
+		}
+		return types;
+	}
+
+	private String getType(String propertyName) {
+		String typeName = null;
+		for ( Element elem : element.getEnclosedElements() ) {
+			if ( elem.getSimpleName().toString().equals( propertyName ) ) {
+				switch ( elem.asType().getKind() ) {
+					case INT: {
+						typeName = "java.lang.Integer";
+						break;
+					}
+					case LONG: {
+						typeName = "java.lang.Long";
+						break;
+					}
+					case BOOLEAN: {
+						typeName = "java.lang.Boolean";
+						break;
+					}
+					case DECLARED: {
+						typeName = elem.asType().toString();
+						break;
+					}
+					case TYPEVAR: {
+						typeName = elem.asType().toString();
+						break;
+					}
+				}
+				break;
+			}
+		}
+		return typeName;
+	}
+
+	@Override
+	public String toString() {
+		final StringBuilder sb = new StringBuilder();
+		sb.append( "XmlMetaEntity" );
+		sb.append( "{type=" ).append( element );
+		sb.append( '}' );
+		return sb.toString();
+	}
+
+	private void parseAttributes(Attributes attributes) {
+		XmlMetaSingleAttribute attribute;
+
+		if ( !attributes.getId().isEmpty() ) {
+			// TODO what do we do if there are more than one id nodes?
+			Id id = attributes.getId().get( 0 );
+			attribute = new XmlMetaSingleAttribute(
+					this, id.getName(), getType( id.getName() )
+			);
+			members.add( 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 );
+		}
+
+		for ( OneToOne oneToOne : attributes.getOneToOne() ) {
+			attribute = new XmlMetaSingleAttribute( this, oneToOne.getName(), getType( oneToOne.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 );
+		}
+	}
+}


Property changes on: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaSingleAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaSingleAttribute.java	                        (rev 0)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaSingleAttribute.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -0,0 +1,35 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen.xml;
+
+import org.hibernate.jpamodelgen.IMetaSingleAttribute;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class XmlMetaSingleAttribute extends XmlMetaAttribute implements IMetaSingleAttribute {
+
+    public XmlMetaSingleAttribute(XmlMetaEntity parent, String propertyName, String type) {
+        super(parent, propertyName, type);
+    }
+
+	@Override
+    public String getMetaType() {
+        return "javax.persistence.metamodel.SingularAttribute";
+    }
+}

Modified: jpamodelgen/trunk/src/main/resources/META-INF/services/javax.annotation.processing.Processor
===================================================================
--- jpamodelgen/trunk/src/main/resources/META-INF/services/javax.annotation.processing.Processor	2009-07-10 17:36:23 UTC (rev 17074)
+++ jpamodelgen/trunk/src/main/resources/META-INF/services/javax.annotation.processing.Processor	2009-07-10 17:52:04 UTC (rev 17075)
@@ -1 +1 @@
-org.hibernate.jpa.metamodel.ap.JPAMetaModelEntityProcessor
\ No newline at end of file
+org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
\ No newline at end of file

Modified: jpamodelgen/trunk/src/test/java/test/QueryTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/test/QueryTest.java	2009-07-10 17:36:23 UTC (rev 17074)
+++ jpamodelgen/trunk/src/test/java/test/QueryTest.java	2009-07-10 17:52:04 UTC (rev 17075)
@@ -139,8 +139,8 @@
 		
 		n = qb.quot(x, y);
 		
-		javax.jpa.criteria.Order o = qb.asc(n);
-		javax.jpa.criteria.Order p = qb.ascending(s);
+		javax.jpamodelgen.criteria.Order o = qb.asc(n);
+		javax.jpamodelgen.criteria.Order p = qb.ascending(s);
 	}*/
 
 }




More information about the hibernate-commits mailing list