Example usage for java.lang.reflect Modifier PUBLIC

List of usage examples for java.lang.reflect Modifier PUBLIC

Introduction

In this page you can find the example usage for java.lang.reflect Modifier PUBLIC.

Prototype

int PUBLIC

To view the source code for java.lang.reflect Modifier PUBLIC.

Click Source Link

Document

The int value representing the public modifier.

Usage

From source file:com.adaptc.mws.plugins.testing.transformations.TestForTransformation.java

protected MethodNode addClassUnderTestMethod(ClassNode classNode, ClassExpression targetClass, String type) {

    String methodName = "setup" + type + "UnderTest";
    String fieldName = TestMixinTransformation.getPropertyNameRepresentation(type);
    String getterName = TestMixinTransformation.getGetterName(fieldName);
    fieldName = '$' + fieldName;

    if (classNode.getField(fieldName) == null) {
        classNode.addField(fieldName, Modifier.PRIVATE, targetClass.getType(), null);
    }/*from   ww  w.  jav a  2 s  .  co  m*/

    MethodNode methodNode = classNode.getMethod(methodName, TestMixinTransformation.ZERO_PARAMETERS);

    VariableExpression fieldExpression = new VariableExpression(fieldName);
    if (methodNode == null) {
        BlockStatement setupMethodBody = new BlockStatement();
        addMockClassUnderTest(type, fieldExpression, targetClass, setupMethodBody);

        methodNode = new MethodNode(methodName, Modifier.PUBLIC, ClassHelper.VOID_TYPE,
                TestMixinTransformation.ZERO_PARAMETERS, null, setupMethodBody);
        methodNode.addAnnotation(BEFORE_ANNOTATION);
        methodNode.addAnnotation(MIXIN_METHOD_ANNOTATION);
        classNode.addMethod(methodNode);
    }

    MethodNode getter = classNode.getMethod(getterName, TestMixinTransformation.ZERO_PARAMETERS);
    if (getter == null) {
        BlockStatement getterBody = new BlockStatement();
        getter = new MethodNode(getterName, Modifier.PUBLIC, targetClass.getType().getPlainNodeReference(),
                TestMixinTransformation.ZERO_PARAMETERS, null, getterBody);
        getterBody.addStatement(new ReturnStatement(fieldExpression));
        classNode.addMethod(getter);
    }

    return methodNode;
}

From source file:org.gvnix.flex.FlexScaffoldMetadata.java

private MethodMetadata getCreateMethod() {
    JavaSymbolName methodName = new JavaSymbolName("create");

    MethodMetadata method = methodExists(methodName);
    if (method != null) {
        return method;
    }//w w  w  .j  a va  2  s  .c o m

    List<AnnotatedJavaType> paramTypes = new ArrayList<AnnotatedJavaType>();
    paramTypes.add(new AnnotatedJavaType(this.entity, new ArrayList<AnnotationMetadata>()));

    List<JavaSymbolName> paramNames = new ArrayList<JavaSymbolName>();
    paramNames.add(new JavaSymbolName(this.entityReference));

    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine(this.entityReference + "."
            + new JpaCrudAnnotationValues(this.entityMetadata).getPersistMethod() + "();");
    bodyBuilder.appendFormalLine("return " + this.entityReference + ";");

    return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, this.entity, paramTypes, paramNames,
            bodyBuilder).build();
}

From source file:org.gvnix.addon.jpa.addon.query.JpaQueryMetadata.java

/**
 * Generate method to get the filterBy information
 * /*from   ww w  .  jav a  2  s  .c o  m*/
 * @param fieldsToProcess
 * @return
 */
private MethodMetadata getFilterByMethod(Map<FieldMetadata, AnnotationMetadata> fieldsToProcess) {

    // public Map<String,List<String>> getJpaQueryFilterBy() {

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(GET_FILTERBY_DEFINITION, new ArrayList<AnnotatedJavaType>());
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter types (none in this case)
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();

    // Define method parameter names (none in this case)
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    buildGetFilterByDefinitionMethodBody(bodyBuilder, fieldsToProcess);

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC,
            GET_FILTERBY_DEFINITION, MAP_STRING_LIST_STRING, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
                                  // instance
}

