示例#1
0
    /**
     * Config from field.
     *
     * @param field the field
     * @see
     *     org.jnetpcap.packet.structure.AnnotatedFieldMethod#configFromField(org.jnetpcap.packet.structure.AnnotatedField)
     */
    @Override
    public final void configFromField(AnnotatedField field) {

      switch (function) {
        case VALUE:
          if (method == null) {
            throw new HeaderDefinitionError(
                field.getDeclaringClass(),
                "no method set for field value getter [" + field.getName() + "]");
          }
          break;

        default:
          throw new HeaderDefinitionError(
              field.getDeclaringClass(), "Invalid Dynamic function type " + function.toString());
      }

      if (method == null) {
        throw new FieldDefinitionException(
            field,
            "Missing field accessor '"
                + function.name().toLowerCase()
                + "' property. [@Dynamic(Property."
                + function.name()
                + ")]");
      }
    }
示例#2
0
    /**
     * Config from field.
     *
     * @param field the field
     * @see
     *     org.jnetpcap.packet.structure.AnnotatedFieldMethod#configFromField(org.jnetpcap.packet.structure.AnnotatedField)
     */
    @Override
    public final void configFromField(AnnotatedField field) {

      switch (function) {
        case LENGTH:
          if (field.getLength() != -1) {
            setValue(field.getLength());
          }
          break;

        case OFFSET:
          if (field.getOffset() != -1) {
            setValue(field.getOffset());
          }
          break;

        default:
          throw new HeaderDefinitionError("Invalid Dynamic function type " + function.toString());
      }

      if (hasStaticValue == false && method == null) {
        throw new FieldDefinitionException(
            field,
            "Missing '"
                + function.name().toLowerCase()
                + "' property. [@Field("
                + function.name().toLowerCase()
                + "=<int>) or @Dynamic(Property."
                + function.name()
                + ")]");
      }
    }
示例#3
0
 private String emitTypefaceField(String className, AnnotatedField field) {
   return "    (("
       + className
       + ")target)."
       + field.getName()
       + ".setTypeface(manager.getTypeface(\""
       + field.getTypefaceName()
       + "\"));\n";
 }
示例#4
0
    /**
     * Instantiates a new string function.
     *
     * @param field the field
     * @param function the function
     */
    public StringFunction(AnnotatedField field, Field.Property function) {
      super(field, function);

      field.getMethod().setAccessible(true);

      configFromField(field);
    }
示例#5
0
    /**
     * Instantiates a new boolean function.
     *
     * @param field the field
     * @param function the function
     */
    public BooleanFunction(AnnotatedField field, Field.Property function) {
      super(field, function);

      setValue(true); // Static fields are always available

      field.getMethod().setAccessible(true);
    }
示例#6
0
    /**
     * Instantiates a new long function.
     *
     * @param field the field
     * @param function the function
     * @param staticValue the static value
     */
    public LongFunction(AnnotatedField field, Field.Property function, long staticValue) {
      super(field, function);

      setValue(staticValue);

      field.getMethod().setAccessible(true);
    }
示例#7
0
  /**
   * Check annotation.
   *
   * @param method the method
   * @param fields the fields
   */
  public static void checkAnnotation(Method method, List<AnnotatedField> fields) {

    Dynamic runtime = method.getAnnotation(Dynamic.class);

    if (runtime.field().length() != 0) {

      boolean found = false;
      final String name = runtime.field();
      for (AnnotatedField f : fields) {
        if (f.getName().equals(name)) {
          found = true;
          break;
        }
      }

      if (!found) {
        throw new HeaderDefinitionError("field name defined in annotation ");
      }
    }
  }
示例#8
0
 /**
  * Method called to add field mix-ins from given mix-in class (and its fields) into already
  * collected actual fields (from introspected classes and their super-classes)
  */
 protected void _addFieldMixIns(Class<?> mixin, Map<String, AnnotatedField> fields) {
   for (Field mixinField : mixin.getDeclaredFields()) {
     /* there are some dummy things (static, synthetic); better
      * ignore
      */
     if (!_isIncludableField(mixinField)) {
       continue;
     }
     String name = mixinField.getName();
     // anything to mask? (if not, quietly ignore)
     AnnotatedField maskedField = fields.get(name);
     if (maskedField != null) {
       for (Annotation a : mixinField.getDeclaredAnnotations()) {
         if (_annotationIntrospector.isHandled(a)) {
           maskedField.addOrOverride(a);
         }
       }
     }
   }
 }
示例#9
0
    /**
     * Config from field.
     *
     * @param field the field
     * @see
     *     org.jnetpcap.packet.structure.AnnotatedFieldMethod#configFromField(org.jnetpcap.packet.structure.AnnotatedField)
     */
    @Override
    public final void configFromField(AnnotatedField field) {

      switch (function) {
        case UNITS:
          if (field.getUnits().length() != 0) {
            setValue(field.getUnits());
          } else if (method == null) {
            setValue(null);
          }
          break;
        case DISPLAY:
          if (field.getDisplay().length() != 0) {
            setValue(field.getDisplay());
          } else if (method == null) {
            setValue(null);
          }
          break;

        case DESCRIPTION:
          if (field.getDescription().length() != 0) {
            setValue(field.getDescription());
          } else if (method == null) {
            setValue(null);
          }
          break;

        default:
          throw new HeaderDefinitionError("Invalid Dynamic function type " + function.toString());
      }

      if (hasStaticValue == false && method == null) {
        throw new FieldDefinitionException(
            field,
            "Missing '"
                + function.name().toLowerCase()
                + "' property. [@Field("
                + function.name().toLowerCase()
                + "=<string>) or @Dynamic(Property."
                + function.name()
                + ")]");
      }
    }
示例#10
0
  /**
   * Instantiates a new annotated field method.
   *
   * @param field the field
   * @param function the function
   * @param method the method
   */
  public AnnotatedFieldMethod(AnnotatedField field, Field.Property function, Method method) {
    super(method);
    this.function = function;

    this.field = field.getName();
  }
示例#11
0
    /**
     * Instantiates a new object function.
     *
     * @param field the field
     * @param fuction the fuction
     */
    public ObjectFunction(AnnotatedField field, Field.Property fuction) {
      super(field, fuction, field.getMethod());

      field.getMethod().setAccessible(true);
    }