use of org.w3c.dom.DOMException 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.DOMException in project che by eclipse.
the class RefactoringSessionTransformer method createArgument.
/**
* Creates a refactoring argument with the specified name and value.
* <p>
* If no refactoring is currently processed, this call has no effect.
* </p>
*
* @param name
* the non-empty name of the argument
* @param value
* the value of the argument
*
* @throws CoreException
* if an error occurs while creating a new argument
*/
public void createArgument(final String name, final String value) throws CoreException {
Assert.isNotNull(name);
//$NON-NLS-1$
Assert.isTrue(!"".equals(name));
Assert.isNotNull(value);
if (fDocument != null && fRefactoringArguments != null && value != null) {
try {
final Attr attribute = fDocument.createAttribute(name);
attribute.setValue(value);
fRefactoringArguments.add(attribute);
} catch (DOMException exception) {
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, exception.getLocalizedMessage(), null));
}
}
}
use of org.w3c.dom.DOMException in project ACS by ACS-Community.
the class LogEntryXML method initLogEntryType.
private void initLogEntryType(Node log) throws DOMException {
String logEntryType = log.getNodeName();
if (logEntryType == null)
throw new DOMException(DOMException.SYNTAX_ERR, "logEntryType is null.");
// todo: reuse Integer objects
setField(LogField.ENTRYTYPE, LogTypeHelper.fromLogTypeDescription(logEntryType).ordinal());
if (getField(LogField.ENTRYTYPE) == null)
throw new DOMException(DOMException.NOT_FOUND_ERR, "Unknown logEntryType: " + logEntryType);
}
use of org.w3c.dom.DOMException in project CloudStack-archive by CloudStack-extras.
the class VsmCommand method getPolicyMap.
public static String getPolicyMap(String name) {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
DOMImplementation domImpl = docBuilder.getDOMImplementation();
Document doc = createDocument(domImpl);
Element get = doc.createElement("nf:get");
doc.getDocumentElement().appendChild(get);
Element filter = doc.createElement("nf:filter");
filter.setAttribute("type", "subtree");
get.appendChild(filter);
// Create the show port-profile name <profile-name> command.
Element show = doc.createElement("show");
filter.appendChild(show);
Element policyMap = doc.createElement("policy-map");
show.appendChild(policyMap);
Element nameNode = doc.createElement("name");
nameNode.setTextContent(name);
policyMap.appendChild(nameNode);
return serialize(domImpl, doc);
} catch (ParserConfigurationException e) {
s_logger.error("Error while creating the message to get policy map details : " + e.getMessage());
return null;
} catch (DOMException e) {
s_logger.error("Error while creating the message to get policy map details : " + e.getMessage());
return null;
}
}
use of org.w3c.dom.DOMException in project CloudStack-archive by CloudStack-extras.
the class VsmCommand method getUpdatePortProfile.
public static String getUpdatePortProfile(String name, SwitchPortMode mode, List<Pair<VsmCommand.OperationType, String>> params) {
try {
// Create the document and root element.
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
DOMImplementation domImpl = docBuilder.getDOMImplementation();
Document doc = createDocument(domImpl);
// Edit configuration command.
Element editConfig = doc.createElement("nf:edit-config");
doc.getDocumentElement().appendChild(editConfig);
// Command to get into exec configure mode.
Element target = doc.createElement("nf:target");
Element running = doc.createElement("nf:running");
target.appendChild(running);
editConfig.appendChild(target);
// Command to update the port profile with the desired configuration.
Element config = doc.createElement("nf:config");
config.appendChild(configPortProfileDetails(doc, name, mode, params));
editConfig.appendChild(config);
return serialize(domImpl, doc);
} catch (ParserConfigurationException e) {
s_logger.error("Error while creating update port profile message : " + e.getMessage());
return null;
} catch (DOMException e) {
s_logger.error("Error while creating update port profile message : " + e.getMessage());
return null;
}
}
Aggregations