/** * 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() + ")]"); } }
/** * 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() + ")]"); } }
private String emitTypefaceField(String className, AnnotatedField field) { return " ((" + className + ")target)." + field.getName() + ".setTypeface(manager.getTypeface(\"" + field.getTypefaceName() + "\"));\n"; }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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 "); } } }
/** * 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); } } } } }
/** * 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() + ")]"); } }
/** * 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(); }
/** * 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); }