Package rocket.generator.rebind

Examples of rocket.generator.rebind.GeneratorContext


  protected String getResourceName() {
    String fileName = null;

    while (true) {
      final MethodParameter parameter = this.getParameter();
      final GeneratorContext context = parameter.getGeneratorContext();
      final Type type = parameter.getType();
      if (type.equals(context.getBoolean())) {
        fileName = Constants.BOOLEAN;
        break;
      }
      if (type.equals(context.getByte())) {
        fileName = Constants.BYTE;
        break;
      }
      if (type.equals(context.getShort())) {
        fileName = Constants.SHORT;
        break;
      }
      if (type.equals(context.getInt())) {
        fileName = Constants.INT;
        break;
      }
      if (type.equals(context.getLong())) {
        fileName = Constants.LONG;
        break;
      }
      if (type.equals(context.getFloat())) {
        fileName = Constants.FLOAT;
        break;
      }
      if (type.equals(context.getDouble())) {
        fileName = Constants.DOUBLE;
        break;
      }
      if (type.equals(context.getChar())) {
        fileName = Constants.CHAR;
        break;
      }
      fileName = Constants.OBJECT;
      break;
View Full Code Here


    // generate readers and then writers
    this.createObjectReaders(serializableReadableTypes, typesToReaders);
    this.createObjectWriters(serializableWritableTypes, typesToWriters);

    // nows the time to create the SerializationFactory
    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    final NewConcreteType serializationFactory = this.createSerializableFactory(newTypeName);

    this.overrideSerializationFactoryGetObjectReader(serializationFactory, typesToReaders);
    this.overrideSerializationFactoryGetObjectWriter(serializationFactory, typesToWriters);
    context.unbranch();

    return serializationFactory;

  }
View Full Code Here

   * expressions.
   *
   * @return A set containing all blacklisted packages.
   */
  protected Set<TypeMatcher> loadBlackLists() {
    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Attempting to load and merge all blacklists (unsorted).");

    final Set<TypeMatcher> blackLists = new HashSet<TypeMatcher>();

    final SubTypesVisitor packageVisitor = new SubTypesVisitor() {

      @Override
      protected boolean visit(final Type type) {
        final Package packagee = type.getPackage();
        if (false == this.packages.contains(packagee)) {
          this.packages.add(packagee);

          final Set<TypeMatcher> loaded = SerializationFactoryGenerator.this.loadBlackListFromPackage(packagee);
          blackLists.addAll(loaded);
        }
        return false;
      }

      @Override
      protected boolean skipInitialType() {
        return false;
      }

      Set<Package> packages = new HashSet<Package>();
    };
    packageVisitor.start(context.getObject());

    context.unbranch();

    return blackLists;
  }
View Full Code Here

   * @return A set of types or an empty set if the black list was not found.
   */
  protected Set<TypeMatcher> loadBlackListFromPackage(final Package packagee) {
    Checker.notNull("parameter:package", packagee);

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

    final Set<TypeMatcher> expressions = new HashSet<TypeMatcher>();

    final String fileName = this.getResourceName(packagee, SerializationConstants.BLACKLIST_FILENAME);
    InputStream inputStream = null;

    while (true) {
      try {
        inputStream = this.getClass().getResourceAsStream(fileName);
        if (null == inputStream) {
          break;
        }
        // context.debug(fileName);

        // use a BufferedReader to read a line at a time skipping
        // comments and empty lines.
        final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

        while (true) {
          final String line = reader.readLine();
          // eof reached...
          if (null == line) {
            break;
          }

          // skip empty / comment lines...
          final String typeName = line.trim();
          if (Tester.isNullOrEmpty(typeName) || typeName.startsWith("#")) {
            continue;
          }
          context.debug(line);

          final TypeMatcher typeNameMatcher = TypeMatcherFactory.createTypeNameMatcher(typeName);
          expressions.add(typeNameMatcher);
        }

        break;

      } catch (final RuntimeException caught) {
        throw caught;
      } catch (final Exception caught) {
        throw new SerializationFactoryGeneratorException("Failed to load black list, message: " + caught.getMessage(), caught);
      } finally {
        InputOutput.closeIfNecessary(inputStream);
      }
    }

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

   * @return
   */
  protected Set<Type> getAllSerializableTypes() {
    final Set<Type> allTypes = new HashSet<Type>();

    final GeneratorContext context = this.getGeneratorContext();
    final Iterator<Type> types = context.getObject().getSubTypes().iterator();
    while (types.hasNext()) {
      final Type type = types.next();
      if (this.isBlackListed(type)) {
        continue;
      }

      allTypes.add(type);
    }

    // TODO hack need to add proper support for arrays
    allTypes.add(context.getType("boolean[]"));
    allTypes.add(context.getType("byte[]"));
    allTypes.add(context.getType("short[]"));
    allTypes.add(context.getType("int[]"));
    allTypes.add(context.getType("long[]"));
    allTypes.add(context.getType("float[]"));
    allTypes.add(context.getType("double[]"));
    allTypes.add(context.getType("char[]"));
    return allTypes;
  }
View Full Code Here

   * @return
   */
  protected Map<Type, Type> findAllReaders(final Set<Type> types) {
    Checker.notNull("parameter:types", types);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Finding existing ObjectReaders...");

    final ObjectReaderFinder finder = new ObjectReaderFinder() {
      @Override
      protected Type getImplementingInterface() {
        return SerializationFactoryGenerator.this.getObjectReader();
      }

      @Override
      protected boolean shouldBeSerialized(final Type type) {
        return SerializationFactoryGenerator.this.isOrHasSerializableSubType(type);
      }
    };

    final Map<Type, Type> typesToReaders = finder.build(types);

    this.logMapping(typesToReaders);

    context.unbranch();

    return typesToReaders;
  }
View Full Code Here

  }

  protected Map<Type, Type> findAllWriters(final Set<Type> types) {
    Checker.notNull("parameter:types", types);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Finding existing ObjectWriters...");

    final ObjectWriterFinder finder = new ObjectWriterFinder() {
      @Override
      protected Type getImplementingInterface() {
        return SerializationFactoryGenerator.this.getObjectWriter();
      }

      @Override
      protected boolean shouldBeSerialized(final Type type) {
        return SerializationFactoryGenerator.this.isOrHasSerializableSubType(type);
      }
    };

    final Map<Type, Type> typesToWriters = finder.build(types);

    this.logMapping(typesToWriters);

    context.unbranch();

    return typesToWriters;
  }
View Full Code Here

  }

  protected void logMapping(final Map<Type, Type> types) {
    Checker.notNull("parameter:types", types);

    final GeneratorContext context = this.getGeneratorContext();

    if (context.isDebugEnabled()) {
      final TreeMap<Type, Type> sorted = new TreeMap<Type, Type>(TypeComparator.INSTANCE);
      sorted.putAll(types);

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

        final Type type = entry.getKey();
        final Type type1 = entry.getValue();

        String message = type.getName();
        if (null != type1) {
          message = message + " = " + type1.getName();
        }
        context.debug(message);
      }
    }
  }
