Wrapper class that holds the attributes of an element, its children, and
any text within it. It then takes care of configuring that element at
runtime.
| Method from org.apache.tools.ant.RuntimeConfigurable Detail: |
public synchronized void addChild(RuntimeConfigurable child) {
children = (children == null) ? new ArrayList() : children;
children.add(child);
}
Adds a child element to the wrapped element. |
public synchronized void addText(String data) {
if (data.length() == 0) {
return;
}
characters = (characters == null)
? new StringBuffer(data) : characters.append(data);
}
Adds characters from #PCDATA areas to the wrapped element. |
public synchronized void addText(char[] buf,
int start,
int count) {
if (count == 0) {
return;
}
characters = ((characters == null)
? new StringBuffer(count) : characters).append(buf, start, count);
}
Adds characters from #PCDATA areas to the wrapped element. |
public void applyPreSet(RuntimeConfigurable r) {
// 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());
}
}
}
Apply presets, attributes and text are set if not currently set.
Nested elements are prepended. |
public synchronized Hashtable getAttributeMap() {
return (attributeMap == null)
? EMPTY_HASHTABLE : new Hashtable(attributeMap);
}
Return the attribute map. |
public synchronized AttributeList getAttributes() {
return attributes;
} Deprecated! Deprecated - since Ant 1.6 in favor of #getAttributeMap .
Returns the list of attributes for the wrapped element. |
synchronized RuntimeConfigurable getChild(int index) {
return (RuntimeConfigurable) children.get(index);
}
Returns the child wrapper at the specified position within the list. |
public synchronized Enumeration getChildren() {
return (children == null) ? new CollectionUtils.EmptyEnumeration()
: Collections.enumeration(children);
}
Returns an enumeration of all child wrappers. |
public synchronized String getElementTag() {
return elementTag;
}
Returns the tag name of the wrapped element. |
public synchronized String getId() {
return id;
}
Returns the id for this element. |
public synchronized String getPolyType() {
return polyType;
}
Get the polymorphic type for this element. |
public synchronized Object getProxy() {
return wrappedObject;
}
Get the object for which this RuntimeConfigurable holds the configuration
information. |
public synchronized StringBuffer getText() {
return (characters == null) ? new StringBuffer(0) : characters;
}
Get the text content of this element. Various text chunks are
concatenated, there is no way ( currently ) of keeping track of
multiple fragments. |
public void maybeConfigure(Project p) throws BuildException {
maybeConfigure(p, true);
}
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. |
public synchronized void maybeConfigure(Project p,
boolean configureChildren) throws BuildException {
if (proxyConfigured) {
return;
}
// Configure the object
Object target = (wrappedObject instanceof TypeAdapter)
? ((TypeAdapter) wrappedObject).getProxy() : wrappedObject;
IntrospectionHelper ih =
IntrospectionHelper.getHelper(p, target.getClass());
if (attributeMap != null) {
for (Iterator iter = attributeMap.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String name = (String) entry.getKey();
String value = (String) entry.getValue();
// reflect these into the target
Object attrValue = PropertyHelper.getPropertyHelper(p).parseProperties(value);
try {
ih.setAttribute(p, target, name, attrValue);
} 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;
}
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. |
public void reconfigure(Project p) {
proxyConfigured = false;
maybeConfigure(p);
}
Reconfigure the element, even if it has already been configured. |
public synchronized void removeAttribute(String name) {
attributeMap.remove(name);
}
Delete an attribute. Not for the faint of heart. |
public synchronized void setAttribute(String name,
String value) {
if (name.equalsIgnoreCase(ProjectHelper.ANT_TYPE)) {
this.polyType = value;
} else {
if (attributeMap == null) {
attributeMap = new LinkedHashMap();
}
if (name.equalsIgnoreCase("refid") && !attributeMap.isEmpty()) {
LinkedHashMap newAttributeMap = new LinkedHashMap();
newAttributeMap.put(name, value);
newAttributeMap.putAll(attributeMap);
attributeMap = newAttributeMap;
} else {
attributeMap.put(name, value);
}
if (name.equals("id")) {
this.id = value;
}
}
}
Set an attribute to a given value. |
public synchronized void setAttributes(AttributeList attributes) {
this.attributes = new AttributeListImpl(attributes);
for (int i = 0; i < attributes.getLength(); i++) {
setAttribute(attributes.getName(i), attributes.getValue(i));
}
} Deprecated! since - 1.6.x.
Sets the attributes for the wrapped element. |
synchronized void setCreator(Creator creator) {
this.creator = creator;
}
Sets the creator of the element to be configured
used to store the element in the parent. |
public synchronized void setElementTag(String elementTag) {
this.elementTag = elementTag;
}
|
public synchronized void setPolyType(String polyType) {
this.polyType = polyType;
}
Set the polymorphic type for this element. |
public synchronized void setProxy(Object proxy) {
wrappedObject = proxy;
proxyConfigured = false;
}
Sets the element to configure. |