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:esg.node.components.registry.LasSistersGleaner.java

public synchronized LasSistersGleaner loadMyLasServers() {
    log.info("Loading my LAS LasServers info from " + sistersPath + sistersFile);
    try {//from w ww. j  a v a 2s  . c o m
        JAXBContext jc = JAXBContext.newInstance(LasServers.class);
        Unmarshaller u = jc.createUnmarshaller();
        JAXBElement<LasServers> root = u.unmarshal(new StreamSource(new File(sistersPath + sistersFile)),
                LasServers.class);
        servers = root.getValue();
    } catch (Exception e) {
        log.error(e);
    }
    return this;
}

From source file:be.fedict.eid.pkira.xkmsws.util.XMLMarshallingUtil.java

/**
 * Extracts the first element from the list matching the type.
 * /*  w ww  . ja  va  2 s.c om*/
 * @param name
 *            name of the element to get.
 * @param list
 *            list with either this type of a JAXBElement with this type.
 * @return the first matching element.
 */
public Object getFromJAXBElementList(List<Object> list, String name) {
    for (Object object : list) {
        if (object instanceof JAXBElement<?>) {
            JAXBElement<?> element = (JAXBElement<?>) object;
            if (name.equals(element.getName().getLocalPart())) {
                return element.getValue();
            }
        } else if (object instanceof Element) {
            Element element = (Element) object;
            if (name.equals(element.getLocalName())) {
                return element.getTextContent().trim();
            }
        }
    }

    return null;
}

From source file:com.agimatec.validation.jsr303.xml.ValidationParser.java

private void applyMappingStreams(ValidationConfigType xmlConfig, ConfigurationImpl target) {
    for (JAXBElement<String> mappingFileName : xmlConfig.getConstraintMapping()) {
        if (log.isDebugEnabled()) {
            log.debug("Trying to open input stream for " + mappingFileName.getValue());
        }//w  ww .j  a  va  2s  .  c om
        InputStream in;
        try {
            in = getInputStream(mappingFileName.getValue());
            if (in == null) {
                throw new ValidationException(
                        "Unable to open input stream for mapping file " + mappingFileName.getValue());
            }
        } catch (IOException e) {
            throw new ValidationException(
                    "Unable to open input stream for mapping file " + mappingFileName.getValue(), e);
        }
        target.addMapping(in);
    }
}

From source file:com.github.lindenb.jvarkit.tools.blast.BlastFilterJS.java

