本文整理汇总了Java中org.eclipse.leshan.core.model.ResourceModel.Type类的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于org.eclipse.leshan.core.model.ResourceModel包,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getType
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
public ResourceModel.Type getType() {
if (booleanValue != null) {
return Type.BOOLEAN;
}
if (floatValue != null) {
return Type.FLOAT;
}
if (objectLinkValue != null) {
// TODO handle object link or not ..
return null;
}
if (stringValue != null) {
return Type.STRING;
}
return null;
}
示例2: deserialize
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
@Override
public ResourceModel deserialize(JsonElement json, java.lang.reflect.Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
if (json == null)
return null;
if (!json.isJsonObject())
return null;
JsonObject jsonObject = json.getAsJsonObject();
if (!jsonObject.has("id"))
return null;
int id = jsonObject.get("id").getAsInt();
String name = jsonObject.get("name").getAsString();
Operations operations = Operations.valueOf(jsonObject.get("operations").getAsString());
String instancetype = jsonObject.get("instancetype").getAsString();
boolean mandatory = jsonObject.get("mandatory").getAsBoolean();
Type type = Type.valueOf(jsonObject.get("type").getAsString().toUpperCase());
String range = jsonObject.get("range").getAsString();
String units = jsonObject.get("units").getAsString();
String description = jsonObject.get("description").getAsString();
return new ResourceModel(id, name, operations, "multiple".equals(instancetype), mandatory, type, range, units,
description);
}
示例3: newResource
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
public static LwM2mMultipleResource newResource(int id, Map<Integer, ?> values, Type type) {
switch (type) {
case INTEGER:
Validate.allElementsOfType(values.values(), Long.class);
break;
case FLOAT:
Validate.allElementsOfType(values.values(), Double.class);
break;
case BOOLEAN:
Validate.allElementsOfType(values.values(), Boolean.class);
break;
case OPAQUE:
Validate.allElementsOfType(values.values(), byte[].class);
break;
case STRING:
Validate.allElementsOfType(values.values(), String.class);
break;
case TIME:
Validate.allElementsOfType(values.values(), Date.class);
break;
default:
throw new IllegalArgumentException(String.format("Type %s is not supported", type.name()));
}
return new LwM2mMultipleResource(id, values, type);
}
示例4: newResource
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
public static LwM2mSingleResource newResource(int id, Object value, Type type) {
switch (type) {
case INTEGER:
if (value instanceof Long)
break;
case FLOAT:
if (value instanceof Double)
break;
case BOOLEAN:
if (value instanceof Boolean)
break;
case OPAQUE:
if (value instanceof byte[])
break;
case STRING:
if (value instanceof String)
break;
case TIME:
if (value instanceof Date)
break;
throw new IllegalArgumentException("Value does not match the given datatype");
default:
throw new IllegalArgumentException(String.format("Type %s is not supported", type.name()));
}
return new LwM2mSingleResource(id, value, type);
}
示例5: equals
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
LwM2mSingleResource other = (LwM2mSingleResource) obj;
if (id != other.id)
return false;
if (type != other.type)
return false;
if (value == null) {
if (other.value != null)
return false;
} else {
// Custom equals to handle byte arrays
return type == Type.OPAQUE ? Arrays.equals((byte[]) value, (byte[]) other.value) : value
.equals(other.value);
}
return true;
}
示例6: encodeTlvValue
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
private byte[] encodeTlvValue(Object value, Type type) {
LOG.trace("Encoding value {} in TLV", value);
switch (type) {
case STRING:
return TlvEncoder.encodeString((String) value);
case INTEGER:
return TlvEncoder.encodeInteger((Number) value);
case FLOAT:
return TlvEncoder.encodeFloat((Number) value);
case BOOLEAN:
return TlvEncoder.encodeBoolean((Boolean) value);
case TIME:
return TlvEncoder.encodeDate((Date) value);
case OPAQUE:
return (byte[]) value;
default:
throw new IllegalArgumentException("Invalid value type: " + type);
}
}
示例7: parseResourceTlv
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
private static LwM2mResource parseResourceTlv(Tlv tlv, int objectId, int objectInstanceId, LwM2mModel model)
throws InvalidValueException {
LwM2mPath resourcePath = new LwM2mPath(objectId, objectInstanceId, tlv.getIdentifier());
Type expectedType = getResourceType(resourcePath, model);
Integer resourceId = tlv.getIdentifier();
switch (tlv.getType()) {
case MULTIPLE_RESOURCE:
return LwM2mMultipleResource.newResource(resourceId,
parseTlvValues(tlv.getChildren(), expectedType, resourcePath), expectedType);
case RESOURCE_VALUE:
return LwM2mSingleResource.newResource(resourceId,
parseTlvValue(tlv.getValue(), expectedType, resourcePath), expectedType);
default:
throw new InvalidValueException("Invalid TLV value", resourcePath);
}
}
示例8: parseTlvValue
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
private static Object parseTlvValue(byte[] value, Type expectedType, LwM2mPath path) throws InvalidValueException {
try {
LOG.trace("TLV value for path {} and expected type {}: {}", path, expectedType, value);
switch (expectedType) {
case STRING:
return TlvDecoder.decodeString(value);
case INTEGER:
return TlvDecoder.decodeInteger(value).longValue();
case FLOAT:
return TlvDecoder.decodeFloat(value).doubleValue();
case BOOLEAN:
return TlvDecoder.decodeBoolean(value);
case TIME:
return TlvDecoder.decodeDate(value);
case OPAQUE:
return value;
default:
throw new InvalidValueException("Unsupported type " + expectedType, path);
}
} catch (TlvException e) {
throw new InvalidValueException("Invalid content for type " + expectedType, path, e);
}
}
示例9: setResourceValue
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
private void setResourceValue(Object value, Type type, JsonArrayEntry jsonResource) {
LOG.trace("Encoding value {} in JSON", value);
// Following table 20 in the Specs
switch (type) {
case STRING:
jsonResource.setStringValue((String) value);
break;
case INTEGER:
case FLOAT:
jsonResource.setFloatValue((Number) value);
break;
case BOOLEAN:
jsonResource.setBooleanValue((Boolean) value);
break;
case TIME:
// Specs device object example page 44, rec 13 is Time
// represented as float?
jsonResource.setFloatValue((((Date) value).getTime() / 1000L));
break;
case OPAQUE:
jsonResource.setStringValue(Base64.encodeBase64String((byte[]) value));
break;
default:
throw new IllegalArgumentException("Invalid value type: " + type);
}
}
示例10: createObjectModels
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
protected List<ObjectModel> createObjectModels() {
// load default object from the spec
List<ObjectModel> objectModels = ObjectLoader.loadDefault();
// define custom model for testing purpose
ResourceModel stringfield = new ResourceModel(STRING_RESOURCE_ID, "stringres", Operations.RW, false, false,
Type.STRING, null, null, null);
ResourceModel booleanfield = new ResourceModel(BOOLEAN_RESOURCE_ID, "booleanres", Operations.RW, false, false,
Type.BOOLEAN, null, null, null);
ResourceModel integerfield = new ResourceModel(INTEGER_RESOURCE_ID, "integerres", Operations.RW, false, false,
Type.INTEGER, null, null, null);
ResourceModel floatfield = new ResourceModel(FLOAT_RESOURCE_ID, "floatres", Operations.RW, false, false,
Type.FLOAT, null, null, null);
ResourceModel timefield = new ResourceModel(TIME_RESOURCE_ID, "timeres", Operations.RW, false, false, Type.TIME,
null, null, null);
ResourceModel opaquefield = new ResourceModel(OPAQUE_RESOURCE_ID, "opaque", Operations.RW, false, false,
Type.OPAQUE, null, null, null);
ResourceModel objlnkfield = new ResourceModel(OBJLNK_MULTI_INSTANCE_RESOURCE_ID, "objlnk", Operations.RW, true,
false, Type.OBJLNK, null, null, null);
ResourceModel objlnkSinglefield = new ResourceModel(OBJLNK_SINGLE_INSTANCE_RESOURCE_ID, "objlnk", Operations.RW,
false, false, Type.OBJLNK, null, null, null);
objectModels.add(new ObjectModel(TEST_OBJECT_ID, "testobject", null, ObjectModel.DEFAULT_VERSION, false, false,
stringfield, booleanfield, integerfield, floatfield, timefield, opaquefield, objlnkfield,
objlnkSinglefield));
return objectModels;
}
示例11: deserialize
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
@Override
public ResourceModel deserialize(JsonObject o) {
if (o == null)
return null;
if (!o.isObject())
return null;
int id = o.getInt("id", -1);
if (id < 0)
return null;
String name = o.getString("name", null);
Operations operations = Operations.valueOf(o.getString("operations", null));
String instancetype = o.getString("instancetype", null);
boolean mandatory = o.getBoolean("mandatory", false);
Type type = Type.valueOf(o.getString("type", "").toUpperCase());
String range = o.getString("range", null);
String units = o.getString("units", null);
String description = o.getString("description", null);
return new ResourceModel(id, name, operations, "multiple".equals(instancetype), mandatory, type, range, units,
description);
}
示例12: encodeTlvValue
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
private byte[] encodeTlvValue(Object value, Type type, LwM2mPath path) {
LOG.trace("Encoding value {} in TLV", value);
try {
switch (type) {
case STRING:
return TlvEncoder.encodeString((String) value);
case INTEGER:
return TlvEncoder.encodeInteger((Number) value);
case FLOAT:
return TlvEncoder.encodeFloat((Number) value);
case BOOLEAN:
return TlvEncoder.encodeBoolean((Boolean) value);
case TIME:
return TlvEncoder.encodeDate((Date) value);
case OPAQUE:
return (byte[]) value;
case OBJLNK:
return TlvEncoder.encodeObjlnk((ObjectLink) value);
default:
throw new CodecException("Invalid value %s for type %s of %s", value, type, path);
}
} catch (IllegalArgumentException e) {
throw new CodecException(e, "Invalid value %s for type %s of %s", value, type, path);
}
}
示例13: parseResourceTlv
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
private static LwM2mResource parseResourceTlv(Tlv tlv, int objectId, int objectInstanceId, LwM2mModel model)
throws CodecException {
LwM2mPath resourcePath = new LwM2mPath(objectId, objectInstanceId, tlv.getIdentifier());
Type expectedType = getResourceType(resourcePath, model);
Integer resourceId = tlv.getIdentifier();
switch (tlv.getType()) {
case MULTIPLE_RESOURCE:
return LwM2mMultipleResource.newResource(resourceId,
parseTlvValues(tlv.getChildren(), expectedType, resourcePath), expectedType);
case RESOURCE_VALUE:
return LwM2mSingleResource.newResource(resourceId,
parseTlvValue(tlv.getValue(), expectedType, resourcePath), expectedType);
default:
throw new CodecException("Invalid TLV type %s for resource %s", tlv.getType(), resourcePath);
}
}
示例14: parseTlvValue
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
private static Object parseTlvValue(byte[] value, Type expectedType, LwM2mPath path) throws CodecException {
try {
LOG.trace("TLV value for path {} and expected type {}: {}", path, expectedType, value);
switch (expectedType) {
case STRING:
return TlvDecoder.decodeString(value);
case INTEGER:
return TlvDecoder.decodeInteger(value).longValue();
case FLOAT:
return TlvDecoder.decodeFloat(value).doubleValue();
case BOOLEAN:
return TlvDecoder.decodeBoolean(value);
case TIME:
return TlvDecoder.decodeDate(value);
case OPAQUE:
return value;
case OBJLNK:
return TlvDecoder.decodeObjlnk(value);
default:
throw new CodecException("Unsupported type %s for path %s", expectedType, path);
}
} catch (TlvException e) {
throw new CodecException(e, "Invalid content [%s] for type %s for path %s", Hex.encodeHexString(value),
expectedType, path);
}
}
示例15: setResourceValue
import org.eclipse.leshan.core.model.ResourceModel.Type; //导入依赖的package包/类
private void setResourceValue(Object value, Type type, JsonArrayEntry jsonResource, LwM2mPath resourcePath) {
LOG.trace("Encoding value {} in JSON", value);
// Following table 20 in the Specs
switch (type) {
case STRING:
jsonResource.setStringValue((String) value);
break;
case INTEGER:
case FLOAT:
jsonResource.setFloatValue((Number) value);
break;
case BOOLEAN:
jsonResource.setBooleanValue((Boolean) value);
break;
case TIME:
// Specs device object example page 44, rec 13 is Time
// represented as float?
jsonResource.setFloatValue((((Date) value).getTime() / 1000L));
break;
case OPAQUE:
jsonResource.setStringValue(Base64.encodeBase64String((byte[]) value));
break;
default:
throw new CodecException("Invalid value type %s for %s", type, resourcePath);
}
}