当前位置: 首页>>代码示例>>Java>>正文


Java ResourceModel类代码示例

本文整理汇总了Java中org.eclipse.leshan.core.model.ResourceModel的典型用法代码示例。如果您正苦于以下问题:Java ResourceModel类的具体用法?Java ResourceModel怎么用?Java ResourceModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResourceModel类属于org.eclipse.leshan.core.model包,在下文中一共展示了ResourceModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeOperation

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
private void writeOperation(String path, Object value, ResourceModel rm){
	try{
 	String[] path_ary = path.split("/");
 	if(path_ary.length == 5){
 	
 		String epName = path_ary[1];
 		String target = path.substring(epName.length() + 1, path.length());
 		int rsID = Integer.parseInt(path_ary[4]);
 		
  	JSONObject root = new JSONObject();
  	root.put("id", rsID);
root.put("value", value);
  	
  	Registration registration = lwServer.getRegistrationService().getByEndpoint(epName);
  	ContentFormat contentFormat = ContentFormat.fromName("TLV");
	
          // create & process request
         LwM2mNode node = gson.fromJson(root.toString(), LwM2mNode.class);
         WriteRequest request = new WriteRequest(Mode.REPLACE, contentFormat, target, node);
         WriteResponse cResponse = lwServer.send(registration, request, 5000);
 	}
	}catch(Exception exp){
		exp.printStackTrace();
	}
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:26,代码来源:SimpleLwm2mServer.java

示例2: getResourceModelInfo

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
public ResourceModel getResourceModelInfo(String path){
  	ResourceModel mModel = null;
  	try{
  		String[] path_arr = path.split("/");
  		if(path_arr.length == 5){
   		int object_id = Integer.parseInt(path_arr[2]);
   		int resource_id = Integer.parseInt(path_arr[4]);
   		
    	LwM2mModel model = lwServer.getModelProvider().getObjectModel(null);
    	ObjectModel[] allmodels = model.getObjectModels().toArray(new ObjectModel[] {});
    	for(int i = 0; i < allmodels.length; i++){
    		
    		if(object_id == allmodels[i].id){
    			mModel = allmodels[i].resources.get(resource_id);
    			break;
    		}
    	}
  		}
  	}catch (Exception e) {
	// TODO: handle exception
}
  	return mModel;
  }
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:24,代码来源:SimpleLwm2mServer.java

示例3: getType

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的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;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:17,代码来源:JsonArrayEntry.java

示例4: serialize

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
@Override
public JsonElement serialize(ObjectModel object, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject element = new JsonObject();

    // sort resources value
    List<ResourceModel> resourceSpecs = new ArrayList<ResourceModel>(object.resources.values());
    Collections.sort(resourceSpecs, new Comparator<ResourceModel>() {
        @Override
        public int compare(ResourceModel r1, ResourceModel r2) {
            return r1.id - r2.id;
        }
    });

    // serialize fields
    element.addProperty("name", object.name);
    element.addProperty("id", object.id);
    element.addProperty("instancetype", object.multiple ? "multiple" : "single");
    element.addProperty("mandatory", object.mandatory);
    element.addProperty("description", object.description);
    element.add("resourcedefs", context.serialize(resourceSpecs));

    return element;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:24,代码来源:ObjectModelSerializer.java

示例5: deserialize

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的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);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:27,代码来源:ResourceModelDeserializer.java

示例6: serialize

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
@Override
public JsonElement serialize(ResourceModel resource, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject element = new JsonObject();

    element.addProperty("id", resource.id);
    element.addProperty("name", resource.name);
    element.addProperty("operations", resource.operations.toString());
    element.addProperty("instancetype", resource.multiple ? "multiple" : "single");
    element.addProperty("mandatory", resource.mandatory);
    element.addProperty("type", resource.type.toString().toLowerCase());
    element.addProperty("range", resource.rangeEnumeration);
    element.addProperty("units", resource.units);
    element.addProperty("description", resource.description);

    return element;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:17,代码来源:ResourceModelSerializer.java

示例7: deserialize

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
@Override
public ObjectModel deserialize(JsonElement json, 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();
    String instancetype = jsonObject.get("instancetype").getAsString();
    boolean mandatory = jsonObject.get("mandatory").getAsBoolean();
    String description = jsonObject.get("description").getAsString();
    ResourceModel[] resourceSpecs = context.deserialize(jsonObject.get("resourcedefs"), ResourceModel[].class);

    return new ObjectModel(id, name, description, "multiple".equals(instancetype), mandatory, resourceSpecs);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:23,代码来源:ObjectModelDeserializer.java

示例8: observe

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
@Override
public synchronized ObserveResponse observe(ServerIdentity identity, ObserveRequest request) {
    LwM2mPath path = request.getPath();

    // observe is not supported for bootstrap
    if (identity.isLwm2mBootstrapServer())
        return ObserveResponse.methodNotAllowed();

    if (!identity.isSystem()) {
        // observe or read of the security object is forbidden
        if (id == LwM2mId.SECURITY)
            return ObserveResponse.notFound();

        // check if the resource is readable.
        if (path.isResource()) {
            ResourceModel resourceModel = objectModel.resources.get(path.getResourceId());
            if (resourceModel != null && !resourceModel.operations.isReadable())
                return ObserveResponse.methodNotAllowed();
        }
    }
    return doObserve(identity, request);
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:23,代码来源:BaseObjectEnabler.java

示例9: createObjectModels

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的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;
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:27,代码来源:IntegrationTestHelper.java

示例10: deserialize

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的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);
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:25,代码来源:ResourceModelSerDes.java

示例11: deserialize

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
@Override
public ObjectModel 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);
    String instancetype = o.getString("instancetype", null);
    boolean mandatory = o.getBoolean("mandatory", false);
    String description = o.getString("description", null);
    String version = o.getString("version", ObjectModel.DEFAULT_VERSION);
    List<ResourceModel> resourceSpecs = resourceModelSerDes.deserialize(o.get("resourcedefs").asArray());

    return new ObjectModel(id, name, description, version, "multiple".equals(instancetype), mandatory,
            resourceSpecs);
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:23,代码来源:ObjectModelSerDes.java

示例12: decode

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
public static LwM2mNode decode(byte[] content, LwM2mPath path, LwM2mModel model) throws CodecException {
    if (!path.isResource())
        throw new CodecException("Invalid path %s : TextDecoder decodes resource only", path);

    ResourceModel rDesc = model.getResourceModel(path.getObjectId(), path.getResourceId());

    String strValue = content != null ? new String(content, StandardCharsets.UTF_8) : "";
    if (rDesc != null && rDesc.type != null) {
        return LwM2mSingleResource.newResource(path.getResourceId(), parseTextValue(strValue, rDesc.type, path),
                rDesc.type);
    } else {
        // unknown resource, returning a default string value
        return LwM2mSingleResource.newStringResource(path.getResourceId(), strValue);
    }

}
 
开发者ID:eclipse,项目名称:leshan,代码行数:17,代码来源:LwM2mNodeTextDecoder.java

示例13: ObjectSpecServlet

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
public ObjectSpecServlet(LwM2mModelProvider pModelProvider) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeHierarchyAdapter(ObjectModel.class, new ObjectModelSerializer());
    gsonBuilder.registerTypeHierarchyAdapter(ResourceModel.class, new ResourceModelSerializer());
    this.gson = gsonBuilder.create();

    // use the provider from the server and return a model by client
    modelProvider = pModelProvider;
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:10,代码来源:ObjectSpecServlet.java

示例14: controlDevice

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
public void controlDevice(String path, Object value){

ResourceModel mModel = getResourceModelInfo(path);

if(mModel.operations == Operations.RW 
		|| mModel.operations == Operations.W){
	writeOperation(path, value, mModel);
} else if(mModel.operations == Operations.E
		|| mModel.operations == Operations.RE){
	excutionOperation(path);
}
  }
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:13,代码来源:SimpleLwm2mServer.java

示例15: getResourceType

import org.eclipse.leshan.core.model.ResourceModel; //导入依赖的package包/类
public static Type getResourceType(LwM2mPath rscPath, LwM2mModel model) throws InvalidValueException {
    ResourceModel rscDesc = model.getResourceModel(rscPath.getObjectId(), rscPath.getResourceId());
    if (rscDesc == null || rscDesc.type == null) {
        LOG.trace("unknown type for resource : {}", rscPath);
        // no resource description... opaque
        return Type.OPAQUE;
    } else {
        return rscDesc.type;
    }
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:11,代码来源:LwM2mNodeTlvDecoder.java


注:本文中的org.eclipse.leshan.core.model.ResourceModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。