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:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.SessionWSDaoImpl.java

@Override
public BlackboardSessionResponse setSessionChairs(long bbSessionId, Set<ConferenceUser> sessionChairs) {
    final BlackboardUpdateSession updateSession = new ObjectFactory().createBlackboardUpdateSession();

    updateSession.setSessionId(bbSessionId);

    final String chairList = buildUidList(sessionChairs);
    updateSession.setChairList(chairList);

    final Object objSessionResponse = sasWebServiceOperations
            .marshalSendAndReceiveToSAS("http://sas.elluminate.com/UpdateSession", updateSession);
    @SuppressWarnings("unchecked")
    JAXBElement<BlackboardSessionResponseCollection> response = (JAXBElement<BlackboardSessionResponseCollection>) objSessionResponse;
    return DataAccessUtils.singleResult(response.getValue().getSessionResponses());
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.SessionWSDaoImpl.java

@Override
public BlackboardSessionResponse setSessionNonChairs(long bbSessionId, Set<ConferenceUser> sessionNonChairs) {
    final BlackboardUpdateSession updateSession = new ObjectFactory().createBlackboardUpdateSession();

    updateSession.setSessionId(bbSessionId);

    final String chairList = buildUidList(sessionNonChairs);
    updateSession.setNonChairList(chairList);

    final Object objSessionResponse = sasWebServiceOperations
            .marshalSendAndReceiveToSAS("http://sas.elluminate.com/UpdateSession", updateSession);
    @SuppressWarnings("unchecked")
    JAXBElement<BlackboardSessionResponseCollection> response = (JAXBElement<BlackboardSessionResponseCollection>) objSessionResponse;
    return DataAccessUtils.singleResult(response.getValue().getSessionResponses());
}

From source file:be.fedict.eid.idp.model.bean.ProtocolServiceManagerBean.java

@SuppressWarnings("unchecked")
public List<IdentityProviderProtocolType> getProtocolServices() {
    List<IdentityProviderProtocolType> protocolServices = new LinkedList<IdentityProviderProtocolType>();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    Enumeration<URL> resources;
    try {/*from  w  ww .  jav  a2 s  .  c om*/
        resources = classLoader.getResources("META-INF/eid-idp-protocol.xml");
    } catch (IOException e) {
        LOG.error("I/O error: " + e.getMessage(), e);
        return protocolServices;
    }
    Unmarshaller unmarshaller;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
        unmarshaller = jaxbContext.createUnmarshaller();
    } catch (JAXBException e) {
        LOG.error("JAXB error: " + e.getMessage(), e);
        return protocolServices;
    }
    while (resources.hasMoreElements()) {
        URL resource = resources.nextElement();
        LOG.debug("resource URL: " + resource.toString());
        JAXBElement<IdentityProviderProtocolsType> jaxbElement;
        try {
            jaxbElement = (JAXBElement<IdentityProviderProtocolsType>) unmarshaller.unmarshal(resource);
        } catch (JAXBException e) {
            LOG.error("JAXB error: " + e.getMessage(), e);
            continue;
        }
        IdentityProviderProtocolsType identityProviderProtocols = jaxbElement.getValue();
        for (IdentityProviderProtocolType identityProviderProtocol : identityProviderProtocols
                .getIdentityProviderProtocol()) {
            protocolServices.add(identityProviderProtocol);
        }
    }
    return protocolServices;
}

From source file:be.fedict.eid.idp.model.bean.AttributeServiceManagerBean.java

@SuppressWarnings("unchecked")
public List<IdentityProviderAttributeType> getAttributeServiceTypes() {

    List<IdentityProviderAttributeType> attributeServices = new LinkedList<IdentityProviderAttributeType>();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    Enumeration<URL> resources;
    try {//from  ww  w. j a v a2 s .co m
        resources = classLoader.getResources("META-INF/eid-idp-attribute.xml");
    } catch (IOException e) {
        LOG.error("I/O error: " + e.getMessage(), e);
        return attributeServices;
    }
    Unmarshaller unmarshaller;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
        unmarshaller = jaxbContext.createUnmarshaller();
    } catch (JAXBException e) {
        LOG.error("JAXB error: " + e.getMessage(), e);
        return attributeServices;
    }
    while (resources.hasMoreElements()) {
        URL resource = resources.nextElement();
        LOG.debug("resource URL: " + resource.toString());
        JAXBElement<IdentityProviderAttributesType> jaxbElement;
        try {
            jaxbElement = (JAXBElement<IdentityProviderAttributesType>) unmarshaller.unmarshal(resource);
        } catch (JAXBException e) {
            LOG.error("JAXB error: " + e.getMessage(), e);
            continue;
        }
        IdentityProviderAttributesType identityProviderAttributes = jaxbElement.getValue();
        for (IdentityProviderAttributeType identityProviderAttribute : identityProviderAttributes
                .getIdentityProviderAttribute()) {
            attributeServices.add(identityProviderAttribute);
        }
    }
    return attributeServices;
}

