Source Code Cross Referenced for GeneralFormatter.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » gfpshare » db » formatter » 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 » ERP CRM Financial » Personal Finance Manager » br.com.gfpshare.db.formatter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 10/07/2004
003:         * 
004:         * Swing Components - visit http://sf.net/projects/gfd
005:         * 
006:         * Copyright (C) 2004  Igor Regis da Silva Simões
007:         * 
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or (at your option) any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package br.com.gfpshare.db.formatter;
024:
025:        import java.lang.reflect.InvocationTargetException;
026:        import java.sql.SQLException;
027:        import java.util.HashMap;
028:        import java.util.Map;
029:
030:        import br.com.gfpshare.db.DAOCreationException;
031:        import br.com.gfpshare.db.DAOProvider;
032:        import br.com.gfpshare.db.PersistentObject;
033:        import br.com.gfpshare.plugin.core.DynamicClassLoader;
034:
035:        /**
036:         * Classe capaz de formatar qualquer tipo de objeto
037:         * @author Igor Regis da Silva Simoes
038:         */
039:        public class GeneralFormatter implements  Formatter {
040:
041:            /**
042:             *	Lista de formatters ja carregados
043:             */
044:            private Map<String, Formatter> formatters = new HashMap<String, Formatter>();
045:
046:            /**
047:             * @see br.com.gfpshare.db.formatter.Formatter#format(java.lang.Object, int, java.lang.String)
048:             */
049:            @SuppressWarnings("unchecked")
050:            public String format(Object objeto, int tipo, String dataType) {
051:                if (hasFormatter(dataType))
052:                    return formatters.get(dataType).format(objeto, tipo,
053:                            dataType);
054:
055:                PersistentObject persistentObject = null;
056:                try {
057:                    if (objeto instanceof  PersistentObject) {
058:                        persistentObject = (PersistentObject) objeto;
059:                    } else if (Integer.parseInt(objeto.toString()) >= 0) {
060:                        try {
061:                            persistentObject = (PersistentObject) DynamicClassLoader
062:                                    .getClassLoader().loadClass(
063:                                            "br.com.gfp.data." + dataType)
064:                                    .getConstructor(
065:                                            new Class[] { Integer.class })
066:                                    .newInstance(
067:                                            new Object[] { new Integer(objeto
068:                                                    .toString()) });
069:                            persistentObject = DAOProvider
070:                                    .getControllerProvider().getController(
071:                                            dataType).getBy(persistentObject);
072:                        } catch (DAOCreationException cce) {
073:                            //TODO Excecao
074:                            cce.printStackTrace();
075:                            return "";
076:                        } catch (SQLException sqle) {
077:                            //TODO Excecao
078:                            sqle.printStackTrace();
079:                            return objeto.toString();
080:                        } catch (InstantiationException ie) {
081:                            //TODO Excecao
082:                            ie.printStackTrace();
083:                            return "";
084:                        } catch (ClassNotFoundException cnfe) {
085:                            //TODO Excecao
086:                            cnfe.printStackTrace();
087:                            return "";
088:                        } catch (NoSuchMethodException nsme) {
089:                            //TODO Excecao
090:                            nsme.printStackTrace();
091:                            return "";
092:                        } catch (IllegalAccessException iae) {
093:                            //TODO Excecao
094:                            iae.printStackTrace();
095:                            return "";
096:                        } catch (InvocationTargetException ite) {
097:                            //TODO Excecao
098:                            ite.printStackTrace();
099:                            return "";
100:                        }
101:                    } else {
102:                        return "";
103:                    }
104:                } catch (NumberFormatException nfe) {
105:                    return null;
106:                }
107:
108:                switch (tipo) {
109:                case Formatter.FORMATO_CURTO:
110:                    return persistentObject.getAsString(PersistentObject.CURTO);
111:                case Formatter.FORMATO_LONGO:
112:                    return "" + persistentObject;
113:                default:
114:                    return "";
115:                }
116:            }
117:
118:            /**
119:             * @see br.com.gfpshare.db.formatter.Formatter#parse(java.lang.String, java.lang.String)
120:             */
121:            public Object parse(String dado, String dataType) {
122:                if (hasFormatter(dataType))
123:                    return formatters.get(dataType).parse(dado, dataType);
124:                //TODO falta implementar a passagem da String para Map e daí para o PersistentObject
125:                return null;
126:            }
127:
128:            /**
129:             * Indica se existe um formatter para determinado tipo de dados
130:             * @param dataType Tipo de dados a ser formatado
131:             * @return boolean Com valor true se existe um formatter para este tipo de dado 
132:             */
133:            public boolean hasFormatter(String dataType) {
134:                if (formatters.containsKey(dataType))
135:                    return true;
136:                try {
137:                    formatters.put(dataType,
138:                            (Formatter) DynamicClassLoader.getClassLoader()
139:                                    .loadClass(
140:                                            "br.com.gfp.data." + dataType
141:                                                    + "Formatter")
142:                                    .newInstance());
143:                    return true;
144:                } catch (IllegalAccessException iae) {
145:                    return false;
146:                } catch (InstantiationException ie) {
147:                    return false;
148:                } catch (ClassNotFoundException cnfe) {
149:                    return false;
150:                }
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.