2

I have the XML document of the various types of OPC UA and some custom object types added to it.. for eg((1) StudentType with properties of Age, Birthplace (2) TeacherType with properties of Name, Expertise))

Also, I have another text input which says (XX -- FolderType, AA -- StudentType, BB --TeacherType) Inshort it mentions the instance name and the type of the instance.

This complete thing can be built with UAModeller tool ofcourse, however we plan to write a java program which does this for us automatically when inputs are provided.

To start off, I have taken the types.xml file, and have parsed it. I have created a list of UAObjectTypes, UAVariableTypes, StudentTypes,TeacherTypes etc.

I have made myself a list which maps the inputlist of instances, to their ObjectTypes. But I am not able to establish the references as expected. For eg:

Structure Types Every node in OPC UA is connected to the other via references. For eg: Class is "OrganisedBy" Objects. Class "organises" Students and Teachers. Students "organises" Rakshan and so on.

I am struggling to establish a dynamic production of this address Space via code. I have the sample address sace produced by the tool. But the java program does not produce the same.

            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();
        } 

Please provide me some guidance. totally clueless as of now.

0 Answers0