Discussions
Categories
- 385.5K All Categories
- 5.1K Data
- 2.5K Big Data Appliance
- 2.5K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 584 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 666 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
JavaME Internal DOM classes

Hi,
I need to implement my own org.w3c.dom.Element class that later on is used as a node in a org.w3c.dom.Document instance.
My own element class essentially implements the required interface and everything works fine, at least in a Java standard edition.
Running it on a micro edition (v 8) I do see some unexpected behaviour. I get a class cast exception.
java.lang.ClassCastException
- com/sun/ukit/dom/XParent.appendChild(), bci=21
Looking for the code I found the following on [1]
public Node appendChild(Node newChild)
throws DOMException
{
if (_isRO())
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
XNode nchild = (XNode)newChild;
if (newChild.getNodeType() != DOCUMENT_FRAGMENT_NODE) {
// Append a new child node.
_appendChild(nchild);
_childAdded(nchild);
} else {
// Recursive call to appendChild for each child of doc fragment
while (nchild.getLength() > 0)
appendChild(nchild.item(0));
}
return nchild;
}
It looks like each newChild node gets casted to XNode. First of all I wonder why and second I would like to know how I can now write my own Node classes. I cannot simply extend XNode given that it seems internal somehow.
Any ideas? Thank you very much for every hint,
-- Daniel
P.S: Sorry for cross posting the same question on JavaME Internal DOM classes (Java Micro Edition forum at JavaRanch)
[1] https://svn.java.net/svn/phoneme~svn/components/jsr280/branches/jsr280-cr-6781500/src/share/oi/com/sun/ukit/dom/XParent.java
Answers
-
Hello Daniel,
Unfortunately, current implementation of JavaME Embedded v8 does not support custom implementations of the org.w3c.dom.Element class.
Could you attach an example of usage of your custom Element. I'll try to suggest workaround for your particular use-case.
Thank you
Alexey
-
Hi Alexey,
Thank you very much for your feedback.
Let me try to explain our goal and maybe there is really a workaround. Would be great!
The main idea is to create a lazy DOM, meaning that by default only a small portion of the DOM is loaded while the rest of the processing is postponed/skipped till it is really needed. The reason for that is that we cannot afford loading the entire DOM due to memory restrictions. Further, in our cases only a small portion is sufficient and other portions of the DOM are loaded (and later on also unloaded).
Attached a snipped of our SCElementMEncode that implements org.w3c.dom.Element. Each SCElementME knows its localName and its namespaceURI. If more information are needed the actual DOM portion needs to be loaded (see checkStatus() method). We make use of the EXI format (http://www.w3.org/TR/exi/) that allows us to to have random access into the XML document by means of selfContained EXI elements.
I hope it is clear what we try to achieve and you can suggest a workaround.
Thanks,
-- Daniel
------------- CODE
public class SCElementME implements Element {
final String namespaceURI;
final String localName;
final Document doc;
final Element el;
boolean loaded = false;
public SCElementME(Document doc, String namespaceURI,
String localName) {
this.doc = doc;
this.namespaceURI = namespaceURI;
this.localName = localName;
this.el = doc.createElementNS(namespaceURI, localName);
}
protected void checkStatus() {
if(!loaded) {
// load EXI SC fragment into element el
// ...
this.el.appendChild(null); // TODO load children etc.
loaded = true;
}
}
public String getLocalName() {
return this.localName;
}
public String getNamespaceURI() {
return this.namespaceURI;
}
public NamedNodeMap getAttributes() {
checkStatus();
return el.getAttributes();
}
public NodeList getChildNodes() {
checkStatus();
return el.getChildNodes();
}
/////// .. more
}