さまざまなタイプの OPC UA の XML ドキュメントとそれに追加されたいくつかのカスタム オブジェクト タイプがあります。
また、別のテキスト入力があります (XX -- FolderType, AA -- StudentType, BB --TeacherType) つまり、インスタンス名とインスタンスのタイプについて言及しています。
もちろん、この完全なものは UAModeller ツールで構築できますが、入力が提供されると自動的にこれを行う Java プログラムを作成する予定です。
まず、types.xml ファイルを取得して解析しました。UAObjectTypes、UAVariableTypes、StudentTypes、TeacherTypes などのリストを作成しました。
インスタンスの入力リストをそれらの ObjectTypes にマップするリストを作成しました。しかし、期待どおりに参照を確立できません。例:
OPC UA のすべてのノードは、参照を介して他のノードに接続されます。例: クラスは「OrganisedBy」オブジェクトです。クラスは生徒と教師を「組織」します。学生はラクシャンなどを「組織」します。
コードを介してこのアドレス空間の動的生成を確立するのに苦労しています。ツールによって作成されたサンプル アドレス スペースがあります。しかし、Java プログラムは同じものを生成しません。
File xmlFile = new File("studteachobjmodel.xml"); //this is the types.xml
JAXBContext jaxbContext;
jaxbContext = JAXBContext.newInstance(UANodeSet.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
UANodeSet xmlentries = (UANodeSet) jaxbUnmarshaller.unmarshal(xmlFile);
entries.add(xmlentries);
//This has to be well known in prior
UANodeSet newUANodeSetObject = new UANodeSet();
List<UAObjectType> objectTypeList = xmlentries.getUAObjectType();
HashMap<String, UAObjectType> mapWithExtractedObjectTypes = new HashMap<String, UAObjectType>();
for(String name: newUniqueList) {
for(UAObjectType o : objectTypeList) {
if(o.getDisplayName().equals(name))
mapWithExtractedObjectTypes.put(o.getDisplayName(), o); //mapping types with their objectTypes
}
}
System.out.println("----------MAPPING DONE---------------------");
List<UAObject> objectList = xmlentries.getUAObject();
List<UAObject> newObjectList = new ArrayList<UAObject>();
UAObject uaObject = null;
List<String> newNameSpaceUris = new ArrayList<String>();
newNameSpaceUris.add("http://yourorganisation.org/trial1/");
newUANodeSetObject.setNamespaceUris(newNameSpaceUris);
List<UAVariable> variableList = new ArrayList<UAVariable>();
for(Map.Entry mapElement:inputMap.entrySet()) {
String key = (String) mapElement.getKey();
String type = inputMap.get(key);
String value = mapWithExtractedObjectTypes.get(type).getNodeId();
UAObjectType tempType =mapWithExtractedObjectTypes.get(type);
// String value = opcuaInternalMap.get(type);
for(UAObjectType o : objectTypeList) {
if (o.getNodeId().equals(value))
{
// System.out.println(o.getReferences());
uaObject = new UAObject();
List<Reference> referencesForObject = new ArrayList<Reference>();
uaObject.setNodeId("ns=1;s="+key);//String.valueOf(min+random.nextInt(upperBound)));
uaObject.setBrowsename("1:"+key);
uaObject.setDisplayName(key);
List<Reference>tempRef=tempType.getReferences();
Reference ref_01= new Reference();
ref_01.setReferenceType("HasTypeDefinition");
ref_01.setReference(value);
//
////////////////////////NEED GUIDANCE HERE//////////////////////////////////
// Reference ref_02= new Reference();
// ref_02.setReferenceType("Organizes");
// ref_02.setReference("i=85");
// referencesForObject.add(ref_01);
// referencesForObject.add(ref_02);
tempRef.add(ref_01);
uaObject.setReferences(tempRef);
break;
}
}
if(uaObject!=null) {
newObjectList.add(uaObject);
}
newUANodeSetObject.setUAObject(newObjectList);
}
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(newUANodeSetObject, new File("Instances.xml"));
}catch (JAXBException e) {
e.printStackTrace();
} catch (FactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
私にいくつかのガイダンスを提供してください。今のところまったく無知。