Added private makeNodeHandle method that honors the

prototyperef attribute when converting an XML tag to a NodeHandle.
This commit is contained in:
hns 2002-07-04 17:35:22 +00:00
parent df4d199072
commit a85ac92e2b

View file

@ -23,6 +23,7 @@ import helma.objectmodel.db.Node;
import helma.objectmodel.db.NodeHandle; import helma.objectmodel.db.NodeHandle;
import helma.objectmodel.db.NodeManager; import helma.objectmodel.db.NodeManager;
import helma.objectmodel.db.Property; import helma.objectmodel.db.Property;
import helma.objectmodel.db.DbMapping;
public class XmlReader implements XmlConstants { public class XmlReader implements XmlConstants {
@ -199,23 +200,24 @@ public class XmlReader implements XmlConstants {
if ( childElement.getTagName().equals("hop:child") ) { if ( childElement.getTagName().equals("hop:child") ) {
// add a new NodeHandle, presume all IDs in this objectcache are unique, // add a new NodeHandle, presume all IDs in this objectcache are unique,
// a prerequisite for a simple internal database. // a prerequisite for a simple internal database.
subnodes.add (new NodeHandle (new DbKey(null,childElement.getAttribute("idref") ) ) ); subnodes.add (makeNodeHandle (childElement) );
continue; continue;
} }
if ( childElement.getTagName().equals("hop:parent") ) { if ( childElement.getTagName().equals("hop:parent") ) {
// add a NodeHandle to parent object // add a NodeHandle to parent object
helmaNode.setParentHandle (new NodeHandle (new DbKey(null,childElement.getAttribute("idref") ) ) ); helmaNode.setParentHandle (makeNodeHandle (childElement) );
continue; continue;
} }
// if we come until here, childelement is a property value // if we come until here, childelement is a property value
// FIXME: Stefan, why are we checking for id, and not just for
// idref here? (hns)
Property prop = new Property (childElement.getTagName(), helmaNode); Property prop = new Property (childElement.getTagName(), helmaNode);
if ( !"".equals(childElement.getAttribute("id")) || if ( !"".equals(childElement.getAttribute("id")) ||
!"".equals(childElement.getAttribute("idref")) ) { !"".equals(childElement.getAttribute("idref")) ) {
// we've got an object! // we've got an object!
String idref = childElement.getAttribute("idref"); prop.setNodeHandle (makeNodeHandle(childElement));
prop.setNodeHandle (new NodeHandle(new DbKey(null,idref)));
} else { } else {
String type = childElement.getAttribute("type"); String type = childElement.getAttribute("type");
String content = XmlUtil.getTextContent(childElement); String content = XmlUtil.getTextContent(childElement);
@ -254,5 +256,15 @@ public class XmlReader implements XmlConstants {
return helmaNode; return helmaNode;
} }
// create a node handle from a node reference DOM element
private NodeHandle makeNodeHandle (Element element) {
String idref = element.getAttribute("idref");
String protoref = element.getAttribute("prototyperef");
DbMapping dbmap = null;
if (protoref != null)
dbmap = nmgr.getDbMapping(protoref);
return new NodeHandle (new DbKey (dbmap, idref));
}
} }