Source Code Cross Referenced for JRXMLADataSourceConnection.java in  » Report » iReport-2.0.5 » it » businesslogic » ireport » connection » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » iReport 2.0.5 » it.businesslogic.ireport.connection 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**   
002:         * Copyright (C) 2005, 2006 CINCOM SYSTEMS, INC.
003:         * All Rights Reserved
004:         * www.cincom.com
005:         *
006:         * JRXMLADataSourceConnection.java
007:         * @authors MPenningroth, HMays.
008:         */package it.businesslogic.ireport.connection;
009:
010:        import it.businesslogic.ireport.IReportConnectionEditor;
011:        import it.businesslogic.ireport.connection.gui.XMLADataSourceConnectionEditor;
012:        import it.businesslogic.ireport.data.olap.CustomHTTPAuthenticator;
013:        import it.businesslogic.ireport.gui.MainFrame;
014:        import it.businesslogic.ireport.util.*;
015:        import it.businesslogic.ireport.util.Misc;
016:        import java.net.Authenticator;
017:        import java.util.Map;
018:        import javax.swing.JOptionPane;
019:        import net.sf.jasperreports.engine.query.JRXmlaQueryExecuterFactory;
020:
021:        public class JRXMLADataSourceConnection extends
022:                it.businesslogic.ireport.IReportConnection {
023:
024:            private String url;
025:
026:            private String username;
027:
028:            private String password = null;
029:
030:            private boolean savePassword;
031:
032:            /** Creates a new instance of JRXMLADataSourceConnection */
033:            public JRXMLADataSourceConnection() {
034:
035:            }
036:
037:            /**
038:             * Returns the url of XMLA Server.
039:             * @return Value of property url.
040:             */
041:            public String getUrl() {
042:                return this .url;
043:            }
044:
045:            /**
046:             * Setter method for url.
047:             * @param <code>String</code> assigns value of the  <code>url </code>
048:             */
049:            public void setUrl(String url) {
050:                this .url = url;
051:            }
052:
053:            public java.util.HashMap getProperties() {
054:                java.util.HashMap map = new java.util.HashMap();
055:                map.put("url", Misc.nvl(this .getUrl(), ""));
056:                map.put("datasource", Misc.nvl(this .getDatasource(), ""));
057:                map.put("catalog", Misc.nvl(this .getCatalog(), ""));
058:                map.put("cube", Misc.nvl(this .getCube(), ""));
059:                map.put("Username", Misc.nvl(this .getUsername(), ""));
060:                if (this .isSavePassword())
061:                    map.put("Password", Misc.nvl(this .getPassword(), ""));
062:                else
063:                    map.put("Password", "");
064:                map.put("SavePassword", "" + this .isSavePassword());
065:
066:                return map;
067:            }
068:
069:            /**
070:             * Assigns the values of Url, Datasource, Catalog, Cube
071:             */
072:            public void loadProperties(java.util.HashMap map) {
073:                this .setUrl((String) map.get("url"));
074:                this .setDatasource((String) map.get("datasource"));
075:                this .setCatalog((String) map.get("catalog"));
076:                this .setCube((String) map.get("cube"));
077:
078:                this .setUsername((String) map.get("Username"));
079:                this .setSavePassword(("" + map.get("SavePassword"))
080:                        .equals("true"));
081:                if (this .isSavePassword())
082:                    this 
083:                            .setPassword(Misc.nvl((String) map.get("Password"),
084:                                    ""));
085:            }
086:
087:            /**
088:             * Holds value of property datasource.
089:             */
090:            private String datasource;
091:
092:            /**
093:             * Getter for property datasource.
094:             * @return Value of property datasource.
095:             */
096:            public String getDatasource() {
097:                return this .datasource;
098:            }
099:
100:            /**
101:             * Setter for property datasource.
102:             * @param datasource New value of property datasource.
103:             */
104:            public void setDatasource(String datasource) {
105:                this .datasource = datasource;
106:            }
107:
108:            /**
109:             * Holds value of property catalog.
110:             */
111:            private String catalog;
112:
113:            /**
114:             * Getter for property catalog.
115:             * @return Value of property catalog.
116:             */
117:            public String getCatalog() {
118:                return this .catalog;
119:            }
120:
121:            /**
122:             * Setter for property catalog.
123:             * @param catalog New value of property catalog.
124:             */
125:            public void setCatalog(String catalog) {
126:                this .catalog = catalog;
127:            }
128:
129:            /**
130:             * Holds value of property cube.
131:             */
132:            private String cube;
133:
134:            /**
135:             * Getter for property cube.
136:             * @return Value of property cube.
137:             */
138:            public String getCube() {
139:                return this .cube;
140:            }
141:
142:            /**
143:             * Setter for property cube.
144:             * @param cube New value of property cube.
145:             */
146:            public void setCube(String cube) {
147:                this .cube = cube;
148:            }
149:
150:            /*
151:             * Return true if this ireport connection can be used using getJRDataSource
152:             * I.E. you can see JDBCConnection
153:             */
154:            public boolean isJRDataSource() {
155:                return false;
156:            }
157:
158:            /**
159:             * This method is call before the datasource is used and permit to add special parameters to the map
160:             *
161:             */
162:            public Map getSpecialParameters(Map map)
163:                    throws net.sf.jasperreports.engine.JRException {
164:                //System.out.println("Starting XMLA MDX Query");
165:
166:                map.put(JRXmlaQueryExecuterFactory.PARAM_XMLA_URL, getUrl());
167:                map.put(JRXmlaQueryExecuterFactory.PARAM_XMLA_DS,
168:                        getDatasource());
169:                map
170:                        .put(JRXmlaQueryExecuterFactory.PARAM_XMLA_CAT,
171:                                getCatalog());
172:
173:                map
174:                        .put(
175:                                net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuterFactory.PARAMETER_XMLA_URL,
176:                                getUrl());
177:                map
178:                        .put(
179:                                net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuterFactory.PARAMETER_XMLA_DATASOURCE,
180:                                getDatasource());
181:                map
182:                        .put(
183:                                net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuterFactory.PARAMETER_XMLA_CATALOG,
184:                                getCatalog());
185:
186:                if (username != null && username.length() > 0) {
187:                    String tmpPassword = getPassword();
188:                    Authenticator.setDefault(new CustomHTTPAuthenticator(
189:                            username, tmpPassword));
190:                    map
191:                            .put(
192:                                    net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuterFactory.PARAMETER_XMLA_USER,
193:                                    getUsername());
194:                    map
195:                            .put(
196:                                    net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuterFactory.PARAMETER_XMLA_PASSWORD,
197:                                    tmpPassword);
198:                }
199:
200:                //System.out.println("XMLA MDX Query completed");
201:
202:                return map;
203:            }
204:
205:            /**
206:             * This method is call after the datasource is used to dispose special parameters
207:             * (i.e. closing an Hibernate session create as parameter with a getSpecialParameters...
208:             *
209:             */
210:            public Map disposeSpecialParameters(Map map) {
211:                return map;
212:            }
213:
214:            public String getUsername() {
215:                return username;
216:            }
217:
218:            public void setUsername(String username) {
219:                this .username = username;
220:            }
221:
222:            public String getPassword() {
223:                if (isSavePassword())
224:                    return password;
225:                else {
226:                    // Ask for password...
227:                    try {
228:                        return it.businesslogic.ireport.gui.PasswordDialog
229:                                .askPassword();
230:                    } catch (Exception ex) {
231:                        ex.printStackTrace();
232:                    }
233:                }
234:                return "";
235:            }
236:
237:            public void setPassword(String password) {
238:                this .password = password;
239:            }
240:
241:            public boolean isSavePassword() {
242:                return savePassword;
243:            }
244:
245:            public void setSavePassword(boolean savePassword) {
246:                this .savePassword = savePassword;
247:            }
248:
249:            public String getDescription() {
250:                return I18n.getString("connectionType.xmlaServer",
251:                        "XMLA Server");
252:            }
253:
254:            public IReportConnectionEditor getIReportConnectionEditor() {
255:                return new XMLADataSourceConnectionEditor();
256:            }
257:
258:            public void test() throws Exception {
259:                /**   
260:                 * Copyright (C) 2005, 2006 CINCOM SYSTEMS, INC.
261:                 * All Rights Reserved
262:                 * www.cincom.com
263:                 *
264:                 */
265:                String urlstr = this .getUrl();
266:                Authenticator.setDefault(new CustomHTTPAuthenticator(
267:                        getUsername(), getPassword()));
268:
269:                String dataSource = this .getDatasource();
270:                String catalog = this .getCatalog();
271:                rex.metadata.ServerMetadata smd = new rex.metadata.ServerMetadata(
272:                        urlstr, MainFrame.getMainInstance());
273:                if (smd.isValidUrl() == false) {
274:                    JOptionPane
275:                            .showMessageDialog(
276:                                    MainFrame.getMainInstance(),
277:                                    I18n
278:                                            .getString(
279:                                                    "messages.connectionDialog.connectionXMLATestFailed.InvalidUrl",
280:                                                    "Connection test failed! Unable to connect to url."),
281:                                    "", JOptionPane.INFORMATION_MESSAGE);
282:                    return;
283:                }
284:                rex.graphics.datasourcetree.elements.DataSourceTreeElement dste[] = smd
285:                        .discoverDataSources();
286:                if (dste == null || dste.length == 0) {
287:                    JOptionPane
288:                            .showMessageDialog(
289:                                    MainFrame.getMainInstance(),
290:                                    I18n
291:                                            .getString(
292:                                                    "messages.connectionDialog.connectionXMLATestFailed.NoDatasources",
293:                                                    "Connection test failed! No datasources found."),
294:                                    "", JOptionPane.INFORMATION_MESSAGE);
295:                    return;
296:                }
297:                boolean found = false;
298:                int intI = 0;
299:                if (dataSource != null && dataSource.length() > 0) {
300:                    while (!found && intI < dste.length) {
301:                        if (dataSource
302:                                .compareTo(dste[intI].getDataSourceInfo()) == 0) {
303:                            found = true;
304:                        } else {
305:                            intI++;
306:                        }
307:                    }
308:                    if (!found) {
309:                        JOptionPane
310:                                .showMessageDialog(
311:                                        MainFrame.getMainInstance(),
312:                                        I18n
313:                                                .getFormattedString(
314:                                                        "messages.connectionDialog.connectionXMLATestFailed.NoDatasourceFound",
315:                                                        "Connection test failed! Datasource {0} not found.",
316:                                                        new Object[] { dataSource
317:                                                                + "" }), "",
318:                                        JOptionPane.INFORMATION_MESSAGE);
319:                        return;
320:                    }
321:                    if (catalog != null && catalog.length() > 0) {
322:                        found = false;
323:                        rex.graphics.datasourcetree.elements.DataSourceTreeElement cats[] = dste[intI]
324:                                .getChildren();
325:                        if (cats == null || cats.length == 0) {
326:                            JOptionPane
327:                                    .showMessageDialog(
328:                                            MainFrame.getMainInstance(),
329:                                            I18n
330:                                                    .getString(
331:                                                            "messages.connectionDialog.connectionXMLATestFailed.NoCatalogs",
332:                                                            "Connection test failed! No catalogs found in datasource."),
333:                                            "", JOptionPane.INFORMATION_MESSAGE);
334:                            return;
335:                        }
336:                        intI = 0;
337:                        while (!found && intI < cats.length) {
338:                            if (catalog
339:                                    .compareTo(((rex.graphics.datasourcetree.elements.CatalogElement) cats[intI])
340:                                            .toString()) == 0) {
341:                                found = true;
342:                            } else {
343:                                intI++;
344:                            }
345:                        }
346:                        if (!found) {
347:                            JOptionPane
348:                                    .showMessageDialog(
349:                                            MainFrame.getMainInstance(),
350:                                            I18n
351:                                                    .getFormattedString(
352:                                                            "messages.connectionDialog.connectionXMLATestFailed.NoCatalogFound",
353:                                                            "Connection test failed! Catalog {0} not found in datasource.",
354:                                                            new Object[] { catalog
355:                                                                    + "" }),
356:                                            "", JOptionPane.INFORMATION_MESSAGE);
357:                            return;
358:                        }
359:                    } else {
360:                        JOptionPane
361:                                .showMessageDialog(
362:                                        MainFrame.getMainInstance(),
363:                                        I18n
364:                                                .getString(
365:                                                        "messages.connectionDialog.connectionXMLATestSuccessful.NoCatalog",
366:                                                        "Connection test successful! Connected to server and found datasource, but no catalog specified."),
367:                                        "", JOptionPane.INFORMATION_MESSAGE);
368:                        return;
369:                    }
370:                } else {
371:                    JOptionPane
372:                            .showMessageDialog(
373:                                    MainFrame.getMainInstance(),
374:                                    I18n
375:                                            .getString(
376:                                                    "messages.connectionDialog.connectionXMLATestSuccessful.NoDatasource",
377:                                                    "Connection test successful! Connected to server, but no datasource specified."),
378:                                    "", JOptionPane.INFORMATION_MESSAGE);
379:                    return;
380:                }
381:                JOptionPane
382:                        .showMessageDialog(
383:                                MainFrame.getMainInstance(),
384:                                I18n
385:                                        .getString(
386:                                                "messages.connectionDialog.connectionXMLATestSuccessful",
387:                                                "Connection test successful! Catalog found in datasource on xmla server."),
388:                                "", JOptionPane.INFORMATION_MESSAGE);
389:                /* end of modification */
390:
391:            }
392:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.