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.jpa.addon.audit.JpaAuditOperationsImpl.java
/** {@inheritDoc} */ @Override/*ww w . j a va2 s . co m*/ public void create(JavaType entity, JavaType target, boolean failIfAlreadySet) { Validate.notNull(entity, "Entity required"); if (target == null) { target = generateListenerJavaType(entity, null); } Validate.isTrue(!JdkJavaType.isPartOfJavaLang(target.getSimpleTypeName()), "Target name '%s' must not be part of java.lang", target.getSimpleTypeName()); int modifier = Modifier.PUBLIC; final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(target, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); File targetFile = new File(typeLocationService.getPhysicalTypeCanonicalPath(declaredByMetadataId)); if (targetFile.exists()) { if (failIfAlreadySet) { Validate.isTrue(!targetFile.exists(), "Type '%s' already exists", target); } else { LOGGER.info(String.format("Ignoring entity '%s': Type '%s' already exists", entity, target)); return; } } // Prepare class builder final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder( declaredByMetadataId, modifier, target, PhysicalTypeCategory.CLASS); // Prepare annotations array List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(2); // Add @GvNIXJpaAuditListener annotation AnnotationMetadataBuilder jpaAuditListenerAnnotation = new AnnotationMetadataBuilder( new JavaType(GvNIXJpaAuditListener.class)); jpaAuditListenerAnnotation.addClassAttribute("entity", entity); annotations.add(jpaAuditListenerAnnotation); // Set annotations cidBuilder.setAnnotations(annotations); // Add GvNIXJpaAudit annotation to entity if (!annotateEntity(entity)) { // Already set annotation. Nothing to do LOGGER.info(String.format("Entity %s is already annotated with %s: ignore this entity.", entity.getFullyQualifiedTypeName(), GvNIXJpaAudit.class.getSimpleName())); return; } // Create Listener class typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); }
From source file:org.gvnix.addon.jpa.addon.geo.providers.hibernatespatial.GvNIXEntityMapLayerMetadata.java
/** * Create a method to filter by a single geometry field * //w w w. jav a 2s . c o m * @param entity * @param finder * @param plural * @param geoFieldNames * @return */ private MethodMetadata getfindAllTheEntityByGeomFilter(JavaType entity, String finder, String plural, Map<JavaSymbolName, AnnotationAttributeValue<Integer>> geoFields) { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); // Adding parameter types parameterTypes.add(AnnotatedJavaType .convertFromJavaType(new JavaType("org.gvnix.jpa.geo.hibernatespatial.util.GeometryFilter"))); parameterTypes.add(AnnotatedJavaType.convertFromJavaType( new JavaType("java.lang.Class", 0, DataType.TYPE, null, Arrays.asList(new JavaType("T"))))); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(new JavaType(MAP.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(JavaType.STRING, JavaType.OBJECT)))); // Getting method name JavaSymbolName methodName = new JavaSymbolName( String.format("findAll%sBy%s", plural, StringUtils.capitalize(finder))); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(methodName, 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>(); parameterNames.add(new JavaSymbolName("geomFilter")); parameterNames.add(new JavaSymbolName("klass")); parameterNames.add(new JavaSymbolName("hints")); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildfindAllTheEntityByGeomFilterMethodBody(entity, plural, finder, bodyBuilder, geoFields); // Return type JavaType responseEntityJavaType = new JavaType("java.util.List", 0, DataType.TYPE, null, Arrays.asList(new JavaType("T"))); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC, methodName, responseEntityJavaType, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); methodBuilder.setGenericDefinition("T"); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:com.viadee.acceptancetests.roo.addon.AcceptanceTestsOperations.java
private MethodMetadata newTestMethod(String storyGroupIdentifier, String story) { List<AnnotationMetadata> methodAnnotations = new ArrayList<AnnotationMetadata>(); methodAnnotations.add(new DefaultAnnotationMetadata(new JavaType("org.junit.Test"), new ArrayList<AnnotationAttributeValue<?>>())); MethodMetadata method = new DefaultMethodMetadata(storyGroupIdentifier, Modifier.PUBLIC, new JavaSymbolName(methodNameFromStory(story)), VOID_PRIMITIVE, null, null, methodAnnotations, null, String.format(/*from www . ja va 2 s . c om*/ "org.junit.Assert.fail(\"Implement the acceptance test for story \\\"%s\\\" here.\");", story)); return method; }
From source file:com.izforge.izpack.util.SelfModifier.java
/** * Check the method for the required properties (public, static, params:(String[])). * * @param method the method/*from ww w . j a v a 2s. co m*/ * @throws NullPointerException if <code>method</code> is null * @throws IllegalArgumentException if <code>method</code> is not public, static, and take a * String array as it's only argument, or of it's declaring class is not public. * @throws SecurityException if access to the method is denied */ private void initMethod(Method method) { int mod = method.getModifiers(); if ((mod & Modifier.PUBLIC) == 0 || (mod & Modifier.STATIC) == 0) { throw new IllegalArgumentException("Method not public and static"); } Class[] params = method.getParameterTypes(); if (params.length != 1 || !params[0].isArray() || !"java.lang.String".equals(params[0].getComponentType().getName())) { throw new IllegalArgumentException("Method must accept String array"); } Class clazz = method.getDeclaringClass(); mod = clazz.getModifiers(); if ((mod & Modifier.PUBLIC) == 0 || (mod & Modifier.INTERFACE) != 0) { throw new IllegalArgumentException("Method must be in a public class"); } this.method = method; }
From source file:org.gvnix.addon.geo.addon.GvNIXWebEntityMapLayerMetadata.java
/** * Gets <code>showOnlyList</code> method. <br> * // w ww. j a va 2 s. c o m * @return */ private MethodMetadata getShowOnlyListMethod(String plural) { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); parameterTypes.add(AnnotatedJavaType.convertFromJavaType(SpringJavaType.MODEL)); parameterTypes .add(AnnotatedJavaType.convertFromJavaType(new JavaType("javax.servlet.http.HttpServletRequest"))); // @RequestParam("path") String listPath AnnotationMetadataBuilder listPathAnnotation = new AnnotationMetadataBuilder(SpringJavaType.REQUEST_PARAM); listPathAnnotation.addStringAttribute("value", "path"); parameterTypes.add(new AnnotatedJavaType(JavaType.STRING, listPathAnnotation.build())); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("uiModel")); parameterNames.add(new JavaSymbolName("request")); parameterNames.add(new JavaSymbolName("listPath")); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(SHOW_ONLY_LIST, 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>(); AnnotationMetadataBuilder requestMappingMetadataBuilder = new AnnotationMetadataBuilder( SpringJavaType.REQUEST_MAPPING); // @RequestMapping(params = "selector", produces = "text/html") requestMappingMetadataBuilder.addStringAttribute("params", "mapselector"); requestMappingMetadataBuilder.addStringAttribute("produces", "text/html"); annotations.add(requestMappingMetadataBuilder); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildShowOnlyListMethodBody(plural, bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, SHOW_ONLY_LIST, JavaType.STRING, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.gvnix.addon.jpa.addon.batch.JpaBatchMetadata.java
/** * Gets <code>deleteByValuesMethod</code> method. <br> * This method performs a delete base on property values condition (value * equal and concatenates conditions using "and" operator) * //from ww w. j a v a 2 s . c o m * @return */ private MethodMetadata getDeleteByValuesMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(MAP_STRING_OBJECT); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(DELETE_BY_VALUES_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>(); annotations.add(new AnnotationMetadataBuilder(SpringJavaType.TRANSACTIONAL)); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("propertyValues")); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildDeleteByValuesMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, DELETE_BY_VALUES_METHOD, JavaType.LONG_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogEntityMetadataBuilder.java
private MethodMetadata getToStringMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(0); // Check if a method exist in type final MethodMetadata method = helper.methodExists(TO_STRING_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method return method; }// w ww .ja v a 2s .c o m // Define method annotations (none in this case) List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names (none in this case) List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(0); // Create the method body InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder(); // return new ToStringBuilder(this).append("id", // id).append("revisonDate", getRevisionDate()).append("userName", // userName).toString(); body.appendFormalLine(String.format( "return new %s(this).append(\"%s\", this.%s).append(\"%s\", this.%s()).append(\"%s\", this.%s).toString();", helper.getFinalTypeName(TO_STRING_BUILDER), ID_FIELD, ID_FIELD, REVISION_DATE_TRANSIENT_FIELD, getRevisionDate().getMethodName(), USER_FIELD, USER_FIELD)); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(context.getMetadataId(), Modifier.PUBLIC, TO_STRING_METHOD, JavaType.STRING, parameterTypes, parameterNames, body); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata }
From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java
/** * @return gets or creates getProperty(name) method *///w ww .jav a 2s . c om private MethodMetadata getPropertyMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(JavaType.STRING); // Check if a method exist in type final MethodMetadata method = helper.methodExists(GET_PROPERTY_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method return method; } // Define method annotations (none in this case) List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names (none in this case) List<JavaSymbolName> parameterNames = helper.toSymbolName("name"); // Create the method body InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder(); // return getProperty(name, new BeanWrapperImpl(Visit.class)); body.appendFormalLine(String.format("return %s(name, new %s(%s.class));", GET_PROPERTY_METHOD, helper.getFinalTypeName(BEAN_WRAPPER_IMPL), StringUtils.capitalize(context.getEntityName()))); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(context.getMetadataId(), Modifier.PUBLIC + Modifier.STATIC, GET_PROPERTY_METHOD, AUDIT_PROPERTY_GENERIC, parameterTypes, parameterNames, body); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata }
From source file:org.codehaus.groovy.grails.compiler.injection.test.TestMixinTransformation.java
protected FieldNode addTestRuleMixinFieldIfNonExistent(ClassNode classNode, ClassNode fieldType, String fieldName, boolean implementsClassRuleFactory, boolean implementsRuleFactory) { if (classNode != null && classNode.getField(fieldName) == null) { FieldNode mixinInstanceFieldNode = classNode.addField(fieldName, Modifier.PRIVATE | (implementsClassRuleFactory ? Modifier.STATIC : 0), fieldType, new ConstructorCallExpression(fieldType, MethodCallExpression.NO_ARGUMENTS)); String ruleFieldNameBase = fieldName; boolean spockTest = isSpockTest(classNode); if (implementsClassRuleFactory) { FieldNode staticRuleFieldNode = classNode.addField(ruleFieldNameBase + "StaticClassRule", Modifier.PRIVATE | Modifier.STATIC, ClassHelper.make(TestRule.class), new MethodCallExpression(new FieldExpression(mixinInstanceFieldNode), "newClassRule", new ClassExpression(classNode))); AnnotationNode classRuleAnnotation = new AnnotationNode(ClassHelper.make(ClassRule.class)); if (spockTest) { // @ClassRule must be added to @Shared field in spock FieldNode spockSharedRuleFieldNode = classNode.addField(ruleFieldNameBase + "SharedClassRule", Modifier.PUBLIC, ClassHelper.make(TestRule.class), new FieldExpression(staticRuleFieldNode)); spockSharedRuleFieldNode.addAnnotation(classRuleAnnotation); spockSharedRuleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Shared.class))); if (spockTest) { addSpockFieldMetadata(spockSharedRuleFieldNode, 0); }//from w w w .jav a 2 s .c om } else { staticRuleFieldNode.setModifiers(Modifier.PUBLIC | Modifier.STATIC); staticRuleFieldNode.addAnnotation(classRuleAnnotation); } } if (implementsRuleFactory) { FieldNode ruleFieldNode = classNode.addField(ruleFieldNameBase + "Rule", Modifier.PUBLIC, ClassHelper.make(TestRule.class), new MethodCallExpression(new FieldExpression(mixinInstanceFieldNode), "newRule", new VariableExpression("this"))); ruleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Rule.class))); if (spockTest) { addSpockFieldMetadata(ruleFieldNode, 0); } } return mixinInstanceFieldNode; } return null; }
From source file:org.gvnix.flex.FlexScaffoldMetadata.java
private MethodMetadata getShowMethod() { JavaSymbolName methodName = new JavaSymbolName("show"); MethodMetadata method = methodExists(methodName); if (method != null) { return method; }//from w w w .ja v a 2 s. c o m // TODO In Roo 1.2.2 migration the identifier fields are multiple: // temporary get first element FieldMetadata identifierField = persistenceMemberLocator.getIdentifierFields(entity).get(0); List<AnnotatedJavaType> paramTypes = new ArrayList<AnnotatedJavaType>(); paramTypes.add(new AnnotatedJavaType(identifierField.getFieldType(), new ArrayList<AnnotationMetadata>())); List<JavaSymbolName> paramNames = new ArrayList<JavaSymbolName>(); paramNames.add(new JavaSymbolName(identifierField.getFieldName().getSymbolName())); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); if (!identifierField.getFieldType().isPrimitive()) { bodyBuilder.appendFormalLine("if (" + identifierField.getFieldName().getSymbolName() + " == null) throw new IllegalArgumentException(\"An Identifier is required\");"); } bodyBuilder.appendFormalLine("return " + this.entity.getNameIncludingTypeParameters(false, this.builder.getImportRegistrationResolver()) + "." + this.entityMetadata.getFindMethod().getMethodName() + "(" + identifierField.getFieldName().getSymbolName() + ");"); return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, this.entity, paramTypes, paramNames, bodyBuilder).build(); }