Example usage for org.eclipse.jdt.core.util IClassFileReader getAttributes

List of usage examples for org.eclipse.jdt.core.util IClassFileReader getAttributes

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.util IClassFileReader getAttributes.

Prototype

IClassFileAttribute[] getAttributes();

Source Link

Document

Answer back the collection of all attributes of the field info.

Usage

From source file:org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities.java

License:Open Source License

public boolean isEJBArchive(IArchive archive) {
    // first check for the deployment descriptor
    if (archiveToJavaEEQuickPeek.containsKey(archive)) {
        JavaEEQuickPeek qp = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archive);
        if (qp.getType() == JavaEEQuickPeek.EJB_TYPE) {
            return true;
        }/*from  w w  w  .ja v  a  2  s .  com*/
    }

    List<IArchiveResource> archiveResources = archive.getArchiveResources();
    for (IArchiveResource archiveResource : archiveResources) {
        if (archiveResource.getType() == IArchiveResource.FILE_TYPE) {
            if (archiveResource.getPath().lastSegment().endsWith(DOT_CLASS)) {
                InputStream ioStream = null;
                try {
                    ioStream = archiveResource.getInputStream();
                    IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(ioStream,
                            IClassFileReader.CLASSFILE_ATTRIBUTES);
                    //classFileReader will be null if this is an invalid java .class file
                    if (classFileReader != null) {
                        IClassFileAttribute[] attributes = classFileReader.getAttributes();
                        for (IClassFileAttribute attribute : attributes) {
                            char[] attributeName = attribute.getAttributeName();
                            if (Arrays.equals(attributeName, RUNTIME_VISIBLE)) {
                                IRuntimeVisibleAnnotationsAttribute annotationsAttribute = (IRuntimeVisibleAnnotationsAttribute) attribute;
                                IAnnotation[] annotations = annotationsAttribute.getAnnotations();
                                for (IAnnotation annotation : annotations) {
                                    char[] typedName = annotation.getTypeName();
                                    if (Arrays.equals(typedName, STATELESS)
                                            || Arrays.equals(typedName, STATEFUL)
                                            || Arrays.equals(typedName, MESSAGEDRIVEN)
                                            || Arrays.equals(typedName, SINGLETON)) {
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                } catch (FileNotFoundException e) {
                    ArchiveUtil.warn(e);
                } catch (IOException e) {
                    ArchiveUtil.warn(e);
                } finally {
                    if (null != ioStream) {
                        try {
                            ioStream.close();
                        } catch (IOException e) {
                            ArchiveUtil.warn(e);
                        }
                    }
                    ioStream = null;
                }
            }
        }
    }
    return false;
}