Example usage for org.apache.commons.beanutils PropertyUtils getNestedProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils getNestedProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils getNestedProperty.

Prototype

public static Object getNestedProperty(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Return the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:com.panemu.tiwulfx.form.BaseControl.java

/**
 * Push value to display in input control
 *
 * @param object//ww  w  .j  a v a  2 s .  c  om
 */
public final void pushValue(Object object) {
    R pushedValue = null;
    try {
        if (propertyName != null && !propertyName.trim().isEmpty()) {
            if (!getPropertyName().contains(".")) {
                pushedValue = (R) PropertyUtils.getSimpleProperty(object, propertyName);
            } else {
                pushedValue = (R) PropertyUtils.getNestedProperty(object, propertyName);
            }
            setValue(pushedValue);
        } else {
            System.out.println("Warning: propertyName is not set for " + getId());
        }

    } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException
            | NoSuchMethodException ex) {
        if (ex instanceof IllegalArgumentException) {
            /**
             * The actual exception needed to be cathect is
             * org.apache.commons.beanutils.NestedNullException. But Scene
             * Builder throw java.lang.ClassNotFoundException:
             * org.apache.commons.beanutils.NestedNullException if
             * NestedNullException is referenced in this class. So I catch
             * its parent isntead.
             */
            setValue(null);
        } else {
            throw new RuntimeException("Error when pushing value \"" + pushedValue + "\" to \"" + propertyName
                    + "\" propertyName. " + ex.getMessage(), ex);
        }
    } catch (Exception ex) {
        throw new RuntimeException("Error when pushing value \"" + pushedValue + "\" to \"" + propertyName
                + "\" propertyName. " + ex.getMessage(), ex);
    }
}

From source file:com.panemu.tiwulfx.form.BaseListControl.java

/**
 * Push value to display in input control
 *
 * @param object/*  w  w  w  .  j a  va2s.  c o  m*/
 */
public final void pushValue(Object object) {
    ObservableList<R> pushedValue = null;
    try {
        if (propertyName != null && !propertyName.trim().isEmpty()) {
            if (!getPropertyName().contains(".")) {
                pushedValue = (ObservableList<R>) PropertyUtils.getSimpleProperty(object, propertyName);
            } else {
                pushedValue = (ObservableList<R>) PropertyUtils.getNestedProperty(object, propertyName);
            }
            setValue(pushedValue);
        } else {
            System.out.println("Warning: propertyName is not set for " + getId());
        }

    } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException
            | NoSuchMethodException ex) {
        if (ex instanceof IllegalArgumentException) {
            /**
             * The actual exception needed to be cathect is
             * org.apache.commons.beanutils.NestedNullException. But Scene
             * Builder throw java.lang.ClassNotFoundException:
             * org.apache.commons.beanutils.NestedNullException if
             * NestedNullException is referenced in this class. So I catch
             * its parent isntead.
             */
            setValue(null);
        } else {
            throw new RuntimeException("Error when pushing value \"" + pushedValue + "\" to \"" + propertyName
                    + "\" propertyName. " + ex.getMessage(), ex);
        }
    } catch (Exception ex) {
        throw new RuntimeException("Error when pushing value \"" + pushedValue + "\" to \"" + propertyName
                + "\" propertyName. " + ex.getMessage(), ex);
    }
}

From source file:net.itransformers.idiscover.discoveryhelpers.xml.XmlDiscoveryHelper.java

public static Object getProperty(Object o, String propertyName) {
    try {/*ww  w.j a v a2s.c  om*/
        Object myValue = PropertyUtils.getNestedProperty(o, propertyName);
        return myValue;
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (NestedNullException nne) {
        return null;
    }
    return null;
}

From source file:com.liusoft.dlog4j.search.SearchProxy.java

/**
 * /*from   w w  w. j  a va 2 s. c  o m*/
 * @param obj
 * @param field
 * @param value
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 * @throws IntrospectionException 
 * @throws InstantiationException 
 */
private static void setNestedProperty(Object obj, String field, Object value) throws IllegalAccessException,
        InvocationTargetException, NoSuchMethodException, IntrospectionException, InstantiationException {
    StringTokenizer st = new StringTokenizer(field, ".");
    Class nodeClass = obj.getClass();
    StringBuffer tmp_prop = new StringBuffer();
    while (st.hasMoreElements()) {
        String f = st.nextToken();
        if (tmp_prop.length() > 0)
            tmp_prop.append('.');
        tmp_prop.append(f);
        PropertyDescriptor[] props = Introspector.getBeanInfo(nodeClass).getPropertyDescriptors();
        for (int i = 0; i < props.length; i++) {
            if (props[i].getName().equals(f)) {
                if (PropertyUtils.getNestedProperty(obj, tmp_prop.toString()) == null) {
                    nodeClass = props[i].getPropertyType();
                    PropertyUtils.setNestedProperty(obj, f, nodeClass.newInstance());
                }
                continue;
            }
        }
    }
    PropertyUtils.setNestedProperty(obj, field, value);
}

From source file:com.liusoft.dlog4j.search.SearchProxy.java

/**
 * ?//from w w w  . j av  a2s . c o m
 * @param obj
 * @param field
 * @return
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 */
private static String getField(Object obj, String field)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    try {
        Object fieldValue = PropertyUtils.getNestedProperty(obj, field);
        if (fieldValue instanceof String)
            return (String) fieldValue;
        if (fieldValue instanceof Date)
            return Long.toString(((Date) fieldValue).getTime());
        return String.valueOf(fieldValue);
    } catch (NestedNullException e) {
    }
    return null;
}

From source file:com.ctrip.infosec.rule.rabbitmq.RabbitMqMessageHandler.java

Object getNestedProperty(Object factOrEventBody, String columnExpression) {
    try {/*from www. j  a  va2  s .  co  m*/
        Object value = PropertyUtils.getNestedProperty(factOrEventBody, columnExpression);
        return value;
    } catch (Exception ex) {
        logger.info(Contexts.getLogPrefix() + "getNestedProperty fault. message: " + ex.getMessage());
    }
    return null;
}

From source file:ome.services.graphs.GraphPathBean.java

/**
 * Process the Hibernate domain object model to initialize this class' instance fields.
 * No other method should write to them.
 * @param sessionFactory the Hibernate session factory
 *///from ww w. jav  a 2 s  .  c om
private void initialize(SessionFactoryImplementor sessionFactory) {
    /* note all the direct superclasses */
    final Map<String, String> superclasses = new HashMap<String, String>();
    final Map<String, ClassMetadata> classesMetadata = sessionFactory.getAllClassMetadata();
    for (final String className : classesMetadata.keySet()) {
        try {
            final Class<?> actualClass = Class.forName(className);
            if (IObject.class.isAssignableFrom(actualClass)) {
                classesBySimpleName.put(actualClass.getSimpleName(), actualClass.asSubclass(IObject.class));
                final Set<String> subclassNames = sessionFactory.getEntityPersister(className)
                        .getEntityMetamodel().getSubclassEntityNames();
                for (final String subclassName : subclassNames) {
                    if (!subclassName.equals(className)) {
                        final Class<?> actualSubclass = Class.forName(subclassName);
                        if (actualSubclass.getSuperclass() == actualClass) {
                            superclasses.put(subclassName, className);
                        }
                    }
                }
            } else {
                log.warn("mapped class " + className + " is not a " + IObject.class.getName());
            }
        } catch (ClassNotFoundException e) {
            log.error("could not instantiate class", e);
        }
    }
    /* note the indirect superclasses and subclasses */
    for (final Entry<String, String> superclassRelationship : superclasses.entrySet()) {
        final String startClass = superclassRelationship.getKey();
        String superclass = superclassRelationship.getValue();
        while (superclass != null) {
            allSuperclasses.put(startClass, superclass);
            allSubclasses.put(superclass, startClass);
            superclass = superclasses.get(superclass);
        }
    }
    /* queue for processing all the properties of all the mapped entities: name, type, nullability */
    final Queue<PropertyDetails> propertyQueue = new LinkedList<PropertyDetails>();
    final Map<String, Set<String>> allPropertyNames = new HashMap<String, Set<String>>();
    for (final Entry<String, ClassMetadata> classMetadata : classesMetadata.entrySet()) {
        final String className = classMetadata.getKey();
        final ClassMetadata metadata = classMetadata.getValue();
        /* note name of identifier property */
        classIdProperties.put(metadata.getEntityName(), metadata.getIdentifierPropertyName());
        /* queue other properties */
        final String[] propertyNames = metadata.getPropertyNames();
        final Type[] propertyTypes = metadata.getPropertyTypes();
        final boolean[] propertyNullabilities = metadata.getPropertyNullability();
        for (int i = 0; i < propertyNames.length; i++) {
            final List<String> propertyPath = Collections.singletonList(propertyNames[i]);
            propertyQueue.add(
                    new PropertyDetails(className, propertyPath, propertyTypes[i], propertyNullabilities[i]));
        }
        final Set<String> propertyNamesSet = new HashSet<String>(propertyNames.length);
        propertyNamesSet.addAll(Arrays.asList(propertyNames));
        allPropertyNames.put(className, propertyNamesSet);
    }
    /* process each property to note entity linkages */
    while (!propertyQueue.isEmpty()) {
        final PropertyDetails property = propertyQueue.remove();
        if (ignoreProperty(property.path.get(property.path.size() - 1))) {
            continue;
        }
        /* if the property has a component type, queue the parts for processing */
        if (property.type instanceof ComponentType) {
            final ComponentType componentType = (ComponentType) property.type;
            final String[] componentPropertyNames = componentType.getPropertyNames();
            final Type[] componentPropertyTypes = componentType.getSubtypes();
            final boolean[] componentPropertyNullabilities = componentType.getPropertyNullability();
            for (int i = 0; i < componentPropertyNames.length; i++) {
                final List<String> componentPropertyPath = new ArrayList<String>(property.path.size() + 1);
                componentPropertyPath.addAll(property.path);
                componentPropertyPath.add(componentPropertyNames[i]);
                propertyQueue.add(new PropertyDetails(property.holder, componentPropertyPath,
                        componentPropertyTypes[i], componentPropertyNullabilities[i]));
            }
        } else {
            /* determine if another mapped entity class is linked by this property */
            final boolean isAssociatedEntity;
            if (property.type instanceof CollectionType) {
                final CollectionType ct = (CollectionType) property.type;
                isAssociatedEntity = sessionFactory.getCollectionPersister(ct.getRole()).getElementType()
                        .isEntityType();
            } else {
                isAssociatedEntity = property.type instanceof AssociationType;
            }
            /* the property can link to entities, so process it further */
            String propertyPath = Joiner.on('.').join(property.path);
            /* find if the property is accessible (e.g., not protected) */
            boolean propertyIsAccessible = false;
            String classToInstantiateName = property.holder;
            Class<?> classToInstantiate = null;
            try {
                classToInstantiate = Class.forName(classToInstantiateName);
                while (Modifier.isAbstract(classToInstantiate.getModifiers())) {
                    classToInstantiateName = allSubclasses.get(classToInstantiateName).iterator().next();
                    classToInstantiate = Class.forName(classToInstantiateName);
                }
                try {
                    PropertyUtils.getNestedProperty(classToInstantiate.newInstance(), propertyPath);
                    propertyIsAccessible = true;
                } catch (NoSuchMethodException e) {
                    /* expected for collection properties */
                } catch (NestedNullException e) {
                    log.warn("guessing " + propertyPath + " of " + property.holder + " to be accessible");
                    propertyIsAccessible = true;
                }
            } catch (ReflectiveOperationException e) {
                log.error("could not probe property " + propertyPath + " of " + property.holder, e);
                continue;
            }
            /* build property report line for log */
            final char arrowShaft = property.isNullable ? '-' : '=';
            final StringBuffer sb = new StringBuffer();
            sb.append(property.holder);
            sb.append(' ');
            for (final String propertyName : property.path) {
                sb.append(arrowShaft);
                sb.append(arrowShaft);
                sb.append(propertyName);
            }
            sb.append(arrowShaft);
            sb.append(arrowShaft);
            sb.append("> ");
            final String valueClassName;
            if (isAssociatedEntity) {
                valueClassName = ((AssociationType) property.type).getAssociatedEntityName(sessionFactory);
                sb.append(valueClassName);
            } else {
                valueClassName = null;
                sb.append("value");
            }
            if (property.type.isCollectionType()) {
                sb.append("[]");
            }
            if (!propertyIsAccessible) {
                sb.append(" (inaccessible)");
            }
            /* determine from which class the property is inherited, if at all */
            String superclassWithProperty = null;
            String currentClass = property.holder;
            while (true) {
                currentClass = superclasses.get(currentClass);
                if (currentClass == null) {
                    break;
                } else if (allPropertyNames.get(currentClass).contains(property.path.get(0))) {
                    superclassWithProperty = currentClass;
                }
            }
            /* check if the property actually comes from an interface */
            final String declaringClassName = superclassWithProperty == null ? property.holder
                    : superclassWithProperty;
            final Class<? extends IObject> interfaceForProperty = getInterfaceForProperty(declaringClassName,
                    property.path.get(0));
            /* report where the property is declared */
            if (superclassWithProperty != null) {
                sb.append(" from ");
                sb.append(superclassWithProperty);
            } else {
                if (interfaceForProperty != null) {
                    sb.append(" see ");
                    sb.append(interfaceForProperty.getName());
                    /* It would be nice to set PropertyDetails to have the interface as the holder,
                     * but then properties would not be unique by declarer class and instance ID. */
                }
                /* entity linkages by non-inherited properties are recorded */
                if (valueClassName == null && property.path.size() > 1) {
                    /* assume that the top-level property suffices for describing simple properties */
                    log.debug("recording " + propertyPath + " as " + property.path.get(0));
                    propertyPath = property.path.get(0);
                }
                final Entry<String, String> classPropertyName = Maps.immutableEntry(property.holder,
                        propertyPath);
                if (valueClassName == null) {
                    simpleProperties.put(property.holder, propertyPath);
                } else {
                    linkedTo.put(property.holder, Maps.immutableEntry(valueClassName, propertyPath));
                    linkedBy.put(valueClassName, classPropertyName);
                }
                final PropertyKind propertyKind;
                if (property.type.isCollectionType()) {
                    propertyKind = PropertyKind.COLLECTION;
                } else if (property.isNullable) {
                    propertyKind = PropertyKind.OPTIONAL;
                } else {
                    propertyKind = PropertyKind.REQUIRED;
                }
                propertyKinds.put(classPropertyName, propertyKind);
                if (propertyIsAccessible) {
                    accessibleProperties.add(classPropertyName);
                }
            }
            if (log.isDebugEnabled()) {
                log.debug(sb.toString());
            }
        }
    }
    log.info("initialized graph path bean with " + propertyKinds.size() + " properties");
}

