Example usage for java.beans PropertyDescriptor getReadMethod

List of usage examples for java.beans PropertyDescriptor getReadMethod

Introduction

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

Prototype

public synchronized Method getReadMethod() 

Source Link

Document

Gets the method that should be used to read the property value.

Usage

From source file:com.googlecode.jsonplugin.JSONWriter.java

/**
 * Instrospect bean and serialize its properties
 *//*from w ww. j  a v  a2s  . c  om*/
private void bean(Object object) throws JSONException {
    this.add("{");

    BeanInfo info;

    try {
        Class clazz = object.getClass();

        info = ((object == this.root) && this.ignoreHierarchy)
                ? Introspector.getBeanInfo(clazz, clazz.getSuperclass())
                : Introspector.getBeanInfo(clazz);

        PropertyDescriptor[] props = info.getPropertyDescriptors();

        boolean hasData = false;
        for (int i = 0; i < props.length; ++i) {
            PropertyDescriptor prop = props[i];
            String name = prop.getName();
            Method accessor = prop.getReadMethod();
            Method baseAccessor = null;
            if (clazz.getName().indexOf("$$EnhancerByCGLIB$$") > -1) {
                try {
                    baseAccessor = Class.forName(clazz.getName().substring(0, clazz.getName().indexOf("$$")))
                            .getMethod(accessor.getName(), accessor.getParameterTypes());
                } catch (Exception ex) {
                    log.debug(ex.getMessage(), ex);
                }
            } else
                baseAccessor = accessor;

            if (baseAccessor != null) {

                JSON json = baseAccessor.getAnnotation(JSON.class);
                if (json != null) {
                    if (!json.serialize())
                        continue;
                    else if (json.name().length() > 0)
                        name = json.name();
                }

                //ignore "class" and others
                if (this.shouldExcludeProperty(clazz, prop)) {
                    continue;
                }
                String expr = null;
                if (this.buildExpr) {
                    expr = this.expandExpr(name);
                    if (this.shouldExcludeProperty(expr)) {
                        continue;
                    }
                    expr = this.setExprStack(expr);
                }

                Object value = accessor.invoke(object, new Object[0]);
                boolean propertyPrinted = this.add(name, value, accessor, hasData);
                hasData = hasData || propertyPrinted;
                if (this.buildExpr) {
                    this.setExprStack(expr);
                }
            }
        }

        // special-case handling for an Enumeration - include the name() as a property */
        if (object instanceof Enum) {
            Object value = ((Enum) object).name();
            this.add("_name", value, object.getClass().getMethod("name"), hasData);
        }
    } catch (Exception e) {
        throw new JSONException(e);
    }

    this.add("}");
}

From source file:com.webpagebytes.cms.local.WPBLocalDataStoreDao.java

public <T> boolean hasClassProperty(Class<T> kind, String property) throws WPBSerializerException {
    try {/*  w w  w . j  ava  2  s .com*/
        PropertyDescriptor pd = new PropertyDescriptor(property, kind);
        return pd.getReadMethod() != null;
    } catch (Exception e) {
        throw new WPBSerializerException("Cannot set property for object", e);
    }
}

From source file:net.jolm.JolmLdapTemplate.java

private AndFilter getAndFilterFromExample(LdapEntity example, boolean wildcardFilters, boolean logFilter) {
    try {/* w ww.  j  a v a 2  s . co m*/
        AndFilter filter = new AndFilter();
        BeanInfo info = Introspector.getBeanInfo(example.getClass());
        for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
            if (isAttributeApplicableInFilter(pd)) {
                Object value = pd.getReadMethod().invoke(example);
                if (value != null) {
                    if (value.getClass().isArray()) {
                        Object[] valueArray = (Object[]) value;
                        for (Object o : valueArray) {
                            addAndFilter(filter, pd, o, wildcardFilters);
                        }
                    } else {
                        if (StringUtils.isNotEmpty(value.toString())) {
                            addAndFilter(filter, pd, value, wildcardFilters);
                        }
                    }
                }
            }
        }

        if (logFilter && log.isDebugEnabled()) {
            log.debug("Finding " + example.getClass().getSimpleName() + "(s) using filter: " + filter.encode());
        }
        return filter;
    } catch (Exception e) {
        throw new RuntimeException("Unable to create the filter from ldap entity:" + example, e);
    }
}

From source file:com.bstek.dorado.view.output.ClientOutputHelper.java

protected Map<String, PropertyConfig> doGetPropertyConfigs(Class<?> beanType) throws Exception {
    beanType = ProxyBeanUtils.getProxyTargetType(beanType);
    Map<String, PropertyConfig> propertyConfigs = new HashMap<String, PropertyConfig>();

    ClientObjectInfo clientObjectInfo = getClientObjectInfo(beanType);
    if (clientObjectInfo != null) {
        for (Map.Entry<String, ClientProperty> entry : clientObjectInfo.getPropertyConfigs().entrySet()) {
            String property = entry.getKey();
            ClientProperty clientProperty = entry.getValue();

            PropertyConfig propertyConfig = new PropertyConfig();
            if (clientProperty.ignored()) {
                propertyConfig.setIgnored(true);
            } else {
                if (StringUtils.isNotEmpty(clientProperty.outputter())) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(clientProperty.outputter(),
                            Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                }/*from w  ww. j  a v  a 2 s .com*/

                if (clientProperty.alwaysOutput()) {
                    propertyConfig.setEscapeValue(FAKE_ESCAPE_VALUE);
                } else if (StringUtils.isNotEmpty(clientProperty.escapeValue())) {
                    propertyConfig.setEscapeValue(clientProperty.escapeValue());
                }
            }
            propertyConfigs.put(property, propertyConfig);
        }
    }

    boolean isAssembledComponent = (AssembledComponent.class.isAssignableFrom(beanType));
    Class<?> superComponentType = null;
    if (isAssembledComponent) {
        superComponentType = beanType;
        while (superComponentType != null && AssembledComponent.class.isAssignableFrom(superComponentType)) {
            superComponentType = superComponentType.getSuperclass();
            Assert.notNull(superComponentType);
        }
    }

    for (PropertyDescriptor propertyDescriptor : PropertyUtils.getPropertyDescriptors(beanType)) {
        String property = propertyDescriptor.getName();
        Method readMethod = propertyDescriptor.getReadMethod();
        if (readMethod.getDeclaringClass() != beanType) {
            try {
                readMethod = beanType.getMethod(readMethod.getName(), readMethod.getParameterTypes());
            } catch (NoSuchMethodException e) {
                // do nothing
            }
        }

        TypeInfo typeInfo;
        Class<?> propertyType = propertyDescriptor.getPropertyType();
        if (Collection.class.isAssignableFrom(propertyType)) {
            typeInfo = TypeInfo.parse((ParameterizedType) readMethod.getGenericReturnType(), true);
            if (typeInfo != null) {
                propertyType = typeInfo.getType();
            }
        } else if (propertyType.isArray()) {
            typeInfo = new TypeInfo(propertyType.getComponentType(), true);
        } else {
            typeInfo = new TypeInfo(propertyType, false);
        }

        PropertyConfig propertyConfig = null;
        ClientProperty clientProperty = readMethod.getAnnotation(ClientProperty.class);
        if (clientProperty != null) {
            propertyConfig = new PropertyConfig();
            if (clientProperty.ignored()) {
                propertyConfig.setIgnored(true);
            } else {
                if (StringUtils.isNotEmpty(clientProperty.outputter())) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(clientProperty.outputter(),
                            Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (Component.class.isAssignableFrom(propertyType)) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(COMPONENT_OUTPUTTER, Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (DataControl.class.isAssignableFrom(propertyType)
                        || FloatControl.class.isAssignableFrom(propertyType)) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(COMPONENT_OUTPUTTER, Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (DataType.class.isAssignableFrom(propertyType)) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(DATA_TYPE_PROPERTY_OUTPUTTER,
                            Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (Object.class.equals(propertyType)) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(DATA_OUTPUTTER, Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                } else if (!EntityUtils.isSimpleType(propertyType) && !propertyType.isArray()) {
                    BeanWrapper beanWrapper = BeanFactoryUtils.getBean(OBJECT_OUTPUTTER, Scope.instant);
                    propertyConfig.setOutputter(beanWrapper.getBean());
                }

                if (!clientProperty.evaluateExpression()) {
                    propertyConfig.setEvaluateExpression(false);
                }

                if (clientProperty.alwaysOutput()) {
                    propertyConfig.setEscapeValue(FAKE_ESCAPE_VALUE);
                } else if (StringUtils.isNotEmpty(clientProperty.escapeValue())) {
                    propertyConfig.setEscapeValue(clientProperty.escapeValue());
                }
            }
        } else if (isAssembledComponent && readMethod.getDeclaringClass() == beanType
                && EntityUtils.isSimpleType(propertyType)) {
            if (BeanUtils.getPropertyDescriptor(superComponentType, property) == null) {
                propertyConfig = new PropertyConfig();
                propertyConfig.setIgnored(true);
            }
        }

        ComponentReference componentReference = readMethod.getAnnotation(ComponentReference.class);
        if (componentReference != null && String.class.equals(propertyType)) {
            if (propertyConfig == null) {
                propertyConfig = new PropertyConfig();
            }
            if (propertyConfig.getOutputter() == null) {
                BeanWrapper beanWrapper = BeanFactoryUtils.getBean(COMPONENT_REFERENCE_OUTPUTTER,
                        Scope.instant);
                propertyConfig.setOutputter(beanWrapper.getBean());
            }
        }

        if (!propertyType.isPrimitive() && (Number.class.isAssignableFrom(propertyType)
                || Boolean.class.isAssignableFrom(propertyType))) {
            if (propertyConfig == null) {
                propertyConfig = new PropertyConfig();
            }
            if (propertyConfig.getEscapeValue() == PropertyConfig.NONE_VALUE) {
                propertyConfig.setEscapeValue(null);
            }
        }

        if (propertyConfig != null) {
            propertyConfigs.put(property, propertyConfig);
        }
    }
    return (propertyConfigs.isEmpty()) ? null : propertyConfigs;
}

From source file:com.webpagebytes.cms.local.WPBLocalDataStoreDao.java

public Object getObjectProperty(Object object, String property) throws WPBSerializerException {
    try {/*from  ww  w.  jav a 2s .c om*/
        PropertyDescriptor pd = new PropertyDescriptor(property, object.getClass());
        return pd.getReadMethod().invoke(object);
    } catch (Exception e) {
        throw new WPBSerializerException("Cannot set property for object", e);
    }
}

From source file:org.jaffa.soa.dataaccess.TransformerUtils.java

static void updateBeanData(String path, GraphDataObject source, UOW uow, ITransformationHandler handler,
        GraphMapping mapping, IPersistent domainObject, DataTransformer.Mode mode, GraphDataObject newGraph)
        throws InstantiationException, IllegalAccessException, InvocationTargetException, ApplicationExceptions,
        FrameworkException {//from   w w w  .j  a  va2s . c om

    try {
        // Call custom validation code in the GraphObject
        // The validate() method may have mandatory-rules bound to it via AOP. Hence do not invoke it during prevalidation
        // No need to invoke it during CLONING/MASS_UPDATE as well, since the source object should be unmodified
        if (mode != DataTransformer.Mode.VALIDATE_ONLY && mode != DataTransformer.Mode.CLONE
                && mode != DataTransformer.Mode.MASS_UPDATE)
            source.validate();

        List<ITransformationHandler> handlers = null;
        if (handler != null) {
            handlers = handler.getTransformationHandlers();
        }

        // Ensure the domain object has not been modified
        domainObjectChangedTest(path, source, mapping, domainObject);

        // Stamp the UOW on the domain object to avoid creation of separate UOWs during foreign-key validations
        if (domainObject.getUOW() == null)
            domainObject.setUOW(uow);

        // Reflect ProcessEventGraphs from newGraph to source - This will handle Pending/Warning Events during a clone/mass update
        if (newGraph != null && newGraph.getProcessEventGraphs() != null)
            source.setProcessEventGraphs(newGraph.getProcessEventGraphs());
        //----------------------------------------------------------------
        // Fire 'startBean' handler
        if (mode != DataTransformer.Mode.VALIDATE_ONLY && handlers != null) {
            for (ITransformationHandler transformationHandler : handlers) {
                transformationHandler.startBean(path, source, domainObject);
            }
        }

        //----------------------------------------------------------------
        // Reflect all normal fields
        for (Iterator it = mapping.getFields().iterator(); it.hasNext();) {
            String field = (String) it.next();
            // ignore read-only fields
            if (mapping.isReadOnly(field))
                continue;

            // values from the newGraph take precedence in CLONE/MASS_UPDATE mode
            if (mode == DataTransformer.Mode.CLONE) {
                // ignore dirty-read fields, and no-cloning fields unless a value is passed in the newGraph
                if (field.equals(mapping.getDirtyReadDataFieldName())
                        || (mapping.isNoCloning(field) && (newGraph == null || !newGraph.hasChanged(field))))
                    continue;
                Object value = getProperty(mapping.getDataFieldDescriptor(field),
                        newGraph != null && newGraph.hasChanged(field) ? newGraph : source);
                updateProperty(mapping.getDomainFieldDescriptor(field), value, domainObject);
            } else if (mode == DataTransformer.Mode.MASS_UPDATE) {
                if (newGraph != null && newGraph.hasChanged(field)) {
                    Object value = getProperty(mapping.getDataFieldDescriptor(field), newGraph);
                    updateProperty(mapping.getDomainFieldDescriptor(field), value, domainObject);
                }
            } else {
                Object value = getProperty(mapping.getDataFieldDescriptor(field), source);
                if ((!domainObject.isDatabaseOccurence() && value != null) || source.hasChanged(field))
                    updateProperty(mapping.getDomainFieldDescriptor(field), value, domainObject);
            }
        }

        //----------------------------------------------------------------
        // Update flex fields
        if (source instanceof IFlexFields && domainObject instanceof IFlexFields) {
            if (log.isDebugEnabled())
                log.debug("Updating flex fields for " + path);
            FlexBean sFlexBean = ((IFlexFields) source).getFlexBean();
            FlexBean tFlexBean = ((IFlexFields) domainObject).getFlexBean();
            if (sFlexBean != null && tFlexBean != null) {
                for (DynaProperty flexProperty : tFlexBean.getDynaClass().getDynaProperties()) {
                    String name = flexProperty.getName();
                    // values from the newGraph take precedence in CLONE/MASS_UPDATE mode
                    if (mode == DataTransformer.Mode.CLONE) {
                        FlexBean nFlexBean = newGraph != null && newGraph instanceof IFlexFields
                                ? ((IFlexFields) newGraph).getFlexBean()
                                : null;
                        Object value = nFlexBean != null && nFlexBean.hasChanged(name) ? nFlexBean.get(name)
                                : sFlexBean.get(name);
                        if (value != null)
                            tFlexBean.set(name, value);
                    } else if (mode == DataTransformer.Mode.MASS_UPDATE) {
                        FlexBean nFlexBean = newGraph != null && newGraph instanceof IFlexFields
                                ? ((IFlexFields) newGraph).getFlexBean()
                                : null;
                        if (nFlexBean != null && nFlexBean.hasChanged(name)) {
                            Object value = nFlexBean.get(name);
                            tFlexBean.set(name, value);
                        }
                    } else {
                        if (sFlexBean.hasChanged(name)) {
                            Object value = sFlexBean.get(name);
                            if (log.isDebugEnabled())
                                log.debug("Update flex field '" + name + '=' + value + "' on object '"
                                        + domainObject.getClass().getName() + '\'');
                            tFlexBean.set(name, value);
                        } else {
                            if (log.isDebugEnabled())
                                log.debug("Flex field '" + name + " has not changed on object "
                                        + source.getClass().getName());
                        }
                    }
                }
            }
        }

        //----------------------------------------------------------------
        // Reflect any foreign keys
        for (Iterator it = mapping.getForeignFields().iterator(); it.hasNext();) {
            String field = (String) it.next();
            // ignore read-only fields
            if (mapping.isReadOnly(field))
                continue;

            // It is possible that the foreign object may get resused, and only its fields may have been changed.
            // Hence also invoke the hasChanged() method on the foreign object itself
            Object value = null;
            boolean hasChanged = false;
            if (mode == DataTransformer.Mode.CLONE) {
                // ignore dirty-read fields, and no-cloning fields unless a value is passed in the newGraph
                if (field.equals(mapping.getDirtyReadDataFieldName())
                        || (mapping.isNoCloning(field) && (newGraph == null || !newGraph.hasChanged(field))))
                    continue;
                value = getProperty(mapping.getDataFieldDescriptor(field),
                        newGraph != null && newGraph.hasChanged(field) ? newGraph : source);
                hasChanged = value != null;
            } else if (mode == DataTransformer.Mode.MASS_UPDATE) {
                if (newGraph != null && newGraph.hasChanged(field)) {
                    value = getProperty(mapping.getDataFieldDescriptor(field), newGraph);
                    hasChanged = true;
                }
            } else {
                value = getProperty(mapping.getDataFieldDescriptor(field), source);
                hasChanged = (!domainObject.isDatabaseOccurence() && value != null) || source.hasChanged(field);
            }
            if (!hasChanged && value != null && value instanceof GraphDataObject)
                hasChanged = ((GraphDataObject) value).hasChanged();
            if (hasChanged) {
                // need to map foreign keys back
                List targetKeys = mapping.getForeignKeys(field);
                GraphMapping fMapping = MappingFactory
                        .getInstance(mapping.getDataFieldDescriptor(field).getPropertyType());
                Set sourceKeys = fMapping.getKeyFields();
                int i = 0;
                for (Iterator i2 = sourceKeys.iterator(); i2.hasNext(); i++) {
                    String sourceFld = (String) i2.next();
                    String targetFld = (String) targetKeys.get(i);
                    if (log.isDebugEnabled())
                        log.debug("Copy Foreign Key Field from " + sourceFld + " to " + targetFld);
                    if (value == null) {
                        // ForeignGraph is null. Null out the foreign-key
                        updateProperty(mapping.getRealDomainFieldDescriptor(targetFld), null, domainObject);
                    } else {
                        // Obtain the key-field from the ForeignGraph
                        Object value2 = getProperty(fMapping.getDataFieldDescriptor(sourceFld), value);

                        // Set the foreign-key, only if the key-field has been flagged as changed in the ForeignGraph.
                        // This will allow the UI to pass in just the modified portion of a composite foreign-key, and thus
                        // ensuring that the un-modified portion doesn't get nulled out
                        // The check is not required while cloning
                        if (mode == DataTransformer.Mode.CLONE || !(value instanceof GraphDataObject)
                                || ((GraphDataObject) value).hasChanged(sourceFld))
                            updateProperty(mapping.getRealDomainFieldDescriptor(targetFld), value2,
                                    domainObject);
                    }
                }

                // Invoke the getter on the domain. An exception will be raised if the foreign-key is invalid
                if (log.isDebugEnabled())
                    log.debug("Performing validation on the domain object for the foreign object "
                            + mapping.getDomainFieldName(field));
                PropertyDescriptor pd = mapping.getDomainFieldDescriptor(field);
                if (pd != null && pd.getReadMethod() != null) {
                    Method m = pd.getReadMethod();
                    if (!m.isAccessible())
                        m.setAccessible(true);
                    m.invoke(domainObject, (Object[]) null);
                }
            }
        }

        //----------------------------------------------------------------
        // Store Record
        if (mode == DataTransformer.Mode.VALIDATE_ONLY) {
            if (log.isDebugEnabled())
                log.debug(
                        "Domain object will not be persisted during prevalidation. Invoking the prevalidateBean handler");
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.prevalidateBean(path, source, domainObject);
                }
            }
        } else if (domainObject.isDatabaseOccurence()) {
            if (log.isDebugEnabled())
                log.debug("UOW.Update Domain Object");
            //----------------------------------------------------------------
            // Fire 'startBeanUpdate' handler
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.startBeanUpdate(path, source, domainObject);
                }
            }
            if (domainObject.isModified()) {
                uow.update(domainObject);
                if (handlers != null) {
                    for (ITransformationHandler transformationHandler : handlers) {
                        transformationHandler.setChangeDone(true);
                    }
                }
            }
            //----------------------------------------------------------------
            // Fire 'endBeanUpdate' handler
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.endBeanUpdate(path, source, domainObject);
                }
            }
        } else {
            if (handlers != null && mode == DataTransformer.Mode.CLONE) {
                if (log.isDebugEnabled()) {
                    log.debug("Invoke startBeanClone");
                }
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.startBeanClone(path, source, domainObject, newGraph);
                }
            } else if (handlers != null && mode == DataTransformer.Mode.MASS_UPDATE) {
                if (log.isDebugEnabled()) {
                    log.debug("Invoke startBeanMassUpdate");
                }
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.startBeanMassUpdate(path, source, domainObject, newGraph);
                }
            }
            if (log.isDebugEnabled())
                log.debug("UOW.Add Domain Object");
            //----------------------------------------------------------------
            // Fire 'startBeanAdd' handler
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.startBeanAdd(path, source, domainObject);
                }
            }
            uow.add(domainObject);
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.setChangeDone(true);
                }
            }
            //----------------------------------------------------------------
            // Fire 'endBeanAdd' handler
            if (handlers != null) {
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.endBeanAdd(path, source, domainObject);
                }
            }
            if (handlers != null && mode == DataTransformer.Mode.CLONE) {
                if (log.isDebugEnabled()) {
                    log.debug("Invoke endBeanClone");
                }
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.endBeanClone(path, source, domainObject, newGraph);
                }
            } else if (handlers != null && mode == DataTransformer.Mode.MASS_UPDATE) {
                if (log.isDebugEnabled()) {
                    log.debug("Invoke endBeanMassUpdate");
                }
                for (ITransformationHandler transformationHandler : handlers) {
                    transformationHandler.endBeanMassUpdate(path, source, domainObject, newGraph);
                }
            }
        }

        //----------------------------------------------------------------
        // Reflect any related objects
        for (Iterator it = mapping.getRelatedFields().iterator(); it.hasNext();) {
            String field = (String) it.next();
            if (mapping.isReadOnly(field))
                continue;
            Object value = null;
            if (mode == DataTransformer.Mode.CLONE) {
                // ignore no-cloning fields unless a value is passed in the newGraph
                if (mapping.isNoCloning(field) && (newGraph == null || !newGraph.hasChanged(field)))
                    continue;
                value = getProperty(mapping.getDataFieldDescriptor(field),
                        newGraph != null && newGraph.hasChanged(field) ? newGraph : source);
            } else if (mode == DataTransformer.Mode.MASS_UPDATE) {
                if (newGraph != null && newGraph.hasChanged(field))
                    value = getProperty(mapping.getDataFieldDescriptor(field), newGraph);
            } else
                value = getProperty(mapping.getDataFieldDescriptor(field), source);
            if (value != null) {
                if (value.getClass().isArray()) {
                    // The related field is an array of objects (one-to-many)
                    Object[] values = (Object[]) value;
                    for (int i = 0; i < values.length; i++) {
                        GraphDataObject dao = (GraphDataObject) values[i]; // Assumes its a DAO....what else could it be?
                        if (dao != null) {
                            if (dao.getDeleteObject() != null && dao.getDeleteObject()) {
                                if (mode == DataTransformer.Mode.VALIDATE_ONLY) {
                                    if (log.isDebugEnabled())
                                        log.debug(
                                                "The 'deleteObject' property is true. No prevalidations will be performed for the childBean.");
                                } else {
                                    if (log.isDebugEnabled())
                                        log.debug(
                                                "The 'deleteObject' property is true. Invoking deleteChildBean()");
                                    deleteChildBean(path + '.' + field + '[' + i + ']', dao, uow, handler,
                                            domainObject, mapping, field);
                                }
                            } else {
                                Object newValue = newGraph != null
                                        ? getProperty(mapping.getDataFieldDescriptor(field), newGraph)
                                        : null;
                                GraphDataObject newDao = newValue != null
                                        && ((GraphDataObject[]) newValue).length > i
                                                ? ((GraphDataObject[]) newValue)[i]
                                                : null;
                                updateChildBean(path + '.' + field + '[' + i + ']', dao, uow, handler,
                                        domainObject, mapping, field, mode, newDao);
                            }
                        }
                    }
                } else {
                    // Or a single Object (one-to-one)
                    GraphDataObject dao = (GraphDataObject) value; // Assumes its a DAO....what else could it be?
                    if (dao.getDeleteObject() != null && dao.getDeleteObject()) {
                        if (mode == DataTransformer.Mode.VALIDATE_ONLY) {
                            if (log.isDebugEnabled())
                                log.debug(
                                        "The 'deleteObject' property is true. No prevalidations will be performed for the childBean.");
                        } else {
                            if (log.isDebugEnabled())
                                log.debug("The 'deleteObject' property is true. Invoking deleteChildBean()");
                            deleteChildBean(path + '.' + field, dao, uow, handler, domainObject, mapping,
                                    field);
                        }
                    } else {
                        GraphDataObject newDao = newGraph != null
                                ? (GraphDataObject) getProperty(mapping.getDataFieldDescriptor(field), newGraph)
                                : null;
                        updateChildBean(path + '.' + field, dao, uow, handler, domainObject, mapping, field,
                                mode, newDao);
                    }
                }
            }
        }

        //----------------------------------------------------------------
        // Fire 'endBean' handler
        if (mode != DataTransformer.Mode.VALIDATE_ONLY && handlers != null) {
            for (ITransformationHandler transformationHandler : handlers) {
                transformationHandler.endBean(path, source, domainObject);
            }
        }

    } catch (SkipTransformException e) {
        if (log.isDebugEnabled()) {
            log.debug("Processing of " + path + " will be skipped", e);
        }
    } catch (ApplicationException e) {
        throw new ApplicationExceptions(e);
    }
}

