本文整理汇总了Java中org.jcrom.util.ReflectionUtils.getParameterizedClass方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.getParameterizedClass方法的具体用法?Java ReflectionUtils.getParameterizedClass怎么用?Java ReflectionUtils.getParameterizedClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jcrom.util.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.getParameterizedClass方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: 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);
}
}
示例3: 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);
}
}
}
}
示例4: mapProtectedPropertyToField
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
void mapProtectedPropertyToField(Object obj, Field field, Node node) throws RepositoryException, IllegalAccessException, IOException {
String name = getProtectedPropertyName(field);
if (isMap(field)) {
// 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);
}
}
示例5: 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 {
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 (isMap(field)) {
// 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 = isList(field.getType()) ? ReflectionUtils.getParameterizedClass(field) : null;
mapToProperty(name, field.getType(), paramClass, field.get(obj), node);
}
}
}
示例6: addMapOfReferencesToNode
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* Maps a Map<String,Object> or Map<String,List<Object>> to a JCR Node.
*/
private void addMapOfReferencesToNode(Field field, Object obj, String containerName, Node node) throws IllegalAccessException, RepositoryException {
JcrReference jcrReference = mapper.getJcrom().getAnnotationReader().getAnnotation(field, JcrReference.class);
// remove previous references if they exist
if (node.hasNode(containerName)) {
node.getNode(containerName).remove();
}
// create a reference container
Node referenceContainer = node.addNode(containerName);
// map the references as properties on the container node
Map<?, ?> referenceMap = (Map<?, ?>) field.get(obj);
if (referenceMap != null && !referenceMap.isEmpty()) {
Class<?> paramClass = ReflectionUtils.getParameterizedClass(field, 1);
for (Map.Entry<?, ?> entry : referenceMap.entrySet()) {
String key = (String) entry.getKey();
if (isList(paramClass)) {
List<?> references = (List<?>) entry.getValue();
List<Value> refValues = getReferenceValues(references, referenceContainer.getSession(), jcrReference);
if (!refValues.isEmpty()) {
referenceContainer.setProperty(key, refValues.toArray(new Value[refValues.size()]));
}
} else {
Object referenceObject = entry.getValue();
mapSingleReference(jcrReference, referenceObject, referenceContainer, key);
}
}
}
}
示例7: getFileMap
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Map<?, ?> getFileMap(Field field, Node fileContainer, JcrFileNode jcrFileNode, Object obj, int depth, NodeFilter nodeFilter, Mapper mapper) throws ClassNotFoundException, InstantiationException, RepositoryException, IllegalAccessException, IOException {
Class<?> mapParamClass = ReflectionUtils.getParameterizedClass(field, 1);
Map<Object, Object> children = jcrFileNode.mapContainerClass().newInstance();
NodeIterator iterator = fileContainer.getNodes();
while (iterator.hasNext()) {
Node childNode = iterator.nextNode();
if (isList(mapParamClass)) {
Class<?> childObjClass = ReflectionUtils.getTypeArgumentOfParameterizedClass(field, 1, 0);
if (jcrFileNode.lazy()) {
// lazy loading
children.put(childNode.getName(), ProxyFactory.createFileNodeListProxy(childObjClass, obj, fileContainer.getPath(), fileContainer.getSession(), mapper, depth, nodeFilter, jcrFileNode));
} else {
children.put(childNode.getName(), getFileList(childObjClass, childNode, obj, jcrFileNode, depth, nodeFilter, mapper));
}
} else {
if (jcrFileNode.lazy()) {
// lazy loading
children.put(childNode.getName(), ProxyFactory.createFileNodeProxy(mapParamClass, obj, fileContainer.getPath(), fileContainer.getSession(), mapper, depth, nodeFilter, jcrFileNode));
} else {
children.put(childNode.getName(), getSingleFile(mapParamClass, fileContainer, obj, jcrFileNode, depth, nodeFilter, mapper));
}
}
}
return children;
}
示例8: addMapOfReferencesToNode
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* Maps a Map<String,Object> or Map<String,List<Object>> to a JCR Node.
*/
private void addMapOfReferencesToNode(Field field, Object obj, String containerName, Node node) throws IllegalAccessException, RepositoryException {
JcrReference jcrReference = mapper.getJcrom().getAnnotationReader().getAnnotation(field, JcrReference.class);
// remove previous references if they exist
if (node.hasNode(containerName)) {
node.getNode(containerName).remove();
}
// create a reference container
Node referenceContainer = node.addNode(containerName);
// map the references as properties on the container node
Map<?, ?> referenceMap = (Map<?, ?>) field.get(obj);
if (referenceMap != null && !referenceMap.isEmpty()) {
Class<?> paramClass = ReflectionUtils.getParameterizedClass(field, 1);
for (Map.Entry<?, ?> entry : referenceMap.entrySet()) {
String key = (String) entry.getKey();
if (ReflectionUtils.implementsInterface(paramClass, List.class)) {
List<?> references = (List<?>) entry.getValue();
List<Value> refValues = getReferenceValues(references, referenceContainer.getSession(), jcrReference);
if (!refValues.isEmpty()) {
referenceContainer.setProperty(key, refValues.toArray(new Value[refValues.size()]));
}
} else {
Object referenceObject = entry.getValue();
mapSingleReference(jcrReference, referenceObject, referenceContainer, key);
}
}
}
}
示例9: getFileMap
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Map<?, ?> getFileMap(Field field, Node fileContainer, JcrFileNode jcrFileNode, Object obj, int depth, NodeFilter nodeFilter, Mapper mapper) throws ClassNotFoundException, InstantiationException, RepositoryException, IllegalAccessException, IOException {
Class<?> mapParamClass = ReflectionUtils.getParameterizedClass(field, 1);
Map<Object, Object> children = jcrFileNode.mapContainerClass().newInstance();
NodeIterator iterator = fileContainer.getNodes();
while (iterator.hasNext()) {
Node childNode = iterator.nextNode();
if (ReflectionUtils.implementsInterface(mapParamClass, List.class)) {
Class<?> childObjClass = ReflectionUtils.getTypeArgumentOfParameterizedClass(field, 1, 0);
if (jcrFileNode.lazy()) {
// lazy loading
children.put(childNode.getName(), ProxyFactory.createFileNodeListProxy(childObjClass, obj, fileContainer.getPath(), fileContainer.getSession(), mapper, depth, nodeFilter, jcrFileNode));
} else {
children.put(childNode.getName(), getFileList(childObjClass, childNode, obj, jcrFileNode, depth, nodeFilter, mapper));
}
} else {
if (jcrFileNode.lazy()) {
// lazy loading
children.put(childNode.getName(), ProxyFactory.createFileNodeProxy(mapParamClass, obj, fileContainer.getPath(), fileContainer.getSession(), mapper, depth, nodeFilter, jcrFileNode));
} else {
children.put(childNode.getName(), getSingleFile(mapParamClass, fileContainer, obj, jcrFileNode, depth, nodeFilter, mapper));
}
}
}
return children;
}
示例10: getFilesFromNode
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
void getFilesFromNode(Field field, Node node, Object obj, int depth, NodeFilter nodeFilter, Mapper mapper) throws ClassNotFoundException, InstantiationException, RepositoryException, IllegalAccessException, IOException {
String nodeName = getNodeName(field);
JcrFileNode jcrFileNode = mapper.getJcrom().getAnnotationReader().getAnnotation(field, JcrFileNode.class);
if (node.hasNode(nodeName) && nodeFilter.isIncluded(field.getName(), depth)) {
// file nodes are always stored inside a folder node
Node fileContainer = node.getNode(nodeName);
if (ReflectionUtils.implementsInterface(field.getType(), List.class)) {
// we can expect more than one child object here
List<?> children;
Class<?> childObjClass = ReflectionUtils.getParameterizedClass(field);
if (jcrFileNode.lazy()) {
// lazy loading
children = ProxyFactory.createFileNodeListProxy(childObjClass, obj, fileContainer.getPath(), node.getSession(), mapper, depth, nodeFilter, jcrFileNode);
} else {
// eager loading
children = getFileList(childObjClass, fileContainer, obj, jcrFileNode, depth, nodeFilter, mapper);
}
field.set(obj, children);
} else if (ReflectionUtils.implementsInterface(field.getType(), Map.class)) {
// dynamic map of child nodes
// lazy loading is applied to each value in the Map
field.set(obj, getFileMap(field, fileContainer, jcrFileNode, obj, depth, nodeFilter, mapper));
} else {
// instantiate the field class
if (fileContainer.hasNodes()) {
if (jcrFileNode.lazy()) {
// lazy loading
field.set(obj, ProxyFactory.createFileNodeProxy(field.getType(), obj, fileContainer.getPath(), node.getSession(), mapper, depth, nodeFilter, jcrFileNode));
} else {
// eager loading
field.set(obj, getSingleFile(field.getType(), fileContainer, obj, jcrFileNode, depth, nodeFilter, mapper));
}
}
}
}
}
示例11: getFilesFromNode
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
void getFilesFromNode(Field field, Node node, Object obj, int depth, NodeFilter nodeFilter, Mapper mapper) throws ClassNotFoundException, InstantiationException, RepositoryException, IllegalAccessException, IOException {
String nodeName = getNodeName(field);
JcrFileNode jcrFileNode = mapper.getJcrom().getAnnotationReader().getAnnotation(field, JcrFileNode.class);
if (node.hasNode(nodeName) && nodeFilter.isIncluded(field.getName(), depth)) {
// file nodes are always stored inside a folder node
Node fileContainer = node.getNode(nodeName);
if (isList(getType(field, obj))) {
// we can expect more than one child object here
List<?> children;
Class<?> childObjClass = ReflectionUtils.getParameterizedClass(field);
if (jcrFileNode.lazy()) {
// lazy loading
children = ProxyFactory.createFileNodeListProxy(childObjClass, obj, fileContainer.getPath(), node.getSession(), mapper, depth, nodeFilter, jcrFileNode);
} else {
// eager loading
children = getFileList(childObjClass, fileContainer, obj, jcrFileNode, depth, nodeFilter, mapper);
}
setObject(field, obj, children);
} else if (isMap(field)) {
// dynamic map of child nodes
// lazy loading is applied to each value in the Map
setObject(field, obj, getFileMap(field, fileContainer, jcrFileNode, obj, depth, nodeFilter, mapper));
} else {
// instantiate the field class
if (fileContainer.hasNodes()) {
Object file = null;
Class type = getType(field, obj);
if (jcrFileNode.lazy()) {
// lazy loading
file = ProxyFactory.createFileNodeProxy(type, obj, fileContainer.getPath(), node.getSession(), mapper, depth, nodeFilter, jcrFileNode);
} else {
// eager loading
file = getSingleFile(type, fileContainer, obj, jcrFileNode, depth, nodeFilter, mapper);
}
setObject(field, obj, file);
}
}
}
}
示例12: getChildContainerNodePaths
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
List<String> getChildContainerNodePaths(Object childObject, Object parentObject, Node parentNode) throws IllegalAccessException, RepositoryException {
Class<?> type = childObject.getClass();
String childNodeName = mapper.getNodeName(childObject);
List<String> containers = new ArrayList<String>();
List<String> children = new ArrayList<String>();
for (Field field : ReflectionUtils.getDeclaredAndInheritedFields(parentObject.getClass(), false)) {
field.setAccessible(true);
if (mapper.getJcrom().getAnnotationReader().isAnnotationPresent(field, JcrChildNode.class)) {
Class<?> childObjClass;
if (isList(field)) {
childObjClass = ReflectionUtils.getParameterizedClass(field);
} else if (isMap(field)) {
childObjClass = ReflectionUtils.getParameterizedClass(field, 1);
} else {
childObjClass = field.getType();
}
if (childObjClass.isAssignableFrom(type)) {
JcrChildNode jcrChildNode = mapper.getJcrom().getAnnotationReader().getAnnotation(field, JcrChildNode.class);
String nodeName = getNodeName(field);
if (jcrChildNode.createContainerNode()) {
if (!parentNode.hasNode(nodeName)) {
throw new IllegalAccessException("The child container node not found with name '" + nodeName + "' from parent node '" + parentNode.getPath() + "'");
}
Node n = parentNode.getNode(nodeName);
containers.add(n.getPath());
} else {
children.add(nodeName);
}
}
}
}
// Check if there is child objects or the childNodeName is equal to one of the object names in the objects which is not creating a container node
if (containers.isEmpty() && !children.contains(childNodeName)) {
throw new IllegalAccessException("Child object not found with name '" + childNodeName + "' and type '" + type + "' from parent object '" + parentObject.getClass() + "'");
}
return containers;
}
示例13: mapPropertyToField
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
boolean mapPropertyToField(Object obj, Field field, Node node, int depth, NodeFilter nodeFilter) throws RepositoryException, IllegalAccessException,
IOException
{
String name = getPropertyName(field);
boolean nameIsARelativePath = name.contains("/");
if(nameIsARelativePath)
{
int positionPathPropertyDelimiter = name.lastIndexOf("/");
String relativePath = name.substring(0, positionPathPropertyDelimiter);
if(node.hasNode(relativePath))
{
node = node.getNode(relativePath);
name = name.substring(positionPathPropertyDelimiter + 1);
}
}
if (nodeFilter == null || nodeFilter.isIncluded(NodeFilter.PROPERTY_PREFIX + field.getName(), node, depth))
{
if (ReflectionUtils.implementsInterface(field.getType(), Map.class))
{
// 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);
}
}
Object defaultValue = getDefaultValue(field);
if (field.get(obj) == null && !JcrProperty.DEFAULT_VALUE.equals(defaultValue))
{
try
{
field.set(obj, defaultValue);
}
catch (Exception e)
{
LOG.error("Error while mapping default value to field.", e);
}
}
boolean propertyRequired = getPropertyRequired(field);
return !propertyRequired || (propertyRequired && field.get(obj) != null);
}
示例14: getChildContainerNodePaths
import org.jcrom.util.ReflectionUtils; //导入方法依赖的package包/类
List<String> getChildContainerNodePaths(Object childObject, Object parentObject, Node parentNode) throws IllegalAccessException, RepositoryException
{
Class<?> type = childObject.getClass();
String childNodeName = mapper.getNodeName(childObject);
List<String> containers = new ArrayList<String>();
List<String> children = new ArrayList<String>();
for (Field field : ReflectionUtils.getDeclaredAndInheritedFields(parentObject.getClass(), false))
{
field.setAccessible(true);
if (mapper.getJcrom().getAnnotationReader().isAnnotationPresent(field, JcrChildNode.class))
{
Class<?> childObjClass;
if (ReflectionUtils.implementsInterface(field.getType(), List.class))
{
childObjClass = ReflectionUtils.getParameterizedClass(field);
}
else if (ReflectionUtils.implementsInterface(field.getType(), Map.class))
{
childObjClass = ReflectionUtils.getParameterizedClass(field, 1);
}
else
{
childObjClass = field.getType();
}
if (childObjClass.isAssignableFrom(type))
{
JcrChildNode jcrChildNode = mapper.getJcrom().getAnnotationReader().getAnnotation(field, JcrChildNode.class);
String nodeName = getNodeName(field);
if (jcrChildNode.createContainerNode())
{
if (!parentNode.hasNode(nodeName))
{
throw new IllegalAccessException("The child container node not found with name '" + nodeName + "' from parent node '"
+ parentNode.getPath() + "'");
}
Node n = parentNode.getNode(nodeName);
containers.add(n.getPath());
}
else
{
children.add(nodeName);
}
}
}
}
// Check if there is child objects or the childNodeName is equal to one of the object names in the objects which is not creating a container node
if (containers.isEmpty() && !children.contains(childNodeName))
{
throw new IllegalAccessException("Child object not found with name '" + childNodeName + "' and type '" + type + "' from parent object '"
+ parentObject.getClass() + "'");
}
return containers;
}