Search in sources :

Example 1 with EnumeratedType

use of org.opcfoundation.opcua.binaryschema.EnumeratedType in project milo by eclipse.

the class DataTypeDictionaryGenerator method createEnumeratedType.

private EnumeratedType createEnumeratedType(EnumDescription description) {
    QualifiedName name = description.getName();
    EnumDefinition definition = description.getEnumDefinition();
    EnumeratedType enumeratedType = new EnumeratedType();
    enumeratedType.setName(name.getName());
    enumeratedType.setLengthInBits(32);
    for (EnumField field : definition.getFields()) {
        EnumeratedValue enumeratedValue = new EnumeratedValue();
        enumeratedValue.setName(field.getName());
        enumeratedValue.setValue(field.getValue().intValue());
        enumeratedType.getEnumeratedValue().add(enumeratedValue);
    }
    return enumeratedType;
}
Also used : EnumField(org.eclipse.milo.opcua.stack.core.types.structured.EnumField) EnumeratedType(org.opcfoundation.opcua.binaryschema.EnumeratedType) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) EnumDefinition(org.eclipse.milo.opcua.stack.core.types.structured.EnumDefinition) EnumeratedValue(org.opcfoundation.opcua.binaryschema.EnumeratedValue)

Example 2 with EnumeratedType

use of org.opcfoundation.opcua.binaryschema.EnumeratedType in project milo by eclipse.

the class BsdParser method parse.

/**
 * Parse an XML document containing a type dictionary conforming to the OPC Binary XML Schema.
 *
 * @param inputStream the {@link InputStream} to read the XML document from.
 * @return a {@link DictionaryDescription}.
 * @throws JAXBException if parsing fails.
 */
public DictionaryDescription parse(InputStream inputStream) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
    TypeDictionary typeDictionary = (TypeDictionary) context.createUnmarshaller().unmarshal(inputStream);
    List<CodecDescription> enumCodecs = typeDictionary.getOpaqueTypeOrEnumeratedTypeOrStructuredType().stream().filter(typeDescription -> typeDescription instanceof EnumeratedType).map(typeDescription -> {
        EnumeratedType enumeratedType = (EnumeratedType) typeDescription;
        logger.debug("EnumeratedType: {}", typeDescription.getName());
        return new CodecDescription(getEnumCodec(enumeratedType), enumeratedType.getName());
    }).collect(toList());
    List<CodecDescription> structCodecs = typeDictionary.getOpaqueTypeOrEnumeratedTypeOrStructuredType().stream().filter(typeDescription -> typeDescription instanceof StructuredType).map(typeDescription -> {
        StructuredType structuredType = (StructuredType) typeDescription;
        logger.debug("StructuredType: {}", typeDescription.getName());
        return new CodecDescription(getStructCodec(structuredType), structuredType.getName());
    }).collect(toList());
    return new DictionaryDescription(typeDictionary.getTargetNamespace(), enumCodecs, structCodecs);
}
Also used : StructuredType(org.opcfoundation.opcua.binaryschema.StructuredType) List(java.util.List) OpcUaBinaryDataTypeCodec(org.eclipse.milo.opcua.stack.core.serialization.codecs.OpcUaBinaryDataTypeCodec) Collectors.toList(java.util.stream.Collectors.toList) Logger(org.slf4j.Logger) ObjectFactory(org.opcfoundation.opcua.binaryschema.ObjectFactory) TypeDictionary(org.opcfoundation.opcua.binaryschema.TypeDictionary) LoggerFactory(org.slf4j.LoggerFactory) EnumeratedType(org.opcfoundation.opcua.binaryschema.EnumeratedType) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) InputStream(java.io.InputStream) EnumeratedType(org.opcfoundation.opcua.binaryschema.EnumeratedType) JAXBContext(javax.xml.bind.JAXBContext) TypeDictionary(org.opcfoundation.opcua.binaryschema.TypeDictionary) StructuredType(org.opcfoundation.opcua.binaryschema.StructuredType)

Aggregations

EnumeratedType (org.opcfoundation.opcua.binaryschema.EnumeratedType)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 OpcUaBinaryDataTypeCodec (org.eclipse.milo.opcua.stack.core.serialization.codecs.OpcUaBinaryDataTypeCodec)1 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)1 EnumDefinition (org.eclipse.milo.opcua.stack.core.types.structured.EnumDefinition)1 EnumField (org.eclipse.milo.opcua.stack.core.types.structured.EnumField)1 EnumeratedValue (org.opcfoundation.opcua.binaryschema.EnumeratedValue)1 ObjectFactory (org.opcfoundation.opcua.binaryschema.ObjectFactory)1 StructuredType (org.opcfoundation.opcua.binaryschema.StructuredType)1 TypeDictionary (org.opcfoundation.opcua.binaryschema.TypeDictionary)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1