From source file:edu.harvard.i2b2.crc.delegate.getnameinfo.GetNameInfoRequestDelegate.java

/**
 * @see edu.harvard.i2b2.crc.delegate.RequestHandlerDelegate#handleRequest(java.lang.String)
 *///w  w w .  j a  v a  2  s.  co  m
public String handleRequest(String requestXml) throws I2B2Exception {
    //      PdoQryHeaderType headerType = null;  PsmQryHeaderType
    FindByChildType childType = null;
    String response = null;
    JAXBUtil jaxbUtil = CRCJAXBUtil.getJAXBUtil();

    try {
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(requestXml);
        RequestMessageType requestMessageType = (RequestMessageType) jaxbElement.getValue();
        BodyType bodyType = requestMessageType.getMessageBody();

        if (bodyType == null) {
            log.error("null value in body type");
            throw new I2B2Exception("null value in body type");
        }

        // Call PM cell to validate user

        StatusType procStatus = null;
        try {
            SecurityType securityType = null;
            String projectId = null;
            if (requestMessageType.getMessageHeader() != null) {
                if (requestMessageType.getMessageHeader().getSecurity() != null) {
                    securityType = requestMessageType.getMessageHeader().getSecurity();
                }
                projectId = requestMessageType.getMessageHeader().getProjectId();
            }

            if (securityType == null) {
                procStatus = new StatusType();
                procStatus.setType("ERROR");
                procStatus.setValue("Request message missing user/password");
                response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
                return response;
            }
            if (projectId == null) {
                procStatus = new StatusType();
                procStatus.setType("ERROR");
                procStatus.setValue("Missing <project_id>");
                response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
                return response;
            }

            PMServiceDriver pmServiceDriver = new PMServiceDriver();
            ProjectType projectType = pmServiceDriver.checkValidUser(securityType, projectId);
            // projectType.getRole()
            if (projectType == null) {
                procStatus = new StatusType();
                procStatus.setType("ERROR");
                procStatus.setValue("Invalid user/password for the given project [" + projectId + "]");
                response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
                return response;
            }

            log.debug("project name from PM " + projectType.getName());
            log.debug("project id from PM " + projectType.getId());
            if (projectType.getRole() != null) {
                log.debug("project role from PM " + projectType.getRole().get(0));
                this.putRoles(projectId, securityType.getUsername(), securityType.getDomain(),
                        projectType.getRole());

                //TODO removed cache
                //Node rootNode = CacheUtil.getCache().getRoot();
                //List<String> roles = (List<String>) rootNode
                //      .get(securityType.getDomain() + "/" + projectId
                //            + "/" + securityType.getUsername());
                List<String> roles = (List<String>) CacheUtil
                        .get(securityType.getDomain() + "/" + projectId + "/" + securityType.getUsername());
                if (roles != null) {
                    log.debug("User Roles count " + roles.size());
                }

                ParamUtil paramUtil = new ParamUtil();
                paramUtil.clearParam(projectId, securityType.getUsername(), securityType.getDomain(),
                        ParamUtil.CRC_ENABLE_UNITCD_CONVERSION);
                if (projectType.getParam() != null) {
                    for (ParamType param : projectType.getParam()) {
                        if (param.getName() != null && param.getName().trim()
                                .equalsIgnoreCase(ParamUtil.CRC_ENABLE_UNITCD_CONVERSION)) {
                            paramUtil.putParam(projectId, securityType.getUsername(), securityType.getDomain(),
                                    ParamUtil.CRC_ENABLE_UNITCD_CONVERSION, param);
                            String unitCdCache = paramUtil.getParam(projectId, securityType.getUsername(),
                                    securityType.getDomain(), ParamUtil.CRC_ENABLE_UNITCD_CONVERSION);
                            log.debug("CRC param stored in the cache Project Id [" + projectId + "] user ["
                                    + securityType.getUsername() + "] domain [" + securityType.getDomain()
                                    + "] " + ParamUtil.CRC_ENABLE_UNITCD_CONVERSION + "[" + unitCdCache + "]");
                            break;
                        }
                    }
                }

            } else {

                log.error("Project role not set for the user ");

            }
        } catch (AxisFault e) {
            procStatus = new StatusType();
            procStatus.setType("ERROR");
            procStatus.setValue("Could not connect to server[" + e.getDetail() + "]");
            response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
            return response;
        } catch (I2B2Exception e) {
            procStatus = new StatusType();
            procStatus.setType("ERROR");
            procStatus.setValue("Project Management cell interface error: [" + e.getMessage() + "]");
            response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
            return response;
        } catch (JAXBUtilException e) {
            procStatus = new StatusType();
            procStatus.setType("ERROR");
            procStatus.setValue("Message error from Project Management cell[" + e.getMessage() + "]");
            response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
            return response;
        }

        JAXBUnWrapHelper unWrapHelper = new JAXBUnWrapHelper();
        childType = (FindByChildType) unWrapHelper.getObjectByClass(bodyType.getAny(),
                edu.harvard.i2b2.crc.datavo.setfinder.query.FindByChildType.class);

        BodyType responseBodyType = null;

        GeNameInfoHandler handler = new GeNameInfoHandler(requestXml);
        responseBodyType = handler.execute();
        /*
        if (childType.getRequestType().equals(
              PdoRequestTypeType.GET_PDO_FROM_INPUT_LIST)) {
           GetPDOFromInputListHandler handler = new GetPDOFromInputListHandler(
          requestXml);
           responseBodyType = handler.execute();
        } else if (headerType.getRequestType().equals(
              PdoRequestTypeType.GET_OBSERVATIONFACT_BY_PRIMARY_KEY)) {
           GetObservationFactFromPrimaryKeyHandler handler = new GetObservationFactFromPrimaryKeyHandler(
          requestXml);
           responseBodyType = handler.execute();
        } else if (headerType.getRequestType().equals(
              PdoRequestTypeType.GET_PDO_TEMPLATE)) {
           GetPDOTemplateHandler handler = new GetPDOTemplateHandler(
          requestXml);
           responseBodyType = handler.execute();
        }
        */
        procStatus = new StatusType();
        procStatus.setType("DONE");
        procStatus.setValue("DONE");

        long startTime = System.currentTimeMillis();
        response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, responseBodyType,
                true);
        long endTime = System.currentTimeMillis();
        long totalTime = endTime - startTime;
        log.debug("Total time to pdo  jaxb  " + totalTime);

    } catch (JAXBUtilException e) {
        log.error("JAXBUtil exception", e);
        StatusType procStatus = new StatusType();
        procStatus.setType("ERROR");
        procStatus.setValue(requestXml + "\n\n" + StackTraceUtil.getStackTrace(e));
        try {
            response = I2B2MessageResponseFactory.buildResponseMessage(null, procStatus, null);
        } catch (JAXBUtilException e1) {
            e1.printStackTrace();
        }
    } catch (I2B2Exception e) {
        log.error("I2B2Exception", e);
        StatusType procStatus = new StatusType();
        procStatus.setType("ERROR");
        procStatus.setValue(StackTraceUtil.getStackTrace(e));
        try {
            response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, null);
        } catch (JAXBUtilException e1) {
            e1.printStackTrace();
        }
    } catch (Throwable e) {
        log.error("Throwable", e);
        StatusType procStatus = new StatusType();
        procStatus.setType("ERROR");
        procStatus.setValue(StackTraceUtil.getStackTrace(e));
        try {
            response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, null);
        } catch (JAXBUtilException e1) {
            e1.printStackTrace();
        }
    }
    return response;
}

