⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlrepository.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    }                    for (int i = 0; i < tab.getObjects().size(); i++)                    {                        ChartObject object = (ChartObject)tab.getObjects().get(i);                        object.setId(new Integer(i));                        object.setParent(tab);                        object.setRepository(this);                    }                }            }                        chartsMap.put(obj.getId(), obj);        }        else if (obj instanceof Watchlist)        {            if (obj.getId() == null)            {                obj.setId(watchlistsNextId);                watchlistsNextId = getNextId(watchlistsNextId);            }            watchlistsMap.put(obj.getId(), obj);        }        else if (obj instanceof Account)        {            if (obj.getId() == null)            {                obj.setId(accountNextId);                accountNextId = getNextId(accountNextId);            }            accountMap.put(obj.getId(), obj);        }        else if (obj instanceof AccountGroup)        {            if (obj.getId() == null)            {                obj.setId(accountGroupNextId);                accountGroupNextId = getNextId(accountGroupNextId);            }            accountGroupMap.put(obj.getId(), obj);        }        else if (obj instanceof TradingSystem)            tradingRepository.save((TradingSystem) obj);        else if (obj instanceof TradingSystemGroup)            tradingRepository.save((TradingSystemGroup) obj);        else if (obj instanceof Order)        {            if (obj.getId() == null)            {                obj.setId(orderNextId);                orderNextId = getNextId(orderNextId);            }        }                super.save(obj);    }    /* (non-Javadoc)     * @see net.sourceforge.eclipsetrader.core.Repository#delete(net.sourceforge.eclipsetrader.core.db.PersistentObject)     */    public void delete(PersistentObject obj)    {        super.delete(obj);        if (obj instanceof Security)        {            securitiesMap.remove(obj.getId());            historyMap.remove(obj.getId());            intradayHistoryMap.remove(obj.getId());            File file = new File(Platform.getLocation().toFile(), "charts/" + String.valueOf(obj.getId()) + ".xml"); //$NON-NLS-1$  $NON-NLS-2$            if (file.exists())                file.delete();            file = new File(Platform.getLocation().toFile(), "history/" + String.valueOf(obj.getId()) + ".xml"); //$NON-NLS-1$  $NON-NLS-2$            if (file.exists())                file.delete();            file = new File(Platform.getLocation().toFile(), "intraday/" + String.valueOf(obj.getId()) + ".xml"); //$NON-NLS-1$  $NON-NLS-2$            if (file.exists())                file.delete();        }        else if (obj instanceof History)        {            if (obj instanceof IntradayHistory)            {                intradayHistoryMap.remove(obj.getId());                File file = new File(Platform.getLocation().toFile(), "intraday/" + String.valueOf(obj.getId()) + ".xml"); //$NON-NLS-1$  $NON-NLS-2$                if (file.exists())                    file.delete();            }            else            {                historyMap.remove(obj.getId());                File file = new File(Platform.getLocation().toFile(), "history/" + String.valueOf(obj.getId()) + ".xml"); //$NON-NLS-1$  $NON-NLS-2$                if (file.exists())                    file.delete();            }        }        else if (obj instanceof Watchlist)            watchlistsMap.remove(obj.getId());        else if (obj instanceof Chart)            chartsMap.remove(obj.getId());        else if (obj instanceof Account)            accountMap.remove(obj.getId());        else if (obj instanceof AccountGroup)            accountGroupMap.remove(obj.getId());        else if (obj instanceof TradingSystem)        {            TradingSystem system = (TradingSystem) obj;            if (system.getGroup() != null)                system.getGroup().getTradingSystems().remove(obj);            getTradingSystems().remove(obj);            tradingRepository.tsMap.remove(obj.getId());        }        else if (obj instanceof TradingSystemGroup)        {            TradingSystemGroup group = (TradingSystemGroup) obj;            if (group.getParent() != null)                group.getParent().getGroups().remove(obj);            getTradingSystemGroups().remove(obj);                        Object[] members = group.getTradingSystems().toArray();            for (int i = 0; i < members.length; i++)                delete((PersistentObject) members[i]);                        members = group.getGroups().toArray();            for (int i = 0; i < members.length; i++)                delete((PersistentObject) members[i]);            tradingRepository.tsGroupMap.remove(obj.getId());        }    }    private Integer getNextId(Integer id)    {        return new Integer(id.intValue() + 1);    }        private History loadHistory(Integer id)    {        History barData = new History(id);                File file = new File(Platform.getLocation().toFile(), "history/" + String.valueOf(id) + ".xml"); //$NON-NLS-1$  $NON-NLS-2$        if (file.exists() == true)        {            try            {                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();                DocumentBuilder builder = factory.newDocumentBuilder();                builder.setErrorHandler(errorHandler);                Document document = builder.parse(file);                barData.addAll(decodeBarData(document.getFirstChild().getChildNodes()));            } catch (Exception e) {                log.error(e.toString(), e);            }        }                barData.clearChanged();                return barData;    }        public IntradayHistory loadIntradayHistory(Integer id)    {        IntradayHistory barData = new IntradayHistory(id);                File file = new File(Platform.getLocation().toFile(), "intraday/" + String.valueOf(id) + ".xml");        if (file.exists() == true)        {            try            {                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();                DocumentBuilder builder = factory.newDocumentBuilder();                builder.setErrorHandler(errorHandler);                Document document = builder.parse(file);                barData.addAll(decodeBarData(document.getFirstChild().getChildNodes()));            } catch (Exception e) {                log.error(e.toString(), e);            }        }                barData.clearChanged();                return barData;    }        private List decodeBarData(NodeList node)    {        Integer id = new Integer(0);        List barData = new ArrayList();                for (int i = 0; i < node.getLength(); i++)        {            Node dataNode = node.item(i);            if (dataNode.getNodeName().equalsIgnoreCase("data")) //$NON-NLS-1$            {                id = new Integer(id.intValue() + 1);                Bar bar = new Bar(id);                NodeList valuesNode = dataNode.getChildNodes();                for (int ii = 0; ii < valuesNode.getLength(); ii++)                {                    Node item = valuesNode.item(ii);                    Node value = item.getFirstChild();                    if (value != null)                    {                        String nodeName = item.getNodeName();                        if (nodeName.equalsIgnoreCase("open") == true)                            bar.setOpen(Double.parseDouble(value.getNodeValue()));                        else if (nodeName.equalsIgnoreCase("high") == true)                            bar.setHigh(Double.parseDouble(value.getNodeValue()));                        else if (nodeName.equalsIgnoreCase("low") == true)                            bar.setLow(Double.parseDouble(value.getNodeValue()));                        else if (nodeName.equalsIgnoreCase("close") == true)                            bar.setClose(Double.parseDouble(value.getNodeValue()));                        else if (nodeName.equalsIgnoreCase("volume") == true)                            bar.setVolume(Long.parseLong(value.getNodeValue()));                        else if (nodeName.equalsIgnoreCase("date") == true)                        {                            try {                                bar.setDate(dateTimeFormat.parse(value.getNodeValue()));                            } catch (Exception e) {                                log.warn(e.toString());                            }                        }                    }                }                barData.add(bar);            }        }                return barData;    }        private void saveHistory(History list)    {        try {            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();            builder.setErrorHandler(errorHandler);            Document document = builder.getDOMImplementation().createDocument(null, "history", null);            Element root = document.getDocumentElement();            encodeBarData(list.getList(), root, document);            if (list instanceof IntradayHistory)                saveDocument(document, "intraday", String.valueOf(list.getId()) + ".xml");            else                saveDocument(document, "history", String.valueOf(list.getId()) + ".xml");        } catch (Exception e) {            log.error(e.toString(), e);        }    }        private void encodeBarData(List list, Element root, Document document)    {        for (Iterator iter = list.iterator(); iter.hasNext(); )        {            Bar bar = (Bar)iter.next();             Element element = document.createElement("data");            root.appendChild(element);                        Element node = document.createElement("open");            node.appendChild(document.createTextNode(String.valueOf(bar.getOpen())));            element.appendChild(node);            node = document.createElement("high");            node.appendChild(document.createTextNode(String.valueOf(bar.getHigh())));            element.appendChild(node);            node = document.createElement("low");            node.appendChild(document.createTextNode(String.valueOf(bar.getLow())));            element.appendChild(node);            node = document.createElement("close");            node.appendChild(document.createTextNode(String.valueOf(bar.getClose())));            element.appendChild(node);            node = document.createElement("volume");            node.appendChild(document.createTextNode(String.valueOf(bar.getVolume())));            element.appendChild(node);            if (bar.getDate() != null)            {                node = document.createElement("date");                node.appendChild(document.createTextNode(dateTimeFormat.format(bar.getDate())));                element.appendChild(node);            }        }    }        private void saveCharts()    {        try {            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();            builder.setErrorHandler(errorHandler);            Document document = builder.getDOMImplementation().createDocument(null, "data", null);            Element root = document.getDocumentElement();            root.setAttribute("nextId", String.valueOf(chartsNextId));                        for (Iterator iter = chartsMap.values().iterator(); iter.hasNext(); )            {                Chart chart = (Chart)iter.next();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -