📄 elementdescriptor.java
字号:
break;
}
if (descriptorWithNullName == null && elementName == null) {
descriptorWithNullName = elementDescriptors[i];
}
}
if (elementDescriptor == null) {
elementDescriptor = descriptorWithNullName;
}
return elementDescriptor;
}
/**
* Sets the descriptors for the child element of the element this describes.
* Also sets the child content descriptors for this element
*
* @param elementDescriptors the <code>ElementDescriptor</code>s of the element
* that this describes
*/
public void setElementDescriptors(ElementDescriptor[] elementDescriptors) {
this.elementDescriptors = elementDescriptors;
this.elementList = null;
setContentDescriptors( elementDescriptors );
}
/**
* Adds a descriptor for child content.
*
* @param descriptor the <code>Descriptor</code> describing the child content to add
* @since 0.5
*/
public void addContentDescriptor(Descriptor descriptor) {
if ( contentList == null ) {
contentList = new ArrayList();
}
getContentList().add( descriptor );
contentDescriptors = null;
}
/**
* Returns descriptors for the child content of the element this describes.
* @return the <code>Descriptor</code> describing the child elements
* of the element that this <code>ElementDescriptor</code> describes
* @since 0.5
*/
public Descriptor[] getContentDescriptors() {
if ( contentDescriptors == null ) {
if ( contentList == null ) {
contentDescriptors = new Descriptor[0];
} else {
contentDescriptors = new Descriptor[ contentList.size() ];
contentList.toArray( contentDescriptors );
// allow GC of List when initialized
contentList = null;
}
}
return contentDescriptors;
}
/**
* <p>Gets the primary descriptor for body text of this element.
* Betwixt collects all body text for any element together.
* This makes it rounds tripping difficult for beans that write more than one
* mixed content property.
* </p><p>
* The algorithm used in the default implementation is that the first TextDescriptor
* found amongst the descriptors is returned.
*
* @return the primary descriptor or null if this element has no mixed body content
* @since 0.5
*/
public TextDescriptor getPrimaryBodyTextDescriptor() {
// todo: this probably isn't the most efficent algorithm
// but should avoid premature optimization
Descriptor[] descriptors = getContentDescriptors();
for (int i=0, size=descriptors.length; i<size; i++) {
if (descriptors[i] instanceof TextDescriptor) {
return (TextDescriptor) descriptors[i];
}
}
// if we haven't found anything, return null.
return null;
}
/**
* Sets the descriptors for the child content of the element this describes.
* @param contentDescriptors the <code>Descriptor</code>s of the element
* that this describes
* @since 0.5
*/
public void setContentDescriptors(Descriptor[] contentDescriptors) {
this.contentDescriptors = contentDescriptors;
this.contentList = null;
}
/**
* Returns the expression used to evaluate the new context of this element.
* @return the expression used to evaluate the new context of this element
*/
public Expression getContextExpression() {
return contextExpression;
}
/**
* Sets the expression used to evaluate the new context of this element
* @param contextExpression the expression used to evaluate the new context of this element
*/
public void setContextExpression(Expression contextExpression) {
this.contextExpression = contextExpression;
}
/**
* Returns true if this element refers to a primitive type property
* @return whether this element refers to a primitive type (or property of a parent object)
* @deprecated 0.6 moved to a declarative style of descriptors where the alrogithmic should
* be done during introspection
*/
public boolean isPrimitiveType() {
return primitiveType;
}
/**
* Sets whether this element refers to a primitive type (or property of a parent object)
* @param primitiveType true if this element refers to a primitive type
* @deprecated 0.6 moved to a declarative style of descriptors where the alrogithmic should
* be done during introspection
*/
public void setPrimitiveType(boolean primitiveType) {
this.primitiveType = primitiveType;
}
// Implementation methods
//-------------------------------------------------------------------------
/**
* Lazily creates the mutable List.
* This nullifies the attributeDescriptors array so that
* as items are added to the list the Array is ignored until it is
* explicitly asked for.
*
* @return list of <code>AttributeDescriptors</code>'s describing the attributes
* of the element that this <code>ElementDescriptor</code> describes
*/
protected List getAttributeList() {
if ( attributeList == null ) {
if ( attributeDescriptors != null ) {
int size = attributeDescriptors.length;
attributeList = new ArrayList( size );
for ( int i = 0; i < size; i++ ) {
attributeList.add( attributeDescriptors[i] );
}
// force lazy recreation later
attributeDescriptors = null;
} else {
attributeList = new ArrayList();
}
}
return attributeList;
}
/**
* Lazily creates the mutable List of child elements.
* This nullifies the elementDescriptors array so that
* as items are added to the list the Array is ignored until it is
* explicitly asked for.
*
* @return list of <code>ElementDescriptor</code>'s describe the child elements of
* the element that this <code>ElementDescriptor</code> describes
*/
protected List getElementList() {
if ( elementList == null ) {
if ( elementDescriptors != null ) {
int size = elementDescriptors.length;
elementList = new ArrayList( size );
for ( int i = 0; i < size; i++ ) {
elementList.add( elementDescriptors[i] );
}
// force lazy recreation later
elementDescriptors = null;
} else {
elementList = new ArrayList();
}
}
return elementList;
}
/**
* Lazily creates the mutable List of child content descriptors.
* This nullifies the contentDescriptors array so that
* as items are added to the list the Array is ignored until it is
* explicitly asked for.
*
* @return list of <code>Descriptor</code>'s describe the child content of
* the element that this <code>Descriptor</code> describes
* @since 0.5
*/
protected List getContentList() {
if ( contentList == null ) {
if ( contentDescriptors != null ) {
int size = contentDescriptors.length;
contentList = new ArrayList( size );
for ( int i = 0; i < size; i++ ) {
contentList.add( contentDescriptors[i] );
}
// force lazy recreation later
contentDescriptors = null;
} else {
contentList = new ArrayList();
}
}
return contentList;
}
/**
* Gets the class which should be used for instantiation.
* @return the class which should be used for instantiation of beans
* mapped from this element, null if the standard class should be used
*/
public Class getImplementationClass() {
return implementationClass;
}
/**
* Sets the class which should be used for instantiation.
* @param implementationClass the class which should be used for instantiation
* or null to use the mapped type
* @since 0.5
*/
public void setImplementationClass(Class implementationClass) {
this.implementationClass = implementationClass;
}
/**
* TODO is this implementation correct?
* maybe this method is unnecessary
*/
public boolean isCollective() {
boolean result = false;
Class type = getPropertyType();
if (type != null) {
result = XMLIntrospectorHelper.isLoopType(type);
}
return result;
}
/**
* @todo is this really a good design?
*/
public ElementDescriptor findParent(ElementDescriptor elementDescriptor) {
ElementDescriptor result = null;
ElementDescriptor[] elementDescriptors = getElementDescriptors();
for (int i=0, size=elementDescriptors.length; i<size; i++) {
if (elementDescriptors[i].equals(elementDescriptor)) {
result = this;
break;
}
else
{
result = elementDescriptors[i].findParent(elementDescriptor);
if (result != null) {
break;
}
}
}
return result;
}
/**
* Returns something useful for logging.
*
* @return a string useful for logging
*/
public String toString() {
return
"ElementDescriptor[qname=" + getQualifiedName() + ",pname=" + getPropertyName()
+ ",class=" + getPropertyType() + ",singular=" + getSingularPropertyType()
+ ",updater=" + getUpdater() + ",wrap=" + isWrapCollectionsInElement() + "]";
}
/**
* Is this decriptor hollow?
* A hollow descriptor is one which gives only the class that the subgraph
* is mapped to rather than describing the entire subgraph.
* A new <code>XMLBeanInfo</code> should be introspected
* and that used to describe the subgraph.
* A hollow descriptor should not have any child descriptors.
* TODO: consider whether a subclass would be better
* @return true if this is hollow
*/
public boolean isHollow() {
return isHollow;
}
/**
* Sets whether this descriptor is hollow.
* A hollow descriptor is one which gives only the class that the subgraph
* is mapped to rather than describing the entire subgraph.
* A new <code>XMLBeanInfo</code> should be introspected
* and that used to describe the subgraph.
* A hollow descriptor should not have any child descriptors.
* TODO: consider whether a subclass would be better
* @param true if this is hollow
*/
public void setHollow(boolean isHollow) {
this.isHollow = isHollow;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -