当前位置: 首页>>代码示例>>Java>>正文


Java ReflectionUtils类代码示例

本文整理汇总了Java中org.jcrom.util.ReflectionUtils的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils类的具体用法?Java ReflectionUtils怎么用?Java ReflectionUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReflectionUtils类属于org.jcrom.util包,在下文中一共展示了ReflectionUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mapPackage

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
/**
 * Tries to map all classes in the package specified.
 * 
 * @param packageName the name of the package to process
 * @param ignoreInvalidClasses specifies whether to ignore classes in the package that cannot be mapped
 * @return the Jcrom instance
 */
public synchronized Jcrom mapPackage(String packageName, boolean ignoreInvalidClasses) {
    try {
        for (Class<?> c : ReflectionUtils.getClasses(packageName)) {
            try {
                // Ignore Enum because these are not entities
                // Can be useful if there is an inner Enum
                if (!c.isEnum()) {
                    map(c);
                }
            } catch (JcrMappingException ex) {
                if (!ignoreInvalidClasses) {
                    throw ex;
                }
            }
        }
        return this;
    } catch (IOException ioex) {
        throw new JcrMappingException("Could not get map classes from package " + packageName, ioex);
    } catch (ClassNotFoundException cnfex) {
        throw new JcrMappingException("Could not get map classes from package " + packageName, cnfex);
    }
}
 
开发者ID:dooApp,项目名称:jcromfx,代码行数:30,代码来源:Jcrom.java

示例2: mapPropertyToField

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
void mapPropertyToField(Object obj, Field field, Node node, int depth, NodeFilter nodeFilter) throws RepositoryException, IllegalAccessException, IOException {
    String name = getPropertyName(field);

    if (nodeFilter == null || nodeFilter.isIncluded(NodeFilter.PROPERTY_PREFIX + field.getName(), node, depth)) {
        if (isMap(field)) {
            // map of properties
            Class<?> valueType = ReflectionUtils.getParameterizedClass(field, 1);
            try {
                Node childrenContainer = node.getNode(name);
                PropertyIterator propIterator = childrenContainer.getProperties();
                mapPropertiesToMap(obj, field, valueType, propIterator, true);
            } catch (PathNotFoundException pne) {
                // ignore here as the Field could have been added to the model
                // since the Node was created and not yet been populated.
            }
        } else {
            mapToField(name, field, obj, node);
        }
    }
}
 
开发者ID:dooApp,项目名称:jcromfx,代码行数:21,代码来源:PropertyMapper.java

示例3: addChildMap

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void addChildMap(Field field, Object obj, Node node, String nodeName, Mapper mapper) throws RepositoryException, IllegalAccessException {

    Map<String, Object> map = (Map<String, Object>) field.get(obj);
    boolean nullOrEmpty = map == null || map.isEmpty();
    // remove the child node
    NodeIterator nodeIterator = node.getNodes(nodeName);
    while (nodeIterator.hasNext()) {
        nodeIterator.nextNode().remove();
    }
    // add the map as a child node
    Node childContainer = node.addNode(mapper.getCleanName(nodeName));
    if (!nullOrEmpty) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            mapToProperty(entry.getKey(), ReflectionUtils.getParameterizedClass(field, 1), null, entry.getValue(), childContainer);
        }
    }
}
 
开发者ID:dooApp,项目名称:jcromfx,代码行数:19,代码来源:PropertyMapper.java

示例4: listClassesInPackage

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
@Test
public void listClassesInPackage() throws Exception {

    Set<Class<?>> classes = ReflectionUtils.getClasses("org.jcrom.annotations");
    assertEquals(19, classes.size());
    assertTrue(classes.contains(JcrChildNode.class));
    assertTrue(classes.contains(JcrFileNode.LoadType.class));

    Set<Class<?>> jcrClasses = ReflectionUtils.getClasses("javax.jcr");

    for (Class<?> c : jcrClasses) {
        System.out.println(c.getName());
    }

    assertTrue(jcrClasses.contains(Node.class));

    Set<Class<?>> classesToMap = ReflectionUtils.getClasses("org.jcrom.dao");
    assertEquals(12, classesToMap.size());
}
 
开发者ID:dooApp,项目名称:jcromfx,代码行数:20,代码来源:TestReflection.java

示例5: validateInternal

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
private void validateInternal(Class<?> c, Set<Class<?>> validClasses, boolean dynamicInstantiation)
{
    if (!validClasses.contains(c))
    {
        if (logger.isLoggable(Level.FINE))
        {
            logger.finer("Processing class: " + c.getName());
        }

        validClasses.add(c);

        // when dynamic instantiation is turned on, we ignore interfaces
        if (!(c.isInterface() && dynamicInstantiation))
        {
            if (c.isArray())
            {
                c = c.getComponentType();
            }
            validateFields(c, ReflectionUtils.getDeclaredAndInheritedFields(c, true), validClasses, dynamicInstantiation);
        }
    }
}
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:23,代码来源:Validator.java

示例6: mapProtectedPropertyToField

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
void mapProtectedPropertyToField(Object obj, Field field, Node node) throws RepositoryException, IllegalAccessException, IOException
{
    String name = getProtectedPropertyName(field);

    if (ReflectionUtils.implementsInterface(field.getType(), Map.class))
    {
        // map of properties
        Class<?> valueType = ReflectionUtils.getParameterizedClass(field, 1);
        Node childrenContainer = node.getNode(name);
        PropertyIterator propIterator = childrenContainer.getProperties();
        mapPropertiesToMap(obj, field, valueType, propIterator, false);
    }
    else
    {
        mapToField(name, field, obj, node);
    }
}
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:18,代码来源:PropertyMapper.java

示例7: addChildMap

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void addChildMap(Field field, Object obj, Node node, String nodeName, Mapper mapper) throws RepositoryException, IllegalAccessException
{

    Map<String, Object> map = (Map<String, Object>) field.get(obj);
    boolean nullOrEmpty = map == null || map.isEmpty();
    // remove the child node
    NodeIterator nodeIterator = node.getNodes(nodeName);
    while (nodeIterator.hasNext())
    {
        nodeIterator.nextNode().remove();
    }
    // add the map as a child node
    Node childContainer = node.addNode(mapper.getCleanName(nodeName));
    boolean fieldIsReadyOnly = getIsReadOnly(field);
    if (!nullOrEmpty && !fieldIsReadyOnly)
    {
        for (Map.Entry<String, Object> entry : map.entrySet())
        {
            mapToProperty(entry.getKey(), ReflectionUtils.getParameterizedClass(field, 1), null, entry.getValue(), childContainer);
        }
    }
}
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:24,代码来源:PropertyMapper.java

示例8: mapFieldToProperty

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
private void mapFieldToProperty(Field field, Object obj, Node node, int depth, NodeFilter nodeFilter, Mapper mapper) throws RepositoryException,
        IllegalAccessException
{
    boolean fieldIsReadyOnly = getIsReadOnly(field);
    if (!fieldIsReadyOnly)
    {

        String name = getPropertyName(field);
        // make sure that this property is supposed to be updated
        if (nodeFilter == null || nodeFilter.isIncluded(NodeFilter.PROPERTY_PREFIX + field.getName(), node, depth))
        {
            if (ReflectionUtils.implementsInterface(field.getType(), Map.class))
            {
                // this is a Map child, where we map the key/value pairs as properties
                addChildMap(field, obj, node, name, mapper);
            }
            else
            {
                // normal property
                Class<?> paramClass = ReflectionUtils.implementsInterface(field.getType(), List.class) ? ReflectionUtils.getParameterizedClass(field)
                        : null;
                mapToProperty(name, field.getType(), paramClass, field.get(obj), node);
            }
        }
    }
}
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:27,代码来源:PropertyMapper.java

示例9: setReferenceProperties

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
private void setReferenceProperties(Field field, Object obj, Node node, NodeFilter nodeFilter) throws IllegalAccessException, RepositoryException {

        String propertyName = getPropertyName(field);

        // make sure that the reference should be updated
        if (nodeFilter == null || nodeFilter.isNameIncluded(field.getName())) {
            if (ReflectionUtils.implementsInterface(field.getType(), List.class)) {
                // multiple references in a List
                addMultipleReferencesToNode(field, obj, propertyName, node);
            } else if (ReflectionUtils.implementsInterface(field.getType(), Map.class)) {
                // multiple references in a Map
                addMapOfReferencesToNode(field, obj, propertyName, node);
            } else {
                // single reference object
                addSingleReferenceToNode(field, obj, propertyName, node);
            }
        }
    }
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:19,代码来源:ReferenceMapper.java

示例10: addSingleFileToNode

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
private void addSingleFileToNode(Field field, Object obj, String nodeName, Node node, Mapper mapper, int depth, NodeFilter nodeFilter) throws IllegalAccessException, RepositoryException, IOException {

        JcrNode fileJcrNode = ReflectionUtils.getJcrNodeAnnotation(field.getType());
        Node fileContainer = createFileFolderNode(fileJcrNode, nodeName, node, mapper);

        if (!fileContainer.hasNodes()) {
            if (field.get(obj) != null) {
                addFileNode(fileJcrNode, fileContainer, (JcrFile) field.get(obj), mapper);
            }
        } else {
            if (field.get(obj) != null) {
                updateFileNode(fileContainer.getNodes().nextNode(), (JcrFile) field.get(obj), nodeFilter, depth, mapper);
            } else {
                // field is now null, so we remove the files
                removeChildren(fileContainer);
            }
        }
    }
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:19,代码来源:FileNodeMapper.java

