bunti/src/main/java/de/ctdo/bunti/model/BuntiDevice.java

116 lines
2.6 KiB
Java

package de.ctdo.bunti.model;
import javax.persistence.*;
import java.io.Serializable;
import javax.persistence.*;
import java.util.Map;
/**
* A physical device type in the bunti system.
* Maybe this is a lamp, or a switchable power source, or a strobe, ...
* @author lucas
*/
@Entity
@Table(name = "devices")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public abstract class BuntiDevice {
private int id;
private String deviceName;
private String picture;
public BuntiDevice() {
}
/**
* Get the type of this device
* @return a string with the class name (=the Type)
*/
@Transient
public final String getType() {
String FQClassName = this.getClass().getName();
int firstChar = FQClassName.lastIndexOf ('.') + 1;
if ( firstChar > 0 ) {
FQClassName = FQClassName.substring ( firstChar );
}
return FQClassName;
}
/**
* Gets the device Id
* @return the device Id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "BUNTIDEVICE_ID", updatable=false, nullable=false)
public final int getId() {
return id;
}
public final void setId(int id) {
this.id = id;
}
/**
* Gets the device name
* @return The name of the device
*/
public String getDeviceName() {
return deviceName;
}
/**
* Sets the device Name
* @param deviceName a String with the device name
*/
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
/**
* Get the relative URL to the picture of this device
* @return the relative URL to the picture
*/
public String getPicture() {
return picture;
}
/**
* Get the relative URL to the picture of this device
* @param picture The relative URL to the picture
*/
public void setPicture(String picture) {
this.picture = picture;
}
/**
* 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);
// @ManyToOne
// @JoinColumn(name="ROOM_ID")
// public Room getRoom() {
// return room;
// }
//
// public void setRoom(Room room) {
// this.room = room;
// }
}