Example usage for java.lang Package isAnnotationPresent

List of usage examples for java.lang Package isAnnotationPresent

Introduction

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

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:com.opensymphony.xwork2.util.finder.ClassFinder.java

public List<Package> findAnnotatedPackages(Class<? extends Annotation> annotation) {
    classesNotLoaded.clear();/*from   www  .  j ava2s  .com*/
    List<Package> packages = new ArrayList<Package>();
    List<Info> infos = getAnnotationInfos(annotation.getName());
    for (Info info : infos) {
        if (info instanceof PackageInfo) {
            PackageInfo packageInfo = (PackageInfo) info;
            try {
                Package pkg = packageInfo.get();
                // double check via proper reflection
                if (pkg.isAnnotationPresent(annotation)) {
                    packages.add(pkg);
                }
            } catch (ClassNotFoundException e) {
                classesNotLoaded.add(packageInfo.getName());
            }
        }
    }
    return packages;
}

From source file:org.apache.struts2.convention.DefaultClassFinder.java

public List<Package> findAnnotatedPackages(Class<? extends Annotation> annotation) {
    classesNotLoaded.clear();/*from w ww. j  a v a 2  s . co m*/
    List<Package> packages = new ArrayList<>();
    List<Info> infos = getAnnotationInfos(annotation.getName());
    for (Info info : infos) {
        if (info instanceof PackageInfo) {
            PackageInfo packageInfo = (PackageInfo) info;
            try {
                Package pkg = packageInfo.get();
                // double check via proper reflection
                if (pkg.isAnnotationPresent(annotation)) {
                    packages.add(pkg);
                }
            } catch (ClassNotFoundException e) {
                classesNotLoaded.add(packageInfo.getName());
            }
        }
    }
    return packages;
}

From source file:org.codehaus.enunciate.modules.xfire.EnunciatedJAXWSOperationBinding.java

/**
 * Loads the set of input properties for the specified operation.
 *
 * @param op The operation./*  w ww  .j av a  2s.c  o  m*/
 * @return The input properties, or null if none were found.
 */
protected OperationBeanInfo getRequestInfo(OperationInfo op) throws XFireFault {
    Method method = op.getMethod();
    Class ei = method.getDeclaringClass();
    Package pckg = ei.getPackage();
    SOAPBinding.ParameterStyle paramStyle = SOAPBinding.ParameterStyle.WRAPPED;
    if (method.isAnnotationPresent(SOAPBinding.class)) {
        SOAPBinding annotation = method.getAnnotation(SOAPBinding.class);
        paramStyle = annotation.parameterStyle();
    } else if (ei.isAnnotationPresent(SOAPBinding.class)) {
        SOAPBinding annotation = ((SOAPBinding) ei.getAnnotation(SOAPBinding.class));
        paramStyle = annotation.parameterStyle();
    }

    boolean schemaValidate = method.isAnnotationPresent(SchemaValidate.class)
            || ei.isAnnotationPresent(SchemaValidate.class) || pckg.isAnnotationPresent(SchemaValidate.class);

    if (paramStyle == SOAPBinding.ParameterStyle.BARE) {
        //return a bare operation info.
        //it's not necessarily the first parameter type! there could be a header or OUT parameter...
        int paramIndex;
        WebParam annotation = null;
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        if (parameterAnnotations.length == 0) {
            throw new IllegalStateException("A BARE web service must have input parameters.");
        }

        PARAM_ANNOTATIONS: for (paramIndex = 0; paramIndex < parameterAnnotations.length; paramIndex++) {
            Annotation[] annotations = parameterAnnotations[paramIndex];
            for (Annotation candidate : annotations) {
                if (candidate instanceof WebParam && !((WebParam) candidate).header()) {
                    WebParam.Mode mode = ((WebParam) candidate).mode();
                    switch (mode) {
                    case OUT:
                    case INOUT:
                        annotation = (WebParam) candidate;
                        break PARAM_ANNOTATIONS;
                    }
                }
            }
        }

        if (annotation == null) {
            paramIndex = 0;
        }

        return new OperationBeanInfo(method.getParameterTypes()[paramIndex], null, op.getInputMessage(),
                schemaValidate);
    } else {
        String requestWrapperClassName;
        RequestWrapper requestWrapperInfo = method.getAnnotation(RequestWrapper.class);
        if ((requestWrapperInfo != null) && (requestWrapperInfo.className() != null)
                && (requestWrapperInfo.className().length() > 0)) {
            requestWrapperClassName = requestWrapperInfo.className();
        } else {
            StringBuilder builder = new StringBuilder(pckg == null ? "" : pckg.getName());
            if (builder.length() > 0) {
                builder.append(".");
            }

            builder.append("jaxws.");

            String methodName = method.getName();
            builder.append(capitalize(methodName));
            requestWrapperClassName = builder.toString();
        }

        Class wrapperClass;
        try {
            wrapperClass = ClassLoaderUtils.loadClass(requestWrapperClassName, getClass());
        } catch (ClassNotFoundException e) {
            LOG.error("Unabled to find request wrapper class " + requestWrapperClassName + "... Operation "
                    + op.getQName() + " will not be able to recieve...");
            return null;
        }

        return new OperationBeanInfo(wrapperClass, loadOrderedProperties(wrapperClass), op.getInputMessage(),
                schemaValidate);
    }

}