Source Code Cross Referenced for Repository.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.common.InfoException;
004:        import java.io.*;
005:        import com.calipso.reportgenerator.common.ReportGeneratorConfiguration;
006:        import com.calipso.reportgenerator.common.LanguageTraslator;
007:        import com.calipso.reportgenerator.services.FileSystemResolver;
008:        import org.exolab.castor.xml.*;
009:        import org.apache.commons.vfs.FileSystemManager;
010:        import org.apache.commons.vfs.FileObject;
011:        import org.xml.sax.InputSource;
012:
013:        /**
014:         * Esta clase abstracta se encarga de la persistencia genérica de los datos dentro de repositorios.
015:         */
016:        public abstract class Repository {
017:
018:            private String directoryName;
019:            private FileSystemManager fileSystemaManager;
020:            public boolean serialize = false; // Indica si se serializa en el repositorio o se guarda como xml
021:
022:            public ReportGeneratorConfiguration reportGeneratorConfiguration;
023:
024:            public abstract Class getObjectClass();
025:
026:            /** Crea el repositorio asignándole un directorio destino.
027:             * 
028:             * @param directoryName Nombre del directorio destino
029:             * @param reportGeneratorConfiguration
030:             */
031:            public Repository(String directoryName,
032:                    ReportGeneratorConfiguration reportGeneratorConfiguration) {
033:                this .directoryName = directoryName;
034:                this .reportGeneratorConfiguration = reportGeneratorConfiguration;
035:            }
036:
037:            /** Retorna el nombre del directorio destino
038:             * @return directorio destino
039:             */
040:            public String getDirectoryName() {
041:                return directoryName;
042:            }
043:
044:            /** Asigna el directorio destino
045:             * @param directoryName directorio destino
046:             */
047:            public void setDirectoryName(String directoryName) {
048:                this .directoryName = directoryName;
049:            }
050:
051:            /**
052:             * Instancia un objeto del repositorio.
053:             * @param ID Nombre del archivo
054:             * @return Objeto instanciado
055:             * @throws InfoException Si no se pudo objeter el objeto
056:             */
057:            public Object getFromID(String ID) throws InfoException {
058:                try {
059:                    return load(ID);
060:                } catch (Exception e) {
061:                    throw new InfoException(LanguageTraslator.traslate("51")
062:                            + ":" + ID, e);
063:                }
064:            };
065:
066:            /**
067:             * Graba el objeto dentro del repositorio
068:             * @param object Objeto a grabar
069:             * @param name - nombre
070:             * @throws InfoException - Si el Object o el name vienen vacíos
071:             * @throws IOException - Si no pudo grabar el
072:             */
073:            protected void save(Object object, String name)
074:                    throws InfoException, IOException {
075:                OutputStream os;
076:                ObjectOutputStream oos;
077:                String fileName;
078:                fileName = directoryName + "/" + name.toUpperCase();
079:
080:                if ((object == null) || (name == "")) {
081:                    throw new InfoException(LanguageTraslator.traslate("52")
082:                            + ":" + name);
083:                } else {
084:                    try {
085:                        try {
086:                            if (serialize) {
087:                                os = getFileSystemManager().resolveFile(
088:                                        fileName).getContent()
089:                                        .getOutputStream();
090:                                oos = new ObjectOutputStream(os);
091:                                oos.writeObject(object);
092:                                os = null;
093:                                oos.flush();
094:                                oos.close();
095:                                oos.reset();
096:                                oos = null;
097:                                resetFileSystemManager();
098:                            } else {
099:                                try {
100:                                    Writer writer = new OutputStreamWriter(
101:                                            getFileSystemManager().resolveFile(
102:                                                    fileName).getContent()
103:                                                    .getOutputStream());
104:                                    Marshaller marshaller = new Marshaller(
105:                                            writer);
106:                                    marshaller.setEncoding("ISO-8859-1");
107:                                    marshaller.marshal(object);
108:                                    writer.flush();
109:                                    writer.close();
110:                                    resetFileSystemManager();
111:                                } catch (Exception e) {
112:                                    throw new InfoException(LanguageTraslator
113:                                            .traslate("195")
114:                                            + ":" + fileName, e);
115:                                }
116:                            }
117:                            getCache().addObject(name, object);
118:                        } catch (IOException e) {
119:                            throw new IOException(LanguageTraslator
120:                                    .traslate("53")
121:                                    + ":" + name + ". " + e.toString());
122:                        }
123:                    } catch (FileNotFoundException e) {
124:                        throw new FileNotFoundException(LanguageTraslator
125:                                .traslate("54")
126:                                + ":" + name);
127:                    }
128:                }
129:            }
130:
131:            private void resetFileSystemManager() {
132:                setFileSystemaManager(null);
133:                FileSystemResolver.resetFileSystemManager();
134:            }
135:
136:            /**
137:             * Carga un objeto de un repositorio
138:             * @param id Identificador de objeto
139:             * @return Objeto instanciado
140:             * @throws IOException Si no se pudo obtener el archivo
141:             * @throws ClassNotFoundException
142:             * @throws InfoException Si no se indicó el nombre
143:             */
144:            protected Object load(String id) throws IOException,
145:                    ClassNotFoundException, InfoException {
146:                InputStream is;
147:                ObjectInputStream ois;
148:                Object returnObject = null;
149:
150:                if (id.equalsIgnoreCase("")) {
151:                    throw new InfoException(LanguageTraslator.traslate("55"));
152:                } else {
153:                    if (getCache().containsObject(id)) {
154:                        return getCache().getObject(id);
155:                    } else {
156:                        try {
157:                            if (serialize) {
158:                                is = getFileSystemManager().resolveFile(
159:                                        getDirectoryName() + "/" + id)
160:                                        .getContent().getInputStream();
161:                                ois = new ObjectInputStream(is);
162:                                returnObject = ois.readObject();
163:                            } else {
164:                                InputStream inputStream = getFileSystemManager()
165:                                        .resolveFile(
166:                                                getDirectoryName() + "/" + id)
167:                                        .getContent().getInputStream();
168:                                InputSource inputSource = new InputSource(
169:                                        inputStream);
170:                                try {
171:                                    returnObject = Unmarshaller.unmarshal(
172:                                            getObjectClass(), inputSource);
173:                                } catch (XMLException e) {
174:                                    throw new InfoException(LanguageTraslator
175:                                            .traslate("194")
176:                                            + ":"
177:                                            + getDirectoryName()
178:                                            + "/"
179:                                            + id, e);
180:                                }
181:                            }
182:                        } catch (FileNotFoundException e) {
183:                            try {
184:                                if (returnObject == null) {
185:                                    returnObject = saveFromSourceFiles(
186:                                            getReportGeneratorConfiguration(),
187:                                            id);
188:                                }
189:                            } catch (Exception ee) {
190:                                throw new InfoException(LanguageTraslator
191:                                        .traslate("56")
192:                                        + ":" + id, ee);
193:                            }
194:                        }
195:                        getCache().addObject(id, returnObject);
196:                        return returnObject;
197:                    }
198:                }
199:            }
200:
201:            protected abstract Object saveFromSourceFiles(
202:                    ReportGeneratorConfiguration reportGeneratorConfiguration,
203:                    String id) throws InfoException;
204:
205:            /**
206:             * Renombra un objeto dentro del repositorio
207:             * @param sourceName Nombre origen
208:             * @param targetName Nombre destino
209:             * @return Indica si fué renombrado
210:             */
211:            protected boolean renameFile(String sourceName, String targetName) {
212:                File sourceFile, targetFile = null;
213:                try {
214:                    sourceFile = new File(getDirectoryName() + "/" + sourceName);
215:                    targetFile = new File(getDirectoryName() + "/" + targetName
216:                            + ".tmp");
217:                    sourceFile.renameTo(targetFile);
218:                } catch (Exception e) {
219:                    return false;
220:                }
221:                return true;
222:            }
223:
224:            /**
225:             * Borra un objeto del repositorio
226:             * @param fileName Nombre del objeto
227:             * @return Indica si el objeto fué borrado
228:             * @throws InfoException Si no se pudo borrar el archivo o no se indica el nombre
229:             */
230:            protected boolean deleteFile(String fileName) throws InfoException {
231:                FileObject fileObject;
232:                if (fileName.equalsIgnoreCase("")) {
233:                    throw new InfoException(LanguageTraslator.traslate("57"));
234:                } else {
235:                    try {
236:                        fileObject = getFileSystemManager().resolveFile(
237:                                new File(getDirectoryName()), fileName);
238:                        if (getCache().containsObject(fileName)) {
239:                            getCache().removeObject(fileName);
240:                        }
241:                        if (fileObject.exists()) {
242:                            fileObject.close();
243:                            fileObject.delete();
244:                        }
245:                        ;
246:                        resetFileSystemManager();
247:                        return true;
248:                    } catch (Exception e) {
249:                        throw new InfoException(LanguageTraslator
250:                                .traslate("58")
251:                                + ":" + fileName, e);
252:                    }
253:                }
254:            }
255:
256:            /**
257:             * Devuelve el objeto cache del repositorio
258:             * @return
259:             */
260:            public abstract CacheRepository getCache();
261:
262:            /**
263:             * Deveulve la configuracion del report manager
264:             * @return
265:             */
266:            public ReportGeneratorConfiguration getReportGeneratorConfiguration() {
267:                return reportGeneratorConfiguration;
268:            }
269:
270:            public FileSystemManager getFileSystemManager()
271:                    throws InfoException {
272:                if (fileSystemaManager == null) {
273:                    try {
274:                        fileSystemaManager = FileSystemResolver
275:                                .getFileSystemManager(getReportGeneratorConfiguration());
276:                    } catch (Exception e) {
277:                        throw new InfoException(LanguageTraslator
278:                                .traslate("211"), e);
279:                    }
280:                }
281:                return fileSystemaManager;
282:            }
283:
284:            public void setFileSystemaManager(
285:                    FileSystemManager fileSystemaManager) {
286:                this .fileSystemaManager = fileSystemaManager;
287:            }
288:
289:            public void deleteAllFiles() throws InfoException {
290:                FileObject fileObject;
291:                String fileName = "";
292:                try {
293:                    fileObject = getFileSystemManager().resolveFile(
294:                            getDirectoryName());
295:                    FileObject[] fileObjects = fileObject.getChildren();
296:                    for (int i = 0; i < fileObjects.length; i++) {
297:                        fileName = fileObjects[i].getName().getBaseName();
298:                        deleteFile(fileName);
299:                    }
300:                    resetFileSystemManager();
301:                } catch (Exception e) {
302:                    throw new InfoException(LanguageTraslator.traslate("253")
303:                            + ":" + fileName + ":" + getDirectoryName(), e);
304:                }
305:            };
306:
307:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.