package net.sf.arianne.marboard.server.core.engine;
import marauroa.common.game.RPObject;
import marauroa.server.game.rp.RPObjectFactory;
import net.sf.arianne.marboard.server.entity.meta.User;
import net.sf.arianne.marboard.server.entity.shape.Dot;
import net.sf.arianne.marboard.server.entity.shape.Oval;
import net.sf.arianne.marboard.server.entity.shape.Rectangle;
import net.sf.arianne.marboard.server.entity.shape.StraightLine;
/**
* Creates concrete objects of Marboard classes.
*
* @author hendrik
*/
public class MarboardObjectFactory extends RPObjectFactory {
private static RPObjectFactory singleton;
/**
* returns the factory instance (this method is called
* by Marauroa using reflection).
*
* @return RPObjectFactory
*/
public static RPObjectFactory getFactory() {
if (singleton == null) {
singleton = new MarboardObjectFactory();
}
return singleton;
}
/**
* This method is called when object is serialized back from database to
* zone, so you can define which subclass of RPObject we are going to use.
* This implements a factory pattern.
*
* @param object the original object
* @return the new instance of the object
*/
@Override
public RPObject transform(RPObject object) {
String rpclass = object.getRPClass().getName();
if (rpclass.equals("user")) {
return new User(object);
} else if (rpclass.equals("dot")) {
return new Dot(object);
} else if (rpclass.equals("rectangle")) {
return new Rectangle(object);
} else if (rpclass.equals("straight_line")) {
return new StraightLine(object);
} else if (rpclass.equals("circle")) {
return new Oval(object);
}
return super.transform(object);
}
}