Example usage for java.beans PropertyDescriptor getName

List of usage examples for java.beans PropertyDescriptor getName

Introduction

In this page you can find the example usage for java.beans PropertyDescriptor getName.

Prototype

public String getName() 

Source Link

Document

Gets the programmatic name of this feature.

Usage

From source file:com.chiralbehaviors.CoRE.phantasm.graphql.schemas.JooqSchema.java

protected GraphQLFieldDefinition.Builder buildReference(GraphQLFieldDefinition.Builder builder,
        PropertyDescriptor field, PhantasmProcessor processor, Class<?> reference) {
    GraphQLOutputType type = (GraphQLOutputType) processor.typeFor(Existential.class);
    builder.name(field.getName()).type(type).dataFetcher(env -> {
        Object record = env.getSource();
        UUID fk;//from w w w.  ja  v a2 s .  c  o m
        try {
            fk = (UUID) field.getReadMethod().invoke(record);
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw new IllegalStateException(
                    String.format("unable to invoke %s", field.getReadMethod().toGenericString()), e);
        }
        return Existential.wrap(Existential.resolve(env, fk));
    });
    return builder;
}

From source file:com.subakva.formicid.options.ParameterHandler.java

public void handleOption(Task task, String optionName, Object value) {
    HashMap<String, PropertyDescriptor> properties = getWritableProperties(task.getClass());
    PropertyDescriptor descriptor = properties.get(optionName.toLowerCase());
    if (descriptor == null) {
        throw new RuntimeException("Unknown property for " + task.getTaskType() + " task: " + optionName);
    }/*  w  ww. j a  v  a  2  s .co  m*/
    Class<?> type = descriptor.getPropertyType();
    Converter converter = container.getConverter(type);
    Object converted = converter.convert(type, value);
    try {
        task.log("converting property: " + descriptor.getName(), Project.MSG_DEBUG);
        task.log("converter: " + converter, Project.MSG_DEBUG);
        task.log("converted: " + converted, Project.MSG_DEBUG);

        descriptor.getWriteMethod().invoke(task, new Object[] { converted });
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.boylesoftware.web.impl.UserInputControllerMethodArgHandler.java

@Override
public boolean prepareUserInput(final RouterRequest request) throws ServletException {

    boolean success = false;
    final PoolableUserInput pooledUserInput = this.beanPool.getSync();
    try {//from   w w  w. j  a va2  s.  c  om
        request.setAttribute(POOLED_OBJ_ATTNAME, pooledUserInput);
        final Object bean = pooledUserInput.getBean();
        request.setAttribute(Attributes.USER_INPUT, bean);
        final UserInputErrors errors = request.getUserInputErrors();
        request.setAttribute(Attributes.USER_INPUT_ERRORS, errors);

        // bind the bean properties
        final int numProps = this.beanFields.length;
        for (int i = 0; i < numProps; i++) {
            final FieldDesc fieldDesc = this.beanFields[i];
            final PropertyDescriptor propDesc = fieldDesc.getPropDesc();
            final String propName = propDesc.getName();
            final String propValStr = (fieldDesc.isNoTrim()
                    ? StringUtils.nullIfEmpty(request.getParameter(propName))
                    : StringUtils.trimToNull(request.getParameter(propName)));
            final Method propSetter = propDesc.getWriteMethod();
            try {
                propSetter.invoke(bean, fieldDesc.getBinder().convert(request, propValStr,
                        fieldDesc.getFormat(), propDesc.getPropertyType()));
            } catch (final BindingException e) {
                if (this.log.isDebugEnabled())
                    this.log.debug("binding error", e);
                propSetter.invoke(bean, e.getDefaultValue());
                errors.add(propName, fieldDesc.getErrorMessage());
            }
        }

        // validate the bean
        final Validator validator = this.validatorFactory.usingContext()
                .messageInterpolator(request.getMessageInterpolator()).getValidator();
        Class<?>[] validationGroups = this.validationGroups;
        if ((this.validationGroups.length == 0) && (bean instanceof DynamicValidationGroups))
            validationGroups = ((DynamicValidationGroups) bean).getValidationGroups(request);
        final Set<ConstraintViolation<Object>> cvs = validator.validate(bean, validationGroups);
        final boolean valid = cvs.isEmpty();
        if (!valid) {
            for (final ConstraintViolation<Object> cv : cvs)
                errors.add(cv.getPropertyPath().toString(), cv.getMessage());
        }

        success = true;

        return valid;

    } catch (final IllegalAccessException | InvocationTargetException e) {
        throw new ServletException("Error working with user input bean.", e);
    } finally {
        if (!success)
            pooledUserInput.recycle();
    }
}

From source file:org.brushingbits.jnap.persistence.hsearch.FullTextDao.java

protected String[] getIndexedFields() {
    if (this.indexedFields == null) {
        PropertyDescriptor[] beanProperties = BeanUtils.getPropertyDescriptors(getEntityClass());
        List<String> fields = new ArrayList<String>();
        for (PropertyDescriptor propertyDescriptor : beanProperties) {
            Field field = ReflectionUtils.getAnnotation(Field.class, propertyDescriptor.getReadMethod());
            if (field == null) {
                java.lang.reflect.Field propertyField = FieldUtils.getField(getEntityClass(),
                        propertyDescriptor.getName());
                if (propertyField != null && propertyField.isAnnotationPresent(Field.class)) {
                    field = propertyField.getAnnotation(Field.class);
                }//ww w .  j  av  a2s .co  m
            }
            if (field != null) {
                String fieldName = propertyDescriptor.getName();
                if (StringUtils.isNotBlank(fieldName)) {
                    fieldName = field.name();
                }
                fields.add(fieldName);
            }
        }
    }
    return this.indexedFields;
}

From source file:edu.northwestern.bioinformatics.studycalendar.web.admin.AdministerUserCommand.java

private void copyBoundProperties(User src, User dst) {
    BeanWrapper srcW = new BeanWrapperImpl(src);
    BeanWrapper dstW = new BeanWrapperImpl(dst);

    for (PropertyDescriptor srcProp : srcW.getPropertyDescriptors()) {
        if (srcProp.getReadMethod() == null || srcProp.getWriteMethod() == null) {
            continue;
        }//from  ww w.  j a  v a  2 s . co m
        Object srcValue = srcW.getPropertyValue(srcProp.getName());
        if (srcValue != null) {
            dstW.setPropertyValue(srcProp.getName(), srcValue);
        }
    }
}

From source file:gov.nih.nci.caarray.application.permissions.PermissionsManagementServiceBean.java

private void convertToLikeProperty(User u, User newUser, PropertyDescriptor pd)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (pd.getPropertyType().equals(String.class)) {
        final String value = (String) PropertyUtils.getSimpleProperty(newUser, pd.getName());
        if (value != null) {
            PropertyUtils.setSimpleProperty(newUser, pd.getName(), value + "%");
        }/*  w ww .j  av  a2 s  .c  om*/
    }
}

From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java

/**
 * Returns a PropertyDescriptor[] for the given Class.
 *
 * @param c The Class to retrieve PropertyDescriptors for.
 * @return A PropertyDescriptor[] describing the Class.
 * @throws SQLException if introspection failed.
 *///from w  w w.j  av  a 2  s .co  m
private PropertyDescriptor[] propertyDescriptors(Class<?> c) throws SQLException {
    // Introspector caches BeanInfo classes for better performance
    BeanInfo beanInfo = null;
    try {
        beanInfo = Introspector.getBeanInfo(c);
    } catch (IntrospectionException e) {
        throw new SQLException("Bean introspection failed: " + e.getMessage());
    }
    List<PropertyDescriptor> propList = Lists.newArrayList();
    PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
    for (PropertyDescriptor prop : props) {
        String propName = prop.getName();
        try {
            Field field = ReflectionUtils.findField(c, propName);
            if (field != null && !field.isAnnotationPresent(Transient.class)) {//1.field=null 2.Transient??
                propList.add(prop);
            }
        } catch (SecurityException e) {
            throw new SQLException("Bean Get Field failed: " + e.getMessage());
        }
    }
    return propList.toArray(new PropertyDescriptor[propList.size()]);
}

From source file:at.molindo.notify.model.BeanParams.java

private void setProperty(Param<?> param, Object value) {
    PropertyDescriptor pd = getDescriptor(param.getName());
    if (pd == null) {
        // TODO simply ignore?
        return;/*from  ww  w .  j a  va2  s  .co m*/
    }

    Object converted;
    if (value == null || pd.getPropertyType().isAssignableFrom(value.getClass())) {
        converted = value;
    } else {
        converted = Param.p(pd.getPropertyType(), pd.getName()).toObject(param.toString(value));
    }

    try {
        PropertyUtils.setProperty(_bean, param.getName(), converted);
    } catch (NoSuchMethodException e) {
        throw new NotifyRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new NotifyRuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new NotifyRuntimeException(e);
    }
}

From source file:org.jnap.core.persistence.hsearch.FullTextDaoSupport.java

protected String[] getIndexedFields() {
    if (this.indexedFields == null) {
        PropertyDescriptor[] beanProperties = BeanUtils.getPropertyDescriptors(getEntityClass());
        List<String> fields = new ArrayList<String>();
        for (PropertyDescriptor propertyDescriptor : beanProperties) {
            Field field = AnnotationUtils.findAnnotation(propertyDescriptor.getReadMethod(), Field.class);
            if (field == null) {
                java.lang.reflect.Field propertyField = FieldUtils.getField(getEntityClass(),
                        propertyDescriptor.getName(), true);
                if (propertyField != null && propertyField.isAnnotationPresent(Field.class)) {
                    field = propertyField.getAnnotation(Field.class);
                }/*  ww w  . j av a2s.com*/
            }
            if (field != null) {
                fields.add(propertyDescriptor.getName());
            }
        }
        if (fields.isEmpty()) {
            throw new HSearchQueryException(""); // TODO ex msg
        }
        this.indexedFields = fields.toArray(new String[] {});
    }
    return this.indexedFields;
}