List of usage examples for org.springframework.util StringUtils capitalize
public static String capitalize(String str)
From source file:nz.co.senanque.workflow.WorkflowManagerImpl.java
@Transactional public Object getField(ProcessInstance processInstance, FieldDescriptor fd) { Object o = getContextDAO().getContext(processInstance.getObjectInstance()); String prefix = "get"; if (fd.getType().endsWith("Boolean")) { prefix = "is"; }//from ww w .j a v a2s . com String name = prefix + StringUtils.capitalize(fd.getName()); try { Method getter = o.getClass().getMethod(name); return getter.invoke(o); } catch (Exception e) { throw new WorkflowException("Problem finding field: " + fd.getName()); } }
From source file:org.shept.persistence.provider.DaoUtils.java
private static Object copyTemplate_Experimental(HibernateDaoSupport dao, Object entityModelTemplate) { ClassMetadata modelMeta = getClassMetadata(dao, entityModelTemplate); if (null == modelMeta) { return null; }/*from ww w . ja v a 2 s .c o m*/ String idName = modelMeta.getIdentifierPropertyName(); Object modelCopy = BeanUtils.instantiateClass(entityModelTemplate.getClass()); BeanUtils.copyProperties(entityModelTemplate, modelCopy, new String[] { idName }); Type idType = modelMeta.getIdentifierType(); if (null == idType || !idType.isComponentType()) { return modelCopy; } Object idValue = modelMeta.getPropertyValue(entityModelTemplate, idName, EntityMode.POJO); if (null == idValue) { return modelCopy; } Object idCopy = BeanUtils.instantiate(idValue.getClass()); BeanUtils.copyProperties(idValue, idCopy); if (null == idValue || (null != idType)) { return modelCopy; } Method idMth = ReflectionUtils.findMethod(entityModelTemplate.getClass(), "set" + StringUtils.capitalize(idName), new Class[] {}); if (idMth != null) { ReflectionUtils.invokeMethod(idMth, modelCopy, idCopy); } return modelCopy; }
From source file:com.opengamma.language.object.ObjectFunctionProvider.java
protected String capitalize(final String str) { return StringUtils.capitalize(str); }
From source file:app.commons.ReflectionUtils.java
public static <T> T invokeGetter(Object instance, String fieldName) { return (T) invokeMethod(instance, "get" + StringUtils.capitalize(fieldName)); }
From source file:org.agatom.springatom.cmp.wizards.validation.ValidationServiceImpl.java
private String getStepValidateMethodName(final String stepId) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("getStepValidateMethodName(stepId=%s)", stepId)); }/* w ww . j a v a 2 s .c o m*/ return String.format("validate%s", StringUtils.capitalize(stepId)); }
From source file:net.nan21.dnet.core.presenter.action.query.QueryBuilderWithJpql.java
protected void processAdvancedFilter() throws Exception { if (this.filterRules == null || this.filterRules.size() == 0) { return;// w ww . j a v a 2 s. c om } operations1 = Arrays.asList(new String[] { OP_LIKE, OP_NOT_LIKE, OP_EQ, OP_NOT_EQ, OP_LT, OP_LT_EQ, OP_GT, OP_GT_EQ, OP_IN, OP_NOT_IN }); operations2 = Arrays.asList(new String[] { OP_BETWEEN }); Map<String, String> refpaths = this.getDescriptor().getRefPaths(); Class<?> clz = this.getModelClass(); Method m = null; int cnt = 0; for (IFilterRule ifr : this.filterRules) { FilterRule fr = (FilterRule) ifr; String fieldName = fr.getFieldName(); if (this.shouldProcessFilterField(fieldName, fieldName)) { // get the filter getter cnt++; try { m = clz.getMethod("get" + StringUtils.capitalize(fieldName)); fr.setDataTypeFQN(m.getReturnType().getCanonicalName()); this.appendJpqlFragmentForFilterRule(fr, refpaths.get(fieldName), cnt); } catch (NoSuchMethodException e) { throw new Exception("Invalid field name: " + fieldName); } } } }
From source file:ch.rasc.extclassgenerator.association.AbstractAssociation.java
public static AbstractAssociation createAssociation(ModelAssociation associationAnnotation, ModelBean model, Class<?> typeOfFieldOrReturnValue, Class<?> declaringClass, String name) { ModelAssociationType type = associationAnnotation.value(); Class<?> associationClass = associationAnnotation.model(); if (associationClass == Object.class) { associationClass = typeOfFieldOrReturnValue; }// ww w . j ava 2 s. c o m final AbstractAssociation association; if (type == ModelAssociationType.HAS_MANY) { association = new HasManyAssociation(associationClass); } else if (type == ModelAssociationType.BELONGS_TO) { association = new BelongsToAssociation(associationClass); } else { association = new HasOneAssociation(associationClass); } association.setAssociationKey(name); if (StringUtils.hasText(associationAnnotation.foreignKey())) { association.setForeignKey(associationAnnotation.foreignKey()); } else if (type == ModelAssociationType.HAS_MANY) { association.setForeignKey(StringUtils.uncapitalize(declaringClass.getSimpleName()) + "_id"); } else if (type == ModelAssociationType.BELONGS_TO || type == ModelAssociationType.HAS_ONE) { association.setForeignKey(name + "_id"); } if (StringUtils.hasText(associationAnnotation.primaryKey())) { association.setPrimaryKey(associationAnnotation.primaryKey()); } else if (type == ModelAssociationType.HAS_MANY && StringUtils.hasText(model.getIdProperty()) && !model.getIdProperty().equals("id")) { association.setPrimaryKey(model.getIdProperty()); } else if (type == ModelAssociationType.BELONGS_TO || type == ModelAssociationType.HAS_ONE) { Model associationModelAnnotation = associationClass.getAnnotation(Model.class); if (associationModelAnnotation != null && StringUtils.hasText(associationModelAnnotation.idProperty()) && !associationModelAnnotation.idProperty().equals("id")) { association.setPrimaryKey(associationModelAnnotation.idProperty()); } ReflectionUtils.doWithFields(associationClass, new FieldCallback() { @Override public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { if (field.getAnnotation(ModelId.class) != null && !"id".equals(field.getName())) { association.setPrimaryKey(field.getName()); } } }); } if (type == ModelAssociationType.HAS_MANY) { HasManyAssociation hasManyAssociation = (HasManyAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(declaringClass, name, association.getType(), "setterName")); } if (StringUtils.hasText(associationAnnotation.getterName())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(declaringClass, name, association.getType(), "getterName")); } if (associationAnnotation.autoLoad()) { hasManyAssociation.setAutoLoad(Boolean.TRUE); } if (StringUtils.hasText(associationAnnotation.name())) { hasManyAssociation.setName(associationAnnotation.name()); } else { hasManyAssociation.setName(name); } } else if (type == ModelAssociationType.BELONGS_TO) { BelongsToAssociation belongsToAssociation = (BelongsToAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { belongsToAssociation.setSetterName(associationAnnotation.setterName()); } else { belongsToAssociation.setSetterName("set" + StringUtils.capitalize(name)); } if (StringUtils.hasText(associationAnnotation.getterName())) { belongsToAssociation.setGetterName(associationAnnotation.getterName()); } else { belongsToAssociation.setGetterName("get" + StringUtils.capitalize(name)); } if (associationAnnotation.autoLoad()) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(declaringClass, name, association.getType(), "autoLoad")); } if (StringUtils.hasText(associationAnnotation.name())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(declaringClass, name, association.getType(), "name")); } } else { HasOneAssociation hasOneAssociation = (HasOneAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { hasOneAssociation.setSetterName(associationAnnotation.setterName()); } else { hasOneAssociation.setSetterName("set" + StringUtils.capitalize(name)); } if (StringUtils.hasText(associationAnnotation.getterName())) { hasOneAssociation.setGetterName(associationAnnotation.getterName()); } else { hasOneAssociation.setGetterName("get" + StringUtils.capitalize(name)); } if (associationAnnotation.autoLoad()) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(declaringClass, name, association.getType(), "autoLoad")); } if (StringUtils.hasText(associationAnnotation.name())) { hasOneAssociation.setName(associationAnnotation.name()); } } if (StringUtils.hasText(associationAnnotation.instanceName())) { association.setInstanceName(associationAnnotation.instanceName()); } return association; }
From source file:org.shredzone.commons.taglib.processor.TaglibProcessor.java
/** * Generates a proxy class that connects to Spring and allows all Spring features like * dependency injection in the implementing tag class. * * @param tag//from w w w .j av a2 s .co m * {@link TagBean} that describes the tag. * @throws IOException * when the generated Java code could not be saved. */ private void generateProxyClass(TagBean tag) throws IOException { String beanFactoryReference = tag.getBeanFactoryReference(); if (beanFactoryReference == null) { beanFactoryReference = taglib.getBeanFactoryReference(); } JavaFileObject src = processingEnv.getFiler().createSourceFile(tag.getProxyClassName()); String packageName = null; int packPos = tag.getClassName().lastIndexOf('.'); if (packPos >= 0) { packageName = tag.getClassName().substring(0, packPos); } String proxyClass = PROXY_MAP.get(tag.getType()); try (PrintWriter out = new PrintWriter(src.openWriter())) { if (packageName != null) { out.printf("package %s;\n", packageName).println(); } out.print("@javax.annotation.Generated(\""); out.print(TaglibProcessor.class.getName()); out.println("\")"); out.printf("public class %s extends %s<%s> %s {", StringUtils.unqualify(tag.getProxyClassName()), proxyClass, tag.getClassName(), (tag.isTryCatchFinally() ? "implements javax.servlet.jsp.tagext.TryCatchFinally" : "")) .println(); if (beanFactoryReference != null) { out.println( " protected org.springframework.beans.factory.BeanFactory getBeanFactory(javax.servlet.jsp.JspContext jspContext) {"); out.printf(" java.lang.Object beanFactory = jspContext.findAttribute(\"%s\");", beanFactoryReference).println(); out.println(" if (beanFactory == null) {"); out.printf(" throw new java.lang.NullPointerException(\"attribute '%s' not set\");", beanFactoryReference).println(); out.println(" }"); out.println(" return (org.springframework.beans.factory.BeanFactory) beanFactory;"); out.println(" }"); } out.println(" protected java.lang.String getBeanName() {"); out.printf(" return \"%s\";", tag.getBeanName()).println(); out.println(" }"); for (AttributeBean attr : new TreeSet<AttributeBean>(tag.getAttributes())) { out.printf(" public void set%s(%s _%s) {", StringUtils.capitalize(attr.getName()), attr.getType(), attr.getName()).println(); out.printf(" getTargetBean().set%s(_%s);", StringUtils.capitalize(attr.getName()), attr.getName()).println(); out.println(" }"); } out.println("}"); } }
From source file:net.nan21.dnet.core.presenter.action.query.QueryBuilderWithJpql.java
protected void processFilter() throws Exception { if (logger.isDebugEnabled()) { logger.debug("Building JPQL where ..."); }/*from w w w . ja va 2 s.c om*/ Map<String, String> refpaths = this.getDescriptor().getRefPaths(); Map<String, String> jpqlFilterRules = this.getDescriptor().getJpqlFieldFilterRules(); this.defaultFilterItems = new HashMap<String, Object>(); Class<?> clz = this.getFilterClass(); // The filter object could be a dedicated filter class or the // data-source model. // Ensure we do not apply filter on the framework specific properties List<String> excludes = Arrays.asList(new String[] { "_entity_", "__clientRecordId__" }); while (clz != null) { Field[] fields = clz.getDeclaredFields(); for (Field field : fields) { String fieldName = field.getName(); if (this.isValidFilterField(field, excludes)) { String filterFieldName = fieldName; FilterFieldNameAndRangeType fnrt = this.resolveRealFilterFieldNameAndRangeType(field); fieldName = fnrt.getName(); if (this.shouldProcessFilterField(fieldName, filterFieldName)) { // get the filter getter Method m = null; try { m = clz.getMethod("get" + StringUtils.capitalize(filterFieldName)); } catch (Exception e) { // break; } // get the value Object fv = m.invoke(getFilter()); if (fv != null) { if (m.getReturnType() == java.lang.String.class) { if (jpqlFilterRules.containsKey(fieldName)) { // if this field has a special filter // condition use it addFilterCondition(jpqlFilterRules.get(fieldName)); } else { // build the default condition on the mapped // entity field in case it is mapped if (refpaths.containsKey(fieldName)) { String _op = "like"; if ("id".equals(fieldName) || "refid".equals(fieldName) || "clientId".equals(fieldName)) { _op = "="; } addFilterCondition(entityAlias + "." + refpaths.get(fieldName) + " " + _op + " :" + fieldName); } } // add the value anyway , maybe it is used in // the ds-level where clause. // If there is no field-level filter condition, the field is not mapped to an entity field, // and there is no filter condition at data-source level to use this field as parameter // it should be forced to null anywhere in pre-query phase. this.defaultFilterItems.put(fieldName, (String) fv); } else { if (fnrt.getType() != FilterFieldNameAndRangeType.NO_RANGE) { if (fnrt.getType() == FilterFieldNameAndRangeType.RANGE_FROM) { this.addFilterCondition(entityAlias + "." + refpaths.get(fieldName) + " >= :" + filterFieldName); } else { this.addFilterCondition(entityAlias + "." + refpaths.get(fieldName) + " < :" + filterFieldName); } this.defaultFilterItems.put(filterFieldName, fv); } else { if (jpqlFilterRules.containsKey(fieldName)) { addFilterCondition(jpqlFilterRules.get(fieldName)); } else { this.addFilterCondition( entityAlias + "." + refpaths.get(fieldName) + " = :" + fieldName); } this.defaultFilterItems.put(fieldName, fv); } } } } } } clz = clz.getSuperclass(); } }
From source file:seava.j4e.presenter.action.query.QueryBuilderWithJpql.java
protected void processFilter() throws Exception { if (logger.isDebugEnabled()) { logger.debug("Building JPQL where ..."); }/*w w w .j a va 2 s .com*/ Map<String, String> refpaths = this.getDescriptor().getRefPaths(); Map<String, String> jpqlFilterRules = this.getDescriptor().getJpqlFieldFilterRules(); this.defaultFilterItems = new HashMap<String, Object>(); Class<?> clz = this.getFilterClass(); // The filter object could be a dedicated filter class or the // data-source model. // Ensure we do not apply filter on the framework specific properties List<String> excludes = Arrays.asList(new String[] { "_entity_", "__clientRecordId__" }); while (clz != null) { Field[] fields = clz.getDeclaredFields(); for (Field field : fields) { String fieldName = field.getName(); if (this.isValidFilterField(field, excludes)) { String filterFieldName = fieldName; FilterFieldNameAndRangeType fnrt = this.resolveRealFilterFieldNameAndRangeType(field); fieldName = fnrt.getName(); if (this.shouldProcessFilterField(fieldName, filterFieldName)) { // get the filter getter Method m = null; try { m = clz.getMethod("get" + StringUtils.capitalize(filterFieldName)); } catch (Exception e) { // break; } // get the value Object fv = m.invoke(getFilter()); if (fv != null) { if (m.getReturnType() == java.lang.String.class) { String _fv = (String) fv; String _op = "like"; String _criteria = null; boolean withParamPlaceholder = true; boolean withParamsAsList = false; if (jpqlFilterRules.containsKey(fieldName)) { // if this field has a special filter // condition use it addFilterCondition(jpqlFilterRules.get(fieldName)); } else { // build the default condition on the mapped // entity field in case it is mapped if (refpaths.containsKey(fieldName)) { if (_fv.startsWith("[NULL]")) { _op = OP_NULL; withParamPlaceholder = false; _criteria = "(" + entityAlias + "." + refpaths.get(fieldName) + " " + _op + " OR " + entityAlias + "." + refpaths.get(fieldName) + " = '' )"; } else if (_fv.startsWith("[!NULL]")) { _op = OP_NOT_NULL; withParamPlaceholder = false; _criteria = "(" + entityAlias + "." + refpaths.get(fieldName) + " " + _op + " AND " + entityAlias + "." + refpaths.get(fieldName) + " <> '' )"; } else if (_fv.indexOf(",") > 0) { withParamsAsList = true; if (_fv.startsWith("[!]")) { _op = OP_NOT_IN; _fv = _fv.substring(3); } else { _op = OP_IN; } } else if ("id".equals(fieldName) || "refid".equals(fieldName) || "clientId".equals(fieldName)) { _op = "="; } if (_criteria != null) { addFilterCondition(_criteria); } else { if (withParamPlaceholder) { addFilterCondition(entityAlias + "." + refpaths.get(fieldName) + " " + _op + " :" + fieldName); } else { addFilterCondition( entityAlias + "." + refpaths.get(fieldName) + " " + _op); } } } } // add the value anyway , maybe it is used in // the ds-level where clause. // If there is no field-level filter condition, // the field is not mapped to an entity field, // and there is no filter condition at // data-source level to use this field as // parameter // it should be forced to null anywhere in // pre-query phase. // if (withParamPlaceholder) { if (withParamsAsList) { this.defaultFilterItems.put(fieldName, Arrays.asList(((String) _fv).split(","))); } else { this.defaultFilterItems.put(fieldName, (String) _fv); } // } } else { if (fnrt.getType() != FilterFieldNameAndRangeType.NO_RANGE) { if (fnrt.getType() == FilterFieldNameAndRangeType.RANGE_FROM) { this.addFilterCondition(entityAlias + "." + refpaths.get(fieldName) + " >= :" + filterFieldName); } else { this.addFilterCondition(entityAlias + "." + refpaths.get(fieldName) + " < :" + filterFieldName); } this.defaultFilterItems.put(filterFieldName, fv); } else { if (jpqlFilterRules.containsKey(fieldName)) { addFilterCondition(jpqlFilterRules.get(fieldName)); } else { this.addFilterCondition( entityAlias + "." + refpaths.get(fieldName) + " = :" + fieldName); } this.defaultFilterItems.put(fieldName, fv); } } } } } } clz = clz.getSuperclass(); } }