From source file:com.mobile.system.db.abatis.AbatisService.java

public Object parseToObject(Class beanClass, Cursor cur)
        throws IllegalAccessException, InstantiationException, SecurityException, NoSuchMethodException {
    Object obj = null;/*ww  w .  ja v  a 2  s  .co  m*/
    Field[] props = beanClass.getDeclaredFields();
    if (props == null || props.length == 0) {
        Log.d(TAG, "Class" + beanClass.getName() + " has no fields");
        return null;
    }
    // Create instance of this Bean class
    obj = beanClass.newInstance();
    // Set value of each member variable of this object
    for (int i = 0; i < props.length; i++) {
        String fieldName = props[i].getName();
        if (props[i].getModifiers() == (Modifier.PUBLIC | Modifier.STATIC)) {
            continue;
        }

        Class type = props[i].getType();
        String typeName = type.getName();
        // Check for Custom type

        Class[] parms = { type };
        Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms);
        m.setAccessible(true);
        // Set value
        try {
            int curIdx = cur.getColumnIndex(fieldName);
            if (curIdx != -1) {
                int nDotIdx = typeName.lastIndexOf(".");
                if (nDotIdx >= 0) {
                    typeName = typeName.substring(nDotIdx);
                }

                if (typeName.equals("int")) {
                    m.invoke(obj, cur.getInt(curIdx));
                } else if (typeName.equals("double")) {
                    m.invoke(obj, cur.getDouble(curIdx));
                } else if (typeName.equals("String")) {
                    m.invoke(obj, cur.getString(curIdx));
                } else if (typeName.equals("long")) {
                    m.invoke(obj, cur.getLong(curIdx));
                } else if (typeName.equals("float")) {
                    m.invoke(obj, cur.getFloat(curIdx));
                } else if (typeName.equals("Date")) {
                    m.invoke(obj, cur.getString(curIdx));
                } else if (typeName.equals("byte[]") || typeName.equals("[B")) {
                    m.invoke(obj, cur.getBlob(curIdx));
                } else {
                    m.invoke(obj, cur.getString(curIdx));
                }
            }

        } catch (Exception ex) {
            Log.d(TAG, ex.getMessage());
        }
    }
    return obj;
}

From source file:autocorrelator.apps.SDFGroovy.java

private static void exitWithHelp(String msg, Options options) {
    System.err.println(msg);//ww  w.jav a  2s . co  m
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(120);
    formatter.printHelp(INTROText, options);

    StringBuilder sb = new StringBuilder();
    Class<SDFGroovyHelper> helper = SDFGroovyHelper.class;
    for (Method m : helper.getMethods()) {
        if ((m.getModifiers() & Modifier.STATIC) == 0 || (m.getModifiers() & Modifier.PUBLIC) == 0)
            continue;

        String meth = m.toString();
        meth = meth.replaceAll("public static final ", "");
        meth = meth.replaceAll("java\\.lang\\.", "");
        meth = meth.replaceAll("java\\.math\\.", "");
        meth = meth.replaceAll("autocorrelator\\.apps\\.SDFGroovyHelper.", "");
        sb.append('\t').append(meth).append('\n');
    }
    System.out.println("Imported internal functions:");
    System.out.println(sb);
    System.exit(1);

}

From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java

/**
 * @return gets or creates getProperty(name,beanWrapper)
 *//* w  w  w .  ja  v a  2 s .  c o  m*/
private MethodMetadata getPropertyMethodWithWrapper() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(JavaType.STRING, BEAN_WRAPPER_IMPL);

    // Check if a method exist in type
    final MethodMetadata method = helper.methodExists(GET_PROPERTY_METHOD, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method
        return method;
    }

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    List<JavaSymbolName> parameterNames = helper.toSymbolName("name", "beanWrapper");

    // Create the method body
    InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder();
    buildGetPropertyMethodWithWrapper(body, helper, context.getEntity());

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(context.getMetadataId(),
            Modifier.PUBLIC + Modifier.STATIC, GET_PROPERTY_METHOD, AUDIT_PROPERTY_GENERIC, parameterTypes,
            parameterNames, body);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
}

From source file:org.gvnix.web.report.roo.addon.addon.ReportMetadata.java

/**
 * Add to the aspect the MethodMetadata of the generateReportForm method. It
 * uses AbstractMetadataItem.builder for add the new method.
 * /* w  w w.j ava  2 s.  c o m*/
 * @param reportName
 * @param entity
 * @param reportMethods2
 * @return
 */
private MethodMetadata addGenerateReportFormMethod(JavaType entity, String reportName, String reportFormats) {
    // Specify the desired method name
    JavaSymbolName methodName = new JavaSymbolName(generateMethodName(reportName, true));

    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(new AnnotatedJavaType(MODEL_TYPE, new ArrayList<AnnotationMetadata>()));

    // Check if a method with the same signature already exists in the
    // target type
    MethodMetadata reportMethod = reportMethodExists(methodName);
    if (reportMethod != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return reportMethod;
    }

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(new JavaSymbolName("uiModel"));

    // Define method annotations
    List<AnnotationAttributeValue<?>> requestMappingAttributes = new ArrayList<AnnotationAttributeValue<?>>();
    requestMappingAttributes.add(new StringAttributeValue(VALUE_SYMBOL_NAME, "/reports/".concat(reportName)));
    requestMappingAttributes.add(new StringAttributeValue(PARAMS_SYMBOL_NAME, "form"));
    requestMappingAttributes.add(new EnumAttributeValue(METHOD_SYMBOL_NAME,
            new EnumDetails(REQUEST_METHOD_TYPE, new JavaSymbolName("GET"))));
    AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(REQUEST_MAPPING_TYPE,
            requestMappingAttributes);
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(requestMapping);

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

    // Populate report_formats list for select
    String reportFormatsAsArray = getReportFormatsAsArray(reportFormats);
    bodyBuilder.appendFormalLine("String[] reportFormats =  ".concat(reportFormatsAsArray).concat(";"));
    bodyBuilder.appendFormalLine("Collection<String> reportFormatsList = Arrays.asList(reportFormats);");
    bodyBuilder.appendFormalLine("uiModel.addAttribute(\"report_formats\", reportFormatsList);");

    // return the View
    bodyBuilder.appendFormalLine(
            "return \"".concat(annotationValues.getPath()).concat("/").concat(reportName).concat("\";"));

    // ImportRegistrationResolver gives access to imports in the
    // Java/AspectJ source
    ImportRegistrationResolver irr = builder.getImportRegistrationResolver();
    irr.addImport(new JavaType("java.util.Arrays"));
    irr.addImport(new JavaType("java.util.Collection"));

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
            JavaType.STRING, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);

    reportMethod = methodBuilder.build();
    builder.addMethod(reportMethod);
    controllerMethods.add(reportMethod);
    return reportMethod;
}

From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java

/** Define an attribute on the managed object.
 * The meta data is defined by looking for standard getter and
 * setter methods. Descriptions are obtained with a call to
 * findDescription with the attribute name.
 * @param name The name of the attribute. Normal java bean
 * capitlization is enforced on this name.
 * @param writable If false, do not look for a setter.
 * @param onMBean ./*ww  w  .  ja  v  a  2s  . c om*/
 */
