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.service.roo.addon.addon.security.WSServiceSecurityMetadata.java
/** * Returns default class constructor (with no parameters) * //from w ww . j a v a 2 s .c o m * @return */ private ConstructorMetadata getDefaultConstructor() { // Checks if default constructor is already defined for (ConstructorMetadata constructor : governorTypeDetails.getDeclaredConstructors()) { if (constructor.getParameterTypes() == null || constructor.getParameterTypes().isEmpty()) { return constructor; } } // Create the constructor InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("super();"); ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(getId()); constructorBuilder.setModifier(Modifier.PUBLIC); constructorBuilder.setBodyBuilder(bodyBuilder); return constructorBuilder.build(); }
From source file:org.exem.flamingo.shared.util.el.ELServiceImpl.java
public static Method findMethod(String className, String methodName) throws ServiceException { Method method = null;/*from w ww . j a va2s . c o m*/ try { Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className); for (Method m : clazz.getMethods()) { if (m.getName().equals(methodName)) { method = m; break; } } if (method == null) { // throw new ServiceException(ErrorCode.E0111, className, methodName); } if ((method.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC)) != (Modifier.PUBLIC | Modifier.STATIC)) { // throw new ServiceException(ErrorCode.E0112, className, methodName); } } catch (ClassNotFoundException ex) { // throw new ServiceException(ErrorCode.E0113, className); } return method; }
From source file:org.ops4j.gaderian.strategy.TestStrategyFactory.java
public void testBuildImplementationClassImproperMethod() { Location l = newLocation();//ww w . ja v a 2 s. com ClassFactory factory = createMock(ClassFactory.class); ClassFab cf = createMock(ClassFab.class); MethodFab mf = createMock(MethodFab.class); ServiceImplementationFactoryParameters fp = createMock(ServiceImplementationFactoryParameters.class); ErrorLog log = createMock(ErrorLog.class); expect(fp.getServiceInterface()).andReturn(Runnable.class); final StrategyParameter param = new StrategyParameter(); expect(fp.getFirstParameter()).andReturn(param); expect(factory.newClass("NewClass", Object.class)).andReturn(cf); cf.addInterface(Runnable.class); cf.addField("_registry", StrategyRegistry.class); Capture<Class[]> classCapture = new Capture<Class[]>(); cf.addConstructor(capture(classCapture), (Class[]) eq(null), eq("_registry = $1;")); expect(cf.addMethod(Modifier.PRIVATE, new MethodSignature(Runnable.class, "_getStrategy", new Class[] { Object.class }, null), "return (java.lang.Runnable) _registry.getStrategy($1.getClass());")).andReturn(mf); MethodSignature sig = new MethodSignature(void.class, "run", null, null); expect(cf.addMethod(Modifier.PUBLIC, sig, "{ }")).andReturn(mf); expect(fp.getErrorLog()).andReturn(log); // Slight fudge: we return the location itself when we should return // an object with this location. expect(fp.getFirstParameter()).andReturn(l); log.error(StrategyMessages.improperServiceMethod(sig), l, null); expect(fp.getServiceId()).andReturn("foo.Bar"); ClassFabUtils.addToStringMethod(cf, StrategyMessages.toString("foo.Bar", Runnable.class)); expectLastCall().andReturn(mf); expect(cf.createClass()).andReturn(String.class); replayAllRegisteredMocks(); StrategyFactory f = new StrategyFactory(); f.setClassFactory(factory); f.buildImplementationClass(fp, "NewClass"); verifyAllRegisteredMocks(); }
From source file:org.openflamingo.uploader.el.ELService.java
public static Method findMethod(String className, String methodName) throws SystemException { Method method = null;//from ww w . j av a 2 s . c o m try { Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className); for (Method m : clazz.getMethods()) { if (m.getName().equals(methodName)) { method = m; break; } } if (method == null) { // throw new SystemException(ErrorCode.E0111, className, methodName); } if ((method.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC)) != (Modifier.PUBLIC | Modifier.STATIC)) { // throw new SystemException(ErrorCode.E0112, className, methodName); } } catch (ClassNotFoundException ex) { // throw new SystemException(ErrorCode.E0113, className); } return method; }
From source file:io.stallion.reflection.PropertyUtils.java
public static List<String> getPropertyNames(Class clazz) throws PropertyException { Method[] methods = clazz.getMethods(); List<String> names = list(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; String name = method.getName(); if (method.getModifiers() == Modifier.PUBLIC && method.getParameterTypes().length == 0 && (name.startsWith("get") || name.startsWith("is")) && containsSetterForGetter(clazz, method)) { String propertyName;//w w w.j av a2 s. co m if (name.startsWith("get")) propertyName = Character.toLowerCase(name.charAt(3)) + name.substring(4); else propertyName = Character.toLowerCase(name.charAt(2)) + name.substring(3); names.add(propertyName); } } return names; }
From source file:org.codehaus.groovy.grails.compiler.injection.DefaultGrailsDomainClassInjector.java
private void injectVersionProperty(ClassNode classNode) { final boolean hasVersion = /*GrailsASTUtils.*/hasProperty(classNode, /*GrailsDomainClassProperty.*/VERSION); if (!hasVersion) { //if(LOG.isDebugEnabled()) { // LOG.debug("[GrailsDomainInjector] Adding property [" + GrailsDomainClassProperty.VERSION + "] to class [" + classNode.getName() + "]"); //}// ww w . j a va2 s . co m classNode.addProperty( /*GrailsDomainClassProperty.*/VERSION, Modifier.PUBLIC, new ClassNode(Long.class), null, null, null); } }
From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderExtLoadWSS4JMetadata.java
/** * Generates constructor method with arguments *///from w ww . ja v a2s . co m private ConstructorMetadataBuilder getExtLoadWSS4JConstWithParam() { // Define method parameter types List<JavaType> parameterTypes = new ArrayList<JavaType>(); parameterTypes.add(new JavaType("java.util.Map", 0, DataType.TYPE, null, Arrays.asList(JavaType.STRING, JavaType.OBJECT))); // Search for an existing constructor final ConstructorMetadata existingExplicitConstructor = governorTypeDetails .getDeclaredConstructor(parameterTypes); if (existingExplicitConstructor != null) { // Found an existing constructor on this class with this params, so // return it return new ConstructorMetadataBuilder(existingExplicitConstructor); } // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("super(props);"); // Use the ConstructorMetadataBuilder for easy creation of // MethodMetadata ConstructorMetadataBuilder consBuilder = new ConstructorMetadataBuilder(getId()); // Set parameters consBuilder.addParameter("props", parameterTypes.get(0)); // Set the modifier public to constructor consBuilder.setModifier(Modifier.PUBLIC); // Set the body to constructor consBuilder.setBodyBuilder(bodyBuilder); // return a ConstructorMetadataBuilder instance return consBuilder; }
From source file:fr.imag.model2roo.addon.graph.GraphOperationsImpl.java
@Override public void newRepository(final JavaType name, final JavaType domainType) { String entityId;/* w w w. j a va2s. co m*/ GraphProvider graphProvider; List<JavaType> repositoryParameters; ClassOrInterfaceTypeDetailsBuilder entityBuilder; // Create repository class entityId = PhysicalTypeIdentifier.createIdentifier(name, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); entityBuilder = new ClassOrInterfaceTypeDetailsBuilder(entityId, Modifier.PUBLIC, name, PhysicalTypeCategory.INTERFACE); // Add neo4j repository base class repositoryParameters = new ArrayList<JavaType>(); repositoryParameters.add(domainType); graphProvider = this.getCurrentGraphProvider(); for (String baseClass : graphProvider.getRepositoryBaseClasses()) { entityBuilder.addExtendsTypes(new JavaType(baseClass, 0, DataType.TYPE, null, repositoryParameters)); } // Save repository typeManagementService.createOrUpdateTypeOnDisk(entityBuilder.build()); }
From source file:org.carewebframework.cal.ui.reporting.drilldown.DrillDownDisplay.java
/** * When debug is true, dataObject is interrogated and the classes get/bean methods are invoked * and displayed on the display as well. * * @param dataObject Object to interrogate. * @param checkOnly If true, only checks to see if the object has additional debug info. * @return True if the object is a type for which additional debug info is available.. *//*from w w w . j a va 2s . c o m*/ private boolean debugObject(Object dataObject, boolean checkOnly) { if (dataObject != null) { Row row; Class<?> clazz = dataObject.getClass(); if (!checkOnly) { log.debug("Adding Verbose DrillDown Object Debug Information"); addRow("-------DEBUG--------", clazz.getName()); row = getLastRow(); row.appendChild(new Label()); row.setSclass(Constants.SCLASS_DRILLDOWN_GRID); } try { Object[] params = null; //Method[] methods = clazz.getDeclaredMethods(); Method[] methods = clazz.getMethods(); if (!(dataObject instanceof String)) { for (Method method : methods) { if (Modifier.PUBLIC == method.getModifiers()) { // Assumes getter methods if (method.getName().startsWith("get") && method.getGenericParameterTypes().length == 0) { if (checkOnly) { return true; } Object invokedObject = method.invoke(getDataObject(), params); String methodName = method.getName(); addRowViaObject(methodName, invokedObject); addLink(invokedObject, clazz.getName() + "." + methodName); } } } } } catch (Exception e) { log.error(e.getMessage(), e); } } return false; }
From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderAuthenticationFilterMetadata.java
/** * Gets all setters methods. <br>//ww w. j av a2 s . co m * * @return */ private MethodMetadata getSetterMethod(String propertyName, JavaType parameterType) { // Define method parameter types List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(parameterType); // Check if a method with the same signature already exists in the // target type JavaSymbolName propertyMethodName = new JavaSymbolName( "set".concat(Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1))); final MethodMetadata method = methodExists(propertyMethodName, 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(propertyName)); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildSetterMethodBody(bodyBuilder, propertyName); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, propertyMethodName, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }