List of usage examples for java.beans Introspector decapitalize
public static String decapitalize(String name)
From source file:com.panet.imeta.core.config.KettleConfig.java
private <E extends AccessibleObject> void inject(E[] elems, TempConfig cfg, ConfigManager<?> parms) throws IllegalAccessException, InvocationTargetException { for (AccessibleObject elem : elems) { Inject inj = elem.getAnnotation(Inject.class); if (inj != null) { // try to inject property from map. elem.setAccessible(true);/* w w w.j ava 2 s .c o m*/ String property = inj.property(); // Can't think of any other way if (elem instanceof Method) { Method meth = (Method) elem; // find out what we are going to inject 1st property = property.equals("") ? Introspector.decapitalize(meth.getName().substring(3)) : property; meth.invoke(parms, cfg.parms.get(property)); } else if (elem instanceof Field) { Field field = (Field) elem; field.set(parms, cfg.parms.get(property.equals("") ? field.getName() : property)); } } } }
From source file:com.opensymphony.able.introspect.EntityInfo.java
protected String createEntityUri() { return Introspector.decapitalize(getEntityName()); }
From source file:com.chiralbehaviors.CoRE.phantasm.graphql.schemas.JooqSchema.java
@SuppressWarnings("unchecked") private void contributeQueries(Builder query, Class<?> record, GraphQLObjectType type) { query.field(// w ww .j a v a2 s . c o m b -> b.name(Introspector.decapitalize(translated(record))).type(type) .argument(a -> a.name("id").type(new GraphQLNonNull(GraphQLUuid)) .description(String.format("ID of the %s", translated(record)))) .dataFetcher(env -> { UUID id = env.getArgument("id"); return fetch(id, record, env); })); query.field( b -> b.name(Introspector.decapitalize(String.format("%ss", translated(record)))) .type(new GraphQLList(type)) .argument(a -> a.name("ids").type(new GraphQLList(GraphQLUuid)) .description(String.format("IDs of the %s", translated(record)))) .dataFetcher(env -> { List<UUID> ids = (List<UUID>) env.getArgument("ids"); if (ids == null) { return fetchAll(record, env); } return ids.stream().map(id -> fetch(id, record, env)).collect(Collectors.toList()); })); }
From source file:hudson.model.Descriptor.java
/** * Obtains the property type of the given field of {@link #clazz} *//*from w ww . jav a2s . c om*/ public PropertyType getPropertyType(String field) { if (propertyTypes == null) { Map<String, PropertyType> r = new HashMap<String, PropertyType>(); for (Field f : clazz.getFields()) r.put(f.getName(), new PropertyType(f)); for (Method m : clazz.getMethods()) if (m.getName().startsWith("get")) r.put(Introspector.decapitalize(m.getName().substring(3)), new PropertyType(m)); propertyTypes = r; } return propertyTypes.get(field); }
From source file:org.toobsframework.data.beanutil.BeanMonkey.java
public static Collection populateCollection(IValidator v, String beanClazz, String indexPropertyName, Map properties, boolean validate, boolean noload) throws IllegalAccessException, InvocationTargetException, ValidationException, ClassNotFoundException, InstantiationException, PermissionException { // Do nothing unless all arguments have been specified if ((beanClazz == null) || (properties == null) || (indexPropertyName == null)) { log.warn("Proper parameters not present."); return null; }//from w w w . j a v a2s. co m ArrayList returnObjs = new ArrayList(); Object[] indexProperty = (Object[]) properties.get(indexPropertyName); if (indexProperty == null) { log.warn("indexProperty [" + indexProperty + "] does not exist in the map."); return returnObjs; } Class beanClass = Class.forName(beanClazz); String beanClazzName = beanClass.getSimpleName(); // beanClazz.substring(beanClazz.lastIndexOf(".") + 1); IObjectLoader odao = null; ICollectionLoader cdao = null; if (objectClass.isAssignableFrom(beanClass)) { odao = (IObjectLoader) beanFactory.getBean( Introspector.decapitalize(beanClazzName.substring(0, beanClazzName.length() - 4)) + "Dao"); if (odao == null) { throw new InvocationTargetException(new Exception("Object DAO class " + Introspector.decapitalize(beanClazzName) + "Dao could not be loaded")); } } else { cdao = (ICollectionLoader) beanFactory.getBean( Introspector.decapitalize(beanClazzName.substring(0, beanClazzName.length() - 4)) + "Dao"); if (cdao == null) { throw new InvocationTargetException(new Exception("Collection DAO class " + Introspector.decapitalize(beanClazzName) + "Dao could not be loaded")); } } boolean namespaceStrict = properties.containsKey("namespaceStrict"); for (int index = 0; index < indexProperty.length; index++) { String guid = (String) indexProperty[index]; boolean newBean = false; Object bean = null; if (!noload && guid != null && guid.length() > 0) { bean = (odao != null) ? odao.load(guid) : cdao.load(Integer.parseInt(guid)); } if (bean == null) { bean = Class.forName(beanClazz).newInstance(); newBean = true; } if (v != null) { v.prePopulate(bean, properties); } if (log.isDebugEnabled()) { log.debug("BeanMonkey.populate(" + bean + ", " + properties + ")"); } Errors e = null; if (validate) { String beanClassName = null; beanClassName = bean.getClass().getName(); beanClassName = beanClassName.substring(beanClassName.lastIndexOf(".") + 1); e = new BindException(bean, beanClassName); } String namespace = null; if (properties.containsKey("namespace") && !"".equals(properties.get("namespace"))) { namespace = (String) properties.get("namespace") + "."; } // Loop through the property name/value pairs to be set Iterator names = properties.keySet().iterator(); while (names.hasNext()) { // Identify the property name and value(s) to be assigned String name = (String) names.next(); if (name == null || (indexPropertyName.equals(name) && !noload) || (namespaceStrict && !name.startsWith(namespace))) { continue; } Object value = null; if (properties.get(name) == null) { log.warn("Property [" + name + "] does not have a value in the map."); continue; } if (properties.get(name).getClass().isArray() && index < ((Object[]) properties.get(name)).length) { value = ((Object[]) properties.get(name))[index]; } else if (properties.get(name).getClass().isArray()) { value = ((Object[]) properties.get(name))[0]; } else { value = properties.get(name); } if (namespace != null) { name = name.replace(namespace, ""); } PropertyDescriptor descriptor = null; Class type = null; // Java type of target property try { descriptor = PropertyUtils.getPropertyDescriptor(bean, name); if (descriptor == null) { continue; // Skip this property setter } } catch (NoSuchMethodException nsm) { continue; // Skip this property setter } catch (IllegalArgumentException iae) { continue; // Skip null nested property } if (descriptor.getWriteMethod() == null) { if (log.isDebugEnabled()) { log.debug("Skipping read-only property"); } continue; // Read-only, skip this property setter } type = descriptor.getPropertyType(); String className = type.getName(); try { value = evaluatePropertyValue(name, className, namespace, value, properties, bean); } catch (NoSuchMethodException nsm) { continue; } try { BeanUtils.setProperty(bean, name, value); } catch (ConversionException ce) { log.error("populate - exception [bean:" + bean.getClass().getName() + " name:" + name + " value:" + value + "] "); if (validate) { e.rejectValue(name, name + ".conversionError", ce.getMessage()); } else { throw new ValidationException(bean, className, name, ce.getMessage()); } } catch (Exception be) { log.error("populate - exception [bean:" + bean.getClass().getName() + " name:" + name + " value:" + value + "] "); if (validate) { e.rejectValue(name, name + ".error", be.getMessage()); } else { throw new ValidationException(bean, className, name, be.getMessage()); } } } /* if (newBean && cdao != null) { BeanUtils.setProperty(bean, "id", -1); } */ if (validate && e.getErrorCount() > 0) { throw new ValidationException(e); } returnObjs.add(bean); } return returnObjs; }
From source file:java2typescript.jaxrs.ServiceDescriptorGenerator.java
private void addModuleVars(Module module, Collection<? extends Class<?>> serviceClasses) { module.getVars().put(ROOT_URL_VAR, StringType.getInstance()); // Adapter function FunctionType adapterFuncType = new FunctionType(); adapterFuncType.setResultType(VoidType.getInstance()); adapterFuncType.getParameters().put("httpMethod", StringType.getInstance()); adapterFuncType.getParameters().put("path", StringType.getInstance()); adapterFuncType.getParameters().put("getParams", ClassType.getObjectClass()); adapterFuncType.getParameters().put("postParams", ClassType.getObjectClass()); adapterFuncType.getParameters().put("body", AnyType.getInstance()); module.getVars().put(ROOT_URL_VAR, StringType.getInstance()); module.getVars().put(ADAPTER_VAR, adapterFuncType); // Generate : var someService : SomeService; for (Class<?> clazz : serviceClasses) { String className = clazz.getSimpleName(); AbstractNamedType type = module.getNamedTypes().get(className); String varName = Introspector.decapitalize(className); module.getVars().put(varName, type); }/*from w ww .jav a2 s. c om*/ }
From source file:org.gvnix.addon.datatables.addon.DatatablesMetadataProvider.java
/** * Locates All {@link FinderMetadataDetails} and its related * {@link QueryHolder} for every declared dynamic finder <br> * <br>/*from w w w . j ava2 s . co m*/ * <em>Note:</em> This method is similar to * {@link WebMetadataServiceImpl#getDynamicFinderMethodsAndFields(JavaType, MemberDetails, String)} * but without register dependency (this dependency produces NPE in * {@link #getMetadata(String, JavaType, PhysicalTypeMetadata, String)} when * it tries to get JPA information) * * @param entity * @param path * @param entityMemberDetails * @param plural * @param entityName * @return * @see WebMetadataServiceImpl#getDynamicFinderMethodsAndFields(JavaType, * MemberDetails, String) */ private Map<FinderMetadataDetails, QueryHolderTokens> getFindersRegisterd(JavaType entity, LogicalPath path, MemberDetails entityMemberDetails, String plural, String entityName) { // Get finder metadata final String finderMetadataKey = FinderMetadata.createIdentifier(entity, path); final FinderMetadata finderMetadata = (FinderMetadata) getMetadataService().get(finderMetadataKey); if (finderMetadata == null) { return null; } QueryHolderTokens queryHolder; FinderMetadataDetails details; Map<FinderMetadataDetails, QueryHolderTokens> findersRegistered = new HashMap<FinderMetadataDetails, QueryHolderTokens>(); // Iterate over for (final MethodMetadata method : finderMetadata.getAllDynamicFinders()) { final List<JavaSymbolName> parameterNames = method.getParameterNames(); final List<JavaType> parameterTypes = AnnotatedJavaType .convertFromAnnotatedJavaTypes(method.getParameterTypes()); final List<FieldMetadata> fields = new ArrayList<FieldMetadata>(); for (int i = 0; i < parameterTypes.size(); i++) { JavaSymbolName fieldName = null; if (parameterNames.get(i).getSymbolName().startsWith("max") || parameterNames.get(i).getSymbolName().startsWith("min")) { fieldName = new JavaSymbolName(Introspector.decapitalize( StringUtils.capitalize(parameterNames.get(i).getSymbolName().substring(3)))); } else { fieldName = parameterNames.get(i); } final FieldMetadata field = BeanInfoUtils.getFieldForPropertyName(entityMemberDetails, fieldName); if (field != null) { final FieldMetadataBuilder fieldMd = new FieldMetadataBuilder(field); fieldMd.setFieldName(parameterNames.get(i)); fields.add(fieldMd.build()); } } details = new FinderMetadataDetails(method.getMethodName().getSymbolName(), method, fields); // locate QueryHolder instances. This objects contain // information about a roo finder (parameters names and types // and a "token" list with of find definition queryHolder = getQueryHolder(entityMemberDetails, method.getMethodName(), plural, entityName); findersRegistered.put(details, queryHolder); } return findersRegistered; }
From source file:dinistiq.Dinistiq.java
/** * Derives a bean name from an optional given name, the beans class and this classes annotations. * * @param name intended name - may be null * @param cls type of the bean//from w w w. j av a 2 s. com * @return name to be used for the bean */ private String getBeanName(Class<? extends Object> cls, String name) { LOG.debug("getBeanName({}) cls={}", name, cls); Named annotation = cls.getAnnotation(Named.class); String beanName = (name == null) ? (annotation == null ? null : annotation.value()) : name; if (StringUtils.isBlank(beanName)) { beanName = Introspector.decapitalize(cls.getSimpleName()); } // if return beanName; }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Return the short string name of a Java class in decapitalized JavaBeans * property format. Strips the outer class name in case of an inner class. * @param clazz the class/*from ww w . j av a 2 s . co m*/ * @return the short name rendered in a standard JavaBeans property format * @see java.beans.Introspector#decapitalize(String) */ public static String getShortNameAsProperty(Class clazz) { String shortName = ClassUtils.getShortName(clazz); int dotIndex = shortName.lastIndexOf('.'); shortName = (dotIndex != -1 ? shortName.substring(dotIndex + 1) : shortName); return Introspector.decapitalize(shortName); }
From source file:com.dianping.resource.io.util.ClassUtils.java
/** * Return the short string name of a Java class in uncapitalized JavaBeans * property format. Strips the outer class name in case of an inner class. * @param clazz the class/*from www .ja va2 s. com*/ * @return the short name rendered in a standard JavaBeans property format * @see java.beans.Introspector#decapitalize(String) */ public static String getShortNameAsProperty(Class<?> clazz) { String shortName = ClassUtils.getShortName(clazz); int dotIndex = shortName.lastIndexOf('.'); shortName = (dotIndex != -1 ? shortName.substring(dotIndex + 1) : shortName); return Introspector.decapitalize(shortName); }