Package rocket.generator.rebind

Examples of rocket.generator.rebind.GeneratorContext


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

    final GeneratorContext context = this.getGeneratorContext();

    final NewMethod newMethod = writer.newMethod();
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setName(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_WRITE_FIELDS_METHOD);
    newMethod.setNative(false);
    newMethod.setReturnType(context.getVoid());
    newMethod.setStatic(false);
    newMethod.setVisibility(Visibility.PUBLIC);

    final NewMethodParameter instance = newMethod.newParameter();
    instance.setFinal(true);
    instance.setName(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_WRITE_FIELDS_INSTANCE_PARAMETER);
    instance.setType(type);

    final NewMethodParameter objectOutputStream = newMethod.newParameter();
    objectOutputStream.setFinal(true);
    objectOutputStream.setName(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_WRITE_FIELDS_OBJECT_OUTPUT_STREAM_PARAMETER);
    objectOutputStream.setType(this.getObjectOutputStream());

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

    // add all fields to the template
    final Iterator fields = this.filterSerializableFields(type.getFields()).iterator();
    int fieldCount = 0;

    context.branch();

    while (fields.hasNext()) {
      final Field field = (Field) fields.next();
      final Method getter = this.createFieldGetter(writer, field);
      body.addFieldGetter(getter);

      fieldCount++;
    }

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


   */
  protected Method createFieldGetter(final NewConcreteType writer, final Field field) {
    Checker.notNull("parameter:writer", writer);
    Checker.notNull("parameter:field", field);

    final GeneratorContext context = this.getGeneratorContext();
    final GetFieldTemplatedFile body = new GetFieldTemplatedFile();
    body.setField(field);

    final NewMethod method = writer.newMethod();
    method.setAbstract(false);
    method.setBody(body);
    method.setFinal(true);
    method.setName(GeneratorHelper.buildGetterName(field.getName()));
    method.setNative(true);

    final Type fieldType = field.getType();
    method.setReturnType(fieldType);
    method.setStatic(false);
    method.setVisibility(Visibility.PRIVATE);

    if (fieldType.equals(context.getLong())) {
      method.addMetaData("com.google.gwt.core.client.UnsafeNativeLong", "");
    }
    // add a parameter
    final NewMethodParameter instance = method.newParameter();
    instance.setFinal(true);
    instance.setName(SerializationConstants.CLIENT_OBJECT_WRITER_IMPL_FIELD_GETTER_INSTANCE_PARAMETER);
    instance.setType(field.getEnclosingType());

    context.debug(field.getName());
    return method;
  }
View Full Code Here

   * @return
   */
  protected NewConcreteType createSerializableFactory(final String newTypeName) {
    Checker.notEmpty("parameter:newTypeName", newTypeName);

    final GeneratorContext context = this.getGeneratorContext();
    context.info("Creating serialization factory " + newTypeName);

    final NewConcreteType serializationFactory = context.newConcreteType(newTypeName);
    serializationFactory.setAbstract(false);
    serializationFactory.setFinal(true);
    serializationFactory.setSuperType(this.getSerializationFactory());
    return serializationFactory;
  }
View Full Code Here

  protected void overrideSerializationFactoryGetObjectReader(final NewConcreteType serializationFactory,
      final Map<Type, Type> objectReaders) {
    Checker.notNull("parameter:serializationFactory", serializationFactory);
    Checker.notNull("parameter:objectReaders", objectReaders);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.debug("Overriding \"" + SerializationConstants.SERIALIZATION_FACTORY_GET_OBJECT_READER
        + "\" to register needed ObjectReaders.");

    final Method method = serializationFactory.getMostDerivedMethod(SerializationConstants.SERIALIZATION_FACTORY_GET_OBJECT_READER,
        Collections.nCopies(1, context.getString()));
    final NewMethod newMethod = method.copy(serializationFactory);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(true);

    final SwitchTemplatedFile body = new SwitchTemplatedFile();

    final Iterator<Map.Entry<Type, Type>> iterator = objectReaders.entrySet().iterator();
    while (iterator.hasNext()) {
      final Map.Entry<Type, Type> entry = iterator.next();

      final Type type = entry.getKey();
      if (false == this.isSerializable(type)) {
        continue;
      }

      final Type objectReader = entry.getValue();
      final Field objectReaderSingleton = objectReader.getField(SerializationConstants.SINGLETON);

      body.register(type, objectReaderSingleton);

      context.debug(type.getName() + " = " + objectReader.getName());
    }

    newMethod.setBody(body);

    context.unbranch();
  }
View Full Code Here

   *         document to beans.
   */
  protected DocumentWalker getDocumentWalker(final Type type) {
    final String fileName = this.getResourceName(type, Constants.BEAN_FILE_SUFFIX);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Preparing to discover components within \"" + fileName + "\".");

    final DocumentWalker document = new DocumentWalker();
    document.setEntityResolver(new BeanFactoryDtdEntityResolver());
    document.setErrorHandler(new RethrowSaxExceptionsErrorHandler());
    document.setGenerator(this);
    document.process(fileName);

    context.unbranch();

    return document;
  }
