Package rocket.beans.rebind.value

Examples of rocket.beans.rebind.value.Value


    context.debug("Constructor parameter values.");

    final List<Value> arguments = bean.getConstructorValues();
    final Iterator<Value> argumentsIterator = arguments.iterator();
    while (argumentsIterator.hasNext()) {
      final Value value = argumentsIterator.next();
      body.addArgument(value);

      if (context.isDebugEnabled()) {
        context.debug(value.toString());
      }
    }

    context.unbranch();

    context.branch();
    context.debug("Matching constructors.");

    final List<Constructor> matchingConstructors = new ArrayList<Constructor>();
    final TypeConstructorsVisitor visitor = new TypeConstructorsVisitor() {

      protected boolean visit(final Constructor constructor) {
        boolean match = false;

        // skip non public constructors
        if (constructor.getVisibility() == Visibility.PUBLIC) {
          final List<ConstructorParameter> constructorParameters = constructor.getParameters();

          // skip the given constructor with different numbers of
          // parameters.
          if (constructorParameters.size() == arguments.size()) {

            match = true;
            final Iterator<Value> valuesIterator = arguments.iterator();
            final Iterator<ConstructorParameter> parametersIterator = constructorParameters.iterator();

            while (valuesIterator.hasNext()) {
              final ConstructorParameter parameter = parametersIterator.next();
              final Value value0 = valuesIterator.next();
              if (false == value0.isCompatibleWith(parameter.getType())) {
                match = false;
              }
            }
          }
        }

        if (match) {
          matchingConstructors.add(constructor);
          context.debug("" + constructor);
        }
        return false;
      }
    };

    final Type beanType = bean.getType();
    visitor.start(beanType);

    if (matchingConstructors.size() == 0) {
      this.throwUnableToFindConstructor(bean);
    }
    if (matchingConstructors.size() > 1) {
      this.throwTooManyConstructors(bean, matchingConstructors);
    }
    context.unbranch();

    final Constructor constructor = (Constructor) matchingConstructors.get(0);
    body.setBean(constructor);

    final Iterator<ConstructorParameter> constructorParameters = constructor.getParameters().iterator();
    final Iterator<Value> valuesIterator = arguments.iterator();
    while (constructorParameters.hasNext()) {
      final ConstructorParameter constructorParameter = constructorParameters.next();
      final Value value = valuesIterator.next();
      value.setPropertyType(constructorParameter.getType());

      this.prepareValue(value);
    }

    if (context.isDebugEnabled()) {
View Full Code Here


    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;
View Full Code Here

    }
  }

  protected void throwTooManySettersFound(final Bean bean, final Property property) {
    //final String name = property.getName();
    final Value value = property.getValue();
    throw new BeanFactoryGeneratorException("The bean \"" + bean.getId() + "\" contains more than one setter for the property "
        + property + " with a value of " + value + " on type \"" + bean.getTypeName() + "\".");
  }
View Full Code Here

      tag.setPlaceHolderResolver(placeHolderResolver);

      final Property property = new Property();
      property.setName(tag.getName());

      final Value value = this.visitConstructorOrPropertyValue(tag.getValue());
      property.setValue(value);

      properties.add(property);
    }
View Full Code Here

   * @param element
   *            The source element
   * @return The built value.
   */
  protected Value visitConstructorOrPropertyValue(final Element element) {
    Value value = null;

    while (true) {
      final String tagName = element.getTagName();

      if (tagName.equals(Constants.NULL_TAG)) {
View Full Code Here

      entry.setElement(entryElement);
      entry.setPlaceHolderResolver(placeHolderResolver);

      final String key = entry.getKey();
      final Element valueElement = entry.getValue();
      final Value value = this.visitConstructorOrPropertyValue(valueElement);

      map.addEntry(key, value);
    }

    return map;
View Full Code Here

    final List<Value> values = new ArrayList<Value>();

    final Iterator<Element> iterator = valueElements.iterator();
    while (iterator.hasNext()) {
      final Element element = iterator.next();
      final Value value = this.visitConstructorOrPropertyValue(element);
      values.add(value);
    }

    return values;
  }
View Full Code Here

    final Iterator<Map.Entry<String, Value>> entries = this.getEntries().entrySet().iterator();

    while (entries.hasNext()) {
      final Map.Entry<String,Value> entry = entries.next();
      final String key = entry.getKey();
      final Value value = entry.getValue();

      template.add(key, value);
    }

    template.write(writer);
View Full Code Here

    final CollectionTemplatedFile template = this.createTemplate();
    final Iterator elements = this.getElements().iterator();

    while (elements.hasNext()) {
      final Value element = (Value) elements.next();

      template.add(element);
    }

    template.write(writer);
View Full Code Here

TOP

Related Classes of rocket.beans.rebind.value.Value

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.