View Javadoc
1   package de.fhdw.wtf.persistence.meta;
2   
3   /**
4    * A class to represent an object in the database. An object is identified by its type, which can be a user type or a
5    * base type and an Id which is unique.
6    * 
7    */
8   public abstract class Object extends InstanceItem {
9   	
10  	/**
11  	 * The Type of this Object. Could be a Base Type or an User Object.
12  	 */
13  	private final Type instanceOf;
14  	
15  	/**
16  	 * Protected superclass constructor which must be inherited by its subclasses.
17  	 * 
18  	 * @param instanceOf
19  	 *            The Type of this Object.
20  	 */
21  	protected Object(final Type instanceOf) {
22  		this.instanceOf = instanceOf;
23  	}
24  	
25  	/**
26  	 * Getter for the Type.
27  	 * 
28  	 * @return Provides the Type of this Object.
29  	 */
30  	public Type getInstanceOf() {
31  		return this.instanceOf;
32  	}
33  	
34  	/**
35  	 * A static factory Method for objects. It checks whether the the given Tuple of Object Id and type information is a
36  	 * base type or not and creates a new object instance of this object.
37  	 * 
38  	 * @param id
39  	 *            The Id of the object in the database.
40  	 * @param instance_of
41  	 *            The type information of the Object.
42  	 * @return Provides a new Instance of the given object. If its a BaseType a BaseTypeValue Class will be instantiated
43  	 *         otherwise a new user object will be instantiated.
44  	 */
45  	public static Object checkForBaseTypes(final long id, final Type instance_of) {
46  		if (instance_of.getId() == StringType.getInstance().getId()) {
47  			return new StringValue(id);
48  		} else if (instance_of.getId() == IntegerType.getInstance().getId()) {
49  			return new IntegerValue(id);
50  		} else {
51  			return UserObject.init(id, instance_of);
52  		}
53  	}
54  	
55  	@Override
56  	public String toString() {
57  		return "(" + this.getId() + "," + this.getInstanceOf().toString() + ")";
58  	}
59  	
60  }