当前位置: 首页>>代码示例>>Java>>正文


Java JAXB.marshal方法代码示例

本文整理汇总了Java中javax.xml.bind.JAXB.marshal方法的典型用法代码示例。如果您正苦于以下问题:Java JAXB.marshal方法的具体用法?Java JAXB.marshal怎么用?Java JAXB.marshal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.bind.JAXB的用法示例。


在下文中一共展示了JAXB.marshal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getXml

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
@GET
@Path("{operation}/{level}")
@Produces("application/xml")
public String getXml(@PathParam("operation") String operation,
   @PathParam("level") int level)
{
   // compute minimum and maximum values for the numbers
   int minimum = (int) Math.pow(10, level - 1);
   int maximum = (int) Math.pow(10, level);

   // create the numbers on the left-hand side of the equation
   int first = randomObject.nextInt(maximum - minimum) + minimum;
   int second = randomObject.nextInt(maximum - minimum) + minimum;

   // create Equation object and marshal it into XML
   Equation equation = new Equation(first, second, operation);
   StringWriter writer = new StringWriter(); // XML output here
   JAXB.marshal(equation, writer); // write Equation to StringWriter
   return writer.toString(); // return XML string
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:21,代码来源:EquationGeneratorXMLResource.java

示例2: InstanceMonitor

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
/**
 * Creates a new {@link InstanceMonitor}.
 */
public InstanceMonitor() {
	super( "Instance monitor" );
	
	ServerSocket serverSocket = null;
	try {
		// Pass 0 as port so the system will choose a free / available port for us.
		serverSocket = new ServerSocket( 0, 0, InetAddress.getByName( "localhost" ) );
		
		Env.LOGGER.trace( "Instance monitor listening on local port: " + serverSocket.getLocalPort() );
		
		// Save instance monitor info bean
		final InstMonInfBean imi = new InstMonInfBean();
		imi.setComProtVer( COM_PROT_VER );
		imi.setPort( serverSocket.getLocalPort() );
		JAXB.marshal( imi, Env.PATH_INSTANCE_MONITOR_INFO.toFile() );
		
	} catch ( final Exception e ) {
		Env.LOGGER.error( "Failed to setup instance monitor!", e );
	}
	this.serverSocket = serverSocket;
}
 
开发者ID:icza,项目名称:scelight,代码行数:25,代码来源:InstanceMonitor.java

示例3: getLemmaSelection_Gzip_Xml

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
/**
 * Same as {@link MockServer#getLemmaSelection_Xml(String)} except the
 * output is forcefully encoded as GZIP
 */
@GET
@Path("getlemma/gzip/xml/{selection}")
public Response getLemmaSelection_Gzip_Xml(@PathParam("selection") final String selection) throws IOException {
    try(final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {

        try(final GZIPOutputStream gzos = new GZIPOutputStream(baos)) {
            JAXB.marshal(getTestSuggestions(selection, null), gzos);
        }

        return Response.status(Response.Status.OK)
                .entity(baos.toByteArray())
                .encoding("gzip")
                .build();
    }
}
 
开发者ID:BCDH,项目名称:TEI-Completer,代码行数:20,代码来源:JerseyClientTest.java

示例4: main

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
/**
 * @param args used to take arguments from the running environment - not used here
 * @throws Exception if any error occurs
 */
public static void main( final String[] args ) throws Exception {
	final PersonBean author = new PersonBean();
	
	final PersonNameBean personName = new PersonNameBean();
	personName.setFirst( "András" );
	personName.setLast( "Belicza" );
	author.setPersonName( personName );
	
	final ContactBean contact = new ContactBean();
	contact.setEmail( "[email protected]" );
	contact.setLocation( "Budapest, Hungary" );
	author.setContact( contact );
	author.setDescription( "Author of BWHF, Sc2gears and Scelight" );
	
	JAXB.marshal( author, new File( LR.get( "bean/author.xml" ).toURI() ) );
}
 
开发者ID:icza,项目名称:scelight,代码行数:21,代码来源:CreateAuthorXml.java

示例5: testCertChain

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
@Test
public void testCertChain() throws Exception {
	FileInputStream fis = new FileInputStream("src/test/resources/qualifNA.xml");
	DiagnosticData diagnosticData = getJAXBObjectFromString(fis, DiagnosticData.class, "/xsd/DiagnosticData.xsd");
	assertNotNull(diagnosticData);

	CustomProcessExecutor executor = new CustomProcessExecutor();
	executor.setDiagnosticData(diagnosticData);
	executor.setValidationPolicy(loadPolicy());
	executor.setCurrentTime(diagnosticData.getValidationDate());

	Reports reports = executor.execute();

	SimpleReport simpleReport = reports.getSimpleReport();
	assertEquals(1, simpleReport.getJaxbModel().getSignaturesCount());
	XmlSignature xmlSignature = simpleReport.getJaxbModel().getSignature().get(0);
	assertTrue(!xmlSignature.getCertificateChain().getCertificate().isEmpty());
	assertEquals(3, xmlSignature.getCertificateChain().getCertificate().size());
	ByteArrayOutputStream s = new ByteArrayOutputStream();
	JAXB.marshal(simpleReport.getJaxbModel(), s);
}
 
开发者ID:esig,项目名称:dss,代码行数:22,代码来源:CustomProcessExecutorTest.java

示例6: testXmlRead

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
@Test
public void testXmlRead() throws Exception {
    String dsId = "testId";
    LocalObject local = new LocalStorage().create();
    local.setLabel(test.getMethodName());
    String format = "testns";
    XmlStreamEditor leditor = local.getEditor(FoxmlUtils.inlineProfile(dsId, format, "label"));
    EditorResult editorResult = leditor.createResult();
    TestXml content = new TestXml("test content");
    JAXB.marshal(content, editorResult);
    leditor.write(editorResult, 0, null);

    RemoteStorage fedora = new RemoteStorage(client);
    fedora.ingest(local, "junit");

    RemoteObject remote = fedora.find(local.getPid());
    RemoteXmlStreamEditor editor = new RemoteXmlStreamEditor(remote, dsId);
    Source src = editor.read();
    assertNotNull(src);
    TestXml resultContent = JAXB.unmarshal(src, TestXml.class);
    assertEquals(content, resultContent);
    long lastModified = editor.getLastModified();
    assertTrue(String.valueOf(lastModified), lastModified != 0 && lastModified < System.currentTimeMillis());
    assertEquals(format, editor.getProfile().getDsFormatURI());
}
 
开发者ID:proarc,项目名称:proarc,代码行数:26,代码来源:RemoteStorageTest.java

示例7: testGetStreamProfile

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
@Test
public void testGetStreamProfile() throws Exception {
    String dsId = "testId";
    LocalObject local = new LocalStorage().create();
    local.setLabel(test.getMethodName());
    String format = "testns";
    XmlStreamEditor leditor = local.getEditor(FoxmlUtils.inlineProfile(dsId, format, "label"));
    EditorResult editorResult = leditor.createResult();
    TestXml content = new TestXml("test content");
    JAXB.marshal(content, editorResult);
    leditor.write(editorResult, 0, null);

    RemoteStorage fedora = new RemoteStorage(client);
    fedora.ingest(local, support.getTestUser());

    RemoteObject remote = fedora.find(local.getPid());
    List<DatastreamProfile> resultProfiles = remote.getStreamProfile(null);
    assertNotNull(resultProfiles);
    assertEquals(2, resultProfiles.size()); // + DC
    assertEquals(dsId, resultProfiles.get(0).getDsID());
}
 
开发者ID:proarc,项目名称:proarc,代码行数:22,代码来源:RemoteStorageTest.java

示例8: testTaskParameterJsonXml

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
@Test
    public void testTaskParameterJsonXml() throws Exception {
        String expectedTimestamp = "2017-01-05T14:51:24.639Z";
        Calendar c = DatatypeConverter.parseDateTime(expectedTimestamp);
        ObjectMapper om = JsonUtils.createJaxbMapper();
        TaskParameterView tp = new TaskParameterView();
        tp.addParamRef("paramRef").addTaskId(BigDecimal.TEN)
//                .addValueString("aha")
//                .addValueNumber(BigDecimal.ONE)
                .addValueDateTime(new Timestamp(c.getTimeInMillis()))
                ;
        tp.setJobId(BigDecimal.ZERO);
        String json = om.writeValueAsString(tp);
        assertTrue(json, json.contains("\"value\":\"" + expectedTimestamp));

        StringWriter stringWriter = new StringWriter();
        JAXB.marshal(tp, stringWriter);
        String xml = stringWriter.toString();
        assertTrue(xml, xml.contains(expectedTimestamp));
    }
 
开发者ID:proarc,项目名称:proarc,代码行数:21,代码来源:TaskParameterTest.java

示例9: sendGuestEvent

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
public void sendGuestEvent(Guest guest) {
    if (null == jmsContext || null == guestEventQueue) {
        LOGGER.log(WARNING, () -> "Sending messages is deactivated!");
        return;
    }

    LOGGER.info(() -> format("Sending info about %s to %s", guest, guestEventQueue));
    try {
        StringWriter w = new StringWriter();
        JAXB.marshal(guest, w);
        TextMessage textMessage = this.jmsContext.createTextMessage(w.toString());
        this.jmsContext.createProducer().send(this.guestEventQueue, textMessage);
    } catch (JMSRuntimeException e) {
        LOGGER.log(SEVERE, e, () -> "Cannot send message due to technical reasons!");
    }
}
 
开发者ID:koenighotze,项目名称:Hotel-Reservation-Tool,代码行数:17,代码来源:AsynchronousGuestEventDispatcher.java

示例10: saveConfiguration

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
/**
 * Saves the defined configuration
 * @param config Configuration to save
 * @param folder Folder where configuration is located. Do not add a trailing slash (/ or \)
 * @param file File to save the configuration in
 * @since v1.2
 */
private static void saveConfiguration(ServerConfiguration config, String folder, String file)
{
    File outputFile = new File(folder + "/" + file);
    if (outputFile.exists() == true) {
        outputFile.delete();
    }
    try {
        new File(folder).mkdir();
        outputFile.createNewFile();
        //LOG//Logger.getLogger(ServerConfiguration.class.getName()).log(Level.INFO, "Created a new configuration file.");
        LogRouter.log(ServerConfiguration.class.getName(), LoggingLevel.system, "Created a new configuration file.");
        JAXB.marshal(config, outputFile);
    } catch (IOException ex) {
        //LOG//Logger.getLogger(ServerConfiguration.class.getName()).log(Level.SEVERE, "Could not create new configuration file.", ex);
        LogRouter.log(ServerConfiguration.class.getName(), LoggingLevel.severe, "Could not create new configuration file.", ex);
    }
    config.printConfiguration();      
}
 
开发者ID:brad-richards,项目名称:AIGS,代码行数:26,代码来源:ServerConfiguration.java

示例11: getChangeRecord

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
public static ChangeRecord getChangeRecord(BusinessService model, org.uddi.api_v3.BusinessService api, String node) throws DispositionReportFaultMessage {
        ChangeRecord cr = new ChangeRecord();
        cr.setEntityKey(model.getEntityKey());
        cr.setNodeID(node);

        cr.setRecordType(ChangeRecord.RecordType.ChangeRecordNewData);
        org.uddi.repl_v3.ChangeRecord crapi = new org.uddi.repl_v3.ChangeRecord();
        crapi.setChangeID(new ChangeRecordIDType(node, -1L));
        crapi.setChangeRecordNewData(new ChangeRecordNewData());
        crapi.getChangeRecordNewData().setBusinessService(api);
        crapi.getChangeRecordNewData().setOperationalInfo(new OperationalInfo());
        MappingModelToApi.mapOperationalInfo(model, crapi.getChangeRecordNewData().getOperationalInfo());
        StringWriter sw = new StringWriter();
        JAXB.marshal(crapi, sw);
        try {
                cr.setContents(sw.toString().getBytes("UTF8"));
        } catch (UnsupportedEncodingException ex) {
                logger.error(ex);
        }
        return cr;
}
 
开发者ID:apache,项目名称:juddi,代码行数:22,代码来源:UDDIPublicationImpl.java

示例12: getChangeRecordConditional

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
private static ChangeRecord getChangeRecordConditional(Tmodel modelTModel, TModel apiTModel, String node) throws DispositionReportFaultMessage {
        ChangeRecord cr = new ChangeRecord();
        if (!apiTModel.getTModelKey().equals(modelTModel.getEntityKey())) {
                throw new FatalErrorException(new ErrorMessage("E_fatalError", "the model and api keys do not match when saving a tmodel!"));
        }
        cr.setEntityKey(modelTModel.getEntityKey());
        cr.setNodeID(node);

        cr.setRecordType(ChangeRecord.RecordType.ChangeRecordNewDataConditional);
        org.uddi.repl_v3.ChangeRecord crapi = new org.uddi.repl_v3.ChangeRecord();
        crapi.setChangeID(new ChangeRecordIDType(node, -1L));
        crapi.setChangeRecordNewDataConditional(new ChangeRecordNewDataConditional());
        crapi.getChangeRecordNewDataConditional().setChangeRecordNewData(new ChangeRecordNewData());
        crapi.getChangeRecordNewDataConditional().getChangeRecordNewData().setTModel(apiTModel);
        crapi.getChangeRecordNewDataConditional().getChangeRecordNewData().getTModel().setTModelKey(modelTModel.getEntityKey());
        crapi.getChangeRecordNewDataConditional().getChangeRecordNewData().setOperationalInfo(new OperationalInfo());
        MappingModelToApi.mapOperationalInfo(modelTModel, crapi.getChangeRecordNewDataConditional().getChangeRecordNewData().getOperationalInfo());
        StringWriter sw = new StringWriter();
        JAXB.marshal(crapi, sw);
        try {
                cr.setContents(sw.toString().getBytes("UTF8"));
        } catch (UnsupportedEncodingException ex) {
                logger.error(ex);
        }
        return cr;
}
 
开发者ID:apache,项目名称:juddi,代码行数:27,代码来源:UDDIPublicationImpl.java

示例13: save

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
/**
 * Saves the memorized tab.
 *
 * @param glyphDefinitions the glyph definitions
 */
public void save(GlyphDefinitions glyphDefinitions) {
    File path = new File(pathName);
    glyphDefinitions.setVersion(properties.getProperty("config.version"));
    Boolean pathExists = path.exists() || path.mkdir();
    if (pathExists) {
        File file = new File(path, fileName);
        LOGGER.info("Storing memorized characters table.");
        try {
            JAXB.marshal(glyphDefinitions, file);
        } catch (DataBindingException e) {
            LOGGER.error("Error storing config.", e);
        }
    } else {
        JOptionPane.showMessageDialog(
                null,
                String.format(
                        i18n.getString(this.getClass().getSimpleName()
                                + ".couldNotCreateFolder"), pathName),
                i18n.getString(this.getClass().getSimpleName()
                        + ".storeError"), JOptionPane.ERROR_MESSAGE);
    }
}
 
开发者ID:richard-strauss-werke,项目名称:glyphpicker,代码行数:28,代码来源:MemorizedCharactersLoader.java

示例14: dumpFailedReplicationRecords

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
void dumpFailedReplicationRecords(String authtoken) throws Exception {
        GetFailedReplicationChangeRecordsMessageRequest req = new GetFailedReplicationChangeRecordsMessageRequest();
        req.setAuthInfo(authtoken);
        req.setMaxRecords(20);
        req.setOffset(0);
        GetFailedReplicationChangeRecordsMessageResponse failedReplicationChangeRecords = juddi.getFailedReplicationChangeRecords(req);
        while (failedReplicationChangeRecords != null
                && failedReplicationChangeRecords.getChangeRecords() != null
                && !failedReplicationChangeRecords.getChangeRecords().getChangeRecord().isEmpty()) {
                for (int i = 0; i < failedReplicationChangeRecords.getChangeRecords().getChangeRecord().size(); i++) {
                        JAXB.marshal(failedReplicationChangeRecords.getChangeRecords().getChangeRecord().get(i), System.out);
                }
                req.setOffset(req.getOffset() + failedReplicationChangeRecords.getChangeRecords().getChangeRecord().size());
                failedReplicationChangeRecords = juddi.getFailedReplicationChangeRecords(req);
        }
}
 
开发者ID:apache,项目名称:juddi,代码行数:17,代码来源:JuddiAdminService.java

示例15: printBusinessList

import javax.xml.bind.JAXB; //导入方法依赖的package包/类
public void printBusinessList(String authtoken, String searchString, boolean rawXml) throws Exception {

                int offset = 0;
                int maxrecords = 100;
                BusinessList findBusiness = getBusinessList(authtoken, searchString, offset, maxrecords);
                while (findBusiness != null && findBusiness.getBusinessInfos() != null
                        && !findBusiness.getBusinessInfos().getBusinessInfo().isEmpty()) {
                        if (rawXml) {
                                JAXB.marshal(findBusiness, System.out);
                        } else {
                                printBusinessInfo(findBusiness.getBusinessInfos());
                                printBusinessDetails(findBusiness.getBusinessInfos(), authtoken);
                                printServiceDetailsByBusiness(findBusiness.getBusinessInfos(), authtoken);
                        }
                        offset = offset + maxrecords;

                        findBusiness = getBusinessList(authtoken, searchString, offset, maxrecords);
                }
        }
 
开发者ID:apache,项目名称:juddi,代码行数:20,代码来源:SimpleBrowse.java


注:本文中的javax.xml.bind.JAXB.marshal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。