001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ChartApplicationBeansContainer.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package org.openesb.tools.charting.persist;
030:
031: import java.util.HashMap;
032: import java.util.Iterator;
033: import java.util.List;
034: import java.util.Map;
035: import java.util.Set;
036: import java.util.TreeMap;
037: import java.util.logging.Logger;
038: import org.openesb.tools.charting.exception.ChartingException;
039:
040: /**
041: *
042: * @author rdwivedi
043: */
044: public class ChartApplicationBeansContainer {
045:
046: private TreeMap map = null;
047: ChartBean mCurrent = null;
048: private Map mDAMap = null;
049: private String dbEditorID = null;
050: ChartDataPersistence helper = new ChartDataPersistence();
051:
052: private static Logger mLogger = Logger
053: .getLogger(ChartApplicationBeansContainer.class.getName());
054:
055: public ChartApplicationBeansContainer() {
056: map = new TreeMap();
057: mDAMap = new HashMap();
058: init();
059: }
060:
061: public String getTitle() {
062: return "Charting";
063: }
064:
065: public void init() {
066: try {
067:
068: List daList = helper.getAllAvailableDataAccess();
069: if (daList != null) {
070: Iterator iter = daList.iterator();
071: while (iter.hasNext()) {
072: DataBean b = (DataBean) iter.next();
073: addADataBean(b);
074:
075: }
076: }
077:
078: List list = helper.getAllAvailableChartIDS();
079: if (list != null) {
080: Iterator iter = list.iterator();
081: while (iter.hasNext()) {
082: ChartBean b = (ChartBean) iter.next();
083: addAChartBean(b);
084:
085: }
086: }
087: } catch (Exception e) {
088: mLogger.severe("Error on init" + e.toString());
089: e.printStackTrace();
090: }
091: }
092:
093: public void addAChartBean(ChartBean bean) {
094: TreeMap o = (TreeMap) map.get(bean.getChartParentName());
095: if (o == null) {
096: o = new TreeMap();
097: map.put(bean.getChartParentName(), o);
098: }
099: o.put(bean.getChartID(), bean);
100: }
101:
102: public ChartBean getChartBeanByID(String id) {
103: ChartBean b = null;
104: Iterator iter = map.values().iterator();
105: while (iter.hasNext()) {
106: TreeMap tm = (TreeMap) iter.next();
107: if (tm.containsKey(id)) {
108: b = (ChartBean) tm.get(id);
109: }
110:
111: }
112: return b;
113: }
114:
115: public Set getAllChartGroups() {
116: return map.keySet();
117: }
118:
119: public Map getAllChartsForGroup(String gName) {
120: Map m = null;
121: if (map.containsKey(gName)) {
122: m = (TreeMap) map.get(gName);
123: }
124: return m;
125: }
126:
127: public ChartBean createNewChart(String name, String pName) {
128: ChartBean b = new ChartBean();
129: b.setChartName(name);
130: b.setChartParentName(pName);
131: b.createNewChartID();
132: this .addAChartBean(b);
133: return b;
134: }
135:
136: public ChartBean getCurrentChartBeanOnEditor() {
137: return mCurrent;
138: }
139:
140: public void setCurrentChartBeanOnEditor(ChartBean n) {
141: mCurrent = n;
142: }
143:
144: public void addADataBean(DataBean bean) {
145: mDAMap.put(bean.getID(), bean);
146: }
147:
148: public DataBean createNewDataBean(String name, String pName) {
149: DataBean b = new DataBean(name, pName);
150: b.createNewID();
151: mDAMap.put(b.getID(), b);
152: mLogger.info("Adding new DBBean" + b.getID() + "Name " + name
153: + "parent name" + pName);
154: return b;
155: }
156:
157: public Map getAllDataBeans() {
158: return mDAMap;
159: }
160:
161: public DataBean getDataBeanByID(String id) {
162:
163: return (DataBean) mDAMap.get(id);
164: }
165:
166: public void setCurrentDBABeanOnEditorID(String id) {
167: mLogger.info("Setting id = " + id + " prv id was ="
168: + dbEditorID);
169: dbEditorID = id;
170:
171: }
172:
173: public String getCurrentDBABeanOnEditorID() {
174: return dbEditorID;
175: }
176:
177: public void persistDataBean(String id) throws ChartingException {
178: mLogger.info("Saving DB " + id + "Current bean is "
179: + dbEditorID);
180: if (dbEditorID.equals(id)) {
181: DataBean bean = getDataBeanByID(id);
182: helper.upsertGroup(bean.getGroupID(), bean
183: .getParentDisplayName());
184: helper.persistDataAccessBean(bean);
185: }
186: }
187:
188: public void persistCurrentChartOnEditor() throws ChartingException {
189: helper.upsertGroup(mCurrent.getParentID(), mCurrent
190: .getChartParentName());
191: helper.persistChartBean(mCurrent);
192: }
193:
194: public DataBean getDataAccessBeanForCurrentChart() {
195: String dbID = mCurrent.getChartDataBeanID();
196: return this.getDataBeanByID(dbID);
197: }
198:
199: }
|