Package rocket.generator.rebind

Examples of rocket.generator.rebind.GeneratorContext


  /**
   * Creates a factory bean for each bean that will be proxied.
   */
  protected void applyAspects() {
    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Checking for beans with one or more aspects.");

    final Set<Bean> beans = this.filterBeansRequiringInterceptors();

    final Iterator<Bean> advisedIterator = beans.iterator();
    while (advisedIterator.hasNext()) {
      final Bean bean = advisedIterator.next();
      this.buildProxyFactoryBean(bean);

      this.registerProxiedBean(bean);
    }

    context.unbranch();
  }
View Full Code Here


    context.unbranch();
  }

  protected Set<Bean> filterBeansRequiringInterceptors() {
    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.debug("Filtering out Beans that dont have any aspects.");

    final Set<Bean> advised = new HashSet<Bean>();

    final Map<String,Bean> beans = this.getBeans();
    final Iterator<Bean> beansIterator = beans.values().iterator();

    while (beansIterator.hasNext()) {
      final Bean bean = beansIterator.next();
      final List<Aspect> aspectss = bean.getAspects();
      if (aspectss.isEmpty()) {
        context.debug(bean.getId());
        continue;
      }
      advised.add(bean);

      context.debug(bean.getId());
    }
    context.unbranch();

    return advised;
  }
View Full Code Here

   *            The bean being proxied
   */
  protected void buildProxyFactoryBean(final Bean bean) {
    Checker.notNull("parameter:bean", bean);

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

    final String id = bean.getId();
    context.debug(id);

    final Type superType = this.getProxyFactoryBean();

    final NewConcreteType beanFactory = this.getBeanFactory();
    final NewNestedType proxyFactoryBean = beanFactory.newNestedType();
    proxyFactoryBean.setStatic(false);
    proxyFactoryBean.setNestedName(this.escapeBeanIdToBeClassNameSafe(id) + Constants.PROXY_FACTORY_BEAN_SUFFIX);
    proxyFactoryBean.setSuperType(superType);
    proxyFactoryBean.setVisibility(Visibility.PRIVATE);

    bean.setProxyFactoryBean(proxyFactoryBean);

    context.debug("ProxyFactoryBean superType: " + superType);

    final NewNestedType proxy = this.createProxy(bean);
    bean.setProxy(proxy);

    this.overrideProxyFactoryBeanCreateProxy(bean);
View Full Code Here

  /**
   * Adds a new method to the bean factory being built that populates a map
   * with all the factory beans keyed by bean id.
   */
  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();
    newMethod.setBody(body);

    context.branch();
    context.info("Overriding " + newMethod + " to register all beans.");

    final Iterator<Bean> beansIterator = this.getBeans().values().iterator();

    while (beansIterator.hasNext()) {
      final Bean bean = beansIterator.next();
      body.addBean(bean);

      context.debug(bean.getId());
    }
    context.unbranch();
  }
View Full Code Here

  protected void registerBeanAliases() {
    this.overrideBeanFactoryGetAliasesToBeans();
  }

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

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

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

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

    context.branch();
    context.info("Overriding " + newMethod + " to register all aliases.");

    final Iterator<Alias> beansIterator = this.getAliases().values().iterator();
    int aliasCount = 0;

    while (beansIterator.hasNext()) {
      final Alias alias = beansIterator.next();
      final String from = alias.getName();
      final String to = alias.getBean();
      body.register(from, to);

      context.debug(from + "=" + to);
      aliasCount++;
    }

    context.debug("Registered " + aliasCount + " aliases.");
    context.unbranch();
  }
