//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
*
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
package com.nexirius.framework.remote;
import com.nexirius.framework.datamodel.DataModel;
import com.nexirius.framework.datamodel.IntModel;
import com.nexirius.framework.datamodel.StringModel;
import com.nexirius.framework.datamodel.StructModel;
import com.nexirius.util.TextToken;
import java.io.PushbackInputStream;
/**
* This class holds a data model remote event
*
* @author Marcel Baumann
*/
public class DataModelRemoteEvent extends StructModel {
public static String COMMAND_GET = "GET";
public static String COMMAND_UPDATE = "UPDATE";
public static String COMMAND_METHOD = "METHOD";
public static String ID = "id";
public static String CHILD_NAME = "childName";
public static String VALUE = "value";
public static String SUBTYPE = "subtype";
public static String INDEX = "index";
public DataModelRemoteEvent() {
}
public int getDataModelID() {
try {
IntModel id = (IntModel) getChild(ID);
return id.getInt();
} catch (Exception ex) {
return -1;
}
}
public String getChildName() {
try {
StringModel m = (StringModel) getChild(CHILD_NAME);
return m.getText();
} catch (Exception ex) {
return null;
}
}
public String getNewValue() {
try {
StringModel m = (StringModel) getChild(VALUE);
return m.getText();
} catch (Exception ex) {
return null;
}
}
public int getSubtype() {
try {
IntModel i = (IntModel) getChild(SUBTYPE);
return i.getInt();
} catch (Exception ex) {
return -1;
}
}
public int getIndex() {
try {
IntModel i = (IntModel) getChild(INDEX);
return i.getInt();
} catch (Exception ex) {
return -1;
}
}
public static DataModelRemoteEvent createEvent(PushbackInputStream in)
throws Exception {
TextToken t = TextToken.nextToken(in);
if (t == null) {
return null;
}
if (t.isIdentifier(COMMAND_UPDATE)) {
return new DataModelUpdateEvent(in);
} else if (t.isIdentifier(COMMAND_GET)) {
return new DataModelGetEvent(in);
} else if (t.isIdentifier(COMMAND_METHOD)) {
return new DataModelMethodEvent(in);
}
throw new Exception("No command '" + t + "'");
}
public String applyOn(DataModel model)
throws Exception {
return "OK";
}
}