Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Persistence.java, 1.5, 1.6
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-08-18 07:01:28
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8300/src/net/sourceforge/bprocessor/model Modified Files: Persistence.java Log Message: Fixed the problem with loading by two hacks. First by making three lists one for Point, Line and Coordinatesystem. Then for some reason it is not possible to make a origin reference to a vertex??? Have to check this further cause can't make reason out of that... But end of it is it works at the moment... Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Persistence.java 3 Aug 2006 14:35:21 -0000 1.5 --- Persistence.java 18 Aug 2006 07:01:24 -0000 1.6 *************** *** 19,22 **** --- 19,23 ---- import net.sourceforge.bprocessor.model.xml.SurfaceType; import net.sourceforge.bprocessor.model.xml.VertexType; + import net.sourceforge.bprocessor.model.xml.VertexesType; import net.sourceforge.bprocessor.model.xml.impl.BmodelImpl; import net.sourceforge.bprocessor.model.xml.impl.CoordinateSystemTypeImpl; *************** *** 28,31 **** --- 29,33 ---- import net.sourceforge.bprocessor.model.xml.impl.SurfaceImpl; import net.sourceforge.bprocessor.model.xml.impl.VertexImpl; + import net.sourceforge.bprocessor.model.xml.impl.VertexesTypeImpl; import java.awt.Color; *************** *** 184,191 **** } { ! Iterator iter = xml.getConstructor().iterator(); while (iter.hasNext()) { ! ConstructorType current = (ConstructorType) iter.next(); ! space.add(internalizeConstructor(current, mapper, xmls)); } } --- 186,207 ---- } { ! Iterator iter = xml.getPoint().iterator(); while (iter.hasNext()) { ! PointType current = (PointType) iter.next(); ! space.add(internalizePoint(current, mapper, xmls)); ! } ! } ! { ! Iterator iter = xml.getLine().iterator(); ! while (iter.hasNext()) { ! LineType current = (LineType) iter.next(); ! space.add(internalizeLine(current, mapper, xmls)); ! } ! } ! { ! Iterator iter = xml.getCoordinatesystem().iterator(); ! while (iter.hasNext()) { ! CoordinateSystemType current = (CoordinateSystemType) iter.next(); ! space.add(internalizeCoordinateSystem(current, mapper, xmls)); } } *************** *** 201,233 **** * @return The Constructor */ ! private static Constructor internalizeConstructor(ConstructorType xml, Map mapper, Collection xmls) { ! Constructor res; ! if (xml instanceof PointType) { ! res = new Point(); ! } else if (xml instanceof LineType) { ! Line l = new Line(); ! l.setDirection(internalizeVertex(((LineType)xml).getDirection(), new HashMap(), new LinkedList())); - res = l; - } else if (xml instanceof CoordinateSystemType) { - CoordinateSystem cs = new CoordinateSystem(); - CoordinateSystemType cst = (CoordinateSystemType)xml; - cs.onlyPlane(cst.isOnlyplane()); - List ijn = cst.getIjn(); - Vertex i = internalizeVertex((VertexType)ijn.get(0), new HashMap(), new LinkedList()); - Vertex j = internalizeVertex((VertexType)ijn.get(1), new HashMap(), new LinkedList()); - Vertex n = internalizeVertex((VertexType)ijn.get(2), new HashMap(), new LinkedList()); - cs.setIJN(i, j, n); - res = cs; - } else { - log.error(xml + " were not a known constructor"); - return null; - } res.setActive(xml.isActive()); res.setEditable(xml.isEditable()); res.setId(new Long(xml.getProgid())); mapper.put(new Long(xml.getId()), res); ! res.setOrigin(internalizeVertex(xml.getOrigin(), new HashMap(), new LinkedList())); xmls.add(xml); return res; --- 217,276 ---- * @return The Constructor */ ! private static Point internalizePoint(PointType xml, Map mapper, Collection xmls) { ! Point res = new Point(); ! res.setActive(xml.isActive()); ! res.setEditable(xml.isEditable()); ! res.setId(new Long(xml.getProgid())); ! mapper.put(new Long(xml.getId()), res); ! res.setOrigin(internalizeVertex(xml.getVertex(), new HashMap(), new LinkedList())); ! xmls.add(xml); ! return res; ! } ! ! /** ! * ! * @param xml The ConstructorType ! * @param mapper The mapper ! * @param xmls The xmls ! * @return The Constructor ! */ ! private static Line internalizeLine(LineType xml, ! Map mapper, Collection xmls) { ! Line res = new Line(); ! res.setDirection(internalizeVertex( ! (VertexType)((LineType)xml).getDirection().getVertex().get(0), new HashMap(), new LinkedList())); res.setActive(xml.isActive()); res.setEditable(xml.isEditable()); res.setId(new Long(xml.getProgid())); mapper.put(new Long(xml.getId()), res); ! res.setOrigin(internalizeVertex(xml.getVertex(), new HashMap(), new LinkedList())); ! xmls.add(xml); ! return res; ! } ! ! /** ! * ! * @param xml The ConstructorType ! * @param mapper The mapper ! * @param xmls The xmls ! * @return The Constructor ! */ ! private static CoordinateSystem internalizeCoordinateSystem(CoordinateSystemType xml, ! Map mapper, Collection xmls) { ! CoordinateSystem res = new CoordinateSystem(); ! CoordinateSystemType cst = (CoordinateSystemType)xml; ! res.onlyPlane(cst.isOnlyplane()); ! List ijn = cst.getIjn().getVertex(); ! Vertex i = internalizeVertex((VertexType)ijn.get(0), new HashMap(), new LinkedList()); ! Vertex j = internalizeVertex((VertexType)ijn.get(1), new HashMap(), new LinkedList()); ! Vertex n = internalizeVertex((VertexType)ijn.get(2), new HashMap(), new LinkedList()); ! res.setIJN(i, j, n); ! res.setActive(xml.isActive()); ! res.setEditable(xml.isEditable()); ! res.setId(new Long(xml.getProgid())); ! mapper.put(new Long(xml.getId()), res); ! res.setOrigin(internalizeVertex(xml.getVertex(), new HashMap(), new LinkedList())); xmls.add(xml); return res; *************** *** 535,539 **** while (iter.hasNext()) { Constructor current = (Constructor) iter.next(); ! xml.getConstructor().add(externalizeConstructor(current, map)); } } --- 578,582 ---- while (iter.hasNext()) { Constructor current = (Constructor) iter.next(); ! externalizeConstructor(current, map, xml); } } *************** *** 545,579 **** * @param constructor The constructor * @param map The map ! * @return The ConstructorImpl */ ! private static ConstructorType externalizeConstructor(Constructor constructor, Map map) { ! ConstructorType xml; if (constructor instanceof Point) { ! xml = new PointTypeImpl(); } else if (constructor instanceof Line) { ! xml = new LineTypeImpl(); ! ((LineType)xml).setDirection(externalizeVertex(((Line)constructor).getDirection(), new HashMap())); } else if (constructor instanceof CoordinateSystem) { CoordinateSystem cs = (CoordinateSystem)constructor; ! CoordinateSystemType cst = new CoordinateSystemTypeImpl(); ! cst.setOnlyplane(((CoordinateSystem)constructor).onlyPlane()); ! List ijn = cst.getIjn(); ijn.add(0, externalizeVertex(cs.getI(), new HashMap())); ijn.add(1, externalizeVertex(cs.getJ(), new HashMap())); ijn.add(2, externalizeVertex(cs.getN(), new HashMap())); ! xml = cst; } else { log.error(constructor + " were of unknown type"); - return null; } - xml.setId(counter++); - xml.setProgid(constructor.getId().longValue()); - xml.setActive(constructor.isActive()); - xml.setEditable(constructor.isEditable()); - VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); - xml.setOrigin(orig); - map.put(constructor, xml); - return xml; } --- 588,640 ---- * @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(); ! xml.setId(counter++); ! xml.setProgid(constructor.getId().longValue()); ! xml.setActive(constructor.isActive()); ! xml.setEditable(constructor.isEditable()); ! VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); ! xml.setVertex(orig); ! to.getPoint().add(xml); ! map.put(constructor, xml); } else if (constructor instanceof Line) { ! LineType xml = new LineTypeImpl(); ! VertexesType vt = new VertexesTypeImpl(); ! vt.getVertex().add(externalizeVertex(((Line)constructor).getDirection(), new HashMap())); + ((LineType)xml).setDirection(vt); + xml.setId(counter++); + xml.setProgid(constructor.getId().longValue()); + xml.setActive(constructor.isActive()); + xml.setEditable(constructor.isEditable()); + VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); + xml.setVertex(orig); + to.getLine().add(xml); + map.put(constructor, xml); } else if (constructor instanceof CoordinateSystem) { CoordinateSystem cs = (CoordinateSystem)constructor; ! CoordinateSystemType xml = new CoordinateSystemTypeImpl(); ! xml.setOnlyplane(((CoordinateSystem)constructor).onlyPlane()); ! VertexesType vt = new VertexesTypeImpl(); ! List ijn = vt.getVertex(); ijn.add(0, externalizeVertex(cs.getI(), new HashMap())); ijn.add(1, externalizeVertex(cs.getJ(), new HashMap())); ijn.add(2, externalizeVertex(cs.getN(), new HashMap())); ! xml.setIjn(vt); ! xml.setId(counter++); ! xml.setProgid(constructor.getId().longValue()); ! xml.setActive(constructor.isActive()); ! xml.setEditable(constructor.isEditable()); ! VertexType orig = externalizeVertex(constructor.getOrigin(), new HashMap()); ! xml.setVertex(orig); ! to.getCoordinatesystem().add(xml); ! map.put(constructor, xml); } else { log.error(constructor + " were of unknown type"); } } |