Java Code Examples for javax.xml.bind.JAXB#unmarshal()
The following examples show how to use
javax.xml.bind.JAXB#unmarshal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BiGramGenerator.java From lucene4ir with Apache License 2.0 | 6 votes |
private void readParamsFromFile() { System.out.println("Reading Param File"); try { p = JAXB.unmarshal(new File(sourceParameterFile), BiGramGeneratorParams.class ); if (p.indexName.toString().isEmpty()) displayMsg ("IndexName Parameter is Missing"); System.out.println("Index: " + p.indexName); if (p.outFilePath.toString().isEmpty()) displayMsg ("Query Output Path Parameter is Missing"); if (p.cutoff < 1) { p.cutoff = 0; } System.out.println("biGram Cutoff: " + p.cutoff); } catch (Exception e) { System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); System.exit(1); } }
Example 2
Source File: JacksonProviderTest.java From proarc with GNU General Public License v3.0 | 6 votes |
@Test public void testDublinCoreRecord() throws Exception { ObjectMapper om = new JacksonProvider().getContext(DublinCoreRecord.class); om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); URL resource = JacksonProviderTest.class.getResource("dc_test.xml"); assertNotNull(resource); OaiDcType dc = JAXB.unmarshal(resource, OaiDcType.class); DublinCoreRecord dr = new DublinCoreRecord(dc, System.currentTimeMillis(), "uuid:1"); String toJson = om.writeValueAsString(dr); // System.out.println(toJson); DublinCoreRecord ndr = om.readValue(toJson, DublinCoreRecord.class); assertEquals(dr.getBatchId(), ndr.getBatchId()); assertEquals(dr.getPid(), ndr.getPid()); assertEquals(dr.getTimestamp(), ndr.getTimestamp()); assertEquals(dr.getDc().getIdentifiers(), ndr.getDc().getIdentifiers()); assertEquals(dr.getDc().getTitles(), ndr.getDc().getTitles()); assertEquals(dr.getDc().getCreators(), ndr.getDc().getCreators()); StringWriter toXml = new StringWriter(); DcUtils.marshal(new StreamResult(toXml), ndr.getDc(), true); toXml.flush(); // System.out.println("---"); // System.out.println(toXml); }
Example 3
Source File: QERetrievalApp.java From lucene4ir with Apache License 2.0 | 6 votes |
/** * 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; }
Example 4
Source File: FieldedRetrievalApp.java From lucene4ir with Apache License 2.0 | 6 votes |
/** * 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); }
Example 5
Source File: Test_Issue144.java From gradle-fury with Apache License 2.0 | 6 votes |
@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()); } } } } }
Example 6
Source File: ExampleStatsApp.java From lucene4ir with Apache License 2.0 | 5 votes |
public void readExampleStatsParamsFromFile(String indexParamFile) { try { IndexParams p = JAXB.unmarshal(new File(indexParamFile), IndexParams.class); indexName = p.indexName; } catch (Exception e) { System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); System.exit(1); } }
Example 7
Source File: RepProcCache.java From scelight with Apache License 2.0 | 5 votes |
/** * Returns the cache config bean. * * @return the cache config bean */ private static ConfigBean getConfig() { if ( config == null && Files.exists( PATH_CONFIG_BEAN ) ) try { config = JAXB.unmarshal( PATH_CONFIG_BEAN.toFile(), ConfigBean.class ); } catch ( final Exception e ) { Env.LOGGER.error( "Failed to read replay processor cache config from: " + PATH_CONFIG_BEAN, e ); } return config; }
Example 8
Source File: TestFhirPath.java From cql_engine with Apache License 2.0 | 5 votes |
private Tests loadTestsFile(String testsFilePath) { try { InputStream testsFileRaw = TestFhirPath.class.getResourceAsStream(testsFilePath); return JAXB.unmarshal(testsFileRaw, Tests.class); } catch (Exception e) { //e.printStackTrace(); throw new IllegalArgumentException("Couldn't load tests file [" + testsFilePath + "]: " + e.toString()); } }
Example 9
Source File: AlephXServer.java From proarc with GNU General Public License v3.0 | 5 votes |
private MetadataItem addBarcodeMetadata(MetadataItem item, int sysno) throws IOException, TransformerException { //add before ending tag of </mods> //identifier type="barcode">XXXX</identifier> String mods = item.getMods(); int pos = mods.indexOf("\n</mods>"); if (pos == -1) { LOG.log(Level.WARNING, "Barcode could not be added. Missing ending tag \"</mods>\""); return item; } ItemDataResponse details = null; try { details = JAXB.unmarshal(fetchItemData(sysno), ItemDataResponse.class); } catch (UnknownHostException ex) { LOG.log(Level.WARNING, "Unknown host: " + ex.getMessage()); } if (details == null) { LOG.log(Level.WARNING, "Could not read item data response. Details null."); return item; } for (ItemDataResponse.Item idr : details.getItems()) { String barcode = idr.getBarcode(); if (barcode == null || barcode.length() != 10 || !barcode.matches("[0-9]+")) { LOG.log(Level.WARNING, "Could not load barcode, invalid format: " + barcode); continue; } mods = mods.substring(0,pos) + "\n<identifier type=\"barcode\">" + barcode + "</identifier>" + mods.substring(pos); } return new MetadataItem(item.getId(), item.getRdczId(), mods, item.getPreview(), item.getTitle()); }
Example 10
Source File: TokenAnalyzerMaker.java From lucene4ir with Apache License 2.0 | 5 votes |
public Analyzer createAnalyzer( String tokenFilterFile) { Analyzer analyzer = null; try { lucene4ir.utils.TokenFilters tokenFilters = JAXB.unmarshal(new File(tokenFilterFile), lucene4ir.utils.TokenFilters.class); CustomAnalyzer.Builder builder; if (tokenFilters.getResourceDir() != null) { builder = CustomAnalyzer.builder(Paths.get(tokenFilters.getResourceDir())); } else { builder = CustomAnalyzer.builder(); } builder.withTokenizer(tokenFilters.getTokenizer()); for (lucene4ir.utils.TokenFilter filter : tokenFilters.getTokenFilters()) { System.out.println("Token filter: " + filter.getName()); List<lucene4ir.utils.Param> params = filter.getParams(); if (params.size() > 0) { Map<String, String> paramMap = new HashMap<>(); for (lucene4ir.utils.Param param : params) { paramMap.put(param.getKey(), param.getValue()); } builder.addTokenFilter(filter.getName(), paramMap); } else { builder.addTokenFilter(filter.getName()); } } analyzer = builder.build(); } catch (IOException ioe){ System.out.println(" caught a " + ioe.getClass() + "\n with message: " + ioe.getMessage()); } return analyzer; }
Example 11
Source File: LocalStorageTest.java From proarc with GNU General Public License v3.0 | 5 votes |
@Test public void testDatastreamEditorWriteXml_ManagedAsAttached() throws Exception { LocalStorage storage = new LocalStorage(); LocalObject lobject = storage.create(); String dsID = "dsID"; MediaType mime = MediaType.TEXT_XML_TYPE; String label = "label"; String formatUri = "formatUri"; XmlStreamEditor editor = lobject.getEditor(FoxmlUtils.managedProfile(dsID, formatUri, label)); assertNotNull(editor); assertNotNull(editor.getProfile()); assertEquals(mime.toString(), editor.getProfile().getDsMIME()); assertEquals(formatUri, editor.getProfile().getDsFormatURI()); File attachment = tmp.newFile(); editor.write(attachment.toURI(), 0, null); XmlData xdata = new XmlData("data"); EditorResult xmlResult = editor.createResult(); JAXB.marshal(xdata, xmlResult); editor.write(xmlResult, editor.getLastModified(), null); lobject.flush(); // is managed DigitalObject dobj = lobject.getDigitalObject(); DatastreamType ds = FoxmlUtils.findDatastream(dobj, dsID); assertNotNull(ds); assertEquals(ControlGroup.MANAGED.toExternal(), ds.getCONTROLGROUP()); // is attached DatastreamVersionType dsv = FoxmlUtils.findDataStreamVersion(dobj, dsID); assertNotNull(dsv); assertEquals(mime.toString(), dsv.getMIMETYPE()); assertEquals(label, dsv.getLABEL()); assertEquals(formatUri, dsv.getFORMATURI()); assertNull(dsv.getBinaryContent()); assertNull(dsv.getXmlContent()); assertNotNull(dsv.getContentLocation()); XmlData result = JAXB.unmarshal(attachment, XmlData.class); assertEquals(xdata, result); }
Example 12
Source File: BigramGenerator.java From lucene4ir with Apache License 2.0 | 5 votes |
public void readBigramGeneratorParamsFromFile(String paramFile) { System.out.println("Reading Param File"); try { p = JAXB.unmarshal(new File(paramFile), BigramGeneratorParams.class); if (p.indexName == null) { p.indexName = "apIndex"; } System.out.println("Index: " + p.indexName); if (p.outFile == null) { p.outFile = "bigram.qry"; } System.out.println("Output File: " + p.outFile); if (p.cutoff < 1) { p.cutoff = 0; } System.out.println("Cutoff: " + p.cutoff); if (p.field == null) { p.field = Lucene4IRConstants.FIELD_ALL; } System.out.println("Field: " + p.field); } catch (Exception e) { System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); System.exit(1); } }
Example 13
Source File: SoftwareListChdSet.java From ia-rcade with Apache License 2.0 | 5 votes |
/** * Get the best SoftwareListChdSet for the given Mame version. * * "Best" means equal or greatest inferior to given Mame version. */ public static SoftwareListChdSet findBest(MameVersion version) { MameVersion bestVersion; if (versions.contains(version)) { bestVersion = version; } else { bestVersion = versions.floor(version); IaRcade.warn("No archive.org softlist CHD set matches your Mame version"); IaRcade.warn("Some files might not be available."); } // Unmarshal SoftwareListChdSet from XML data stored in classpath StringBuilder builder = new StringBuilder("softwarelist-chd-set/"); builder.append(bestVersion); builder.append(".xml"); InputStream stream = SoftwareListChdSet.class.getClassLoader() .getResourceAsStream(builder.toString()); SoftwareListChdSet chdSet = JAXB.unmarshal(stream, SoftwareListChdSet.class); return chdSet; }
Example 14
Source File: Test_Issue144.java From gradle-fury with Apache License 2.0 | 5 votes |
@Test public void validatePom() throws Exception { for (int i=0; i < Main.allPoms.length; i++) { Model project = JAXB.unmarshal(new File(Main.allPoms[i]), Model.class); Assert.assertNotNull(project); } }
Example 15
Source File: GlobalTransactionManager.java From dapeng-soa with Apache License 2.0 | 5 votes |
private static String callServiceMethod(TGlobalTransactionProcess process, boolean rollbackOrForward) throws Exception { String responseJson; OptimizedMetadata.OptimizedService service = null; //获取服务的metadata String metadata = new MetadataClient(process.getServiceName(), process.getVersionName()).getServiceMetadata(); if (metadata != null) { try (StringReader reader = new StringReader(metadata)) { service = new OptimizedMetadata.OptimizedService(JAXB.unmarshal(reader, Service.class)); } } //获取服务的ip和端口 JsonPost jsonPost = new JsonPost(process.getServiceName(), process.getVersionName(), process.getMethodName()); InvocationContextImpl invocationContext = (InvocationContextImpl)InvocationContextImpl.Factory.currentInstance(); invocationContext.serviceName(process.getServiceName()); invocationContext.versionName(process.getVersionName()); invocationContext.methodName(rollbackOrForward ? process.getRollbackMethodName() : process.getMethodName()); invocationContext.callerMid("GlobalTransactionManager"); invocationContext.transactionId(process.getTransactionId()); invocationContext.transactionSequence(process.getTransactionSequence()); if (rollbackOrForward) { responseJson = jsonPost.callServiceMethod("{}", service); } else { responseJson = jsonPost.callServiceMethod(process.getRequestJson(), service); } return responseJson; }
Example 16
Source File: JsonSerializerTest.java From dapeng-soa with Apache License 2.0 | 4 votes |
private static Service getService(final String xmlFilePath) throws IOException { String xmlContent = IOUtils.toString(JsonSerializerTest.class.getResource(xmlFilePath), "UTF-8"); return JAXB.unmarshal(new StringReader(xmlContent), Service.class); }
Example 17
Source File: RegManager.java From scelight with Apache License 2.0 | 4 votes |
/** * Creates a new {@link RegManager}. */ public RegManager() { // Check registration file if ( !Files.exists( PATH_REGISTRATION_FILE ) ) { regStatus = RegStatus.NOT_FOUND; LEnv.LOGGER.debug( "No registration file found." ); regInfo = null; return; } // Load registration info RegInfoBean regInfo_; try { final byte[] regInfoEncData = Files.readAllBytes( PATH_REGISTRATION_FILE ); // "reginfo.xml.deflated.enc" int offset = 0; // Check magic for ( int i = 0; i < REG_FILE_MAGIC.length; i++, offset++ ) if ( REG_FILE_MAGIC[ i ] != regInfoEncData[ offset ] ) throw new RuntimeException( "Invalid magic word!" ); // Check version for ( int i = 0; i < REG_FILE_VERSION.length; i++, offset++ ) if ( REG_FILE_VERSION[ i ] != regInfoEncData[ offset ] ) throw new RuntimeException( "Invalid or unsupported version!" ); // Check key selector for ( int i = 0; i < KEY_SELECTOR.length; i++, offset++ ) if ( KEY_SELECTOR[ i ] != regInfoEncData[ offset ] ) throw new RuntimeException( "Invalid or unsupported key selector!" ); // We're cool, decrypt... final byte[] regInfodeflatedXmlData = DecryptUtil.decrypt( regInfoEncData, offset, regInfoEncData.length - offset ); // "reginfo.xml.deflated" if ( regInfodeflatedXmlData == null ) throw new Exception( "Failed to decrypt registration file!" ); // ...and inflate try ( final InputStream in = new InflaterInputStream( new ByteArrayInputStream( regInfodeflatedXmlData ) ) ) { regInfo_ = JAXB.unmarshal( in, RegInfoBean.class ); // "reginfo.xml" } if ( LEnv.LOGGER.testDebug() ) LEnv.LOGGER.debug( "Registration info loaded (registered to: " + regInfo_.getPerson().getPersonName() + ")." ); if ( LEnv.LOGGER.testTrace() ) LEnv.LOGGER.trace( "Registration info: " + regInfo_.toString() ); } catch ( final Exception e ) { regStatus = RegStatus.INVALID; LEnv.LOGGER.error( "Invalid or corrupt registration file: " + PATH_REGISTRATION_FILE, e ); regInfo = null; return; } regInfo = regInfo_; // Check expiration final Calendar expCal = Calendar.getInstance(); expCal.setTime( regInfo.getEncryptionDate() ); expCal.add( Calendar.MONTH, REG_FILE_EXPIRATION_MONTHS ); if ( new Date().after( expCal.getTime() ) ) { regStatus = RegStatus.EXPIRED; LEnv.LOGGER.warning( "Registration file has expired!" ); return; } // Quick check if registered system info matches current system info if ( !LUtils.getSysInfo().matches( regInfo.getSysInfo() ) ) { regStatus = RegStatus.SYSINFO_MISMATCH; LEnv.LOGGER.warning( "Registration info mismatch: your system info does not match the registered system info!" ); return; } regStatus = RegStatus.MATCH; }
Example 18
Source File: MachineRepository.java From ia-rcade with Apache License 2.0 | 4 votes |
/** * Return a MameSystem object corresponding to the given system name */ public Machine findByName(String machineName) throws IOException, InterruptedException, MachineDoesntExistException { // Call MameRuntime to get Xml data of the given system, // then unmarshall it String[] mameCommandLine = {"-listxml", machineName}; InputStream is; MameXmlContainer ms = null; try { is = this.mame.executeAndReturnStdoutAsInputStream(mameCommandLine); ms = JAXB.unmarshal(is, MameXmlContainer.class); } catch (MameExecutionException | DataBindingException e) { throw (MachineDoesntExistException) new MachineDoesntExistException( String.format("The machine '%s' doesn't exist or is not " + "supported by the provided Mame version", machineName)) .initCause(e); } Machine machine = null; Set<Machine> subMachines = new HashSet<>(); for (Machine m : ms.getMachines()) { if (m.getName().equals(machineName.toLowerCase())) { machine = m; String cloneof = m.getCloneof(); if (cloneof != null) { m.setClonedMachine(this.findByName(cloneof)); } String romof = m.getRomof(); if (romof != null) { m.setRomOfMachine(this.findByName(romof)); } } else { // Others machines of the set are considered "subMachines" subMachines.add(m); } } if (machine == null) { throw new RuntimeException(String .format("Unhandled case: Mame returned no errors while searching " + "for machine %s but the machine has not been found " + "on the XML content", machineName)); } machine.setSubMachines(subMachines); return machine; }
Example 19
Source File: RetrievalAppQueryExpansion.java From lucene4ir with Apache License 2.0 | 4 votes |
public void readParamsFromFile(String paramFile){ /* Reads in the xml formatting parameter file Maybe this code should go into the RetrievalParams class. Actually, it would probably be neater to create a ParameterFile class which these apps can inherit from - and customize accordinging. */ try { p = JAXB.unmarshal(new File(paramFile), RetrievalParams.class); } catch (Exception e){ System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); System.exit(1); } setSim(p.model); if (p.maxResults==0.0) {p.maxResults=1000;} if (p.b == 0.0){ p.b = 0.75f;} if (p.beta == 0.0){p.beta = 500f;} if (p.k ==0.0){ p.k = 1.2f;} if (p.lam==0.0){p.lam = 0.5f;} if (p.mu==0.0){p.mu = 500f;} if (p.c==0.0){p.c=10.0f;} if (p.model == null){ p.model = "def"; } if (p.runTag == null){ p.runTag = p.model.toLowerCase(); } if (p.resultFile == null){ p.resultFile = p.runTag+"_results.res"; } System.out.println("Path to index: " + p.indexName); System.out.println("Query File: " + p.queryFile); System.out.println("Result File: " + p.resultFile); System.out.println("Model: " + p.model); System.out.println("Max Results: " + p.maxResults); System.out.println("b: " + p.b); }
Example 20
Source File: RetrievalAppByIndexAPI.java From lucene4ir with Apache License 2.0 | 4 votes |
public static RetrieverParams readParamsFromFile(String paramFile){ /* Reads in the xml formatting parameter file Maybe this code should go into the RetrieverParams class. Actually, it would probably be neater to create a ParameterFile class which these apps can inherit from - and customize accordinging. */ RetrieverParams p = null; try { p = JAXB.unmarshal(new File(paramFile), RetrieverParams.class); } catch (Exception e){ e.printStackTrace(); System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); System.exit(1); } if (p.maxResults==0.0) {p.maxResults=1000;} if (p.b == 0.0){ p.b = 0.75f;} if (p.beta == 0.0){p.beta = 500f;} if (p.k ==0.0){ p.k = 1.2f;} if (p.delta==0.0){p.delta = 1.0f;} if (p.lam==0.0){p.lam = 0.5f;} if (p.mu==0.0){p.mu = 500f;} if (p.c==0.0){p.c=10.0f;} if (p.model == null){ p.model = "def"; } if (p.runTag == null){ p.runTag = p.model.toLowerCase(); } if (p.resultFile == null){ p.resultFile = p.runTag+"_results.res"; } System.out.println("Path to index: " + p.indexName); System.out.println("Query File: " + p.queryFile); System.out.println("Result File: " + p.resultFile); System.out.println("Model: " + p.model); System.out.println("Max Results: " + p.maxResults); System.out.println("b: " + p.b); return p; }