Source Code Cross Referenced for ReportDefinitionRepository.java in  » Report » jmagallanes-1.0 » com » calipso » reportgenerator » reportmanager » 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 » jmagallanes 1.0 » com.calipso.reportgenerator.reportmanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.calipso.reportgenerator.reportmanager;
002:
003:        import com.calipso.reportgenerator.reportdefinitions.ReportDefinition;
004:        import com.calipso.reportgenerator.common.*;
005:        import com.calipso.reportgenerator.services.FileSystemResolver;
006:
007:        import java.io.IOException;
008:        import java.io.Serializable;
009:        import java.io.FileReader;
010:        import java.util.*;
011:        import com.calipso.reportgenerator.common.InfoException;
012:        import org.apache.commons.vfs.FileObject;
013:        import org.apache.commons.vfs.FileSystemException;
014:        import org.apache.commons.vfs.FileSystemManager;
015:        import org.exolab.castor.xml.Unmarshaller;
016:
017:        /**
018:         * Repositorio de definiciones de reportes
019:         */
020:        public class ReportDefinitionRepository extends Repository implements 
021:                Serializable {
022:            private static CacheRepository cache;
023:
024:            public static final String NAME_FINALIZATION = "--";
025:
026:            /**
027:             * Carga una definición a partir de un identificador
028:             * @param id Identificador
029:             * @return Objeto instanciado
030:             * @throws InfoException Si no pudo obtener la definición
031:             */
032:            public ReportDefinition loadFromID(String id) throws InfoException {
033:                Object object;
034:                try {
035:                    object = super .load(getFileName(id));
036:                } catch (Exception e) {
037:                    throw new InfoException(LanguageTraslator.traslate("61"), e);
038:                }
039:                if (object != null) {
040:                    return (ReportDefinition) object;
041:                } else {
042:                    return null;
043:                }
044:            }
045:
046:            /**
047:             * Devuelve el nombre real del archivo correspondiente al objeto
048:             * @param id Identificador del report definition
049:             * @return
050:             */
051:            private String getFileName(String id) throws InfoException {
052:                String fileName, returnedFileName, sourceName;
053:                returnedFileName = "";
054:                FileObject fileObject;
055:                int index;
056:
057:                try {
058:                    fileObject = getFileSystemManager().resolveFile(
059:                            getDirectoryName());
060:                } catch (FileSystemException e) {
061:                    throw new InfoException(LanguageTraslator.traslate("212")
062:                            + ":" + getDirectoryName(), e);
063:                }
064:                try {
065:                    for (int i = 0; i < fileObject.getChildren().length; i++) {
066:                        try {
067:                            fileName = fileObject.getChildren()[i].getName()
068:                                    .getBaseName();
069:                            index = id.length() + NAME_FINALIZATION.length();
070:                            if ((id.length() + NAME_FINALIZATION.length()) > fileName
071:                                    .length()) {
072:                                index = fileName.length();
073:                            }
074:                            ;
075:                            sourceName = fileName.substring(0, index)
076:                                    .toUpperCase();
077:                            if (sourceName
078:                                    .equalsIgnoreCase((id.toUpperCase() + NAME_FINALIZATION)
079:                                            .substring(0, index))) {
080:                                returnedFileName = fileName;
081:                            }
082:                        } catch (Exception e) {
083:                        }
084:                    }
085:                } catch (Exception e) {
086:                    throw new InfoException(LanguageTraslator.traslate("213")
087:                            + ":" + getDirectoryName(), e);
088:                }
089:                if (returnedFileName.equals("")) {
090:                    return id;//throw new InfoException(LanguageTraslator.traslate("62"));
091:                } else {
092:                    return returnedFileName;
093:                }
094:            }
095:
096:            /**
097:             * Graba una definición
098:             * @param reportDefinition
099:             */
100:
101:            public void save(ReportDefinition reportDefinition)
102:                    throws InfoException {
103:                try {
104:                    super .save(reportDefinition, reportDefinition.getId()
105:                            + NAME_FINALIZATION + "EE"
106:                            + reportDefinition.getEntity());
107:                } catch (IOException e) {
108:                    throw new InfoException(LanguageTraslator.traslate("63"), e);
109:                }
110:            }
111:
112:            /**
113:             * Retorna una lista de todas las definiciones de reportes registradas
114:             * @return
115:             */
116:            public Map getAllDefinitions() throws InfoException {
117:                Hashtable hashtable;
118:                hashtable = new Hashtable();
119:                String fileName;
120:                String id;
121:                FileObject fileObject;
122:                int index;
123:
124:                try {
125:                    fileObject = getFileSystemManager().resolveFile(
126:                            getDirectoryName());
127:                } catch (FileSystemException e) {
128:                    throw new InfoException(LanguageTraslator.traslate("212")
129:                            + ":" + getDirectoryName(), e);
130:                }
131:                try {
132:                    for (int i = 0; i < fileObject.getChildren().length; i++) {
133:                        fileName = fileObject.getChildren()[i].getName()
134:                                .getBaseName();
135:                        index = fileName.indexOf(NAME_FINALIZATION);
136:                        if (index < 0) {
137:                            index = fileName.length();
138:                        }
139:                        id = (fileName.substring(0, index));
140:                        DefinitionInfo definitionInfo = new DefinitionInfo();
141:                        definitionInfo.setId(id);
142:                        try {
143:                            definitionInfo
144:                                    .setDescription(new DefinitionTraslator(
145:                                            (ReportDefinition) load(fileName),
146:                                            reportGeneratorConfiguration
147:                                                    .getLocaleLanguage(),
148:                                            reportGeneratorConfiguration
149:                                                    .getCountry())
150:                                            .getDescription());
151:                        } catch (Exception e) {
152:                            if (!fileName.substring(fileName.length() - 4,
153:                                    fileName.length() - 3)
154:                                    .equalsIgnoreCase(".")) {
155:                                throw new InfoException(LanguageTraslator
156:                                        .traslate("176")
157:                                        + ":" + id, e);
158:                            } else {
159:                                break;
160:                            }
161:                        }
162:                        hashtable.put(id, definitionInfo);
163:                    }
164:                } catch (Exception e) {
165:                    throw new InfoException(LanguageTraslator.traslate("213")
166:                            + ":" + getDirectoryName(), e);
167:                }
168:                return hashtable;
169:            }
170:
171:            /**
172:             * Retorna una lista de todas las definiciones de reportes registradas para una entidad
173:             * @param entityName Nombre de la entidad
174:             * @return
175:             */
176:            public Map getAllDfefinitionForEntity(String entityName)
177:                    throws InfoException {
178:                Map map = new Hashtable();
179:                String ee = "EE";
180:                String fileName, entityFileName, reportFileName;
181:                FileObject fileObject;
182:
183:                try {
184:                    fileObject = getFileSystemManager().resolveFile(
185:                            getDirectoryName());
186:                } catch (FileSystemException e) {
187:                    throw new InfoException(LanguageTraslator.traslate("212")
188:                            + ":" + getDirectoryName(), e);
189:                }
190:                try {
191:                    for (int i = 0; i < fileObject.getChildren().length; i++) {
192:                        fileName = fileObject.getChildren()[i].getName()
193:                                .getBaseName();
194:                        entityFileName = fileName.substring(fileName
195:                                .indexOf(ee) + 2, fileName.length());
196:                        reportFileName = fileName.substring(0, fileName
197:                                .indexOf(NAME_FINALIZATION));
198:                        if (entityName.equalsIgnoreCase(entityFileName)) {
199:                            DefinitionInfo definitionInfo = new DefinitionInfo();
200:                            definitionInfo.setId(reportFileName);
201:                            try {
202:                                definitionInfo
203:                                        .setDescription(new DefinitionTraslator(
204:                                                (ReportDefinition) load(fileName),
205:                                                reportGeneratorConfiguration
206:                                                        .getLocaleLanguage(),
207:                                                reportGeneratorConfiguration
208:                                                        .getCountry())
209:                                                .getDescription());
210:                            } catch (Exception e) {
211:                                throw new InfoException(LanguageTraslator
212:                                        .traslate("176")
213:                                        + ":" + reportFileName, e);
214:                            }
215:                            map.put(reportFileName, definitionInfo);
216:                        }
217:                    }
218:                } catch (Exception e) {
219:                    throw new InfoException(LanguageTraslator.traslate("213")
220:                            + ":" + getDirectoryName(), e);
221:                }
222:                return map;
223:            }
224:
225:            /**
226:             * Devuelve el objeto cache del repositorio
227:             * @return
228:             */
229:            public CacheRepository getCache() {
230:                if (cache == null) {
231:                    cache = new CacheRepository("ReportDefinition");
232:                }
233:                return cache;
234:            }
235:
236:            public void deleteAll() throws InfoException {
237:                getCache().deleteAll();
238:                deleteAllFiles();
239:            }
240:
241:            public void delete(String id) throws InfoException {
242:                String fileName = getFileName(id);
243:                deleteFile(fileName);
244:                getCache().delete(fileName);
245:            }
246:
247:            public Class getObjectClass() {
248:                return ReportDefinition.class;
249:            }
250:
251:            /**
252:             * Inicializa el repositorio
253:             * @param directoryName
254:             * @param reportGeneratorConfiguration
255:             */
256:            public ReportDefinitionRepository(String directoryName,
257:                    ReportGeneratorConfiguration reportGeneratorConfiguration) {
258:                super (directoryName, reportGeneratorConfiguration);
259:            }
260:
261:            protected Object saveFromSourceFiles(
262:                    ReportGeneratorConfiguration reportGeneratorConfiguration,
263:                    String id) throws InfoException {
264:                ReportDefinition result = null;
265:                try {
266:                    FileSystemManager fileSystemManager = FileSystemResolver
267:                            .getFileSystemManager(getReportGeneratorConfiguration());
268:                    FileObject fileObject = fileSystemManager
269:                            .resolveFile(getReportGeneratorConfiguration()
270:                                    .getSourceReportDefinitionsPath());
271:                    String fileName = id + ".xml";
272:                    result = (ReportDefinition) Unmarshaller.unmarshal(
273:                            ReportDefinition.class, new FileReader(
274:                                    getReportGeneratorConfiguration()
275:                                            .getSourceReportDefinitionsPath()
276:                                            + "/" + fileName));
277:                    save(result);
278:                } catch (Exception e) {
279:                    throw new InfoException(LanguageTraslator.traslate("413"));
280:                }
281:                return result;
282:            }
283:
284:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.