List of usage examples for java.lang Class getMethods
@CallerSensitive public Method[] getMethods() throws SecurityException
From source file:net.mindengine.oculus.frontend.db.jdbc.BeanMappingFactory.java
public void loadBean(Node node) throws Exception { BeanMapper beanMapper = new BeanMapper(); beanMapper.setClassName(getAttribute(node, "class")); Class<?> clazz = Class.forName(beanMapper.getClassName()); Method[] methods = clazz.getMethods(); Map<String, FieldMapper> fields = new HashMap<String, FieldMapper>(); NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node n = nodeList.item(i); if ("property".equals(n.getNodeName())) { String property = getAttribute(n, "name"); String column = getAttribute(n, "column"); String setter = beanMapper.createSetter(property); FieldMapper fieldMapper = new FieldMapper(); fieldMapper.setProperty(property); fieldMapper.setColumn(column); boolean bFound = false; for (int j = 0; j < methods.length && !bFound; j++) { if (methods[j].getName().equals(setter)) { fieldMapper.setMethod(methods[j]); bFound = true;/*from w w w.j a v a 2s . co m*/ } } if (!bFound) { throw new Exception("There is no setter method for property '" + property + "'"); } fields.put(fieldMapper.getColumn(), fieldMapper); } } beanMapper.setFields(fields); beans.put(beanMapper.getClassName(), beanMapper); }
From source file:edu.umn.msi.tropix.common.reflect.ReflectionHelperImpl.java
public boolean hasMethod(final Class<?> clazz, final String name) { boolean hasMethod = false; for (Method method : clazz.getMethods()) { if (method.getName().equals(name)) { hasMethod = true;// w w w. j a v a 2 s .c o m break; } } return hasMethod; }
From source file:pl.bristleback.server.bristle.conf.resolver.action.client.ClientActionClassesResolver.java
private Map<String, ClientActionInformation> prepareActions(Class<?> actionClass, String actionClassName) { Map<String, ClientActionInformation> actionsMap = new HashMap<String, ClientActionInformation>(); for (Method action : actionClass.getMethods()) { ClientAction actionClassAnnotation = AnnotationUtils.findAnnotation(action, ClientAction.class); if (actionClassAnnotation != null) { ClientActionInformation actionInformation = clientActionResolver .prepareActionInformation(actionClassName, action); actionsMap.put(actionInformation.getName(), actionInformation); }/* w w w.j a v a 2 s .c o m*/ } return actionsMap; }
From source file:org.querybyexample.jpa.JpaUniqueUtil.java
private Method columnNameToMethod(Class<?> clazz, String columnName) { for (Method method : clazz.getMethods()) { Column column = method.getAnnotation(Column.class); if (column != null && equalsIgnoreCase(columnName, column.name())) { return method; }//from w w w . ja v a2 s. c o m } return null; }
From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java
@Test public void checkImplementedMethods() { Class<?> bukkitEvent = eventImpl.getSuperclass(); for (Method method : bukkitEvent.getMethods()) { int modifiers = method.getModifiers(); if (Modifier.isStatic(modifiers) || isDefault(method) || method.getDeclaringClass() == Event.class || method.getDeclaringClass() == Object.class || method.getName().equals("getHandlers") || method.getName().startsWith("_INVALID_")) { continue; }//w ww .j ava 2 s . com try { eventImpl.getDeclaredMethod(method.getName(), method.getParameterTypes()); } catch (NoSuchMethodException e) { fail(eventImpl.getSimpleName() + ": should override method " + method); } } }
From source file:com.jcraft.weirdx.XJSExtension.java
XJSExtension() { try {/*from w w w . j a va 2 s . co m*/ Method getw = null; Class<?> c = Class.forName("netscape.javascript.JSObject"); Method ms[] = c.getMethods(); for (int i = 0; i < ms.length; i++) { if (ms[i].getName().compareTo("getWindow") == 0) { getw = ms[i]; } else if (ms[i].getName().compareTo("call") == 0) { jscall = ms[i]; } else if (ms[i].getName().compareTo("eval") == 0) { jseval = ms[i]; } } Object a[] = new Object[1]; a[0] = WeirdX.weirdx; jswin = getw.invoke(c, a); } catch (Exception ee) { } eventcount = 0; errorcount = 0; ctyp = XResource.newType(); etyp = XResource.newType(); name = "WeirdX-JavaScript"; }
From source file:com.bstek.dorado.data.config.DataObjectAnnotationEngineStartupListener.java
@SuppressWarnings("rawtypes") public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) {/*from w w w. j a v a2 s.c om*/ for (Method method : beanType.getMethods()) { DataProvider dataProviderAnnotation = method.getAnnotation(DataProvider.class); if (dataProviderAnnotation != null) { pendingDataObjects.add(new PendingDataObject(DataObjectType.dataProvider, dataProviderAnnotation, beanName, method.getName())); } DataResolver dataResolverAnnotation = method.getAnnotation(DataResolver.class); if (dataResolverAnnotation != null) { pendingDataObjects.add(new PendingDataObject(DataObjectType.dataResolver, dataResolverAnnotation, beanName, method.getName())); } } }
From source file:com.kixeye.chassis.transport.websocket.WebSocketMessageMappingRegistry.java
@PostConstruct public void registerWebSocketActions() throws BeansException { String[] controllerBeanNames = beanFactory.getBeanNamesForAnnotation(WebSocketController.class); if (controllerBeanNames != null && controllerBeanNames.length > 0) { try {/* w w w . j a v a 2 s . co m*/ for (String beanName : controllerBeanNames) { BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); Class<?> beanClass = Class.forName(beanDef.getBeanClassName()); for (Method method : beanClass.getMethods()) { ActionMapping mapping = method.getAnnotation(ActionMapping.class); if (mapping != null) { if (mapping.value() != null && mapping.value().length > 0) { Map<String, String> requirements = new HashMap<>(); if (mapping.propertyRequirements() != null) { for (ActionPropertyRequirement requirement : mapping.propertyRequirements()) { requirements.put(requirement.name(), requirement.value()); } } for (String action : mapping.value()) { logger.info("Registering destination [{}] with handler [{}].", action, method.toString()); Map<String, WebSocketActionArgumentResolver> argumentResolverBeans = beanFactory .getBeansOfType(WebSocketActionArgumentResolver.class); if (argumentResolverBeans != null && !argumentResolverBeans.isEmpty()) { logger.info( "Registering WebSocketActionArgumentResolver beans {} with action {}", Joiner.on(",").join(argumentResolverBeans.keySet(), action)); } actions.put(action, new WebSocketAction(method, requirements, argumentResolverBeans == null ? null : argumentResolverBeans.values().toArray( new WebSocketActionArgumentResolver[argumentResolverBeans .size()]))); } } } } } } catch (Exception e) { throw new FatalBeanException("Unable to configure bean", e); } } else { logger.warn("No WebSocketController beans defined."); } }
From source file:com.fluidops.iwb.api.CommunicationServiceImpl.java
/** * lookup getter method for a given property * @param ifc the ontology class/*from ww w . j av a 2 s. c o m*/ * @param prop the prop / method name * @return the method getting the prop name * @throws NoSuchMethodException */ public static Method getGetter(Class<?> ifc, String prop) throws NoSuchMethodException { for (Method method : ifc.getMethods()) if (method.getParameterTypes().length == 0) { if (method.getName().equals(StringUtil.beanifyField(prop, "get"))) return method; if (method.getName().equals(StringUtil.beanifyField(prop, "is"))) return method; if (method.getName().equals(prop)) return method; OWLProperty p = AnnotationProcessor.getOWLProperty(ifc, method); if (p != null) { if (p.propName().equals(prop)) return method; if (EndpointImpl.api().getNamespaceService().guessURIOrCreateInDefaultNS(p.propName()) .equals(EndpointImpl.api().getNamespaceService().guessURIOrCreateInDefaultNS(prop))) return method; } } return null; }
From source file:com.bfd.harpc.config.spring.HarpcBeanDefinitionParser.java
/** * {@link#parse}/* w w w . j ava 2 s. c om*/ * <p> * * @param element * @param parserContext * @param clazz * @return {@link BeanDefinition} */ private BeanDefinition parse(Element element, ParserContext parserContext, Class<?> clazz) { RootBeanDefinition beanDefinition = new RootBeanDefinition(); beanDefinition.setBeanClass(clazz); Method[] methods = clazz.getMethods(); String id = StringUtils.EMPTY; for (Method method : methods) { if (method.getName().length() > 3 && method.getName().startsWith("set") && method.getParameterTypes().length == 1) { String attribute = method.getName().substring(3); char ch = attribute.charAt(0); attribute = Character.toLowerCase(ch) + attribute.substring(1); String value = element.getAttribute(attribute); if (StringUtils.isNotEmpty(value)) { Type type = method.getParameterTypes()[0]; if (type == boolean.class) { beanDefinition.getPropertyValues().addPropertyValue(attribute, Boolean.valueOf(value)); } else { if ("ref".equals(attribute) && parserContext.getRegistry().containsBeanDefinition(value)) { beanDefinition.getPropertyValues().addPropertyValue(attribute, new RuntimeBeanReference(value)); } else { beanDefinition.getPropertyValues().addPropertyValue(attribute, value); if ("id".equals(attribute)) { id = value; } } } } } } parserContext.getRegistry().registerBeanDefinition(id, beanDefinition); return beanDefinition; }