Example usage for javax.xml.bind JAXBElement getValue

List of usage examples for javax.xml.bind JAXBElement getValue

Introduction

In this page you can find the example usage for javax.xml.bind JAXBElement getValue.

Prototype

public T getValue() 

Source Link

Document

Return the content model and attribute values for this element.

See #isNil() for a description of a property constraint when this value is null

Usage

From source file:edu.harvard.i2b2.query.QueryTopPanel.java

private void jRunQueryButtonActionPerformed(java.awt.event.ActionEvent evt) {
    //System.out.println("value set on the slider: "+ jSlider1.getValue());
    if (dataModel.isAllPanelEmpty()) {
        JOptionPane.showMessageDialog(this, "All groups are empty.");
        return;/*from w w  w . j a va 2s .c  o m*/
    }

    String queryNametmp = jNameTextField.getText();
    //if(queryNametmp.equals("") || queryNametmp == null) {
    queryNametmp = dataModel.getTmpQueryName();
    //}
    Object selectedValue = JOptionPane.showInputDialog(this, "Please supply a name for this query: ",
            "Query Name Dialog", JOptionPane.PLAIN_MESSAGE, null, null, queryNametmp);

    if (selectedValue == null) {
        return;
    } else {
        queryNametmp = (String) selectedValue;
    }

    dataModel.queryName(queryNametmp);
    final String queryName = queryNametmp;
    //System.out.println("Provided query name: " + queryName);

    ImageIcon buttonIcon = createImageIcon("indicator_18.gif");
    this.jRunQueryButton.setIcon(buttonIcon);
    this.jRunQueryButton.setText("         Running ......");
    final Color defaultcolor = jRunQueryButton.getBackground();

    dataModel.specificity(0);//jSlider1.getValue());
    final String xmlStr = dataModel.wirteQueryXML();
    parentPanel.lastRequestMessage(xmlStr);
    parentPanel.setPatientCount("");
    parentPanel.setRequestText(xmlStr);
    parentPanel.setResponseText("Waiting for response ...");
    //System.out.println("Query request: "+xmlStr);
    jNameTextField.setText(queryName);

    queryThread = new Thread() {
        public void run() {
            //setCursor(new Cursor(Cursor.WAIT_CURSOR));
            response = QueryRequestClient.sendQueryRequestREST(xmlStr);
            parentPanel.lastResponseMessage(response);
            if (response != null) {
                //response = response.substring(response.indexOf("<ns2:response"), response.indexOf("</i2b2:response>"));
                parentPanel.setResponseText(response);
                JAXBUtil jaxbUtil = QueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    BodyType bt = messageType.getMessageBody();
                    MasterInstanceResultResponseType masterInstanceResultResponseType = (MasterInstanceResultResponseType) new JAXBUnWrapHelper()
                            .getObjectByClass(bt.getAny(), MasterInstanceResultResponseType.class);
                    String queryId = null;
                    //ResponseMessageType messageType = jaxbUtil.unMashallResponseMessageTypeFromString(response);
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();
                    queryId = new Integer(masterInstanceResultResponseType.getQueryMaster().getQueryMasterId())
                            .toString();//messageType.getResponseHeader().getInfo().getValue();
                    //System.out.println("Get query id: "+queryId);

                    QueryMasterData nameNode = new QueryMasterData();
                    nameNode.name(queryName);
                    nameNode.visualAttribute("CA");
                    nameNode.userId(UserInfoBean.getInstance().getUserName());
                    nameNode.tooltip("A query run by " + nameNode.userId());
                    nameNode.id(queryId);
                    //nameNode.xmlContent(xmlStr);

                    String count = "";
                    if (status.equalsIgnoreCase("DONE")) {
                        String refId = null;
                        try {
                            edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.StatusType cellStatusType = masterInstanceResultResponseType
                                    .getStatus();
                            if (cellStatusType.getCondition().get(0).getValue().equalsIgnoreCase("RUNNING")) {
                                JOptionPane.showMessageDialog(parentPanel,
                                        "Query is still running, you may check its status later \n"
                                                + "in the previous queries view by right clicking on a node\n"
                                                + "then selecting refresh all.");
                                jRunQueryButton.setIcon(null);
                                jRunQueryButton.setText("Run Query");
                                return;
                            } else if (cellStatusType.getCondition().get(0).getValue()
                                    .equalsIgnoreCase("ERROR")) {
                                JOptionPane.showMessageDialog(parentPanel,
                                        "Error message delivered from the remote server, "
                                                + "you may wish to retry your last action");
                                jRunQueryButton.setIcon(null);
                                jRunQueryButton.setText("Run Query");
                                return;
                            }

                            QueryResultInstanceType queryResultInstanceType = masterInstanceResultResponseType
                                    .getQueryResultInstance().get(0);
                            refId = new Integer(queryResultInstanceType.getResultInstanceId()).toString();
                            //System.out.println("Set Ref id: "+ refId);
                            count = new Integer(queryResultInstanceType.getSetSize()).toString();
                            parentPanel.setPatientCount(count);
                        } catch (Exception e) {
                            e.printStackTrace();
                            JOptionPane.showMessageDialog(parentPanel,
                                    "Response delivered from the remote server could not be understood,\n"
                                            + "you may wish to retry your last action.");

                            jRunQueryButton.setIcon(null);
                            jRunQueryButton.setText("Run Query");
                            return;
                        }

                        IWorkbenchPage page = ((QueryPanelInvestigator) parentPanel).parentview.getViewSite()
                                .getPage();
                        ViewPart previousqueryview = (ViewPart) page.findView(
                                "edu.harvard.i2b2.eclipse.plugins.previousquery.views.PreviousQueryView");
                        ((ICommonMethod) previousqueryview).doSomething(nameNode.name() + " ["
                                + dataModel.getDayString() + "]" + "#i2b2seperater#" + nameNode.id());

                        ArrayList<String> nodeXmls = new ArrayList<String>();
                        for (int i = 0; i < dataModel.getCurrentPanelCount(); i++) {
                            ArrayList<QueryConceptTreeNodeData> nodelist = dataModel.getTreePanel(i).getItems();
                            for (int j = 0; j < nodelist.size(); j++) {
                                QueryConceptTreeNodeData nodedata = nodelist.get(j);
                                String termStatus = nodedata.setXmlContent();
                                if (termStatus.equalsIgnoreCase("error")) {
                                    JOptionPane.showMessageDialog(parentPanel,
                                            "Response delivered from the remote server could not be understood,\n"
                                                    + "you may wish to retry your last action.");
                                    jRunQueryButton.setIcon(null);
                                    jRunQueryButton.setText("Run Query");
                                    return;
                                }
                                nodeXmls.add(nodedata.xmlContent());
                            }
                        }

                        ViewPart explorerview = (ViewPart) page
                                .findView("edu.harvard.i2b2.eclipse.plugins.explorer.views.ExplorerView");
                        String str1 = "" + count;
                        String str2 = "-" + refId;
                        ((ICommonMethod) explorerview).doSomething(str1 + str2);
                        ((ICommonMethod) explorerview).doSomething(nodeXmls);
                    } else {
                        JOptionPane.showMessageDialog(parentPanel,
                                "Error message delivered from the remote server, "
                                        + "you may wish to retry your last action");

                        jRunQueryButton.setIcon(null);
                        jRunQueryButton.setText("Run Query");
                        return;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(parentPanel,
                            "Response delivered from the remote server could not be understood,\n"
                                    + "you may wish to retry your last action.");
                    jRunQueryButton.setIcon(null);
                    jRunQueryButton.setText("Run Query");
                    return;
                }
            }
            //setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            jRunQueryButton.setIcon(null);
            jRunQueryButton.setText("Run Query");
            //jRunQueryButton.setBackground(defaultcolor);
        }
    };

    try {
        queryThread.start();
    } catch (Exception e) {
        e.printStackTrace();
        parentPanel.setResponseText(e.getMessage());
    }
}

From source file:com.helger.peppol.smpclient.SMPClientReadOnly.java

/**
 * Gets a signed service metadata object given by its service group id and its
 * document type. This is a specification compliant method.
 *
 * @param aServiceGroupID/*  w  w w.j a  v a2  s .com*/
 *        The service group id of the service metadata to get. May not be
 *        <code>null</code>.
 * @param aDocumentTypeID
 *        The document type of the service metadata to get. May not be
 *        <code>null</code>.
 * @return A signed service metadata object. Never <code>null</code>.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         A HTTP Forbidden was received, should not happen.
 * @throws SMPClientNotFoundException
 *         The service group id or document type did not exist.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #getServiceRegistrationOrNull(IParticipantIdentifier,
 *      IDocumentTypeIdentifier)
 */
@Nonnull
public SignedServiceMetadataType getServiceRegistration(@Nonnull final IParticipantIdentifier aServiceGroupID,
        @Nonnull final IDocumentTypeIdentifier aDocumentTypeID) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");

    try {
        final String sURI = m_sSMPHost + IdentifierHelper.getIdentifierURIPercentEncoded(aServiceGroupID)
                + "/services/" + IdentifierHelper.getIdentifierURIPercentEncoded(aDocumentTypeID);
        Request aRequest = Request.Get(sURI);
        SignedServiceMetadataType aMetadata = executeRequest(aRequest).handleResponse(
                SMPHttpResponseHandlerSigned.create(new SMPMarshallerSignedServiceMetadataType()));

        // If the Redirect element is present, then follow 1 redirect.
        if (aMetadata.getServiceMetadata() != null && aMetadata.getServiceMetadata().getRedirect() != null) {
            final RedirectType aRedirect = aMetadata.getServiceMetadata().getRedirect();

            // Follow the redirect
            s_aLogger.info("Following a redirect from '" + sURI + "' to '" + aRedirect.getHref() + "'");
            aRequest = Request.Get(aRedirect.getHref());
            aMetadata = executeRequest(aRequest).handleResponse(
                    SMPHttpResponseHandlerSigned.create(new SMPMarshallerSignedServiceMetadataType()));

            // Check that the certificateUID is correct.
            boolean bCertificateSubjectFound = false;
            outer: for (final Object aObj : aMetadata.getSignature().getKeyInfo().getContent()) {
                final Object aInfoValue = ((JAXBElement<?>) aObj).getValue();
                if (aInfoValue instanceof X509DataType) {
                    final X509DataType aX509Data = (X509DataType) aInfoValue;
                    for (final Object aX509Obj : aX509Data.getX509IssuerSerialOrX509SKIOrX509SubjectName()) {
                        final JAXBElement<?> aX509element = (JAXBElement<?>) aX509Obj;
                        // Find the first subject (of type string)
                        if (aX509element.getValue() instanceof String) {
                            final String sSubject = (String) aX509element.getValue();
                            if (!aRedirect.getCertificateUID().equals(sSubject)) {
                                throw new SMPClientException(
                                        "The certificate UID of the redirect did not match the certificate subject. Subject is '"
                                                + sSubject + "'. Required certificate UID is '"
                                                + aRedirect.getCertificateUID() + "'");
                            }
                            bCertificateSubjectFound = true;
                            break outer;
                        }
                    }
                }
            }

            if (!bCertificateSubjectFound)
                throw new SMPClientException("The X509 certificate did not contain a certificate subject.");
        }
        return aMetadata;
    } catch (final Exception ex) {
        throw getConvertedException(ex);
    }
}

From source file:com.evolveum.midpoint.testing.model.client.sample.AbstractTestForExchangeConnector.java

protected static <T> T unmarshallResource(String path) throws JAXBException, FileNotFoundException {
    JAXBContext jc = ModelClientUtil.instantiateJaxbContext();
    Unmarshaller unmarshaller = jc.createUnmarshaller();

    InputStream is = null;/*ww  w  .j a v a  2  s  . c  om*/
    JAXBElement<T> element = null;
    try {
        is = AbstractTestForExchangeConnector.class.getClassLoader().getResourceAsStream(path);
        if (is == null) {
            throw new FileNotFoundException("System resource " + path + " was not found");
        }
        element = (JAXBElement<T>) unmarshaller.unmarshal(is);
    } finally {
        if (is != null) {
            IOUtils.closeQuietly(is);
        }
    }
    if (element == null) {
        return null;
    }
    return element.getValue();
}

From source file:at.gv.egovernment.moa.id.auth.servlet.PEPSConnectorWithLocalSigningServlet.java

private X509Certificate getSignerCertificate(String citizenSignature)
        throws CertificateException, JAXBException, UnsupportedEncodingException {
    JAXBContext ctx = JAXBContext.newInstance(SignatureType.class.getPackage().getName());
    SignatureType root = ((JAXBElement<SignatureType>) ctx.createUnmarshaller()
            .unmarshal(IOUtils.toInputStream(citizenSignature))).getValue();

    // extract certificate
    for (Object current : root.getKeyInfo().getContent())
        if (((JAXBElement<?>) current).getValue() instanceof X509DataType) {
            for (Object currentX509Data : ((JAXBElement<X509DataType>) current).getValue()
                    .getX509IssuerSerialOrX509SKIOrX509SubjectName()) {
                JAXBElement<?> casted = ((JAXBElement<?>) currentX509Data);
                if (casted.getName().getLocalPart().equals("X509Certificate")) {
                    return new X509Certificate(((String) casted.getValue()).getBytes("UTF-8"));
                }/*from ww w.j  a  va2  s  . c  o  m*/
            }
        }
    return null;
}

From source file:com.evolveum.midpoint.testing.wstest.AbstractWebserviceTest.java

protected void assertAttribute(ShadowType shadow, QName attrName, String attrVal) {
    ShadowAttributesType attributes = shadow.getAttributes();
    for (Object any : attributes.getAny()) {
        if (any instanceof Element) {
            Element element = (Element) any;
            if (DOMUtil.getQName(element).equals(attrName)) {
                assertEquals("Wrong attribute " + attrName + " in shadow " + ModelClientUtil.toString(shadow),
                        attrVal, element.getTextContent());
            }//from  w  w  w . j  a v  a  2  s .c  o  m
        } else if (any instanceof JAXBElement<?>) {
            JAXBElement<?> jaxbElement = (JAXBElement<?>) any;
            if (jaxbElement.getName().equals(attrName)) {
                assertEquals("Wrong attribute " + attrName + " in shadow " + ModelClientUtil.toString(shadow),
                        attrVal, jaxbElement.getValue().toString());
            }
        } else {
            AssertJUnit.fail("Unexpected thing " + any + " in shadow attributes");
        }
    }
}

From source file:edu.harvard.i2b2.eclipse.plugins.workplace.views.NodeDropListener.java

public void drop(DropTargetEvent event) {
    String text = (String) event.data;
    if (text != null) {
        XmlValueType xml = XmlUtil.stringToXml(text);
        TreeNode currentTarget = (TreeNode) event.item.getData();

        FolderType workItem = null;//from ww w. j a  va  2  s  . c o m
        String dragShareId = null;
        Boolean moveFlag = false;
        // check contents of display.getData
        if (event.display.getData() != null) {
            // display.getData == M|O*V+E means we did not move previous item 
            //   within workplace tree.   So reset to null.
            if (event.display.getData().equals("M|O*V+E"))
                event.display.setData(null);
            // otherwise display.getData == the work object being dragged.
            // we need this to get name/annotation info in event of rename or new annotation
            else {
                workItem = (FolderType) event.display.getData();
                dragShareId = workItem.getShareId();
            }

        }
        //set up M|O*V+E flag so dragFinish can clean up appropriately
        // if source or destination is shared do a copy not a move
        //   if workItem is empty -- drag source is not from a workplace folder.
        if (!(currentTarget.getData().getShareId().equals("Y")) && (workItem != null)
                && !(dragShareId.equals("Y"))) {
            event.display.setData("M|O*V+E");
            moveFlag = true;
        }

        // Check that xml dragged in is of a type we know about.
        // Set icon to correct type.

        String visualAttribute = "";
        String workXmlI2B2Type = "";
        String name = XmlUtil.getName(xml);

        if (XmlUtil.hasFolderTag(xml)) {

            JAXBUtil jaxbUtil = WorkplaceJAXBUtil.getJAXBUtil();
            FoldersType folders = null;
            FolderType folder = null;
            try {
                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(text);
                DndType dndType = (DndType) jaxbElement.getValue();
                folders = (FoldersType) new JAXBUnWrapHelper().getObjectByClass(dndType.getAny(),
                        FoldersType.class);
                folder = folders.getFolder().get(0);
            } catch (JAXBUtilException e) {
                log.error("Unwrap error: " + e.getMessage(), e);
                return;
            }
            TreeData data = new TreeData(folder);
            data.setParentIndex(currentTarget.getData().getIndex());
            data.setTableCd(currentTarget.getData().getTableCd());
            data.setVisualAttributes("FA");
            data.setShareId(currentTarget.getData().getShareId());
            TreeNode node = new TreeNode(data);
            currentTarget.addChild(node);

            if (moveFlag == true)
                node.moveNode(viewer).start();

            else {
                String copiedTo = new AddChildRequestMessage().generateMessageId();

                // we are copying (from a shared folder)
                // Give the node its own index
                node.getData().setIndex(copiedTo);
                // This is a hack to pass the index and shareId back to dragListener
                //   so children of copied Folder can also be copied.
                event.display.setData(copiedTo + "," + data.getShareId());

                // set up folder with placeholder child so display is correct
                if ((node.getData().getVisualAttributes().equals("FA"))) {
                    TreeNode placeholder = new TreeNode("working...", "working...", "LAO");
                    node.addChild(placeholder);

                } else if ((node.getData().getVisualAttributes().equals("FH"))) {
                    TreeNode placeholder = new TreeNode("working...", "working...", "LHO");
                    node.addChild(placeholder);

                }

                node.addNode(viewer).start();

            }
            viewer.refresh();
            return;
        }
        /*
         * This code used to single out folders for different processing (move only)
         * 
         * 
         *    if(XmlUtil.hasFolderTag(xml)) {
              // Folders are processed differently
              // They are moved as opposed to added to the db
              JAXBUtil jaxbUtil = WorkplaceJAXBUtil.getJAXBUtil();
              FoldersType folders = null;
              FolderType folder = null;
              try {
                 JAXBElement jaxbElement  = jaxbUtil.unMashallFromString(text);
                 DndType dndType = (DndType)jaxbElement.getValue();     
                 folders = (FoldersType) new JAXBUnWrapHelper().getObjectByClass(dndType.getAny(),
             FoldersType.class);
                 folder = folders.getFolder().get(0);
              } catch (JAXBUtilException e) {
                 log.error("Unwrap error: " + e.getMessage(), e);
                 return;
              }  
              TreeData data = new TreeData(folder);
              data.setParentIndex(currentTarget.getData().getIndex());
              data.setTableCd(currentTarget.getData().getTableCd());
              data.setVisualAttributes("FA");
              data.setShareId(currentTarget.getData().getShareId());
              TreeNode node = new TreeNode(data);
              currentTarget.addChild(node);
              /// dont allow copying folders between private area and shared area for the moment
              if((!(data.getShareId().equals("Y")) && (currentTarget.getData().getShareId().equals("Y"))) ||
          (data.getShareId().equals("Y") && (!(currentTarget.getData().getShareId().equals("Y"))))){
                 MessageBox mBox = new MessageBox(Display.getCurrent().getActiveShell(),SWT.ICON_INFORMATION | SWT.OK);
                 mBox.setText("Copy Folder Message");
                 mBox.setMessage("Copying folders between shared and local areas not allowed \n" +
             "Create a new folder and then copy its contents.");
                 int result = mBox.open();      
              }
              // other wise move the folder
              else
                 node.moveNode(viewer).start();
                
              viewer.refresh();
              return;
           }*/
        else if (XmlUtil.hasConceptTag(xml)) {

            visualAttribute = "ZA";
            workXmlI2B2Type = "CONCEPT";

            try {
                JAXBUtil jaxbUtil = WorkplaceJAXBUtil.getJAXBUtil();
                ConceptType concept = null;
                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(text);
                DndType dndType = (DndType) jaxbElement.getValue();
                ConceptsType conceptsType = (ConceptsType) new JAXBUnWrapHelper()
                        .getObjectByClass(dndType.getAny(), ConceptsType.class);

                List concepts = conceptsType.getConcept();
                if (concepts != null) {
                    Iterator conceptsIterator = concepts.iterator();
                    while (conceptsIterator.hasNext()) {
                        concept = (ConceptType) conceptsIterator.next();
                        XmlValueType conceptXml = createWorkXml(concept);
                        if (concept.getVisualattributes().startsWith("FA"))
                            visualAttribute = "ZAF";
                        String cname = concept.getName();
                        if (concept.getModifier() != null) {
                            cname += " [" + concept.getModifier().getName() + "]";
                        }

                        //         createWorkplaceNode(workItem, currentTarget, conceptXml, XmlUtil.getName(conceptXml), workXmlI2B2Type, visualAttribute, moveFlag);
                        createWorkplaceNode(workItem, currentTarget, conceptXml, cname, workXmlI2B2Type,
                                visualAttribute, moveFlag);

                    }
                }
            } catch (JAXBUtilException e) {
                log.error("Unwrap error: " + e.getMessage(), e);
                return;
            }
        }

        else if (XmlUtil.hasPatientSetTag(xml)) {
            visualAttribute = "ZA";
            workXmlI2B2Type = "PATIENT_COLL";
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        }

        else if (XmlUtil.hasEncounterSetTag(xml)) {
            visualAttribute = "ZA";
            workXmlI2B2Type = "ENCOUNTER_COLL";
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        }

        else if (XmlUtil.hasPatientCountTag(xml)) {
            visualAttribute = "ZA";
            workXmlI2B2Type = "PATIENT_COUNT_XML";
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        }

        else if (XmlUtil.hasBreakdownTag(xml)) {
            visualAttribute = "ZA";
            workXmlI2B2Type = XmlUtil.getXmlI2B2Type(xml);
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        }
        // this has to be after patient set and patient count tag checks 
        else if (XmlUtil.hasPrevQueryTag(xml)) {
            visualAttribute = "ZA";
            workXmlI2B2Type = "PREV_QUERY";
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        }

        else if (XmlUtil.hasGroupTemplateTag(xml)) {
            visualAttribute = "ZA";
            workXmlI2B2Type = "GROUP_TEMPLATE";
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        }

        else if (XmlUtil.hasQueryDefinitionTag(xml)) {
            visualAttribute = "ZA";
            workXmlI2B2Type = "QUERY_DEFINITION";
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        }

        /// NEXT SET == ORDER IMPORTANT
        //  Have to rule out pdo before trying observations, patients, events, etc

        else if (XmlUtil.hasPatientDataTag(xml)) {
            visualAttribute = "ZA";
            workXmlI2B2Type = "PDO";
            name = "PDO" + MessageUtil.getInstance().getTimestamp();
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        }

        else if (XmlUtil.hasObservationTag(xml)) {
            visualAttribute = "ZA";
            workXmlI2B2Type = "OBSERVATION";
            if (name.equals("PDO"))
                name = "OBS" + MessageUtil.getInstance().getTimestamp();
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        }

        else if (XmlUtil.hasPatientTag(xml)) {
            /*visualAttribute = "ZA";      
            workXmlI2B2Type = "PATIENT";
            if(name.equals("PDO"))
               name = "PATIENT " + XmlUtil.getSiteId(xml)
               +":"+ XmlUtil.getPatientId(xml);
            createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
            */
            Element rootElement = xml.getAny().get(0);
            NodeList nameElements = rootElement.getElementsByTagName("patient_id");
            if (nameElements.getLength() != 0 && nameElements.item(0).getAttributes().getLength() != 0) {

                for (int i = 0; i < nameElements.getLength(); i++) {
                    visualAttribute = "ZA";
                    workXmlI2B2Type = "PATIENT";
                    String site = nameElements.item(i).getAttributes().item(0).getTextContent();
                    String id = nameElements.item(i).getTextContent();
                    if (name.equals("PDO"))
                        name = "PATIENT " + site + ":" + id;
                    //XmlUtil.getSiteId(xml)+":"+ XmlUtil.getPatientId(xml);
                    //////
                    StringWriter strWriter = new StringWriter();
                    try {

                        JAXBUtil jaxbUtil = WorkplaceJAXBUtil.getJAXBUtil();

                        PatientSet pdoPatientSet = new PatientSet();
                        //for (int i = 0, n = selection.length; i < n; i++) {

                        // JAXBElement jaxbElement =
                        // jaxbUtil.unMashallFromString(nodedata.xmlContent());
                        // ResponseMessageType messageType =
                        // (ResponseMessageType)jaxbElement.getValue();
                        // BodyType bt = messageType.getMessageBody();
                        // ResultResponseType resultResponseType =
                        // (ResultResponseType) new
                        // JAXBUnWrapHelper().getObjectByClass(bt.getAny(),
                        // ResultResponseType.class);
                        // QueryResultInstanceType queryResultInstanceType =
                        // resultResponseType.getQueryResultInstance().get(0);
                        // strWriter = new StringWriter();

                        //log.info(jTable1.getSelectedColumn());

                        //else {
                        //site = "HIVE";
                        //}
                        //String hid = patientRowData.get(selection[i]-1).patientID;
                        //String site = "HIVE";
                        edu.harvard.i2b2.wkplclient.datavo.dnd.PatientType patientType = new edu.harvard.i2b2.wkplclient.datavo.dnd.PatientType();
                        edu.harvard.i2b2.wkplclient.datavo.dnd.PatientSet patientSet = new edu.harvard.i2b2.wkplclient.datavo.dnd.PatientSet();
                        patientType.setPatientId(id);//nodedata.patientID());
                        // patientType.setUploadId(nodedata.patientSetID());
                        //patientSet.setPatientSetId(nodedata.patientSetID());
                        //patientSet.setPatientSetName(nodedata.queryName());
                        patientSet.getPatient().add(patientType);

                        PidType pidType = new PidType();
                        PidType.PatientId pid = new PidType.PatientId();
                        pid.setValue(id);//nodedata.patientID());
                        pidType.setPatientId(pid);

                        PidSet pset = new PidSet();
                        pset.getPid().add(pidType);

                        PatientIdType pdoPidType = new PatientIdType();
                        pdoPidType.setValue(id);
                        pdoPidType.setSource(site);

                        PatientType pdoPatientType = new PatientType();
                        pdoPatientType.setPatientId(pdoPidType);
                        pdoPatientSet.getPatient().add(pdoPatientType);
                        //}

                        DndType dnd = new DndType();
                        // edu.harvard.i2b2.crcxmljaxb.datavo.pdo.ObjectFactory
                        // pdoOf = new
                        // edu.harvard.i2b2.crcxmljaxb.datavo.pdo.ObjectFactory();
                        // dnd.getAny().add(patientType);

                        //dnd.getAny().add(patientSet);
                        //dnd.getAny().add(pset);
                        dnd.getAny().add(pdoPatientSet);
                        edu.harvard.i2b2.wkplclient.datavo.dnd.ObjectFactory of = new edu.harvard.i2b2.wkplclient.datavo.dnd.ObjectFactory();
                        WorkplaceJAXBUtil.getJAXBUtil().marshaller(of.createPluginDragDrop(dnd), strWriter);
                    } catch (JAXBUtilException e) {
                        // log.error("Error marshalling Ont drag text");
                        // throw e;
                        e.printStackTrace();
                    }
                    //////
                    createWorkplaceNode(workItem, currentTarget,
                            XmlUtil.stringToXml(strWriter.toString())/*xml*/, name, workXmlI2B2Type,
                            visualAttribute, moveFlag);
                    name = "PDO";
                }
            }
        }

        if (visualAttribute.equals("")) {
            MessageBox mBox = new MessageBox(Display.getCurrent().getActiveShell(),
                    SWT.ICON_INFORMATION | SWT.OK);
            mBox.setText("Unsupported Work Item Message");
            mBox.setMessage("Work item being dropped is not supported.");
            log.info("Work item being dropped is not supported.");
            int result = mBox.open();
            return;
        }

        /*         TreeData tdata = new TreeData();
                
                 if(workItem != null){
                    tdata.setTooltip(workItem.getTooltip());
                    tdata.setName(workItem.getName());
                    tdata.setIndex(workItem.getIndex());
                 }
                 else{
                    tdata.setTooltip(workXmlI2B2Type + ":" + name);
                    tdata.setName(name);
                    tdata.setIndex(new AddChildRequestMessage().generateMessageId());      
                 }
                
                 tdata.setParentIndex(currentTarget.getData().getIndex());
                 tdata.setVisualAttributes(visualAttribute);
                 tdata.setWorkXml(xml);
                 tdata.setWorkXmlI2B2Type(workXmlI2B2Type);
                 tdata.setUserId(UserInfoBean.getInstance().getUserName());
                 tdata.setGroupId(currentTarget.getData().getGroupId());
                 tdata.setShareId(currentTarget.getData().getShareId());
                 tdata.setWorkXmlSchema(null);
                 tdata.setEntryDate(null);
                 tdata.setChangeDate(null);
                 tdata.setStatusCd(null);
                 tdata.setTableCd(currentTarget.getData().getTableCd());
                      
                 TreeNode child = new TreeNode(tdata);
                 currentTarget.addChild(child);
                 // check to see if we are moving node or adding a new nod
                 if(event.display.getData() != null) {
                    if(event.display.getData().equals("M|O*V+E"))
                       child.moveNode(viewer).start();
                 }
                 else
                    child.addNode(viewer).start(); */
        //      createWorkplaceNode(workItem, currentTarget, xml, name, workXmlI2B2Type, visualAttribute, moveFlag);
        viewer.refresh();
    }

    else
        log.debug("No transfer happened -- data was null");
}

From source file:esg.node.components.registry.RegistrationGleaner.java

public Registration createRegistrationFromString(String registrationContent) {
    log.trace("Creating registration info from String:\n" + registrationContent + "\n");
    Registration fromContentRegistration = null;
    try {//ww  w.  jav  a2  s  .co m
        JAXBContext jc = JAXBContext.newInstance(Registration.class);
        Unmarshaller u = jc.createUnmarshaller();
        JAXBElement<Registration> root = u.unmarshal(new StreamSource(new StringReader(registrationContent)),
                Registration.class);
        fromContentRegistration = root.getValue();
    } catch (Exception e) {
        log.error(e);
    }
    return fromContentRegistration;
}

From source file:com.evolveum.midpoint.testing.wstest.AbstractWebserviceTest.java

protected void assertNoAttribute(ShadowType shadow, QName attrName) {
    ShadowAttributesType attributes = shadow.getAttributes();
    for (Object any : attributes.getAny()) {
        if (any instanceof Element) {
            Element element = (Element) any;
            if (DOMUtil.getQName(element).equals(attrName)) {
                AssertJUnit.fail("Unexpected attribute " + attrName + " in shadow "
                        + ModelClientUtil.toString(shadow) + ": " + element.getTextContent());
            }//from w  ww .j a  v  a  2s.  c o  m
        } else if (any instanceof JAXBElement<?>) {
            JAXBElement<?> jaxbElement = (JAXBElement<?>) any;
            if (jaxbElement.getName().equals(attrName)) {
                AssertJUnit.fail("Unexpected attribute " + attrName + " in shadow "
                        + ModelClientUtil.toString(shadow) + ": " + jaxbElement.getValue());
            }
        } else {
            AssertJUnit.fail("Unexpected thing " + any + " in shadow attributes");
        }
    }

}

From source file:edu.harvard.i2b2.eclipse.login.LoginDialog.java

/**
 * Method to get the message version of the hive.
 * //from  w  w w.ja v a2  s  . c  om
 * @return  version
 * 
 */
private String getHiveMessageVersion() {
    StringWriter strWriter = null;
    try {
        strWriter = new StringWriter();

        edu.harvard.i2b2.pm.datavo.pm.version.RequestMessageType reqMessageType = new edu.harvard.i2b2.pm.datavo.pm.version.RequestMessageType();
        edu.harvard.i2b2.pm.datavo.pm.version.RequestMessageType.MessageBody body = new edu.harvard.i2b2.pm.datavo.pm.version.RequestMessageType.MessageBody();
        body.setGetMessageVersion(""); //$NON-NLS-1$
        reqMessageType.setMessageBody(body);

        edu.harvard.i2b2.pm.datavo.pm.version.ObjectFactory of = new edu.harvard.i2b2.pm.datavo.pm.version.ObjectFactory();
        ProjectManagementJAXBUtil.getJAXBUtil().marshaller(of.createRequest(reqMessageType), strWriter);
        //      log.info("get version request: "+strWriter.toString());

        String response = ""; //$NON-NLS-1$

        if (System.getProperty("webServiceMethod").equals("SOAP")) { //$NON-NLS-1$ //$NON-NLS-2$
            response = LoginHelper.sendSOAP(new EndpointReference(currentPrj.getUrl()), strWriter.toString(),
                    "http://rpdr.partners.org/GetVersion", "GetVersion"); //$NON-NLS-1$ //$NON-NLS-2$
            log.info(currentPrj.getUrl());
            log.info("version response: " + response); //$NON-NLS-1$
        } else {
            response = LoginHelper.sendREST(new EndpointReference(
                    //pmAddress + "getVersion"), 
                    currentPrj.getUrl() + "getVersion"), //$NON-NLS-1$
                    strWriter.toString());
            log.info(currentPrj.getUrl() + "getVersion"); //$NON-NLS-1$
            log.info("version response: " + response); //$NON-NLS-1$
        }

        JAXBElement element = ProjectManagementJAXBUtil.getJAXBUtil().unMashallFromString(response);
        edu.harvard.i2b2.pm.datavo.pm.version.ResponseMessageType responseMessageType = (edu.harvard.i2b2.pm.datavo.pm.version.ResponseMessageType) element
                .getValue();

        return responseMessageType.getMessageBody().getI2B2MessageVersion();
    } catch (JAXBUtilException e) {
        log.error("Error marshalling get version request message"); //$NON-NLS-1$
        //e.printStackTrace();
        return null;
    } catch (AxisFault e) {
        e.printStackTrace();
        return null;
    } catch (Exception e) {
        //e.printStackTrace();
        return null;
    }
}

