use of org.w3c.dom.Element in project jmonkeyengine by jMonkeyEngine.
the class DOMOutputCapsule method write.
@Override
public void write(Savable object, String name, Savable defVal) throws IOException {
if (object == null) {
return;
}
if (object.equals(defVal)) {
return;
}
Element old = currentElement;
Element el = writtenSavables.get(object);
String className = null;
if (!object.getClass().getName().equals(name)) {
className = object.getClass().getName();
}
try {
doc.createElement(name);
} catch (DOMException e) {
// Ridiculous fallback behavior.
// Would be far better to throw than to totally disregard the
// specified "name" and write a class name instead!
// (Besides the fact we are clobbering the managed .getClassTag()).
name = "Object";
className = object.getClass().getName();
}
if (el != null) {
String refID = el.getAttribute("reference_ID");
if (refID.length() == 0) {
refID = object.getClass().getName() + "@" + object.hashCode();
el.setAttribute("reference_ID", refID);
}
el = appendElement(name);
el.setAttribute("ref", refID);
} else {
el = appendElement(name);
// jME3 NEW: Append version number(s)
int[] versions = SavableClassUtil.getSavableVersions(object.getClass());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < versions.length; i++) {
sb.append(versions[i]);
if (i != versions.length - 1) {
sb.append(", ");
}
}
el.setAttribute("savable_versions", sb.toString());
writtenSavables.put(object, el);
object.write(exporter);
}
if (className != null) {
el.setAttribute("class", className);
}
currentElement = old;
}
use of org.w3c.dom.Element in project jmonkeyengine by jMonkeyEngine.
the class DOMOutputCapsule method write.
@Override
public void write(double[][] value, String name, double[][] defVal) throws IOException {
if (value == null)
return;
if (Arrays.deepEquals(value, defVal))
return;
Element el = appendElement(name);
el.setAttribute("size", String.valueOf(value.length));
for (int i = 0; i < value.length; i++) {
double[] array = value[i];
write(array, "array_" + i, defVal == null ? null : defVal[i]);
}
currentElement = (Element) el.getParentNode();
}
use of org.w3c.dom.Element in project jmonkeyengine by jMonkeyEngine.
the class DOMOutputCapsule method write.
@Override
public void write(IntBuffer value, String name, IntBuffer defVal) throws IOException {
if (value == null) {
return;
}
if (value.equals(defVal)) {
return;
}
Element el = appendElement(name);
el.setAttribute("size", String.valueOf(value.limit()));
StringBuilder buf = new StringBuilder();
int pos = value.position();
value.rewind();
int ctr = 0;
while (value.hasRemaining()) {
ctr++;
buf.append(value.get());
buf.append(" ");
}
if (ctr != value.limit()) {
throw new IOException("'" + name + "' buffer contention resulted in write data consistency. " + ctr + " values written when should have written " + value.limit());
}
if (buf.length() > 0) {
//remove last space
buf.setLength(buf.length() - 1);
}
value.position(pos);
el.setAttribute(dataAttributeName, buf.toString());
currentElement = (Element) el.getParentNode();
}
use of org.w3c.dom.Element in project hadoop by apache.
the class QueueConfigurationParser method loadResource.
/**
* Method to load the resource file.
* generates the root.
*
* @param resourceInput InputStream that provides the XML to parse
* @return
* @throws ParserConfigurationException
* @throws SAXException
* @throws IOException
*/
protected Queue loadResource(InputStream resourceInput) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
//ignore all comments inside the xml file
docBuilderFactory.setIgnoringComments(true);
//allow includes in the xml file
docBuilderFactory.setNamespaceAware(true);
try {
docBuilderFactory.setXIncludeAware(true);
} catch (UnsupportedOperationException e) {
LOG.info("Failed to set setXIncludeAware(true) for parser " + docBuilderFactory + NAME_SEPARATOR + e);
}
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
Document doc = null;
Element queuesNode = null;
doc = builder.parse(resourceInput);
queuesNode = doc.getDocumentElement();
return this.parseResource(queuesNode);
}
use of org.w3c.dom.Element in project hadoop by apache.
the class QueueConfigurationParser method getQueueElement.
/**
* Construct an {@link Element} for a single queue, constructing the inner
* queue <name/>, <properties/>, <state/> and the inner
* <queue> elements recursively.
*
* @param document
* @param jqi
* @return
*/
static Element getQueueElement(Document document, JobQueueInfo jqi) {
// Queue
Element q = document.createElement(QUEUE_TAG);
// Queue-name
Element qName = document.createElement(QUEUE_NAME_TAG);
qName.setTextContent(getSimpleQueueName(jqi.getQueueName()));
q.appendChild(qName);
// Queue-properties
Properties props = jqi.getProperties();
Element propsElement = document.createElement(PROPERTIES_TAG);
if (props != null) {
Set<String> propList = props.stringPropertyNames();
for (String prop : propList) {
Element propertyElement = document.createElement(PROPERTY_TAG);
propertyElement.setAttribute(KEY_TAG, prop);
propertyElement.setAttribute(VALUE_TAG, (String) props.get(prop));
propsElement.appendChild(propertyElement);
}
}
q.appendChild(propsElement);
// Queue-state
String queueState = jqi.getState().getStateName();
if (queueState != null && !queueState.equals(QueueState.UNDEFINED.getStateName())) {
Element qStateElement = document.createElement(STATE_TAG);
qStateElement.setTextContent(queueState);
q.appendChild(qStateElement);
}
// Queue-children
List<JobQueueInfo> children = jqi.getChildren();
if (children != null) {
for (JobQueueInfo child : children) {
q.appendChild(getQueueElement(document, child));
}
}
return q;
}
Aggregations