Package rocket.generator.rebind.method

Examples of rocket.generator.rebind.method.Method


    }
    asyncMethodParameters.add(this.getAsyncCallback());

    // make sure that a method with the same signature actually exists on
    // the async interface...
    Method asyncMethod = asyncServiceInterface.findMostDerivedMethod(methodName, asyncMethodParameters);
    if (null == asyncMethod) {
      this.throwMatchingAsyncInterfaceMethodNotFoundException(method);
    }
    if (false == asyncMethod.returnsVoid()) {
      this.throwIncompatibleMethodFound(asyncMethod);
    }
    context.debug("Found matching async interface method: " + asyncMethod);

    // create the method on client...
    final NewMethod newMethod = asyncMethod.copy(client);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);

    // rename all parameters to parameterN
    GeneratorHelper.renameParametersToParameterN(newMethod);
View Full Code Here


  protected void overrideFactoryBeanCreateInstanceFactoryMethod(final Bean bean) {
    Checker.notNull("parameter:bean", bean);

    final Type beanType = bean.getType();
    final String factoryMethodName = bean.getFactoryMethod();
    final Method factoryMethod = beanType.findMethod(factoryMethodName, Collections.<Type>emptyList() );
    if (null == factoryMethod || false == factoryMethod.isStatic() || factoryMethod.getVisibility() != Visibility.PUBLIC) {
      this.throwFactoryMethodNotFound(bean, factoryMethodName);
    }

    this.getGeneratorContext().debug("FactoryBean will create new instance by calling " + factoryMethod);
View Full Code Here

  }

  protected NewMethod createCreateInstanceMethod(final NewType factoryBean) {
    Checker.notNull("parameter:factoryBean", factoryBean);

    final Method method = factoryBean.getMostDerivedMethod(Constants.CREATE_INSTANCE, Collections.<Type>emptyList());

    final NewMethod newMethod = method.copy(factoryBean);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

    return newMethod;
View Full Code Here

  protected void overrideFactoryBeanSatisfyInit(final Bean bean) {
    Checker.notNull("parameter:bean", bean);

    final Type beanType = bean.getType();
    final String initMethodName = bean.getInitMethod();
    final Method initMethod = beanType.findMethod(initMethodName, Collections.<Type>emptyList());
    if (null == initMethod || initMethod.isStatic() || initMethod.getVisibility() != Visibility.PUBLIC) {
      throwInitMethodNotFound(bean, initMethodName);
    }

    final GeneratorContext context = this.getGeneratorContext();
    context.debug("Overriding satisfyInit to call " + initMethod);

    final NewType beanFactory = bean.getFactoryBean();
    final Method beanFactoryInitMethod = beanFactory.getMostDerivedMethod(Constants.SATISFY_INIT, this
        .getParameterListWithOnlyObject());
    final NewMethod newMethod = beanFactoryInitMethod.copy(beanFactory);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

    final InvokeMethodTemplatedFile body = new InvokeMethodTemplatedFile();
View Full Code Here

  protected void overrideFactoryBeanSatisfyPropertiesWithSettingServiceEntryPoint(final Rpc rpc) {
    Checker.notNull("parameter:rpc", rpc);

    final NewType factoryBean = rpc.getFactoryBean();

    final Method method = factoryBean.getMostDerivedMethod(Constants.SATISFY_PROPERTIES, this.getParameterListWithOnlyObject());
    final NewMethod newMethod = method.copy(factoryBean);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

    final SetPropertiesTemplatedFile body = new SetPropertiesTemplatedFile();
    newMethod.setBody(body);

    final NewMethodParameter instanceParameter = (NewMethodParameter) newMethod.getParameters().get(0);
    instanceParameter.setFinal(true);
    instanceParameter.setName(Constants.SATISFY_PROPERTIES_INSTANCE_PARAMETER);

    final Type serviceDefTarget = this.getServiceDefTarget();
    body.setBean(serviceDefTarget);

    final GeneratorContext context = this.getGeneratorContext();

    final Type string = context.getString();
    final Method setter = serviceDefTarget.getMostDerivedMethod(Constants.SET_SERVICE_ENTRY_POINT, Collections.nCopies(1, string));
    final StringValue addressValue = new StringValue();
    addressValue.setGeneratorContext(context);
    addressValue.setType(string);

    final String serviceEntryPoint = rpc.getServiceEntryPoint();
View Full Code Here

    final SetPropertiesTemplatedFile body = new SetPropertiesTemplatedFile();
    body.setBean(beanType);

    final NewType factoryBean = bean.getFactoryBean();
    final Method method = factoryBean.getMostDerivedMethod(Constants.SATISFY_PROPERTIES, this.getParameterListWithOnlyObject());

    final NewMethod newMethod = method.copy(factoryBean);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

    final NewMethodParameter instanceParameter = (NewMethodParameter) newMethod.getParameters().get(0);
    instanceParameter.setFinal(true);
    instanceParameter.setName(Constants.SATISFY_PROPERTIES_INSTANCE_PARAMETER);

    newMethod.setBody(body);

    // loop thru all properties
    final Set<Property> properties = bean.getProperties();
    final Iterator<Property> propertyIterator = properties.iterator();
    while (propertyIterator.hasNext()) {
      final Property property = propertyIterator.next();
      final String propertyName = property.getName();
      final String setterName = GeneratorHelper.buildSetterName(propertyName);

      final Value value = property.getValue();
      this.prepareValue(value);

      final List<Method> matchingSetters = new ArrayList<Method>();

      final VirtualMethodVisitor visitor = new VirtualMethodVisitor() {
        protected boolean visit(final Method method) {

          while (true) {
            // names dont match
            if (false == method.getName().equals(setterName)) {
              break;
            }
            // return type must be void
            if (false == method.getReturnType().equals(voidType)) {
              break;
            }
            // parameter types must be compatible...
            final List<MethodParameter> parameters = method.getParameters();
            if (parameters.size() != 1) {
              break;
            }

            final MethodParameter parameter = (MethodParameter) parameters.get(0);
            final Type propertyType = parameter.getType();
            if (false == value.isCompatibleWith(propertyType)) {
              break;
            }

            value.setPropertyType(propertyType);
            matchingSetters.add(method);
            break;
          }

          return false;
        }

        protected boolean skipJavaLangObjectMethods() {
          return true;
        }
      };

      visitor.start(beanType);
      if (matchingSetters.isEmpty()) {
        this.throwUnableToFindSetter(bean, property);
      }
      if (matchingSetters.size() != 1) {
        this.throwTooManySettersFound(bean, property);
      }

      final Method setter = (Method) matchingSetters.get(0);
      body.addProperty(setter, value);

      context.debug(propertyName + "=" + value);
    }
  }
View Full Code Here

  protected void overrideSingletonFactoryBeanDestroy(final Bean bean) {
    Checker.notNull("parameter:bean", bean);

    final Type beanType = bean.getType();
    final String destroyMethodName = bean.getDestroyMethod();
    final Method destroyMethod = beanType.findMethod(destroyMethodName, Collections.<Type>emptyList());
    if (null == destroyMethod || destroyMethod.isStatic() || destroyMethod.getVisibility() != Visibility.PUBLIC) {
      throwCustomMethodNotFound(bean, destroyMethodName);
    }

    final GeneratorContext context = this.getGeneratorContext();
    context.debug("Overriding destroy to call " + destroyMethod + " for bean: " + bean);

    final NewType beanFactory = bean.getFactoryBean();
    final Method beanFactoryInitMethod = beanFactory.getMostDerivedMethod(Constants.DESTROY, this.getParameterListWithOnlyObject());
    final NewMethod newMethod = beanFactoryInitMethod.copy(beanFactory);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

    final InvokeMethodTemplatedFile body = new InvokeMethodTemplatedFile();
View Full Code Here

    body.setMethod(newMethod);
    body.setTargetMethod(method);

    final Type methodInterceptor = this.getMethodInterceptor();
    final List<Type> methodInvocationParameterList = Arrays.asList(new Type[] { this.getMethodInvocation() });
    final Method invoke = methodInterceptor.getMethod(Constants.METHOD_INTERCEPTOR_INVOKE, methodInvocationParameterList);
    final MethodParameter target = (MethodParameter) invoke.getParameters().get(0);

    body.setTarget(target);
    newMethod.setBody(body);
  }
View Full Code Here

  protected void overrideProxyFactoryBeanCreateProxy(final Bean bean) {
    Checker.notNull("parameter:bean", bean);

    final NewNestedType proxyFactoryBean = bean.getProxyFactoryBean();
    final List<Type> objectParameterList = this.getParameterListWithOnlyObject();
    final Method method = proxyFactoryBean.getMostDerivedMethod(Constants.CREATE_PROXY, objectParameterList);

    final NewMethod newMethod = method.copy(proxyFactoryBean);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

    // add a new constructor...
View Full Code Here

  protected void overrideBeanFactoryRegisterFactoryBeans() {
    final GeneratorContext context = this.getGeneratorContext();
    context.branch();

    final NewType beanFactory = this.getBeanFactory();
    final Method abstractMethod = beanFactory.getSuperType().getMostDerivedMethod(Constants.REGISTER_FACTORY_BEANS, Collections.<Type>emptyList());

    final NewMethod newMethod = abstractMethod.copy(beanFactory);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

    final RegisterFactoryBeansTemplatedFile body = new RegisterFactoryBeansTemplatedFile();
View Full Code Here

TOP

Related Classes of rocket.generator.rebind.method.Method

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.