Fields Summary |
---|
private static final Hashtable | EMPTY_HASHTABLEEmpty Hashtable. |
private String | elementTagName of the element to configure. |
private List | childrenList of child element wrappers. |
private transient Object | wrappedObjectThe element to configure. It is only used during
maybeConfigure. |
private transient IntrospectionHelper.Creator | creatorthe creator used to make the wrapped object |
private transient AttributeList | attributesXML attributes for the element. |
private List | attributeNamesAttribute names and values. While the XML spec doesn't require
preserving the order ( AFAIK ), some ant tests do rely on the
exact order. The following code is copied from AttributeImpl.
We could also just use SAX2 Attributes and convert to SAX1 ( DOM
attribute Nodes can also be stored in SAX2 Attributes )
XXX under JDK 1.4 you can just use a LinkedHashMap for this purpose -jglick
The only exception to this order is the treatment of
refid. A number of datatypes check if refid is set
when other attributes are set. This check will not
work if the build script has the other attribute before
the "refid" attribute, so now (ANT 1.7) the refid
attribute will be processed first. |
private Map | attributeMapMap of attribute names to values |
private StringBuffer | charactersText appearing within the element. |
private boolean | proxyConfiguredIndicates if the wrapped object has been configured |
private String | polyTypethe polymorphic type |
private String | idthe "id" of this Element if it has one |
Methods Summary |
---|
public synchronized void | addChild(org.apache.tools.ant.RuntimeConfigurable child)Adds a child element to the wrapped element.
children = (children == null) ? new ArrayList() : children;
children.add(child);
|
public synchronized void | addText(java.lang.String data)Adds characters from #PCDATA areas to the wrapped element.
if (data.length() == 0) {
return;
}
characters = (characters == null)
? new StringBuffer(data) : characters.append(data);
|
public synchronized void | addText(char[] buf, int start, int count)Adds characters from #PCDATA areas to the wrapped element.
if (count == 0) {
return;
}
characters = ((characters == null)
? new StringBuffer(count) : characters).append(buf, start, count);
|
public void | applyPreSet(org.apache.tools.ant.RuntimeConfigurable r)Apply presets, attributes and text are set if not currently set.
Nested elements are prepended.
// Attributes
if (r.attributeMap != null) {
for (Iterator i = r.attributeMap.keySet().iterator(); i.hasNext();) {
String name = (String) i.next();
if (attributeMap == null || attributeMap.get(name) == null) {
setAttribute(name, (String) r.attributeMap.get(name));
}
}
}
// poly type
polyType = (polyType == null) ? r.polyType : polyType;
// Children (this is a shadow of UnknownElement#children)
if (r.children != null) {
List newChildren = new ArrayList();
newChildren.addAll(r.children);
if (children != null) {
newChildren.addAll(children);
}
children = newChildren;
}
// Text
if (r.characters != null) {
if (characters == null
|| characters.toString().trim().length() == 0) {
characters = new StringBuffer(r.characters.toString());
}
}
|
public synchronized java.util.Hashtable | getAttributeMap()Return the attribute map.
return (attributeMap == null)
? EMPTY_HASHTABLE : new Hashtable(attributeMap);
|
public synchronized org.xml.sax.AttributeList | getAttributes()Returns the list of attributes for the wrapped element.
return attributes;
|
synchronized org.apache.tools.ant.RuntimeConfigurable | getChild(int index)Returns the child wrapper at the specified position within the list.
return (RuntimeConfigurable) children.get(index);
|
public synchronized java.util.Enumeration | getChildren()Returns an enumeration of all child wrappers.
return (children == null) ? new CollectionUtils.EmptyEnumeration()
: Collections.enumeration(children);
|
public synchronized java.lang.String | getElementTag()Returns the tag name of the wrapped element.
return elementTag;
|
public synchronized java.lang.String | getId()Returns the id for this element.
return id;
|
public synchronized java.lang.String | getPolyType()Get the polymorphic type for this element.
return polyType;
|
public synchronized java.lang.Object | getProxy()Get the object for which this RuntimeConfigurable holds the configuration
information.
return wrappedObject;
|
public synchronized java.lang.StringBuffer | getText()Get the text content of this element. Various text chunks are
concatenated, there is no way ( currently ) of keeping track of
multiple fragments.
return (characters == null) ? new StringBuffer(0) : characters;
|
public void | maybeConfigure(Project p)Configures the wrapped element and all its children.
The attributes and text for the wrapped element are configured,
and then each child is configured and added. Each time the
wrapper is configured, the attributes and text for it are
reset.
If the element has an id attribute, a reference
is added to the project as well.
maybeConfigure(p, true);
|
public synchronized void | maybeConfigure(Project p, boolean configureChildren)Configures the wrapped element. The attributes and text for
the wrapped element are configured. Each time the wrapper is
configured, the attributes and text for it are reset.
If the element has an id attribute, a reference
is added to the project as well.
if (proxyConfigured) {
return;
}
// Configure the object
Object target = (wrappedObject instanceof TypeAdapter)
? ((TypeAdapter) wrappedObject).getProxy() : wrappedObject;
IntrospectionHelper ih =
IntrospectionHelper.getHelper(p, target.getClass());
if (attributeNames != null) {
for (int i = 0; i < attributeNames.size(); i++) {
String name = (String) attributeNames.get(i);
String value = (String) attributeMap.get(name);
// reflect these into the target
value = p.replaceProperties(value);
try {
ih.setAttribute(p, target, name, value);
} catch (UnsupportedAttributeException be) {
// id attribute must be set externally
if (name.equals("id")) {
// Do nothing
} else if (getElementTag() == null) {
throw be;
} else {
throw new BuildException(
getElementTag() + " doesn't support the \""
+ be.getAttribute() + "\" attribute", be);
}
} catch (BuildException be) {
if (name.equals("id")) {
// Assume that this is an not supported attribute type
// thrown for example by a dymanic attribute task
// Do nothing
} else {
throw be;
}
}
}
}
if (characters != null) {
ProjectHelper.addText(p, wrappedObject, characters.substring(0));
}
if (id != null) {
p.addReference(id, wrappedObject);
}
proxyConfigured = true;
|
public void | reconfigure(Project p)Reconfigure the element, even if it has already been configured.
proxyConfigured = false;
maybeConfigure(p);
|
public synchronized void | removeAttribute(java.lang.String name)Delete an attribute. Not for the faint of heart.
attributeNames.remove(name);
attributeMap.remove(name);
|
public synchronized void | setAttribute(java.lang.String name, java.lang.String value)Set an attribute to a given value.
if (name.equalsIgnoreCase(ProjectHelper.ANT_TYPE)) {
this.polyType = value;
} else {
if (attributeNames == null) {
attributeNames = new ArrayList();
attributeMap = new HashMap();
}
if (name.toLowerCase(Locale.US).equals("refid")) {
attributeNames.add(0, name);
} else {
attributeNames.add(name);
}
attributeMap.put(name, value);
if (name.equals("id")) {
this.id = value;
}
}
|
public synchronized void | setAttributes(org.xml.sax.AttributeList attributes)Sets the attributes for the wrapped element.
this.attributes = new AttributeListImpl(attributes);
for (int i = 0; i < attributes.getLength(); i++) {
setAttribute(attributes.getName(i), attributes.getValue(i));
}
|
synchronized void | setCreator(IntrospectionHelper.Creator creator)Sets the creator of the element to be configured
used to store the element in the parent.
this.creator = creator;
|
public synchronized void | setElementTag(java.lang.String elementTag)Set the element tag.
this.elementTag = elementTag;
|
public synchronized void | setPolyType(java.lang.String polyType)Set the polymorphic type for this element.
this.polyType = polyType;
|
public synchronized void | setProxy(java.lang.Object proxy)Sets the element to configure.
wrappedObject = proxy;
proxyConfigured = false;
|