Source Code Cross Referenced for ActionManager.java in  » Wiki-Engine » VeryQuickWiki » vqwiki » 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 » Wiki Engine » VeryQuickWiki » vqwiki 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2004, Gareth Cronin
003:         * User: garethc
004:         * Date: 6/06/2004
005:         * Time: 09:19:14
006:         */package vqwiki;
007:
008:        import org.apache.log4j.Logger;
009:
010:        import java.io.File;
011:        import java.io.FileOutputStream;
012:        import java.io.IOException;
013:        import java.io.InputStream;
014:        import java.net.URL;
015:        import java.util.Properties;
016:
017:        /**
018:         * Manager that maintains bindings between logical action names and classes that implement {@link WikiAction}
019:         * The action manager can delegate requests to appropriate actions.
020:         */
021:        public class ActionManager {
022:
023:            /** Logger */
024:            public static final Logger logger = Logger
025:                    .getLogger(ActionManager.class);
026:            /** Mapping of action names to classes */
027:            private Properties mapping;
028:            /** Singleton instance */
029:            private static ActionManager ourInstance = new ActionManager();
030:            /** Name of the resource that is the mapping file to persist to */
031:            private static final String MAPPING_PROPERTIES_FILE = "/actions.properties";
032:
033:            /**
034:             * Get singleton instance
035:             *
036:             * @return singleton instance
037:             */
038:            public static ActionManager getInstance() {
039:                return ourInstance;
040:            }
041:
042:            /**
043:             * Hide constructor
044:             */
045:            private ActionManager() {
046:            }
047:
048:            /**
049:             * Return an instance of the named action
050:             *
051:             * @param actionName name
052:             * @return instance or null if there is no mapping for the named action
053:             * @throws ClassNotFoundException if the mapped class can't be found
054:             * @throws IllegalAccessException on a security problem
055:             * @throws InstantiationException if the mapped class can't be instantiated
056:             */
057:            public WikiAction getActionInstance(String actionName)
058:                    throws ClassNotFoundException, IllegalAccessException,
059:                    InstantiationException {
060:                logger.debug("getting action instance: " + actionName);
061:                String className = getMapping().getProperty(actionName);
062:                if (className == null) {
063:                    return null;
064:                }
065:                Class clazz = Class.forName(className);
066:                return (WikiAction) clazz.newInstance();
067:            }
068:
069:            /**
070:             * Get the current mapping
071:             *
072:             * @return mapping
073:             */
074:            private Properties getMapping() {
075:                if (mapping == null) {
076:                    InputStream in = ActionManager.class
077:                            .getResourceAsStream(MAPPING_PROPERTIES_FILE);
078:                    if (in == null) {
079:                        logger.warn(MAPPING_PROPERTIES_FILE + " not found");
080:                    }
081:                    mapping = new Properties();
082:                    try {
083:                        mapping.load(in);
084:                        in.close();
085:                    } catch (IOException e) {
086:                        logger.warn(e);
087:                    }
088:                }
089:                logger.debug("mapping: " + mapping);
090:                return mapping;
091:            }
092:
093:            /**
094:             * Add a mapping
095:             *
096:             * @param actionName action name
097:             * @param className  class implementing {@link WikiAction}
098:             * @throws IOException on any error persisting the mapping
099:             */
100:            public void addMapping(String actionName, String className)
101:                    throws IOException {
102:                logger.debug("adding action mapping: " + actionName + "->"
103:                        + className);
104:                getMapping().setProperty(actionName, className);
105:                URL base = ActionManager.class.getResource("/");
106:                FileOutputStream out = null;
107:                try {
108:                    out = new FileOutputStream(new File(base.getFile(),
109:                            MAPPING_PROPERTIES_FILE));
110:                    getMapping().store(out, "actions");
111:                } finally {
112:                    if (out != null) {
113:                        out.close();
114:                    }
115:                }
116:            }
117:
118:            /**
119:             * Return whether a mapping exists for the named action
120:             *
121:             * @param actionName action name
122:             * @return true if it exists
123:             */
124:            public boolean actionExists(String actionName) {
125:                boolean result = getMapping().containsKey(actionName);
126:                logger.debug("action exists: '" + actionName + "' ?" + result);
127:                return result;
128:            }
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.