// Path: game-common/src/main/java/com/game/common/util/PersistenceManager.java
// public class PersistenceManager {
// 	private static final Logger log = LoggerFactory.getLogger(PersistenceManager.class);
// 
// 	public class PacketHandler {
// 		public Packet.Type[] types;
// 		public Class<?> handler;
// 	}
// 
// 	public class ItemHandler {
// 		public int[] ids;
// 		public Class<?> handler;
// 	}
// 
// 	protected static final XStream xstream;
// 
// 	static {
// 		xstream = new XStream();
// 
// 		xstream.alias("type", Packet.Type.class);
// 
// 		xstream.alias("PacketHandler", PacketHandler.class);
// 		xstream.alias("ItemHandler", ItemHandler.class);
// 
// 		xstream.alias("ItemDef", Item.Definition.class);
// 		xstream.alias("TileDef", Tile.Definition.class);
// 	}
// 
// 	public static void alias(String name, Class<?> type) {
// 		xstream.alias(name, type);
// 	}
// 
// 	public static Object load(URL path) {
// 		try {
// 			InputStream in = path.openStream();
// 			Object o = xstream.fromXML(in);
// 			in.close();
// 
// 			return o;
// 		}
// 		catch (IOException ioe) {
// 			log.error("Error loading object: " + ioe.getMessage());
// 			System.exit(1); // fatal error
// 
// 			return null;
// 		}
// 	}
// 
// 	public static void save(Object o, File f) throws IOException {
// 		OutputStream out = new FileOutputStream(f);
// 		xstream.toXML(o, out);
// 		out.close();
// 	}
// }


import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.URL;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.game.common.util.PersistenceManager;
package com.game.common.model;




public class Item implements Serializable {
	private static final Logger log = LoggerFactory.getLogger(Item.class);
	private static final long serialVersionUID = 1L;

	protected static final Map<Integer, Definition> definitions;

	static {
		definitions = Item.loadDefinitions();

		if (log.isDebugEnabled())
			log.debug("Loaded " + definitions.size() + " item definitions");
	}

	public static Map<Integer, Definition> getDefinitions() {
		return definitions;
	}

	// do nothing - static {} does the work
	public static void load() { }

	@SuppressWarnings("unchecked")
	private static Map<Integer, Definition> loadDefinitions() {
		URL path = Item.class.getResource("items.xml");
		if (path == null) {
			log.error("Unable to find items.xml resource");
			System.exit(1); // fatal error
			return null;
		}

// Path: game-common/src/main/java/com/game/common/util/PersistenceManager.java
// public class PersistenceManager {
// 	private static final Logger log = LoggerFactory.getLogger(PersistenceManager.class);
// 
// 	public class PacketHandler {
// 		public Packet.Type[] types;
// 		public Class<?> handler;
// 	}
// 
// 	public class ItemHandler {
// 		public int[] ids;
// 		public Class<?> handler;
// 	}
// 
// 	protected static final XStream xstream;
// 
// 	static {
// 		xstream = new XStream();
// 
// 		xstream.alias("type", Packet.Type.class);
// 
// 		xstream.alias("PacketHandler", PacketHandler.class);
// 		xstream.alias("ItemHandler", ItemHandler.class);
// 
// 		xstream.alias("ItemDef", Item.Definition.class);
// 		xstream.alias("TileDef", Tile.Definition.class);
// 	}
// 
// 	public static void alias(String name, Class<?> type) {
// 		xstream.alias(name, type);
// 	}
// 
// 	public static Object load(URL path) {
// 		try {
// 			InputStream in = path.openStream();
// 			Object o = xstream.fromXML(in);
// 			in.close();
// 
// 			return o;
// 		}
// 		catch (IOException ioe) {
// 			log.error("Error loading object: " + ioe.getMessage());
// 			System.exit(1); // fatal error
// 
// 			return null;
// 		}
// 	}
// 
// 	public static void save(Object o, File f) throws IOException {
// 		OutputStream out = new FileOutputStream(f);
// 		xstream.toXML(o, out);
// 		out.close();
// 	}
// }


// Path: game-common/src/main/java/com/game/common/model/Item.java
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.URL;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.game.common.util.PersistenceManager;

package com.game.common.model;




public class Item implements Serializable {
	private static final Logger log = LoggerFactory.getLogger(Item.class);
	private static final long serialVersionUID = 1L;

	protected static final Map<Integer, Definition> definitions;

	static {
		definitions = Item.loadDefinitions();

		if (log.isDebugEnabled())
			log.debug("Loaded " + definitions.size() + " item definitions");
	}

	public static Map<Integer, Definition> getDefinitions() {
		return definitions;
	}

	// do nothing - static {} does the work
	public static void load() { }

	@SuppressWarnings("unchecked")
	private static Map<Integer, Definition> loadDefinitions() {
		URL path = Item.class.getResource("items.xml");
		if (path == null) {
			log.error("Unable to find items.xml resource");
			System.exit(1); // fatal error
			return null;
		}

		return (Map<Integer, Definition>) PersistenceManager.load(path);