📄 xmlintrospector.java
字号:
List attributes,
List contents)
throws
IntrospectionException {
addProperty( propertyDescriptor, elements, attributes, contents);
}
/**
* Process a property.
* Go through and work out whether it's a loop property, a primitive or a standard.
* The class property is ignored.
*
* @param propertyDescriptor the PropertyDescriptor to process
* @param elements ElementDescriptor list to which elements will be added
* @param attributes AttributeDescriptor list to which attributes will be added
* @param contents Descriptor list to which mixed content will be added
* @throws IntrospectionException if the bean introspection fails
* @deprecated 0.5 use {@link #addProperty(BeanProperty, List, List, List)} instead
*/
protected void addProperty(
PropertyDescriptor propertyDescriptor,
List elements,
List attributes,
List contents)
throws
IntrospectionException {
addProperty(new BeanProperty( propertyDescriptor ), elements, attributes, contents);
}
/**
* Process a property.
* Go through and work out whether it's a loop property, a primitive or a standard.
* The class property is ignored.
*
* @param beanProperty the bean property to process
* @param elements ElementDescriptor list to which elements will be added
* @param attributes AttributeDescriptor list to which attributes will be added
* @param contents Descriptor list to which mixed content will be added
* @since 0.5
*/
protected void addProperty(
BeanProperty beanProperty,
List elements,
List attributes,
List contents) {
Descriptor nodeDescriptor = createXMLDescriptor(beanProperty);
if (nodeDescriptor == null) {
return;
}
if (nodeDescriptor instanceof ElementDescriptor) {
elements.add(nodeDescriptor);
} else if (nodeDescriptor instanceof AttributeDescriptor) {
attributes.add(nodeDescriptor);
} else {
contents.add(nodeDescriptor);
}
}
/**
* Loop through properties and process each one
*
* @param beanInfo the BeanInfo whose properties will be processed
* @param elements ElementDescriptor list to which elements will be added
* @param attributes AttributeDescriptor list to which attributes will be added
* @throws IntrospectionException if the bean introspection fails
* @deprecated 0.5 this method does not support mixed content.
* Use {@link #addProperties(BeanInfo, List, List, List)} instead.
*/
protected void addProperties(
BeanInfo beanInfo,
List elements,
List attributes)
throws
IntrospectionException {
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
if ( descriptors != null ) {
for ( int i = 0, size = descriptors.length; i < size; i++ ) {
addProperty(beanInfo, descriptors[i], elements, attributes);
}
}
if (getLog().isTraceEnabled()) {
getLog().trace(elements);
getLog().trace(attributes);
}
}
/**
* Process a property.
* Go through and work out whether it's a loop property, a primitive or a standard.
* The class property is ignored.
*
* @param beanInfo the BeanInfo whose property is being processed
* @param propertyDescriptor the PropertyDescriptor to process
* @param elements ElementDescriptor list to which elements will be added
* @param attributes AttributeDescriptor list to which attributes will be added
* @throws IntrospectionException if the bean introspection fails
* @deprecated 0.5 this method does not support mixed content.
* Use {@link #addProperty(BeanInfo, PropertyDescriptor, List, List, List)} instead.
*/
protected void addProperty(
BeanInfo beanInfo,
PropertyDescriptor propertyDescriptor,
List elements,
List attributes)
throws
IntrospectionException {
NodeDescriptor nodeDescriptor = XMLIntrospectorHelper
.createDescriptor(propertyDescriptor,
isAttributesForPrimitives(),
this);
if (nodeDescriptor == null) {
return;
}
if (nodeDescriptor instanceof ElementDescriptor) {
elements.add(nodeDescriptor);
} else {
attributes.add(nodeDescriptor);
}
}
/**
* Factory method to create XMLBeanInfo instances
*
* @param beanInfo the BeanInfo from which the XMLBeanInfo will be created
* @return XMLBeanInfo describing the bean-xml mapping
*/
protected XMLBeanInfo createXMLBeanInfo( BeanInfo beanInfo ) {
XMLBeanInfo xmlBeanInfo = new XMLBeanInfo( beanInfo.getBeanDescriptor().getBeanClass() );
return xmlBeanInfo;
}
/**
* Is this class a loop?
*
* @param type the Class to test
* @return true if the type is a loop type
*/
public boolean isLoopType(Class type) {
return XMLIntrospectorHelper.isLoopType(type);
}
/**
* Is this class a primitive?
* TODO: this method will probably be deprecated when primitive types
* are subsumed into the simple type concept
* @param type the Class to test
* @return true for primitive types
*/
public boolean isPrimitiveType(Class type) {
TypeBindingStrategy.BindingType bindingType
= configuration.getTypeBindingStrategy().bindingType( type ) ;
boolean result = (bindingType.equals(TypeBindingStrategy.BindingType.PRIMITIVE));
return result;
}
/** Some type of pseudo-bean */
private abstract class BeanType {
/**
* Gets the name for this bean type
* @return the bean type name, not null
*/
public abstract String getBeanName();
/**
* Gets the type to be used by the associated element
* @return a Class that is the type not null
*/
public abstract Class getElementType();
/**
* Is this type a primitive?
* @return true if this type should be treated by betwixt as a primitive
*/
public abstract boolean isPrimitiveType();
/**
* is this type a map?
* @return true this should be treated as a map.
*/
public abstract boolean isMapType();
/**
* Is this type a loop?
* @return true if this should be treated as a loop
*/
public abstract boolean isLoopType();
/**
* Gets the properties associated with this bean.
* @return the BeanProperty's, not null
*/
public abstract BeanProperty[] getProperties();
/**
* Create string representation
* @return something useful for logging
*/
public String toString() {
return "Bean[name=" + getBeanName() + ", type=" + getElementType();
}
}
/** Supports standard Java Beans */
private class JavaBeanType extends BeanType {
/** Introspected bean */
private BeanInfo beanInfo;
/** Bean class */
private Class beanClass;
/** Bean name */
private String name;
/** Bean properties */
private BeanProperty[] properties;
/**
* Constructs a BeanType for a standard Java Bean
* @param beanInfo the BeanInfo describing the standard Java Bean, not null
*/
public JavaBeanType(BeanInfo beanInfo) {
this.beanInfo = beanInfo;
BeanDescriptor beanDescriptor = beanInfo.getBeanDescriptor();
beanClass = beanDescriptor.getBeanClass();
name = beanDescriptor.getName();
// Array's contain a bad character
if (beanClass.isArray()) {
// called all array's Array
name = "Array";
}
}
/** @see BeanType #getElementType */
public Class getElementType() {
return beanClass;
}
/** @see BeanType#getBeanName */
public String getBeanName() {
return name;
}
/** @see BeanType#isPrimitiveType */
public boolean isPrimitiveType() {
return XMLIntrospector.this.isPrimitiveType( beanClass );
}
/** @see BeanType#isLoopType */
public boolean isLoopType() {
return XMLIntrospectorHelper.isLoopType( beanClass );
}
/** @see BeanType#isMapType */
public boolean isMapType() {
return Map.class.isAssignableFrom( beanClass );
}
/** @see BeanType#getProperties */
public BeanProperty[] getProperties() {
// lazy creation
if ( properties == null ) {
ArrayList propertyDescriptors = new ArrayList();
// add base bean info
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
if ( descriptors != null ) {
for (int i=0, size=descriptors.length; i<size; i++) {
propertyDescriptors.add( descriptors[i] );
}
}
// add properties from additional bean infos
BeanInfo[] additionals = beanInfo.getAdditionalBeanInfo();
if ( additionals != null ) {
for ( int i=0, outerSize=additionals.length; i<outerSize; i++ ) {
BeanInfo additionalInfo = additionals[i];
descriptors = beanInfo.getPropertyDescriptors();
if ( descriptors != null ) {
for (int j=0, innerSize=descriptors.length; j<innerSize; j++) {
propertyDescriptors.add( descriptors[j] );
}
}
}
}
// what happens when size is zero?
properties = new BeanProperty[ propertyDescriptors.size() ];
int count = 0;
for ( Iterator it = propertyDescriptors.iterator(); it.hasNext(); count++) {
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) it.next();
properties[count] = new BeanProperty( propertyDescriptor );
}
}
return properties;
}
}
/** Implementation for DynaClasses */
private class DynaClassBeanType extends BeanType {
/** BeanType for this DynaClass */
private DynaClass dynaClass;
/** Properties extracted in constuctor */
private BeanProperty[] properties;
/**
* Constructs a BeanType for a DynaClass
* @param dynaClass not null
*/
public DynaClassBeanType(DynaClass dynaClass) {
this.dynaClass = dynaClass;
DynaProperty[] dynaProperties = dynaClass.getDynaProperties();
properties = new BeanProperty[dynaProperties.length];
for (int i=0, size=dynaProperties.length; i<size; i++) {
properties[i] = new BeanProperty(dynaProperties[i]);
}
}
/** @see BeanType#getBeanName */
public String getBeanName() {
return dynaClass.getName();
}
/** @see BeanType#getElementType */
public Class getElementType() {
return DynaClass.class;
}
/** @see BeanType#isPrimitiveType */
public boolean isPrimitiveType() {
return false;
}
/** @see BeanType#isMapType */
public boolean isMapType() {
return false;
}
/** @see BeanType#isLoopType */
public boolean isLoopType() {
return false;
}
/** @see BeanType#getProperties */
public BeanProperty[] getProperties() {
return properties;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -