7 Replies Latest reply on Oct 2, 2012 9:21 AM by objectiser

    BaseModel and QName attributes

    objectiser

      Hi

       

      I have a ComponentImplementationModel that has an attribute which is a QName. Currently this gets returned as a string, but then I only get the namespace prefix and local part, whereas I would actually like to have the qname (i.e. namespace and local part).

       

      There does not seem to be an obvious way to resolve the namespace on the model - can someone point me in the right direction? just wondering whether there should be a 'getModelAttributeAsQName' method on the BaseModel?

       

      Thanks in advance.

       

      Regards

      Gary

        • 1. Re: BaseModel and QName attributes
          dward

          There isn't a direct way on the interface right now, however:

          1. I added a jira to cover this: https://issues.jboss.org/browse/SWITCHYARD-1058
          2. You can, for now:

           

          // pseudo

          public class MyModel extends BaseModel {

              public QName getFoo() {

                  String foo = getModelAttribute("foo");

                  if (foo != null && foo.indexOf(':') != -1) {

                      String [] split = foo.split(":", 2);

                     Map<String,String> map = getModelConfiguration().getPrefixNamespaceMap();

                      String ns = map.get(split[0]);

                      String localName = split[1];

                      return new QName(ns, localName);

                  }

              }

          }

          1 of 1 people found this helpful
          • 2. Re: BaseModel and QName attributes
            objectiser

            Thanks David, I'll give it a go.

            • 3. Re: BaseModel and QName attributes
              objectiser

              Unfortunately didn't work. I have the following switchyard.xml:

               

               

              <?xml version="1.0" encoding="UTF-8"?>
              <switchyard xmlns="urn:switchyard-config:switchyard:1.0"
                           xmlns:swyd="urn:switchyard-config:switchyard:1.0"
                           xmlns:trfm="urn:switchyard-config:transform:1.0"
                           xmlns:bean="urn:switchyard-component-bean:config:1.0"
                           xmlns:soap="urn:switchyard-component-soap:config:1.0"
                           xmlns:bpel="http://docs.oasis-open.org/ns/opencsa/sca/200903"
                           xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
                           xmlns:ls="http://example.com/loan-approval/loanService/"
                           xmlns:ra="http://example.com/loan-approval/riskAssessment/"
                           targetNamespace="urn:switchyard-quickstart:bpel-loan-approval:0.1.0"
                           name="loanapproval">
                   <sca:composite name="loanservice" targetNamespace="urn:bpel:test:1.0">
                      <sca:service name="loanService" promote="loanService">
                          <soap:binding.soap>
                              <soap:wsdl>loanServicePT.wsdl</soap:wsdl>
                              <soap:socketAddr>localhost:18001</soap:socketAddr>
                          </soap:binding.soap>
                       </sca:service>
              
                       <sca:component name="loanService">
                           <bpel:implementation.bpel process="ls:loanApprovalProcess" />
                           <sca:service name="loanService">
                               <sca:interface.wsdl interface="loanServicePT.wsdl#wsdl.porttype(loanServicePT)"/>
                           </sca:service>
                           <sca:reference name="riskAssessor" >
                               <sca:interface.wsdl interface="riskAssessmentPT.wsdl#wsdl.porttype(riskAssessmentPT)"/>
                           </sca:reference>
                       </sca:component>
                       
                       <sca:component name="riskAssessor" >
                           <bpel:implementation.bpel process="ra:riskAssessmentProcess" />
                           <sca:service name="riskAssessor">
                               <sca:interface.wsdl interface="riskAssessmentPT.wsdl#wsdl.porttype(riskAssessmentPT)"/>
                           </sca:service>
                       </sca:component>
              
                   </sca:composite>
              </switchyard>
              

               

              When I attempt to retrieve the QName for the first "bpel:implementation" model element, the namespace/prefix map contains:

               

              map={ns0=http://www.w3.org/2000/xmlns/, ns1=http://docs.oasis-open.org/ns/opencsa/sca/200903}

               

              Regards

              Gary

              • 4. Re: BaseModel and QName attributes
                dward

                Okay, I'll squeeze something into 0.6.0-SNAPSHOT for you later today.

                • 5. Re: BaseModel and QName attributes
                  dward

                  Sorry; it's gonna hafta be tomorrow.

                  • 6. Re: BaseModel and QName attributes
                    dward

                    Gary,

                     

                    I finally submitted a pull request that fixes https://issues.jboss.org/browse/SWITCHYARD-1058 for you.

                     

                    You can now call getModelAttributeAsQName(String):QName or getModelAttributeAsQName(QName):QName.  You can also set model attibutes as qnames.

                     

                    I tested it with your XML, and I get the proper qnames out per your examples, testing the prefix, namespace and local parts are all good:

                     

                    pfx: ls

                    ns: http://example.com/loan-approval/loanService/

                    lp: loanApprovalProcess

                     

                     

                    pfx: ra

                    ns: http://example.com/loan-approval/riskAssessment/

                    lp: riskAssessmentProcess

                     

                    So once this gets processed, you should be good to go.  Thanks for your patience!

                     

                    Sincerely,

                    David

                    • 7. Re: BaseModel and QName attributes
                      objectiser

                      Thanks David.