/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.delegate.doctor.checkup;
import beans.doctor.checkup.dicom.DicomDeviceParamsBean;
import beans.doctor.checkup.dicom.DicomDeviceParamsBeanRemote;
import cli_fmw.delegate.DelegateLine2;
import clips.dicom.dicombaseclass.DICOMDeviceParam;
import cli_fmw.main.ClipsException;
import com.thoughtworks.xstream.XStream;
import beans.doctor.checkup.dicom.DicomDeviceParamsDetails;
import cli_fmw.delegate.AuditListener;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom.Document;
import org.jdom.JDOMException;
import framework.utils.Converter;
/**
*
* @author finder
*/
public class DicomDeviceParamsLocal extends DelegateLine2<DicomDeviceParamsBeanRemote, DicomDeviceParamsDetails>{
public DicomDeviceParamsLocal(DicomDeviceParamsDetails d, AuditListener al) {
super(d, al);
}
public DicomDeviceParamsLocal(int initializedID, AuditListener al) {
super(initializedID, al);
}
DicomDeviceParamsLocal(DICOMDeviceParam param, AuditListener al) throws ClipsException {
super((int)param.getDeviceID(), al);
setFrom(param);
}
public DicomDeviceParamsLocal(AuditListener al) {
super(al);
}
@Override
protected DicomDeviceParamsDetails getNewDetails() {
return new DicomDeviceParamsDetails();
}
@Override
protected String getBeanName() {
return DicomDeviceParamsBean.class.getSimpleName();
}
public DICOMDeviceParam getParams() throws ClipsException{
/*DICOMDeviceParam target = new DICOMDeviceParam(
getDetails().userFriendlyName, getDetails().modelName, getDetails().deviceUi,
getDetails().implementationUid, getDetails().implementationVersion);*/
DICOMDeviceParam target;
try {
target = DICOMDeviceParam.fromXml(
Converter.stringToXml(getDetails().configXml).getRootElement(),
getDetails().userFriendlyName, getDetails().modelName, getDetails().deviceUi,
getDetails().implementationUid, getDetails().implementationVersion);
} catch (JDOMException ex) {
ex.printStackTrace();
target = new DICOMDeviceParam(
getDetails().userFriendlyName, getDetails().modelName, getDetails().deviceUi,
getDetails().implementationUid, getDetails().implementationVersion);
}
target.setIpAddres(getDetails().ipAddres);
target.setPort(getDetails().port);
target.setDeviceID(getID());
target.setModifyDate(getDetails().modifyTime);
return target;
}
final public void setFrom(DICOMDeviceParam src) throws ClipsException{
if (!isNewlyCreated()){
if (src.getDeviceID() != getID()){
return;
}
if (src.getModifyDate() == null) {
return;
}
if (getDetails().modifyTime.getTime() > src.getModifyDate().getTime() + 5000){
return;
}
}
getDetails().userFriendlyName = src.getName();
getDetails().modelName = src.getModelName();
getDetails().deviceUi = src.getDeviceUI();
getDetails().implementationUid = src.getImplementationUID();
getDetails().implementationVersion = src.getImplementationVersion();
getDetails().ipAddres = src.getIpAddres();
getDetails().port = src.getPort();
getDetails().configXml = Converter.xmlToString(new Document(src.toXML("deviceParam")));
XStream xstrm = new XStream();
getDetails().configXml = xstrm.toXML(src);
}
@Override
public String toString() {
try {
return getDetails().userFriendlyName;
} catch (ClipsException ex) {
ex.printStackTrace();
}
return "<Ошибка>";
}
}