From source file:nz.co.senanque.sandbox.ObjectTest.java

@Test
public void test1() throws Exception {
    @SuppressWarnings("unused")
    Object en = IndustryType.fromValue("Ag");
    ValidationSession validationSession = m_validationEngine.createSession();

    // create a customer
    Customer customer = m_customerDAO.createCustomer();
    validationSession.bind(customer);/*from  w  w w  .j a va  2 s  .  c  om*/
    Invoice invoice = new Invoice();
    invoice.setDescription("test invoice");
    invoice.setTestBoolean(true);
    customer.getInvoices().add(invoice);
    boolean exceptionFound = false;
    try {
        customer.setName("ttt");
    } catch (ValidationException e) {
        exceptionFound = true;
    }
    assertTrue(exceptionFound);

    final ObjectMetadata customerMetadata = validationSession.getMetadata(customer);
    @SuppressWarnings("unused")
    final FieldMetadata customerTypeMetadata = customerMetadata.getFieldMetadata(Customer.CUSTOMERTYPE);

    //        assertFalse(customerTypeMetadata.isActive());
    //        assertFalse(customerTypeMetadata.isReadOnly());
    //        assertFalse(customerTypeMetadata.isRequired());

    customer.setName("aaaab");
    exceptionFound = false;
    try {
        customer.setCustomerType("B");
    } catch (Exception e) {
        exceptionFound = true;
    }
    //        assertTrue(exceptionFound);
    exceptionFound = false;
    try {
        customer.setCustomerType("XXX");
    } catch (Exception e) {
        exceptionFound = true;
    }
    assertTrue(exceptionFound);
    customer.setBusiness(IndustryType.AG);
    customer.setAmount(new Double(500.99));
    final long id = m_customerDAO.save(customer);
    log.info("{}", id);

    // fetch customer back
    customer = m_customerDAO.getCustomer(id);
    @SuppressWarnings("unused")
    final int invoiceCount = customer.getInvoices().size();
    validationSession.bind(customer);
    invoice = new Invoice();
    ValidationUtils.setDefaults(invoice);
    invoice.setDescription("test invoice2");
    invoice.setTestBoolean(true);
    customer.getInvoices().add(invoice);
    assertEquals("xyz", invoice.getTestDefault());
    assertEquals("Ag", invoice.getTestEnumDefault().value());
    m_customerDAO.save(customer);

    // fetch customer again
    customer = m_customerDAO.getCustomer(id);
    customer.toString();
    final Invoice inv0 = customer.getInvoices().get(0);
    assertTrue(inv0.isTestBoolean());

    validationSession.bind(customer);
    final Invoice inv = customer.getInvoices().get(0);
    assertTrue(inv.isTestBoolean());
    customer.getInvoices().remove(inv);

    //ObjectMetadata metadata = validationSession.getMetadata(customer);
    ObjectMetadata metadata = customer.getMetadata();
    assertEquals("this is a description", metadata.getFieldMetadata(Customer.NAME).getDescription());
    assertEquals("ABC", metadata.getFieldMetadata(Customer.NAME).getPermission());
    @SuppressWarnings("unused")
    List<ChoiceBase> choices = metadata.getFieldMetadata(Customer.BUSINESS).getChoiceList();
    //        assertEquals(1,choices.size());
    List<ChoiceBase> choices2 = metadata.getFieldMetadata(Customer.CUSTOMERTYPE).getChoiceList();
    //        assertEquals(1,choices2.size());
    choices2 = metadata.getFieldMetadata(Customer.CUSTOMERTYPE).getChoiceList();
    //        assertEquals(1,choices2.size());

    for (ChoiceBase choice : choices2) {
        System.out.println(choice.getDescription());
    }

    customer.setName("aab");
    choices2 = metadata.getFieldMetadata(Customer.CUSTOMERTYPE).getChoiceList();
    //        assertEquals(6,choices2.size());

    // Convert customer to XML
    QName qname = new QName("http://www.example.org/sandbox", "Session");
    JAXBElement<Session> sessionJAXB = new JAXBElement<Session>(qname, Session.class, new Session());
    sessionJAXB.getValue().getCustomers().add(customer); //??This fails to actually add
    StringWriter marshallWriter = new StringWriter();
    Result marshallResult = new StreamResult(marshallWriter);
    m_marshaller.marshal(sessionJAXB, marshallResult);
    marshallWriter.flush();
    String result = marshallWriter.getBuffer().toString().trim();
    String xml = result.replaceAll("\\Qhttp://www.example.org/sandbox\\E", "http://www.example.org/sandbox");
    log.info("{}", xml);

    // Convert customer back to objects
    SAXBuilder builder = new SAXBuilder();
    org.jdom.Document resultDOM = builder.build(new StringReader(xml));
    @SuppressWarnings("unchecked")
    JAXBElement<Session> request = (JAXBElement<Session>) m_unmarshaller.unmarshal(new JDOMSource(resultDOM));
    validationSession = m_validationEngine.createSession();
    validationSession.bind(request.getValue());
    assertEquals(3, validationSession.getProxyCount());
    List<Customer> customers = request.getValue().getCustomers();
    assertEquals(1, customers.size());
    assertTrue(customers.get(0).getInvoices().get(0).isTestBoolean());
    customers.clear();
    assertEquals(1, validationSession.getProxyCount());
    request.toString();
    validationSession.close();
}

