Menu

#93 Accessing Type of Element

latest_release
closed
None
1
2022-12-30
2016-08-09
Anonymous
No

Hi Blenta,

I want to get the Type (or namespace) of a complex (child) Element with data, but I can't find a way to get it working.
I know how to do it when I am just working with ComplexTypes from the beginning, but now I want to do it when starting with an Element, that contains values. Every method I tried to access the complex Type/ Schema from that point resulted in null pointers.

I added a little example Project and the corresponding model and xsd.

I hope you can help me with the solution.

Best regards,
Sebastian

3 Attachments

Discussion

  • Anonymous

    Anonymous - 2016-08-09

    Please use this jar org.yaoqiang.bpmn.model-5.0.7.jar.

    XMLElement elementType = comp.getElementType();
    ComplexType complexType = XMLModelUtils.getSchemaComplexType(elementType);
    System.out.println(complexType.getName());
    
     
  • Anonymous

    Anonymous - 2016-08-10

    Thanks for your response, my example works with this new module.

    However, when I try to use it in my main project, I encounter a very strange problem. I need this in the context of a Web Apllication, made by professor Mueller. And for some reason the access of the type does not work in the web application.

    In order to eliminate other mistakes I created a little part of Code. It only requires the process-instance-Id (188 in this case) of a running Demo.bpmn Process that is in UserTask 2 (ID: _4) and has one produkt in the cart.

    Yaoqiang yaoqiang = new Yaoqiang();
                yaoqiang.initDatabase();
                Map<String,Object> workItem = yaoqiang.getWorkItem((long) 118, "_4");
                Map<String, DataInput> dataInputs = yaoqiang.getDataInputs(workItem);
                DataInput input = dataInputs.get("Cart");
                XMLComplexElement cart = yaoqiang.getWorkItemComplexTypeValue(workItem, input);
                XMLElement item = cart.get("Item");
                XMLCollectionElement itemCol= (XMLCollectionElement) item;
                XMLElement element = itemCol.getFirstCollectionElement();
                XMLComplexElement comp = (XMLComplexElement) element;
                System.out.println(comp.toName());
                System.out.println(comp.get("pName").toValue());
                System.out.println(comp.get("pID").toValue());
                XMLElement elementType = comp.getElementType();
                System.out.println(elementType != null);
                ComplexType complexType = XMLModelUtils.getSchemaComplexType(elementType);
                System.out.println(complexType.getName());
    

    In a simple Java Project this works totally fine, but if I use it in the web apllication the elementType is null for some reason.
    It might seem strange, but since this code schould be able to run everywhere, I just added it to the beginning point of the controller class (action == null). This way the code is executed as soon, as someone clicks the Start link.

    I added the project as attachment.

    Could you please take a look at this strange bug?

     
    • Anonymous

      Anonymous - 2016-08-10

      I forgot one thing:
      In the Controller the workflowMgtBean.registerModel(...) Methods will be a problem because you probably don't have these models in your repository. It would be better to add a block comment for those.

       
  • Anonymous

    Anonymous - 2016-08-10

    Sorry, I think I "found" my problem. I don't know why, but my default glassfish domain seems to be bugged. When I tried it again on another system (my laptop), it suddenly worked and with a new domain it also works on my main pc.

    Thank you for your work again.

     
  • 史耀强(Blenta)

    • status: open --> closed
     

Anonymous
Anonymous

Add attachments
Cancel