From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing4110.java | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing4110.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing4110.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4110.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4110.java new file mode 100644 index 0000000..5c48011 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4110.java @@ -0,0 +1,52 @@ +/* Listing4110.java */ + +import java.io.*; +import java.util.*; + +public class Listing4110 +{ + public static void main(String[] args) + { + //Erzeugen und Speichern des Objektspeichers + TrivialObjectStore tos = new TrivialObjectStore("shop"); + tos.putObject("name", "Tami-Shop Norderelbe"); + tos.putObject("besitzer", "Meier, Fridolin"); + Vector products = new Vector(10); + products.addElement("Dinky Dino"); + products.addElement("96er Classic"); + products.addElement("Black Frog"); + products.addElement("SmartGotchi"); + products.addElement("Pretty Dolly"); + tos.putObject("produkte", products); + try { + tos.save(); + } catch (IOException e) { + System.err.println(e.toString()); + } + + //Einlesen des Objektspeichers + TrivialObjectStore tos2 = new TrivialObjectStore("shop"); + try { + tos2.load(); + Enumeration names = tos2.getAllNames(); + while (names.hasMoreElements()) { + String name = (String)names.nextElement(); + Object obj = tos2.getObject(name); + System.out.print(name + ": "); + System.out.println(obj.getClass().toString()); + if (obj instanceof Collection) { + Iterator it = ((Collection)obj).iterator(); + while (it.hasNext()) { + System.out.println(" " + it.next().toString()); + } + } else { + System.out.println(" " + obj.toString()); + } + } + } catch (IOException e) { + System.err.println(e.toString()); + } catch (ClassNotFoundException e) { + System.err.println(e.toString()); + } + } +} \ No newline at end of file -- cgit v1.2.3