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


Java Type.OPAQUE属性代码示例

本文整理汇总了Java中org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE属性的典型用法代码示例。如果您正苦于以下问题:Java Type.OPAQUE属性的具体用法?Java Type.OPAQUE怎么用?Java Type.OPAQUE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.eclipse.leshan.core.model.ResourceModel.Type的用法示例。


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

示例1: equals

@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;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:23,代码来源:LwM2mSingleResource.java

示例2: createObjectModels

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,代码行数:26,代码来源:IntegrationTestHelper.java

示例3: hashCode

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + id;
    result = prime * result + ((type == null) ? 0 : type.hashCode());
    if (type == Type.OPAQUE) {
        // Custom hashcode to handle byte arrays
        result = prime * result + ((value == null) ? 0 : Arrays.hashCode((byte[]) value));
    } else {
        result = prime * result + ((value == null) ? 0 : value.hashCode());
    }
    return result;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:14,代码来源:LwM2mSingleResource.java

示例4: getResourceType

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,代码行数:10,代码来源:LwM2mNodeTlvDecoder.java

示例5: decode

public static LwM2mNode decode(byte[] content, LwM2mPath path, LwM2mModel model) throws InvalidValueException {
    // single resource value
    Validate.notNull(path.getResourceId());
    ResourceModel desc = model.getResourceModel(path.getObjectId(), path.getResourceId());
    if (desc != null && desc.type != Type.OPAQUE) {
        throw new InvalidValueException(
                "Invalid content format, OPAQUE can only be used for single OPAQUE resource", path);
    }
    return LwM2mSingleResource.newBinaryResource(path.getResourceId(), content);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:10,代码来源:LwM2mNodeOpaqueDecoder.java

示例6: visit

@Override
public void visit(LwM2mResource resource) {
    if (resource.isMultiInstances()) {
        throw new IllegalArgumentException("Mulitple instances resource cannot be encoded in opaque format");
    }
    ResourceModel rSpec = model.getResourceModel(objectId, resource.getId());
    if (rSpec != null && rSpec.type != Type.OPAQUE) {
        throw new IllegalArgumentException("Only single opaque resource can be encoded in opaque format");
    }
    LOG.trace("Encoding resource {} into text", resource);
    Object value = Lwm2mNodeEncoderUtil.convertValue(resource.getValue(), resource.getType(), Type.OPAQUE);
    encoded = (byte[]) value;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:13,代码来源:LwM2mNodeOpaqueEncoder.java

示例7: internalMapEquals

/**
 * This is a copy of {@link AbstractMap#equals(Object)} with custom code to handle byte array equality
 */
private boolean internalMapEquals(Map<?, ?> m1, Object o2) {
    if (o2 == this)
        return true;

    if (!(o2 instanceof Map))
        return false;
    Map<?, ?> m2 = (Map<?, ?>) o2;
    if (m2.size() != m1.size())
        return false;

    try {
        for (Object o : m1.entrySet()) {
            Entry<?, ?> e = (Entry<?, ?>) o;
            Object key = e.getKey();
            Object value = e.getValue();
            if (value == null) {
                if (!(m2.get(key) == null && m2.containsKey(key)))
                    return false;
            } else {
                // Custom equals to handle byte arrays
                return type == Type.OPAQUE ? Arrays.equals((byte[]) value, (byte[]) m2.get(key)) : value.equals(m2
                        .get(key));
            }
        }
    } catch (ClassCastException | NullPointerException unused) {
        return false;
    }

    return true;
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:33,代码来源:LwM2mMultipleResource.java

示例8: getResourceType

public static Type getResourceType(LwM2mPath rscPath, LwM2mModel model) throws CodecException {
    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:eclipse,项目名称:leshan,代码行数:10,代码来源:LwM2mNodeTlvDecoder.java

示例9: decode

public static LwM2mNode decode(byte[] content, LwM2mPath path, LwM2mModel model) throws CodecException {
    if (!path.isResource())
        throw new CodecException("Invalid path %s : OpaqueDecoder decodes resource only", path);

    ResourceModel desc = model.getResourceModel(path.getObjectId(), path.getResourceId());
    if (desc != null && desc.type != Type.OPAQUE) {
        throw new CodecException(
                "Invalid content format [%s] for path [%s], OPAQUE can only be used for single OPAQUE resource",
                desc.type, path);
    }
    return LwM2mSingleResource.newBinaryResource(path.getResourceId(), content);
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:12,代码来源:LwM2mNodeOpaqueDecoder.java

示例10: WriteRequest

private WriteRequest(final Mode mode, ContentFormat format, final LwM2mPath target, final LwM2mNode node) {
    super(target);
    Validate.notNull(mode);
    Validate.notNull(node);

    // Validate Mode
    if (getPath().isResource() && mode == Mode.UPDATE) {
        throw new IllegalArgumentException(
                String.format("Invalid mode for '%s': update is not allowed on resource", target.toString()));
    }

    // Validate node and path coherence
    if (getPath().isResource()) {
        if (!(node instanceof LwM2mResource)) {
            throw new IllegalArgumentException(String.format("path '%s' and node type '%s' does not match",
                    target.toString(), node.getClass().getSimpleName()));
        }
    } else if (getPath().isObjectInstance()) {
        if (!(node instanceof LwM2mObjectInstance)) {
            throw new IllegalArgumentException(String.format("path '%s' and node type '%s' does not match",
                    target.toString(), node.getClass().getSimpleName()));
        }
    } else if (getPath().isObject()) {
        throw new IllegalArgumentException("write request cannot target an object: " + target.toString());
    }

    // Validate content format
    if (ContentFormat.TEXT == format || ContentFormat.OPAQUE == format) {
        if (!getPath().isResource()) {
            throw new IllegalArgumentException(
                    String.format("%s format must be used only for single resources", format.toString()));
        } else {
            LwM2mResource resource = (LwM2mResource) node;
            if (resource.isMultiInstances()) {
                throw new IllegalArgumentException(
                        String.format("%s format must be used only for single resources", format.toString()));
            } else {
                if (resource.getType() == Type.OPAQUE && format == ContentFormat.TEXT) {
                    throw new IllegalArgumentException(
                            "TEXT format must not be used for byte array single resources");
                } else if (resource.getType() != Type.OPAQUE && format == ContentFormat.OPAQUE) {
                    throw new IllegalArgumentException(
                            "OPAQUE format must be used only for byte array single resources");
                }
            }
        }
    }

    this.node = node;
    if (format == null) {
        this.contentFormat = ContentFormat.TLV; // use TLV as default content type
    } else {
        this.contentFormat = format;
    }
    this.mode = mode;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:56,代码来源:WriteRequest.java

示例11: BootstrapWriteRequest

public BootstrapWriteRequest(final LwM2mPath target, final LwM2mNode node, ContentFormat format) {
    super(target);
    Validate.notNull(node);

    // Validate node and path coherence
    if (getPath().isResource()) {
        if (!(node instanceof LwM2mResource)) {
            throw new IllegalArgumentException(String.format("path '%s' and node type '%s' does not match",
                    target.toString(), node.getClass().getSimpleName()));
        }
    } else if (getPath().isObjectInstance()) {
        if (!(node instanceof LwM2mObjectInstance)) {
            throw new IllegalArgumentException(String.format("path '%s' and node type '%s' does not match",
                    target.toString(), node.getClass().getSimpleName()));
        }
    } else if (getPath().isObject()) {
        if (!(node instanceof LwM2mObject)) {
            throw new IllegalArgumentException(String.format("path '%s' and node type '%s' does not match",
                    target.toString(), node.getClass().getSimpleName()));
        }
    }

    // Validate content format
    if (ContentFormat.TEXT == format || ContentFormat.OPAQUE == format) {
        if (!getPath().isResource()) {
            throw new IllegalArgumentException(
                    String.format("%s format must be used only for single resources", format.toString()));
        } else {
            LwM2mResource resource = (LwM2mResource) node;
            if (resource.isMultiInstances()) {
                throw new IllegalArgumentException(
                        String.format("%s format must be used only for single resources", format.toString()));
            } else {
                if (resource.getType() == Type.OPAQUE && format == ContentFormat.TEXT) {
                    throw new IllegalArgumentException(
                            "TEXT format must not be used for byte array single resources");
                } else if (resource.getType() != Type.OPAQUE && format == ContentFormat.OPAQUE) {
                    throw new IllegalArgumentException(
                            "OPAQUE format must be used only for byte array single resources");
                }
            }
        }
    }

    this.node = node;
    if (format == null) {
        this.contentFormat = ContentFormat.TLV; // use TLV as default content type
    } else {
        this.contentFormat = format;
    }
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:51,代码来源:BootstrapWriteRequest.java

示例12: parseResource

private ResourceModel parseResource(Node item) {

        Integer id = Integer.valueOf(item.getAttributes().getNamedItem("ID").getTextContent());
        String name = null;
        Operations operations = Operations.NONE;
        boolean multiple = false;
        boolean mandatory = false;
        Type type = Type.STRING;
        String rangeEnumeration = null;
        String units = null;
        String description = null;

        for (int i = 0; i < item.getChildNodes().getLength(); i++) {
            Node field = item.getChildNodes().item(i);
            switch (field.getNodeName()) {
            case "Name":
                name = field.getTextContent();
                break;
            case "Operations":
                String strOp = field.getTextContent();
                if (strOp != null && !strOp.isEmpty()) {
                    operations = Operations.valueOf(strOp);
                }
                break;
            case "MultipleInstances":
                multiple = "Multiple".equals(field.getTextContent());
                break;
            case "Mandatory":
                mandatory = "Mandatory".equals(field.getTextContent());
                break;
            case "Type":
                switch (field.getTextContent()) {
                case "String":
                    type = Type.STRING;
                    break;
                case "Integer":
                    type = Type.INTEGER;
                    break;
                case "Float":
                    type = Type.FLOAT;
                    break;
                case "Boolean":
                    type = Type.BOOLEAN;
                    break;
                case "Opaque":
                    type = Type.OPAQUE;
                    break;
                case "Time":
                    type = Type.TIME;
                    break;
                }
                break;
            case "RangeEnumeration":
                rangeEnumeration = field.getTextContent();
                break;
            case "Units":
                units = field.getTextContent();
                break;
            case "Description":
                description = field.getTextContent();
                break;
            }

        }

        return new ResourceModel(id, name, operations, multiple, mandatory, type, rangeEnumeration, units, description);
    }
 
开发者ID:iotoasis,项目名称:SI,代码行数:67,代码来源:DDFFileParser.java

示例13: newBinaryResource

public static LwM2mMultipleResource newBinaryResource(int id, Map<Integer, byte[]> values) {
    Validate.noNullElements(values.values());
    return new LwM2mMultipleResource(id, values, Type.OPAQUE);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:4,代码来源:LwM2mMultipleResource.java

示例14: newBinaryResource

public static LwM2mSingleResource newBinaryResource(int id, byte[] value) {
    return new LwM2mSingleResource(id, value, Type.OPAQUE);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:3,代码来源:LwM2mSingleResource.java

示例15: write

@Override
public WriteResponse write(int resourceId, LwM2mResource value) {
    LOG.debug("Write on resource {}: {}", resourceId, value);

    // restricted to BS server?

    switch (resourceId) {

    case SEC_SERVER_URI: // server uri
        if (value.getType() != Type.STRING) {
            return WriteResponse.badRequest("invalid type");
        }
        serverUri = (String) value.getValue();
        return WriteResponse.success();

    case SEC_BOOTSTRAP: // is bootstrap server
        if (value.getType() != Type.BOOLEAN) {
            return WriteResponse.badRequest("invalid type");
        }
        bootstrapServer = (Boolean) value.getValue();
        return WriteResponse.success();

    case SEC_SECURITY_MODE: // security mode
        if (value.getType() != Type.INTEGER) {
            return WriteResponse.badRequest("invalid type");
        }
        securityMode = ((Long) value.getValue()).intValue();
        return WriteResponse.success();

    case SEC_PUBKEY_IDENTITY: // Public Key or Identity
        if (value.getType() != Type.OPAQUE) {
            return WriteResponse.badRequest("invalid type");
        }
        publicKeyOrIdentity = (byte[]) value.getValue();
        return WriteResponse.success();
    case SEC_SERVER_PUBKEY: // server public key
        if (value.getType() != Type.OPAQUE) {
            return WriteResponse.badRequest("invalid type");
        }
        secretKey = (byte[]) value.getValue();
        return WriteResponse.success();
    case SEC_SECRET_KEY: // Secret Key
        if (value.getType() != Type.OPAQUE) {
            return WriteResponse.badRequest("invalid type");
        }
        secretKey = (byte[]) value.getValue();
        return WriteResponse.success();
    case SEC_SERVER_ID: // short server id
        if (value.getType() != Type.INTEGER) {
            return WriteResponse.badRequest("invalid type");
        }
        shortServerId = ((Long) value.getValue()).intValue();
        return WriteResponse.success();

    default:
        return super.write(resourceId, value);
    }

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


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