From source file:be.fedict.eid.dss.client.DigitalSignatureServiceClient.java

/**
 * Verifies whether the given document has been signed and reports back on
 * the signing parties.//w w w.  ja v a2s  .c o  m
 * 
 * @param signedDocument
 *            signed document to verify
 * @param mimeType
 *            optional mime-type, default is "text/xml".
 * @param originalDocument
 *            the optional original document.
 * @return a list of signature information objects detailing on the signing
 *         parties.
 * @throws NotParseableXMLDocumentException
 *             XML document was not parseable.
 */
public List<SignatureInfo> verifyWithSigners(byte[] signedDocument, String mimeType, byte[] originalDocument)
        throws NotParseableXMLDocumentException {

    ResponseBaseType responseBase = doVerification(signedDocument, mimeType, false, true, originalDocument);

    validateResult(responseBase);

    // parse VerificationReport
    List<SignatureInfo> signers = new LinkedList<SignatureInfo>();
    VerificationReportType verificationReport = findVerificationReport(responseBase);
    if (null == verificationReport) {
        return signers;
    }

    List<IndividualReportType> individualReports = verificationReport.getIndividualReport();
    for (IndividualReportType individualReport : individualReports) {

        if (!DSSConstants.RESULT_MAJOR_SUCCESS.equals(individualReport.getResult().getResultMajor())) {
            LOG.warn("some invalid VR result reported: " + individualReport.getResult().getResultMajor());
            continue;
        }
        SignedObjectIdentifierType signedObjectIdentifier = individualReport.getSignedObjectIdentifier();
        Date signingTime = signedObjectIdentifier.getSignedProperties().getSignedSignatureProperties()
                .getSigningTime().toGregorianCalendar().getTime();

        List<Object> details = individualReport.getDetails().getAny();
        X509Certificate signer = null;
        String role = null;
        for (Object detail : details) {
            if (detail instanceof JAXBElement<?>) {
                JAXBElement<?> detailElement = (JAXBElement<?>) detail;
                if (detailedSignatureReportQName.equals(detailElement.getName())) {
                    DetailedSignatureReportType detailedSignatureReport = (DetailedSignatureReportType) detailElement
                            .getValue();

                    List<CertificateValidityType> certificateValidities = detailedSignatureReport
                            .getCertificatePathValidity().getPathValidityDetail().getCertificateValidity();
                    CertificateValidityType certificateValidity = certificateValidities.get(0);
                    byte[] encodedSigner = certificateValidity.getCertificateValue();
                    try {
                        signer = (X509Certificate) this.certificateFactory
                                .generateCertificate(new ByteArrayInputStream(encodedSigner));
                    } catch (CertificateException e) {
                        throw new RuntimeException("cert decoding error: " + e.getMessage(), e);
                    }

                    PropertiesType properties = detailedSignatureReport.getProperties();
                    if (null != properties) {
                        SignerRoleType signerRole = properties.getSignedProperties()
                                .getSignedSignatureProperties().getSignerRole();
                        if (null != signerRole) {
                            role = (String) signerRole.getClaimedRoles().getClaimedRole().get(0).getContent()
                                    .get(0);
                        }
                    }
                }
            }
        }
        if (null == signer) {
            throw new RuntimeException("no signer certificate present in verification report");
        }
        SignatureInfo signatureInfo = new SignatureInfo(signer, signingTime, role);
        signers.add(signatureInfo);
    }

    return signers;
}