1 2 package org.catacomb.serial.om; 3 4 import org.catacomb.interlish.structure.Attribute; 5 import org.catacomb.interlish.structure.Constructor; 6 import org.catacomb.report.E; 7 8 9 10 11 public class ElementConstructor implements Constructor { 12 13 14 public Object newInstance(String s) { 15 return new OmElement(s); 16 } 17 18 19 public boolean setAttributeField(Object parent, String fieldName, String val) { 20 if (parent instanceof OmElement) { 21 OmElement omp = (OmElement)parent; 22 omp.addAttribute(fieldName, val); 23 } 24 return true; 25 } 26 27 28 public void appendContent(Object obj, String s) { 29 ((OmElement)obj).addToBody(s); 30 } 31 32 33 public Object getChildObject(Object parent, String name, Attribute[] atta) { 34 35 OmElement elt = new OmElement(name); 36 37 return elt; 38 } 39 40 41 public void applyAttributes(Object obj, Attribute[] atta) { 42 ((OmElement)obj).copyAttributes(atta); 43 } 44 45 46 47 public boolean setField(Object parent, String fieldName, Object child) { 48 boolean ok = false; 49 50 if (parent instanceof OmElement && child instanceof String) { 51 52 OmElement omp = (OmElement)parent; 53 OmElement ec = new OmElement(fieldName); 54 55 ec.setBody((String)child); 56 omp.addElement(ec); 57 58 59 } else if (parent instanceof OmElement && child instanceof OmElement) { 60 OmElement omp = (OmElement)parent; 61 OmElement omc = (OmElement)child; 62 63 if (omc.getName().equals(fieldName)) { 64 omp.addElement(omc); 65 ok = true; 66 67 } else { 68 E.error(" - element instantiator set field hs fieldname " + 69 fieldName + " but element " + omc.getName()); 70 } 71 72 } else { 73 E.error(" - ElementInstantiator set field : fieldname=" + fieldName + 74 " parent=" + parent + 75 " child=" + child + " " + child.getClass().getName() + 76 " but need elements only"); 77 (new Exception()).printStackTrace(); 78 } 79 return ok; 80 } 81 82 83 public Object getField(Object parent, String fieldName) { 84 return new OmElement(fieldName); 85 } 86 87 88 public void setIntFromStatic(Object ret, String id, String sv) { 89 E.missing(); 90 } 91 92 93 }