From source file:omero.cmd.graphs.DuplicateI.java

/**
 * Duplicate model object properties, linking them as appropriate with each other and with other model objects.
 * @throws GraphException if duplication failed
 *///from   www  . j av a  2 s.  c om
private void setDuplicatePropertyValues() throws GraphException {
    /* organize duplicate index by class name and ID */
    final Map<Entry<String, Long>, IObject> duplicatesByOriginalClassAndId = new HashMap<Entry<String, Long>, IObject>();
    for (final Entry<IObject, IObject> originalAndDuplicate : originalsToDuplicates.entrySet()) {
        final IObject original = originalAndDuplicate.getKey();
        final String originalClass = Hibernate.getClass(original).getName();
        final Long originalId = original.getId();
        final IObject duplicate = originalAndDuplicate.getValue();
        duplicatesByOriginalClassAndId.put(Maps.immutableEntry(originalClass, originalId), duplicate);
    }
    /* allow lookup regardless of if original is actually a Hibernate proxy object */
    final Function<Object, Object> duplicateLookup = new Function<Object, Object>() {
        @Override
        public Object apply(Object original) {
            if (original instanceof IObject) {
                final String originalClass;
                if (original instanceof HibernateProxy) {
                    originalClass = Hibernate.getClass(original).getName();
                } else {
                    originalClass = original.getClass().getName();
                }
                final Long originalId = ((IObject) original).getId();
                return duplicatesByOriginalClassAndId.get(Maps.immutableEntry(originalClass, originalId));
            } else {
                return null;
            }
        }
    };
    /* copy property values into duplicates and link with other model objects */
    final Session session = helper.getSession();
    for (final Entry<IObject, IObject> originalAndDuplicate : originalsToDuplicates.entrySet()) {
        final IObject original = originalAndDuplicate.getKey();
        final IObject duplicate = originalAndDuplicate.getValue();
        final String originalClass = Hibernate.getClass(original).getName();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("copying properties from " + originalClass + ":" + original.getId());
        }
        try {
            /* process property values for a given object that is duplicated */
            for (final String superclassName : graphPathBean.getSuperclassesOfReflexive(originalClass)) {
                /* process property values that link from the duplicate to other model objects */
                for (final Entry<String, String> forwardLink : graphPathBean.getLinkedTo(superclassName)) {
                    /* next forward link */
                    final String linkedClassName = forwardLink.getKey();
                    final String property = forwardLink.getValue();
                    /* ignore details for now, duplicates never preserve original ownership */
                    if (property.startsWith("details.")) {
                        continue;
                    }
                    /* note which of the objects to which the original links should be ignored */
                    final Set<Long> linkedToIdsToIgnore = new HashSet<Long>();
                    for (final Entry<String, Collection<Long>> linkedToClassIds : graphTraversal
                            .getLinkeds(superclassName, property, original.getId()).asMap().entrySet()) {
                        final String linkedToClass = linkedToClassIds.getKey();
                        final Collection<Long> linkedToIds = linkedToClassIds.getValue();
                        if (classifier.getClass(
                                Class.forName(linkedToClass).asSubclass(IObject.class)) == Inclusion.IGNORE) {
                            linkedToIdsToIgnore.addAll(linkedToIds);
                        }
                    }
                    /* check for another accessor for inaccessible properties */
                    if (graphPathBean.isPropertyAccessible(superclassName, property)) {
                        /* copy the linking from the original's property over to the duplicate's */
                        Object value;
                        try {
                            value = PropertyUtils.getNestedProperty(original, property);
                        } catch (NestedNullException e) {
                            continue;
                        }
                        if (value instanceof Collection) {
                            /* if a collection property, include only the objects that aren't to be ignored */
                            final Collection<IObject> valueCollection = (Collection<IObject>) value;
                            final Collection<IObject> valueToCopy;
                            if (value instanceof List) {
                                valueToCopy = new ArrayList<IObject>();
                            } else if (value instanceof Set) {
                                valueToCopy = new HashSet<IObject>();
                            } else {
                                throw new GraphException("unexpected collection type: " + value.getClass());
                            }
                            for (final IObject linkedTo : valueCollection) {
                                if (!linkedToIdsToIgnore.contains(linkedTo.getId())) {
                                    valueToCopy.add(linkedTo);
                                }
                            }
                            value = valueToCopy;
                        } else if (value instanceof IObject) {
                            /* if the property value is to be ignored then null it */
                            if (linkedToIdsToIgnore.contains(((IObject) value).getId())) {
                                value = null;
                            }
                        }
                        /* copy the property value, replacing originals with corresponding duplicates */
                        final Object duplicateValue = GraphUtil.copyComplexValue(duplicateLookup, value);
                        try {
                            PropertyUtils.setNestedProperty(duplicate, property, duplicateValue);
                        } catch (NestedNullException e) {
                            throw new GraphException(
                                    "cannot set property " + superclassName + '.' + property + " on duplicate");
                        }
                    } else {
                        /* this could be a one-to-many property with direct accessors protected */
                        final Class<? extends IObject> linkerClass = Class.forName(superclassName)
                                .asSubclass(IObject.class);
                        final Class<? extends IObject> linkedClass = Class.forName(linkedClassName)
                                .asSubclass(IObject.class);
                        final Method reader, writer;
                        try {
                            reader = linkerClass.getMethod("iterate" + StringUtils.capitalize(property));
                            writer = linkerClass.getMethod("add" + linkedClass.getSimpleName(), linkedClass);
                        } catch (NoSuchMethodException | SecurityException e) {
                            /* no luck, so ignore this property */
                            continue;
                        }
                        /* copy the linking from the original's property over to the duplicate's */
                        final Iterator<IObject> linkedTos = (Iterator<IObject>) reader.invoke(original);
                        while (linkedTos.hasNext()) {
                            final IObject linkedTo = linkedTos.next();
                            /* copy only links to other duplicates, as otherwise we may steal objects from the original */
                            final IObject duplicateOfLinkedTo = (IObject) duplicateLookup.apply(linkedTo);
                            if (duplicateOfLinkedTo != null) {
                                writer.invoke(duplicate, duplicateOfLinkedTo);
                            }
                        }
                    }
                }
                /* process property values that link to the duplicate from other model objects */
                for (final Entry<String, String> backwardLink : graphPathBean.getLinkedBy(superclassName)) {
                    /* next backward link */
                    final String linkingClass = backwardLink.getKey();
                    final String property = backwardLink.getValue();
                    /* ignore inaccessible properties */
                    if (!graphPathBean.isPropertyAccessible(linkingClass, property)) {
                        continue;
                    }
                    for (final Entry<String, Collection<Long>> linkedFromClassIds : graphTraversal
                            .getLinkers(linkingClass, property, original.getId()).asMap().entrySet()) {
                        final String linkedFromClass = linkedFromClassIds.getKey();
                        final Collection<Long> linkedFromIds = linkedFromClassIds.getValue();
                        if (classifier.getClass(
                                Class.forName(linkedFromClass).asSubclass(IObject.class)) == Inclusion.IGNORE) {
                            /* these linkers are to be ignored */
                            continue;
                        }
                        /* load the instances that link to the original */
                        final String rootQuery = "FROM " + linkedFromClass + " WHERE id IN (:ids)";
                        for (final List<Long> idsBatch : Iterables.partition(linkedFromIds, BATCH_SIZE)) {
                            final List<IObject> linkers = session.createQuery(rootQuery)
                                    .setParameterList("ids", idsBatch).list();
                            for (final IObject linker : linkers) {
                                if (originalsToDuplicates.containsKey(linker)) {
                                    /* ignore linkers that are to be duplicated, those are handled as forward links */
                                    continue;
                                }
                                /* copy the linking from the original's property over to the duplicate's */
                                Object value;
                                try {
                                    value = PropertyUtils.getNestedProperty(linker, property);
                                } catch (NestedNullException e) {
                                    continue;
                                }
                                /* for linkers only adjust collection properties */
                                if (value instanceof Collection) {
                                    final Collection<IObject> valueCollection = (Collection<IObject>) value;
                                    final Collection<IObject> newDuplicates = new ArrayList<IObject>();
                                    for (final IObject originalLinker : valueCollection) {
                                        final IObject duplicateOfValue = originalsToDuplicates
                                                .get(originalLinker);
                                        if (duplicateOfValue != null) {
                                            /* previous had just original, now include duplicate too */
                                            newDuplicates.add(duplicateOfValue);
                                        }
                                    }
                                    valueCollection.addAll(newDuplicates);
                                }
                            }
                        }
                    }
                }
                /* process property values that do not relate to edges in the model object graph */
                for (final String property : graphPathBean.getSimpleProperties(superclassName)) {
                    /* ignore inaccessible properties */
                    if (!graphPathBean.isPropertyAccessible(superclassName, property)) {
                        continue;
                    }
                    /* copy original property value to duplicate */
                    final Object value = PropertyUtils.getProperty(original, property);
                    PropertyUtils.setProperty(duplicate, property,
                            GraphUtil.copyComplexValue(duplicateLookup, value));
                }
            }
        } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException
                | NoSuchMethodException e) {
            throw new GraphException("failed to duplicate " + originalClass + ':' + original.getId());
        }
    }
}

