public static Element serializeCaseComponent(
      CaseComponent casecomponent, String name, Document doc) {
    try {
      Element root = doc.createElement("CaseComponent");
      root.setAttribute("Name", name);
      root.setAttribute("Class", casecomponent.getClass().getCanonicalName());
      root.setAttribute("IdAttribute", casecomponent.getIdAttribute().getName());

      for (Attribute at : AttributeUtils.getAttributes(casecomponent)) {
        if (CaseComponent.class.isAssignableFrom(at.getType()))
          root.appendChild(
              serializeCaseComponent(
                  (CaseComponent) at.getValue(casecomponent), at.getName(), doc));
        else {
          Element child = doc.createElement(at.getName());
          Object value = at.getValue(casecomponent);
          if (value != null) child.appendChild(doc.createTextNode(value.toString()));
          root.appendChild(child);
        }
      }

      return root;
    } catch (Exception e) {
      org.apache.commons.logging.LogFactory.getLog(CaseComponentSerializer.class).error(e);
    }
    return null;
  }
Example #2
0
  private static void defineNewIds(CaseComponent cc, HashMap componentsKeys)
      throws jcolibri.exception.ExecutionException {
    if (cc == null) return;
    Attribute keyAtt = cc.getIdAttribute();
    Object newkeyvalue = componentsKeys.get(keyAtt);

    try {
      if (newkeyvalue != null) keyAtt.setValue(cc, newkeyvalue);

      for (Object on : cc.getClass().getDeclaredFields()) {
        java.lang.reflect.Field f = (java.lang.reflect.Field) on;
        Attribute at = new Attribute(f);
        Object o = at.getValue(cc);
        if (o instanceof CaseComponent) defineNewIds((CaseComponent) o, componentsKeys);
      }
    } catch (Exception e) {
      org.apache.commons.logging.LogFactory.getLog(DefineNewIdsMethod.class).error(e);
    }
  }