@Override
protected Collection<Throwable> call(String inputName) throws Exception {

    final CompiledScript compiledScript;
    Unmarshaller unmarshaller;//from  w  ww.j a v a2 s .  c  o m
    Marshaller marshaller;
    try {
        compiledScript = super.compileJavascript();

        JAXBContext jc = JAXBContext.newInstance("gov.nih.nlm.ncbi.blast");

        unmarshaller = jc.createUnmarshaller();
        marshaller = jc.createMarshaller();

        XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        PrintWriter pw = openFileOrStdoutAsPrintWriter();
        XMLOutputFactory xof = XMLOutputFactory.newFactory();
        xof.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
        XMLEventWriter w = xof.createXMLEventWriter(pw);

        StreamSource src = null;
        if (inputName == null) {
            LOG.info("Reading stdin");
            src = new StreamSource(stdin());
        } else {
            LOG.info("Reading file " + inputName);
            src = new StreamSource(new File(inputName));
        }

        XMLEventReader r = xmlInputFactory.createXMLEventReader(src);

        XMLEventFactory eventFactory = XMLEventFactory.newFactory();

        SimpleBindings bindings = new SimpleBindings();
        while (r.hasNext()) {
            XMLEvent evt = r.peek();
            switch (evt.getEventType()) {
            case XMLEvent.START_ELEMENT: {
                StartElement sE = evt.asStartElement();
                Hit hit = null;
                JAXBElement<Hit> jaxbElement = null;
                if (sE.getName().getLocalPart().equals("Hit")) {
                    jaxbElement = unmarshaller.unmarshal(r, Hit.class);
                    hit = jaxbElement.getValue();
                } else {
                    w.add(r.nextEvent());
                    break;
                }

                if (hit != null) {

                    bindings.put("hit", hit);

                    boolean accept = super.evalJavaScriptBoolean(compiledScript, bindings);

                    if (accept) {
                        marshaller.marshal(jaxbElement, w);
                        w.add(eventFactory.createCharacters("\n"));
                    }
                }

                break;
            }
            case XMLEvent.SPACE:
                break;
            default: {
                w.add(r.nextEvent());
                break;
            }
            }
            r.close();
        }
        w.flush();
        w.close();
        pw.flush();
        pw.close();
        return RETURN_OK;
    } catch (Exception err) {
        return wrapException(err);
    } finally {

    }
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.AbstractActivityParser.java

/**
 * Deals with the not-so-helpful/*from   w w w .  jav a  2  s.c  o  m*/
 * getHandledReferenceSchemesOrTranslatedElementTypeOrName method
 * 
 * @param portBean
 * @param elementName
 * @return
 */
private <T> T getPortElement(ActivityPortDefinitionBean portBean, String elementName, Class<T> type) {
    for (JAXBElement<?> elem : portBean.getHandledReferenceSchemesOrTranslatedElementTypeOrName())
        if (elem.getName().getLocalPart().equals(elementName))
            return type.cast(elem.getValue());
    return null;
}

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

public synchronized AzsWhitelistGleaner loadMyAzsWhitelist() {
    log.info("Loading my AZS Whitelist info from " + azsWhitelistPath + azsWhitelistFile);
    try {/*from ww  w  . ja va  2 s .  c o m*/
        JAXBContext jc = JAXBContext.newInstance(AzsWhitelist.class);
        Unmarshaller u = jc.createUnmarshaller();
        JAXBElement<AzsWhitelist> root = u
                .unmarshal(new StreamSource(new File(azsWhitelistPath + azsWhitelistFile)), AzsWhitelist.class);
        azss = root.getValue();
    } catch (Exception e) {
        log.error(e);
    }
    return this;
}

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

public synchronized IdpWhitelistGleaner loadMyIdpWhitelist() {
    log.info("Loading my IDP Whitelist info from " + idpWhitelistPath + idpWhitelistFile);
    try {//from  ww w.j  a  v  a2  s .  c  om
        JAXBContext jc = JAXBContext.newInstance(IdpWhitelist.class);
        Unmarshaller u = jc.createUnmarshaller();
        JAXBElement<IdpWhitelist> root = u
                .unmarshal(new StreamSource(new File(idpWhitelistPath + idpWhitelistFile)), IdpWhitelist.class);
        idps = root.getValue();
    } catch (Exception e) {
        log.error(e);
    }
    return this;
}

From source file:ddf.catalog.registry.transformer.RegistryTransformer.java

private Metacard unmarshal(InputStream xmlStream) throws ParserException, RegistryConversionException {
    MetacardImpl metacard = null;//w  w w  .  ja v a 2 s .c o  m

    JAXBElement<RegistryObjectType> registryObjectTypeJAXBElement = parser.unmarshal(configurator,
            JAXBElement.class, xmlStream);
    if (registryObjectTypeJAXBElement != null) {

        RegistryObjectType registryObjectType = registryObjectTypeJAXBElement.getValue();

        if (registryObjectType != null) {

            metacard = (MetacardImpl) RegistryPackageConverter.getRegistryObjectMetacard(registryObjectType);

        }
    }

    return metacard;
}

From source file:it.govpay.ejb.ndp.util.wsclient.NodoPerPa.java

private void dump(StringBuffer content, JAXBElement<?> jaxb) {
    if (jaxb.getValue() instanceof NodoInviaRPT) {
        NodoInviaRPT obj = ((NodoInviaRPT) jaxb.getValue());
        content.append("\n\tidentificativoCanale: " + obj.getIdentificativoCanale());
        content.append("\n\tidentificativoIntermediarioPSP: " + obj.getIdentificativoIntermediarioPSP());
        content.append("\n\tidentificativoPSP: " + obj.getIdentificativoPSP());
        content.append("\n\ttipoFirma: " + obj.getTipoFirma());
        content.append("\n\t" + new String(obj.getRpt()));
        log.debug(content);//ww  w . j a  v a  2s  . c  o  m
        return;
    }

    if (jaxb.getValue() instanceof NodoInviaCarrelloRPT) {
        NodoInviaCarrelloRPT obj = ((NodoInviaCarrelloRPT) jaxb.getValue());
        content.append("\n\tidentificativoCanale: " + obj.getIdentificativoCanale());
        content.append("\n\tidentificativoIntermediarioPSP: " + obj.getIdentificativoIntermediarioPSP());
        content.append("\n\tidentificativoPSP: " + obj.getIdentificativoPSP());
        for (TipoElementoListaRPT ele : obj.getListaRPT().getElementoListaRPT()) {
            content.append("\n\tidentificativoDominio: " + ele.getIdentificativoDominio());
            content.append("\n\tidentificativoUnivocoVersamento: " + ele.getIdentificativoUnivocoVersamento());
            content.append("\n\ttipoFirma: " + ele.getTipoFirma());
            content.append("\n\t" + new String(ele.getRpt()));
        }
        log.debug(content);
        return;
    }

    if (jaxb.getValue() instanceof NodoChiediInformativaPSPRisposta) {
        NodoChiediInformativaPSPRisposta obj = ((NodoChiediInformativaPSPRisposta) jaxb.getValue());
        try {
            if (obj.getXmlInformativa() != null)
                content.append(IOUtils.toString(obj.getXmlInformativa().getInputStream()));
            else
                log.warn("Informativa PSP vuota");
        } catch (IOException e) {
            log.warn("Impossibile serializzare l'Informativa PSP: " + e);
        }
        log.debug(content);
        return;
    }

    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        NdpUtils.marshal(jaxb, baos);
        content.append("Contenuto XML: \n" + baos.toString());
    } catch (Exception e) {
        log.error("Impossibile serializzare il messaggio: " + e);
    }

    log.debug(content);
}

From source file:be.fedict.eid.pkira.xkmsws.util.XMLMarshallingUtil.java

/**
 * Extracts the first element from the list matching the type.
 * //  w  w w.j  a v  a 2s  .co m
 * @param <T>
 *            expected type.
 * @param clazz
 *            expected type.
 * @param list
 *            list with either this type of a JAXBElement with this type.
 * @return the first matching element.
 */
public <T> T getFromList(Class<T> clazz, List<Object> list) {
    for (Object object : list) {
        if (clazz.isInstance(object)) {
            return clazz.cast(object);
        }
        if (object instanceof JAXBElement<?>) {
            JAXBElement<?> jaxbElement = (JAXBElement<?>) object;
            if (jaxbElement.getDeclaredType().equals(clazz)) {
                return clazz.cast(jaxbElement.getValue());
            }
        }
    }

    return null;
}