Package net.sf.cglib.reflect

Examples of net.sf.cglib.reflect.FastMethod


        for (final WriteablePropertyDescriptor writable : writables)
        {
            EventPropertyDescriptor propertyDesc = new EventPropertyDescriptor(writable.getPropertyName(), writable.getType(), null, false, false, false, false, false);
            desc[count++] = propertyDesc;

            final FastMethod fastMethod = fastClass.getMethod(writable.getWriteMethod());
            writers.put(writable.getPropertyName(), new Pair<EventPropertyDescriptor, BeanEventPropertyWriter>(propertyDesc, new BeanEventPropertyWriter(clazz, fastMethod)));
        }

        writerMap = writers;
        writeablePropertyDescriptors = desc;
View Full Code Here


                                                               ScheduleBucket scheduleBucket,
                                                               ExprEvaluatorContext exprEvaluatorContext)
            throws ExprValidationException
    {
        // Try to resolve the method
        FastMethod staticMethod;
        Class declaringClass;
        try
    {
      Method method = methodResolutionService.resolveMethod(methodStreamSpec.getClassName(), methodStreamSpec.getMethodName());
            declaringClass = method.getDeclaringClass();
            FastClass declaringFastClass = FastClass.create(Thread.currentThread().getContextClassLoader(), method.getDeclaringClass());
      staticMethod = declaringFastClass.getMethod(method);
    }
    catch(Exception e)
    {
      throw new ExprValidationException(e.getMessage());
    }

        // Determine object type returned by method
        Class beanClass = staticMethod.getReturnType();
        if ((beanClass == void.class) || (beanClass == Void.class) || (JavaClassHelper.isJavaBuiltinDataType(beanClass)))
        {
            throw new ExprValidationException("Invalid return type for static method '" + staticMethod.getName() + "' of class '" + methodStreamSpec.getClassName() + "', expecting a Java class");
        }
        if (staticMethod.getReturnType().isArray())
        {
            beanClass = staticMethod.getReturnType().getComponentType();
        }

        // If the method returns a Map, look up the map type
        Map<String, Object> mapType = null;
        String mapTypeName = null;
        if ( (JavaClassHelper.isImplementsInterface(staticMethod.getReturnType(), Map.class)) ||
             (staticMethod.getReturnType().isArray() && JavaClassHelper.isImplementsInterface(staticMethod.getReturnType().getComponentType(), Map.class)) )
        {
            MethodMetadataDesc metadata = getCheckMetadata(methodStreamSpec.getMethodName(), methodStreamSpec.getClassName(), methodResolutionService, Map.class);
            mapTypeName = metadata.getTypeName();
            mapType = (Map<String, Object>) metadata.getTypeMetadata();
        }

        // If the method returns an Object[] or Object[][], look up the type information
        LinkedHashMap<String, Object> oaType = null;
        String oaTypeName = null;
        if (staticMethod.getReturnType() == Object[].class || staticMethod.getReturnType() == Object[][].class)
        {
            MethodMetadataDesc metadata = getCheckMetadata(methodStreamSpec.getMethodName(), methodStreamSpec.getClassName(), methodResolutionService, LinkedHashMap.class);
            oaTypeName = metadata.getTypeName();
            oaType = (LinkedHashMap<String, Object>) metadata.getTypeMetadata();
        }

        // Determine event type from class and method name
        EventType eventType;
        if (mapType != null) {
            eventType = eventAdapterService.addNestableMapType(mapTypeName, mapType, null, false, true, true, false, false);
        }
        else if (oaType != null) {
            eventType = eventAdapterService.addNestableObjectArrayType(oaTypeName, oaType, null, false, true, true, false, false);
        }
        else {
            eventType = eventAdapterService.addBeanType(beanClass.getName(), beanClass, false, true, true);
        }

        // Construct polling strategy as a method invocation
        ConfigurationMethodRef configCache = engineImportService.getConfigurationMethodRef(declaringClass.getName());
        if (configCache == null)
        {
            configCache = engineImportService.getConfigurationMethodRef(declaringClass.getSimpleName());
        }
        ConfigurationDataCache dataCacheDesc = (configCache != null) ? configCache.getDataCacheDesc() : null;
        DataCache dataCache = DataCacheFactory.getDataCache(dataCacheDesc, epStatementAgentInstanceHandle, schedulingService, scheduleBucket);
        PollExecStrategy methodPollStrategy;
        if (mapType != null) {
            if (staticMethod.getReturnType().isArray()) {
                methodPollStrategy = new MethodPollingExecStrategyMapArray(eventAdapterService, staticMethod, eventType);
            }
            else {
                methodPollStrategy = new MethodPollingExecStrategyMapPlain(eventAdapterService, staticMethod, eventType);
            }
        }
        else if (oaType != null) {
            if (staticMethod.getReturnType() == Object[][].class) {
                methodPollStrategy = new MethodPollingExecStrategyOAArray(eventAdapterService, staticMethod, eventType);
            }
            else {
                methodPollStrategy = new MethodPollingExecStrategyOAPlain(eventAdapterService, staticMethod, eventType);
            }
        }
        else {
            if (staticMethod.getReturnType().isArray()) {
                methodPollStrategy = new MethodPollingExecStrategyPOJOArray(eventAdapterService, staticMethod, eventType);
            }
            else {
                methodPollStrategy = new MethodPollingExecStrategyPOJOPlain(eventAdapterService, staticMethod, eventType);
            }
View Full Code Here

    public boolean isAlive() {
        return method != null;
    }

    public static FastMethod discover(Introspector is, Class<?> clazz, String property) {
        FastMethod method = discoverGet(is, "get", clazz, property);
        if (method == null) {
            // 尝试一下"is"方法
            method = discoverGet(is, "is", clazz, property);
        }
        return method;
View Full Code Here

        }
        return method;
    }

    public static FastMethod discoverGet(Introspector is, String which, Class<?> clazz, String property) {
        FastMethod method = null;
        final int start = which.length(); // "get" or "is" 情况处理
        StringBuilder sb = new StringBuilder(which);
        sb.append(property);
        char c = sb.charAt(start);
        sb.setCharAt(start, Character.toUpperCase(c));// 转化为 getXxx()
View Full Code Here

        String[] getters = new String[fields.length];
        String[] setters = new String[fields.length];
        for (int i = 0; i < fields.length; i++) {
            String property = fields[i];
            Class arg = args[i];
            FastMethod setMethod = FastPropertySetExecutor.discover(is, clazz, property, arg);
            FastMethod getMethod = FastPropertyGetExecutor.discover(is, clazz, property);
            if (setMethod == null) {
                throw new BeanMappingException("class[" + clazz.getName() + "] field[" + property + "] arg["
                                               + arg.getName() + "] set Method is not exist!");
            }

            if (getMethod == null) {
                throw new BeanMappingException("class[" + clazz.getName() + "] field[" + property
                                               + "] get Method is not exist!");
            }

            if (getMethod.getReturnType() != arg) {
                throw new BeanMappingException("class[" + clazz.getName() + "] field[" + property
                                               + "] getMethod does not match declared type");
            }
            setters[i] = setMethod.getName();
            getters[i] = getMethod.getName();
        }

        bulkBean = BulkBean.create(clazz, getters, setters, args);
        return bulkBean;
    }
View Full Code Here

                return fc.getMethod(method);
            } else {
                return null;
            }
        } else {// 明确指定参数,根据method name + param进行查找
            FastMethod fastMethod = is.getFastMethod(clazz, sb.toString(), arg);
            // lowercase nth char
            if (fastMethod == null) {
                sb.setCharAt(start, Character.toLowerCase(c));
                fastMethod = is.getFastMethod(clazz, sb.toString(), arg);
            }
View Full Code Here

     */
    public FastMethod getFastMethod(Class<?> clazz, String methodName, Class... parameterTypes) {
        String clazzName = clazz.getName();
        String methodKey = buildMethodKey(clazzName, methodName, parameterTypes);

        FastMethod method = fastMethodCache.get(methodKey);
        if (null == method) {
            getFastClass(clazz);// 分析一次clazz,这时会跟新fastMethodCache
            return fastMethodCache.get(methodKey);
        } else {
            return method;
View Full Code Here

                Set<WriteablePropertyDescriptor> props = PropertyHelper.getWritableProperties(beanClass);
                writers = new HashMap<String, BeanEventPropertyWriter>();
                writersMap.put(beanClass, writers);
                FastClass fastClass = FastClass.create(beanClass);
                for (WriteablePropertyDescriptor prop : props) {
                    FastMethod writerMethod = fastClass.getMethod(prop.getWriteMethod());
                    writers.put(prop.getPropertyName(), new BeanEventPropertyWriter(beanClass, writerMethod));
                }
                // populate writers
            }
View Full Code Here

                                                               ScheduleBucket scheduleBucket,
                                                               ExprEvaluatorContext exprEvaluatorContext)
            throws ExprValidationException
    {
        // Try to resolve the method
        FastMethod staticMethod;
        Class declaringClass;
        try
    {
      Method method = methodResolutionService.resolveMethod(methodStreamSpec.getClassName(), methodStreamSpec.getMethodName());
            declaringClass = method.getDeclaringClass();
            FastClass declaringFastClass = FastClass.create(Thread.currentThread().getContextClassLoader(), method.getDeclaringClass());
      staticMethod = declaringFastClass.getMethod(method);
    }
    catch(Exception e)
    {
      throw new ExprValidationException(e.getMessage());
    }

        // Determine object type returned by method
        Class beanClass = staticMethod.getReturnType();
        if ((beanClass == void.class) || (beanClass == Void.class) || (JavaClassHelper.isJavaBuiltinDataType(beanClass)))
        {
            throw new ExprValidationException("Invalid return type for static method '" + staticMethod.getName() + "' of class '" + methodStreamSpec.getClassName() + "', expecting a Java class");
        }
        if (staticMethod.getReturnType().isArray())
        {
            beanClass = staticMethod.getReturnType().getComponentType();
        }

        // If the method returns a Map, look up the map type
        Map<String, Object> mapType = null;
        String mapTypeName = null;
        if ( (JavaClassHelper.isImplementsInterface(staticMethod.getReturnType(), Map.class)) ||
             (staticMethod.getReturnType().isArray() && JavaClassHelper.isImplementsInterface(staticMethod.getReturnType().getComponentType(), Map.class)) )
        {
            Method typeGetterMethod = null;
            String getterMethodName = methodStreamSpec.getMethodName() + "Metadata";
            try
            {
View Full Code Here

                allConstants = false;
            }
        }

        // Try to resolve the method
        final FastMethod staticMethod;
        Method method;
        try
        {
            if (optionalClass != null) {
                method = methodResolutionService.resolveMethod(optionalClass, methodName, paramTypes, allowEventBeanType, allowEventBeanCollType);
View Full Code Here

TOP

Related Classes of net.sf.cglib.reflect.FastMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.