KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > api > metadata > common > service > impl > hibernate > TestListWrapper


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate;
22
23 import java.io.BufferedInputStream JavaDoc;
24 import java.io.FileInputStream JavaDoc;
25 import java.io.FileNotFoundException JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.Properties JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
33 import org.springframework.beans.factory.xml.XmlBeanFactory;
34 import org.springframework.core.io.ClassPathResource;
35
36 import com.jaspersoft.jasperserver.api.metadata.common.domain.ListOfValuesItem;
37 import com.jaspersoft.jasperserver.api.metadata.common.domain.ResourceLookup;
38 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;
39 import com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent.RepoListOfValuesItem;
40 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportUnit;
41 import com.jaspersoft.jasperserver.api.metadata.view.domain.FilterCriteria;
42
43 /**
44  * Test class to an end point to connect across SOAP
45  * @author tkavanagh
46  *
47  */

48 public class TestListWrapper {
49
50     protected static final Log log = LogFactory.getLog(TestListWrapper.class);
51     
52     private Properties JavaDoc jdbcProps;
53     private RepositoryService repo;
54     private StringBuffer JavaDoc strBuff = new StringBuffer JavaDoc();
55     
56     public String JavaDoc findReportUnits(String JavaDoc arg1) {
57         
58         try {
59             setUp();
60         
61             log.warn("before findResource call: ");
62             
63             ResourceLookup[] units = repo.findResource(null, FilterCriteria.createFilter(ReportUnit.class));
64                         
65             log.warn("After findResource call: units.length=" + units.length);
66             
67             // loop through the report units and pull out naming info
68
if (units != null && units.length > 0)
69             {
70                 strBuff.append("\n\n<reportList>\n");
71                 for (int i = 0; i < units.length; i++)
72                 {
73                     ResourceLookup unit = units[i];
74                     
75                     strBuff.append("\t<report>\n");
76                     strBuff.append("\t\t<name>" + unit.getName() + "</name>\n");
77                     strBuff.append("\t\t<label>" + unit.getLabel() + "</label>\n");
78                     strBuff.append("\t\t<description>" + unit.getDescription() + "</description>\n");
79                     strBuff.append("\t</report>\n");
80                 }
81             } else {
82                 return "XYZ: units is null: ";
83             }
84              
85             strBuff.append("</reportList>\n");
86             
87             
88         } catch (Exception JavaDoc e) {
89             log.warn("Caught exception: " + e.getMessage());
90             //log.warn("Caught exception: stack trace" + e.getStackTrace());
91
System.out.println("TestListWrapper: caught exception");
92             System.out.println("exception: " + e.toString());
93             e.printStackTrace();
94         }
95         
96         return strBuff.toString();
97     }
98     
99     
100     protected void setUp() throws Exception JavaDoc {
101         loadJdbcProps();
102
103         ClassPathResource resource = new ClassPathResource("viewService.xml");
104         XmlBeanFactory factory = new XmlBeanFactory(resource);
105
106         PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
107         cfg.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE");
108         cfg.setProperties(jdbcProps);
109         cfg.postProcessBeanFactory(factory);
110
111         repo = (RepositoryService) factory.getBean("repoService");
112     }
113     
114     protected Properties JavaDoc loadJdbcProps() throws IOException JavaDoc, FileNotFoundException JavaDoc {
115         jdbcProps = new Properties JavaDoc();
116         String JavaDoc jdbcPropFile = System.getProperty("test.hibernate.jdbc.properties");
117         //BufferedInputStream is = new BufferedInputStream(new FileInputStream("C:/Docume~1/tony/.m2/jdbc.properties"));
118
BufferedInputStream JavaDoc is = new BufferedInputStream JavaDoc(new FileInputStream JavaDoc(jdbcPropFile));
119         jdbcProps.load(is);
120         is.close();
121         return jdbcProps;
122     }
123     
124 }
125
Popular Tags