[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Attribute.java, 1.22, 1.23 Persisten
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-10-11 10:21:53
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29413/src/net/sourceforge/bprocessor/model Modified Files: Attribute.java Persistence.java Log Message: Added globals to the things persistens puts in a bp file. Index: Attribute.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Attribute.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Attribute.java 9 Aug 2007 16:07:53 -0000 1.22 --- Attribute.java 11 Oct 2007 10:21:46 -0000 1.23 *************** *** 8,11 **** --- 8,12 ---- import java.util.Collection; + import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; *************** *** 254,256 **** --- 255,263 ---- this.the2ndValue = the2ndValue; } + + protected static class AttributeComparator implements Comparator<Attribute> { + public int compare(Attribute o1, Attribute o2) { + return o1.name.compareTo(o2.name); + } + } } Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** Persistence.java 9 Aug 2007 16:07:53 -0000 1.45 --- Persistence.java 11 Oct 2007 10:21:46 -0000 1.46 *************** *** 82,85 **** --- 82,86 ---- import java.util.ArrayList; import java.util.Collection; + import java.util.Collections; import java.util.HashMap; import java.util.HashSet; *************** *** 141,144 **** --- 142,157 ---- p.changed(p); { + List<Attribute> attributes = new LinkedList<Attribute>(); + for (Object o : document.getGlobal()) { + if (o instanceof MapElementType) { + MapElementType elem = (MapElementType)o; + attributes.add(internalizeKeyValue(elem, mapper)); + } + } + Collections.sort(attributes, new Attribute.AttributeComparator()); + Project.getInstance().getGlobals().setAttributes(attributes); + } + + { Iterator iter = document.getCamera().iterator(); while (iter.hasNext()) { *************** *** 438,457 **** m.setId(new Long(xml.getProgid())); List<MapElementType> attributes = xml.getAttribute(); ! HashMap content = new HashMap(); for (MapElementType elem : attributes) { ! 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 BooleanType) { ! content.put(elem.getKey(), ((BooleanType)val).isBoolean()); ! } 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"); ! } } m.setContent(content); --- 451,458 ---- m.setId(new Long(xml.getProgid())); List<MapElementType> attributes = xml.getAttribute(); ! HashMap<String, Object> content = new HashMap(); for (MapElementType elem : attributes) { ! Attribute a = internalizeKeyValue(elem, map); ! content.put(a.getName(), a.getValue()); } m.setContent(content); *************** *** 467,470 **** --- 468,490 ---- } + private static Attribute internalizeKeyValue(MapElementType elem, Map map) { + Object val = elem.getValue(); + Attribute res = null; + if (val instanceof IntegerType) { + res = new Attribute(elem.getKey(), new Integer(((IntegerType)val).getInteger())); + } else if (val instanceof StringType) { + res = new Attribute(elem.getKey(), ((StringType)val).getString()); + } else if (val instanceof BooleanType) { + res = new Attribute(elem.getKey(), ((BooleanType)val).isBoolean()); + } else if (val instanceof DoubleType) { + res = new Attribute(elem.getKey(), new Double(((DoubleType)val).getDouble())); + } else if (val instanceof RefType) { + res = new Attribute(elem.getKey(), get(((RefType)val).getRef(), map)); + } else { + log.warn("Non supported type"); + } + return res; + } + /** * *************** *** 780,783 **** --- 800,809 ---- { + Collection globals = document.getGlobal(); + for (Attribute a : Project.getInstance().getGlobals().getAttributes()) { + globals.add(externalizeKeyValue(a.getName(), a.getValue(), mapper)); + } + } + { Collection cams = document.getCamera(); Iterator iter = Project.getInstance().getCameras().iterator(); |