List of usage examples for java.lang.reflect Modifier PUBLIC
int PUBLIC
To view the source code for java.lang.reflect Modifier PUBLIC.
Click Source Link
From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderMetadata.java
/** * Gets <code>additionalAuthenticationChecks</code> method. <br> * // www .j a v a 2 s .co m * @return */ private MethodMetadata getAdditionalAuthenticationChecksMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes( new JavaType("org.springframework.security.core.userdetails.UserDetails"), new JavaType("org.springframework.security.authentication.UsernamePasswordAuthenticationToken")); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(ADDITIONAL_CHECKS_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); throwsTypes.add(new JavaType("org.springframework.security.core.AuthenticationException")); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("userDetails")); parameterNames.add(new JavaSymbolName("authentication")); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildAdditionalAuthenticationChecksMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, ADDITIONAL_CHECKS_METHOD, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:net.minecraftforge.common.util.EnumHelper.java
@SuppressWarnings({ "unchecked", "serial" }) @Nullable/* ww w . j a v a 2 s . c o m*/ private static <T extends Enum<?>> T addEnum(boolean test, final Class<T> enumType, @Nullable String enumName, final Class<?>[] paramTypes, @Nullable Object[] paramValues) { if (!isSetup) { setup(); } Field valuesField = null; Field[] fields = enumType.getDeclaredFields(); for (Field field : fields) { String name = field.getName(); if (name.equals("$VALUES") || name.equals("ENUM$VALUES")) //Added 'ENUM$VALUES' because Eclipse's internal compiler doesn't follow standards { valuesField = field; break; } } int flags = (FMLForgePlugin.RUNTIME_DEOBF ? Modifier.PUBLIC : Modifier.PRIVATE) | Modifier.STATIC | Modifier.FINAL | 0x1000 /*SYNTHETIC*/; if (valuesField == null) { String valueType = String.format("[L%s;", enumType.getName().replace('.', '/')); for (Field field : fields) { if ((field.getModifiers() & flags) == flags && field.getType().getName().replace('.', '/').equals(valueType)) //Apparently some JVMs return .'s and some don't.. { valuesField = field; break; } } } if (valuesField == null) { final List<String> lines = Lists.newArrayList(); lines.add(String.format("Could not find $VALUES field for enum: %s", enumType.getName())); lines.add(String.format("Runtime Deobf: %s", FMLForgePlugin.RUNTIME_DEOBF)); lines.add(String.format("Flags: %s", String.format("%16s", Integer.toBinaryString(flags)).replace(' ', '0'))); lines.add("Fields:"); for (Field field : fields) { String mods = String.format("%16s", Integer.toBinaryString(field.getModifiers())).replace(' ', '0'); lines.add(String.format(" %s %s: %s", mods, field.getName(), field.getType().getName())); } for (String line : lines) FMLLog.log.fatal(line); if (test) { throw new EnhancedRuntimeException("Could not find $VALUES field for enum: " + enumType.getName()) { @Override protected void printStackTrace(WrappedPrintStream stream) { for (String line : lines) stream.println(line); } }; } return null; } if (test) { Object ctr = null; Exception ex = null; try { ctr = getConstructorAccessor(enumType, paramTypes); } catch (Exception e) { ex = e; } if (ctr == null || ex != null) { throw new EnhancedRuntimeException( String.format("Could not find constructor for Enum %s", enumType.getName()), ex) { private String toString(Class<?>[] cls) { StringBuilder b = new StringBuilder(); for (int x = 0; x < cls.length; x++) { b.append(cls[x].getName()); if (x != cls.length - 1) b.append(", "); } return b.toString(); } @Override protected void printStackTrace(WrappedPrintStream stream) { stream.println("Target Arguments:"); stream.println(" java.lang.String, int, " + toString(paramTypes)); stream.println("Found Constructors:"); for (Constructor<?> ctr : enumType.getDeclaredConstructors()) { stream.println(" " + toString(ctr.getParameterTypes())); } } }; } return null; } valuesField.setAccessible(true); try { T[] previousValues = (T[]) valuesField.get(enumType); T newValue = makeEnum(enumType, enumName, previousValues.length, paramTypes, paramValues); setFailsafeFieldValue(valuesField, null, ArrayUtils.add(previousValues, newValue)); cleanEnumCache(enumType); return newValue; } catch (Exception e) { FMLLog.log.error("Error adding enum with EnumHelper.", e); throw new RuntimeException(e); } }
From source file:org.gvnix.addon.geo.addon.GvNIXGeoConversionServiceMetadata.java
/** * Gets <code>getPointToStringConverter</code> method. <br> * /*from ww w . j a v a 2s . co m*/ * @return */ private MethodMetadata getPointToStringConverterMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(POINT_TO_STRING_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildGetPointToStringConverterMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, POINT_TO_STRING_METHOD, CONVERTER_POINT_STRING, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.gvnix.service.roo.addon.addon.security.WSServiceSecurityMetadata.java
/** * Return method for handle password/* w w w. j a v a2 s.co m*/ * * @return */ private MethodMetadata getCallBackHandlerMethod() { // Prepare method parameter definition List<JavaType> parameterTypes = new ArrayList<JavaType>(); parameterTypes.add(CALLBACKS_PARAM_TYPE); List<AnnotatedJavaType> parameters = AnnotatedJavaType.convertFromJavaTypes(parameterTypes); // Check if a method with the same signature already exists in the // target type if (MemberFindingUtils.getDeclaredMethod(governorTypeDetails, HANDLE_METHOD_NAME, parameterTypes) != null) { // If it already exists, just return the method and omit its // generation via the ITD return null; } // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); throwsTypes.add(IO_EXCEPTION_TYPE); throwsTypes.add(UNSUPPORTED_CALLBACK_TYPE); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(CALBACK_PARAM_NAME); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("final String propPath = \"".concat(propertiesPath).concat("\";")); bodyBuilder.appendFormalLine( "final String propKey = \"org.apache.ws.security.crypto.merlin.keystore.password\";"); bodyBuilder.appendFormalLine("try {"); bodyBuilder.indent(); bodyBuilder.append("// Get class loader to get file from project"); bodyBuilder.newLine(); bodyBuilder.appendFormalLine("ClassLoader classLoader = Thread.currentThread().getContextClassLoader();"); bodyBuilder.appendFormalLine( "java.io.File file = new java.io.File(classLoader.getResource(propPath).toURI());"); bodyBuilder.appendFormalLine("if (file != null && file.exists()) {"); bodyBuilder.indent(); bodyBuilder.append("// Load properties"); bodyBuilder.newLine(); bodyBuilder.appendFormalLine("java.util.Properties properties = new java.util.Properties();"); bodyBuilder.appendFormalLine("java.io.FileInputStream ins = null;"); bodyBuilder.appendFormalLine("try {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine("ins = new java.io.FileInputStream(file);"); bodyBuilder.appendFormalLine("properties.load(ins);"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("} finally {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine("if (ins != null) {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine("ins.close();"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); // End if bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); // End try (ins) bodyBuilder.appendFormalLine("String value = properties.getProperty(propKey);"); bodyBuilder.appendFormalLine("if (value != null) {"); bodyBuilder.indent(); bodyBuilder .appendFormalLine("((org.apache.ws.security.WSPasswordCallback) callbacks[0]).setPassword(value);"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("} else {"); // Else value != null bodyBuilder.indent(); bodyBuilder .appendFormalLine("throw new IOException(\"Property \".concat(propKey).concat(\" not exists\"));"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); // Endif value != null bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("} else {"); // Else file.exists() bodyBuilder.indent(); bodyBuilder.appendFormalLine("throw new IOException(\"File \".concat(propPath).concat(\" not exists\"));"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); // Endif file.exists() bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("} catch (java.net.URISyntaxException e) {"); bodyBuilder.indent(); bodyBuilder.appendFormalLine( "throw new IOException(\"Problem getting \".concat(propPath).concat(\" file\"),e);"); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); // End try // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, HANDLE_METHOD_NAME, JavaType.VOID_PRIMITIVE, parameters, parameterNames, bodyBuilder); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:com.all.app.DefaultContext.java
private void checkInvokePredestroy(Method method, Object ob) { boolean annotationPresent = false; boolean noArguments = method.getParameterTypes().length == 0; boolean isVoid = method.getReturnType().equals(void.class); boolean isPublic = (method.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC; boolean isNotStatic = (method.getModifiers() & Modifier.STATIC) != Modifier.STATIC; Annotation[] annotations = method.getAnnotations(); for (Annotation annotation : annotations) { if (annotation.getClass().getName().contains("PreDestroy") || annotation.toString().contains("PreDestroy")) { annotationPresent = true;// w ww . j a va 2 s .c o m } } if (annotationPresent && noArguments && isPublic && isNotStatic && isVoid) { try { method.invoke(ob); } catch (Exception e) { log.error(e, e); } } }
From source file:com.github.venkateshamurthy.designpatterns.builders.FluentBuilders.java
/** * Return true if class passed is <b>not</b> a public class * /*from w ww.jav a2 s. com*/ * @param thisPojoClass * to be verified if its public * @return true if thisPojoClass is <b>not</b> public */ private boolean isNotAPublicClass(final Class<?> thisPojoClass) { return thisPojoClass != null && (Modifier.PUBLIC & thisPojoClass.getModifiers()) != Modifier.PUBLIC; }
From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogEntityMetadataBuilder.java
private ClassOrInterfaceTypeDetails getRevisionListener() { // Check class exists ClassOrInterfaceTypeDetails innerClass = governorTypeDetails.getDeclaredInnerType(revisionListenerType); if (innerClass != null) { // If class exists (already push-in) we can do nothing return innerClass; }/*from www.j a v a 2s . c o m*/ // Create inner class ClassOrInterfaceTypeDetailsBuilder classBuilder = new ClassOrInterfaceTypeDetailsBuilder( context.getMetadataId(), Modifier.PUBLIC + Modifier.STATIC, revisionListenerType, PhysicalTypeCategory.CLASS); classBuilder.addImplementsType(REVISION_LISTENER); classBuilder.addMethod(getNewRevisionMethod()); return classBuilder.build(); }
From source file:org.gvnix.addon.geo.addon.GvNIXGeoConversionServiceMetadata.java
/** * Gets <code>parseWkt</code> method. <br> * //from w ww . ja v a 2 s. c o m * @return */ private MethodMetadata getParseWktConverterMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); parameterTypes.add(new AnnotatedJavaType(JavaType.STRING)); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(PARSE_WKT_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); throwsTypes.add(new JavaType("com.vividsolutions.jts.io.ParseException")); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("wkt")); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildParseWktMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, PARSE_WKT_METHOD, GEOMETRY_TYPE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.gvnix.flex.FlexOperationsImpl.java
public void createRemotingDestination(JavaType service, JavaType entity) { Validate.notNull(service, "Remoting Destination Java Type required"); Validate.notNull(entity, "Entity Java Type required"); String resourceIdentifier = this.typeLocationService.getPhysicalTypeCanonicalPath(service, LogicalPath.getInstance(Path.SRC_MAIN_JAVA, "")); // create annotation @RooFlexScaffold List<AnnotationAttributeValue<?>> rooFlexScaffoldAttributes = new ArrayList<AnnotationAttributeValue<?>>(); rooFlexScaffoldAttributes.add(new ClassAttributeValue(new JavaSymbolName("entity"), entity)); AnnotationMetadata atRooFlexScaffold = new AnnotationMetadataBuilder( new JavaType(RooFlexScaffold.class.getName()), rooFlexScaffoldAttributes).build(); // create annotation @RemotingDestination List<AnnotationAttributeValue<?>> remotingDestinationAttributes = new ArrayList<AnnotationAttributeValue<?>>(); AnnotationMetadata atRemotingDestination = new AnnotationMetadataBuilder( new JavaType("org.springframework.flex.remoting.RemotingDestination"), remotingDestinationAttributes).build(); // create annotation @Service List<AnnotationAttributeValue<?>> serviceAttributes = new ArrayList<AnnotationAttributeValue<?>>(); AnnotationMetadata atService = new AnnotationMetadataBuilder( new JavaType("org.springframework.stereotype.Service"), serviceAttributes).build(); String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(service, getPathResolver().getPath(resourceIdentifier)); ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder( declaredByMetadataId, Modifier.PUBLIC, service, PhysicalTypeCategory.CLASS); typeBuilder.addAnnotation(atRooFlexScaffold); typeBuilder.addAnnotation(atRemotingDestination); typeBuilder.addAnnotation(atService); ClassOrInterfaceTypeDetails details = typeBuilder.build(); this.typeManagementService.generateClassFile(details); ActionScriptType asType = ActionScriptMappingUtils.toActionScriptType(entity); // Trigger creation of corresponding ActionScript entities this.metadataService.get(ActionScriptEntityMetadata.createTypeIdentifier(asType, "src/main/flex")); }
From source file:org.gvnix.web.screen.roo.addon.EntityBatchMetadata.java
/** * <p>// w w w .j ava2 s.c o m * Gets method for target operation. * </p> * <p> * First, try to look for it in governors. If not exists, create a new * method. * </p> * * @param methodName * @param targetMethod * @return */ private MethodMetadata getMethodFor(JavaSymbolName methodName, String targetMethod) { // Define method parameter types List<AnnotatedJavaType> parameterTypes = getParamsTypesForMethods(); // Check if a method with the same signature already exists in the // target type MethodMetadata method = methodExists(methodName, parameterTypes.get(0).getJavaType()); if (method != null) { // If it already exists, just return null and omit its // generation via the ITD return null; } // Define method annotations List<AnnotationMetadataBuilder> annotations = getAnnotationsForMethods(); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names List<JavaSymbolName> parameterNames = getParamsNamesForMethods(); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); /* * for (${entityName} entity : entities.list) { * entity.${targetMethod}(); } */ bodyBuilder.appendFormalLine(MessageFormat.format("for ({0} entity : entities.list) '{'", new Object[] { destination.getSimpleTypeName() })); bodyBuilder.indent(); bodyBuilder.appendFormalLine(MessageFormat.format("entity.{0}();", new Object[] { targetMethod })); bodyBuilder.indentRemove(); bodyBuilder.appendFormalLine("}"); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC | Modifier.STATIC, methodName, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); }