示例11: setFiles

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
private void setFiles(Field field, Object obj, Node node, Mapper mapper, int depth, NodeFilter nodeFilter) throws IllegalAccessException, RepositoryException, IOException {

        String nodeName = getNodeName(field);

        // make sure that this child is supposed to be updated
        if (nodeFilter == null || nodeFilter.isIncluded(field.getName(), depth)) {
            if (ReflectionUtils.implementsInterface(field.getType(), List.class)) {
                // multiple file nodes in a List
                addMultipleFilesToNode(field, obj, nodeName, node, mapper, depth, nodeFilter);
            } else if (ReflectionUtils.implementsInterface(field.getType(), Map.class)) {
                // dynamic map of file nodes
                addMapOfFilesToNode(field, obj, nodeName, node, mapper, depth, nodeFilter);
            } else {
                // single child
                addSingleFileToNode(field, obj, nodeName, node, mapper, depth, nodeFilter);
            }
        }
    }
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:19,代码来源:FileNodeMapper.java

示例12: clearCglib

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
/**
 * This is a temporary solution to enable lazy loading of single child nodes and single references. The problem is that Jcrom uses direct field
 * modification, but CGLIB fails to cascade field changes between the enhanced class and the lazy object.
 * 
 * @param obj
 * @return
 * @throws java.lang.IllegalAccessException
 */
Object clearCglib(Object obj) throws IllegalAccessException
{
    for (Field field : ReflectionUtils.getDeclaredAndInheritedFields(obj.getClass(), true))
    {
        field.setAccessible(true);
        if (field.getName().equals("CGLIB$LAZY_LOADER_0"))
        {
            if (field.get(obj) != null)
            {
                return field.get(obj);
            }
            else
            {
                // lazy loading has not been triggered yet, so
                // we do it manually
                return triggerLazyLoading(obj);
            }
        }
    }
    return obj;
}
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:30,代码来源:Mapper.java

示例13: triggerLazyLoading

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
Object triggerLazyLoading(Object obj) throws IllegalAccessException
{
    for (Field field : ReflectionUtils.getDeclaredAndInheritedFields(obj.getClass(), false))
    {
        field.setAccessible(true);
        if (field.getName().equals("CGLIB$CALLBACK_0"))
        {
            try
            {
                return ((LazyLoader) field.get(obj)).loadObject();
            }
            catch (Exception e)
            {
                throw new JcrMappingException("Could not trigger lazy loading", e);
            }
        }
    }
    return obj;
}
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:20,代码来源:Mapper.java

示例14: addMapChild

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
private void addMapChild(Class<?> paramClass, Node childContainer, Map<?, ?> childMap, String key, String cleanKey, Mapper mapper)
        throws IllegalAccessException, RepositoryException, IOException
{
    if (ReflectionUtils.implementsInterface(paramClass, List.class))
    {
        List<?> childList = (List<?>) childMap.get(key);
        // create a container for the List
        Node listContainer = childContainer.addNode(cleanKey);
        for (int i = 0; i < childList.size(); i++)
        {
            mapper.addNode(listContainer, childList.get(i), null, null);
        }
    }
    else
    {
        mapper.setNodeName(childMap.get(key), cleanKey);
        mapper.addNode(childContainer, childMap.get(key), null, null);
    }
}
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:20,代码来源:ChildNodeMapper.java

示例15: listClassesInPackage

import org.jcrom.util.ReflectionUtils; //导入依赖的package包/类
@Test
public void listClassesInPackage() throws Exception {

    Set<Class<?>> classes = ReflectionUtils.getClasses("org.jcrom.annotations");
    assertEquals(22, classes.size());
    assertTrue(classes.contains(JcrChildNode.class));
    assertTrue(classes.contains(JcrFileNode.LoadType.class));

    Set<Class<?>> jcrClasses = ReflectionUtils.getClasses("javax.jcr");

    for (Class<?> c : jcrClasses) {
        System.out.println(c.getName());
    }

    assertTrue(jcrClasses.contains(Node.class));

    Set<Class<?>> classesToMap = ReflectionUtils.getClasses("org.jcrom.dao");
    assertEquals(12, classesToMap.size());
}
 
开发者ID:sbrinkmann,项目名称:jcrom-extended,代码行数:20,代码来源:TestReflection.java


注:本文中的org.jcrom.util.ReflectionUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。