Java Code Examples for com.klarna.reflection.ReflectionUtils#getStaticFieldValue()
The following examples show how to use
com.klarna.reflection.ReflectionUtils#getStaticFieldValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlinkStandaloneHiveRunner.java From flink with Apache License 2.0 | 6 votes |
private void loadAnnotatedSetupScripts(Class testClass, HiveShellBuilder hiveShellBuilder) { Set<Field> setupScriptFields = ReflectionUtils.getAllFields(testClass, withAnnotation(HiveSetupScript.class)); for (Field setupScriptField : setupScriptFields) { if (ReflectionUtils.isOfType(setupScriptField, String.class)) { String script = ReflectionUtils.getStaticFieldValue(testClass, setupScriptField.getName(), String.class); hiveShellBuilder.addSetupScript(script); } else if (ReflectionUtils.isOfType(setupScriptField, File.class) || ReflectionUtils.isOfType(setupScriptField, Path.class)) { Path path = getMandatoryPathFromField(testClass, setupScriptField); hiveShellBuilder.addSetupScript(readAll(path)); } else { throw new IllegalArgumentException( "Field annotated with @HiveSetupScript currently only supports type String, File and Path"); } } }
Example 2
Source File: FlinkStandaloneHiveRunner.java From flink with Apache License 2.0 | 6 votes |
private void loadAnnotatedResources(Class testClass, HiveShellBuilder workFlowBuilder) throws IOException { Set<Field> fields = ReflectionUtils.getAllFields(testClass, withAnnotation(HiveResource.class)); for (Field resourceField : fields) { HiveResource annotation = resourceField.getAnnotation(HiveResource.class); String targetFile = annotation.targetFile(); if (ReflectionUtils.isOfType(resourceField, String.class)) { String data = ReflectionUtils.getStaticFieldValue(testClass, resourceField.getName(), String.class); workFlowBuilder.addResource(targetFile, data); } else if (ReflectionUtils.isOfType(resourceField, File.class) || ReflectionUtils.isOfType(resourceField, Path.class)) { Path dataFile = getMandatoryPathFromField(testClass, resourceField); workFlowBuilder.addResource(targetFile, dataFile); } else { throw new IllegalArgumentException( "Fields annotated with @HiveResource currently only supports field type String, File or Path"); } } }
Example 3
Source File: FlinkStandaloneHiveRunner.java From flink with Apache License 2.0 | 6 votes |
private void loadAnnotatedSetupScripts(Class testClass, HiveShellBuilder hiveShellBuilder) { Set<Field> setupScriptFields = ReflectionUtils.getAllFields(testClass, withAnnotation(HiveSetupScript.class)); for (Field setupScriptField : setupScriptFields) { if (ReflectionUtils.isOfType(setupScriptField, String.class)) { String script = ReflectionUtils.getStaticFieldValue(testClass, setupScriptField.getName(), String.class); hiveShellBuilder.addSetupScript(script); } else if (ReflectionUtils.isOfType(setupScriptField, File.class) || ReflectionUtils.isOfType(setupScriptField, Path.class)) { Path path = getMandatoryPathFromField(testClass, setupScriptField); hiveShellBuilder.addSetupScript(readAll(path)); } else { throw new IllegalArgumentException( "Field annotated with @HiveSetupScript currently only supports type String, File and Path"); } } }
Example 4
Source File: FlinkStandaloneHiveRunner.java From flink with Apache License 2.0 | 6 votes |
private void loadAnnotatedResources(Class testClass, HiveShellBuilder workFlowBuilder) throws IOException { Set<Field> fields = ReflectionUtils.getAllFields(testClass, withAnnotation(HiveResource.class)); for (Field resourceField : fields) { HiveResource annotation = resourceField.getAnnotation(HiveResource.class); String targetFile = annotation.targetFile(); if (ReflectionUtils.isOfType(resourceField, String.class)) { String data = ReflectionUtils.getStaticFieldValue(testClass, resourceField.getName(), String.class); workFlowBuilder.addResource(targetFile, data); } else if (ReflectionUtils.isOfType(resourceField, File.class) || ReflectionUtils.isOfType(resourceField, Path.class)) { Path dataFile = getMandatoryPathFromField(testClass, resourceField); workFlowBuilder.addResource(targetFile, dataFile); } else { throw new IllegalArgumentException( "Fields annotated with @HiveResource currently only supports field type String, File or Path"); } } }
Example 5
Source File: FlinkStandaloneHiveRunner.java From flink with Apache License 2.0 | 5 votes |
private Path getMandatoryPathFromField(Class testClass, Field resourceField) { Path path; if (ReflectionUtils.isOfType(resourceField, File.class)) { File dataFile = ReflectionUtils.getStaticFieldValue(testClass, resourceField.getName(), File.class); path = Paths.get(dataFile.toURI()); } else if (ReflectionUtils.isOfType(resourceField, Path.class)) { path = ReflectionUtils.getStaticFieldValue(testClass, resourceField.getName(), Path.class); } else { throw new IllegalArgumentException( "Only Path or File type is allowed on annotated field " + resourceField); } Preconditions.checkArgument(Files.exists(path), "File %s does not exist", path); return path; }
Example 6
Source File: FlinkStandaloneHiveRunner.java From flink with Apache License 2.0 | 5 votes |
private Path getMandatoryPathFromField(Class testClass, Field resourceField) { Path path; if (ReflectionUtils.isOfType(resourceField, File.class)) { File dataFile = ReflectionUtils.getStaticFieldValue(testClass, resourceField.getName(), File.class); path = Paths.get(dataFile.toURI()); } else if (ReflectionUtils.isOfType(resourceField, Path.class)) { path = ReflectionUtils.getStaticFieldValue(testClass, resourceField.getName(), Path.class); } else { throw new IllegalArgumentException( "Only Path or File type is allowed on annotated field " + resourceField); } Preconditions.checkArgument(Files.exists(path), "File %s does not exist", path); return path; }