Source Code Cross Referenced for Plugin.java in  » Source-Control » sourcejammer » org » sourcejammer » client » gui » conf » 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 » Source Control » sourcejammer » org.sourcejammer.client.gui.conf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright (C) 2001-2003 Robert MacGrogan
003:         *
004:         *  This library is free software; you can redistribute it and/or
005:         *  modify it under the terms of the GNU Lesser General Public
006:         *  License as published by the Free Software Foundation; either
007:         *  version 2.1 of the License, or (at your option) any later version.
008:         *
009:         *  This library is distributed in the hope that it will be useful,
010:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         *  Lesser General Public License for more details.
013:         *
014:         *  You should have received a copy of the GNU Lesser General Public
015:         *  License along with this library; if not, write to the Free Software
016:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:         *
018:         *
019:         * $Archive: SourceJammer$
020:         * $FileName: Plugin.java$
021:         * $FileID: 4682$
022:         *
023:         * Last change:
024:         * $AuthorName: Rob MacGrogan$
025:         * $Date: 8/8/03 11:24 PM$
026:         * $Comment: Add ability to save values to XML Element.$
027:         */
028:        package org.sourcejammer.client.gui.conf;
029:
030:        import java.util.Enumeration;
031:        import java.util.HashMap;
032:        import java.util.Iterator;
033:        import java.util.StringTokenizer;
034:
035:        import org.sourcejammer.client.plugin.SJClientPlugin;
036:        import org.sourcejammer.util.ConfigurationException;
037:        import org.sourcejammer.util.EnumeratedType;
038:        import org.sourcejammer.xml.XMLNodeDoesNotExistException;
039:        import org.sourcejammer.xml.XMLUtil;
040:        import org.w3c.dom.Element;
041:        import org.w3c.dom.Node;
042:        import org.w3c.dom.NodeList;
043:
044:        /**
045:         * Title: $FileName: Plugin.java$
046:         * @version $VerNum: 3$
047:         * @author $AuthorName: Rob MacGrogan$<br><br>
048:         *
049:         * $Description: $<br>
050:         * $KeyWordsOff: $<br>
051:         */
052:        public class Plugin {
053:
054:            private String name = null;
055:            private String pluginClass = null;
056:            private HashMap types = new HashMap();
057:            private HashMap params = new HashMap();
058:            private SJClientPlugin plugin = null;
059:            private Element definition = null;
060:
061:            public static final class PluginType {
062:                public static final String ACTION = "Action";
063:                public static final String FILE_EVENT = "FileEvent";
064:                public static final String PROJECT_EVENT = "ProjectEvent";
065:            }
066:
067:            public static final class XMLNodes {
068:                public static final String PLUGINS = "plugins";
069:                public static final String PLUGIN = "plugin";
070:                public static final String PLUGIN_NAME = "name";
071:                public static final String PLUGIN_CLASS = "class";
072:                public static final String PLUGIN_TYPE = "type";
073:                public static final String PLUGIN_PARAMS = "params";
074:                public static final String PLUGIN_PARAM = "param";
075:                public static final String PLUGIN_PARAM_NAME = "param-name";
076:                public static final String PLUGIN_PARAM_VALUE = "param-value";
077:            }
078:
079:            public Plugin(Element pluginElement) {
080:                definition = pluginElement;
081:                name = pluginElement.getAttribute(XMLNodes.PLUGIN_NAME);
082:                if (name == null || name.equals("")) {
083:                    throw new ConfigurationException(
084:                            "Name attribute missing in plugin definition.");
085:                }
086:
087:                pluginClass = pluginElement.getAttribute(XMLNodes.PLUGIN_CLASS);
088:                if (pluginClass == null || pluginClass.equals("")) {
089:                    throw new ConfigurationException(
090:                            "Class attribute missing in plugin definition.");
091:                }
092:
093:                String types = pluginElement.getAttribute(XMLNodes.PLUGIN_TYPE);
094:                if (types == null || types.equals("")) {
095:                    throw new ConfigurationException(
096:                            "Type attribute missing in plugin definition.");
097:                }
098:                parseTypes(types);
099:
100:                //Try to load the class
101:                try {
102:                    Class cl = Class.forName(pluginClass);
103:                    Object o = cl.newInstance();
104:                    if (o instanceof  SJClientPlugin) {
105:                        plugin = (SJClientPlugin) o;
106:                        plugin.initPlugin(params);
107:                    } else {
108:                        throw new ConfigurationException(
109:                                "Specified plugin class, "
110:                                        + pluginClass
111:                                        + ", does not implement SJClientPlugin.");
112:                    }
113:                } catch (ClassNotFoundException e) {
114:                    throw new ConfigurationException(
115:                            "Could not load plugin class " + pluginClass + ".",
116:                            e);
117:                } catch (InstantiationException e) {
118:                    throw new ConfigurationException(
119:                            "Could not load plugin class " + pluginClass + ".",
120:                            e);
121:                } catch (IllegalAccessException e) {
122:                    throw new ConfigurationException(
123:                            "Could not load plugin class " + pluginClass + ".",
124:                            e);
125:                }
126:            }
127:
128:            private void parseTypes(String types) {
129:                //Space separated.
130:                StringTokenizer tokenizer = new StringTokenizer(types, " ");
131:                while (tokenizer.hasMoreTokens()) {
132:                    String type = tokenizer.nextToken();
133:                    this .types.put(type, "placeholder");
134:                }
135:            }
136:
137:            private void loadParams(Element pluginElement) {
138:                try {
139:                    Element elmParams = XMLUtil.getChildElement(
140:                            XMLNodes.PLUGIN_PARAMS, pluginElement);
141:                    NodeList paramList = elmParams.getChildNodes();
142:                    for (int i = 0; i < paramList.getLength(); i++) {
143:                        Node nd = paramList.item(i);
144:                        if (nd instanceof  Element) {
145:                            Element param = (Element) nd;
146:                            String sName = XMLUtil.getValue(
147:                                    XMLNodes.PLUGIN_PARAM_NAME, param);
148:                            String sValue = XMLUtil.getValue(
149:                                    XMLNodes.PLUGIN_PARAM_VALUE, param);
150:                            params.put(sName, sValue);
151:                        }
152:                    }
153:                } catch (XMLNodeDoesNotExistException ex) {
154:                    //ignore
155:                }
156:            }
157:
158:            public Element writePluginElement(Element pluginsElement) {
159:                Element pluginElement = XMLUtil.addNewChildElement(
160:                        XMLNodes.PLUGIN, pluginsElement);
161:                pluginElement.setAttribute(XMLNodes.PLUGIN_NAME, name);
162:                pluginElement.setAttribute(XMLNodes.PLUGIN_CLASS, pluginClass);
163:
164:                Iterator itr = types.keySet().iterator();
165:                StringBuffer str = new StringBuffer();
166:                boolean first = true;
167:                while (itr.hasNext()) {
168:                    if (!first) {
169:                        str.append(" ");
170:                    }
171:                    str.append((String) itr.next());
172:                    first = false;
173:                }
174:                pluginElement
175:                        .setAttribute(XMLNodes.PLUGIN_TYPE, str.toString());
176:
177:                if (params.size() > 0) {
178:                    Element elmParams = XMLUtil.addNewChildElement(
179:                            XMLNodes.PLUGIN_PARAMS, pluginElement);
180:                    itr = params.keySet().iterator();
181:                    while (itr.hasNext()) {
182:                        Element elmParam = XMLUtil.addNewChildElement(
183:                                XMLNodes.PLUGIN_PARAM, elmParams);
184:                        String paramName = (String) itr.next();
185:                        XMLUtil.addNewChildElement(XMLNodes.PLUGIN_PARAM_NAME,
186:                                paramName, elmParam);
187:                        String paramValue = (String) params.get(paramName);
188:                        XMLUtil.addNewChildElement(XMLNodes.PLUGIN_PARAM_VALUE,
189:                                paramValue, elmParam);
190:                    }
191:                }
192:
193:                return pluginElement;
194:            }
195:
196:            /**
197:             * Returns the definition.
198:             * @return Element
199:             */
200:            public Element getDefinition() {
201:                return definition;
202:            }
203:
204:            /**
205:             * Returns the name.
206:             * @return String
207:             */
208:            public String getName() {
209:                return name;
210:            }
211:
212:            /**
213:             * Returns the params.
214:             * @return HashMap
215:             */
216:            public HashMap getParams() {
217:                return params;
218:            }
219:
220:            /**
221:             * Returns the plugin.
222:             * @return SJClientPlugin
223:             */
224:            public SJClientPlugin getPlugin() {
225:                return plugin;
226:            }
227:
228:            /**
229:             * Returns the pluginClass.
230:             * @return String
231:             */
232:            public String getPluginClass() {
233:                return pluginClass;
234:            }
235:
236:            public boolean isType(String type) {
237:                Object o = types.get(type);
238:                return (o != null);
239:            }
240:
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.