From source file:de.micromata.genome.db.jpa.logging.BaseJpaLoggingImpl.java

/**
 * Inits the./*from ww w . jav  a  2  s  .  co m*/
 */
protected void initProps() {
    final BeanInfo bi;
    try {
        bi = Introspector.getBeanInfo(getMasterClass());
    } catch (IntrospectionException e) {
        log.error("unable to introspect hibernate DO for logging -> no searchable fields will be available", e);
        return;
    }

    for (PropertyDescriptor pd : bi.getPropertyDescriptors()) {
        if (pd.getReadMethod() == null || pd.getWriteMethod() == null) {
            continue;
        }
        EntityLogSearchAttribute ent = pd.getReadMethod().getAnnotation(EntityLogSearchAttribute.class);
        if (ent == null) {
            continue;
        }
        Column col = pd.getReadMethod().getAnnotation(Column.class);
        if (col == null) {
            log.warn("Found EntityLogSearchAttribute but no Column: " + pd);
            continue;
        }
        for (String en : ent.enumName()) {
            searchableAttributeProperties.put(en, new SearchColumnDesc(pd, col.length()));
        }
    }
}

From source file:org.jdbcluster.privilege.PrivilegeCheckerImpl.java

/**
 * gets Field instance of property path/*from ww  w . ja v a  2  s  .  c  o m*/
 * 
 * @param propertyPath property path
 * @param propDesc PropertyDescriptor
 * @return Field instance
 */
