I want to save my Object Mall into XML, however it doesn't seem to save when I open the XML file. Is it because there are too many objects within the Mall class to be saved therefore it can't be saved?
Below are my codes :
Mall Class
public class Mall implements ActionExecute,Serializable { private static Mall singleton = null; private ArrayList<Store> storeList = new ArrayList (); private ArrayList<Customer> customerList = new ArrayList (); public static Mall instance() { if(singleton == null) { singleton = new Mall(); } return singleton; } public void createStore(String factory,String storeType,String storeName) { AbstractFactory Factory = FactoryProducer.getFactory(factory); if(factory.equals("store")) { Store newstore = Factory.getStore(storeType,storeName); storeList.add(newstore); } }
SaveFile Class
public class saveFile { public static void write(Mall f) throws Exception{ try (XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream( new FileOutputStream("designpattern.xml")))) { encoder.writeObject(f); } } }
XML file Result
<?xml version="1.0" encoding="UTF-8"?> <java version="1.7.0_25" class="java.beans.XMLDecoder"> <object class="designpattern.Mall"/> </java>
No comments:
Post a Comment