コード例 #1
0
  private Map getFields(XClass clazz, String prefix) throws XDocletException {
    Map fields = new LinkedHashMap();

    Collection curFields = clazz.getMethods(true);

    for (Iterator iterator = curFields.iterator(); iterator.hasNext(); ) {
      XMethod setter = (XMethod) iterator.next();

      if (MethodTagsHandler.isSetterMethod(setter)) {
        String name = MethodTagsHandler.getPropertyNameFor(setter);
        XParameter param = (XParameter) setter.getParameters().iterator().next();
        String type = param.getType().getQualifiedName();
        XMethod getter = setter.getAccessor();

        setCurrentClass(setter.getContainingClass());
        super.setCurrentMethod(getter);
        Properties pro = new Properties();
        pro.setProperty("tagName", "hibernate.component");

        if (super.hasTag(pro, FOR_METHOD)) {
          name += "Form";
          fields.putAll(getFields(param.getType(), prefix + name + "."));
        } else {
          fields.put(prefix + name, setter);
        }
      }
    }

    return fields;
  }
コード例 #2
0
 /**
  * Method methodTagValue
  *
  * @param attributes
  * @return
  * @throws XDocletException
  */
 public String methodTagValue(Properties attributes) throws XDocletException {
   XMethod method = getCurrentMethod();
   setCurrentMethod(method.getAccessor());
   String value = getTagValue(attributes, FOR_METHOD);
   setCurrentMethod(method);
   return value;
 }
コード例 #3
0
  /**
   * Iterates the body for each field of the current form requiring validation.
   *
   * @param template
   * @param attributes
   * @throws XDocletException
   */
  public void forAllFields(String template, Properties attributes) throws XDocletException {
    XClass clazz = getCurrentClass();
    Map setters = new LinkedHashMap(getFields(clazz));

    for (Iterator iterator = setters.keySet().iterator(); iterator.hasNext(); ) {
      curFieldName = (String) iterator.next();

      XMethod field = (XMethod) setters.get(curFieldName);

      XMethod getter = field.getAccessor();
      setCurrentMethod(getter);
      curFieldIsIdorVersion = false;
      Properties prop = new Properties();
      prop.setProperty("tagName", "hibernate.id");

      if (hasTag(prop, FOR_METHOD)) {
        prop.setProperty("paramName", "generator-class");
        String generatorClass = methodTagValue(prop);
        System.out.println("generatorClass: " + generatorClass);
        if (generatorClass != null && generatorClass.equals("assigned")) {
          curFieldIsIdorVersion = false;
        } else {
          curFieldIsIdorVersion = true;
        }
      } else {
        curFieldIsIdorVersion = false;
      }

      prop.setProperty("tagName", "hibernate.version");

      if (hasTag(prop, FOR_METHOD)) {
        curFieldIsIdorVersion = true;
      }

      String typename = field.getPropertyType().getType().getQualifiedName();
      curFieldIsBoolean = typename.equals("boolean") || typename.equals("java.lang.Boolean");
      curFieldIsDate = typename.equals("java.util.Date") || typename.equals("java.sql.Timestamp");

      curType = typename;
      setCurrentMethod(field);

      if (!iterator.hasNext()) {
        lastField = true;
      } else {
        lastField = false;
      }

      generate(template);
    }
  }