Example #1
0
  /**
   * Generates getter and setter methods for all fields of the class 'class_name' which are accessed
   * via callout. Informations are received via attributs (CallinBindingManager).
   *
   * @param cg the ClassGen of the appropriate class
   * @param class_name the name of the class
   * @param cpg the ConstantPoolGen of the class
   * @param es the ExtensionSet to add the new access methods
   */
  private void generateFieldAccessForCallout(
      ClassEnhancer ce, ClassGen cg, String class_name, ConstantPoolGen cpg) {
    InstructionFactory factory = null;

    HashSet<String> addedAccessMethods = this.generatedFieldCalloutAccessors;

    List<FieldDescriptor> getter = CallinBindingManager.getCalloutGetFields(class_name);
    if (getter != null) {
      factory = new InstructionFactory(cg);
      Iterator<FieldDescriptor> it = getter.iterator();
      while (it.hasNext()) {
        FieldDescriptor fd = it.next();
        String key = "get_" + class_name + "." + fd.getFieldName() + fd.getFieldSignature();
        if (logging) printLogMessage("Generating getter method " + key);
        if (addedAccessMethods == null) addedAccessMethods = new HashSet<String>();
        if (addedAccessMethods.contains(key)) continue; // this getter has already been created
        ce.addMethod(generateGetter(cpg, class_name, fd, factory), cg);
        addedAccessMethods.add(key);
      }
    }

    List<FieldDescriptor> setter = CallinBindingManager.getCalloutSetFields(class_name);
    if (setter != null) {
      if (factory == null) factory = new InstructionFactory(cg);
      Iterator<FieldDescriptor> it = setter.iterator();
      while (it.hasNext()) {
        FieldDescriptor fd = it.next();
        String key = "set_" + class_name + "." + fd.getFieldName() + fd.getFieldSignature();
        if (logging) printLogMessage("Generating setter method " + key);
        if (addedAccessMethods == null) addedAccessMethods = new HashSet<String>();
        if (addedAccessMethods.contains(key)) continue; // this setter has already been created
        ce.addMethod(generateSetter(cpg, class_name, fd, factory), cg);
        addedAccessMethods.add(key);
      }
    }
  }