View Full Code Here

  protected void overrideSerializationFactoryGetObjectWriter(final NewConcreteType serializationFactory,
      final Map<Type, Type> objectWriters) {
    Checker.notNull("parameter:serializationFactory", serializationFactory);
    Checker.notNull("parameter:objectWriters", objectWriters);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.debug("Overriding \"" + SerializationConstants.SERIALIZATION_FACTORY_GET_OBJECT_WRITER
        + "\" to register needed ObjectWriters.");

    final Method method = serializationFactory.getMostDerivedMethod(SerializationConstants.SERIALIZATION_FACTORY_GET_OBJECT_WRITER,
        Collections.nCopies(1, context.getString()));
    final NewMethod newMethod = method.copy(serializationFactory);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(true);

    final SwitchTemplatedFile body = new SwitchTemplatedFile();

    final Iterator<Map.Entry<Type, Type>> iterator = objectWriters.entrySet().iterator();
    while (iterator.hasNext()) {
      final Map.Entry<Type, Type> entry = iterator.next();

      final Type type = entry.getKey();
      if (false == this.isSerializable(type)) {
        continue;
      }

      final Type objectWriter = entry.getValue();
      final Field objectWriterSingleton = objectWriter.getField(SerializationConstants.SINGLETON);

      body.register(type, objectWriterSingleton);

      context.debug(type.getName() + " = " + objectWriter.getName());
    }

    newMethod.setBody(body);

    context.unbranch();
  }
View Full Code Here

   *            bean type interface
   */
  protected void verifyBeanFactory(final Type type) {
    Checker.notNull("parameter:type", type);

    final GeneratorContext context = this.getGeneratorContext();
    context.info("Verifying " + type + " is a bean factory.");

    final Type beanFactory = this.getBeanFactoryType();
    if (false == type.isAssignableTo(beanFactory)) {
      throwNotABeanFactory("The type \"" + type + "\" is not a " + beanFactory);
    }
View Full Code Here

   *            A set containing all beans
   */
  protected void buildFactoryBeans(final Set<Bean> beans) {
    Checker.notNull("parameter:beans", beans);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Creating FactoryBean's for all beans.");

    final Iterator<Bean> iterator = beans.iterator();
    int nestedBeanCounter = 0;
    int rpcCounter = 0;
    int beansCounter = 0;

    while (iterator.hasNext()) {
      final Bean bean = iterator.next();
      context.branch();

      context.debug(bean.getId());

      while (true) {
        if (bean instanceof Rpc) {
          this.createRpcFactoryBean((Rpc) bean);
          rpcCounter++;
          break;
        }
        if (bean instanceof NestedBean) {
          this.createBeanFactoryBean(bean);
          nestedBeanCounter++;
          break;
        }

        this.createBeanFactoryBean(bean);
        beansCounter++;
        break;
      }

      context.unbranch();
    }

    context.debug("Total: " + beans.size() + ", beans: " + beansCounter + ", nested(anonymous): " + nestedBeanCounter + ", rpcs: "
        + rpcCounter);
    context.unbranch();
  }
View Full Code Here

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

    final GeneratorContext context = this.getGeneratorContext();

    final String beanName = bean.getId();
    if (Tester.isNullOrEmpty(beanName)) {
      throwBeanIdIsMissing(bean);
    }
    this.checkIdIsUnique(bean);

    final String className = bean.getTypeName();
    final Type beanType = this.getConcreteType(beanName, className);
    bean.setType(beanType);

    context.debug(beanType.getName());

    final boolean singleton = bean.isSingleton();
    bean.setSingleton(singleton);
    context.debug(singleton ? "singleton" : "prototype");

    // process the eager/lazy attribute
    final boolean eager = bean.isEagerLoaded();
    bean.setEagerLoaded(eager);
    this.checkPrototypesAreNotMarkedAsEager(bean);

    if (singleton) {
      context.debug(eager ? "eager" : "lazyloaded");
    }

    if (false == singleton) {
      final String destroyMethod = bean.getDestroyMethod();
      if (false == Tester.isNullOrEmpty(destroyMethod)) {
        throwPrototypeCantBeContainerDestroyed(bean);
      }

      final Type disposableBean = this.getDisposableBean();
      if (beanType.isAssignableTo(disposableBean)) {
        context.warn("Ignoring the fact the bean implements DisposableBean (because its a prototype)"
            + (context.isDebugEnabled() ? "." : ", bean: " + bean));
      }
    }

    // start creating the factory bean...
    final Type superType = singleton ? this.getSingletonFactoryBean() : this.getPrototypeFactoryBean();
    final NewConcreteType beanFactory = this.getBeanFactory();
    final NewNestedType factoryBean = beanFactory.newNestedType();
    factoryBean.setStatic(false);
    factoryBean.setNestedName(this.escapeBeanIdToBeClassNameSafe(beanName) + Constants.FACTORY_BEAN_SUFFIX);
    factoryBean.setSuperType(superType);
    factoryBean.setVisibility(Visibility.PRIVATE);

    // add an annotation that declares the actual bean type.
    factoryBean.addMetaData(Constants.FACTORY_BEAN_OBJECT_TYPE, bean.getType().getName());

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

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

   *            documents.
   */
  protected void overrideAllFactoryBeanCreateInstances(final Set<Bean> beans) {
    Checker.notNull("parameter:beans", beans);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Overriding createInstance methods for all bean(s).");

    final Iterator<Bean> iterator = beans.iterator();
    while (iterator.hasNext()) {
      final Bean bean = iterator.next();
      context.branch();
      context.debug(bean.getId());

      this.overrideFactoryBeanCreateInstance(bean);

      context.unbranch();
    }

    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.