private void write0(Object data) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, SecurityException { // simple strategy: // nil: if (data == null) { this.driver.startElement(DTD.ELEMENT_NIL); this.driver.endElement(); return; } // non-nil: final Class cls = data.getClass(); SimpleStrategy ss = this.simpleStrategies.lookup(cls); if (ss != null) { this.driver.startElement(ss.name()); this.driver.writeValue(ss.marshal(data, this.context)); this.driver.endElement(); return; } // composite strategy: // check if data was already visited in the object graph: final Integer idRef = this.encoded.get(data); if (idRef != null) { // write object idref for already-visited data: this.driver.startElement(DTD.ELEMENT_OBJECT); this.driver.setAttribute(DTD.ATTRIBUTE_IDREF, idRef.toString()); this.driver.endElement(); } else { // mark data as visited: final int nextUniqueId = this.encoded.size() + 1; this.encoded.put(data, nextUniqueId); this.driver.setOneTimeUniqueIdTo(String.valueOf(nextUniqueId)); // visit data: final CompositeStrategy cs = this.compositeStrategies.lookup(cls); if (cs != null) { cs.marshal(data, this.driver, this.context); } else if (cls.isArray()) { this.writeArray(data); } else { this.writeObject(data); } } }