@Override
  public void setBean(B bean) {
    Class<?> beanClass = bean.getClass();
    java.lang.reflect.Field[] fields = ClassUtils.getAllFields(beanClass);
    for (java.lang.reflect.Field field : fields) {
      Field<?> formField = onCreateField(field.getName());
      if (formField != null) {
        attachForm.attachField(field.getName(), formField);
      } else {
        if (field.getAnnotation(NotBindable.class) != null) {
          continue;
        } else {
          try {
            final String propertyValue =
                BeanUtils.getProperty(attachForm.getBean(), field.getName());
            formField = new DefaultViewField(propertyValue);
          } catch (Exception e) {
            LOG.error("Error while get field value", e);
            formField = new DefaultViewField("Error");
          }

          attachForm.attachField(field.getName(), formField);
        }
      }
    }
  }
 public XMPPBean exchange(B bean, ResultBeanType resultBeanPrototype, int retries) {
   synchronized (this) {
     this.maxRetries = retries;
     this.beanOut = bean;
     this.resultBeanPrototype = resultBeanPrototype;
     try {
       // add IQ provider if necessary
       if (ProviderManager.getInstance()
               .getIQProvider(
                   resultBeanPrototype.getChildElement(), resultBeanPrototype.getNamespace())
           == null) {
         (new BeanProviderAdapter(resultBeanPrototype.getClass().newInstance()))
             .addToProviderManager();
       }
       if (ProviderManager.getInstance().getIQProvider(bean.getChildElement(), bean.getNamespace())
           == null) {
         (new BeanProviderAdapter(bean.getClass().newInstance())).addToProviderManager();
       }
     } catch (InstantiationException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (IllegalAccessException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     // catch response bean and error bean
     this.beanCollector =
         connection.createPacketCollector(
             new OrFilter(
                 new BeanFilterAdapter(resultBeanPrototype), new BeanFilterAdapter(bean)));
     return sendAndWaitForResult(bean);
   }
 }
Exemple #3
0
  @Override
  public void write(DataOutput out) throws IOException {
    // Serialize class names of each non-null field
    final ClassIndex index = new ClassIndex();

    if (fst != null) index.addClass(fst.getClass());
    if (snd != null) index.addClass(snd.getClass());
    index.write(out);

    // Indicate which fields are null
    out.writeByte((fst == null ? FST_NULL : NOT_NULL) | (snd == null ? SND_NULL : NOT_NULL));

    // Serialize each non-null field
    if (fst != null) {
      out.writeByte(index.getId(fst.getClass()));
      fst.write(out);
    }
    if (snd != null) {
      out.writeByte(index.getId(snd.getClass()));
      snd.write(out);
    }
  }
  private void checkClassOfBeanPropertiesInit(B bean) {
    Class<? extends IPersistableComparableLookupRow> beanClass = bean.getClass();
    Field[] declaredFields = beanClass.getDeclaredFields();

    for (int i = 0; i < declaredFields.length; i++) {
      Field propertyDescriptor = declaredFields[i];
      int fieldModifier = propertyDescriptor.getModifiers();
      if (Modifier.isPublic(fieldModifier)) {
        Class<?> clazzOfBeanProperty = propertyDescriptor.getType();
        String propertyName = propertyDescriptor.getName();
        if (!FIELDS_TO_OMIT_SET.contains(propertyName)
            && !CUSTOM_SERIALIZATION_CLASSES_SET.contains(clazzOfBeanProperty)) {
          // if (WRITE_WARNING_IF_INHERITED_SET.contains(clazzOfBeanProperty)) {
          // propNameToCheckIsInherited.add(propertyDescriptor);
          // } else {
          // skipBytesEnabled = false;
          // break;
          // }
          skipBytesEnabled = false;
          break;
        }

        // boolean propertyIsPrimtive = clazzOfBeanProperty.isPrimitive();
        // Object[] signers = clazzOfBeanProperty.getSigners();
        // if (!propertyIsPrimtive) {
        // int modifiers = clazzOfBeanProperty.getModifiers();
        // boolean propertyHasFinalType = Modifier.isFinal(modifiers);
        // if (!propertyHasFinalType) {
        // propNameToCheckAtEachLine.add(propertyDescriptor);
        // } else {
        // Object propertyValue = null;
        // try {
        // propertyValue = propertyDescriptor.get(bean);
        // } catch (IllegalAccessException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }
        // if (propertyValue != null) {
        // String className = clazzOfBeanProperty.getName();
        // objectsToWriteAtBeginningOfValuesFile.put(className, propertyValue);
        // } else {
        // propNameToCheckWhileValueIsNull.add(propertyDescriptor);
        // }
        // }
        // }
      }
    }

    System.out.println("skipBytesEnabled=" + skipBytesEnabled);
  }
Exemple #5
0
    /**
     * Takes an instance of Buffer and checks the class name to see if it contains the class name of
     * a Buffer base class. For example: InstanceName.contains(SimpleName); // where -> InstanceName
     * = "java.nio.DirectFloatBufferS"; SimpleName = "FloatBuffer"; // Enumeration value class name
     *
     * @param <B> the getType of buffer as input
     * @param buffer the buffer to check getType
     * @return BufferType if match found, null if not
     */
    public static <B extends Buffer> BufferType getType(B buffer) {
      if (buffer == null) {
        throw new NullPointerException("Buffer is null.");
      }
      BufferType type = null;
      String instanceClassName = buffer.getClass().getName();

      // Check if buffer class name contains the simple enum name
      for (BufferType t : BufferType.values()) {
        if (instanceClassName.contains(t.BUFFER_CLASS.getSimpleName())) {
          type = t;
          break;
        }
      }
      return type;
    }