Source Code Cross Referenced for GraphXmlSerializer.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » graph » xmlbeans » 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 » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.graph.xmlbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.graph.xmlbeans;
002:
003:        import net.sourceforge.squirrel_sql.client.session.ISession;
004:        import net.sourceforge.squirrel_sql.fw.xml.XMLBeanWriter;
005:        import net.sourceforge.squirrel_sql.fw.xml.XMLBeanReader;
006:        import net.sourceforge.squirrel_sql.fw.xml.XMLException;
007:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
008:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
009:        import net.sourceforge.squirrel_sql.plugins.graph.GraphMainPanelTab;
010:        import net.sourceforge.squirrel_sql.plugins.graph.GraphPlugin;
011:
012:        import java.io.File;
013:        import java.io.FilenameFilter;
014:        import java.io.IOException;
015:        import java.io.FileNotFoundException;
016:
017:        public class GraphXmlSerializer {
018:
019:            private static final StringManager s_stringMgr = StringManagerFactory
020:                    .getStringManager(GraphXmlSerializer.class);
021:
022:            private static final String XML_BEAN_POSTFIX = ".graph.xml";
023:
024:            private GraphPlugin _plugin;
025:            private ISession _session;
026:            private String _graphFile;
027:
028:            /**
029:             * Either graphPane or graphFileName might be null.
030:             */
031:            public GraphXmlSerializer(GraphPlugin plugin, ISession session,
032:                    GraphMainPanelTab graphPane, String graphFileName) {
033:                try {
034:                    _plugin = plugin;
035:                    _session = session;
036:                    String url = _session.getAlias().getUrl();
037:
038:                    if (null == graphFileName) {
039:                        _graphFile = getFileName(plugin
040:                                .getPluginUserSettingsFolder().getPath(), url,
041:                                graphPane.getTitle());
042:                    } else {
043:                        _graphFile = graphFileName;
044:                    }
045:                } catch (Exception e) {
046:                    throw new RuntimeException(e);
047:                }
048:            }
049:
050:            public void write(GraphControllerXmlBean xmlBean) {
051:                try {
052:                    XMLBeanWriter bw = new XMLBeanWriter(xmlBean);
053:                    bw.save(_graphFile);
054:
055:                    String[] params = { xmlBean.getTitle(), _graphFile };
056:                    // i18n[graph.graphSaved=Graph "{0}" saved to "{1}"]
057:                    String msg = s_stringMgr.getString("graph.graphSaved",
058:                            params);
059:
060:                    _session.showMessage(msg);
061:                } catch (Exception e) {
062:                    throw new RuntimeException(e);
063:                }
064:            }
065:
066:            public GraphControllerXmlBean read() {
067:                try {
068:                    XMLBeanReader br = new XMLBeanReader();
069:                    br.load(_graphFile, this .getClass().getClassLoader());
070:                    return (GraphControllerXmlBean) br.iterator().next();
071:                } catch (Exception e) {
072:                    throw new RuntimeException(e);
073:                }
074:            }
075:
076:            private String getFileName(String path, String url, String title) {
077:                final String filePrefix = javaNormalize(url) + "."
078:                        + javaNormalize(title);
079:                File p = new File(path);
080:
081:                String buf = filePrefix;
082:                for (int i = 1; prefixExists(p, buf); ++i) {
083:                    buf = filePrefix + "_" + i;
084:                }
085:
086:                return path + File.separator + buf + XML_BEAN_POSTFIX;
087:            }
088:
089:            private boolean prefixExists(File path, final String filePrefix) {
090:                File[] files = path.listFiles(new FilenameFilter() {
091:                    public boolean accept(File dir, String name) {
092:                        if (name.toLowerCase().equals(
093:                                filePrefix.toLowerCase() + XML_BEAN_POSTFIX)) {
094:                            return true;
095:                        }
096:                        return false;
097:                    }
098:                });
099:                return 0 < files.length;
100:            }
101:
102:            private static String javaNormalize(String text) {
103:                StringBuffer buf = new StringBuffer(text.length());
104:
105:                if (Character.isJavaIdentifierStart(text.charAt(0))) {
106:                    buf.append(text.charAt(0));
107:                } else {
108:                    buf.append('_');
109:                }
110:
111:                for (int i = 1; i < text.length(); ++i) {
112:                    if (Character.isLetterOrDigit(text.charAt(i))) {
113:                        buf.append(text.charAt(i));
114:                    } else {
115:                        buf.append('_');
116:                    }
117:                }
118:
119:                String ret = buf.toString();
120:
121:                return ret;
122:            }
123:
124:            public static GraphXmlSerializer[] getGraphXmSerializers(
125:                    GraphPlugin plugin, ISession session) {
126:                try {
127:                    File settingsPath = plugin.getPluginUserSettingsFolder();
128:                    final String urlPrefix = javaNormalize(session.getAlias()
129:                            .getUrl())
130:                            + ".";
131:
132:                    File[] graphXmlFiles = settingsPath
133:                            .listFiles(new FilenameFilter() {
134:                                public boolean accept(File dir, String name) {
135:                                    if (name.startsWith(urlPrefix)) {
136:                                        return true;
137:                                    }
138:                                    return false;
139:                                }
140:                            });
141:
142:                    GraphXmlSerializer[] ret = new GraphXmlSerializer[graphXmlFiles.length];
143:                    for (int i = 0; i < graphXmlFiles.length; i++) {
144:                        ret[i] = new GraphXmlSerializer(plugin, session, null,
145:                                graphXmlFiles[i].getPath());
146:                    }
147:
148:                    return ret;
149:
150:                } catch (IOException e) {
151:                    throw new RuntimeException(e);
152:                }
153:            }
154:
155:            public void rename(String newName) {
156:                try {
157:                    String url = _session.getAlias().getUrl();
158:                    String newGraphFile = getFileName(_plugin
159:                            .getPluginUserSettingsFolder().getPath(), url,
160:                            newName);
161:                    (new File(_graphFile)).renameTo(new File(newGraphFile));
162:
163:                    String[] params = { _graphFile, newGraphFile };
164:                    // i18n[graph.graphRenamed=Renamed "{0}" to "{1}"]
165:                    _session.showMessage(s_stringMgr.getString(
166:                            "graph.graphRenamed", params));
167:
168:                    _graphFile = newGraphFile;
169:                } catch (Exception e) {
170:                    throw new RuntimeException(e);
171:                }
172:
173:            }
174:
175:            public void remove() {
176:                (new File(_graphFile)).delete();
177:
178:                String[] params = { _graphFile };
179:                // i18n[graph.graphRemoved=Removed graph file "{0}"]
180:                _session.showMessage(s_stringMgr.getString(
181:                        "graph.graphRemoved", params));
182:
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.