From source file:fi.kela.kanta.cda.Purkaja.java

/**
 * Apumetodi nimen purkamiseen Muodostaan KokoNimiTOn annetun PN Listan pohjalta
 *
 * @param names//from ww w  .  j av a2  s .c  o m
 *            List<PN> nimet
 * @return KokoNimiTO nimist
 */
protected KokoNimiTO puraKokoNimi(List<PN> names) {
    KokoNimiTO kokoNimi = new KokoNimiTO();
    for (PN name : names) {
        for (Serializable element : name.getContent()) {
            if (element instanceof JAXBElement<?>) {
                JAXBElement<?> el = (JAXBElement<?>) element;
                if (el.getValue() instanceof ENXP) {
                    puraNimitieto((ENXP) el.getValue(), kokoNimi);
                }
            }
        }

    }
    return kokoNimi;
}

From source file:eu.dasish.annotation.backend.rest.AnnotationResourceTest.java

@Test
public void testGetAnnotation() throws NotInDataBaseException, IOException {
    System.out.println("getAnnotation");
    final String externalIDstring = "00000000-0000-0000-0000-000000000021";
    final Annotation expectedAnnotation = (new TestInstances("/api")).getAnnotationOne();
    annotationResource.setHttpServletRequest(mockRequest);
    mockRequest.setRemoteUser("alice@mail.domain");
    mockRequest.setContextPath("/backend");
    mockRequest.setServletPath("/api");
    mockeryRest.checking(new Expectations() {
        {/*from  w  w w.  j  a v a  2  s  .c o  m*/

            oneOf(mockDbDispatcher).setResourcesPaths("/backend/api");

            oneOf(mockDbDispatcher).getPrincipalInternalIDFromRemoteID("alice@mail.domain");
            will(returnValue(3));

            oneOf(mockDbDispatcher).getResourceInternalIdentifier(with(aNonNull(UUID.class)),
                    with(aNonNull((Resource.class))));
            will(returnValue(1));

            oneOf(mockDbDispatcher).canDo(Access.READ, 3, 1, Resource.ANNOTATION);
            will(returnValue(true));

            oneOf(mockDbDispatcher).getAnnotation(1);
            will(returnValue(expectedAnnotation));
        }
    });

    JAXBElement<Annotation> result = annotationResource.getAnnotation(externalIDstring);
    assertTrue(expectedAnnotation.equals(result.getValue()));
}

