Package rocket.generator.rebind

Examples of rocket.generator.rebind.GeneratorContext


  /**
   * Verifies that the incoming serviceInterface is an interface and extends
   * JsonRpcService
   */
  protected void verifyServiceInterface(final Type serviceInterface) {
    final GeneratorContext context = this.getGeneratorContext();
    context.info("Verifying service interface: " + serviceInterface);

    // verify serviceInterface is an interface
    if (false == serviceInterface.isInterface()) {
      this.throwServiceInterfaceIsNotAnInterface(serviceInterface);
    }

    // verify serviceInterface implements JsonRpcService
    final Type requiredServiceInterface = this.getRequiredInterface();
    if (false == serviceInterface.isAssignableTo(requiredServiceInterface)) {
      this.throwDoesntImplementRemoteJsonService(serviceInterface);
    }

    context.debug(serviceInterface.toString());
  }
View Full Code Here


   * @param serviceInterface
   */
  protected void verifyAsyncServiceInterface(final Type serviceInterface) {
    Checker.notNull("parameter:serviceInterface", serviceInterface);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Verifying async interface for : " + serviceInterface);

    try {
      final Type asyncServiceInterface = this.getAsyncServiceInterface(serviceInterface);

      if (false == asyncServiceInterface.isInterface()) {
        this.throwAsyncTypeIsNotAnInterface(asyncServiceInterface);
      }

      context.debug(asyncServiceInterface.toString());

    } catch (final TypeNotFoundException notFound) {
      this.throwUnableToFindAsyncType(serviceInterface);
    }

    context.unbranch();
  }
View Full Code Here

   * @param serviceInterface
   * @param superType
   * @return A new NewConcreteType
   */
  protected NewConcreteType createRpcServiceClient(final String newTypeName, final Type serviceInterface, final Type superType) {
    final GeneratorContext context = this.getGeneratorContext();
    final NewConcreteType type = context.newConcreteType(newTypeName);
    type.setAbstract(false);
    type.setFinal(true);
    type.setSuperType(superType);
    type.setVisibility(Visibility.PUBLIC);

View Full Code Here

      final NewConcreteType client) {
    Checker.notNull("parameter:method", method);
    Checker.notNull("parameter:asyncServiceInterface", asyncServiceInterface);
    Checker.notNull("parameter:remoteJsonClient", client);

    final GeneratorContext context = this.getGeneratorContext();

    final String methodName = method.getName();

    // build up a list of the parameter types for the async method...
    final List<Type> asyncMethodParameters = new ArrayList<Type>();
    final Iterator<MethodParameter> serviceMethodParameters = method.getParameters().iterator();
    while (serviceMethodParameters.hasNext()) {
      final MethodParameter methodParameter = serviceMethodParameters.next();
      asyncMethodParameters.add(methodParameter.getType());
    }
    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);

    // the last parameter must be called "callback"
    final List parameters = newMethod.getParameters();
    final NewMethodParameter callback = (NewMethodParameter) parameters.get(parameters.size() - 1);
    callback.setName(Constants.CALLBACK_PARAMETER);

    context.debug("Finishing renaming parameters, parameters: " + parameters);

    return newMethod;
  }
View Full Code Here

  @Override
  protected NewConcreteType assembleNewType(final Type serviceInterface, final String newTypeName) {
    Checker.notNull("parameter:serviceInterface", serviceInterface);
    GeneratorHelper.checkJavaTypeName("parameter:TypeName", newTypeName);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();

    this.verifyServiceInterface(serviceInterface);
    this.verifyAsyncServiceInterface(serviceInterface);

    final NewConcreteType client = this.createRpcServiceClient(newTypeName, serviceInterface, this.getJsonRpcServiceClient());
    this.implementPublicMethods(serviceInterface, client);

    context.unbranch();
    return client;
  }
View Full Code Here

   */
  protected NewConcreteType subClassCometClient(final String newTypeName, final Type cometClient) {
    GeneratorHelper.checkJavaTypeName("parameter:newTypeName", newTypeName);
    Checker.notNull("parameter:cometClient", cometClient);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info(newTypeName);
    context.debug("extends " + cometClient.getName());
    context.debug("final");

    final NewConcreteType subClass = context.newConcreteType(newTypeName);
    subClass.setAbstract(false);
    subClass.setFinal(true);
    subClass.setSuperType(cometClient);

    context.unbranch();

    return subClass;
  }