From source file:org.apache.hadoop.hive.metastore.TestGetPartitionsUsingProjectionAndFilterSpecs.java

/**
 * Confirms if the partitionWithoutSD object at partitionWithoutSDSIndex index has all the
 * projected fields set to values which are same as the ones set in origPartitions
 * @param projectedFields/*from ww  w. ja va 2s  .  c  om*/
 * @param sharedSD
 * @param partitionWithoutSDS
 * @param partitionWithoutSDSIndex
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 */
private void comparePartitionForSingleValuedFields(List<String> projectedFields, StorageDescriptor sharedSD,
        List<PartitionWithoutSD> partitionWithoutSDS, int partitionWithoutSDSIndex)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    for (Partition origPart : origPartitions) {
        for (String projectField : projectedFields) {
            // dbname, tableName and catName is not stored in partition
            if (projectField.equals("dbName") || projectField.equals("tableName")
                    || projectField.equals("catName"))
                continue;
            if (projectField.startsWith("sd")) {
                String sdPropertyName = projectField.substring(projectField.indexOf("sd.") + 3);
                if (sdPropertyName.equals("location")) {
                    // in case of location sharedSD has the base location and partition has relative location
                    Assert.assertEquals("Location does not match", origPart.getSd().getLocation(),
                            sharedSD.getLocation()
                                    + partitionWithoutSDS.get(partitionWithoutSDSIndex).getRelativePath());
                } else {
                    Assert.assertEquals(PropertyUtils.getNestedProperty(origPart, projectField),
                            PropertyUtils.getNestedProperty(sharedSD, sdPropertyName));
                }
            } else {
                Assert.assertEquals(PropertyUtils.getNestedProperty(origPart, projectField), PropertyUtils
                        .getNestedProperty(partitionWithoutSDS.get(partitionWithoutSDSIndex), projectField));
            }
        }
        partitionWithoutSDSIndex++;
    }
}

From source file:org.charleech.primefaces.eval.ui.table.lazy.LazyMyDataDataModel.java

/**
 * Get the data field value by using the specified property.
 *
 * @param data/* w w  w  . jav a  2s  .c om*/
 *            The source data
 * @param property
 *            The getting property
 * @return The property value matched by the specified property
 * @throws IllegalArgumentException
 *             If there is any error.
 * @throws IllegalAccessException
 *             If there is any error.
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @since 0.0.1
 */
private String getFieldValue(final MyData data, final String property) throws IllegalArgumentException,
        IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    return String.valueOf(PropertyUtils.getNestedProperty(data, property));
}