/** * Load in the configuration files * * @throws SimulatorException */ public void loadConfigFiles(JSAPResult parserConfig) throws SimulatorException { // load in the simulator config file String configFile = parserConfig.getString("configPath") + parserConfig.getString("simulatorConfigFile"); XStream xstream = new XStream(); xstream.alias("SpaceSettlersConfig", SpaceSettlersConfig.class); xstream.alias("HighLevelTeamConfig", HighLevelTeamConfig.class); xstream.alias("BaseConfig", BaseConfig.class); xstream.alias("AsteroidConfig", AsteroidConfig.class); try { simConfig = (SpaceSettlersConfig) xstream.fromXML(new File(configFile)); } catch (Exception e) { throw new SimulatorException("Error parsing config file at string " + e.getMessage()); } // load in the ladder config file configFile = parserConfig.getString("configPath") + parserConfig.getString("ladderConfigFile"); xstream = new XStream(); xstream.alias("LadderConfig", LadderConfig.class); xstream.alias("HighLevelTeamConfig", HighLevelTeamConfig.class); try { ladderConfig = (LadderConfig) xstream.fromXML(new File(configFile)); ladderConfig.makePlayerNamesUnique(); } catch (Exception e) { throw new SimulatorException("Error parsing config file at string " + e.getMessage()); } }
public void setInput(Input input) throws IOException { super.setInput(input); Object stuff; XStream xstr = XStreamFactory.forVersion(0.2); try { stuff = xstr.fromXML(input.getReader()); } catch (Exception e) { xstr = XStreamFactory.forVersion(0.1); try { System.out.println("trying to read JRS v0.1"); stuff = xstr.fromXML(input.copy().getReader()); System.out.println("JRS v0.1 success."); } catch (Exception e2) { throw new IOException("illegal JRS file"); } } if (stuff instanceof JrScene) { read = (JrScene) stuff; root = read.getSceneRoot(); } else { if (stuff instanceof SceneGraphComponent) root = (SceneGraphComponent) stuff; else { root = new SceneGraphComponent(); root.setName("jrs"); SceneGraphUtility.addChildNode(root, (SceneGraphNode) stuff); } } }
/** Loads the list of commands from one game */ @Override public List<Object> getAll(int gameID) { try { db.start(); DBCollection collection = db.getDB().getCollection("moves"); XStream xStream = new XStream(); DBCursor cursor = collection.find(); if (cursor == null) return null; List<Object> commands = new ArrayList<Object>(); while (cursor.hasNext()) { DBObject obj = cursor.next(); String xml = (String) obj.get(Integer.toString(gameID)); if (xml != null) commands.add((Object) xStream.fromXML(xml)); } db.stop(true); return commands; } catch (Exception e) { e.printStackTrace(); return null; } }
/** 把xml转化为java对象 */ public static void xmlToJavaBean() { XStream stream = new XStream(new DomDriver()); String xml = "book.xml"; try { // 设置节点对应的实体类 stream.alias("book", Book.class); stream.alias("books", Books.class); // 设置XML解析出来的对象是Books对象,根节点books对应Books类,book节点对应Book类,有多个book节点,这里需转换到集合中 stream.addImplicitCollection(Books.class, "books"); // 从XML解析出Books对象 Books books = (Books) stream.fromXML(new FileReader(new File(xml))); ArrayList<Book> bookList = books.getBooks(); for (int i = 0; i < bookList.size(); i++) { Book book = (Book) bookList.get(i); // 打印实体类 System.out.println( "name:" + book.getName() + "," + "author:" + book.getAuthor() + "," + "date:" + book.getDate()); } } catch (FileNotFoundException e) { e.printStackTrace(); } }
/** @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized */ public ProjectDescriptor deserialize(InputStream source) { ProjectDescriptor descriptor = (ProjectDescriptor) xstream.fromXML(source); if (postProcess) { postProcess(descriptor); } return descriptor; }
public static Object getObjectFromXML(String xml, Class tClass) { // 将从API返回的XML数据映射到Java对象 XStream xStreamForResponseData = new XStream(); xStreamForResponseData.alias("xml", tClass); xStreamForResponseData.ignoreUnknownElements(); // 暂时忽略掉一些新增的字段 return xStreamForResponseData.fromXML(xml); }
private Set<String> getResourceNames( String namespaceName, Configuration config, String resourceType) throws MalformedURLException { Map<String, String> valueMap = new HashMap<String, String>(); Azure azure = config.getAzure(); valueMap.put("SubscriptionId", azure.getSubscriptionId()); valueMap.put("NameSpace", namespaceName); valueMap.put("ResourceType", resourceType); StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap); String resourceNamesUrlString = strSubstitutor.replace(RESOURCE_NAMES_URL); URL resourceNamesUrl = new URL(resourceNamesUrlString); if (logger.isDebugEnabled()) { logger.debug("Request resource from URL [ " + resourceNamesUrl + " ]"); } InputStream inputStream = processGetRequest( resourceNamesUrl, azure.getKeyStoreLocation(), azure.getKeyStorePassword()); XStream xstream = new XStream(); xstream.ignoreUnknownElements(); xstream.processAnnotations(Feed.class); xstream.processAnnotations(Entry.class); Feed feed = (Feed) xstream.fromXML(inputStream); Set<String> topicNames = new HashSet<String>(); List<Entry> entries = feed.getEntries(); if (entries != null && !entries.isEmpty()) { for (Entry entry : entries) { topicNames.add(entry.getTitle()); } } return topicNames; }
/** * Returns a ShopifyProductGroup representing the collection of products as specified in the xml * payload. If the xml payload is null or matches the EMPTY_RESULT guard condition, then an empty * product group is returned. * * @param xml The payload to deserialize into product group. * @return A ShopifyProductGroup either empty if xml was null/guarded or populated, but never * null. */ public static ShopifyProductGroup getProducts(String xml) { if (xml == null || xml.equalsIgnoreCase(EMPTY_RESULT)) { return new ShopifyProductGroup(); } return (ShopifyProductGroup) xstream.fromXML(xml); }
@Override @SuppressWarnings("unchecked") public <T> T deserialize(ChannelBuffer xml, Class<T> type) { if (!xml.readable()) return null; return (T) xstream.fromXML(new ChannelBufferInputStream(xml)); }
/** * Retrieves representation of an instance of org.azrul.epice.rest.service.RetrivePasswordResource * * @return an instance of java.lang.String */ @POST @Produces("application/xml") public String getXml() { // TODO return proper representation object XStream writer = new XStream(); writer.setMode(XStream.XPATH_ABSOLUTE_REFERENCES); writer.alias("RetrievePasswordResponse", RetrievePasswordResponse.class); XStream reader = new XStream(); reader.setMode(XStream.XPATH_ABSOLUTE_REFERENCES); reader.alias("RetrievePasswordRequest", RetrievePasswordRequest.class); RetrievePasswordResponse errorResponse = new RetrievePasswordResponse(); List<String> errors = new ArrayList<String>(); errors.add("MODIFY PASSWORD ERROR"); errorResponse.setErrors(errors); MultivaluedMap<String, String> params = context.getQueryParameters(); try { String request = URLDecoder.decode(params.getFirst("REQUEST"), "UTF-8"); RetrievePasswordRequest oRequest = (RetrievePasswordRequest) reader.fromXML(request); RetrievePasswordResponse oResponse = doService(oRequest); return URLEncoder.encode(writer.toXML(oResponse), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); return writer.toXML(errorResponse); } }
@Override public void transform(Object object) { Code code = (Code) object; if (code != null) { if (deepSerialize) { try { code = (Code) xStream.fromXML(xStream.toXML(code)); } catch (Exception ex) { deepSerialize = false; } } if (code != null) { CodeTransModel codeModel = new CodeTransModel(); codeModel.setCode(code.getCode()); codeModel.setCodeId(code.getCodeId()); codeModel.setCodeType(code.getCodeType()); codeModel.setLabel(code.getLabel()); getContext().transform(codeModel); } else { LOGGER.error("Serialization failed for user group transformer"); getContext().write(null); } } }
/** * Tests {@link * TriggerContextConverter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext)}. With "matrix_build.xml" as input. * * @throws Exception if so. */ @Test public void testUnmarshalOldMatrixBuild() throws Exception { XStream xStream = new XStream2(); xStream.registerConverter(new TriggerContextConverter()); xStream.alias("matrix-run", MatrixRun.class); Object obj = xStream.fromXML(getClass().getResourceAsStream("matrix_build.xml")); assertTrue(obj instanceof MatrixRun); MatrixRun run = (MatrixRun) obj; Cause.UpstreamCause upCause = run.getCause(Cause.UpstreamCause.class); List upstreamCauses = Whitebox.getInternalState(upCause, "upstreamCauses"); GerritCause cause = (GerritCause) upstreamCauses.get(0); assertNotNull(cause.getEvent()); assertEquals("platform/project", cause.getEvent().getChange().getProject()); assertNotNull(cause.getContext()); assertNotNull(cause.getContext().getThisBuild()); assertEquals("Gerrit_master-theme_matrix", cause.getContext().getThisBuild().getProjectId()); assertEquals(102, cause.getContext().getThisBuild().getBuildNumber().intValue()); assertNotNull(cause.getContext().getOthers()); assertEquals(1, cause.getContext().getOthers().size()); TriggeredItemEntity entity = cause.getContext().getOthers().get(0); assertEquals("master-theme", entity.getProjectId()); assertNull(entity.getBuildNumber()); }
/** * Tests {@link TriggerContextConverter#marshal(Object, * com.thoughtworks.xstream.io.HierarchicalStreamWriter, * com.thoughtworks.xstream.converters.MarshallingContext)}. With an empty list of "others". * * @throws Exception if so. */ @Test public void testMarshalNoOthers() throws Exception { TriggeredItemEntity entity = new TriggeredItemEntity(100, "projectX"); PatchsetCreated event = Setup.createPatchsetCreated(); TriggerContext context = new TriggerContext(event); context.setThisBuild(entity); context.setOthers(new LinkedList<TriggeredItemEntity>()); TestMarshalClass t = new TestMarshalClass(context, "Bobby", new TestMarshalClass(context, "SomeoneElse")); XStream xStream = new XStream2(); xStream.registerConverter(new TriggerContextConverter()); String xml = xStream.toXML(t); TestMarshalClass readT = (TestMarshalClass) xStream.fromXML(xml); assertNotNull(readT.getEntity()); assertNotNull(readT.getEntity().getEvent()); assertNotNull(readT.getEntity().getThisBuild()); assertEquals("project", readT.getEntity().getEvent().getChange().getProject()); assertEquals(100, readT.getEntity().getThisBuild().getBuildNumber().intValue()); assertEquals("projectX", readT.getEntity().getThisBuild().getProjectId()); assertSame(readT.getEntity(), readT.getTestClass().getEntity()); }
/** * Tests {@link * TriggerContextConverter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext)}. With "retriggerAction_oldData2.xml" * as input. * * @throws Exception if so. */ @Test public void testUnmarshalOldData2() throws Exception { XStream xStream = new XStream2(); xStream.registerConverter(new TriggerContextConverter()); Object obj = xStream.fromXML(getClass().getResourceAsStream("retriggerAction_oldData2.xml")); assertTrue(obj instanceof RetriggerAction); RetriggerAction action = (RetriggerAction) obj; TriggerContext context = Whitebox.getInternalState(action, "context"); assertNotNull(context.getEvent()); assertEquals( "semctools/hudson/plugins/gerrit-trigger-plugin", context.getEvent().getChange().getProject()); assertEquals("1", context.getEvent().getPatchSet().getNumber()); assertNotNull(context.getThisBuild()); assertEquals(6, context.getThisBuild().getBuildNumber().intValue()); assertEquals("EXPERIMENTAL_Gerrit_Trigger_1", context.getThisBuild().getProjectId()); assertNotNull(context.getOthers()); assertEquals(2, context.getOthers().size()); TriggeredItemEntity entity = context.getOthers().get(0); assertEquals(16, entity.getBuildNumber().intValue()); assertEquals("EXPERIMENTAL_Gerrit_Trigger_2", entity.getProjectId()); entity = context.getOthers().get(1); assertEquals(15, entity.getBuildNumber().intValue()); assertEquals("EXPERIMENTAL_Gerrit_Trigger_3", entity.getProjectId()); }
@Override public Set<Currency> getCurrencies() throws AmountMoneyCurrencyStorageException { if (!file.exists()) { LOGGER.info( String.format( "Currency storage file '%s' doesn't exist, creating it " + "with default currencies", file)); if (!file.getParentFile().exists()) { if (!file.getParentFile().mkdirs()) { throw new AmountMoneyCurrencyStorageException( String.format( "Currency " + "storage file's parent directory '%s' couldn't " + "be created", file.getParentFile())); } } saveCurrencies(AmountMoneyComponent.DEFAULT_CURRENCIES); } try { InputStream inputStream = new FileInputStream(file); XStream xStream = new XStream(); xStream.registerConverter(CURRENCY_CONVERTER); Set<Currency> currencies = (Set<Currency>) xStream.fromXML(inputStream); if (currencies.isEmpty()) { LOGGER.info( String.format( "Currency storage file '%s' contains " + "0 currency, using default currencies", file)); saveCurrencies(AmountMoneyComponent.DEFAULT_CURRENCIES); return AmountMoneyComponent.DEFAULT_CURRENCIES; } return currencies; } catch (IOException ex) { throw new AmountMoneyCurrencyStorageException(ex); } }
/** * Loads the settings from the given directories (Windows: "APPDATA", Unix: ".user.home") The * settings loaded from the .xml format and has the name "fmsettings". If there is no "fmsettings" * file a new one with the following default values will be created fontsize: 12, max loop count: * 3, Z3 timeout: 20000 and a empty Z3 Path and Default Path */ private Settings loadSettings() { Settings tempSettings = null; XStream xstream = new XStream(); String settingsPath; // Windows settingsPath = System.getenv("APPDATA"); // Unix if (settingsPath == null) { settingsPath = System.getProperty("user.home"); } File file = new File(settingsPath + File.separatorChar + ".fmsettings"); if (file.isFile()) { // load from settings from "fmsettings" file try { tempSettings = (Settings) xstream.fromXML(file); } catch (CannotResolveClassException e) { tempSettings = defaultSettings(); } catch (StreamException e) { tempSettings = defaultSettings(); } } else { tempSettings = defaultSettings(); } return tempSettings; }
// TODO Carregar campos a partir do XML de um .ktr @SuppressWarnings("unchecked") @Override public void loadXML( Node stepDomNode, List<DatabaseMeta> databases, Map<String, Counter> sequenceCounters) throws KettleXMLException { try { XStream xs = new XStream(new DomDriver()); StringWriter sw = new StringWriter(); Transformer t = TransformerFactory.newInstance().newTransformer(); // IPC: se algum colocar um caracter, seja qual for, no getXML() o // getFirstChild() para de funcionar aqui! t.transform( new DOMSource( XMLHandler.getSubNode(stepDomNode, Field.DATA_ROOT_NODE.name()).getFirstChild()), new StreamResult(sw)); Map<String, Object> data = (Map<String, Object>) xs.fromXML(sw.toString()); endpointUri = (String) data.get(Field.ENDPOINT_URI.name()); defaultGraph = (String) data.get(Field.DEFAULT_GRAPH.name()); queryString = (String) data.get(Field.QUERY_STRING.name()); prefixes = (List<List<String>>) data.get(Field.PREFIXES.name()); varResult = (String) data.get(Field.VAR_RESULT.name()); } catch (Throwable e) { e.printStackTrace(); } }
public List<SequenciaDidatica> listaDeSequenciaDidatica(String filtro) { XStream x = new XStream(new DomDriver()); int indice = Integer.parseInt(IGEDProperties.getInstance().getPropety("indicesSequencia")); String path = IGEDProperties.getInstance().getPropety("sequenciaPath"); sequenciasDidatica = new ArrayList<SequenciaDidatica>(); if (filtro.equals("") || filtro == null) { try { for (int i = 1; i < indice; i++) { FileInputStream input = new FileInputStream(path + "/sequencia-" + i + ".xml"); x.alias("sequenciaDidatica", SequenciaDidatica.class); SequenciaDidatica sequencia = (SequenciaDidatica) x.fromXML(input); sequenciasDidatica.add(sequencia); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } return sequenciasDidatica; }
private void readMigrations( SortedMap<Long, List<ConfigMigrationStategy>> configMigrations, URL url) throws IOException { InputStreamReader r = null; try { r = new InputStreamReader(url.openStream(), ConfigUtilConstants.DEFAULT_TEXT_ENCODING); XStream x = createXStream(); ConfigManagerMigrations migrations = (ConfigManagerMigrations) x.fromXML(r); for (Migration m : migrations.getMigrationList()) { long versionTarget = m.getTargetVersion(); String className = m.getMigrationClass(); String[] constructorArguments = m.getArguments(); List<ConfigMigrationStategy> configMigrationForVersionTarget = configMigrations.get(versionTarget); if (configMigrationForVersionTarget == null) { configMigrationForVersionTarget = new ArrayList(); configMigrations.put(versionTarget, configMigrationForVersionTarget); } ConfigMigrationStategy configMigration = createMigrationStrategy(versionTarget, className, constructorArguments); configMigrationForVersionTarget.add(configMigration); } } finally { try { if (r != null) r.close(); } catch (IOException e) { ConfigLogImplementation.logMethods.error( "Failed to close ConfigMigration InputStream from URL " + url, e); } } }
@Test public void testNotNullValue() { Value value = TextType.get().valueOf("The Value"); String xml = xstream.toXML(value); Value unmarshalled = (Value) xstream.fromXML(xml); assertThat(value).isEqualTo(unmarshalled); }
public Configuration getConfiguration(File configFile) throws IOException { if (!configFile.exists()) { configFile.getParentFile().mkdirs(); save(configFile, new Configuration()); } return (Configuration) xstream.fromXML(new FileInputStream(configFile)); }
@Override protected SalesforceException createRestException(ContentExchange httpExchange) { // try parsing response according to format try { if ("json".equals(format)) { List<RestError> restErrors = objectMapper.readValue( httpExchange.getResponseContent(), new TypeReference<List<RestError>>() {}); return new SalesforceException(restErrors, httpExchange.getResponseStatus()); } else { RestErrors errors = new RestErrors(); xStream.fromXML(httpExchange.getResponseContent(), errors); return new SalesforceException(errors.getErrors(), httpExchange.getResponseStatus()); } } catch (IOException e) { // log and ignore String msg = "Unexpected Error parsing " + format + " error response: " + e.getMessage(); LOG.warn(msg, e); } catch (RuntimeException e) { // log and ignore String msg = "Unexpected Error parsing " + format + " error response: " + e.getMessage(); LOG.warn(msg, e); } // just report HTTP status info return new SalesforceException("Unexpected error", httpExchange.getResponseStatus()); }
@Test public void testXMLTest1Len() { Test1 test1 = new Test1(); Test2 test2 = new Test2(); Test3 test3 = new Test3(); test2.setTest1(test1); test1.setTest2(test2); test1.setTest3(test3); test3.setTest2(test2); try { String bigcontent = FileUtil.getFileContent( new File( "F:\\workspace\\bbossgroups-3.5\\bboss-core\\test\\org\\frameworkset\\soa\\testxstream.xml"), "UTF-8"); // 预热bboss和xstream test1.setXmlvalue(bigcontent); String xml = ObjectSerializable.toXML(test1); System.out.println("bboss:" + xml.getBytes().length); Test1 test1_ = (Test1) ObjectSerializable.toBean(xml, Test1.class); String xmlXstream = xStream.toXML(test1); Test1 p = (Test1) xStream.fromXML(xmlXstream); System.out.println("xmlXstream:" + xmlXstream.getBytes().length); // 测试用例结束 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * reads the configuration file and returns a <code>FilterPipeInfo</code> object. * * @throws Exception if anything goes wrong while reading the configuration file. */ public static FilterPipeInfo read(String fName, Map servers) throws Exception { Reader r = new FileReader(fName); FilterPipeInfo pipe = (FilterPipeInfo) (xs.fromXML(r)); pipe.name = getName(fName); int l = pipe.dfas.size(); pipe.request = new PipelineRequest[l]; for (int i = 0; i < l; i++) { // System.out.println("looking up `"+ pipe.dfas.get(i)+"'"); FilterSvrInfo svr = (FilterSvrInfo) servers.get(pipe.dfas.get(i)); if (svr == null) { pipe.e = new IOException("no information for server `" + pipe.dfas.get(i) + "' available"); return pipe; } if (svr.e != null) { Exception e = new IOException( "referenced server configuration for server `" + svr.name + "' is broken"); e.initCause(svr.e); pipe.e = e; return pipe; } pipe.request[i] = svr.getRequest(); } return pipe; }
/* * (non-Javadoc) * * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { FileReader fr = null; try { DigitalCircuit cir; fr = new FileReader("temp-cir.xml"); cir = (DigitalCircuit) st.fromXML(fr); DigitalWindow win = new DigitalWindow(); // create a new window DrawingPad pad = win.getDrawingPad(); pad.setCircuit(cir); MDIWindow.addWindow(win); win.show(); fr.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } catch (Exception e1) { try { fr.close(); } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } }
@Test public void testNullHTMLEscapedField() { LdapUserAndGroupConfigTestRequest resource = new LdapUserAndGroupConfigTestRequest(); LdapUserAndGroupConfigTestRequestDTO dto = new LdapUserAndGroupConfigTestRequestDTO(); resource.setData(dto); dto.setLdapFilter(null); // already null, but more clear for the test String xml = this.xstreamXML.toXML(resource); LdapUserAndGroupConfigTestRequestDTO result = ((LdapUserAndGroupConfigTestRequest) this.xstreamXML.fromXML(xml)).getData(); Assert.assertNull(result.getLdapFilter()); // simple json string with an explicit null value (generated from the Nexus UI) String payload = "{\"data\":{\"ldapFilter\":null}}"; StringBuffer sb = new StringBuffer("{ \"") .append(LdapUserAndGroupConfigTestRequest.class.getName()) .append("\" : ") .append(payload) .append(" }"); // validate this parses without error xstreamJSON.fromXML(sb.toString()); }
private void test(HierarchicalStreamDriver driver) { XStream xstream = new XStream(driver); xstream.registerConverter( new CollectionConverter(xstream.getMapper()) { public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { ExtendedHierarchicalStreamReader exReader = (ExtendedHierarchicalStreamReader) reader; if (exReader.peekNextChild() == null) { return new ArrayList(); } return super.unmarshal(reader, context); } }); SampleLists in = new SampleLists(); in.good.add("one"); in.good.add("two"); in.good.add("three"); in.bad.add(Boolean.TRUE); in.bad.add(Boolean.FALSE); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); xstream.toXML(in, buffer); Object out = xstream.fromXML(new ByteArrayInputStream(buffer.toByteArray())); Assert.assertEquals(in, out); }
public FTPConfig load() { InputStream in = null; try { File configFile = findConfigFile(); if (!configFile.exists()) { FTPConfig ftpConfig = new FTPConfig(); save(ftpConfig); return ftpConfig; } in = new FileInputStream(configFile); XStream xs = getPersister(); FTPConfig config = (FTPConfig) xs.fromXML(in); return config; } catch (IOException e) { throw new RuntimeException(e); } finally { if (in != null) { try { in.close(); } catch (IOException ignore) { // ignore } } } }
public boolean manualDataInsertion(String Xstream4Rest) { logger.debug("Received Stream Element at the push wrapper."); try { StreamElement4Rest se = (StreamElement4Rest) XSTREAM.fromXML(Xstream4Rest); StreamElement streamElement = se.toStreamElement(); // If the stream element is out of order, we accept the stream element and wait for the next // (update the last received time and return true) if (isOutOfOrder(streamElement)) { lastReceivedTimestamp = streamElement.getTimeStamp(); return true; } // Otherwise, we first try to insert the stream element. // If the stream element was inserted succesfully, we wait for the next, // otherwise, we return false. boolean status = postStreamElement(streamElement); if (status) lastReceivedTimestamp = streamElement.getTimeStamp(); return status; } catch (SQLException e) { logger.warn(e.getMessage(), e); return false; } catch (XStreamException e) { logger.warn(e.getMessage(), e); return false; } }
private static boolean createInstanceFromFile() { XStream xstream = new XStream(); File propertiesFile = new File( System.getProperty("user.home") + File.separator + PROPERTIES_DIR + File.separator + "properties.xml"); if (!propertiesFile.exists()) { System.out.println("Could not find Property File"); // There is no properties file. return false; } try { FileReader reader = new FileReader(propertiesFile); instance = (GlobalProperties) xstream.fromXML(reader); reader.close(); } catch (Exception e) { System.err.println( "Not possible to read properties file, because of the following reason:" + e.getMessage()); return false; } instance.initializeNotSerializeFeelds(); return true; }