Example usage for java.lang Package getDeclaredAnnotations

List of usage examples for java.lang Package getDeclaredAnnotations

Introduction

In this page you can find the example usage for java.lang Package getDeclaredAnnotations.

Prototype

public Annotation[] getDeclaredAnnotations() 

Source Link

Usage

From source file:Main.java

public static void main(String args[]) {

    // create a package object for java.lang package
    Package pack = Package.getPackage("java.io");
    for (Annotation at : pack.getDeclaredAnnotations()) {
        System.out.println(at);/*from   ww w.j av  a 2s . co m*/
    }

}

From source file:org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.java

/**
 * Parse information in package-level class annotations.
 *///from w  w  w.j a v a  2 s .  c  om
private void parsePackageAnnotations() {
    Package pkg = _cls.getPackage();
    if (pkg == null)
        return;

    int pkgMode = getSourceMode(pkg);
    if (pkgMode == 0 && _log.isTraceEnabled())
        _log.trace(_loc.get("parse-package", _cls.getName()));
    if ((pkgMode & _mode) == _mode) // already visited
        return;

    MetaDataTag tag;
    for (Annotation anno : pkg.getDeclaredAnnotations()) {
        tag = _tags.get(anno.annotationType());
        if (tag == null) {
            handleUnknownPackageAnnotation(pkg, anno);
            continue;
        }

        switch (tag) {
        case NATIVE_QUERIES:
            if (isQueryMode() && (pkgMode & MODE_QUERY) == 0)
                parseNamedNativeQueries(pkg, ((NamedNativeQueries) anno).value());
            break;
        case NATIVE_QUERY:
            if (isQueryMode() && (pkgMode & MODE_QUERY) == 0)
                parseNamedNativeQueries(pkg, (NamedNativeQuery) anno);
            break;

        case QUERIES:
            if (isQueryMode() && (pkgMode & MODE_QUERY) == 0)
                parseNamedQueries(pkg, ((NamedQueries) anno).value());
            break;
        case QUERY:
            if (isQueryMode() && (pkgMode & MODE_QUERY) == 0)
                parseNamedQueries(pkg, (NamedQuery) anno);
            break;
        case SEQ_GENERATOR:
            if (isMappingOverrideMode() && (pkgMode & MODE_MAPPING) == 0)
                parseSequenceGenerator(pkg, (SequenceGenerator) anno);
            break;
        default:
            throw new UnsupportedException(_loc.get("unsupported", pkg, anno.toString()));
        }
    }

    // always parse mapping stuff after metadata stuff, in case there are
    // dependencies on metadata
    if (isMappingOverrideMode() && (pkgMode & MODE_MAPPING) == 0)
        parsePackageMappingAnnotations(pkg);
}

From source file:org.apache.openjpa.persistence.jdbc.AnnotationPersistenceMappingParser.java

@Override
protected void parsePackageMappingAnnotations(Package pkg) {
    MappingTag tag;//w w w.  j a  va  2 s  . c o  m
    for (Annotation anno : pkg.getDeclaredAnnotations()) {
        tag = _tags.get(anno.annotationType());
        if (tag == null) {
            handleUnknownPackageMappingAnnotation(pkg, anno);
            continue;
        }

        switch (tag) {
        case TABLE_GEN:
            parseTableGenerator(pkg, (TableGenerator) anno);
            break;
        case STOREDPROCEDURE_QUERIES:
            if (isQueryMode())
                parseNamedStoredProcedureQueries(pkg, ((NamedStoredProcedureQueries) anno).value());
            break;
        case STOREDPROCEDURE_QUERY:
            if (isQueryMode())
                parseNamedStoredProcedureQueries(pkg, ((NamedStoredProcedureQuery) anno));
            break;
        default:
            throw new UnsupportedException(_loc.get("unsupported", pkg, anno.toString()));
        }
    }
}