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:com.evolveum.midpoint.wf.impl.processors.primary.user.AddAccountAssignmentAspect.java

private AttributeLookupValueInfo getApplicationInfo(AssignmentType a) {

    if (a == null) {
        throw new IllegalArgumentException("Invalid parameter: " + a);
    }/* ww w.  java2s  .  c  o  m*/
    ConstructionType construction = a.getConstruction();
    List<ResourceAttributeDefinitionType> attrs = construction.getAttribute();
    for (ResourceAttributeDefinitionType attr : attrs) {
        String attrName = attr.getRef().getLocalPart();
        if (attrName.equals("psetApplication")) {
            List<JAXBElement<?>> values = attr.getOutbound().getExpression().getExpressionEvaluator();

            JAXBElement<?> firstElement = values.iterator().next();
            RawType val = (RawType) firstElement.getValue();
            XNode xnode = val.getXnode();
            if (xnode instanceof PrimitiveXNode) {
                PrimitiveXNode pxNode = (PrimitiveXNode) xnode;
                if (pxNode.getValue() != null) {
                    Object applicationId = pxNode.getValue();
                    LOGGER.info("Application id found: " + applicationId);

                    ApplicationContext idmpApplicationContext = SpringApplicationContextHolder
                            .getApplicationContext();
                    AttributeLookupService metadataManager = (AttributeLookupService) idmpApplicationContext
                            .getBean("attributeLookupService");
                    AttributeLookupValueInfo appInfo = metadataManager.getLoookupValueInfo("UnixPermissionSet",
                            MetadataType.Application.getMetaString(),
                            new Integer(String.valueOf(applicationId)));

                    /*                      EntityInfo info = appInfo.getOwner().getOwnerInfo();
                                          LOGGER.info("App Owner: " + info.getIdentifier());*/
                    return appInfo;
                }
            }
        }
    }

    return null;
}

From source file:com.azaptree.services.command.http.handler.CommandServiceHandlerTest.java

@Test
public void test_addNumbersCommand() throws IOException, JAXBException, InterruptedException {
    final ContentExchange contentExchange = new ContentExchange(true);
    contentExchange.setMethod("POST");
    final String commandCatalogName = "CommandServiceHandlerTest";
    final String commandName = "addNumbersCommand";
    contentExchange.setURL(String.format("http://localhost:%d/command-service/%s/%s",
            httpSericeConfig.getPort(), commandCatalogName, commandName));
    contentExchange.setRequestContentType("application/xml");

    final AdditionRequestMessage requestMessage = new AdditionRequestMessage();
    requestMessage.getNumber().add(1d);/*w  w  w.ja va 2  s  . c  om*/
    requestMessage.getNumber().add(2d);
    requestMessage.getNumber().add(3d);
    final Marshaller marshaller = addNumbersCommand.getJaxbContext().get().createMarshaller();
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final ObjectFactory objectFactory = new ObjectFactory();
    marshaller.marshal(objectFactory.createAddNumbersRequest(requestMessage), bos);
    System.out.println(bos.toString());

    contentExchange.setRequestContent(new ByteArrayBuffer(bos.toByteArray()));
    client.send(contentExchange);

    contentExchange.waitForDone();
    Assert.assertEquals(contentExchange.getResponseStatus(), HttpStatus.OK_200);

    final byte[] responseContent = contentExchange.getResponseContentBytes();
    final ByteArrayInputStream bis = new ByteArrayInputStream(responseContent);
    log.info("test_addNumbersCommand(): response content: {}", new String(responseContent));
    final Unmarshaller unmarshaller = addNumbersCommand.getJaxbContext().get().createUnmarshaller();

    final JAXBElement<AdditionResponseMessage> responseMessage = (JAXBElement<AdditionResponseMessage>) unmarshaller
            .unmarshal(bis);
    Assert.assertEquals(responseMessage.getValue().getSum(), 1d + 2d + 3d);
}

From source file:de.fhg.iais.cortex.services.ingest.worker.IndexerWorker.java

private void addViewToIndex(IIngestContext context, IIndexerDocument document) throws JAXBException {

    AipObject aipObject = context.getAipObject();
    if (aipObject.isNewFormat()) {
        String institutionName = aipObject.getObjectForPathOrNull(
                NewSchemaPaths.PATH_CORTEX_ITEM_VIEW_ITEM_INSTITUTION_NAME.path(), String.class);
        if (!Strings.isNullOrEmpty(institutionName)) {
            document.addInstitutionName(institutionName);
        }/*from  w  w w  .j a v a 2s  . c o  m*/

        String rights = aipObject
                .getObjectForPathOrNull(NewSchemaPaths.PATH_CORTEX_ITEM_VIEW_ITEM_RIGHTS.path(), String.class);
        if (!Strings.isNullOrEmpty(rights)) {
            document.addView(StringUtils.normalizeSpace(rights));
        }

        Iterator<NewItemPropertyField> displayFields = aipObject.getIteratorForPath(
                NewSchemaPaths.PATH_CORTEX_ITEM_VIEW_ITEM_FIELDS_DISPLAY.path(), NewItemPropertyField.class);

        addFieldsFromView(document, displayFields);

        Iterator<NewItemPropertyField> extendedFields = aipObject.getIteratorForPath(
                NewSchemaPaths.PATH_CORTEX_ITEM_VIEW_ITEM_FIELDS_EXTENDED_DISPLAY.path(),
                NewItemPropertyField.class);
        addFieldsFromView(document, extendedFields);

        Cortex aip = aipObject.getAip();
        if (aip != null) {
            View view = aip.getView();
            if (view != null) {
                ViewInstitution institution = view.getCortexInstitution();
                if (institution != null) {
                    ViewInstitution.Locations locations = institution.getLocations();
                    if (locations != null) {
                        for (ViewInstitution.Locations.Location location : locations.getLocation()) {
                            Address institutionAddress = location.getAddress();
                            if (institutionAddress != null) {
                                document.addView(institutionAddress.getStreet());
                                document.addView(institutionAddress.getHouseIdentifier());
                                document.addView(institutionAddress.getAddressSupplement());
                                document.addView(institutionAddress.getPostalCode());
                                document.addView(institutionAddress.getCity());
                                document.addView(institutionAddress.getCountry());
                            }
                            String locationDisplayName = location.getLocationDisplayName();
                            if (!Strings.isNullOrEmpty(locationDisplayName)) {
                                document.addLocationDisplayName(locationDisplayName);
                            }
                        }
                    }
                }
            }
        }
    } else {
        String institutionName = aipObject.getObjectForPathOrNull(
                OldSchemaPaths.PATH_CORTEX_ITEM_VIEW_ITEM_INSTITUTION_NAME.path(), String.class);
        if (!Strings.isNullOrEmpty(institutionName)) {
            document.addInstitutionName(institutionName);
        }

        HtmlSnippet rights = aipObject.getObjectForPathOrNull(
                OldSchemaPaths.PATH_CORTEX_ITEM_VIEW_ITEM_RIGHTS.path(), HtmlSnippet.class);
        if (rights != null) {
            for (Serializable content : rights.getContent()) {
                if (content instanceof String) {
                    document.addView(StringUtils.normalizeSpace((String) content));
                }
            }
        }

        Iterator<ItemPropertyField> fields = aipObject.getIteratorForPath(
                OldSchemaPaths.PATH_CORTEX_ITEM_VIEW_ITEM_FIELDS.path(), ItemPropertyField.class);

        while (fields.hasNext()) {
            ItemPropertyField field = fields.next();
            for (Serializable content : field.getValue().getContent()) {
                if (content instanceof JAXBElement) {
                    JAXBElement<?> element = (JAXBElement<?>) content;
                    if (element.getValue() instanceof ItemPropertyField.Value.A) {
                        String normalizedLink = normalizeLink((A) element.getValue());
                        if (!Strings.isNullOrEmpty(normalizedLink)) {
                            document.addView(normalizedLink);
                        }
                    }
                } else if (content instanceof String) {
                    String contentAsString = StringUtils.normalizeSpace((String) content);
                    if (!Strings.isNullOrEmpty(contentAsString)) {
                        document.addView(contentAsString);
                    }
                }
            }
        }

        Address institutionAddress = aipObject.getObjectForPathOrNull(
                OldSchemaPaths.PATH_CORTEX_ITEM_VIEW_INSTITUTION_ADDRESS.path(), Address.class);

        if (institutionAddress != null) {
            document.addView(institutionAddress.getStreet());
            document.addView(institutionAddress.getHouseIdentifier());
            document.addView(institutionAddress.getAddressSupplement());
            document.addView(institutionAddress.getPostalCode());
            document.addView(institutionAddress.getCity());
            document.addView(institutionAddress.getCountry());
        }

    }
}

