コード例 #1
0
  public Object deserializeInto(@NotNull Object result, @NotNull Element element) {
    Set<Binding> bindings = myPropertyBindings.keySet();
    MultiMap<Binding, Object> data = MultiMap.createSmartList();
    nextNode:
    for (Object child : ContainerUtil.concat(element.getContent(), element.getAttributes())) {
      if (XmlSerializerImpl.isIgnoredNode(child)) {
        continue;
      }

      for (Binding binding : bindings) {
        if (binding.isBoundTo(child)) {
          data.putValue(binding, child);
          continue nextNode;
        }
      }

      final String message = "Format error: no binding for " + child + " inside " + this;
      LOG.debug(message);
      Logger.getInstance(myBeanClass.getName()).debug(message);
      Logger.getInstance("#" + myBeanClass.getName()).debug(message);
    }

    for (Binding binding : data.keySet()) {
      binding.deserialize(result, ArrayUtil.toObjectArray(data.get(binding)));
    }

    return result;
  }
コード例 #2
0
 public BeanBinding(Class<?> beanClass) {
   assert !beanClass.isArray() : "Bean is an array: " + beanClass;
   assert !beanClass.isPrimitive() : "Bean is primitive type: " + beanClass;
   myBeanClass = beanClass;
   myTagName = getTagName(beanClass);
   assert !StringUtil.isEmptyOrSpaces(myTagName) : "Bean name is empty: " + beanClass;
 }
コード例 #3
0
 private static String getTagName(Class<?> aClass) {
   for (Class<?> c = aClass; c != null; c = c.getSuperclass()) {
     String name = getTagNameFromAnnotation(c);
     if (name != null) {
       return name;
     }
   }
   return aClass.getSimpleName();
 }
コード例 #4
0
 private static void collectFieldAccessors(Class<?> aClass, List<Accessor> accessors) {
   for (Field field : aClass.getFields()) {
     final int modifiers = field.getModifiers();
     if (Modifier.isPublic(modifiers)
         && !Modifier.isStatic(modifiers)
         && !Modifier.isFinal(modifiers)
         && !Modifier.isTransient(modifiers)
         && field.getAnnotation(Transient.class) == null) {
       accessors.add(new FieldAccessor(field));
     }
   }
 }
コード例 #5
0
  private static void collectPropertyAccessors(Class<?> aClass, List<Accessor> accessors) {
    final Map<String, Couple<Method>> candidates =
        ContainerUtilRt.newTreeMap(); // (name,(getter,setter))
    for (Method method : aClass.getMethods()) {
      if (!Modifier.isPublic(method.getModifiers())) {
        continue;
      }

      Pair<String, Boolean> propertyData = getPropertyData(method.getName()); // (name,isSetter)
      if (propertyData == null
          || propertyData.first.equals("class")
          || method.getParameterTypes().length != (propertyData.second ? 1 : 0)) {
        continue;
      }

      Couple<Method> candidate = candidates.get(propertyData.first);
      if (candidate == null) {
        candidate = Couple.getEmpty();
      }
      if ((propertyData.second ? candidate.second : candidate.first) != null) {
        continue;
      }
      candidate =
          Couple.of(
              propertyData.second ? candidate.first : method,
              propertyData.second ? method : candidate.second);
      candidates.put(propertyData.first, candidate);
    }
    for (Map.Entry<String, Couple<Method>> candidate : candidates.entrySet()) {
      Couple<Method> methods = candidate.getValue(); // (getter,setter)
      if (methods.first != null
          && methods.second != null
          && methods.first.getReturnType().equals(methods.second.getParameterTypes()[0])
          && methods.first.getAnnotation(Transient.class) == null
          && methods.second.getAnnotation(Transient.class) == null) {
        accessors.add(
            new PropertyAccessor(
                candidate.getKey(), methods.first.getReturnType(), methods.first, methods.second));
      }
    }
  }
コード例 #6
0
 public String toString() {
   return "BeanBinding[" + myBeanClass.getName() + ", tagName=" + myTagName + "]";
 }
コード例 #7
0
 private static String getTagNameFromAnnotation(Class<?> aClass) {
   Tag tag = aClass.getAnnotation(Tag.class);
   if (tag != null && !tag.value().isEmpty()) return tag.value();
   return null;
 }