View Full Code Here

   * initialized on factory startup.
   */
  protected void overrideLoadEagerBeans() {
    final Map<String, Bean> beans = this.getBeans();

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Overriding BeanFactory." + Constants.GET_EAGER_SINGELTON_BEAN_NAMES_METHOD
        + "() to initialize eager singleton beans on factory startup.");
    context.branch();

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

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

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

    int eagerSingletonBeanCount = 0;
    int lazySingletonBeanCount = 0;

    final Iterator<Bean> beansIterator = beans.values().iterator();
    while (beansIterator.hasNext()) {
      final Bean bean = (Bean) beansIterator.next();

      if (false == bean.isSingleton()) {
        continue;
      }

      // only singletons can be singletons.
      final boolean eager = bean.isEagerLoaded();
      if (eager) {
        body.addBean(bean.getId());
        eagerSingletonBeanCount++;

        context.debug(bean.toString());
      } else {
        lazySingletonBeanCount++;
      }
    }
    context.unbranch();
    context.debug("When instantiated " + eagerSingletonBeanCount + " singletons will be eaglerly loaded, the remaining "
        + lazySingletonBeanCount + " will be lazily loaded on first request.");
    context.unbranch();
  }
View Full Code Here

   * @param webPageTestRunner
   */
  protected void addBuildCandidates(final NewConcreteType testBuilder, final Type webPageTestRunner) {
    Checker.notNull("parameter:testBuilder", testBuilder);

    final GeneratorContext context = this.getGeneratorContext();

    final Method method = this.getTestBuilder().findMethod(Constants.BUILD_CANDIDATES_METHOD, Collections.EMPTY_LIST);
    final NewMethod newMethod = method.copy(testBuilder);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

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

    final Type voidType = this.getGeneratorContext().getVoid();

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

    // find and add public methods that start with test
    final VirtualMethodVisitor testMethodFinder = new VirtualMethodVisitor() {

      protected boolean visit(final Method method) {

        while (true) {
          if (method.getVisibility() != Visibility.PUBLIC) {
            break;
          }
          if (false == method.getName().startsWith(Constants.TEST_METHOD_NAME_PREFIX)) {
            context.debug("Ignoring method " + method + " because it doesnt start with public.");
            break;
          }

          // test method must return void
          final Type returnType = method.getReturnType();
          if (returnType != voidType) {
            throwTestMethodDoesntReturnVoid(method);
          }

          // test method must have no parameters.
          final List<MethodParameter> parameters = method.getParameters();
          if (false == parameters.isEmpty()) {
            throwTestMethodHasParameters(method);
          }

          // public void test*() method found...
          methods.add(method);
          break;
        }

        return false;
      }

      protected boolean skipJavaLangObjectMethods() {
        return true;
      }
    };
    testMethodFinder.start(webPageTestRunner);

    Collections.sort(methods, new Comparator<Method>() {
      public int compare(final Method method, final Method otherMethod) {
        return TestBuilderGenerator.this.getOrder( method) - TestBuilderGenerator.this.getOrder(otherMethod);
      }
    });

    final Iterator<Method> iterator = methods.iterator();
    while (iterator.hasNext()) {
      final Method testMethod = iterator.next();
      body.addTestMethod(testMethod);
      context.debug("Adding test method " + testMethod);
    }
  }
