本文整理汇总了Java中org.eclipse.leshan.core.model.ObjectModel类的典型用法代码示例。如果您正苦于以下问题:Java ObjectModel类的具体用法?Java ObjectModel怎么用?Java ObjectModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectModel类属于org.eclipse.leshan.core.model包,在下文中一共展示了ObjectModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResourceModelInfo
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的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;
}
示例2: serialize
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的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;
}
示例3: deserialize
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的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);
}
示例4: getFactoryFor
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的package包/类
protected LwM2mInstanceEnablerFactory getFactoryFor(ObjectModel objectModel) {
// if we have a factory for this object id, return it
LwM2mInstanceEnablerFactory instanceFactory = factories.get(objectModel.id);
if (instanceFactory != null)
return instanceFactory;
// if there are no factory for this object check in instance list.
LwM2mInstanceEnabler[] instances = this.instances.get(objectModel.id);
if (instances != null) {
for (LwM2mInstanceEnabler instance : instances) {
// check if the class of this instance has a default constructors;
try {
Class<? extends LwM2mInstanceEnabler> clazz = instance.getClass();
clazz.getConstructor();
return getClassFactory(clazz);
} catch (NoSuchMethodException e) {
// no default constructor.
}
}
}
// default class :
return defaultFactory;
}
示例5: createObjectModels
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的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;
}
示例6: deserialize
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的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);
}
示例7: des_ser_must_be_equals
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的package包/类
@Test
public void des_ser_must_be_equals() throws IOException {
// load file
InputStream inputStream = ObjectModelSerDesTest.class.getResourceAsStream("/model.json");
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
String smodel = result.toString("UTF-8");
// deserialize
ObjectModelSerDes serDes = new ObjectModelSerDes();
JsonValue json = Json.parse(smodel);
List<ObjectModel> models = serDes.deserialize(json.asArray());
// serialize
JsonArray arr = serDes.jSerialize(models);
String res = arr.toString(WriterConfig.PRETTY_PRINT);
Assert.assertEquals("value should be equals", smodel, res);
}
示例8: ObjectSpecServlet
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的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;
}
示例9: doGet
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (req.getPathInfo() == null) {
LwM2mModel model = modelProvider.getObjectModel(null);
String json = this.gson.toJson(model.getObjectModels().toArray(new ObjectModel[] {}));
System.out.println(json);
resp.setContentType("application/json");
resp.getOutputStream().write(json.getBytes(StandardCharsets.UTF_8));
resp.setStatus(HttpServletResponse.SC_OK);
return;
}
}
示例10: visit
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的package包/类
@Override
public void visit(LwM2mObject object) {
LOG.trace("Encoding object {} into TLV", object);
Tlv[] tlvs = null;
ObjectModel objectModel = model.getObjectModel(object.getId());
if (objectModel != null && !objectModel.multiple) {
// single instance object, the instance is level is not needed
tlvs = encodeResources(object.getInstance(0).getResources().values());
} else {
// encoded as an array of instances
tlvs = new Tlv[object.getInstances().size()];
int i = 0;
for (Entry<Integer, LwM2mObjectInstance> instance : object.getInstances().entrySet()) {
Tlv[] resources = encodeResources(instance.getValue().getResources().values());
tlvs[i] = new Tlv(TlvType.OBJECT_INSTANCE, resources, null, instance.getKey());
i++;
}
}
try {
out.write(TlvEncoder.encode(tlvs).array());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例11: doGet
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (req.getPathInfo() == null) {
LwM2mModel model = modelProvider.getObjectModel(null);
String json = this.gson.toJson(model.getObjectModels().toArray(new ObjectModel[] {}));
resp.setContentType("application/json");
resp.getOutputStream().write(json.getBytes("UTF-8"));
resp.setStatus(HttpServletResponse.SC_OK);
return;
}
}
示例12: ObjectEnabler
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的package包/类
public ObjectEnabler(int id, ObjectModel objectModel, Map<Integer, LwM2mInstanceEnabler> instances,
LwM2mInstanceEnablerFactory instanceFactory) {
super(id, objectModel);
this.instances = new HashMap<>(instances);
this.instanceFactory = instanceFactory;
for (Entry<Integer, LwM2mInstanceEnabler> entry : this.instances.entrySet()) {
addInstance(entry.getKey(), entry.getValue());
}
}
示例13: setInstancesForObject
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的package包/类
public void setInstancesForObject(int objectId, LwM2mInstanceEnabler... instances) {
ObjectModel objectModel = model.getObjectModel(objectId);
if (objectModel == null) {
throw new IllegalArgumentException(
"Cannot set Instances Class for Object " + objectId + " because no model is defined for this id.");
}
Validate.notNull(instances);
Validate.notEmpty(instances);
if (instances.length > 1 && !objectModel.multiple)
throw new IllegalArgumentException("Cannot set more than one instance for the single Object " + objectId);
this.instances.put(objectId, instances);
}
示例14: createMandatory
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的package包/类
public List<LwM2mObjectEnabler> createMandatory() {
Collection<ObjectModel> objectModels = model.getObjectModels();
List<LwM2mObjectEnabler> enablers = new ArrayList<>();
for (ObjectModel objectModel : objectModels) {
if (objectModel.mandatory) {
ObjectEnabler objectEnabler = createNodeEnabler(objectModel);
if (objectEnabler != null)
enablers.add(objectEnabler);
}
}
return enablers;
}
示例15: create
import org.eclipse.leshan.core.model.ObjectModel; //导入依赖的package包/类
public LwM2mObjectEnabler create(int objectId) {
ObjectModel objectModel = model.getObjectModel(objectId);
if (objectModel == null) {
throw new IllegalArgumentException(
"Cannot create object for id " + objectId + " because no model is defined for this id.");
}
return createNodeEnabler(objectModel);
}