Example usage for javax.xml.bind Unmarshaller unmarshal

List of usage examples for javax.xml.bind Unmarshaller unmarshal

Introduction

In this page you can find the example usage for javax.xml.bind Unmarshaller unmarshal.

Prototype

public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException;

Source Link

Document

Unmarshal XML data from the specified pull parser and return the resulting content tree.

Usage

From source file:jp.co.tis.gsp.tools.db.ObjectBrowserErParser.java

public void parse(File erdFile) throws JAXBException, IOException, TemplateException {
    JAXBContext context = JAXBContext.newInstance(Erd.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    Erd erd = (Erd) unmarshaller.unmarshal(erdFile);
    erd.init();/*from   w  w  w .j  a v a2 s.c  o m*/
    setupTemplateLoader();

    Template template = getTemplate("createTable.ftl");
    Template indexTemplate = getTemplate("createIndex.ftl");
    Template fkTemplate = getTemplate("addForeignKey.ftl");
    Template viewTemplate = getTemplate("createView.ftl");

    Map<String, Object> dto = new HashMap<String, Object>();
    erd.setSchema(schema);
    dto.put("erd", erd);
    List<Entity> entityList;
    List<View> viewList;
    ModelView modelView = erd.getModelView(schema);
    if (modelView == null) {
        entityList = erd.entityList;
        viewList = erd.getViewList();
    } else {
        entityList = modelView.getEntityList();
        viewList = modelView.getViewList();
    }

    for (Entity entity : entityList) {

        // != ??????
        if (!user.equals(schema)) {
            //ftl?.()??????????????
            entity.setSchema(schema + ".");
        }

        // SHOWTYPE?0????
        if (entity.getShowType() != 0) {
            continue;
        }

        // ?????????
        for (Column column : entity.getColumnList()) {
            if (typeMapper != null) {
                typeMapper.convert(column);
            }
        }
        dto.put("entity", entity);
        dto.put("LengthSemantics",
                BeansWrapper.getDefaultInstance().getEnumModels().get(LengthSemantics.class.getName()));
        dto.put("lengthSemantics", lengthSemantics);
        dto.put("allocationSize", allocationSize);

        if (printTable) {
            template.process(dto, getWriter("10_CREATE_" + entity.getName()));
        }

        // index
        int i = 0;
        for (Index index : entity.getIndexList()) {
            // ??????NULL?????
            if (!printIndex || index.getColumnList() == null) {
                continue;
            }
            if (StringUtils.isBlank(index.getName())) {
                index.setName("IDX_" + entity.getName() + String.format("%02d", ++i));
            }
            Map<String, Object> indexDto = new HashMap<String, Object>(dto);
            indexDto.put("index", index);
            indexTemplate.process(indexDto, getWriter("20_CREATE_" + index.getName()));
        }

        // Foreign Key
        i = 0;
        for (ForeignKey foreignKey : entity.getForeignKeyList()) {
            // ?????????EntityList?????????
            // FK????
            if (!printForeignKey || foreignKey.getReferenceEntity().getShowType() != 0
                    || !contains(entityList, foreignKey.getReferenceEntity())) {
                continue;
            }
            if (StringUtils.isBlank(foreignKey.getName())) {
                foreignKey.setName("FK_" + entity.getName() + String.format("%02d", ++i));
            }
            Map<String, Object> fkDto = new HashMap<String, Object>(dto);
            fkDto.put("foreignKey", foreignKey);
            fkTemplate.process(fkDto, getWriter("30_CREATE_" + foreignKey.getName()));
        }
    }
    // View
    if (viewList != null) {
        for (View view : viewList) {

            // != ??????
            if (!user.equals(schema)) {
                //ftl?.()??????????????
                view.setSchema(schema + ".");
            }

            if (!printView || view.getShowType() != 0) {
                continue;
            }
            dto.put("view", view);
            viewTemplate.process(dto, getWriter("40_CREATE_" + view.getName()));
        }
    }
}

From source file:com.amazonaws.sqs.util.SQSClient.java

/**
 * This method calls SQS and unmarshalls the response based on the
 * JAXBContext provided in the constructor.
 * //from  w  w  w. ja v a 2 s  .com
 * @return an object corresponding to the response from SQS
 * @throws QueueException
 */
public Object callAndUnmarshal() throws Exception {
    int maxRetries = 5;
    int numRetriesLeft = maxRetries;
    Object obj = null;
    do {
        try {
            HttpResponse response = makeCall();
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            //           System.out.println("Got a response from SQS: " + response.getBody());
            obj = unmarshaller.unmarshal(new StringReader(response.getBody()));
            break;
        } catch (Exception e) {
            if (numRetriesLeft <= 0) {
                throw e;
            }
            // else -- sleep for a bit before trying again
            Thread.sleep(1000 * (maxRetries - numRetriesLeft));
        }
    } while (numRetriesLeft-- > 0);
    return obj;
}

From source file:org.exist.xquery.RestBinariesTest.java

@Override
protected QueryResultAccessor<Result, Exception> executeXQuery(final String xquery) throws Exception {
    final HttpResponse response = postXquery(xquery);
    final HttpEntity entity = response.getEntity();
    try (final InputStream is = entity.getContent()) {
        final JAXBContext jaxbContext = JAXBContext.newInstance("org.exist.http.jaxb");
        final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        final Result result = (Result) unmarshaller.unmarshal(is);

        return consumer -> consumer.accept(result);
    }//  w  w w. j av  a2s .  c  om
}

From source file:edu.htwm.vsp.phoebook.rest.client.RestClient.java

/**
 * Example code for deserializing a PhoneUser via JAXB.
 *///from  w ww.j  a  v  a2 s.co  m
public PhoneUser unmarshalPhoneUserFromXML(Reader in) throws JAXBException {

    JAXBContext jc = JAXBContext.newInstance(PhoneUser.class);
    assertNotNull(jc);
    Unmarshaller unmarshaller = jc.createUnmarshaller();

    assertNotNull(unmarshaller);
    Object unmarshalledObj = unmarshaller.unmarshal(in);

    assertNotNull(unmarshalledObj);

    assertTrue(unmarshalledObj instanceof PhoneUser);
    return (PhoneUser) unmarshalledObj;
}

From source file:broadwick.Broadwick.java

/**
 * Read the configuration file from the configuration file.
 * <p>/*from   w ww .  ja v a2  s .co m*/
 * @param logFacade  the LoggingFacade object used to log any messages.
 * @param configFile the name of the configuration file.
 */
private void readConfigFile(final LoggingFacade logFacade, final String configFile) {
    if (!configFile.isEmpty()) {
        final File cfg = new File(configFile);
        if (!cfg.exists()) {
            throw new BroadwickException("Configuration file [" + configFile + "] does not exist.");
        }
        try {
            // read the configuration file
            final JAXBContext jaxbContext = JAXBContext.newInstance(Constants.GENERATED_CONFIG_CLASSES_DIR);
            final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            project = (Project) unmarshaller.unmarshal(cfg);

            // save the config file as a string for later use
            final StringWriter writer = new StringWriter();
            jaxbContext.createMarshaller().marshal(project, writer);
            configXml = writer.toString();

            // Validate the configuration file
            final ConfigValidator validator = new ConfigValidator(project);
            final ConfigValidationErrors validationErrors = validator.validate();

            // now set up the logger as defined in the config file, we want to do this
            // BEFORE writing the results of validation
            final Logs.File file = project.getLogs().getFile();
            if (file != null) {
                logFacade.addFileLogger(file.getName(), file.getLevel(), file.getPattern(), file.isOverwrite());
            }
            final Logs.Console console = project.getLogs().getConsole();
            if (console != null) {
                logFacade.addConsoleLogger(console.getLevel(), console.getPattern());
            }

            // Log any validation errors.
            if (validationErrors.getNumErrors() > 0) {
                log.error("Invalid configuration file.\n{}Correct any errors before continuing.",
                        validationErrors.getValidationErrors());
                project = validator.getValidatedProject();
            }

        } catch (JAXBException ex) {
            log.error("Could not read configuration file. {}", ex.toString());
            log.trace(com.google.common.base.Throwables.getStackTraceAsString(ex));
        }
    } else {
        throw new BroadwickException("No configuration file specified");
    }
}

From source file:com.evolveum.midpoint.web.application.DescriptorLoader.java

public void loadData(MidPointApplication application) {
    LOGGER.info("Loading data from descriptor files.");

    String baseFileName = "/WEB-INF/descriptor.xml";
    String customFileName = "/WEB-INF/classes/descriptor.xml";

    try (InputStream baseInput = application.getServletContext().getResourceAsStream(baseFileName);
            InputStream customInput = application.getServletContext().getResourceAsStream(customFileName)) {
        if (baseInput == null) {
            LOGGER.error(/*from ww w.ja  v  a2  s  .co m*/
                    "Couldn't find " + baseFileName + " file, can't load application menu and other stuff.");
        }

        JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        JAXBElement<DescriptorType> element = (JAXBElement) unmarshaller.unmarshal(baseInput);
        DescriptorType descriptor = element.getValue();

        LOGGER.debug("Loading menu bar from " + baseFileName + " .");
        MenuType menu = descriptor.getMenu();
        Map<Integer, RootMenuItemType> rootMenuItems = new HashMap<>();
        mergeRootMenuItems(menu, rootMenuItems);

        DescriptorType customDescriptor = null;
        if (customInput != null) {
            element = (JAXBElement) unmarshaller.unmarshal(customInput);
            customDescriptor = element.getValue();
            mergeRootMenuItems(customDescriptor.getMenu(), rootMenuItems);
        }

        List<RootMenuItemType> sortedRootMenuItems = sortRootMenuItems(rootMenuItems);
        loadMenuBar(sortedRootMenuItems);

        scanPackagesForPages(descriptor.getPackagesToScan(), application);
        if (customDescriptor != null) {
            scanPackagesForPages(customDescriptor.getPackagesToScan(), application);
        }
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "Couldn't process application descriptor", ex);
    }
}

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

private JAXBElement<BlackboardUrlResponse> mockSessionUrlResponse() throws JAXBException {
    final JAXBContext context = JAXBContext.newInstance("com.elluminate.sas");
    final Unmarshaller unmarshaller = context.createUnmarshaller();
    @SuppressWarnings("unchecked")
    JAXBElement<BlackboardUrlResponse> response = (JAXBElement<BlackboardUrlResponse>) unmarshaller
            .unmarshal(this.getClass().getResourceAsStream("/data/mockSessionCreatorUrl.xml"));

    return response;
}

From source file:be.e_contract.mycarenet.certra.CertRAClient.java

public RevocableCertificatesDataResponse getRevocableCertificates(byte[] signedCms) throws Exception {

    GetRevocableCertificatesRequest request = this.protocolObjectFactory
            .createGetRevocableCertificatesRequest();
    request.setRevocableCertificatesDataRequest(signedCms);
    GetRevocableCertificatesResponse getRevocableCertificatesResponse = this.port
            .getRevocableCertificates(request);

    byte[] responseCmsData = getRevocableCertificatesResponse.getRevocableCertificatesDataResponse();

    byte[] responseData = getCmsData(responseCmsData);

    JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    RevocableCertificatesDataResponse revocableCertificatesDataResponse = (RevocableCertificatesDataResponse) unmarshaller
            .unmarshal(new ByteArrayInputStream(responseData));
    return revocableCertificatesDataResponse;
}

From source file:io.mapzone.controller.catalog.http.CatalogRequest.java

<T> T parseBody() throws Exception {
    Unmarshaller unmarshaller = CswResponse.jaxbContext.get().createUnmarshaller();
    InputStream in = httpRequest.getInputStream();
    System.out.println("REQUEST: ");
    TeeInputStream tee = new TeeInputStream(in, System.out);
    parsedBody = ((JAXBElement) unmarshaller.unmarshal(new StreamSource(tee))).getValue();
    return (T) parsedBody;
}