public static DefaultCellInfo loadFrom(Element e) { String cellId; int cellNumber; boolean isInList; final String nodeReference; DefaultCellInfo parentInfo = null; cellId = e.getAttributeValue(CELL_ID); String num = e.getAttributeValue(CELL_NUMBER); if (num == null) return null; try { cellNumber = Integer.parseInt(num); } catch (NumberFormatException ex) { return null; } isInList = "true".equals(e.getAttributeValue(IS_IN_LIST)); Element nodeElem = e.getChild(NODE); if (nodeElem == null) return null; nodeReference = nodeElem.getAttributeValue(NODE_REFERENCE); if (nodeReference == null) return null; Element parentElem = e.getChild(PARENT); if (parentElem != null) { parentInfo = loadFrom(parentElem); if (parentInfo == null) return null; } final DefaultCellInfo result = new DefaultCellInfo(); result.myNodeReference = PersistenceFacade.getInstance().createNodeReference(nodeReference); result.myCellId = cellId; result.myParentInfo = parentInfo; result.myIsInList = isInList; result.myCellNumber = cellNumber; return result; }
public void saveTo(Element e) { if (myCellId != null) { e.setAttribute(CELL_ID, myCellId); } e.setAttribute(CELL_NUMBER, "" + myCellNumber); e.setAttribute(IS_IN_LIST, "" + myIsInList); Element nodeElement = new Element(NODE); if (myNodeReference != null) { nodeElement.setAttribute(NODE_REFERENCE, myNodeReference.toString()); } e.addContent(nodeElement); if (myParentInfo instanceof DefaultCellInfo) { Element parentElement = new Element(PARENT); ((DefaultCellInfo) myParentInfo).saveTo(parentElement); e.addContent(parentElement); } }