下面列出了java.lang.reflect.Field#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
ModuleFactory(String referenceModuleID, Class<? extends IModule> clazz) throws ModuleInitException {
// NOTE: Instanciable only from ModuleRegistry
this.clazz = clazz;
this.referenceModuleID = referenceModuleID;
// Determine configurable fields via reflection
for(Field field : clazz.getFields()) {
ModuleParameter cfg = field.getDeclaredAnnotation(ModuleParameter.class);
if( cfg == null )
continue;
try {
field.setAccessible(true);
}
catch(SecurityException e) {
throw new ModuleInitException("Failed to acquire reflection access to field '" + field.toString() + "', annotated by @ModuleParameter.", e);
}
configurableFields.put(cfg.value(), field);
}
// Determine overrides
overridableMethods.putAll(ModuleOverrideHandler.getOverrideMethodsFromClass(clazz, true));
}
public void doProcess(WSheet wSheet, Object obj, Field field, Annotation ann, AnnotationReader reader,
XLSBeansConfig config, List<NeedPostProcess> needPostProcess) throws Exception {
IterateTables iterateTables = (IterateTables) ann;
Class<?> fieldType = field.getType();
// create multi-table objects.
List<?> value = createTables(wSheet, iterateTables, reader, config, needPostProcess);
if (List.class.isAssignableFrom(fieldType)) {
field.set(obj, value);
} else if (fieldType.isArray()) {
Class<?> type = fieldType.getComponentType();
Object array = Array.newInstance(type, value.size());
for (int i = 0; i < value.size(); i++) {
Array.set(array, i, value.get(i));
}
field.set(obj, array);
} else {
throw new XLSBeansException("Arguments of '" + field.toString() + "' is invalid.");
}
}
public void doProcess(WSheet wSheet, Object obj, Field field, Annotation ann, AnnotationReader reader,
XLSBeansConfig config, List<NeedPostProcess> needPostProcess) throws Exception {
IterateTables iterateTables = (IterateTables) ann;
Class<?> fieldType = field.getType();
// create multi-table objects.
List<?> value = createTables(wSheet, iterateTables, reader, config, needPostProcess);
if (List.class.isAssignableFrom(fieldType)) {
field.set(obj, value);
} else if (fieldType.isArray()) {
Class<?> type = fieldType.getComponentType();
Object array = Array.newInstance(type, value.size());
for (int i = 0; i < value.size(); i++) {
Array.set(array, i, value.get(i));
}
field.set(obj, array);
} else {
throw new XLSBeansException("Arguments of '" + field.toString() + "' is invalid.");
}
}
public Location getFieldLocation(final Field field) {
return new Location() {
@Override
public String toString() {
return field.toString();
}
};
}
public Location getFieldLocation(final Field field) {
return new Location() {
@Override
public String toString() {
return field.toString();
}
};
}
public Location getFieldLocation(final Field field) {
return new Location() {
@Override
public String toString() {
return field.toString();
}
};
}
public Location getFieldLocation(final Field field) {
return new Location() {
@Override
public String toString() {
return field.toString();
}
};
}
public Location getFieldLocation(final Field field) {
return new Location() {
@Override
public String toString() {
return field.toString();
}
};
}
private static boolean assertStaticClassVarsAreFromPackage() {
//String packagename = System.getProperty("jawk.rtPackgeName", "org.jawk.jrt");
String packagename = "org.jawk.jrt";
if (packagename != null) {
// use reflection to get all static Class definitions
// and verify that they are members of the
// runtime package
Class c = AwkCompilerImpl.class;
// foreach field in declared in the class...
for (Field f : c.getDeclaredFields()) {
int mod = f.getModifiers();
// if a "private static final" member...
if ( (mod & Modifier.PRIVATE) > 0
&& (mod & Modifier.STATIC) > 0
&& (mod & Modifier.FINAL) > 0
&& f.getType() == Class.class)
{
try {
// obtain the value of the field
// and apply it here!
Object o = f.get(null);
Class cls = (Class) o;
if (!cls.getPackage().getName().equals(packagename)) {
throw new AssertionError("class " + c.toString() + " is not contained within '" + packagename + "' package. Field = " + f.toString());
}
} catch (IllegalAccessException iae) {
throw new AssertionError(iae); // NOTE Thought there is an AssertionError#AssertionError(String, Throwable) ctor aswell, it was only introduced in Java 1.7, so we should not yet use it.
}
}
}
}
// all's well
return true;
}
public Location getFieldLocation(final Field field) {
return new Location() {
@Override
public String toString() {
return field.toString();
}
};
}
public Location getFieldLocation(final Field field) {
return new Location() {
@Override
public String toString() {
return field.toString();
}
};
}
private BlueOceanConfigImpl() {
Properties properties = System.getProperties();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String ks = entry.getKey() == null ? "" : entry.getKey().toString();
if (ks.startsWith(BlueOceanConfig.FEATURE_PROPERTY_PREFIX)) {
Object value = entry.getValue();
String vs = value == null ? "" : value.toString();
if ("true".equalsIgnoreCase(vs) || "false".equalsIgnoreCase(vs)) {
value = Boolean.valueOf(vs);
}
config.put(ks.substring(BlueOceanConfig.FEATURE_PROPERTY_PREFIX.length()), value);
}
}
for (Field f : BlueOceanConfig.class.getFields()) {
if (Modifier.isStatic(f.getModifiers())
&& Modifier.isPublic(f.getModifiers())
&& f.getType() == String.class) {
try {
String featureName = (String)f.get(null);
if (!BlueOceanConfig.FEATURE_PROPERTY_PREFIX.equals(featureName)
&& !config.containsKey(featureName)) {
config.put(featureName, Boolean.FALSE);
}
} catch (IllegalArgumentException | IllegalAccessException ex) {
throw new RuntimeException("Unable to read field: " + f.toString(), ex);
}
}
}
}
public Location getFieldLocation(final Field field) {
return new Location() {
@Override
public String toString() {
return field.toString();
}
};
}
protected FlagField<?> boundFlagField(Field field, Object declaredIn) {
FlagField<?> flagField = null;
if (!Flag.class.isAssignableFrom(field.getType())) {
throw new RuntimeException(
String.format(
"Field(%s#%s) annotated with @FlagInfo but not a Flag.",
field.getDeclaringClass().getCanonicalName(),
field.getName()));
}
try {
final boolean wasAccessible = field.isAccessible();
if (!field.isAccessible()) {
field.setAccessible(true);
}
flagField = (FlagField<?>) field.get(declaredIn);
flagField.bind(field);
FlagProperty property = propertySyncer.fieldPropertyAnnotation(field);
if (property != null) {
propertySyncer.handlePropertyAnnotaton(flagField, property);
}
if (!wasAccessible) {
field.setAccessible(false);
}
} catch (IllegalAccessException exception) {
// Should never happen because access is granted, but let's get a nice stack trace.
throw new RuntimeException("Unexpected problem parsing Field " + field.toString(), exception);
}
return flagField;
}
public Object getClassField(final String className,
final String classFieldName) throws Exception {
final Class<?> clazz = this.classLoader.loadClass(className);
final Field field = clazz.getField(classFieldName);
if (!Modifier.isStatic(field.getModifiers())) {
throw new RuntimeException(
"Oops, field " + field.toString() + " is not static");
}
// get the value of field, as class field object == null
final Object result = field.get(null);
return result;
}
private void validateAnnotatedField(
final Bin defaultBin,
final Bin fieldBin,
final Field field
) {
//TODO
final Bin bin = fieldBin == null ? defaultBin : fieldBin;
if ((bin.type() == BinType.UNDEFINED
&& field.getType().isArray()
|| bin.type().name().endsWith("_ARRAY"))
&& bin.arraySizeExpr().isEmpty()) {
throw new IllegalArgumentException(field.toString() + ": missing expression in Bin#arraySizeExpression");
}
}
/**
* Delete anything up to the last . (dot)
*
* Example:
* Input: private static long javasmmr.zoowsome.models.animals.Cow.counter
* Output: counter
*/
public String[] getStringFromFields(List<Field> fields) {
String[] fieldsString = new String[fields.size()];
for (int i = 0; i < fields.size(); i++) {
Field f = fields.get(i);
fieldsString[i] = f.toString();
fieldsString[i] = fieldsString[i].replaceAll("\\w+(\\s+|\\.+)", "");
}
return fieldsString;
}
/**
* Delete anything up to the last . (dot)
*
* Example:
* Input: private static long javasmmr.zoowsome.models.animals.Cow.counter
* Output: counter
*/
public String[] getStringFromFields(List<Field> fields) {
String[] fieldsString = new String[fields.size()];
for (int i = 0; i < fields.size(); i++) {
Field f = fields.get(i);
fieldsString[i] = f.toString();
fieldsString[i] = fieldsString[i].replaceAll("\\w+(\\s+|\\.+)", "");
}
return fieldsString;
}
private Annotation[] getAnnotations(final Field field) {
final String fieldName = field.toString();
Annotation[] annotations = annotationCache.get(fieldName);
if ( annotations == null ) {
annotations = field.getAnnotations();
annotationCache.put(fieldName, annotations);
}
return annotations;
}
public static final void findMetaData( Object object, int level, List<StringSearchResult> stringList,
Object parentObject, Object grandParentObject ) {
if ( ( object == null ) || level > 5 ) {
return;
}
PluginRegistry registry = PluginRegistry.getInstance();
if ( transformPluginPackages == null ) {
transformPluginPackages = registry.getPluginPackages( TransformPluginType.class );
}
if ( jobEntryPluginPackages == null ) {
jobEntryPluginPackages = registry.getPluginPackages( ActionPluginType.class );
}
Class<? extends Object> baseClass = object.getClass();
Field[] fields = baseClass.getDeclaredFields();
for ( int i = 0; i < fields.length; i++ ) {
Field field = fields[ i ];
boolean processThisOne = true;
if ( ( field.getModifiers() & Modifier.FINAL ) > 0 ) {
processThisOne = false;
}
if ( ( field.getModifiers() & Modifier.STATIC ) > 0 ) {
processThisOne = false;
}
// Investigate only if we're dealing with a sanctioned package.
// A sanctioned package is either the local package (org.apache.hop) or
// a package of one of the plugins.
//
boolean sanctionedPackage = false;
String fieldToString = field.toString();
if ( fieldToString.indexOf( LOCAL_PACKAGE ) >= 0 ) {
sanctionedPackage = true;
}
for ( int x = 0; x < JAVA_PACKAGES.length && !sanctionedPackage; x++ ) {
if ( fieldToString.indexOf( JAVA_PACKAGES[ x ] ) >= 0 ) {
sanctionedPackage = true;
}
}
for ( int x = 0; x < transformPluginPackages.size() && !sanctionedPackage; x++ ) {
if ( fieldToString.indexOf( transformPluginPackages.get( x ) ) >= 0 ) {
sanctionedPackage = true;
}
}
for ( int x = 0; x < jobEntryPluginPackages.size() && !sanctionedPackage; x++ ) {
if ( fieldToString.indexOf( jobEntryPluginPackages.get( x ) ) >= 0 ) {
sanctionedPackage = true;
}
}
if ( !sanctionedPackage ) {
processThisOne = false; // Stay in the sanctioned code-base.
}
// Dig into the metadata from here...
//
if ( processThisOne ) {
try {
Object obj = field.get( object );
if ( obj != null ) {
stringSearchInObject( obj, level, stringList, parentObject, grandParentObject, field );
}
} catch ( IllegalAccessException e ) {
// OK, it's private, let's see if we can go there later on using
// getters and setters...
// fileName becomes: getFileName();
// OK, how do we get the value now?
try {
Method method = findMethod( baseClass, field.getName() );
if ( method != null ) {
// String fullMethod =
// baseClass.getName()+"."+method.getName()+"()";
Object string = method.invoke( object, (Object[]) null );
if ( string != null ) {
stringSearchInObject( string, level, stringList, parentObject, grandParentObject, field );
}
}
} catch ( Throwable ex ) {
// Ignore this error silently. If we can't access the method there
// is nothing you can do about it.
}
}
}
}
}