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.sf.ddao.crud.param.CRUDBeanPropsParameter.java

public void appendParam(Context ctx, StringBuilder sb) throws SQLException {
    if (descriptors == null) {
        init(ctx);//from w  w  w . j  a va  2  s  .  c  o m
    }
    int c = 0;
    final Object bean = getBean(ctx);
    DirtyPropertyAware dirtyPropertyAware = null;
    if (bean instanceof DirtyPropertyAware) {
        dirtyPropertyAware = (DirtyPropertyAware) bean;
    }
    for (PropertyDescriptor descriptor : descriptors) {
        if (dirtyPropertyAware != null && !dirtyPropertyAware.isDirty(descriptor.getName())) {
            continue;
        }
        if (c > 0) {
            sb.append(",");
        }
        final String fieldName = mapPropName2Field(descriptor);
        sb.append(MessageFormat.format(fmt, fieldName));
        c++;
    }
}

From source file:com.complexible.pinto.RDFMapper.java

private static boolean isIgnored(final PropertyDescriptor thePropertyDescriptor) {
    // we'll ignore getClass() on the bean
    if (thePropertyDescriptor.getName().equals("class")
            && thePropertyDescriptor.getReadMethod().getDeclaringClass() == Object.class
            && thePropertyDescriptor.getReadMethod().getReturnType().equals(Class.class)) {
        return true;
    }/*from   ww w  .  jav  a 2 s  .  c o m*/

    return false;
}

From source file:com.twinsoft.convertigo.beans.core.DatabaseObject.java

protected static PropertyDescriptor findPropertyDescriptor(PropertyDescriptor[] pds, String pn) {
    int len = pds.length;
    PropertyDescriptor pd;
    for (int i = 0; i < len; i++) {
        pd = pds[i];//from w ww.  ja va 2 s. c  o m
        if (pn.equals(pd.getName())) {
            return pd;
        }
    }
    return null;
}

From source file:name.ikysil.beanpathdsl.codegen.CodeGen.java

private String getNavigationMethodName(PropertyDescriptor pd) {
    String name = pd.getName();
    if (!Character.isJavaIdentifierStart(name.charAt(0)) || isJavaKeyword(name)) {
        name = KEYWORD_PREFIX + name;//from  ww w  . j  av  a 2 s. c  o  m
    }
    return name;
}

From source file:com.nortal.petit.beanmapper.BeanMappingFactoryImpl.java

public <B> void initProps(Map<String, Property<B, Object>> props, List<Property<B, Object>> idProps,
        Class<B> type) {/*from  www  .  j a  va 2 s . c  o  m*/
    Collection<PropertyDescriptor> pds = findPropertyDescriptors(type);

    for (PropertyDescriptor pd : pds) {
        initProperty(props, idProps, pd.getName(), type);
    }
}

From source file:com.bstek.dorado.data.entity.BeanEntityEnhancer.java

protected synchronized void buildReflectionCahce() throws Exception {
    synchronized (cachedTypes) {
        if (!cachedTypes.contains(beanType)) {
            cachedTypes.add(beanType);/*from  ww  w. jav a 2s . c  om*/

            Map<String, Boolean> properties = new Hashtable<String, Boolean>();
            Map<Method, String> readMethods = new Hashtable<Method, String>();
            Map<Method, String> writeMethods = new Hashtable<Method, String>();
            PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(beanType);
            for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
                String property = propertyDescriptor.getName();
                if (propertyDescriptor.getReadMethod() == null) {
                    continue;
                }

                properties.put(property, Boolean.valueOf(propertyDescriptor.getWriteMethod() != null));

                Method readMethod = propertyDescriptor.getReadMethod();
                Method writeMethod = propertyDescriptor.getWriteMethod();
                if (readMethod != null) {
                    if (readMethod.getDeclaringClass() != beanType) {
                        readMethod = beanType.getMethod(readMethod.getName(), readMethod.getParameterTypes());
                    }
                    readMethods.put(readMethod, property);
                }
                if (writeMethod != null) {
                    if (writeMethod.getDeclaringClass() != beanType) {
                        writeMethod = beanType.getMethod(writeMethod.getName(),
                                writeMethod.getParameterTypes());
                    }
                    writeMethods.put(writeMethod, property);
                }
            }
            propertiesCache.put(beanType, properties);
            readMethodsCache.put(beanType, readMethods);
            writeMethodsCache.put(beanType, writeMethods);
            this.properties = properties;
            this.readMethods = readMethods;
            this.writeMethods = writeMethods;
        } else {
            this.properties = propertiesCache.get(beanType);
            this.readMethods = readMethodsCache.get(beanType);
            this.writeMethods = writeMethodsCache.get(beanType);
        }
    }
}