private Field getPropertyField(String propertyPath, PropertyDescriptor propDesc) {
    Method propertyReadMethod = propDesc.getReadMethod();
    String mName = propertyReadMethod.getName();
    String pName = mName.substring(3, 4).toLowerCase() + mName.substring(4);
    Class clazzContainingProperty = propertyReadMethod.getDeclaringClass();
    Field f = JDBClusterUtil.getField(pName, clazzContainingProperty);
    if (f == null)
        throw new ConfigurationException("property [" + propertyPath + "] does not exist");
    return f;
}

From source file:org.apache.tapestry.enhance.ComponentClassFactory.java

protected void scanForBindingProperty(String parameterName, IParameterSpecification ps) {
    String propertyName = parameterName + Tapestry.PARAMETER_PROPERTY_NAME_SUFFIX;
    PropertyDescriptor pd = getPropertyDescriptor(propertyName);

    // only enhance custom parameter binding properties if they are declared abstract
    if (ps.getDirection() == Direction.CUSTOM) {
        if (pd == null)
            return;

        if (!(isAbstract(pd.getReadMethod()) || isAbstract(pd.getWriteMethod())))
            return;
    }//from   ww  w. j a  v a  2 s  .c o  m

    if (isImplemented(pd))
        return;

    // Need to create the property.
    getEnhancedClass().createProperty(propertyName, IBinding.class.getName());
}