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.query.JpaQueryMetadata.java
/** * Create metadata for a field definition. * //from www. ja va2 s. c o m * @return a FieldMetadata object */ private FieldMetadata getFilterByField() { if (filterByField == null) { JavaSymbolName curName = new JavaSymbolName("filterByAssociations"); String initializer = "null"; int modifier = Modifier.PUBLIC + Modifier.STATIC; filterByField = getOrCreateField(curName, MAP_STRING_LIST_STRING, initializer, modifier, null); } return filterByField; }
From source file:org.gvnix.addon.geo.addon.GvNIXWebEntityMapLayerMetadata.java
/** * Gets <code>listGeoEntityOnMapViewer</code> method. <br> * /*from ww w.jav a2 s . c o m*/ * @return */ private MethodMetadata getListGeoEntityOnMapViewerMethod(JavaType entity, String plural) { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); // @RequestParam(required = false, value = "GeometryFilter") // GeometryFilter geomFilter AnnotationMetadataBuilder geometryAnnotation = new AnnotationMetadataBuilder(SpringJavaType.REQUEST_PARAM); geometryAnnotation.addBooleanAttribute("required", false); geometryAnnotation.addStringAttribute("value", "GeometryFilter"); parameterTypes .add(new AnnotatedJavaType(new JavaType("org.gvnix.jpa.geo.hibernatespatial.util.GeometryFilter"), geometryAnnotation.build())); // @RequestParam(required = false, value="fields") String[] fields AnnotationMetadataBuilder fieldsAnnotation = new AnnotationMetadataBuilder(SpringJavaType.REQUEST_PARAM); fieldsAnnotation.addBooleanAttribute("required", false); fieldsAnnotation.addStringAttribute("value", "fields"); parameterTypes.add(new AnnotatedJavaType(JavaType.STRING_ARRAY, fieldsAnnotation.build())); // @RequestParam(required = false, value="scale") String scale AnnotationMetadataBuilder scaleAnnotation = new AnnotationMetadataBuilder(SpringJavaType.REQUEST_PARAM); scaleAnnotation.addBooleanAttribute("required", false); scaleAnnotation.addStringAttribute("value", "scale"); parameterTypes.add(new AnnotatedJavaType(JavaType.STRING, scaleAnnotation.build())); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("geomFilter")); parameterNames.add(new JavaSymbolName("fields")); parameterNames.add(new JavaSymbolName("scale")); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(LIST_GEO_ENTITY_ON_MAP_VIEWER, 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 = "entityMapList", headers = // "Accept=application/json", produces = "application/json", consumes = // "application/json") requestMappingMetadataBuilder.addStringAttribute("params", "entityMapList"); requestMappingMetadataBuilder.addStringAttribute("headers", "Accept=application/json"); requestMappingMetadataBuilder.addStringAttribute("produces", "application/json"); requestMappingMetadataBuilder.addStringAttribute("consumes", "application/json"); // @ResponseBody AnnotationMetadataBuilder responseBodyMetadataBuilder = new AnnotationMetadataBuilder( SpringJavaType.RESPONSE_BODY); annotations.add(requestMappingMetadataBuilder); annotations.add(responseBodyMetadataBuilder); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildlistGeoEntityOnMapViewerMethodBody(entity, plural, bodyBuilder); // Return type: ResponseEntity<List<Owner>> JavaType responseEntityJavaType = new JavaType(SpringJavaType.RESPONSE_ENTITY.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(new JavaType("java.util.List", 0, DataType.TYPE, null, Arrays.asList(entity)))); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, LIST_GEO_ENTITY_ON_MAP_VIEWER, responseEntityJavaType, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:io.stallion.reflection.PropertyUtils.java
public static <T extends Annotation> T getAnnotationForProperty(Class cls, String name, Class<T> anno) { String postFix = name.toUpperCase(); if (name.length() > 1) { postFix = name.substring(0, 1).toUpperCase() + name.substring(1); }/*from ww w . j a va 2 s.c o m*/ Method method = null; try { method = cls.getMethod("get" + postFix); } catch (NoSuchMethodException e) { } if (method == null) { try { method = cls.getMethod("is" + postFix); } catch (NoSuchMethodException e) { } } if (method == null) { return null; } if (method.getModifiers() != Modifier.PUBLIC) { return null; } if (method.isAnnotationPresent(anno)) { return method.getDeclaredAnnotation(anno); } return null; }
From source file:org.gvnix.addon.jpa.addon.query.JpaQueryMetadata.java
/** * Create metadata for a field definition. * //from www . j a va 2s. com * @return a FieldMetadata object */ private FieldMetadata getOrderByField() { if (orderByField == null) { JavaSymbolName curName = new JavaSymbolName("orderyByAssociations"); String initializer = "null"; int modifier = Modifier.PUBLIC + Modifier.STATIC; orderByField = getOrCreateField(curName, MAP_STRING_LIST_STRING, initializer, modifier, null); } return orderByField; }
From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderUserAuthorityMetadata.java
/** * Gets <code>equals</code> method. <br> * /*from w ww . j a v a 2 s. com*/ * @return */ private MethodMetadata getEqualsMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(JavaType.OBJECT); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(EQUALS_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>(); parameterNames.add(new JavaSymbolName("obj")); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildEqualsMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, EQUALS_METHOD, JavaType.BOOLEAN_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:com.sap.research.connectivity.gw.GwOperationsImpl.java
public void createEntity(final String endpointName, final String remoteEntitySetName) throws Exception { final String subPackagePath = getSubPackagePath(oDataFolder); // Verify if the endpoint and remote entity set are valid if (!fileManager.exists(subPackagePath + SEPARATOR + endpointName + "_metadata.xml")) { throw new Exception("Namespace \"" + endpointName + "\" does not exist or is corrupted. Please specify a valid namespace."); } else {//from w w w. ja v a 2 s . c o m InputStream metaDataIs = fileManager .getInputStream(subPackagePath + SEPARATOR + endpointName + "_metadata.xml"); Document doc = XmlUtils.getDocumentBuilder().parse(metaDataIs); NodeList nodeList = doc.getElementsByTagName("entity"); boolean remoteEntityExists = false; for (int i = 0; i < nodeList.getLength(); i++) { Attr attr = (Attr) nodeList.item(i).getAttributes().getNamedItem("name"); if (attr.getValue().toString().equals(remoteEntitySetName)) { remoteEntityExists = true; break; } } if (!remoteEntityExists) { throw new Exception("Remote entity set \"" + remoteEntitySetName + "\" does not exist. Please specify a valid remote entity."); } } // Create entity class and add JPA Annotations. int modifier = Modifier.PUBLIC; String localEntityPath = typeLocationService.getTopLevelPackageForModule( projectOperations.getFocusedModule()) + "." + domain + "." + remoteEntitySetName; JavaType localEntity = new JavaType(localEntityPath); final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(localEntity, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder( declaredByMetadataId, modifier, localEntity, PhysicalTypeCategory.CLASS); final List<AnnotationMetadataBuilder> annotationBuilder = new ArrayList<AnnotationMetadataBuilder>(); annotationBuilder.add(ROO_JAVA_BEAN_BUILDER); annotationBuilder.add(ROO_TO_STRING_BUILDER); annotationBuilder.add(ROO_JPA_ACTIVE_RECORD_BUILDER); cidBuilder.setAnnotations(annotationBuilder); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); }
From source file:fr.imag.model2roo.addon.graph.GraphOperationsImpl.java
@Override public void newRelationshipEntity(final JavaType name, final String type, final JavaType startNode, final JavaType endNode, List<String> properties) { String entityId;//from w w w. j a va2s. c o m GraphProvider graphProvider; FieldMetadataBuilder fieldBuilder; ClassOrInterfaceTypeDetails entityDetails; ClassOrInterfaceTypeDetailsBuilder entityBuilder; List<AnnotationMetadataBuilder> relationshipAnnotations; // Create relationship class entityId = PhysicalTypeIdentifier.createIdentifier(name, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); entityBuilder = new ClassOrInterfaceTypeDetailsBuilder(entityId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS); // Associate appropriate annotations graphProvider = this.getCurrentGraphProvider(); relationshipAnnotations = graphProvider.getRelationshipEntityAnnotations(); for (AnnotationMetadataBuilder annotation : relationshipAnnotations) { annotation.addStringAttribute("type", type); } entityBuilder.setAnnotations(relationshipAnnotations); entityBuilder.addAnnotation(ROO_JAVA_BEAN_BUILDER); entityBuilder.addAnnotation(ROO_TO_STRING_BUILDER); typeManagementService.createOrUpdateTypeOnDisk(entityBuilder.build()); // Id entityDetails = typeLocationService.getTypeDetails(name); fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, graphProvider.getIdAnnotations(), new JavaSymbolName("relationshipId"), JavaType.LONG_OBJECT); entityBuilder.addField(fieldBuilder.build()); // Start node fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, graphProvider.getRelationshipStartNodeAnnotations(), new JavaSymbolName("startNode"), startNode); entityBuilder.addField(fieldBuilder.build()); // End node fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, graphProvider.getRelationshipEndNodeAnnotations(), new JavaSymbolName("endNode"), endNode); entityBuilder.addField(fieldBuilder.build()); // Properties if (properties != null) { // One field of type String for each property for (String property : properties) { fieldBuilder = new FieldMetadataBuilder(entityDetails.getDeclaredByMetadataId(), Modifier.PRIVATE, new ArrayList<AnnotationMetadataBuilder>(), new JavaSymbolName(property), JavaType.STRING); entityBuilder.addField(fieldBuilder.build()); } } typeManagementService.createOrUpdateTypeOnDisk(entityBuilder.build()); }
From source file:com.yek.keyboard.ChewbaccaUncaughtExceptionHandler.java
private void addResourceNameWithId(StringBuilder resources, int resourceId, Class clazz) { for (Field field : clazz.getFields()) { if (field.getType().equals(int.class)) { if ((field.getModifiers() & (Modifier.STATIC | Modifier.PUBLIC)) != 0) { try { if (resourceId == field.getInt(null)) { resources.append(clazz.getName()).append(".").append(field.getName()); resources.append('\n'); }/*from w ww . j a va 2 s .com*/ } catch (IllegalAccessException e) { Logger.d("EEEE", "Failed to access " + field.getName(), e); } } } } }
From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogEntityMetadataBuilder.java
private MethodMetadata getRevisionDate() { if (revsionDateGetter == null) { JavaSymbolName methodName = helper.getGetterMethodNameForField(REVISION_DATE_TRANSIENT_FIELD); // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(0); // Check if a method exist in type final MethodMetadata method = helper.methodExists(methodName, parameterTypes); if (method != null) { // If it already exists, just return the method return method; }/*from w ww .j a v a 2s .c om*/ // Define method annotations (none in this case) List<AnnotationMetadataBuilder> annotations = helper.toAnnotationMetadata(JpaJavaType.TRANSIENT); // 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 Date(this.timestamp); body.appendFormalLine(String.format("return new %s(this.%s);", helper.getFinalTypeName(JdkJavaType.DATE), TIMESTAMP_FIELD)); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(context.getMetadataId(), Modifier.PUBLIC, methodName, JdkJavaType.DATE, parameterTypes, parameterNames, body); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); revsionDateGetter = methodBuilder.build(); // Build and return a // MethodMetadata } return revsionDateGetter; }
From source file:fr.imag.model2roo.addon.graph.NodeEntityMetadata.java
private MethodMetadataBuilder getIdentifierMutator() { if (parent != null) { final MethodMetadataBuilder parentIdMutator = parent.getIdentifierMutator(); if (parentIdMutator != null && parentIdMutator.getParameterTypes().get(0).getJavaType().equals(idType)) { return parentIdMutator; }/*ww w . j av a2 s.c o m*/ } JavaSymbolName requiredMutatorName = BeanInfoUtils.getMutatorMethodName(idField); final List<JavaType> parameterTypes = Arrays.asList(idField.getFieldType()); final List<JavaSymbolName> parameterNames = Arrays.asList(new JavaSymbolName("id")); // See if the user provided the field if (!getId().equals(idField.getDeclaredByMetadataId())) { // Locate an existing mutator final MethodMetadata method = memberDetails.getMethod(requiredMutatorName, parameterTypes); if (method != null) { if (Modifier.isPublic(method.getModifier())) { // Method exists and is public so return it return new MethodMetadataBuilder(method); } // Method is not public so make the required mutator name unique requiredMutatorName = new JavaSymbolName(requiredMutatorName.getSymbolName() + "_"); } } // We declared the field in this ITD, so produce a public mutator for it final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("this." + idField.getFieldName().getSymbolName() + " = id;"); return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, requiredMutatorName, JavaType.VOID_PRIMITIVE, AnnotatedJavaType.convertFromJavaTypes(parameterTypes), parameterNames, bodyBuilder); }