private List<Class<?>> scanClassAndPutMetadata(InputStream bits, Reader reader,
            Map<String, EntityMetadata> entityMetadataMap, Map<String, Class<?>> entityNameToClassMap,
            String persistenceUnit, String client, Map<String, List<String>> clazzToPuMap,
            Map<String, IdDiscriptor> entityNameToKeyDiscriptorMap) throws IOException
    {
        DataInputStream dstream = new DataInputStream(new BufferedInputStream(bits));
        ClassFile cf = null;
        String className = null;

        List<Class<?>> classes = new ArrayList<Class<?>>();

        try
        {
            cf = new ClassFile(dstream);

            className = cf.getName();

            List<String> annotations = new ArrayList<String>();

            reader.accumulateAnnotations(annotations,
                    (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag));
            reader.accumulateAnnotations(annotations,
                    (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag));
            

            // iterate through all valid annotations
            for (String validAnn : reader.getValidAnnotations())
            {
            	

                // check if the current class has one?
                if (annotations.contains(validAnn))
                {
                	
                	Class<?> clazz = this.getClass().getClassLoader().loadClass(className);
                    this.factory.validate(clazz);

                    // get the name of entity to be used for entity to class map
                    // if or not annotated with name
                    String entityName = getEntityName(clazz);

                    if ((entityNameToClassMap.containsKey(entityName) && !entityNameToClassMap.get(entityName)
                            .getName().equals(clazz.getName())))
                    {
                        throw new MetamodelLoaderException("Name conflict between classes "
                                + entityNameToClassMap.get(entityName).getName() + " and " + clazz.getName()
                                + ". Make sure no two entity classes with the same name "
                                + " are specified for persistence unit " + persistenceUnit);
                    }
                    entityNameToClassMap.put(entityName, clazz);

                    EntityMetadata metadata = entityMetadataMap.get(clazz);
                    if (null == metadata)
                    {
                        log.debug("Metadata not found in cache for " + clazz.getName());
                        // double check locking.
                        synchronized (clazz)
                        {
                            if (null == metadata)
                            {
                                MetadataBuilder metadataBuilder = new MetadataBuilder(persistenceUnit, client,
                                        KunderaCoreUtils.getExternalProperties(persistenceUnit, externalPropertyMap,
                                                persistenceUnits), kunderaMetadata);
                                metadata = metadataBuilder.buildEntityMetadata(clazz);

                                // in case entity's pu does not belong to parse
                                // persistence unit, it will be null.
                                if (metadata != null)
                                {
                                    entityMetadataMap.put(clazz.getName(), metadata);
                                    mapClazztoPu(clazz, persistenceUnit, clazzToPuMap);
                                    processGeneratedValueAnnotation(clazz, persistenceUnit, metadata,
                                            entityNameToKeyDiscriptorMap);
                                }
                            }
                        }
                    }

                    // TODO :
                    onValidateClientProperties(classes, clazz, persistenceUnit);
                }
            }
        }
        catch (ClassNotFoundException e)
        {
            log.error("Class " + className + " not found, it won't be loaded as entity");
        }

        finally
        {
            if (dstream != null)
            {
                dstream.close();
            }
            if (bits != null)
            {
                bits.close();
            }
        }

        return classes;
    }
private List < Class < ? > > scanClassAndPutMetadata ( InputStream bits , Reader reader , Map < String , EntityMetadata > entityMetadataMap , Map < String , Class < ? > > entityNameToClassMap , String persistenceUnit , String client , Map < String , List < String > > clazzToPuMap , Map < String , IdDiscriptor > entityNameToKeyDiscriptorMap ) throws IOException { DataInputStream dstream = new DataInputStream ( new BufferedInputStream ( bits ) ) ; ClassFile cf = null ; String className = null ; List < Class < ? > > classes = new ArrayList < Class < ? > > ( ) ; try { cf = new ClassFile ( dstream ) ; className = cf . getName ( ) ; List < String > annotations = new ArrayList < String > ( ) ; reader . accumulateAnnotations ( annotations , ( AnnotationsAttribute ) cf . getAttribute ( AnnotationsAttribute . visibleTag ) ) ; reader . accumulateAnnotations ( annotations , ( AnnotationsAttribute ) cf . getAttribute ( AnnotationsAttribute . invisibleTag ) ) ; for ( String validAnn : reader . getValidAnnotations ( ) ) { if ( annotations . contains ( validAnn ) ) { Class < ? > clazz = this . getClass ( ) . getClassLoader ( ) . loadClass ( className ) ; this . factory . validate ( clazz ) ; String entityName = getEntityName ( clazz ) ; if ( ( entityNameToClassMap . containsKey ( entityName ) && ! entityNameToClassMap . get ( entityName ) . getName ( ) . equals ( clazz . getName ( ) ) ) ) { throw new MetamodelLoaderException ( "Name conflict between classes " + entityNameToClassMap . get ( entityName ) . getName ( ) + " and " + clazz . getName ( ) + ". Make sure no two entity classes with the same name " + " are specified for persistence unit " + persistenceUnit ) ; } entityNameToClassMap . put ( entityName , clazz ) ; EntityMetadata metadata = entityMetadataMap . get ( clazz ) ; if ( null == metadata ) { log . debug ( "Metadata not found in cache for " + clazz . getName ( ) ) ; synchronized ( clazz ) { if ( null == metadata ) { MetadataBuilder metadataBuilder = new MetadataBuilder ( persistenceUnit , client , KunderaCoreUtils . getExternalProperties ( persistenceUnit , externalPropertyMap , persistenceUnits ) , kunderaMetadata ) ; metadata = metadataBuilder . buildEntityMetadata ( clazz ) ; if ( metadata != null ) { entityMetadataMap . put ( clazz . getName ( ) , metadata ) ; mapClazztoPu ( clazz , persistenceUnit , clazzToPuMap ) ; processGeneratedValueAnnotation ( clazz , persistenceUnit , metadata , entityNameToKeyDiscriptorMap ) ; } } } } onValidateClientProperties ( classes , clazz , persistenceUnit ) ; } } } catch ( ClassNotFoundException e ) { log . error ( "Class " + className + " not found, it won't be loaded as entity" ) ; } finally { if ( dstream != null ) { dstream . close ( ) ; } if ( bits != null ) { bits . close ( ) ; } } return classes ; }
Scan class and put metadata.

@param bits
the bits
@param reader
the reader
@param entityMetadataMap
the entity metadata map
@param entityNameToClassMap
the entity name to class map
@param keyDiscriptor
@param persistence
unit the persistence unit.
@throws IOException
Signals that an I/O exception has occurred.
@throws RuleValidationException