From source file:com.evolveum.midpoint.model.impl.ModelWebService.java

private ExecuteScriptsResponseType doExecuteScripts(List<JAXBElement<?>> scriptsToExecute,
        ExecuteScriptsOptionsType options, Task task, OperationResult result) {
    ExecuteScriptsResponseType response = new ExecuteScriptsResponseType();
    ScriptOutputsType outputs = new ScriptOutputsType();
    response.setOutputs(outputs);/*ww  w. j  a v a 2s .c o m*/

    try {
        for (JAXBElement<?> script : scriptsToExecute) {

            ScriptExecutionResult executionResult = scriptingService
                    .evaluateExpression((ScriptingExpressionType) script.getValue(), task, result);

            SingleScriptOutputType output = new SingleScriptOutputType();
            outputs.getOutput().add(output);

            output.setTextOutput(executionResult.getConsoleOutput());
            if (options == null || options.getOutputFormat() == null
                    || options.getOutputFormat() == OutputFormatType.XML) {
                output.setXmlData(prepareXmlData(executionResult.getDataOutput()));
            } else {
                // temporarily we send serialized XML in the case of MSL output
                ItemListType jaxbOutput = prepareXmlData(executionResult.getDataOutput());
                output.setMslData(prismContext.serializeAnyData(jaxbOutput, SchemaConstants.C_VALUE,
                        PrismContext.LANG_XML));
            }
        }
        result.computeStatusIfUnknown();
    } catch (ScriptExecutionException | JAXBException | SchemaException | RuntimeException
            | SecurityViolationException e) {
        result.recordFatalError(e.getMessage(), e);
        LoggingUtils.logException(LOGGER, "Exception while executing script", e);
    }
    result.summarize();
    response.setResult(result.createOperationResultType());
    return response;
}

From source file:hermes.impl.DefaultXMLHelper.java

public MessageSet readContent(InputStream istream) throws Exception {
    JAXBContext jc = contextTL.get();
    Unmarshaller u = jc.createUnmarshaller();
    JAXBElement<MessageSet> node = u.unmarshal(new StreamSource(istream), MessageSet.class);

    return node.getValue();
}

From source file:com.vmware.vchs.publicapi.samples.GatewayRuleSample.java

/**
 * This method will retrieve information to configure gateways and use the details to add Nat
 * and Firewall Rules. It will use the gateway specified by name.
 * /*w w w.jav a2  s  .  c  o m*/
 * @param edgeGatewaysHref
 *            the Href to the edgegateways
 */
private void addRules(String edgeGatewaysHref) {
    // invoking API for EdgeGateways
    HttpResponse response = HttpUtils.httpInvoke(vcd.get(edgeGatewaysHref, options));
    QueryResultRecordsType queryRecords = HttpUtils.unmarshal(response.getEntity(),
            QueryResultRecordsType.class);
    List<JAXBElement<? extends QueryResultRecordType>> Records = queryRecords.getRecord();
    String gatewayHref = null;

    // Iterating through the EdgeGateway to find href for the gateway to be used to add rules
    for (JAXBElement<? extends QueryResultRecordType> qResult : Records) {
        QueryResultEdgeGatewayRecordType rslt = new QueryResultEdgeGatewayRecordType();
        rslt = (QueryResultEdgeGatewayRecordType) qResult.getValue();

        if (rslt.getName().equalsIgnoreCase(options.edgeGateway)) {
            gatewayHref = rslt.getHref();
            // Found, break from loop
            break;
        }
    }

    // Make sure returned gatewayHref is not null
    if (null != gatewayHref) {
        // Before configuring the gateway rules need to find the url to perform the service
        // configuration action
        String serviceConfHref = getServiceConfHref(gatewayHref);

        // Retrieving the Href for the network,on which nat rules to be applied on
        String networkHref = getNetworkHref(gatewayHref);
        if (networkHref != null) {
            // Performing the main action of sample that is adding nat and firewall rules
            configureRules(networkHref, serviceConfHref);
        } else {
            throw new RuntimeException("\nFailed to find network to be used to apply rules.");
        }
    } else {
        throw new RuntimeException("Could not find gateway Href for edge gateways: " + edgeGatewaysHref);
    }
}

