コード例 #1
0
  /** Create the appropriate properties for a bean. */
  public void createProperties(DeployBeanDescriptor<?> desc) {

    createProperties(desc, desc.getBeanType(), 0);
    desc.sortProperties();

    // check the transient properties...
    Iterator<DeployBeanProperty> it = desc.propertiesAll();

    while (it.hasNext()) {
      DeployBeanProperty prop = it.next();
      if (prop.isTransient()) {
        if (prop.getWriteMethod() == null || prop.getReadMethod() == null) {
          // Typically a helper method ... this is expected
          logger.finest("... transient: " + prop.getFullBeanName());
        } else {
          // dubious, possible error...
          String msg = Message.msg("deploy.property.nofield", desc.getFullName(), prop.getName());
          logger.warning(msg);
        }
      }
    }
  }
コード例 #2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  private DeployBeanProperty createProp(DeployBeanDescriptor<?> desc, Field field) {

    Class<?> propertyType = field.getType();
    Class<?> innerType = propertyType;

    // check for Collection type (list, set or map)
    ManyType manyType = determineManyType.getManyType(propertyType);

    if (manyType != null) {
      // List, Set or Map based object
      Class<?> targetType = determineTargetType(field);
      if (targetType == null) {
        Transient transAnnotation = field.getAnnotation(Transient.class);
        if (transAnnotation != null) {
          // not supporting this field (generic type used)
          return null;
        }
        logger.warning(
            "Could not find parameter type (via reflection) on "
                + desc.getFullName()
                + " "
                + field.getName());
      }
      return createManyType(desc, targetType, manyType);
    }

    if (innerType.isEnum() || innerType.isPrimitive()) {
      return new DeployBeanProperty(desc, propertyType, null, null);
    }

    ScalarType<?> scalarType = typeManager.getScalarType(innerType);
    if (scalarType != null) {
      return new DeployBeanProperty(desc, propertyType, scalarType, null);
    }

    CtCompoundType<?> compoundType = typeManager.getCompoundType(innerType);
    if (compoundType != null) {
      return new DeployBeanPropertyCompound(desc, propertyType, compoundType, null);
    }

    if (!isTransientField(field)) {
      try {
        CheckImmutableResponse checkImmutable = typeManager.checkImmutable(innerType);
        if (checkImmutable.isImmutable()) {
          if (checkImmutable.isCompoundType()) {
            // use reflection to support compound immutable value objects
            typeManager.recursiveCreateScalarDataReader(innerType);
            compoundType = typeManager.getCompoundType(innerType);
            if (compoundType != null) {
              return new DeployBeanPropertyCompound(desc, propertyType, compoundType, null);
            }

          } else {
            // use reflection to support simple immutable value objects
            scalarType = typeManager.recursiveCreateScalarTypes(innerType);
            return new DeployBeanProperty(desc, propertyType, scalarType, null);
          }
        }
      } catch (Exception e) {
        logger.log(Level.SEVERE, "Error with " + desc + " field:" + field.getName(), e);
      }
    }

    return new DeployBeanPropertyAssocOne(desc, propertyType);
  }