public synchronized void defineAttribute(String name, boolean writable, boolean onMBean) {
    _dirty = true;

    String uName = name.substring(0, 1).toUpperCase() + name.substring(1);
    name = java.beans.Introspector.decapitalize(name);
    Class oClass = onMBean ? this.getClass() : _object.getClass();

    Class type = null;
    Method getter = null;
    Method setter = null;
    Method[] methods = oClass.getMethods();
    for (int m = 0; m < methods.length; m++) {
        if ((methods[m].getModifiers() & Modifier.PUBLIC) == 0)
            continue;

        // Look for a getter
        if (methods[m].getName().equals("get" + uName) && methods[m].getParameterTypes().length == 0) {
            if (getter != null)
                throw new IllegalArgumentException("Multiple getters for attr " + name);
            getter = methods[m];
            if (type != null && !type.equals(methods[m].getReturnType()))
                throw new IllegalArgumentException("Type conflict for attr " + name);
            type = methods[m].getReturnType();
        }

        // Look for an is getter
        if (methods[m].getName().equals("is" + uName) && methods[m].getParameterTypes().length == 0) {
            if (getter != null)
                throw new IllegalArgumentException("Multiple getters for attr " + name);
            getter = methods[m];
            if (type != null && !type.equals(methods[m].getReturnType()))
                throw new IllegalArgumentException("Type conflict for attr " + name);
            type = methods[m].getReturnType();
        }

        // look for a setter
        if (writable && methods[m].getName().equals("set" + uName)
                && methods[m].getParameterTypes().length == 1) {
            if (setter != null)
                throw new IllegalArgumentException("Multiple setters for attr " + name);
            setter = methods[m];
            if (type != null && !type.equals(methods[m].getParameterTypes()[0]))
                throw new IllegalArgumentException("Type conflict for attr " + name);
            type = methods[m].getParameterTypes()[0];
        }
    }

    if (getter == null && setter == null)
        throw new IllegalArgumentException("No getter or setters found for " + name);

    try {
        // Remember the methods
        _getter.put(name, getter);
        _setter.put(name, setter);
        // create and add the info
        _attributes.add(new ModelMBeanAttributeInfo(name, findDescription(name), getter, setter));
    } catch (Exception e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new IllegalArgumentException(e.toString());
    }
}

From source file:jp.go.nict.langrid.servicecontainer.handler.jsonrpc.servlet.JsonRpcServlet.java

