本文整理汇总了Java中org.eclipse.milo.opcua.stack.core.types.builtin.Variant.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Variant.getValue方法的具体用法?Java Variant.getValue怎么用?Java Variant.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.milo.opcua.stack.core.types.builtin.Variant
的用法示例。
在下文中一共展示了Variant.getValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFromValueAtRange
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
public static Object readFromValueAtRange(Variant value, NumericRange range) throws UaException {
Object array = value.getValue();
if (array == null) {
throw new UaException(StatusCodes.Bad_IndexRangeNoData);
}
if (!array.getClass().isArray()) {
if (!(array instanceof String) && !(array instanceof ByteString)) {
throw new UaException(StatusCodes.Bad_IndexRangeInvalid);
}
}
try {
return readFromValueAtRange(array, range, 1);
} catch (Throwable ex) {
throw new UaException(StatusCodes.Bad_IndexRangeNoData, ex);
}
}
示例2: writeToValueAtRange
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
public static Object writeToValueAtRange(Variant currentVariant,
Variant updateVariant,
NumericRange range) throws UaException {
Object current = currentVariant.getValue();
Object update = updateVariant.getValue();
if (current == null || update == null) {
throw new UaException(StatusCodes.Bad_IndexRangeNoData);
}
try {
return writeToValueAtRange(current, update, range, 1);
} catch (Throwable ex) {
throw new UaException(StatusCodes.Bad_IndexRangeNoData, ex);
}
}
示例3: run
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
registerCustomCodec();
// synchronous connect
client.connect().get();
// synchronous read request via VariableNode
VariableNode node = client.getAddressSpace().createVariableNode(
new NodeId(2, "HelloWorld/CustomDataTypeVariable"));
logger.info("DataType={}", node.getDataType().get());
DataValue value = node.readValue().get();
logger.info("Value={}", value);
Variant variant = value.getValue();
ExtensionObject xo = (ExtensionObject) variant.getValue();
CustomDataType decoded = xo.decode();
logger.info("Decoded={}", decoded);
future.complete(client);
}
示例4: write
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
@Override
public void write(final WriteContext context, final List<WriteValue> writeValues) {
final List<StatusCode> results = Lists.newArrayListWithCapacity(writeValues.size());
for (final WriteValue writeValue : writeValues) {
try {
final ServerNode node = this.nodeManager.getNode(writeValue.getNodeId())
.orElseThrow(() -> new UaException(StatusCodes.Bad_NodeIdUnknown));
node.writeAttribute(new AttributeContext(context), writeValue.getAttributeId(), writeValue.getValue(),
writeValue.getIndexRange());
if (LOG.isTraceEnabled()) {
final Variant variant = writeValue.getValue().getValue();
final Object o = variant != null ? variant.getValue() : null;
LOG.trace("Wrote value={} to attributeId={} of {}", o, writeValue.getAttributeId(),
writeValue.getNodeId());
}
results.add(StatusCode.GOOD);
} catch (final UaException e) {
results.add(e.getStatusCode());
}
}
context.complete(results);
}
示例5: testVariant_UaStructure
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
@Test
public void testVariant_UaStructure() {
ServiceCounterDataType sc1 = new ServiceCounterDataType(Unsigned.uint(1), Unsigned.uint(2));
Variant v = new Variant(sc1);
writer.writeVariant(v);
Variant decoded = reader.readVariant();
ExtensionObject extensionObject = (ExtensionObject) decoded.getValue();
ServiceCounterDataType sc2 = extensionObject.decode();
Assert.assertEquals(sc1.getTotalCount(), sc2.getTotalCount());
Assert.assertEquals(sc1.getErrorCount(), sc2.getErrorCount());
}
示例6: read
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
@Override
public void read(ReadContext context, Double maxAge, TimestampsToReturn timestamps, List<ReadValueId> readValueIds) {
List<DataValue> results = Lists.newArrayListWithCapacity(readValueIds.size());
for (ReadValueId id : readValueIds) {
ServerNode node = nodeManager.get(id.getNodeId());
if (node != null) {
DataValue value = node.readAttribute(
new AttributeContext(context),
id.getAttributeId(),
timestamps,
id.getIndexRange()
);
if (logger.isTraceEnabled()) {
Variant variant = value.getValue();
Object o = variant != null ? variant.getValue() : null;
logger.trace("Read value={} from attributeId={} of {}",
o, id.getAttributeId(), id.getNodeId());
}
results.add(value);
} else {
results.add(new DataValue(new StatusCode(StatusCodes.Bad_NodeIdUnknown)));
}
}
context.complete(results);
}
示例7: write
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
@Override
public void write(WriteContext context, List<WriteValue> writeValues) {
List<StatusCode> results = Lists.newArrayListWithCapacity(writeValues.size());
for (WriteValue writeValue : writeValues) {
try {
ServerNode node = nodeManager.getNode(writeValue.getNodeId())
.orElseThrow(() -> new UaException(StatusCodes.Bad_NodeIdUnknown));
node.writeAttribute(
new AttributeContext(context),
writeValue.getAttributeId(),
writeValue.getValue(),
writeValue.getIndexRange()
);
if (logger.isTraceEnabled()) {
Variant variant = writeValue.getValue().getValue();
Object o = variant != null ? variant.getValue() : null;
logger.trace("Wrote value={} to attributeId={} of {}",
o, writeValue.getAttributeId(), writeValue.getNodeId());
}
results.add(StatusCode.GOOD);
} catch (UaException e) {
results.add(e.getStatusCode());
}
}
context.complete(results);
}
示例8: extract
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T extract(DataValue value) throws UaException {
Variant variant = value.getValue();
if (variant == null) return null;
Object o = variant.getValue();
if (o == null) return null;
try {
return (T) o;
} catch (ClassCastException e) {
throw new UaException(StatusCodes.Bad_TypeMismatch);
}
}
示例9: validateDataType
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
static DataValue validateDataType(ExpandedNodeId dataType, DataValue value) throws UaException {
Variant variant = value.getValue();
if (variant == null) return value;
Object o = variant.getValue();
if (o == null) throw new UaException(StatusCodes.Bad_TypeMismatch);
Class<?> expected = TypeUtil.getBackingClass(dataType);
Class<?> actual = o.getClass().isArray() ?
o.getClass().getComponentType() : o.getClass();
if (expected == null) {
throw new UaException(StatusCodes.Bad_TypeMismatch);
} else {
if (!expected.isAssignableFrom(actual)) {
/*
* Writing a ByteString to a UByte[] is explicitly allowed by the spec.
*/
if (o instanceof ByteString && expected == UByte.class) {
ByteString byteString = (ByteString) o;
return new DataValue(
new Variant(byteString.uBytes()),
value.getStatusCode(),
value.getSourceTime(),
value.getServerTime());
} else if (expected == Variant.class) {
// allow to write anything to a Variant
return value;
} else {
throw new UaException(StatusCodes.Bad_TypeMismatch);
}
}
}
return value;
}
示例10: toString
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; //导入方法依赖的package包/类
public static String toString(Variant variant) {
if (variant == null || variant.isNull()) {
return null;
}
final Object value = variant.getValue();
if (value instanceof byte[]) {
return toString((byte[]) variant.getValue());
}
if (variant.getValue() instanceof String) {
return (String) variant.getValue();
}
if (variant.getValue() instanceof NodeId) {
return toString((NodeId) variant.getValue());
}
if (variant.getValue() instanceof String[]) {
return toString((String[]) variant.getValue());
}
if (variant.getValue() instanceof DateTime) {
return toString((DateTime) variant.getValue());
}
if (variant.getValue() instanceof ByteString) {
return toString((ByteString) variant.getValue());
}
if (variant.getValue() instanceof XmlElement) {
return toString((XmlElement) variant.getValue());
}
if (variant.getValue() instanceof QualifiedName) {
return toString((QualifiedName) variant.getValue());
}
if (variant.getValue() instanceof ExtensionObject) {
return toString((ExtensionObject) variant.getValue());
}
if (variant.getValue() instanceof Object[]) {
return toString((Object[]) variant.getValue());
}
if (variant.getValue() instanceof LocalizedText) {
return toString((LocalizedText) variant.getValue());
}
return String.valueOf(variant.getValue());
}