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


001:        /**
002:         * Copyright 2004 Sun Microsystems, Inc. All
003:         * rights reserved. Use of this product is subject
004:         * to license terms. Federal Acquisitions:
005:         * Commercial Software -- Government Users
006:         * Subject to Standard License Terms and
007:         * Conditions.
008:         *
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010:         * are trademarks or registered trademarks of Sun Microsystems,
011:         * Inc. in the United States and other countries.
012:         */package com.sun.portal.fabric.tasks;
013:
014:        import com.sun.portal.fabric.util.FileUtil;
015:        import com.sun.portal.fabric.util.NetworkUtil;
016:        import com.sun.portal.fabric.util.ClasspathGenUtil;
017:        import com.sun.portal.admin.common.Tags;
018:        import com.sun.portal.admin.common.context.PSConfigContext;
019:        import com.sun.portal.monitoring.MonitoringConfiguration;
020:        import com.sun.portal.monitoring.MonitoringException;
021:        import com.sun.portal.log.common.PortalLogger;
022:
023:        import java.io.*;
024:        import java.util.logging.Logger;
025:        import java.util.logging.Level;
026:        import java.util.List;
027:        import java.util.ArrayList;
028:        import java.util.Properties;
029:
030:        import com.sun.portal.util.Platform;
031:
032:        /**
033:         * Provides the functionality needed for configuring
034:         * a Portal on a host.
035:         *
036:         */
037:        public class PortalInstance {
038:
039:            /**
040:             * Portal identifier
041:             */
042:            private String portalID;
043:
044:            /**
045:             * Portal instance identifier
046:             */
047:            private String instanceID;
048:
049:            /**
050:             * Portal instace hostname
051:             */
052:            private String host;
053:
054:            /**
055:             * Portal instace web container type
056:             */
057:            private String containerType;
058:
059:            /**
060:             * Portal Configuration context
061:             */
062:            private PSConfigContext context;
063:
064:            /**
065:             * Logger instance
066:             */
067:            private static Logger logger = PortalLogger
068:                    .getLogger(PortalInstance.class);
069:
070:            /**
071:             *  File separator
072:             */
073:            public final static String fs = Platform.fs;
074:
075:            /**
076:             * Constructor
077:             *
078:             * @param portalID  portal identifier
079:             * @param instanceID portal instance identifier
080:             * @param host portal instance host
081:             * @param containerType portal instance web container type
082:             * @param context Portal Server configuration context
083:             */
084:            public PortalInstance(String portalID, String instanceID,
085:                    String host, String containerType, PSConfigContext context) {
086:                this .portalID = portalID;
087:                this .instanceID = instanceID;
088:                this .host = host;
089:                this .containerType = containerType;
090:                this .context = context;
091:            }
092:
093:            public void setupInstanceConfigFiles()
094:                    throws ConfigurationException {
095:
096:                //copying all instance level configuration files from templates dir
097:                String portalDir = context.getPSDataDir() + fs + "portals" + fs
098:                        + portalID;
099:                String portalConfigDir = portalDir + fs + "config";
100:                String instConfigDir = portalConfigDir + fs + instanceID;
101:                String sPSBaseDir = context.getPSBaseDir();
102:                String instTemplateDir = sPSBaseDir + fs + "template" + fs
103:                        + "instance";
104:
105:                File iconfDir = new File(instConfigDir);
106:                iconfDir.mkdirs();
107:
108:                FileUtil.makeDir(instConfigDir);
109:                copyInstanceConfigurationFiles(instTemplateDir, instConfigDir);
110:
111:                // Copy JES MF files to instance dir
112:                // JES MF files are not shipped in instance template dir to handle 7.0 upgrade scenarios
113:                if (context.getJESMFLibDir() != null) {
114:                    String jesmfTemplateDir = sPSBaseDir + fs + "template" + fs
115:                            + "jesmf";
116:                    copyJesMfConfigurationFiles(jesmfTemplateDir, instConfigDir);
117:                }
118:
119:                List files = new ArrayList();
120:                if (FileUtil.getFiles(iconfDir, files)) {
121:                    int iFilesNum = files.size();
122:                    for (int i = 0; i < iFilesNum; i++) {
123:                        File configFile = (File) files.get(i);
124:                        //Tagswap %PORTAL_ID%, %PORTAL_DIR%, %PORTAL_CONFIG_DIR%,
125:                        // %INSTANCE_ID%, %INSTANCE_CONFIG_DIR%, %PS_DIR%, %JESMF_LIB_LOCATION% tags
126:                        String[] tokens = { Tags.PORTAL_ID, Tags.PORTAL_DIR,
127:                                Tags.PORTAL_CONFIG_DIR, Tags.INSTANCE_ID,
128:                                Tags.INSTANCE_CONFIG_DIR, Tags.PS_DIR,
129:                                Tags.JESMF_LIB_LOCATION };
130:                        String sJesMfLibDir = context.getJESMFLibDir();
131:                        sJesMfLibDir = (sJesMfLibDir != null) ? sJesMfLibDir
132:                                : "";
133:                        String[] values = { portalID, portalDir,
134:                                portalConfigDir, instanceID, instConfigDir,
135:                                sPSBaseDir, sJesMfLibDir };
136:                        boolean replaced = FileUtil.replaceTokensInFile(
137:                                configFile, tokens, values);
138:                        if (!replaced) {
139:                            logger.log(Level.SEVERE, "PSFB_CSPFT0283",
140:                                    configFile.getAbsolutePath());
141:                            throw new ConfigurationException(
142:                                    "Failed to replace tokens in "
143:                                            + configFile.getAbsolutePath());
144:                        }
145:                    }
146:
147:                    //Monitoring configuration
148:                    configureMonitoring();
149:                } else {
150:                    logger.log(Level.SEVERE, "PSFB_CSPFT0284");
151:                    throw new ConfigurationException(
152:                            "Failed to copy portal instance configuration templates");
153:                }
154:            }
155:
156:            /**
157:             * Copy instance specific configuration files from templates dir
158:             * If the file has a web container specific version, copy only this as the property file
159:             * Web container specific version should have naming format of:
160:             * FileName.WebContainerType.Extension
161:             * Supported webcontainer types are found in com.sun.portal.admin.common.InstanceAttributes
162:             * If not found default to original template. The default template should alway be found.
163:             *
164:             * @param instanceTemplateDir - instance template directory
165:             * @param instanceConfigDir - instance configuration directory
166:             */
167:            private void copyInstanceConfigurationFiles(
168:                    String instanceTemplateDir, String instanceConfigDir) {
169:                File templateDir = new File(instanceTemplateDir);
170:                List templateFiles = new ArrayList();
171:                List srcFiles = new ArrayList();
172:                List dstFiles = new ArrayList();
173:                if (FileUtil.getFiles(templateDir, templateFiles)) {
174:                    int iTemplateFilesNum = templateFiles.size();
175:                    for (int i = 0; i < iTemplateFilesNum; i++) {
176:                        File file = (File) templateFiles.get(i);
177:                        String fileName = file.getName();
178:                        String filePfx = fileName.substring(0, fileName
179:                                .indexOf('.'));
180:                        String fileSfx = fileName.substring(fileName
181:                                .lastIndexOf('.') + 1);
182:
183:                        //Does instance specific config file exist
184:                        String instConfFile = filePfx + "." + containerType
185:                                + "." + fileSfx;
186:                        String defConfFile = filePfx + "." + fileSfx;
187:                        if (FileUtil.fileExists(instanceTemplateDir + fs
188:                                + instConfFile)) {
189:                            //Is it already in the source files list dont add it
190:                            if (!srcFiles.contains(instConfFile)) {
191:                                srcFiles.add(instConfFile);
192:                                dstFiles.add(defConfFile);
193:                            }
194:                        } else if (FileUtil.fileExists(instanceTemplateDir + fs
195:                                + defConfFile)) {
196:                            // if instance specific file does not exist add default
197:                            if (!srcFiles.contains(defConfFile)) {
198:                                srcFiles.add(defConfFile);
199:                                dstFiles.add(defConfFile);
200:                            }
201:                        }
202:                    }
203:                }
204:
205:                //Now copy all source files from template dir to destination files in config dir
206:                int iSrcFilesNum = srcFiles.size();
207:                for (int i = 0; i < iSrcFilesNum; i++) {
208:                    FileUtil.copyFile(instanceTemplateDir + fs
209:                            + (String) srcFiles.get(i), instanceConfigDir + fs
210:                            + (String) dstFiles.get(i));
211:                }
212:            }
213:
214:            private void copyJesMfConfigurationFiles(String jesmfTemplateDir,
215:                    String instanceConfigDir) {
216:
217:                File templateDir = new File(jesmfTemplateDir);
218:                List templateFiles = new ArrayList();
219:                List srcFiles = new ArrayList();
220:                List dstFiles = new ArrayList();
221:
222:                if (FileUtil.getFiles(templateDir, templateFiles)) {
223:                    int iTemplateFilesNum = templateFiles.size();
224:                    for (int i = 0; i < iTemplateFilesNum; i++) {
225:                        File file = (File) templateFiles.get(i);
226:                        String fileName = file.getName();
227:                        FileUtil.copyFile(jesmfTemplateDir + fs
228:                                + (String) fileName, instanceConfigDir + fs
229:                                + fileName);
230:                    }
231:                }
232:            }
233:
234:            /**
235:             * Monitoring sepecific configuration
236:             */
237:            private void configureMonitoring() {
238:                //monitoring.properties configuration
239:                String monPropFile = context.getPSDataDir() + fs + "portals"
240:                        + fs + portalID + fs + "config" + fs + instanceID + fs
241:                        + "monitoring.properties";
242:                MonitoringConfigurationHelper.configurePropertyFile(
243:                        monPropFile, host, context);
244:            }
245:
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.