[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Persistence.java, 1.56, 1.57 Library
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-11-12 19:17:29
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv11856/src/net/sourceforge/bprocessor/model Modified Files: Persistence.java LibraryObj.java Project.java Log Message: Progress on library, not working 100% yet Index: LibraryObj.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/LibraryObj.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LibraryObj.java 12 Nov 2007 14:15:22 -0000 1.1 --- LibraryObj.java 12 Nov 2007 19:17:32 -0000 1.2 *************** *** 81,84 **** --- 81,85 ---- void setSpace(Space s) { space = s; + name = s.getName(); } *************** *** 113,117 **** att.add(new Attribute("geometry", getSpace())); att.add(new Attribute("Locked", isLocked())); ! att.add(new Attribute("File", getFile().getAbsoluteFile())); att.add(new Attribute("Author", getAuthor())); att.add(new Attribute("Version", getVersion())); --- 114,122 ---- att.add(new Attribute("geometry", getSpace())); att.add(new Attribute("Locked", isLocked())); ! String fileStr = "n/a"; ! if (getFile() != null) { ! fileStr = getFile().getAbsolutePath(); ! } ! att.add(new Attribute("File", fileStr)); att.add(new Attribute("Author", getAuthor())); att.add(new Attribute("Version", getVersion())); *************** *** 150,153 **** --- 155,161 ---- */ public String getAuthor() { + if (author == null) { + author = "n/a"; + } return author; } *************** *** 164,167 **** --- 172,178 ---- */ public String getVersion() { + if (version == null) { + version = "n/a"; + } return version; } *************** *** 173,175 **** --- 184,193 ---- this.version = version; } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } } Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** Persistence.java 9 Nov 2007 08:04:41 -0000 1.56 --- Persistence.java 12 Nov 2007 19:17:32 -0000 1.57 *************** *** 21,24 **** --- 21,26 ---- import net.sourceforge.bprocessor.model.xml.IDTransformType; import net.sourceforge.bprocessor.model.xml.IntegerType; + import net.sourceforge.bprocessor.model.xml.LibObjType; + import net.sourceforge.bprocessor.model.xml.Library; import net.sourceforge.bprocessor.model.xml.LineType; import net.sourceforge.bprocessor.model.xml.MapElementType; *************** *** 53,56 **** --- 55,60 ---- import net.sourceforge.bprocessor.model.xml.impl.IDTransformTypeImpl; import net.sourceforge.bprocessor.model.xml.impl.IntegerTypeImpl; + import net.sourceforge.bprocessor.model.xml.impl.LibObjTypeImpl; + import net.sourceforge.bprocessor.model.xml.impl.LibraryImpl; import net.sourceforge.bprocessor.model.xml.impl.LineTypeImpl; import net.sourceforge.bprocessor.model.xml.impl.MapElementTypeImpl; *************** *** 151,154 **** --- 155,166 ---- } { + p.getCatalogObjects().clear(); + for (Object o : document.getCatalogObjects()) { + LibObjType lot = (LibObjType)o; + LibraryObj lo = internalizeLibraryObj(lot, mapper, xmls); + p.addCalalogObject(lo); + } + } + { Iterator iter = document.getCamera().iterator(); while (iter.hasNext()) { *************** *** 784,787 **** --- 796,805 ---- } } + { + Collection libObjs = document.getCatalogObjects(); + for (LibraryObj lo : Project.getInstance().getCatalogObjects()) { + libObjs.add(externalizeLibObj(lo, mapper)); + } + } document.setCs(id(mapper, Project.getInstance().getActiveCoordinateSystem())); document.setActive(id(mapper, Project.getInstance().getActiveSpace())); *************** *** 915,919 **** private static SpaceType externalizeSpace(SpaceType xml, Space space, Map map) { xml.setId(counter++); ! xml.setProgid(space.getId().longValue()); xml.setName(space.getName()); xml.setType(space.getType()); --- 933,939 ---- private static SpaceType externalizeSpace(SpaceType xml, Space space, Map map) { xml.setId(counter++); ! if (space.getId() != null) { ! xml.setProgid(space.getId()); ! } xml.setName(space.getName()); xml.setType(space.getType()); *************** *** 1526,1529 **** --- 1546,1550 ---- Classification functional = internalizeClassification( (XMLClassificationType)xml.getXMLClassification().get(1), typeMap, Space.FUNCTIONAL); + input.close(); return new Object[]{construction, functional, types}; } *************** *** 1589,1598 **** } /** * Load all lbr files in the library folder * @return A collection of library objects */ ! public static Collection<Space> loadLibrary() { ! return new LinkedList<Space>(); } } --- 1610,1697 ---- } + ///////////////////////////////////////////////////////////////////////////////////////////// + // LIBRARAY INTERNALIZE AND EXTERNALIZE + ///////////////////////////////////////////////////////////////////////////////////////////// + /** * Load all lbr files in the library folder * @return A collection of library objects + * @throws Exception a exception */ ! public static Collection<LibraryObj> loadLibrary() throws Exception { ! Map<Integer, Object> map = new HashMap<Integer, Object>(); ! Collection<Object> xmls = new LinkedList<Object>(); ! Collection<LibraryObj> library = new LinkedList<LibraryObj>(); ! File libdir = new File("Library"); ! if (libdir.isDirectory()) { ! File[] libs = libdir.listFiles(); ! for (int i = 0; i < libs.length; i++) { ! File f = libs[i]; ! library.addAll(internalizeLibObjs(f, map, xmls)); ! } ! } ! return library; ! } ! ! private static List<LibraryObj> internalizeLibObjs(File f, Map map, Collection xmls) ! throws Exception { ! List<LibraryObj> res = new LinkedList<LibraryObj>(); ! if (f.exists() && f.canRead()) { ! FileInputStream is = new FileInputStream(f); ! Library lib = (Library)loadFile(is); ! for (Object lo : lib.getLibObj()) { ! LibObjType lot = (LibObjType)lo; ! LibraryObj libo = internalizeLibraryObj(lot, map, xmls); ! libo.setFile(f); ! res.add(libo); ! } ! is.close(); ! } ! return res; ! } ! ! private static LibraryObj internalizeLibraryObj(LibObjType lot, Map map, Collection xmls) { ! LibraryObj lo = new LibraryObj(); ! lo.setAuthor(lot.getAuthor()); ! lo.setVersion(lot.getVersion()); ! lo.setName(lot.getName()); ! lo.setLocked(lot.isLocked()); ! lo.setSpace(internalizeSpace(null, lot.getSpace(), map, xmls)); ! return lo; ! } ! ! /** ! * Save the library to file ! * @throws Exception one of the java file exceptions ! */ ! public static void saveLibrary() throws Exception { ! FileOutputStream fos = new FileOutputStream(new File("library\\lib.bpl")); ! ! Library lib = externalizeLibrary(Project.getLibraryObjects()); ! saveFile(lib, fos); ! ! fos.flush(); ! fos.close(); ! } ! ! private static Library externalizeLibrary(Collection<LibraryObj> catalogObjects) { ! HashMap<Long, Object> map = new HashMap<Long, Object>(); ! Library lib = new LibraryImpl(); ! List libobjs = lib.getLibObj(); ! for (LibraryObj libo : catalogObjects) { ! libobjs.add(externalizeLibObj(libo, map)); ! } ! return lib; ! } ! ! private static LibObjType externalizeLibObj(LibraryObj libo, HashMap<Long, Object> map) { ! LibObjType libobj = new LibObjTypeImpl(); ! libobj.setLocked(libo.isLocked()); ! libobj.setAuthor(libo.getAuthor()); ! libobj.setName(libo.getName()); ! libobj.setSpace(externalizeSpace(libo.getSpace(), map)); ! libobj.setUseableLevels(libo.getUseLevel()); ! libobj.setVersion(libo.getVersion()); ! return libobj; } } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.140 retrieving revision 1.141 diff -C2 -d -r1.140 -r1.141 *** Project.java 12 Nov 2007 14:15:22 -0000 1.140 --- Project.java 12 Nov 2007 19:17:32 -0000 1.141 *************** *** 64,68 **** private static Collection<ClassificationType> classificationTypes; ! private static Collection<Space> library; /** The cameras */ --- 64,68 ---- private static Collection<ClassificationType> classificationTypes; ! private static Collection<LibraryObj> library; /** The cameras */ *************** *** 132,139 **** try { Object[] loaded = Persistence.loadDBK(new File("Classification.xml")); - library = Persistence.loadLibrary(); constructionClas = (Classification)loaded[0]; functionalClas = (Classification)loaded[1]; classificationTypes = (Collection<ClassificationType>)loaded[2]; /*Map<String, ClassificationType> typeMap = ClassificationFileReader.loadTypes(""); constructionClas = ClassificationFileReader.loadClassification(true, "", typeMap); --- 132,139 ---- try { Object[] loaded = Persistence.loadDBK(new File("Classification.xml")); constructionClas = (Classification)loaded[0]; functionalClas = (Classification)loaded[1]; classificationTypes = (Collection<ClassificationType>)loaded[2]; + library = Persistence.loadLibrary(); /*Map<String, ClassificationType> typeMap = ClassificationFileReader.loadTypes(""); constructionClas = ClassificationFileReader.loadClassification(true, "", typeMap); *************** *** 317,320 **** --- 317,321 ---- public void clear() { world.clear(); + getCatalogObjects().clear(); this.setActiveSpace(world); CoordinateSystem cs = new CoordinateSystem(new Vertex(1, 0, 0), *************** *** 1053,1057 **** */ public void addCalalogObject(LibraryObj lo) { ! catalog.add(lo); } } --- 1054,1069 ---- */ public void addCalalogObject(LibraryObj lo) { ! if (!catalog.contains(lo)) { ! catalog.add(lo); ! lo.getSpace().setOwner(this.world); ! } ! } ! ! /** ! * Return the program library objects ! * @return the lib objs ! */ ! public static Collection<LibraryObj> getLibraryObjects() { ! return library; } } |