View Full Code Here

  protected String getResourceName() {
    String fileName = null;

    while (true) {
      final Type returnType = this.getMethodReturnType();
      final GeneratorContext context = returnType.getGeneratorContext();

      if (returnType.equals(context.getBoolean())) {
        fileName = Constants.BOOLEAN_TEMPLATE;
        break;
      }
      if (returnType.equals(context.getByte())) {
        fileName = Constants.BYTE_TEMPLATE;
        break;
      }
      if (returnType.equals(context.getShort())) {
        fileName = Constants.SHORT_TEMPLATE;
        break;
      }
      if (returnType.equals(context.getInt())) {
        fileName = Constants.INT_TEMPLATE;
        break;
      }
      if (returnType.equals(context.getLong())) {
        fileName = Constants.LONG_TEMPLATE;
        break;
      }
      if (returnType.equals(context.getFloat())) {
        fileName = Constants.FLOAT_TEMPLATE;
        break;
      }
      if (returnType.equals(context.getDouble())) {
        fileName = Constants.DOUBLE_TEMPLATE;
        break;
      }
      if (returnType.equals(context.getChar())) {
        fileName = Constants.CHAR_TEMPLATE;
        break;
      }
      if (returnType.equals(context.getVoid())) {
        fileName = Constants.VOID_TEMPLATE;
        break;
      }
      fileName = Constants.OBJECT_TEMPLATE;
      break;
View Full Code Here

   *            The rpc bean under construction.
   */
  protected void createRpcFactoryBean(final Rpc rpc) {
    Checker.notNull("parameter:rpc", rpc);

    final GeneratorContext context = this.getGeneratorContext();

    rpc.setSingleton(true);
    rpc.setEagerLoaded(false);

    context.debug("singleton");
    context.debug("lazy load");

    final String interfaceName = rpc.getServiceInterface();
    final String id = rpc.getId();
    final Type beanType = this.getInterfaceType(id, interfaceName + Constants.ASYNC_SUFFIX);
    rpc.setType(beanType);

    context.debug("service interface: " + interfaceName);
    context.debug("async service interface: " + beanType.getName());

    final Type superType = this.getSingletonFactoryBean();
    final NewConcreteType beanFactory = this.getBeanFactory();
    final NewNestedType factoryBean = beanFactory.newNestedType();
    factoryBean.setStatic(false);
    factoryBean.setNestedName(this.escapeBeanIdToBeClassNameSafe(id) + Constants.FACTORY_BEAN_SUFFIX);
    factoryBean.setSuperType(superType);
    factoryBean.setVisibility(Visibility.PRIVATE);
    rpc.setFactoryBean(factoryBean);

    context.debug("FactoryBean: " + factoryBean.getName());

    this.addBean(rpc);
  }
View Full Code Here

   *            All the aspects within all xml files.
   */
  protected void buildAspects(final Set<Aspect> aspects) {
    Checker.notNull("parameter:aspects", aspects);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Processing and verifying " + aspects.size() + " aspect(s).");

    final MethodMatcherFactory methodMatcherFactory = createMethodMatcherFactory();

    final Iterator<Aspect> iterator = aspects.iterator();
    while (iterator.hasNext()) {
      final Aspect aspect = iterator.next();

      context.branch();
      final String advisorId = aspect.getAdvisor();
      final String targetBeanId = aspect.getTarget();
      context.debug(advisorId + "=" + targetBeanId);

      aspect.setMethodMatcher(methodMatcherFactory.create(aspect.getMethodExpression()));

      final Bean bean = this.getBean(targetBeanId);
      this.verifyProxyTarget(bean);
      this.verifyAdvisorBean(aspect);
      this.verifyMethodExpression(aspect);

      bean.addAspect(aspect);

      context.unbranch();
    }

    context.unbranch();
  }
View Full Code Here

    final String id = aspect.getTarget();
    final Bean bean = this.getBean(id);
    final Type type = bean.getType();
    final MethodMatcher matcher = aspect.getMethodMatcher();

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.debug("Discovering methods that match: " + matcher + " against " + type);

    final List<Method> matchedMethods = new ArrayList<Method>();
    final Type object = context.getObject();

    final VirtualMethodVisitor visitor = new VirtualMethodVisitor() {

      @Override
      protected boolean visit(final Method method) {
        while (true) {
          if (method.isFinal()) {
            if (false == method.getEnclosingType().equals(object)) {
              BeanFactoryGenerator.this.throwTargetMethodIsFinal(method);
            }
          }
          break;
        }

        if (method.getVisibility() == Visibility.PUBLIC && matcher.matches(method)) {
          matchedMethods.add(method);
          context.debug(method.toString());
        }
        return false;
      }

      @Override
      protected boolean skipJavaLangObjectMethods() {
        return false;
      }
    };
    visitor.start(type);

    if (matchedMethods.isEmpty()) {
      throwNoMatchedMethods(aspect);
    }

    context.debug("Matched " + matchedMethods.size() + " methods(s).");
    context.unbranch();
  }
View Full Code Here

TOP

Related Classes of rocket.generator.rebind.GeneratorContext

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.