2012-03-02 21:09:43 +00:00
|
|
|
package de.ctdo.bunti.model;
|
|
|
|
|
2012-03-25 14:23:45 +00:00
|
|
|
import javax.persistence.*;
|
|
|
|
import java.io.Serializable;
|
2012-03-21 22:43:00 +00:00
|
|
|
import javax.persistence.*;
|
2012-03-03 01:29:06 +00:00
|
|
|
import java.util.Map;
|
|
|
|
|
2012-03-09 22:37:26 +00:00
|
|
|
/**
|
|
|
|
* A physical device type in the bunti system.
|
|
|
|
* Maybe this is a lamp, or a switchable power source, or a strobe, ...
|
|
|
|
* @author lucas
|
|
|
|
*/
|
2012-03-21 22:43:00 +00:00
|
|
|
@Entity
|
|
|
|
@Table(name = "devices")
|
|
|
|
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
|
2012-03-03 01:29:06 +00:00
|
|
|
public abstract class BuntiDevice {
|
2012-03-25 14:23:45 +00:00
|
|
|
private int id;
|
2012-03-06 23:42:30 +00:00
|
|
|
private String deviceName;
|
2012-03-13 23:57:00 +00:00
|
|
|
private String picture;
|
2012-03-21 22:43:00 +00:00
|
|
|
|
|
|
|
public BuntiDevice() {
|
|
|
|
|
|
|
|
}
|
2012-03-04 09:50:50 +00:00
|
|
|
|
|
|
|
|
2012-03-09 22:37:26 +00:00
|
|
|
/**
|
|
|
|
* Get the type of this device
|
|
|
|
* @return a string with the class name (=the Type)
|
|
|
|
*/
|
2012-03-21 22:43:00 +00:00
|
|
|
@Transient
|
2012-03-09 22:37:26 +00:00
|
|
|
public final String getType() {
|
|
|
|
String FQClassName = this.getClass().getName();
|
|
|
|
int firstChar = FQClassName.lastIndexOf ('.') + 1;
|
|
|
|
if ( firstChar > 0 ) {
|
|
|
|
FQClassName = FQClassName.substring ( firstChar );
|
|
|
|
}
|
|
|
|
return FQClassName;
|
2012-03-04 09:50:50 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 22:37:26 +00:00
|
|
|
/**
|
|
|
|
* Gets the device Id
|
|
|
|
* @return the device Id
|
|
|
|
*/
|
2012-03-21 22:43:00 +00:00
|
|
|
@Id
|
2012-03-25 14:23:45 +00:00
|
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
|
|
@Column(name = "BUNTIDEVICE_ID", updatable=false, nullable=false)
|
2012-03-21 20:22:53 +00:00
|
|
|
public final int getId() {
|
2012-03-25 14:23:45 +00:00
|
|
|
return id;
|
2012-03-06 23:42:30 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 22:43:00 +00:00
|
|
|
public final void setId(int id) {
|
2012-03-25 14:23:45 +00:00
|
|
|
this.id = id;
|
2012-03-21 22:43:00 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 22:37:26 +00:00
|
|
|
/**
|
|
|
|
* Gets the device name
|
|
|
|
* @return The name of the device
|
|
|
|
*/
|
2012-03-25 14:23:45 +00:00
|
|
|
public String getDeviceName() {
|
2012-03-06 23:42:30 +00:00
|
|
|
return deviceName;
|
|
|
|
}
|
|
|
|
|
2012-03-09 22:37:26 +00:00
|
|
|
/**
|
|
|
|
* Sets the device Name
|
|
|
|
* @param deviceName a String with the device name
|
|
|
|
*/
|
2012-03-25 14:23:45 +00:00
|
|
|
public void setDeviceName(String deviceName) {
|
2012-03-06 23:42:30 +00:00
|
|
|
this.deviceName = deviceName;
|
|
|
|
}
|
|
|
|
|
2012-03-13 23:57:00 +00:00
|
|
|
/**
|
|
|
|
* Get the relative URL to the picture of this device
|
|
|
|
* @return the relative URL to the picture
|
|
|
|
*/
|
2012-03-25 14:23:45 +00:00
|
|
|
public String getPicture() {
|
2012-03-13 23:57:00 +00:00
|
|
|
return picture;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the relative URL to the picture of this device
|
|
|
|
* @param picture The relative URL to the picture
|
|
|
|
*/
|
2012-03-25 14:23:45 +00:00
|
|
|
public void setPicture(String picture) {
|
2012-03-13 23:57:00 +00:00
|
|
|
this.picture = picture;
|
|
|
|
}
|
|
|
|
|
2012-03-06 23:42:30 +00:00
|
|
|
/**
|
|
|
|
* Switch this device off.
|
|
|
|
*/
|
|
|
|
public abstract void switchOff();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch this device on.
|
|
|
|
*/
|
|
|
|
public abstract void switchOn();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The the internal options corresponding to the given Key Value Map
|
|
|
|
*
|
|
|
|
* @param options The options Map.
|
|
|
|
* @return True on success. False otherwise.
|
|
|
|
*/
|
|
|
|
public abstract boolean setValuesFromOptions(Map<String, Object> options);
|
2012-03-02 21:09:43 +00:00
|
|
|
|
2012-03-13 23:57:00 +00:00
|
|
|
|
2012-03-21 22:43:00 +00:00
|
|
|
// @ManyToOne
|
|
|
|
// @JoinColumn(name="ROOM_ID")
|
|
|
|
// public Room getRoom() {
|
|
|
|
// return room;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public void setRoom(Room room) {
|
|
|
|
// this.room = room;
|
|
|
|
// }
|
2012-03-02 21:09:43 +00:00
|
|
|
}
|