本文整理匯總了Java中javax.xml.bind.JAXB類的典型用法代碼示例。如果您正苦於以下問題:Java JAXB類的具體用法?Java JAXB怎麽用?Java JAXB使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JAXB類屬於javax.xml.bind包,在下文中一共展示了JAXB類的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: submitJButtonActionPerformed
import javax.xml.bind.JAXB; //導入依賴的package包/類
private void submitJButtonActionPerformed(//GEN-FIRST:event_submitJButtonActionPerformed
java.awt.event.ActionEvent evt)
{//GEN-HEADEREND:event_submitJButtonActionPerformed
String name = nameJTextField.getText(); // get name from JTextField
// the URL for the REST service
String url = "http://localhost:8080/WelcomeRESTXML/" +
"webresources/welcome/" + name;
// read from URL and convert from XML to Java String
String message = JAXB.unmarshal(url, String.class);
// display the message to the user
JOptionPane.showMessageDialog(this, message,
"Welcome", JOptionPane.INFORMATION_MESSAGE);
}
開發者ID:cleitonferreira,項目名稱:LivroJavaComoProgramar10Edicao,代碼行數:17,代碼來源:WelcomeRESTXMLClientJFrame.java
示例3: generateJButtonActionPerformed
import javax.xml.bind.JAXB; //導入依賴的package包/類
private void generateJButtonActionPerformed(//GEN-FIRST:event_generateJButtonActionPerformed
java.awt.event.ActionEvent evt)
{//GEN-HEADEREND:event_generateJButtonActionPerformed
try
{
String url = String.format("http://localhost:8080/" +
"EquationGeneratorXML/webresources/equation/%s/%d",
operation, difficulty);
// convert XML back to an Equation object
Equation equation = JAXB.unmarshal(url, Equation.class);
answer = equation.getResult();
equationJLabel.setText(equation.getLeftHandSide() + " =");
checkAnswerJButton.setEnabled(true);
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
開發者ID:cleitonferreira,項目名稱:LivroJavaComoProgramar10Edicao,代碼行數:22,代碼來源:EquationGeneratorXMLClientJFrame.java
示例4: StringReader
import javax.xml.bind.JAXB; //導入依賴的package包/類
/**
* スキーマのスキーマ情報を取得するテスト$metadata_$metadata.
*/
@Test
public final void スキーマのスキーマ情報を取得するテスト$metadata_$metadata() {
TResponse res = Http.request("box/$metadata-$metadata-get.txt")
.with("path", "\\$metadata/\\$metadata")
.with("col", "setodata")
.with("accept", "application/xml")
.with("token", PersoniumUnitConfig.getMasterToken())
.returns()
.statusCode(HttpStatus.SC_OK)
.debug();
// レスポンスボディーのチェック
String str = res.getBody();
Edmx edmx = JAXB.unmarshal(new StringReader(str), Edmx.class);
Edmx checkBody = getRightEdmx();
assertTrue(checkBody.equals(edmx));
}
示例5: marshalingAndUnmarshalingEmptyObjectYieldsEqualObject
import javax.xml.bind.JAXB; //導入依賴的package包/類
/**
* Verify that unmarshal(marshal(TlsAction)) for empty action equals
* original action.
* <p>
* "Empty" action refers to a TlsAction instance initialized with empty
* constructor and without any additional values set.
* <p>
* Calling this method is expensive. <b>Should be invoked by tests in
*
* @Category(SlowTests.class) only</b>
* <p>
*
* @param actionClass
* the Class to test
* @param logger
* to which messages are written to
* @see this.marshalingEmptyActionYieldsMinimalOutput(Class<T>)
*/
public static <T extends TlsAction> void marshalingAndUnmarshalingEmptyObjectYieldsEqualObject(
Class<T> actionClass, Logger logger) {
try {
T action = actionClass.newInstance();
StringWriter writer = new StringWriter();
action.filter();
JAXB.marshal(action, writer);
TlsAction actual = JAXB.unmarshal(new StringReader(writer.getBuffer().toString()), actionClass);
action.normalize();
actual.normalize();
assertEquals(action, actual);
} catch (InstantiationException | IllegalAccessException ex) {
logger.error(ex.getLocalizedMessage(), ex);
fail();
}
}
示例6: 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();
}
}
示例7: getLemmaSelectionWithDependent_Gzip_Xml
import javax.xml.bind.JAXB; //導入依賴的package包/類
/**
* Same as {@link MockServer#getLemmaSelectionWithDependent_Xml(String, String)} except the
* output is forcefully encoded as GZIP
*/
@GET
@Path("getlemma/gzip/xml/{selection}/{dependent}")
@Produces({MediaType.APPLICATION_XML})
public Response getLemmaSelectionWithDependent_Gzip_Xml(@PathParam("selection") final String selection, @PathParam("dependent") final String dependent) throws IOException {
try(final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try(final GZIPOutputStream gzos = new GZIPOutputStream(baos)) {
JAXB.marshal( getTestSuggestions(selection, dependent), gzos);
}
return Response.status(Response.Status.OK)
.entity(baos.toByteArray())
.encoding("gzip")
.build();
}
}
示例8: unmarschallTest
import javax.xml.bind.JAXB; //導入依賴的package包/類
@Test
public void unmarschallTest()
{
UCPersoenlicheVersichertendatenXML pd = JAXB
.unmarshal(
new StringReader(
"<?xml version=\"1.0\" encoding=\"ISO-8859-15\" standalone=\"yes\"?><UC_PersoenlicheVersichertendatenXML CDM_VERSION=\"5.1.0\" xmlns=\"http://ws.gematik.de/fa/vsds/UC_PersoenlicheVersichertendatenXML/v5.1\"><Versicherter><Versicherten_ID>H719994900</Versicherten_ID><Person><Geburtsdatum>19901124</Geburtsdatum><Vorname>Niklas</Vorname><Nachname>Bunge</Nachname><Geschlecht>M</Geschlecht><StrassenAdresse><Postleitzahl>74072</Postleitzahl><Ort>Heilbronn</Ort><Land><Wohnsitzlaendercode>D</Wohnsitzlaendercode></Land><Strasse>Oststr.</Strasse><Hausnummer>100</Hausnummer></StrassenAdresse></Person></Versicherter></UC_PersoenlicheVersichertendatenXML>"),
UCPersoenlicheVersichertendatenXML.class);
UCPersoenlicheVersichertendatenXML pd2 = JAXB
.unmarshal(
new StringReader(
"<?xml version=\"1.0\" encoding=\"ISO-8859-15\" standalone=\"yes\"?><UC_PersoenlicheVersichertendatenXML CDM_VERSION=\"5.1.0\" xmlns=\"http://ws.gematik.de/fa/vsds/UC_PersoenlicheVersichertendatenXML/v5.1\"><Versicherter><Versicherten_ID>D110104619</Versicherten_ID><Person><Geburtsdatum>19800112</Geburtsdatum><Vorname>Ltu</Vorname><Nachname>Musterkarte-0461</Nachname><Geschlecht>M</Geschlecht><StrassenAdresse><Postleitzahl>24937</Postleitzahl><Ort>Flensburg</Ort><Land><Wohnsitzlaendercode>D</Wohnsitzlaendercode></Land><Strasse>M�hlenstr.</Strasse><Hausnummer>46</Hausnummer></StrassenAdresse></Person></Versicherter></UC_PersoenlicheVersichertendatenXML>"),
UCPersoenlicheVersichertendatenXML.class);
UCPersoenlicheVersichertendatenXML pd3 = JAXB
.unmarshal(
new StringReader(
"<?xml version=\"1.0\" encoding=\"ISO-8859-15\" standalone=\"yes\"?><UC_PersoenlicheVersichertendatenXML CDM_VERSION=\"5.1.0\" xmlns=\"http://ws.gematik.de/fa/vsds/UC_PersoenlicheVersichertendatenXML/v5.1\"><Versicherter><Versicherten_ID>D110104619</Versicherten_ID><Person><Geburtsdatum>19800112</Geburtsdatum><Vorname>Ltu</Vorname><Nachname>Musterkarte-0461</Nachname><Geschlecht>M</Geschlecht><StrassenAdresse><Postleitzahl>24937</Postleitzahl><Ort>Flensburg</Ort><Land><Wohnsitzlaendercode>D</Wohnsitzlaendercode></Land><Strasse>Mühlenstr.</Strasse><Hausnummer>46</Hausnummer></StrassenAdresse></Person></Versicherter></UC_PersoenlicheVersichertendatenXML>"),
UCPersoenlicheVersichertendatenXML.class);
assertNotNull(pd.getVersicherter());
assertNotNull(pd2.getVersicherter());
assertNotNull(pd3.getVersicherter());
assertNotNull(pd.getVersicherter().getPerson());
}
示例9: 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() ) );
}
示例10: 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;
}
示例11: actionPerformed
import javax.xml.bind.JAXB; //導入依賴的package包/類
@Override
public void actionPerformed( final ActionEvent event ) {
final XFileChooser fc = new XFileChooser( SAVE_FOLDER );
fc.setDialogTitle( "Choose a file to load Replay Filters from" );
fc.setFileFilter( new FileNameExtensionFilter( "Replay Filter files (*."
+ REP_FILTERS_FILE_EXT + ")", REP_FILTERS_FILE_EXT ) );
if ( XFileChooser.APPROVE_OPTION != fc.showOpenDialog( RepFiltersEditorDialog.this ) )
return;
try {
repFiltersBean = JAXB
.unmarshal( fc.getSelectedPath().toFile(), RepFiltersBean.class );
if ( rfBean != null )
rfBean.setRepFiltersBean( (RepFiltersBean) repFiltersBean );
} catch ( final Exception e ) {
Env.LOGGER.error(
"Failed to load Replay filters from file: " + fc.getSelectedPath(), e );
GuiUtils.showErrorMsg( "Failed to load Replay filters from file file:",
fc.getSelectedPath() );
return;
}
rebuildTable();
}
示例12: testExclusions
import javax.xml.bind.JAXB; //導入依賴的package包/類
@Test
public void testExclusions() throws Exception{
for (int i=0; i < Main.allPoms.length; i++) {
if (Main.allPoms[i].contains("hello-world-apk")) {
Model project = JAXB.unmarshal(new File(Main.allPoms[i]), Model.class);
Assert.assertNotNull(project);
for (int k=0; k < project.getDependencies().getDependency().size(); k++){
Dependency dependency = project.getDependencies().getDependency().get(k);
if (dependency.getGroupId().equals("ch.acra") &&
dependency.getArtifactId().equals("acra")){
Assert.assertNotNull("no exclusions were present", dependency.getExclusions());
Assert.assertEquals("no exclusions were present", 1,dependency.getExclusions().getExclusion().size());
}
}
}
}
}
示例13: readFieldedParamsFromFile
import javax.xml.bind.JAXB; //導入依賴的package包/類
/**
* Reads the additional parameters required for fielded retrieval.
* Fields and boosts are read here.
* @param paramFile
*/
public void readFieldedParamsFromFile(String paramFile){
try {
fl = JAXB.unmarshal(new File(paramFile), Fields.class);
} catch (Exception e){
System.out.println(" caught a " + e.getClass() +
"\n with message: " + e.getMessage());
System.exit(1);
}
for (Field field : fl.fields){
if(field.fieldName.equals(null))
field.fieldName=Lucene4IRConstants.FIELD_ALL;
else if(field.fieldBoost <= 0.0f)
field.fieldBoost=0.0f;
System.out.println("Field " +field.fieldName + " Boost: " + field.fieldBoost);
}
System.out.println("Fielded Results File: " + p.resultFile);
}
示例14: readQEParamsFromFile
import javax.xml.bind.JAXB; //導入依賴的package包/類
/**
* Reads the additional parameters required for expansion.
* noDocs, noTerms and additional alphas.
* @param paramFile
*/
public void readQEParamsFromFile(String paramFile){
try {
qep = JAXB.unmarshal(new File(paramFile), QERetrievalParams.class);
} catch (Exception e){
System.out.println(" caught a " + e.getClass() +
"\n with message: " + e.getMessage());
System.exit(1);
}
if (qep.noDocs<1)
qep.noDocs=10;
if (qep.noTerms<1)
qep.noTerms=10;
qeBeta=qep.qeBeta;
feedbackDocs = qep.noDocs;
feedbackTerms = qep.noTerms;
}
示例15: readIndexParamsFromFile
import javax.xml.bind.JAXB; //導入依賴的package包/類
public void readIndexParamsFromFile(String indexParamFile){
try {
p = JAXB.unmarshal(new File(indexParamFile), IndexParams.class);
} catch (Exception e){
e.printStackTrace();
System.exit(1);
}
if(p.recordPositions==null)
p.recordPositions=false;
System.out.println("Index type: " + p.indexType);
System.out.println("Path to index: " + p.indexName);
System.out.println("List of files to index: " + p.fileList);
System.out.println("Record positions in index: " + p.recordPositions);
}