[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Persistence.java, 1.12, 1.13
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-10-14 23:42:47
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv11288/src/net/sourceforge/bprocessor/model Modified Files: Persistence.java Log Message: Made bug fixes and now persistence of modellors partially work Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Persistence.java 13 Oct 2006 15:54:59 -0000 1.12 --- Persistence.java 14 Oct 2006 23:42:43 -0000 1.13 *************** *** 12,15 **** --- 12,16 ---- import net.sourceforge.bprocessor.model.xml.ConstructorType; import net.sourceforge.bprocessor.model.xml.CoordinateSystemType; + import net.sourceforge.bprocessor.model.xml.DoubleType; import net.sourceforge.bprocessor.model.xml.EdgeType; import net.sourceforge.bprocessor.model.xml.EntityType; *************** *** 21,24 **** --- 22,26 ---- import net.sourceforge.bprocessor.model.xml.ModellorType; import net.sourceforge.bprocessor.model.xml.PointType; + import net.sourceforge.bprocessor.model.xml.RefType; import net.sourceforge.bprocessor.model.xml.RotateType; import net.sourceforge.bprocessor.model.xml.ScaleType; *************** *** 33,36 **** --- 35,39 ---- import net.sourceforge.bprocessor.model.xml.impl.BmodelImpl; import net.sourceforge.bprocessor.model.xml.impl.CoordinateSystemTypeImpl; + import net.sourceforge.bprocessor.model.xml.impl.DoubleTypeImpl; import net.sourceforge.bprocessor.model.xml.impl.EdgeImpl; import net.sourceforge.bprocessor.model.xml.impl.IDTransformTypeImpl; *************** *** 41,47 **** --- 44,52 ---- import net.sourceforge.bprocessor.model.xml.impl.ModellorTypeImpl; import net.sourceforge.bprocessor.model.xml.impl.PointTypeImpl; + import net.sourceforge.bprocessor.model.xml.impl.RefTypeImpl; import net.sourceforge.bprocessor.model.xml.impl.RotateTypeImpl; import net.sourceforge.bprocessor.model.xml.impl.ScaleTypeImpl; import net.sourceforge.bprocessor.model.xml.impl.SpaceImpl; + import net.sourceforge.bprocessor.model.xml.impl.StringTypeImpl; import net.sourceforge.bprocessor.model.xml.impl.SurfaceImpl; import net.sourceforge.bprocessor.model.xml.impl.TranslateTypeImpl; *************** *** 161,165 **** space.setClassification(xml.getClassification()); mapper.put(new Long(xml.getId()), space); - space.setModellor(internalizeModellor(xml.getModellor())); xmls.add(xml); --- 166,169 ---- *************** *** 256,262 **** * Internalize the modellor * @param xml the xml version of the modellor * @return the model modellor */ ! private static Modellor internalizeModellor(ModellorType xml) { if (xml != null) { Class model; --- 260,267 ---- * Internalize the modellor * @param xml the xml version of the modellor + * @param map the map of objects * @return the model modellor */ ! private static Modellor internalizeModellor(ModellorType xml, Map map) { if (xml != null) { Class model; *************** *** 270,273 **** --- 275,279 ---- try { Modellor m = (Modellor)model.getConstructor(new Class[0]).newInstance(new Object[0]); + m.setId(new Long(xml.getProgid())); HashMap content = new HashMap(); Iterator iter = xml.getAttribute().iterator(); *************** *** 276,282 **** Object val = elem.getValue(); if (val instanceof IntegerType) { ! content.put(elem.getKey(), elem.getValue()); } else if (val instanceof StringType) { ! content.put(elem.getKey(), elem.getValue()); } else { log.warn("Non supported type"); --- 282,292 ---- Object val = elem.getValue(); if (val instanceof IntegerType) { ! content.put(elem.getKey(), new Integer(((IntegerType)val).getInteger())); } else if (val instanceof StringType) { ! content.put(elem.getKey(), ((StringType)val).getString()); ! } else if (val instanceof DoubleType) { ! content.put(elem.getKey(), new Double(((DoubleType)val).getDouble())); ! } else if (val instanceof RefType) { ! content.put(elem.getKey(), get(((RefType)val).getRef(), map)); } else { log.warn("Non supported type"); *************** *** 504,507 **** --- 514,521 ---- object.setProto((Space) get(xml.getProtoref(), map)); object.setEnvelope(asSet(xml.getBoundary(), map)); + { + Modellor m = internalizeModellor(xml.getModellor(), map); + object.setModellor(m); + } } *************** *** 626,634 **** Map cont = m.getContent(); if (cont != null) { ! Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry o = (Map.Entry)iter.next(); MapElementType elem = new MapElementTypeImpl(); ! elem.setKey((String)o.getKey()); Object val = o.getValue(); if (val instanceof Integer) { --- 640,653 ---- Map cont = m.getContent(); if (cont != null) { ! Iterator iter = cont.entrySet().iterator(); while (iter.hasNext()) { Map.Entry o = (Map.Entry)iter.next(); MapElementType elem = new MapElementTypeImpl(); ! if (o.getKey() instanceof String) { ! elem.setKey((String)o.getKey()); ! } else { ! log.error("Key should always be of type String but were " + ! o.getKey().getClass().getName()); ! } Object val = o.getValue(); if (val instanceof Integer) { *************** *** 636,641 **** t.setInteger(((Integer)val).intValue()); elem.setValue(t); } - att.add(elem); } } --- 655,681 ---- t.setInteger(((Integer)val).intValue()); elem.setValue(t); + } else if (val instanceof Double) { + DoubleType t = new DoubleTypeImpl(); + t.setDouble(((Double)val).doubleValue()); + elem.setValue(t); + } else if (val instanceof String) { + StringType t = new StringTypeImpl(); + t.setString((String)val); + elem.setValue(t); + } else if (val instanceof Entity) { + RefType r = new RefTypeImpl(); + r.setRef(id(map, val)); + if (r.getRef() == 0) { + log.error("Could not find " + val); + } + elem.setValue(r); + } else if (val == null) { + elem = null; + } else { + log.error("Type were not implemented " + val.getClass().getName()); + } + if (elem != null) { + att.add(elem); } } } *************** *** 659,668 **** xml.setDescription(space.getDescription().toString()); xml.setClassification(space.getClassification().toString()); - if (space.getModellor() != null) { - xml.setModellor(externalizeModellor(space.getModellor(), map)); - } map.put(space, xml); if (!space.isInstance()) { { Iterator iter = space.getElements().iterator(); --- 699,706 ---- xml.setDescription(space.getDescription().toString()); xml.setClassification(space.getClassification().toString()); map.put(space, xml); if (!space.isInstance()) { + //Only save geometry if space isn't a instance { Iterator iter = space.getElements().iterator(); *************** *** 704,708 **** while (iter.hasNext()) { Constructor current = (Constructor) iter.next(); ! externalizeConstructor(current, map, xml); } } --- 742,746 ---- while (iter.hasNext()) { Constructor current = (Constructor) iter.next(); ! xml.getConstructor().add(externalizeConstructor(current, map)); } } *************** *** 711,748 **** Iterator iter = space.getTransformations().stack().iterator(); while (iter.hasNext()) { ! List trans = xml.getTransforms(); ! Object current = iter.next(); ! if (current instanceof Rotate) { ! Rotate r = (Rotate) current; ! RotateTypeImpl rot = new RotateTypeImpl(); ! rot.setX(r.rx()); ! rot.setY(r.ry()); ! rot.setZ(r.rz()); ! trans.add(0, rot); ! } else if (current instanceof IDTransform) { ! trans.add(0, new IDTransformTypeImpl()); ! } else if (current instanceof AxisRotate) { ! AxisRotate ar = (AxisRotate) current; ! AxisRotateType arot = new AxisRotateTypeImpl(); ! arot.setAngle(ar.angle()); ! arot.setX(ar.rx()); ! arot.setY(ar.ry()); ! arot.setZ(ar.rz()); ! trans.add(0, arot); ! } else if (current instanceof Scale) { ! Scale s = (Scale) current; ! ScaleType st = new ScaleTypeImpl(); ! st.setX(s.sx()); ! st.setY(s.sy()); ! st.setZ(s.sz()); ! trans.add(0, st); ! } else if (current instanceof Translate) { ! Translate t = (Translate) current; ! TranslateType tt = new TranslateTypeImpl(); ! tt.setX(t.tx()); ! tt.setY(t.ty()); ! tt.setZ(t.tz()); ! trans.add(0, tt); ! } } } --- 749,754 ---- Iterator iter = space.getTransformations().stack().iterator(); while (iter.hasNext()) { ! Transform t = (Transform)iter.next(); ! xml.getTransforms().add(externalizeTransformation(t, map)); } } *************** *** 751,761 **** /** * Create an xml ConstructorImpl and place it in the map * @param constructor The constructor * @param map The map ! * @param to The space that the constructors are extracted from */ ! private static void externalizeConstructor(Constructor constructor, ! Map map, SpaceType to) { if (constructor instanceof Point) { PointType xml = new PointTypeImpl(); --- 757,815 ---- /** + * Externalize a transformation + * @param current the original object + * @param map the map of original to xml object + * @return the xml object + */ + private static Object externalizeTransformation(Transform current, Map map) { + if (current instanceof Rotate) { + Rotate r = (Rotate) current; + RotateTypeImpl rot = new RotateTypeImpl(); + rot.setX(r.rx()); + rot.setY(r.ry()); + rot.setZ(r.rz()); + map.put(r, rot); + return rot; + } else if (current instanceof IDTransform) { + IDTransformType id = new IDTransformTypeImpl(); + map.put(current, id); + return id; + } else if (current instanceof AxisRotate) { + AxisRotate ar = (AxisRotate) current; + AxisRotateType arot = new AxisRotateTypeImpl(); + arot.setAngle(ar.angle()); + arot.setX(ar.rx()); + arot.setY(ar.ry()); + arot.setZ(ar.rz()); + map.put(ar, arot); + return arot; + } else if (current instanceof Scale) { + Scale s = (Scale) current; + ScaleType st = new ScaleTypeImpl(); + st.setX(s.sx()); + st.setY(s.sy()); + st.setZ(s.sz()); + map.put(s, st); + return st; + } else if (current instanceof Translate) { + Translate t = (Translate) current; + TranslateType tt = new TranslateTypeImpl(); + tt.setX(t.tx()); + tt.setY(t.ty()); + tt.setZ(t.tz()); + map.put(t, tt); + return tt; + } + return null; + } + + /** * Create an xml ConstructorImpl and place it in the map * @param constructor The constructor * @param map The map ! * @return the xml version */ ! private static ConstructorType externalizeConstructor(Constructor constructor, ! Map map) { if (constructor instanceof Point) { PointType xml = new PointTypeImpl(); *************** *** 766,771 **** VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); xml.setVertex(orig); - to.getConstructor().add(xml); map.put(constructor, xml); } else if (constructor instanceof Line) { LineType xml = new LineTypeImpl(); --- 820,825 ---- VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); xml.setVertex(orig); map.put(constructor, xml); + return xml; } else if (constructor instanceof Line) { LineType xml = new LineTypeImpl(); *************** *** 780,785 **** VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); xml.setVertex(orig); - to.getConstructor().add(xml); map.put(constructor, xml); } else if (constructor instanceof CoordinateSystem) { CoordinateSystem cs = (CoordinateSystem)constructor; --- 834,839 ---- VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); xml.setVertex(orig); map.put(constructor, xml); + return xml; } else if (constructor instanceof CoordinateSystem) { CoordinateSystem cs = (CoordinateSystem)constructor; *************** *** 798,805 **** VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); xml.setVertex(orig); - to.getConstructor().add(xml); map.put(constructor, xml); } else { log.error(constructor + " were of unknown type"); } } --- 852,860 ---- VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); xml.setVertex(orig); map.put(constructor, xml); + return xml; } else { log.error(constructor + " were of unknown type"); + return null; } } *************** *** 942,945 **** --- 997,1003 ---- } xml.getBoundary().addAll(ids(map, object.getEnvelope())); + if (object.getModellor() != null) { + xml.setModellor(externalizeModellor(object.getModellor(), map)); + } } |