View Full Code Here

  protected NewConcreteType createObjectWriter(final Type type, final Map serializables) {
    Checker.notNull("parameter:type", type);
    Checker.notNull("parameter:serializables", serializables);

    final GeneratorContext context = this.getGeneratorContext();
    context.debug(type.getName());

    final String newTypeName = this.getGeneratedTypeName(type, SerializationConstants.OBJECT_WRITER_GENERATED_TYPE_SUFFIX,
        "rocket.serialization.client.writer");
    final NewConcreteType newConcreteType = context.newConcreteType(newTypeName);
    newConcreteType.setAbstract(false);
    newConcreteType.setFinal(false);

    context.debug(newTypeName);

    // check super class of type. if its not object extend its object writer
    // rather than cowi.
    Type objectWriterSuperType = null;

    while (true) {
      if (type.isArray()) {
        objectWriterSuperType = this.getArrayWriter();
        break;
      }
      final Type superType = type.getSuperType();
      if (superType.equals(context.getObject())) {
        objectWriterSuperType = this.getObjectWriterImpl();
        break;
      }

      objectWriterSuperType = (Type) serializables.get(type.getSuperType());
      if (null == objectWriterSuperType) {
        throw new IllegalStateException("Unable to fetch the writer for the super type \"" + superType
            + "\" whilst processing \"" + type.getName() + "\".");
      }
      break;
    }

    newConcreteType.setSuperType(objectWriterSuperType);
    context.debug("extends " + objectWriterSuperType);

    newConcreteType.addMetaData(SerializationConstants.SERIALIZABLE_TYPE, type.getName());

    final NewConstructor constructor = newConcreteType.newConstructor();
    constructor.setBody(EmptyCodeBlock.INSTANCE);
View Full Code Here

  protected void overrideObjectWriterWriteMethod0ForArrayType(final NewConcreteType writer, final Type type) {
    Checker.notNull("parameter:writer", writer);
    Checker.notNull("parameter:type", type);

    final GeneratorContext context = this.getGeneratorContext();

    // locate the writeFields method that will be overridden.
    final List<Type> parameterTypes = new ArrayList<Type>();
    parameterTypes.add(context.getObject());
    parameterTypes.add(this.getObjectOutputStream());

    final Method method = writer
        .getMostDerivedMethod(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_WRITE0_METHOD, parameterTypes);
    final NewMethod newMethod = method.copy(writer);
    newMethod.setAbstract(false);

    // rename parameters to the same names used in templates...
    final List newMethodParameters = newMethod.getParameters();
    final NewMethodParameter object = (NewMethodParameter) newMethodParameters.get(0);
    object.setFinal(true);
    object.setName(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_WRITE0_INSTANCE_PARAMETER);

    final NewMethodParameter objectOutputStream = (NewMethodParameter) newMethodParameters.get(1);
    objectOutputStream.setFinal(true);
    objectOutputStream.setName(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_WRITE0_OBJECT_OUTPUT_STREAM_PARAMETER);

    final WriteArrayTemplatedFile body = new WriteArrayTemplatedFile();
    body.setType(type);
    newMethod.setBody(body);

    if (type.getComponentType() == context.getLong()) {
      newMethod.addMetaData("com.google.gwt.core.client.UnsafeNativeLong", "");
    }

    context.debug("Overridden " + newMethod);
  }
View Full Code Here

  protected void overrideObjectWriterWrite0MethodForNonArrayType(final NewConcreteType writer, final Type type) {
    Checker.notNull("parameter:writer", writer);
    Checker.notNull("parameter:type", type);

    final GeneratorContext context = this.getGeneratorContext();

    // locate the writeFields method that will be overridden.
    final List<Type> parameterTypes = new ArrayList<Type>();
    parameterTypes.add(context.getObject());
    parameterTypes.add(this.getObjectOutputStream());

    final Method method = writer
        .getMostDerivedMethod(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_WRITE0_METHOD, parameterTypes);
    final NewMethod newMethod = method.copy(writer);
    newMethod.setAbstract(false);

    // rename parameters to the same names used in templates...
    final List<MethodParameter> newMethodParameters = newMethod.getParameters();
    final NewMethodParameter object = (NewMethodParameter) newMethodParameters.get(0);
    object.setFinal(true);
    object.setName(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_WRITE0_INSTANCE_PARAMETER);

    final NewMethodParameter objectOutputStream = (NewMethodParameter) newMethodParameters.get(1);
    objectOutputStream.setFinal(true);
    objectOutputStream.setName(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_WRITE0_OBJECT_OUTPUT_STREAM_PARAMETER);

    final WriteTemplatedFile body = new WriteTemplatedFile();
    body.setType(type);
    newMethod.setBody(body);

    newMethod.addMetaData(com.google.gwt.core.client.UnsafeNativeLong.class.getName(), "");
    context.debug("Overridden " + newMethod);
  }
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.