use of org.opcfoundation.opcua.binaryschema.TypeDictionary in project milo by eclipse.
the class DataTypeDictionaryGenerator method writeToOutputStream.
public void writeToOutputStream(OutputStream outputStream) throws IOException {
TypeDictionary typeDictionary = new TypeDictionary();
typeDictionary.setDefaultByteOrder(ByteOrder.LITTLE_ENDIAN);
typeDictionary.setTargetNamespace(namespaceUri);
enumeratedTypes.forEach(t -> typeDictionary.getOpaqueTypeOrEnumeratedTypeOrStructuredType().add(t));
structuredTypes.forEach(t -> typeDictionary.getOpaqueTypeOrEnumeratedTypeOrStructuredType().add(t));
namespaces.forEach(namespace -> {
ImportDirective importDirective = new ImportDirective();
importDirective.setNamespace(namespace);
typeDictionary.getImport().add(importDirective);
});
try {
JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
try {
marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new OpcUaNamespacePrefixMapper());
} catch (PropertyException e) {
logger.debug("NamespacePrefixMapper not supported", e);
}
marshaller.marshal(typeDictionary, outputStream);
} catch (Throwable t) {
throw new IOException("failed to write dictionary to OutputStream", t);
}
}
use of org.opcfoundation.opcua.binaryschema.TypeDictionary 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);
}
Aggregations