📄 xmlrepository.java
字号:
{ log.info("Loading accounts"); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.parse(file); Node firstNode = document.getFirstChild(); accountNextId = new Integer(firstNode.getAttributes().getNamedItem("nextId").getNodeValue()); //$NON-NLS-1$ accountGroupNextId = new Integer(firstNode.getAttributes().getNamedItem("nextGroupId").getNodeValue()); //$NON-NLS-1$ NodeList childNodes = firstNode.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); String nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("account")) //$NON-NLS-1$ { Account obj = loadAccount(item.getChildNodes(), null); obj.setRepository(this); } else if (nodeName.equalsIgnoreCase("group")) //$NON-NLS-1$ { AccountGroup obj = loadAccountGroup(item.getChildNodes(), null); obj.setRepository(this); } } } catch (Exception e) { log.error(e.toString(), e); } } file = new File(Platform.getLocation().toFile(), "events.xml"); //$NON-NLS-1$ if (file.exists() == true) { log.info("Loading events"); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.parse(file); Node firstNode = document.getFirstChild(); NodeList childNodes = firstNode.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); String nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("event")) //$NON-NLS-1$ { Event obj = loadEvent(item.getChildNodes()); obj.setRepository(this); allEvents().add(obj); } } } catch (Exception e) { log.error(e.toString(), e); } } file = new File(Platform.getLocation().toFile(), "orders.xml"); //$NON-NLS-1$ if (file.exists() == true) { log.info("Loading orders"); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.parse(file); Node firstNode = document.getFirstChild(); orderNextId = new Integer(firstNode.getAttributes().getNamedItem("nextId").getNodeValue()); //$NON-NLS-1$ NodeList childNodes = firstNode.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); String nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("order")) //$NON-NLS-1$ { Order obj = loadOrder(item.getChildNodes()); obj.setRepository(this); allOrders().add(obj); } } } catch (Exception e) { log.error(e.toString(), e); } } eventNextId = new Integer(allEvents().size() + 1); tradingRepository = new TradingSystemRepository(this); } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.core.Repository#dispose() */ public void dispose() { saveSecurities(); saveWatchlists(); saveCharts(); saveAccounts(); saveNews(); saveEvents(); saveOrders(); tradingRepository.saveTradingSystems(); super.dispose(); } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.core.Repository#clear() */ public void clear() { File file = new File(Platform.getLocation().toFile(), "securities.xml"); //$NON-NLS-1$ if (file.exists() == true) file.delete(); file = new File(Platform.getLocation().toFile(), "watchlists.xml"); //$NON-NLS-1$ if (file.exists() == true) file.delete(); file = new File(Platform.getLocation().toFile(), "charts.xml"); //$NON-NLS-1$ if (file.exists() == true) file.delete(); file = new File(Platform.getLocation().toFile(), "news.xml"); //$NON-NLS-1$ if (file.exists() == true) file.delete(); file = new File(Platform.getLocation().toFile(), "accounts.xml"); //$NON-NLS-1$ if (file.exists() == true) file.delete(); file = new File(Platform.getLocation().toFile(), "events.xml"); //$NON-NLS-1$ if (file.exists() == true) file.delete(); file = new File(Platform.getLocation().toFile(), "orders.xml"); //$NON-NLS-1$ if (file.exists() == true) file.delete(); for (Iterator iter = allSecurities().iterator(); iter.hasNext(); ) { Security security = (Security)iter.next(); file = new File(Platform.getLocation().toFile(), "history/" + String.valueOf(security.getId()) + ".xml"); //$NON-NLS-1$ $NON-NLS-2$ if (file.exists() == true) file.delete(); file = new File(Platform.getLocation().toFile(), "intraday/" + String.valueOf(security.getId()) + ".xml"); //$NON-NLS-1$ $NON-NLS-2$ if (file.exists() == true) file.delete(); } securitiesNextId = new Integer(1); securitiesGroupNextId = new Integer(1); securitiesMap = new HashMap(); chartsNextId = new Integer(1); chartsMap = new HashMap(); watchlistsNextId = new Integer(1); watchlistsMap = new HashMap(); accountGroupNextId = new Integer(1); accountGroupMap = new HashMap(); accountNextId = new Integer(1); accountMap = new HashMap(); eventNextId = new Integer(1); orderNextId = new Integer(1); tradingRepository.clear(); historyMap = new ReferenceIdentityMap(); intradayHistoryMap = new ReferenceIdentityMap(); super.clear(); } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.core.Repository#load(java.lang.Class, java.lang.Integer) */ public PersistentObject load(Class clazz, Integer id) { PersistentObject obj = null; if (clazz.equals(Security.class)) obj = (PersistentObject)securitiesMap.get(id); else if (clazz.equals(IntradayHistory.class)) { obj = (IntradayHistory)intradayHistoryMap.get(id); if (obj == null) { obj = loadIntradayHistory(id); intradayHistoryMap.put(id, obj); } } else if (clazz.equals(History.class)) { obj = (History)historyMap.get(id); if (obj == null) { obj = loadHistory(id); historyMap.put(id, obj); } } else if (clazz.equals(Chart.class)) obj = (PersistentObject)chartsMap.get(id); else if (clazz.equals(Watchlist.class)) obj = (PersistentObject)watchlistsMap.get(id); else if (clazz.equals(Account.class)) obj = (PersistentObject)accountMap.get(id); else if (clazz.equals(AccountGroup.class)) obj = (PersistentObject)accountGroupMap.get(id); else if (clazz.equals(TradingSystem.class)) obj = (PersistentObject)tradingRepository.tsMap.get(id); else if (clazz.equals(TradingSystemGroup.class)) obj = (PersistentObject)tradingRepository.tsGroupMap.get(id); if (obj == null) { if (clazz.equals(Chart.class)) { obj = loadChart(id); if (obj != null) chartsMap.put(id, obj); } } if (obj != null && !clazz.isInstance(obj)) return null; if (obj != null) obj.setRepository(this); return obj; } /* (non-Javadoc) * @see net.sourceforge.eclipsetrader.core.Repository#save(net.sourceforge.eclipsetrader.core.db.PersistentObject) */ public void save(PersistentObject obj) { if (obj instanceof Event) { if (obj.getId() == null) { obj.setId(eventNextId); eventNextId = getNextId(eventNextId); } } else if (obj instanceof Security) { if (obj.getId() == null) { obj.setId(securitiesNextId); securitiesNextId = getNextId(securitiesNextId); } securitiesMap.put(obj.getId(), obj); } else if (obj instanceof SecurityGroup) { if (obj.getId() == null) { obj.setId(securitiesGroupNextId); securitiesGroupNextId = getNextId(securitiesGroupNextId); } } else if (obj instanceof History) saveHistory((History)obj); else if (obj instanceof Chart) { if (obj.getId() == null) { obj.setId(chartsNextId); chartsNextId = getNextId(chartsNextId); } Chart chart = (Chart)obj; for (int r = 0; r < chart.getRows().size(); r++) { ChartRow row = (ChartRow)chart.getRows().get(r); row.setId(new Integer(r)); row.setParent(chart); row.setRepository(this); for (int t = 0; t < row.getTabs().size(); t++) { ChartTab tab = (ChartTab)row.getTabs().get(t); tab.setId(new Integer(t)); tab.setParent(row); tab.setRepository(this); for (int i = 0; i < tab.getIndicators().size(); i++) { ChartIndicator indicator = (ChartIndicator)tab.getIndicators().get(i); indicator.setId(new Integer(i)); indicator.setParent(tab); indicator.setRepository(this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -