📄 beanproperty.java
字号:
descriptor
= createDescriptorForCollective( configuration, propertyUpdater, propertyExpression );
}
} else {
if (log.isTraceEnabled()) {
log.trace( "Standard property: " + getPropertyName());
}
descriptor =
createDescriptorForStandard(
propertyExpression,
propertyUpdater,
configuration);
}
if (log.isTraceEnabled()) {
log.trace( "Created descriptor:" );
log.trace( descriptor );
}
return descriptor;
}
/**
* Configures descriptor (in the standard way).
* This sets the common properties.
*
* @param propertyName the name of the property mapped to the Descriptor, not null
* @param propertyType the type of the property mapped to the Descriptor, not null
* @param descriptor Descriptor to map, not null
* @param configuration IntrospectionConfiguration, not null
*/
private void configureDescriptor(
NodeDescriptor descriptor,
IntrospectionConfiguration configuration) {
NameMapper nameMapper = configuration.getElementNameMapper();
if (descriptor instanceof AttributeDescriptor) {
// we want to use the attributemapper only when it is an attribute..
nameMapper = configuration.getAttributeNameMapper();
}
descriptor.setLocalName( nameMapper.mapTypeToElementName( propertyName ));
descriptor.setPropertyName( getPropertyName() );
descriptor.setPropertyType( getPropertyType() );
}
/**
* Creates an <code>ElementDescriptor</code> for a standard property
* @param propertyExpression
* @param propertyUpdater
* @return
*/
private ElementDescriptor createDescriptorForStandard(
Expression propertyExpression,
Updater propertyUpdater,
IntrospectionConfiguration configuration) {
ElementDescriptor result;
ElementDescriptor elementDescriptor = new ElementDescriptor();
elementDescriptor.setContextExpression( propertyExpression );
if ( propertyUpdater != null ) {
elementDescriptor.setUpdater( propertyUpdater );
}
elementDescriptor.setHollow(true);
result = elementDescriptor;
configureDescriptor(result, configuration);
return result;
}
/**
* Creates an ElementDescriptor for an <code>Map</code> type property
* @param configuration
* @param propertyExpression
* @return
*/
private ElementDescriptor createDescriptorForMap(
IntrospectionConfiguration configuration,
Expression propertyExpression) {
//TODO: need to clean the element descriptors so that the wrappers are plain
ElementDescriptor result;
ElementDescriptor entryDescriptor = new ElementDescriptor();
entryDescriptor.setContextExpression(
new IteratorExpression( propertyExpression )
);
entryDescriptor.setLocalName( "entry" );
entryDescriptor.setPropertyName( getPropertyName() );
entryDescriptor.setPropertyType( getPropertyType() );
// add elements for reading
ElementDescriptor keyDescriptor = new ElementDescriptor( "key" );
keyDescriptor.setHollow( true );
entryDescriptor.addElementDescriptor( keyDescriptor );
ElementDescriptor valueDescriptor = new ElementDescriptor( "value" );
valueDescriptor.setHollow( true );
entryDescriptor.addElementDescriptor( valueDescriptor );
if ( configuration.isWrapCollectionsInElement() ) {
ElementDescriptor wrappingDescriptor = new ElementDescriptor();
wrappingDescriptor.setElementDescriptors( new ElementDescriptor[] { entryDescriptor } );
NameMapper nameMapper = configuration.getElementNameMapper();
wrappingDescriptor.setLocalName( nameMapper.mapTypeToElementName( propertyName ));
result = wrappingDescriptor;
} else {
result = entryDescriptor;
}
return result;
}
/**
* Creates an <code>ElementDescriptor</code> for a collective type property
* @param configuration
* @param propertyUpdater, <code>Updater</code> for the property, possibly null
* @param propertyExpression
* @return
*/
private ElementDescriptor createDescriptorForCollective(
IntrospectionConfiguration configuration,
Updater propertyUpdater,
Expression propertyExpression) {
ElementDescriptor result;
ElementDescriptor loopDescriptor = new ElementDescriptor();
loopDescriptor.setContextExpression(
new IteratorExpression( propertyExpression )
);
loopDescriptor.setPropertyName(getPropertyName());
loopDescriptor.setPropertyType(getPropertyType());
loopDescriptor.setHollow(true);
// set the property updater (if it exists)
// may be overridden later by the adder
loopDescriptor.setUpdater(propertyUpdater);
if ( configuration.isWrapCollectionsInElement() ) {
// create wrapping desctiptor
ElementDescriptor wrappingDescriptor = new ElementDescriptor();
wrappingDescriptor.setElementDescriptors( new ElementDescriptor[] { loopDescriptor } );
wrappingDescriptor.setLocalName(
configuration.getElementNameMapper().mapTypeToElementName( propertyName ));
result = wrappingDescriptor;
} else {
// unwrapped Descriptor
result = loopDescriptor;
}
return result;
}
/**
* Creates a NodeDescriptor for a primitive type node
* @param configuration
* @param name
* @param log
* @param propertyExpression
* @param propertyUpdater
* @return
*/
private NodeDescriptor createDescriptorForPrimitive(
IntrospectionConfiguration configuration,
Expression propertyExpression,
Updater propertyUpdater) {
Log log = configuration.getIntrospectionLog();
NodeDescriptor descriptor;
if (log.isTraceEnabled()) {
log.trace( "Primitive type: " + getPropertyName());
}
SimpleTypeMapper.Binding binding
= configuration.getSimpleTypeMapper().bind(
propertyName,
propertyType,
configuration);
if ( SimpleTypeMapper.Binding.ATTRIBUTE.equals( binding )) {
if (log.isTraceEnabled()) {
log.trace( "Adding property as attribute: " + getPropertyName() );
}
descriptor = new AttributeDescriptor();
} else {
if (log.isTraceEnabled()) {
log.trace( "Adding property as element: " + getPropertyName() );
}
descriptor = new ElementDescriptor();
}
descriptor.setTextExpression( propertyExpression );
if ( propertyUpdater != null ) {
descriptor.setUpdater( propertyUpdater );
}
configureDescriptor(descriptor, configuration);
return descriptor;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -