當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。