From source file:edu.harvard.i2b2.eclipse.plugins.adminTool.utils.PmServiceController.java

@SuppressWarnings("rawtypes")
public void setUserInfo(String responseXML) throws Exception {
    //log.info("PM response message: /n"+responseXML);
    UserInfoBean.pmResponse(responseXML);

    JAXBUtil jaxbUtil = new JAXBUtil(new String[] { "edu.harvard.i2b2.pm.datavo.pm", //$NON-NLS-1$
            "edu.harvard.i2b2.pm.datavo.i2b2message" //$NON-NLS-1$
    });/*from  w  ww .j  a v a2 s .  c  o m*/
    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseXML);
    ResponseMessageType responseMessageType = (ResponseMessageType) jaxbElement.getValue();

    String procStatus = responseMessageType.getResponseHeader().getResultStatus().getStatus().getType();
    String procMessage = responseMessageType.getResponseHeader().getResultStatus().getStatus().getValue();

    //String serverVersion = responseMessageType.getMessageHeader()
    //.getSendingApplication().getApplicationVersion();
    //System.setProperty("serverVersion", serverVersion);

    if (procStatus.equals("ERROR")) { //$NON-NLS-1$
        setMsg(procMessage);
    } else if (procStatus.equals("WARNING")) { //$NON-NLS-1$
        setMsg(procMessage);
    } else {
        BodyType bodyType = responseMessageType.getMessageBody();
        JAXBUnWrapHelper helper = new JAXBUnWrapHelper();
        ConfigureType response = (ConfigureType) helper.getObjectByClass(bodyType.getAny(),
                ConfigureType.class);

        userInfoBean.setEnvironment(response.getEnvironment());
        userInfoBean.setUserName(response.getUser().getUserName());
        userInfoBean.setUserFullName(response.getUser().getFullName());
        //userInfoBean.setUserPassword(response.getUser().getPassword());
        userInfoBean.setUserKey(response.getUser().getKey());
        userInfoBean.setUserDomain(response.getUser().getDomain());
        userInfoBean.setHelpURL(response.getHelpURL());

        //Save Global variables in properties
        if (response.getGlobalData() != null) {
            for (ParamType param : response.getGlobalData().getParam())
                userInfoBean.setGlobals(param.getName(), param.getValue());
        }
        //Save projects         
        if (response.getUser().getProject() != null)
            //userInfoBean.setProjects( response.getUser().getProject());

            //Save Cell
            if (response.getCellDatas() != null) {
            }
        //userInfoBean.setCellDatas(response.getCellDatas());
    }
}

From source file:org.wallerlab.yoink.service.PropertyWrapper.java

private void putPartitioningResultInProperty(Job<JAXBElement> job, JAXBElement<Cml> cmlElement,
        Map<JobParameter, Object> parameters, Map<String, Object> properties) {
    ObjectFactory objectFactory = new ObjectFactory();
    PropertyList propertyList = objectFactory.createPropertyList();
    propertyList.setTitle("Partitioning result  : ");
    Property property = wrapPartitionResult(job, properties, objectFactory, propertyList);
    JAXBElement propertyListJAXB = objectFactory.createPropertyList(propertyList);
    cmlElement.getValue().getAnyCmlOrAnyOrAny().add(propertyListJAXB);
}

From source file:com.microsoft.exchange.impl.ExchangeResponseUtilsImpl.java

private String parseInnerResponse(JAXBElement<? extends ResponseMessageType> innerResponse) {

    ResponseMessageType responseMessage = innerResponse.getValue();
    return parseInnerResponse(responseMessage);

}

From source file:org.cleverbus.core.AbstractOperationRouteTest.java

protected <T> T unmarshalFragment(String responseXML, Class<T> fragmentClass) throws JAXBException {
    Unmarshaller unmarshaller = JAXBContext.newInstance(fragmentClass).createUnmarshaller();
    JAXBElement<T> jaxbElement = unmarshaller.unmarshal(new StringSource(responseXML), fragmentClass);
    return jaxbElement.getValue();
}