Source Code Cross Referenced for CMCProperties.java in  » Portal » Open-Portal » com » sun » portal » community » mc » impl » 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 » Portal » Open Portal » com.sun.portal.community.mc.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.community.mc.impl;
002:
003:        import java.util.Properties;
004:        import java.util.Set;
005:        import java.util.HashSet;
006:        import java.util.StringTokenizer;
007:
008:        import java.io.InputStream;
009:        import java.io.FileInputStream;
010:        import java.io.File;
011:        import java.io.FileNotFoundException;
012:        import java.io.IOException;
013:        import com.sun.portal.community.mc.*;
014:        import com.sun.portal.util.ResourceLoader;
015:        import java.util.Map;
016:        import java.util.HashMap;
017:        import java.util.Iterator;
018:
019:        /**
020:         * Utility class that wraps a Java <CODE>Properties</CODE> object and provides
021:         * community MC related convenience methods.
022:         */
023:        public abstract class CMCProperties {
024:            /**
025:             * Factory class for contributor Class objects.
026:             *
027:             * This class pre-loads all CMCUser and CMCNode
028:             * implementation Class objects based on the package names
029:             * defined in the community MC properties file. This avoids
030:             * calling Class.forName() for each new CU and CN object,
031:             * for each contributor and also the manager class.
032:             */
033:            private abstract static class ClassFactory {
034:                protected Map classes = new HashMap();
035:
036:                public ClassFactory(Properties p, Set types)
037:                        throws CMCException {
038:                    init(p, types);
039:                }
040:
041:                /**
042:                 * Return the correct class name based on the package name.
043:                 */
044:                protected abstract String getClassName(String pkgName);
045:
046:                protected void init(Properties p, Set types)
047:                        throws CMCException {
048:                    //
049:                    // scan properties looking for keys that end in .package
050:                    // these define the contributor's package name. use the
051:                    // pkg name to build a class name, and then a Class
052:                    // object
053:                    //
054:                    for (Iterator i = types.iterator(); i.hasNext();) {
055:                        String type = (String) i.next();
056:                        String pkgKey = type + ".package";
057:                        String pkg = p.getProperty(pkgKey);
058:                        if (pkg == null) {
059:                            throw new CMCException(
060:                                    "package name is null for properties type: "
061:                                            + type);
062:                        }
063:
064:                        String typeClassName = getClassName(pkg);
065:                        Class c;
066:
067:                        try {
068:                            c = Class.forName(typeClassName);
069:                        } catch (ClassNotFoundException cnfe) {
070:                            throw new CMCException(cnfe);
071:                        } catch (NoClassDefFoundError ncdfe) {
072:                            throw new CMCException(ncdfe);
073:                        } catch (ClassCastException cce) {
074:                            throw new CMCException(cce);
075:                        }
076:
077:                        classes.put(type, c);
078:                    }
079:                }
080:
081:                public Class getClass(String type) {
082:                    return (Class) classes.get(type);
083:                }
084:            }
085:
086:            /**
087:             * Factory class for contributor user Class objects.
088:             */
089:            private static class CMCUserClassFactory extends ClassFactory {
090:                CMCUserClassFactory(Properties p, Set types)
091:                        throws CMCException {
092:                    super (p, types);
093:                }
094:
095:                protected String getClassName(String pkg) {
096:                    return pkg + "." + CMCFactory.USER_CLASS_NAME;
097:                }
098:            }
099:
100:            /**
101:             * Factory class for contributor node Class objects.
102:             */
103:            private static class CMCNodeClassFactory extends ClassFactory {
104:                CMCNodeClassFactory(Properties p, Set types)
105:                        throws CMCException {
106:                    super (p, types);
107:                }
108:
109:                protected String getClassName(String pkg) {
110:                    return pkg + "." + CMCFactory.NODE_CLASS_NAME;
111:                }
112:            }
113:
114:            /**
115:             * Factory class for contributor node Class objects.
116:             */
117:            private static class CMCNodeManagerClassFactory extends
118:                    ClassFactory {
119:                CMCNodeManagerClassFactory(Properties p, Set types)
120:                        throws CMCException {
121:                    super (p, types);
122:                }
123:
124:                protected String getClassName(String pkg) {
125:                    return pkg + "." + CMCFactory.NODE_MANAGER_CLASS_NAME;
126:                }
127:            }
128:
129:            private static final String COMMUNITYMC_PROPERTIES = "communitymc.properties";
130:            private static Properties properties;
131:            private static ClassFactory userClassFactory;
132:            private static ClassFactory nodeClassFactory;
133:            private static ClassFactory nodeManagerClassFactory;
134:            private static Set contributors;
135:
136:            static {
137:                try {
138:                    loadProperties();
139:                    initContributorNames();
140:
141:                    // pre-load Class objects
142:
143:                    // add manager type, even though it is not 
144:                    // officially a contributor
145:                    Set types = new HashSet(contributors);
146:                    types.add("manager");
147:
148:                    userClassFactory = new CMCUserClassFactory(properties,
149:                            types);
150:                    nodeClassFactory = new CMCNodeClassFactory(properties,
151:                            types);
152:                    nodeManagerClassFactory = new CMCNodeManagerClassFactory(
153:                            properties, types);
154:                } catch (CMCException ce) {
155:                    throw new Error(ce);
156:                }
157:            }
158:
159:            /**
160:             * Property key for the community MC contributor types.
161:             */
162:            public static final String CONTRIBUTOR_KEY = "manager.contributors";
163:
164:            private CMCProperties() throws CMCException {
165:            }
166:
167:            private static void loadProperties() throws CMCException {
168:                try {
169:                    properties = ResourceLoader.getInstance(
170:                            System.getProperties()).getProperties(
171:                            COMMUNITYMC_PROPERTIES);
172:                } catch (FileNotFoundException fnfe) {
173:                    throw new CMCException(fnfe);
174:                } catch (IOException ioe) {
175:                    throw new CMCException(ioe);
176:                }
177:
178:            }
179:
180:            /**
181:             * Get the original Java <CODE>Properties</CODE> object.
182:             */
183:            public static Properties getProperties() {
184:                return properties;
185:            }
186:
187:            /**
188:             * Get the contributor types.
189:             */
190:            public static Iterator getContributorNames() {
191:                return contributors.iterator();
192:            }
193:
194:            private static void initContributorNames() {
195:                String ts = properties.getProperty(CONTRIBUTOR_KEY);
196:                StringTokenizer tokens = new StringTokenizer(ts, "|");
197:                contributors = new HashSet();
198:                while (tokens.hasMoreTokens()) {
199:                    contributors.add(tokens.nextToken());
200:                }
201:            }
202:
203:            /**
204:             * Get the Java class name that implements the CMCUser
205:             * interface, for the given type.
206:             */
207:            public static Class getUserClass(String type) {
208:                return userClassFactory.getClass(type);
209:            }
210:
211:            /**
212:             * Get the Java class name that implements the CMCNode
213:             * interface, for the given type.
214:             */
215:            public static Class getNodeClass(String type) {
216:                return nodeClassFactory.getClass(type);
217:            }
218:
219:            /**
220:             * Get the Java class name that implements the CMCNodeManager
221:             * interface, for the given type.
222:             */
223:            public static Class getNodeManagerClass(String type) {
224:                return nodeManagerClassFactory.getClass(type);
225:            }
226:
227:            /**
228:             * Get the type-specific property value for the given type
229:             * and key.
230:             */
231:            public static String getTypeProperty(String type, String key) {
232:                return properties.getProperty(type + "." + key);
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.