@Override
  @SuppressWarnings({"unchecked"})
  public void prepare(MetadataSources sources) {
    // create a jandex index from the annotated classes
    Indexer indexer = new Indexer();
    for (Class<?> clazz : sources.getAnnotatedClasses()) {
      indexClass(indexer, clazz.getName().replace('.', '/') + ".class");
    }

    // add package-info from the configured packages
    for (String packageName : sources.getAnnotatedPackages()) {
      indexClass(indexer, packageName.replace('.', '/') + "/package-info.class");
    }

    index = indexer.complete();

    List<JaxbRoot<XMLEntityMappings>> mappings = new ArrayList<JaxbRoot<XMLEntityMappings>>();
    for (JaxbRoot<?> root : sources.getJaxbRootList()) {
      if (root.getRoot() instanceof XMLEntityMappings) {
        mappings.add((JaxbRoot<XMLEntityMappings>) root);
      }
    }
    if (!mappings.isEmpty()) {
      // process the xml configuration
      final OrmXmlParser ormParser = new OrmXmlParser(metadata);
      index = ormParser.parseAndUpdateIndex(mappings, index);
    }

    if (index.getAnnotations(PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS) != null) {
      metadata.setGloballyQuotedIdentifiers(true);
    }
  }
 @Override
 @SuppressWarnings({"unchecked"})
 public void prepare(MetadataSources sources) {
   this.processors = new ArrayList<HibernateMappingProcessor>();
   for (JaxbRoot jaxbRoot : sources.getJaxbRootList()) {
     if (jaxbRoot.getRoot() instanceof XMLHibernateMapping) {
       processors.add(
           new HibernateMappingProcessor(metadata, (JaxbRoot<XMLHibernateMapping>) jaxbRoot));
     }
   }
 }
 public void bindMappingMetadata(List<String> processedEntityNames) {
   if (hibernateMapping.getClazzOrSubclassOrJoinedSubclass() == null) {
     return;
   }
   for (Object clazzOrSubclass : hibernateMapping.getClazzOrSubclassOrJoinedSubclass()) {
     if (XMLHibernateMapping.XMLClass.class.isInstance(clazzOrSubclass)) {
       XMLHibernateMapping.XMLClass clazz =
           XMLHibernateMapping.XMLClass.class.cast(clazzOrSubclass);
       new RootEntityBinder(this, clazz).process(clazz);
     } else if (XMLSubclassElement.class.isInstance(clazzOrSubclass)) {
       //					PersistentClass superModel = getSuperclass( mappings, element );
       //					handleSubclass( superModel, mappings, element, inheritedMetas );
     } else if (XMLJoinedSubclassElement.class.isInstance(clazzOrSubclass)) {
       //					PersistentClass superModel = getSuperclass( mappings, element );
       //					handleJoinedSubclass( superModel, mappings, element, inheritedMetas );
     } else if (XMLUnionSubclassElement.class.isInstance(clazzOrSubclass)) {
       //					PersistentClass superModel = getSuperclass( mappings, element );
       //					handleUnionSubclass( superModel, mappings, element, inheritedMetas );
     } else {
       throw new org.hibernate.metamodel.source.MappingException(
           "unknown type of class or subclass: " + clazzOrSubclass.getClass().getName(),
           jaxbRoot.getOrigin());
     }
   }
 }
 private void bindFilterDefinitions() {
   if (hibernateMapping.getFilterDef() == null) {
     return;
   }
   for (XMLHibernateMapping.XMLFilterDef filterDefinition : hibernateMapping.getFilterDef()) {
     final String name = filterDefinition.getName();
     final Map<String, Type> parameters = new HashMap<String, Type>();
     String condition = null;
     for (Object o : filterDefinition.getContent()) {
       if (o instanceof String) {
         // represents the condition
         if (condition != null) {
           // log?
         }
         condition = (String) o;
       } else if (o instanceof XMLHibernateMapping.XMLFilterDef.XMLFilterParam) {
         final XMLHibernateMapping.XMLFilterDef.XMLFilterParam paramElement =
             (XMLHibernateMapping.XMLFilterDef.XMLFilterParam) o;
         // todo : should really delay this resolution until later to allow typedef names
         parameters.put(
             paramElement.getName(),
             metadata.getTypeResolver().heuristicType(paramElement.getType()));
       } else {
         throw new MappingException("Unrecognized nested filter content", jaxbRoot.getOrigin());
       }
     }
     if (condition == null) {
       condition = filterDefinition.getCondition();
     }
     metadata.addFilterDefinition(new FilterDefinition(name, condition, parameters));
   }
 }
 private void bindDatabaseObjectDefinitions() {
   if (hibernateMapping.getDatabaseObject() == null) {
     return;
   }
   for (XMLHibernateMapping.XMLDatabaseObject databaseObjectElement :
       hibernateMapping.getDatabaseObject()) {
     final AuxiliaryDatabaseObject auxiliaryDatabaseObject;
     if (databaseObjectElement.getDefinition() != null) {
       final String className = databaseObjectElement.getDefinition().getClazz();
       try {
         auxiliaryDatabaseObject =
             (AuxiliaryDatabaseObject) classLoaderService().classForName(className).newInstance();
       } catch (ClassLoadingException e) {
         throw e;
       } catch (Exception e) {
         throw new MappingException(
             "could not instantiate custom database object class [" + className + "]",
             jaxbRoot.getOrigin());
       }
     } else {
       Set<String> dialectScopes = new HashSet<String>();
       if (databaseObjectElement.getDialectScope() != null) {
         for (XMLHibernateMapping.XMLDatabaseObject.XMLDialectScope dialectScope :
             databaseObjectElement.getDialectScope()) {
           dialectScopes.add(dialectScope.getName());
         }
       }
       auxiliaryDatabaseObject =
           new BasicAuxiliaryDatabaseObjectImpl(
               databaseObjectElement.getCreate(), databaseObjectElement.getDrop(), dialectScopes);
     }
     metadata.addAuxiliaryDatabaseObject(auxiliaryDatabaseObject);
   }
 }
 private void bindNamedQueries() {
   if (hibernateMapping.getQueryOrSqlQuery() == null) {
     return;
   }
   for (Object queryOrSqlQuery : hibernateMapping.getQueryOrSqlQuery()) {
     if (XMLQueryElement.class.isInstance(queryOrSqlQuery)) {
       //					bindNamedQuery( element, null, mappings );
     } else if (XMLSqlQueryElement.class.isInstance(queryOrSqlQuery)) {
       //				bindNamedSQLQuery( element, null, mappings );
     } else {
       throw new MappingException(
           "unknown type of query: " + queryOrSqlQuery.getClass().getName(), jaxbRoot.getOrigin());
     }
   }
 }
 public void bindFetchProfiles(
     List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
   for (XMLFetchProfileElement fetchProfile : fetchProfiles) {
     String profileName = fetchProfile.getName();
     Set<FetchProfile.Fetch> fetches = new HashSet<FetchProfile.Fetch>();
     for (XMLFetchProfileElement.XMLFetch fetch : fetchProfile.getFetch()) {
       String entityName = fetch.getEntity() == null ? containingEntityName : fetch.getEntity();
       if (entityName == null) {
         throw new MappingException(
             "could not determine entity for fetch-profile fetch ["
                 + profileName
                 + "]:["
                 + fetch.getAssociation()
                 + "]",
             jaxbRoot.getOrigin());
       }
       fetches.add(new FetchProfile.Fetch(entityName, fetch.getAssociation(), fetch.getStyle()));
     }
     metadata.addFetchProfile(new FetchProfile(profileName, fetches));
   }
 }
  public HibernateMappingProcessor(
      MetadataImplementor metadata, JaxbRoot<XMLHibernateMapping> jaxbRoot) {
    this.metadata = metadata;
    this.jaxbRoot = jaxbRoot;

    this.hibernateMapping = jaxbRoot.getRoot();
    this.mappingDefaults =
        new OverriddenMappingDefaults(
            metadata.getMappingDefaults(),
            hibernateMapping.getPackage(),
            hibernateMapping.getSchema(),
            hibernateMapping.getCatalog(),
            null,
            null,
            hibernateMapping.getDefaultCascade(),
            hibernateMapping.getDefaultAccess(),
            hibernateMapping.isDefaultLazy());

    autoImport = hibernateMapping.isAutoImport();

    metaAttributeContext = extractMetaAttributes();
  }
 @Override
 public Origin getOrigin() {
   return jaxbRoot.getOrigin();
 }