示例#1
0
  private static void loadPropertyNamesValues(
      Class clazz, Object instance, List names, List values) {
    PropertyDescriptor pd;
    BeanInfo info = null;
    try {
      info = Introspector.getBeanInfo(clazz);
    } catch (IntrospectionException ex) {
      Err.error(ex);
    }

    PropertyDescriptor[] propertyDescriptors = info.getPropertyDescriptors();
    for (int i = 0; i < propertyDescriptors.length; ++i) {
      pd = propertyDescriptors[i];

      Object value = SelfReferenceUtils.invokeReadProperty(info, pd, instance, pd.getName());
      if (value == null) { // Err.pr( "No property set for " + pd.getName() + " in " + clazz);
      } else {
        names.add(pd.getName());
        values.add(value);
      }
    }
    if (names.isEmpty()) {
      Err.error("Strange that there are no properties with values in " + clazz);
    }
  }
示例#2
0
 public static String getName(Object comp) {
   String result;
   Method getNameControlMethod = null;
   String methodName = "getName";
   Class controlClass = comp.getClass();
   try {
     getNameControlMethod = controlClass.getMethod(methodName, (Class[]) null);
   } catch (Exception ex) {
     Err.error("Missing method " + methodName + " from " + controlClass);
   }
   result = (String) SelfReferenceUtils.invoke(comp, getNameControlMethod);
   return result;
 }
示例#3
0
 public static void setEditable(Object comp, boolean b) {
   Class[] args1 = new Class[1];
   args1[0] = Boolean.TYPE;
   Method setEditableControlMethod = null;
   String methodName = "setEditable";
   Class controlClass = comp.getClass();
   try {
     setEditableControlMethod = controlClass.getMethod(methodName, args1);
   } catch (Exception ex) {
     Err.error("Missing method " + methodName + " from " + controlClass);
   }
   SelfReferenceUtils.invoke(comp, setEditableControlMethod, Boolean.valueOf(b));
 }
示例#4
0
 /**
  * TODO - Think about reason are not going to ControlSignatures for this. Pros for not -
  * ControlSignatures is part of strandz core, whereas this is lgpl Pros for having in
  * ControlSignatures - Controls inside a table should be treated in exactly the same way as other
  * field controls. (This would require changes to info package).
  *
  * <p>Of course providing a service interface would be the answer, but changing info provides
  * inertia. Bugs because of differences will help the case for change.
  */
 public static boolean isEditable(Object comp) {
   boolean result = false;
   Method isEditableControlMethod = null;
   String methodName = "isEditable";
   Class controlClass = comp.getClass();
   boolean noMethod = false;
   try {
     isEditableControlMethod = controlClass.getMethod(methodName, (Class[]) null);
   } catch (NoSuchMethodException ex1) {
     noMethod = true;
   } catch (Exception ex2) {
     Err.error("Missing method " + methodName + " from " + controlClass + ", ex: " + ex2);
   }
   if (!noMethod) {
     result = ((Boolean) SelfReferenceUtils.invoke(comp, isEditableControlMethod)).booleanValue();
   }
   return result;
 }
示例#5
0
 public static void setText(Object comp, Object txt) {
   Class[] args1 = new Class[1];
   args1[0] = String.class;
   Method setTextControlMethod = null;
   String methodName = "setText";
   Class controlClass = comp.getClass();
   try {
     setTextControlMethod = controlClass.getMethod(methodName, args1);
   } catch (Exception ex1) {
     args1[0] = Object.class;
     try {
       setTextControlMethod = controlClass.getMethod(methodName, args1);
     } catch (Exception ex2) {
       Err.error("Missing method " + methodName + " from " + controlClass);
     }
   }
   String s = null;
   if (txt != null) {
     s = txt.toString();
   }
   SelfReferenceUtils.invoke(comp, setTextControlMethod, s);
 }