View Full Code Here

  protected String getResourceName() {
    String fileName = null;
    while (true) {
      // the return type of the getter is also the field type.
      final Type type = this.getFieldType();
      final GeneratorContext context = type.getGeneratorContext();
      if (context.getBoolean().equals(type)) {
        fileName = Constants.READ_FIELD_BOOLEAN_FIELD_TEMPLATE;
        break;
      }
      if (context.getByte().equals(type)) {
        fileName = Constants.READ_FIELD_BYTE_FIELD_TEMPLATE;
        break;
      }
      if (context.getShort().equals(type)) {
        fileName = Constants.READ_FIELD_SHORT_FIELD_TEMPLATE;
        break;
      }
      if (context.getInt().equals(type)) {
        fileName = Constants.READ_FIELD_INT_FIELD_TEMPLATE;
        break;
      }
      if (context.getLong().equals(type)) {
        fileName = Constants.READ_FIELD_LONG_FIELD_TEMPLATE;
        break;
      }
      if (context.getFloat().equals(type)) {
        fileName = Constants.READ_FIELD_FLOAT_FIELD_TEMPLATE;
        break;
      }
      if (context.getDouble().equals(type)) {
        fileName = Constants.READ_FIELD_DOUBLE_FIELD_TEMPLATE;
        break;
      }
      if (context.getChar().equals(type)) {
        fileName = Constants.READ_FIELD_CHAR_FIELD_TEMPLATE;
        break;
      }
      fileName = Constants.READ_FIELD_OBJECT_FIELD_TEMPLATE;
      break;
View Full Code Here

  protected Set<Type> getTypesFromAnnotation(final String title, final Type type, final String annotation) {
    Checker.notNull("parameter:type", type);
    Checker.notEmpty("parameter:annotation", annotation);

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

    final TreeSet<Type> types = new TreeSet<Type>(TypeComparator.INSTANCE);

    final Iterator<String> typeNames = type.getMetadataValues(annotation).iterator();
    while (typeNames.hasNext()) {
      final String typeName = typeNames.next();
      final Type listedType = context.findType(typeName);
      if (null == listedType) {
        this.throwUnableToFindAnnotatedType(typeName, type);
      }

      types.add(listedType);
      context.debug(listedType.getName());
    }

    context.unbranch();
    return types;
  }
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.