/**
 * /*from  ww  w.  jav  a  2 s  . c o  m*/
 * 
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ServiceContext sc = new ServletConfigServiceContext(getServletConfig());
    HttpServletRequestParameterContext param = new HttpServletRequestParameterContext(req);
    if (param.getValue("sample") == null && param.getValue("method") != null && getMethodEnabled) {
        doProcess(req, resp);
        return;
    }
    ServiceLoader loader = new ServiceLoader(sc, defaultLoaders);
    String sample = param.getValue("sample");
    if (sample != null) {
        resp.setContentType("text/plain");
        resp.setCharacterEncoding("UTF-8");
        PrintWriter os = resp.getWriter();
        String serviceName = getServiceName(req);
        String method = req.getParameter("method");
        os.println("request:");
        printSampleRequest(loader, serviceName, method, os);
        os.println("");
        os.println("");
        os.println("response:");
        printSampleResponse(loader, serviceName, method, os);
        os.flush();
        return;
    }
    String uri = req.getRequestURI();
    String cp = getServletContext().getContextPath();
    int idx = uri.indexOf(cp);
    if (idx == -1) {
        super.doGet(req, resp);
        return;
    }
    int sidx = uri.indexOf('/', idx + cp.length() + 1);
    if (sidx != -1) {
        resp.sendRedirect(uri.substring(idx, sidx));
        return;
    }

    resp.setContentType("text/html");
    resp.setCharacterEncoding("UTF-8");
    PrintWriter w = resp.getWriter();
    w.println("<html><head>");
    w.println(css);
    w.println(js);
    w.println("</head><body>");
    w.println("<h2>And now... Some JsonRpc Services</h2>");
    w.println("<ul>");
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Set<String> names = new TreeSet<String>();
    try {
        for (String s : loader.listServiceNames()) {
            names.add(s);
        }
        int id = 0;
        for (String s : names) {
            w.print("<li><b>" + s);
            ServiceFactory f = loader.loadServiceFactory(cl, s);
            if (f == null) {
                w.println("<font color=\"red\">(Failed to load service factory(null))</font></b></li>");
                continue;
            }
            Object service = f.getService();
            if (service instanceof StreamingNotifier) {
                w.print("(Streaming ready!)");
            }
            String sdesc = RpcAnnotationUtil.getServiceDescriptions(Service.class, "en");
            if (sdesc != null && sdesc.length() > 0) {
                w.print(" - " + StringEscapeUtils.escapeHtml(sdesc));
            }
            w.print("</b><ul>");
            w.print("<li>interfaces<ul>");
            try {
                Set<Class<?>> visited = new HashSet<Class<?>>();
                for (Class<?> intf : f.getInterfaces()) {
                    if (visited.contains(intf))
                        continue;
                    visited.add(intf);
                    if (StreamingNotifier.class.isAssignableFrom(intf))
                        continue;
                    w.print("<li>" + prettyName(intf));
                    String desc = RpcAnnotationUtil.getServiceDescriptions(intf, "en");
                    if (desc != null && desc.length() > 0) {
                        w.print(" - " + StringEscapeUtils.escapeHtml(desc));
                    }
                    w.print("<ul>");
                    try {
                        Set<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
                            public int compare(Method o1, Method o2) {
                                int r = o1.getName().compareTo(o2.getName());
                                if (r != 0)
                                    return r;
                                return o1.getParameterTypes().length - o2.getParameterTypes().length;
                            }
                        });
                        methods.addAll(Arrays.asList(intf.getMethods()));
                        for (Method m : methods) {
                            if (m.isSynthetic())
                                continue;
                            if ((m.getModifiers() & Modifier.PUBLIC) == 0)
                                continue;
                            printMethod(s, m, getImplementedMethod(service, m), id++, w);
                        }
                    } finally {
                        w.println("</ul></li>");
                    }
                }
            } catch (SecurityException e) {
            } finally {
                w.println("</ul></li>");
            }
            w.print("<li>implementation<ul>");
            if (service != null) {
                w.println("<li>" + prettyName(service.getClass()) + "</li>");
                if (service instanceof AbstractCompositeService) {
                    boolean first = true;
                    for (Pair<Invocation, Class<?>> v : ((AbstractCompositeService) service).invocations()) {
                        if (first) {
                            w.println("<li>invocations<ul>");
                            first = false;
                        }
                        w.println(
                                "<li><b>" + v.getFirst().name() + (v.getFirst().required() ? "(required)" : "")
                                        + "</b>: " + prettyName(v.getSecond()) + "</li>");
                    }
                    if (!first) {
                        w.println("</ul></li>");
                    }
                }
            } else {
                w.println("<li><font color=\"red\"><b>failed to load implementation class.</b></font></li>");
            }
            w.println("</ul></li>");
            w.println("</ul></li>");
            w.println("<br/>");
        }
    } catch (IOException e) {
        w.println("<pre><font color=\"red\">");
        e.printStackTrace(w);
        w.println("</font></pre>");
    }
    w.println("</ul>");
    w.println("</body></html>");
}

From source file:org.gradle.build.docs.dsl.source.SourceMetaDataVisitor.java

private int extractModifiers(GroovySourceAST ast) {
    GroovySourceAST modifiers = ast.childOfType(MODIFIERS);
    if (modifiers == null) {
        return 0;
    }/*  w w w.  j a v  a  2 s  .c  o m*/
    int modifierFlags = 0;
    for (GroovySourceAST child = (GroovySourceAST) modifiers
            .getFirstChild(); child != null; child = (GroovySourceAST) child.getNextSibling()) {
        switch (child.getType()) {
        case LITERAL_private:
            modifierFlags |= Modifier.PRIVATE;
            break;
        case LITERAL_protected:
            modifierFlags |= Modifier.PROTECTED;
            break;
        case LITERAL_public:
            modifierFlags |= Modifier.PUBLIC;
            break;
        case FINAL:
            modifierFlags |= Modifier.FINAL;
            break;
        case LITERAL_static:
            modifierFlags |= Modifier.STATIC;
            break;
        }
    }
    return modifierFlags;
}