From source file:net.audumla.concurrent.TemplatedExecuter.java

protected void mergeProperties(Object source, Object destination) throws IntrospectionException {
    BeanInfo info = Introspector.getBeanInfo(source.getClass());
    for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
        try {/*from   www .  ja v  a  2 s . co m*/
            // get the property value from the destination object.
            Object destvalue = BeanUtils.getProperty(destination, descriptor.getName());
            // only copy the value if the destination has not been set. This will therefore only work on non primitive types
            if (destvalue == null) {
                Object sourceValue = descriptor.getReadMethod().invoke(source);
                // Only copy values values where the destination values is null
                if (sourceValue != null) {
                    BeanUtils.copyProperty(destination, descriptor.getName(), sourceValue);
                }
            }

        } catch (Exception ignored) {

        }
    }
}

From source file:com.bradmcevoy.property.BeanPropertySource.java

@Override
public List<QName> getAllPropertyNames(Resource r) {
    BeanPropertyResource anno = getAnnotation(r);
    if (anno == null)
        return null;
    PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(r);
    List<QName> list = new ArrayList<QName>();
    for (PropertyDescriptor pd : pds) {
        if (pd.getReadMethod() != null) {
            list.add(new QName(anno.value(), pd.getName()));
        }//from w w  w. j a v  a  2 s .  c om
    }
    return list;
}

From source file:com.hubspot.jinjava.lib.tag.ForTag.java

@SuppressWarnings("unchecked")
@Override/*from w w  w .j a  v a  2 s .com*/
public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) {
    List<String> helper = new HelperStringTokenizer(tagNode.getHelpers()).splitComma(true).allTokens();

    List<String> loopVars = Lists.newArrayList();
    int inPos = 0;
    while (inPos < helper.size()) {
        String val = helper.get(inPos);

        if ("in".equals(val)) {
            break;
        } else {
            loopVars.add(val);
            inPos++;
        }
    }

    if (inPos >= helper.size()) {
        throw new TemplateSyntaxException(tagNode.getMaster().getImage(),
                "Tag 'for' expects valid 'in' clause, got: " + tagNode.getHelpers(), tagNode.getLineNumber());
    }

    String loopExpr = StringUtils.join(helper.subList(inPos + 1, helper.size()), ",");
    Object collection = interpreter.resolveELExpression(loopExpr, tagNode.getLineNumber());
    ForLoop loop = ObjectIterator.getLoop(collection);

    try (InterpreterScopeClosable c = interpreter.enterScope()) {
        interpreter.getContext().put(LOOP, loop);

        StringBuilder buff = new StringBuilder();
        while (loop.hasNext()) {
            Object val = loop.next();

            // set item variables
            if (loopVars.size() == 1) {
                interpreter.getContext().put(loopVars.get(0), val);
            } else {
                for (String loopVar : loopVars) {
                    if (Map.Entry.class.isAssignableFrom(val.getClass())) {
                        Map.Entry<String, Object> entry = (Entry<String, Object>) val;
                        Object entryVal = null;

                        if ("key".equals(loopVar)) {
                            entryVal = entry.getKey();
                        } else if ("value".equals(loopVar)) {
                            entryVal = entry.getValue();
                        }

                        interpreter.getContext().put(loopVar, entryVal);
                    } else {
                        try {
                            PropertyDescriptor[] valProps = Introspector.getBeanInfo(val.getClass())
                                    .getPropertyDescriptors();
                            for (PropertyDescriptor valProp : valProps) {
                                if (loopVar.equals(valProp.getName())) {
                                    interpreter.getContext().put(loopVar, valProp.getReadMethod().invoke(val));
                                    break;
                                }
                            }
                        } catch (Exception e) {
                            throw new InterpretException(e.getMessage(), e, tagNode.getLineNumber());
                        }
                    }
                }
            }

            for (Node node : tagNode.getChildren()) {
                buff.append(node.render(interpreter));
            }
        }

        return buff.toString();
    }

}

From source file:net.urosk.reportEngine.BirtConfigs.java

public void printOutProperties() throws Exception {

    final BeanWrapper wrapper = new BeanWrapperImpl(this);
    for (final PropertyDescriptor descriptor : wrapper.getPropertyDescriptors()) {
        logger.info(descriptor.getName() + ":" + descriptor.getReadMethod().invoke(this));
    }//from   ww w  .java2 s.  co  m
}