From source file:fi.kela.kanta.cda.Purkaja.java

protected void puraDocParagraph(StrucDocParagraph paragraph, List<String> nayttomuoto) {
    List<Serializable> content = paragraph.getContent();
    for (int i = 0; i < content.size(); i++) {
        if (content.get(i) instanceof JAXBElement) {
            JAXBElement<?> elem = (JAXBElement<?>) content.get(i);
            if (elem.getValue() instanceof StrucDocContent) {
                StrucDocContent doc = (StrucDocContent) elem.getValue();
                puraDocContent(doc, nayttomuoto);
            }//from ww w.  j  a v  a2 s  .  c  o m
        }

    }
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.SessionWSDaoImpl.java

@Override
public BlackboardSessionTelephonyResponse createSessionTelephony(long sessionId, SessionTelephony telephony) {
    BlackboardSetSessionTelephony request = new ObjectFactory().createBlackboardSetSessionTelephony();
    request.setSessionId(sessionId);// ww  w.  j  ava  2s .c om
    request.setChairPhone(telephony.getChairPhone());
    request.setChairPIN(telephony.getChairPIN());
    request.setIsPhone(telephony.isPhone());
    request.setNonChairPhone(telephony.getNonChairPhone());
    request.setNonChairPIN(telephony.getNonChairPIN());
    request.setSessionPIN(telephony.getSessionPIN());
    request.setSessionSIPPhone(telephony.getSessionSIPPhone());
    Object obj = sasWebServiceOperations
            .marshalSendAndReceiveToSAS("http://sas.elluminate.com/SetSessionTelephony", request);

    @SuppressWarnings("unchecked")
    JAXBElement<BlackboardSessionTelephonyResponseCollection> jaxbResponse = (JAXBElement<BlackboardSessionTelephonyResponseCollection>) obj;
    return DataAccessUtils.singleResult(jaxbResponse.getValue().getSessionTelephonyResponses());
}