Source Code Cross Referenced for SunASAutoIntegrationProvider.java in  » IDE-Netbeans » profiler » org » netbeans » modules » profiler » j2ee » sunas » 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 » IDE Netbeans » profiler » org.netbeans.modules.profiler.j2ee.sunas 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         * The Original Software is NetBeans. The Initial Developer of the Original
0026:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0027:         * Microsystems, Inc. All Rights Reserved.
0028:         *
0029:         * If you wish your version of this file to be governed by only the CDDL
0030:         * or only the GPL Version 2, indicate your decision by adding
0031:         * "[Contributor] elects to include this software in this distribution
0032:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0033:         * single choice of license, a recipient has the option to distribute
0034:         * your version of this file under either the CDDL, the GPL Version 2 or
0035:         * to extend the choice of license to its licensees as provided above.
0036:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0037:         * Version 2 license, then the option applies only if the new code is
0038:         * made subject to such option by the copyright holder.
0039:         */
0040:
0041:        package org.netbeans.modules.profiler.j2ee.sunas;
0042:
0043:        import org.netbeans.lib.profiler.common.AttachSettings;
0044:        import org.openide.util.NbBundle;
0045:        import org.w3c.dom.Document;
0046:        import org.w3c.dom.Element;
0047:        import org.w3c.dom.Node;
0048:        import org.w3c.dom.NodeList;
0049:        import org.xml.sax.EntityResolver;
0050:        import org.xml.sax.InputSource;
0051:        import org.xml.sax.SAXException;
0052:        import java.io.File;
0053:        import java.io.IOException;
0054:        import java.io.StringReader;
0055:        import java.io.StringWriter;
0056:        import java.text.MessageFormat;
0057:        import java.util.Collection;
0058:        import java.util.Properties;
0059:        import java.util.ResourceBundle;
0060:        import java.util.Vector;
0061:        import javax.xml.parsers.DocumentBuilder;
0062:        import javax.xml.parsers.DocumentBuilderFactory;
0063:        import javax.xml.transform.OutputKeys;
0064:        import javax.xml.transform.Transformer;
0065:        import javax.xml.transform.TransformerFactory;
0066:        import javax.xml.transform.dom.DOMSource;
0067:        import javax.xml.transform.stream.StreamResult;
0068:        import org.netbeans.lib.profiler.common.integration.IntegrationUtils;
0069:        import org.netbeans.modules.profiler.attach.AttachWizard;
0070:        import org.netbeans.modules.profiler.attach.providers.IDESettingsPersistor;
0071:        import org.netbeans.modules.profiler.attach.providers.SettingsPersistor;
0072:        import org.netbeans.modules.profiler.attach.providers.ValidationResult;
0073:        import org.netbeans.modules.profiler.attach.providers.scripted.AbstractScriptIntegrationProvider;
0074:        import org.netbeans.modules.profiler.attach.providers.scripted.ProfilerScriptModifier;
0075:        import org.netbeans.modules.profiler.attach.providers.scripted.ScriptHeaderModifier;
0076:        import org.netbeans.modules.profiler.attach.providers.scripted.ScriptModificationException;
0077:        import org.netbeans.modules.profiler.attach.providers.scripted.TextScriptHeaderModifier;
0078:        import org.netbeans.modules.profiler.attach.providers.scripted.XmlScriptHeaderModifier;
0079:        import org.netbeans.modules.profiler.attach.spi.IntegrationProvider;
0080:        import org.netbeans.modules.profiler.attach.spi.ModificationException;
0081:        import org.netbeans.modules.profiler.attach.wizard.steps.SimpleWizardStep;
0082:
0083:        /**
0084:         *
0085:         * @author Tomas Hurka
0086:         * @author Jaroslav Bachorik
0087:         */
0088:        public abstract class SunASAutoIntegrationProvider extends
0089:                AbstractScriptIntegrationProvider {
0090:            //~ Static fields/initializers -----------------------------------------------------------------------------------------------
0091:
0092:            // <editor-fold defaultstate="collapsed" desc="Resources">
0093:            private static final ResourceBundle messages = ResourceBundle
0094:                    .getBundle("org.netbeans.modules.profiler.j2ee.sunas.Bundle"); // NOI18N
0095:            private static final String PATH_TO_JVM_DIR_TEXT = messages
0096:                    .getString("SunAS8IntegrationProvider_PathToJvmDirText"); // NOI18N
0097:            private static final String MANUAL_REMOTE_STEP3_MSG = messages
0098:                    .getString("SunAS8IntegrationProvider_ManualRemoteStep3Msg"); // NOI18N
0099:            private static final String MANUAL_REMOTE_STEP4_50_MSG = messages
0100:                    .getString("SunAS8IntegrationProvider_ManualRemoteStep450Msg"); // NOI18N
0101:            private static final String MANUAL_REMOTE_STEP5_MSG = messages
0102:                    .getString("SunAS8IntegrationProvider_ManualRemoteStep5Msg"); // NOI18N
0103:            private static final String MANUAL_REMOTE_STEP6_MSG = messages
0104:                    .getString("SunAS8IntegrationProvider_ManualRemoteStep6Msg"); // NOI18N
0105:            private static final String MANUAL_REMOTE_STEP7_MSG = messages
0106:                    .getString("SunAS8IntegrationProvider_ManualRemoteStep7Msg"); // NOI18N
0107:            private static final String MANUAL_DIRECT_DYNAMIC_STEP1_MSG = messages
0108:                    .getString("SunAS8IntegrationProvider_ManualDirectDynamicStep1Msg"); // NOI18N
0109:            private static final String MANUAL_DIRECT_DYNAMIC_STEP2_50_MSG = messages
0110:                    .getString("SunAS8IntegrationProvider_ManualDirectDynamicStep250Msg"); // NOI18N
0111:            private static final String MANUAL_DIRECT_STEP3_MSG = messages
0112:                    .getString("SunAS8IntegrationProvider_ManualDirectStep3Msg"); // NOI18N
0113:            private static final String MANUAL_DIRECT_STEP4_MSG = messages
0114:                    .getString("SunAS8IntegrationProvider_ManualDirectStep4Msg"); // NOI18N
0115:            private static final String MANUAL_DIRECT_STEP5_MSG = messages
0116:                    .getString("SunAS8IntegrationProvider_ManualDirectStep5Msg"); // NOI18N
0117:            private static final String MANUAL_DYNAMIC_STEP3_MSG = messages
0118:                    .getString("SunAS8IntegrationProvider_ManualDynamicStep3Msg"); // NOI18N
0119:            private static final String INTEGR_REVIEW_STEP1_MSG = messages
0120:                    .getString("SunAS8IntegrationProvider_IntegrReviewStep1Msg"); // NOI18N
0121:            private static final String INTEGR_REVIEW_STEP2_MSG = messages
0122:                    .getString("SunAS8IntegrationProvider_IntegrReviewStep2Msg"); // NOI18N
0123:            private static final String INTEGR_REVIEW_STEP3_DIRECT_MSG = messages
0124:                    .getString("SunAS8IntegrationProvider_IntegrReviewStep3DirectMsg"); // NOI18N
0125:            private static final String INTEGR_REVIEW_STEP3_DYNAMIC_MSG = messages
0126:                    .getString("SunAS8IntegrationProvider_IntegrReviewStep3DynamicMsg"); // NOI18N
0127:            private static final String RESTORE_SETTINGS_WARNING_MSG = messages
0128:                    .getString("SunAS8IntegrationProvider_RestoreSettingsWarningMsg"); // NOI18N
0129:            private static final String ADDITIONAL_STEPS_STEP1_DIRECT_MSG = messages
0130:                    .getString("SunAS8IntegrationProvider_AdditionalStepsStep1DirectMsg"); // NOI18N
0131:            private static final String ADDITIONAL_STEPS_STEP1_DYNAMIC_MSG = messages
0132:                    .getString("SunAS8IntegrationProvider_AdditionalStepsStep1DynamicMsg"); // NOI18N
0133:            private static final String ADDITIONAL_STEPS_STEP2_MSG = messages
0134:                    .getString("SunAS8IntegrationProvider_AdditionalStepsStep2Msg"); // NOI18N
0135:            private static final String ADDITIONAL_STEPS_STEP3_DIRECT_MSG = messages
0136:                    .getString("SunAS8IntegrationProvider_AdditionalStepsStep3DirectMsg"); // NOI18N
0137:            private static final String ADDITIONAL_STEPS_STEP3_DYNAMIC_PID_MSG = messages
0138:                    .getString("SunAS8IntegrationProvider_AdditionalStepsStep3DynamicPidMsg"); // NOI18N
0139:            private static final String ADDITIONAL_STEPS_AUTO_START_MSG = messages
0140:                    .getString("SunAS8IntegrationProvider_AdditionalStepsAutoStartMsg"); // NOI18N
0141:            private static final String ENTER_INSTALL_DIR_MSG = messages
0142:                    .getString("SunAS8IntegrationProvider_EnterInstallDirMsg"); // NOI18N
0143:            private static final String INVALID_INSTALL_DIR_MSG = messages
0144:                    .getString("SunAS8IntegrationProvider_InvalidInstallDirMsg"); // NOI18N
0145:            private static final String DYNAMIC_WARNING_MESSAGE = messages
0146:                    .getString("SunASIntegrationProvider_DynamicWarningMessage"); // NOI18N  
0147:            // </editor-fold>
0148:
0149:            // <editor-fold defaultstate="collapsed" desc="Constants">
0150:            private static final String SUNAS_INSTALL_VAR_STRING = "AS_INSTALL"; // NOI18N
0151:            private static final String SUNAS_HOME_VAR_STRING = "AS_HOME"; // NOI18N
0152:            private static final String SUNAS_8PE_BINDIR_NAME = "bin"; // NOI18N
0153:            private static final String SUNAS_8PE_ASADMINSCRIPT_NAME = "asadmin"; // NOI18N
0154:            private static final String SUNAS_8PE_CONFIGDIR_NAME = "config"; // NOI18N
0155:            private static final String SUNAS_8PE_ASENVSCRIPT_NAME = "asenv"; // NOI18N
0156:            private static final String SUNAS_8PE_DOMAINSDIR_NAME = "domains"; // NOI18N
0157:            private static final String SUNAS_8PE_DOMAINCONFIGDIR_NAME = "config"; // NOI18N
0158:            private static final String SUNAS_8PE_DOMAINSCRIPT_NAME = "domain.xml"; // NOI18N
0159:            private static final String ASENV_INSERTION_POINT_WIN_0_STRING = "set AS_JAVA"; // NOI18N
0160:            private static final String ASENV_INSERTION_POINT_NOWIN_0_STRING = "AS_JAVA"; // NOI18N
0161:            // </editor-fold>
0162:
0163:            //~ Instance fields ----------------------------------------------------------------------------------------------------------
0164:
0165:            private SettingsPersistor persistor;
0166:            private String appserverDomain = ""; // NOI18N
0167:            private String scriptPublicId = ""; // NOI18N
0168:            private String scriptSystemId = ""; // NOI18N
0169:
0170:            //~ Constructors -------------------------------------------------------------------------------------------------------------
0171:
0172:            public SunASAutoIntegrationProvider() {
0173:                super ();
0174:                this .attachedWizard = new SimpleWizardStep(NbBundle.getMessage(
0175:                        SunASAutoIntegrationProvider.class,
0176:                        "AttachWizard_LocateRequiredFilesString"),
0177:                        new SunASIntegrationPanel()); // NOI18N
0178:                this .persistor = new IDESettingsPersistor() {
0179:                    protected String getSettingsFileName() {
0180:                        return "SunAS8IntegrationProvider.properties"; // NOI18N
0181:                    }
0182:
0183:                    protected void parsePersistableSettings(Properties settings) {
0184:                        setTargetJava(settings.getProperty(
0185:                                "SunAS8IntegrationProvider_" + getMagicNumber()
0186:                                        + "_JavaPlatform", "")); // NOI18N
0187:                        setInstallationPath(settings.getProperty(
0188:                                "SunAS8IntegrationProvider_" + getMagicNumber()
0189:                                        + "_InstallDir", "")); // NOI18N
0190:                        setDomain(settings.getProperty(
0191:                                "SunAS8IntegrationProvider_" + getMagicNumber()
0192:                                        + "_DomainName", "")); // NOI18N
0193:
0194:                        if ((getInstallationPath() == null)
0195:                                || (getInstallationPath().length() == 0)) {
0196:                            setInstallationPath(getDefaultInstallationPath());
0197:                        }
0198:                    }
0199:
0200:                    protected Properties preparePersistableSettings() {
0201:                        Properties settings = new Properties();
0202:                        settings.setProperty("SunAS8IntegrationProvider_"
0203:                                + getMagicNumber() + "_JavaPlatform",
0204:                                getTargetJava()); // NOI18N
0205:                        settings.setProperty("SunAS8IntegrationProvider_"
0206:                                + getMagicNumber() + "_InstallDir",
0207:                                getInstallationPath()); // NOI18N
0208:                        settings
0209:                                .setProperty("SunAS8IntegrationProvider_"
0210:                                        + getMagicNumber() + "_DomainName",
0211:                                        getDomain()); // NOI18N
0212:
0213:                        return settings;
0214:                    }
0215:                };
0216:            }
0217:
0218:            //~ Methods ------------------------------------------------------------------------------------------------------------------
0219:
0220:            public IntegrationProvider.IntegrationHints getAfterInstallationHints(
0221:                    AttachSettings attachSettings, boolean automation) {
0222:                IntegrationProvider.IntegrationHints instructions = new IntegrationProvider.IntegrationHints();
0223:
0224:                String targetOS = attachSettings.getHostOS();
0225:
0226:                // Step 1
0227:                if (attachSettings.isDirect()) {
0228:                    instructions.addStep(MessageFormat.format(
0229:                            ADDITIONAL_STEPS_STEP1_DIRECT_MSG,
0230:                            new Object[] { getAsAdminScriptFilePath(targetOS)
0231:                                    + " start-domain --domaindir "
0232:                                    + getInstallationPath()
0233:                                    + IntegrationUtils
0234:                                            .getDirectorySeparator(targetOS)
0235:                                    + SUNAS_8PE_DOMAINSDIR_NAME + " "
0236:                                    + getDomain() })); // NOI18N
0237:                } else {
0238:                    instructions
0239:                            .addStep(MessageFormat
0240:                                    .format(
0241:                                            ADDITIONAL_STEPS_STEP1_DYNAMIC_MSG,
0242:                                            new Object[] {
0243:                                                    getAsAdminScriptFilePath(targetOS)
0244:                                                            + " start-domain --domaindir "
0245:                                                            + getInstallationPath()
0246:                                                            + IntegrationUtils
0247:                                                                    .getDirectorySeparator(targetOS)
0248:                                                            + SUNAS_8PE_DOMAINSDIR_NAME
0249:                                                            + " " + getDomain(),
0250:                                                    "" })); // NOI18N
0251:                }
0252:
0253:                // Step 2
0254:                instructions.addStep(ADDITIONAL_STEPS_STEP2_MSG);
0255:
0256:                if (attachSettings.isDirect()) {
0257:                    instructions.addStep(ADDITIONAL_STEPS_STEP3_DIRECT_MSG);
0258:                } else {
0259:                    instructions
0260:                            .addStep(ADDITIONAL_STEPS_STEP3_DYNAMIC_PID_MSG);
0261:                    instructions
0262:                            .addWarning(MessageFormat
0263:                                    .format(
0264:                                            DYNAMIC_WARNING_MESSAGE,
0265:                                            new Object[] {
0266:                                                    IntegrationUtils
0267:                                                            .getJavaPlatformName(getTargetJava()),
0268:                                                    IntegrationUtils
0269:                                                            .getProfilerAgentCommandLineArgs(
0270:                                                                    targetOS,
0271:                                                                    getTargetJava(),
0272:                                                                    attachSettings
0273:                                                                            .isRemote(),
0274:                                                                    attachSettings
0275:                                                                            .getPort()) }));
0276:                }
0277:
0278:                // modified files warning
0279:                instructions.addWarning(MessageFormat.format(
0280:                        RESTORE_SETTINGS_WARNING_MSG, new Object[] {
0281:                                getAsEnvScriptFileName(targetOS),
0282:                                SUNAS_8PE_DOMAINSCRIPT_NAME }));
0283:
0284:                instructions.addHint(ADDITIONAL_STEPS_AUTO_START_MSG);
0285:
0286:                return instructions;
0287:            }
0288:
0289:            public final Collection getAvailableDomains(String installPath) {
0290:                final String separator = System.getProperty("file.separator"); // NOI18N
0291:                final StringBuffer path = new StringBuffer();
0292:                final Collection availableDomains = new Vector();
0293:
0294:                path.append(installPath);
0295:
0296:                if (!installPath.endsWith(separator)) {
0297:                    path.append(separator);
0298:                }
0299:
0300:                path.append(SUNAS_8PE_DOMAINSDIR_NAME);
0301:
0302:                File domainsDir = new File(path.toString());
0303:
0304:                // invalid domains directory
0305:                if (domainsDir.exists()) {
0306:                    File[] domains = domainsDir.listFiles();
0307:
0308:                    // no valid domains found in domains directory
0309:                    if (!((domains == null) || (domains.length == 0))) {
0310:                        // searching for available domains with domain.xml script
0311:                        for (int i = 0; i < domains.length; i++) {
0312:                            StringBuffer configPath = new StringBuffer(
0313:                                    domains[i].getAbsolutePath());
0314:                            configPath.append(separator).append(
0315:                                    SUNAS_8PE_DOMAINCONFIGDIR_NAME).append(
0316:                                    separator).append(
0317:                                    SUNAS_8PE_DOMAINSCRIPT_NAME);
0318:
0319:                            if (domains[i].isDirectory()
0320:                                    && new File(configPath.toString()).exists()) {
0321:                                availableDomains.add(domains[i].getName());
0322:                            }
0323:                        }
0324:                    }
0325:                }
0326:
0327:                return availableDomains;
0328:            }
0329:
0330:            public void setDomain(String domain) {
0331:                appserverDomain = domain;
0332:            }
0333:
0334:            // </editor-fold>
0335:            public String getDomain() {
0336:                return appserverDomain;
0337:            }
0338:
0339:            public String getDomainScriptDirPath(
0340:                    final AttachSettings attachSettings) {
0341:                String targetOS = attachSettings.getHostOS();
0342:
0343:                return getDomainScriptDirPath(targetOS);
0344:            }
0345:
0346:            public IntegrationProvider.IntegrationHints getIntegrationReview(
0347:                    AttachSettings attachSettings) {
0348:                IntegrationProvider.IntegrationHints instructions = new IntegrationProvider.IntegrationHints();
0349:
0350:                String targetOS = attachSettings.getHostOS();
0351:
0352:                // Step 1
0353:                instructions.addStep(MessageFormat.format(
0354:                        INTEGR_REVIEW_STEP1_MSG, new Object[] {
0355:                                getAsEnvScriptFilePath(targetOS),
0356:                                getDomainScriptFilePath(targetOS),
0357:                                getAsEnvScriptFileName(targetOS),
0358:                                SUNAS_8PE_DOMAINSCRIPT_NAME }));
0359:
0360:                // Step 2
0361:                instructions
0362:                        .addStep(MessageFormat
0363:                                .format(
0364:                                        INTEGR_REVIEW_STEP2_MSG,
0365:                                        new Object[] {
0366:                                                getAsEnvScriptFileName(targetOS),
0367:                                                (IntegrationUtils
0368:                                                        .isWindowsPlatform(targetOS) ? ASENV_INSERTION_POINT_WIN_0_STRING
0369:                                                        : ASENV_INSERTION_POINT_NOWIN_0_STRING)
0370:                                                        + "=\""
0371:                                                        + getTargetJavaHome()
0372:                                                        + "\"" })); // NOI18N
0373:
0374:                // Step 3
0375:                if (attachSettings.isDirect()) {
0376:                    instructions
0377:                            .addStep(MessageFormat
0378:                                    .format(
0379:                                            INTEGR_REVIEW_STEP3_DIRECT_MSG,
0380:                                            new Object[] {
0381:                                                    SUNAS_8PE_DOMAINSCRIPT_NAME,
0382:                                                    "",
0383:                                                    getProfilerAgentCommandLineArgsForDomainScript(
0384:                                                            targetOS,
0385:                                                            attachSettings
0386:                                                                    .isRemote(),
0387:                                                            attachSettings
0388:                                                                    .getPort()) })); // NOI18N
0389:                } else {
0390:                    instructions.addStep(MessageFormat.format(
0391:                            INTEGR_REVIEW_STEP3_DYNAMIC_MSG,
0392:                            new Object[] { SUNAS_8PE_DOMAINSCRIPT_NAME }));
0393:                }
0394:
0395:                // modified files warning
0396:                instructions.addWarning(MessageFormat.format(
0397:                        RESTORE_SETTINGS_WARNING_MSG, new Object[] {
0398:                                getAsEnvScriptFileName(targetOS),
0399:                                SUNAS_8PE_DOMAINSCRIPT_NAME }));
0400:
0401:                return instructions;
0402:            }
0403:
0404:            public IntegrationProvider.IntegrationHints getModificationHints(
0405:                    AttachSettings attachSettings) {
0406:                IntegrationProvider.IntegrationHints hints = null;
0407:
0408:                if (attachSettings.isRemote()) {
0409:                    hints = getManualRemoteIntegrationStepsInstructions(
0410:                            attachSettings.getHostOS(), attachSettings);
0411:                } else {
0412:                    if (attachSettings.isDirect()) {
0413:                        hints = getManualLocalDirectIntegrationStepsInstructions(
0414:                                attachSettings.getHostOS(), attachSettings);
0415:                    } else {
0416:                        hints = getManualLocalDynamicIntegrationStepsInstructions(
0417:                                attachSettings.getHostOS(), attachSettings);
0418:                    }
0419:                }
0420:
0421:                return hints;
0422:            }
0423:
0424:            public SettingsPersistor getSettingsPersistor() {
0425:                return this .persistor;
0426:            }
0427:
0428:            /**
0429:             * Overrides the modify method of the AbstractScriptIntegrationProvider in order to be able to modify Env script
0430:             */
0431:            public void modify(AttachSettings attachSettings)
0432:                    throws ModificationException {
0433:                String targetOS = attachSettings.getHostOS();
0434:
0435:                try {
0436:                    modifyAsEnvScriptFile(targetOS, attachSettings);
0437:                    super .modify(attachSettings);
0438:                } catch (ScriptModificationException e) {
0439:                    throw new ModificationException(e);
0440:                }
0441:            }
0442:
0443:            public ValidationResult validateInstallation(final String targetOS,
0444:                    final String path) {
0445:                if ((path == null) || (path.length() == 0)
0446:                        || !(new File(path).exists())) {
0447:                    return new ValidationResult(false, MessageFormat.format(
0448:                            ENTER_INSTALL_DIR_MSG, new Object[] { this 
0449:                                    .getTitle() }));
0450:                }
0451:
0452:                String asenv = getAsScriptFilePath(path,
0453:                        SUNAS_8PE_CONFIGDIR_NAME,
0454:                        getAsEnvScriptFileName(targetOS), targetOS);
0455:
0456:                if (!(new File(asenv).exists())) {
0457:                    return new ValidationResult(false, MessageFormat.format(
0458:                            INVALID_INSTALL_DIR_MSG, new Object[] { getTitle(),
0459:                                    getAsEnvScriptFileName(targetOS) }));
0460:                }
0461:
0462:                return new ValidationResult(true);
0463:            }
0464:
0465:            protected boolean isBackupRequired() {
0466:                return true;
0467:            }
0468:
0469:            protected String getDefaultScriptEncoding() {
0470:                return "UTF-8"; // NOI18N // domain.xml must be written in UTF-8 encoding
0471:            }
0472:
0473:            protected ScriptHeaderModifier getHeaderModifier(
0474:                    final String targetOS) {
0475:                ScriptHeaderModifier modifier = new XmlScriptHeaderModifier() {
0476:                    private static final String PROFILER_LINE = "<profiler enabled=\"true\" name=\"NetBeansProfiler\">";
0477:                    private boolean needsProfilerLine = true;
0478:
0479:                    public void lineRead(final StringBuffer line) {
0480:                        super .lineRead(line);
0481:
0482:                        if (needsProfilerLine
0483:                                && (line.indexOf(PROFILER_LINE) != -1)) {
0484:                            needsProfilerLine = false;
0485:                        }
0486:                    }
0487:
0488:                    protected boolean needsWritingHeaders() {
0489:                        return super .needsWritingHeaders() || needsProfilerLine;
0490:                    }
0491:                };
0492:
0493:                modifier.setOptionalHeaders(new String[] {
0494:                        IntegrationUtils.ORIGINAL_BACKUP_LOCATION_STRING, "" }); // NOI18N
0495:
0496:                return modifier;
0497:            }
0498:
0499:            protected abstract int getMagicNumber();
0500:
0501:            protected IntegrationProvider.IntegrationHints getManualLocalDirectIntegrationStepsInstructions(
0502:                    String targetOS, AttachSettings attachSettings) {
0503:                IntegrationProvider.IntegrationHints instructions = new IntegrationProvider.IntegrationHints();
0504:
0505:                // Step 1
0506:                instructions.addStep(MessageFormat.format(
0507:                        MANUAL_DIRECT_DYNAMIC_STEP1_MSG, new Object[] {
0508:                                getAsEnvScriptFileName(targetOS),
0509:                                IntegrationUtils.getEnvVariableReference(
0510:                                        "AS_INSTALL", targetOS),
0511:                                IntegrationUtils
0512:                                        .getDirectorySeparator(targetOS),
0513:                                this .getTitle() })); // NOI18N
0514:
0515:                // Step 2
0516:                instructions
0517:                        .addStep(MessageFormat
0518:                                .format(
0519:                                        MANUAL_DIRECT_DYNAMIC_STEP2_50_MSG,
0520:                                        new Object[] {
0521:                                                IntegrationUtils
0522:                                                        .getJavaPlatformName(getTargetJava()),
0523:                                                getAsEnvScriptFileName(targetOS),
0524:                                                IntegrationUtils
0525:                                                        .isWindowsPlatform(targetOS) ? (IntegrationUtils
0526:                                                        .getExportCommandString(targetOS)
0527:                                                        + " AS_JAVA=" + MessageFormat
0528:                                                        .format(
0529:                                                                PATH_TO_JVM_DIR_TEXT,
0530:                                                                new Object[] { IntegrationUtils
0531:                                                                        .getJavaPlatformName(getTargetJava()) }))
0532:                                                        : ("AS_JAVA=\""
0533:                                                                + MessageFormat
0534:                                                                        .format(
0535:                                                                                PATH_TO_JVM_DIR_TEXT,
0536:                                                                                new Object[] { IntegrationUtils
0537:                                                                                        .getJavaPlatformName(getTargetJava()) }) + "\""),
0538:                                                this .getTitle() })); // NOI18N
0539:
0540:                // Step 3
0541:                instructions.addStep(MessageFormat.format(
0542:                        MANUAL_DIRECT_STEP3_MSG, new Object[] {
0543:                                IntegrationUtils.getEnvVariableReference(
0544:                                        "AS_INSTALL", targetOS),
0545:                                IntegrationUtils
0546:                                        .getDirectorySeparator(targetOS) })); // NOI18N
0547:
0548:                // Step 4
0549:                instructions.addStep(MessageFormat.format(
0550:                        MANUAL_DIRECT_STEP4_MSG, new Object[] {
0551:                                "",
0552:                                getProfilerAgentCommandLineArgsForDomainScript(
0553:                                        targetOS, attachSettings.isRemote(),
0554:                                        attachSettings.getPort()) })); // NOI18N
0555:
0556:                // Step 5
0557:                instructions.addStep(MessageFormat.format(
0558:                        MANUAL_DIRECT_STEP5_MSG, new Object[] {
0559:                                IntegrationUtils.getEnvVariableReference(
0560:                                        "AS_INSTALL", targetOS),
0561:                                IntegrationUtils
0562:                                        .getDirectorySeparator(targetOS) })); // NOI18N
0563:
0564:                // Note about decreasing CPU profiling overhead
0565:                instructions.addHint(REDUCE_OVERHEAD_MSG);
0566:
0567:                instructions.addWarning(MessageFormat.format(
0568:                        DYNAMIC_WARNING_MESSAGE, new Object[] {
0569:                                IntegrationUtils
0570:                                        .getJavaPlatformName(getTargetJava()),
0571:                                IntegrationUtils
0572:                                        .getProfilerAgentCommandLineArgs(
0573:                                                targetOS, getTargetJava(),
0574:                                                attachSettings.isRemote(),
0575:                                                attachSettings.getPort()) }));
0576:
0577:                return instructions;
0578:            }
0579:
0580:            protected IntegrationProvider.IntegrationHints getManualLocalDynamicIntegrationStepsInstructions(
0581:                    String targetOS, AttachSettings attachSettings) {
0582:                IntegrationProvider.IntegrationHints instructions = new IntegrationProvider.IntegrationHints();
0583:
0584:                // Step 1
0585:                instructions.addStep(MessageFormat.format(
0586:                        MANUAL_DIRECT_DYNAMIC_STEP1_MSG, new Object[] {
0587:                                getAsEnvScriptFileName(targetOS),
0588:                                IntegrationUtils.getEnvVariableReference(
0589:                                        "AS_INSTALL", targetOS),
0590:                                IntegrationUtils
0591:                                        .getDirectorySeparator(targetOS),
0592:                                this .getTitle() })); // NOI18N
0593:
0594:                // Step 2
0595:                instructions
0596:                        .addStep(MessageFormat
0597:                                .format(
0598:                                        MANUAL_DIRECT_DYNAMIC_STEP2_50_MSG,
0599:                                        new Object[] {
0600:                                                IntegrationUtils
0601:                                                        .getJavaPlatformName(getTargetJava()),
0602:                                                getAsEnvScriptFileName(targetOS),
0603:                                                IntegrationUtils
0604:                                                        .isWindowsPlatform(targetOS) ? (IntegrationUtils
0605:                                                        .getExportCommandString(targetOS)
0606:                                                        + " AS_JAVA=" + MessageFormat
0607:                                                        .format(
0608:                                                                PATH_TO_JVM_DIR_TEXT,
0609:                                                                new Object[] { IntegrationUtils
0610:                                                                        .getJavaPlatformName(getTargetJava()) }))
0611:                                                        : ("AS_JAVA=\""
0612:                                                                + MessageFormat
0613:                                                                        .format(
0614:                                                                                PATH_TO_JVM_DIR_TEXT,
0615:                                                                                new Object[] { IntegrationUtils
0616:                                                                                        .getJavaPlatformName(getTargetJava()) }) + "\""),
0617:                                                this .getTitle() })); // NOI18N
0618:                // Step 3
0619:
0620:                instructions.addStep(MessageFormat.format(
0621:                        MANUAL_DYNAMIC_STEP3_MSG, new Object[] {
0622:                                IntegrationUtils.getEnvVariableReference(
0623:                                        "AS_INSTALL", targetOS),
0624:                                IntegrationUtils
0625:                                        .getDirectorySeparator(targetOS) })); // NOI18N
0626:
0627:                // Note about decreasing CPU profiling overhead
0628:                instructions.addHint(REDUCE_OVERHEAD_MSG);
0629:
0630:                instructions.addWarning(MessageFormat.format(
0631:                        DYNAMIC_WARNING_MESSAGE, new Object[] {
0632:                                IntegrationUtils
0633:                                        .getJavaPlatformName(getTargetJava()),
0634:                                IntegrationUtils
0635:                                        .getProfilerAgentCommandLineArgs(
0636:                                                targetOS, getTargetJava(),
0637:                                                attachSettings.isRemote(),
0638:                                                attachSettings.getPort()) }));
0639:
0640:                return instructions;
0641:            }
0642:
0643:            // <editor-fold defaultstate="collapsed" desc="Manual integration">
0644:            protected IntegrationProvider.IntegrationHints getManualRemoteIntegrationStepsInstructions(
0645:                    String targetOS, AttachSettings attachSettings) {
0646:                IntegrationProvider.IntegrationHints instructions = new IntegrationProvider.IntegrationHints();
0647:
0648:                // Step 1
0649:                instructions.addStep(getManualRemoteStep1(targetOS));
0650:
0651:                // Step 2
0652:                instructions.addStep(getManualRemoteStep2(targetOS));
0653:
0654:                // Step 3
0655:                instructions.addStep(MessageFormat.format(
0656:                        MANUAL_REMOTE_STEP3_MSG, new Object[] {
0657:                                getAsEnvScriptFileName(targetOS),
0658:                                IntegrationUtils.getEnvVariableReference(
0659:                                        "REMOTE_AS_INSTALL", targetOS),
0660:                                IntegrationUtils
0661:                                        .getDirectorySeparator(targetOS),
0662:                                this .getTitle() })); // NOI18N
0663:
0664:                // Step 4
0665:                instructions
0666:                        .addStep(MessageFormat
0667:                                .format(
0668:                                        MANUAL_REMOTE_STEP4_50_MSG,
0669:                                        new Object[] {
0670:                                                IntegrationUtils
0671:                                                        .getJavaPlatformName(getTargetJava()),
0672:                                                getAsEnvScriptFileName(targetOS),
0673:                                                IntegrationUtils
0674:                                                        .isWindowsPlatform(targetOS) ? (IntegrationUtils
0675:                                                        .getExportCommandString(targetOS)
0676:                                                        + " AS_JAVA=" + MessageFormat
0677:                                                        .format(
0678:                                                                PATH_TO_JVM_DIR_TEXT,
0679:                                                                new Object[] { IntegrationUtils
0680:                                                                        .getJavaPlatformName(getTargetJava()) }))
0681:                                                        : ("AS_JAVA=\""
0682:                                                                + MessageFormat
0683:                                                                        .format(
0684:                                                                                PATH_TO_JVM_DIR_TEXT,
0685:                                                                                new Object[] { IntegrationUtils
0686:                                                                                        .getJavaPlatformName(getTargetJava()) }) + "\""),
0687:                                                this .getTitle() })); // NOI18N
0688:
0689:                // Step 5
0690:                instructions.addStep(MessageFormat.format(
0691:                        MANUAL_REMOTE_STEP5_MSG, new Object[] {
0692:                                IntegrationUtils.getEnvVariableReference(
0693:                                        "REMOTE_AS_INSTALL", targetOS),
0694:                                IntegrationUtils
0695:                                        .getDirectorySeparator(targetOS) })); // NOI18N
0696:
0697:                // Step 6
0698:                instructions
0699:                        .addStep(MessageFormat
0700:                                .format(
0701:                                        MANUAL_REMOTE_STEP6_MSG,
0702:                                        new Object[] {
0703:                                                "",
0704:                                                getProfilerAgentCommandLineArgsForDomainScript(
0705:                                                        targetOS,
0706:                                                        attachSettings
0707:                                                                .isRemote(),
0708:                                                        attachSettings
0709:                                                                .getPort()),
0710:                                                IntegrationUtils
0711:                                                        .getRemoteAbsolutePathHint() })); // NOI18N
0712:
0713:                // Step 7
0714:                instructions.addStep(MessageFormat.format(
0715:                        MANUAL_REMOTE_STEP7_MSG, new Object[] {
0716:                                IntegrationUtils.getEnvVariableReference(
0717:                                        "REMOTE_AS_INSTALL", targetOS),
0718:                                IntegrationUtils
0719:                                        .getDirectorySeparator(targetOS) })); // NOI18N
0720:
0721:                // Note about decreasing CPU profiling overhead
0722:                instructions.addHint(REDUCE_OVERHEAD_MSG);
0723:
0724:                return instructions;
0725:            }
0726:
0727:            protected String getModifiedScriptPath(final String targetOS,
0728:                    final boolean quoted) {
0729:                return getScriptPath(targetOS, quoted);
0730:            }
0731:
0732:            protected String getScriptPath(final String targetOS,
0733:                    final boolean quoted) {
0734:                StringBuffer path = new StringBuffer();
0735:                path.append(getDomainScriptFilePath(targetOS));
0736:
0737:                if (quoted) {
0738:                    path.insert(0, "\"");
0739:                    path.append("\"");
0740:                }
0741:
0742:                return path.toString();
0743:            }
0744:
0745:            protected abstract String getWinSpecificCommandLineArgs(
0746:                    String targetPlatform, boolean isRemote, int portNumber);
0747:
0748:            protected void generateCommands(String targetOS,
0749:                    Collection commandsArray) {
0750:                final String asadminScript = getAsAdminScriptFilePath(targetOS);
0751:                final String domainsDir = getInstallationPath()
0752:                        + IntegrationUtils.getDirectorySeparator(targetOS)
0753:                        + "domains"; // NOI18N
0754:                final String domainName = getDomain();
0755:
0756:                if (IntegrationUtils.isWindowsPlatform(targetOS)) {
0757:                    commandsArray.add("call"); // NOI18N
0758:                    commandsArray.add(asadminScript);
0759:                    commandsArray.add("start-domain"); // NOI18N
0760:                    commandsArray.add("--verbose"); // NOI18N
0761:                    commandsArray.add("--domaindir"); // NOI18N
0762:                    commandsArray.add(domainsDir);
0763:                    commandsArray.add(domainName);
0764:                } else {
0765:                    commandsArray.add(asadminScript);
0766:                    commandsArray.add("start-domain"); // NOI18N
0767:                    commandsArray.add("--verbose"); // NOI18N
0768:                    commandsArray.add("--domaindir"); // NOI18N
0769:                    commandsArray.add(domainsDir);
0770:                    commandsArray.add(domainName);
0771:                }
0772:            }
0773:
0774:            protected void modifyScriptFileForDirectAttach(
0775:                    final String targetOS, final int commPort,
0776:                    final boolean isReplaceFile, final StringBuffer buffer) {
0777:                Document domainScriptDocument = loadDomainScriptFile(buffer);
0778:
0779:                if (domainScriptDocument == null) {
0780:                    return;
0781:                }
0782:
0783:                // Remove any previously defined profiler element(s)
0784:                NodeList profilerElementNodeList = domainScriptDocument
0785:                        .getElementsByTagName("profiler"); // NOI18N
0786:
0787:                if ((profilerElementNodeList != null)
0788:                        && (profilerElementNodeList.getLength() > 0)) {
0789:                    while (profilerElementNodeList.getLength() > 0) {
0790:                        profilerElementNodeList.item(0).getParentNode()
0791:                                .removeChild(profilerElementNodeList.item(0));
0792:                    }
0793:                }
0794:
0795:                //    // Add a comment with Profiler modified file header if modifying fresh file
0796:                //    if (isModified) {
0797:                //      domainScriptDocument.insertBefore(domainScriptDocument.createComment(IntegrationUtils.ORIGINAL_BACKUP_LOCATION_STRING), domainScriptDocument.getFirstChild());
0798:                //      domainScriptDocument.insertBefore(domainScriptDocument.createComment(IntegrationUtils.MODIFIED_FOR_PROFILER_STRING), domainScriptDocument.getFirstChild());
0799:                //    }
0800:
0801:                // Create "profiler" element
0802:                Element profilerElement = domainScriptDocument
0803:                        .createElement("profiler"); // NOI18N
0804:                profilerElement.setAttribute("enabled", "true"); // NOI18N
0805:                profilerElement.setAttribute("name", "NetBeansProfiler"); // NOI18N
0806:
0807:                // Create "jvm-options" element
0808:                Element jvmOptionsElement = domainScriptDocument
0809:                        .createElement("jvm-options"); // NOI18N
0810:                String jvmOptionsElementTextContent = getProfilerAgentCommandLineArgsForDomainScript(
0811:                        targetOS, false, commPort);
0812:
0813:                // debugging property for agent side - wire I/O
0814:                if (System
0815:                        .getProperty("org.netbeans.lib.profiler.wireprotocol.WireIO.agent") != null) { // NOI18N
0816:                    jvmOptionsElementTextContent += " -Dorg.netbeans.lib.profiler.wireprotocol.WireIO=true"; // NOI18N
0817:                    // debugging property for agent side - Class loader hook
0818:                }
0819:
0820:                if (System
0821:                        .getProperty("org.netbeans.lib.profiler.server.ProfilerInterface.classLoadHook") != null) { // NOI18N
0822:                    jvmOptionsElementTextContent += " -Dorg.netbeans.lib.profiler.server.ProfilerInterface.classLoadHook=true"; // NOI18N
0823:                }
0824:
0825:                jvmOptionsElement.setTextContent(jvmOptionsElementTextContent);
0826:                profilerElement.appendChild(jvmOptionsElement);
0827:
0828:                // Find the "java-config" element
0829:                NodeList javaConfigNodeList = domainScriptDocument
0830:                        .getElementsByTagName("java-config"); // NOI18N
0831:
0832:                if ((javaConfigNodeList == null)
0833:                        || (javaConfigNodeList.getLength() == 0)) {
0834:                    //            lastErrorMessage = MessageFormat.format(CANNOT_FIND_JAVACONFIG_MSG, new Object[] {domainScriptFilePath});
0835:                    //            return false;
0836:                    return;
0837:                }
0838:
0839:                // Insert the "profiler" element as a first child of "java-config" element
0840:                Node javaConfigNode = javaConfigNodeList.item(0);
0841:
0842:                if (javaConfigNode.getFirstChild() != null) {
0843:                    javaConfigNode.insertBefore(profilerElement, javaConfigNode
0844:                            .getFirstChild());
0845:                } else {
0846:                    javaConfigNode.appendChild(profilerElement);
0847:                }
0848:
0849:                // Save domain.xml
0850:                saveDomainScriptFile(domainScriptDocument, buffer);
0851:            }
0852:
0853:            protected void modifyScriptFileForDynamicAttach(
0854:                    final String hostOS, final int port,
0855:                    final boolean isReplaceFile, final StringBuffer buffer) {
0856:                Document domainScriptDocument = loadDomainScriptFile(buffer);
0857:
0858:                if (domainScriptDocument == null) {
0859:                    return;
0860:                }
0861:
0862:                // Remove any previously defined profiler element(s)
0863:                NodeList profilerElementNodeList = domainScriptDocument
0864:                        .getElementsByTagName("profiler"); // NOI18N
0865:
0866:                if ((profilerElementNodeList != null)
0867:                        && (profilerElementNodeList.getLength() > 0)) {
0868:                    while (profilerElementNodeList.getLength() > 0) {
0869:                        profilerElementNodeList.item(0).getParentNode()
0870:                                .removeChild(profilerElementNodeList.item(0));
0871:                    }
0872:                }
0873:
0874:                // Save domain.xml
0875:                saveDomainScriptFile(domainScriptDocument, buffer);
0876:            }
0877:
0878:            private static String getAsScriptFilePath(final String installDir,
0879:                    final String specDir, final String scriptName,
0880:                    final String targetOS) {
0881:                final String separator = System.getProperty("file.separator"); // NOI18N
0882:                StringBuffer path = new StringBuffer();
0883:
0884:                path.append(installDir);
0885:
0886:                if (!installDir.endsWith(separator)) {
0887:                    path.append(separator);
0888:                }
0889:
0890:                path.append(specDir).append(separator).append(scriptName);
0891:
0892:                return path.toString();
0893:            }
0894:
0895:            private String getAsAdminScriptFileName(String targetOS) {
0896:                return getAsScriptFile(SUNAS_8PE_ASADMINSCRIPT_NAME, targetOS);
0897:            }
0898:
0899:            private String getAsAdminScriptFilePath(String targetOS) {
0900:                return getAsScriptFilePath(SUNAS_8PE_BINDIR_NAME,
0901:                        getAsAdminScriptFileName(targetOS), targetOS);
0902:            }
0903:
0904:            private String getAsEnvScriptFileName(String targetOS) {
0905:                if (IntegrationUtils.isWindowsPlatform(targetOS)) {
0906:                    return SUNAS_8PE_ASENVSCRIPT_NAME + ".bat"; // NOI18N
0907:                } else {
0908:                    return SUNAS_8PE_ASENVSCRIPT_NAME + ".conf"; // NOI18N
0909:                }
0910:            }
0911:
0912:            private String getAsEnvScriptFilePath(String targetOS) {
0913:                return getAsScriptFilePath(SUNAS_8PE_CONFIGDIR_NAME,
0914:                        getAsEnvScriptFileName(targetOS), targetOS);
0915:            }
0916:
0917:            private String getAsScriptFile(final String scriptName,
0918:                    final String targetOS) {
0919:                if (IntegrationUtils.isWindowsPlatform(targetOS)) {
0920:                    return scriptName + ".bat"; // NOI18N
0921:                }
0922:
0923:                return scriptName + ""; // NOI18N
0924:            }
0925:
0926:            private String getAsScriptFilePath(final String specDir,
0927:                    final String scriptName, final String targetOS) {
0928:                return getAsScriptFilePath(getInstallationPath(), specDir,
0929:                        scriptName, targetOS);
0930:            }
0931:
0932:            private String getDefaultInstallationPath() {
0933:                String home = ""; // NOI18N
0934:
0935:                try {
0936:                    String homeEnv = System.getenv(SUNAS_INSTALL_VAR_STRING); // java.lang.Error: getenv no longer supported exception is thrown on 1.4.2
0937:
0938:                    if ((homeEnv != null) && (homeEnv.length() > 1)) {
0939:                        File homeDir = new File(homeEnv);
0940:
0941:                        if (homeDir.exists() && homeDir.isDirectory()) {
0942:                            home = homeEnv;
0943:                        }
0944:                    } else {
0945:                        homeEnv = System.getenv(SUNAS_HOME_VAR_STRING); // java.lang.Error: getenv no longer supported exception is thrown on 1.4.2
0946:
0947:                        if ((homeEnv != null) && (homeEnv.length() > 1)) {
0948:                            File homeDir = new File(homeEnv);
0949:
0950:                            if (homeDir.exists() && homeDir.isDirectory()) {
0951:                                home = homeEnv;
0952:                            }
0953:                        }
0954:                    }
0955:                } catch (ThreadDeath td) {
0956:                    throw td;
0957:                } catch (Throwable t) { /* IGNORE */
0958:                }
0959:
0960:                return home;
0961:            }
0962:
0963:            private String getDomainScriptDirPath(String targetOS) {
0964:                final String separator = IntegrationUtils
0965:                        .getDirectorySeparator(targetOS);
0966:                StringBuffer path = new StringBuffer();
0967:
0968:                path.append(getInstallationPath());
0969:
0970:                if (!getInstallationPath().endsWith(separator)) {
0971:                    path.append(separator);
0972:                }
0973:
0974:                path.append(SUNAS_8PE_DOMAINSDIR_NAME).append(separator)
0975:                        .append(getDomain());
0976:                path.append(separator).append(SUNAS_8PE_DOMAINCONFIGDIR_NAME);
0977:
0978:                return path.toString();
0979:            }
0980:
0981:            private String getDomainScriptFilePath(String targetOS) {
0982:                final String separator = System.getProperty("file.separator"); // NOI18N
0983:                StringBuffer path = new StringBuffer();
0984:
0985:                path.append(getDomainScriptDirPath(targetOS)).append(separator)
0986:                        .append(SUNAS_8PE_DOMAINSCRIPT_NAME);
0987:
0988:                return path.toString();
0989:            }
0990:
0991:            private String getProfilerAgentCommandLineArgsForDomainScript(
0992:                    String targetOS, boolean isRemote, int portNumber) {
0993:                if (!IntegrationUtils.isWindowsPlatform(targetOS)
0994:                        || (IntegrationUtils.getNativeLibrariesPath(targetOS,
0995:                                getTargetJava(), isRemote).indexOf(' ') == -1)) {
0996:                    return IntegrationUtils
0997:                            .getProfilerAgentCommandLineArgsWithoutQuotes(
0998:                                    targetOS, getTargetJava(), isRemote,
0999:                                    portNumber); // NOI18N
1000:                }
1001:
1002:                return getWinSpecificCommandLineArgs(targetOS, isRemote,
1003:                        portNumber);
1004:            }
1005:
1006:            private Document loadDomainScriptFile(StringBuffer scriptBuffer) {
1007:                Document document = null;
1008:
1009:                try {
1010:                    DocumentBuilderFactory dbFactory = DocumentBuilderFactory
1011:                            .newInstance();
1012:                    dbFactory.setValidating(false);
1013:
1014:                    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
1015:
1016:                    dBuilder.setEntityResolver(new EntityResolver() {
1017:                        public InputSource resolveEntity(String publicId,
1018:                                String systemId) throws SAXException,
1019:                                IOException {
1020:                            StringReader reader = new StringReader(
1021:                                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); // NOI18N
1022:                            InputSource source = new InputSource(reader);
1023:                            scriptPublicId = publicId;
1024:                            scriptSystemId = systemId;
1025:                            source.setPublicId(publicId);
1026:                            source.setSystemId(systemId);
1027:
1028:                            return source;
1029:                        }
1030:                    });
1031:
1032:                    StringReader scriptReader = new StringReader(scriptBuffer
1033:                            .toString());
1034:                    InputSource scriptSource = new InputSource(scriptReader);
1035:
1036:                    return document = dBuilder.parse(scriptSource);
1037:                } catch (Exception e) {
1038:                    return null;
1039:                }
1040:            }
1041:
1042:            private void modifyAsEnvScriptFile(final String targetOS,
1043:                    final AttachSettings attachSettings)
1044:                    throws ScriptModificationException {
1045:                final String asJavaString = (IntegrationUtils
1046:                        .isWindowsPlatform(targetOS) ? ASENV_INSERTION_POINT_WIN_0_STRING
1047:                        : ASENV_INSERTION_POINT_NOWIN_0_STRING);
1048:
1049:                this 
1050:                        .modifyScript(
1051:                                getAsEnvScriptFilePath(targetOS),
1052:                                new ProfilerScriptModifier(
1053:                                        new TextScriptHeaderModifier(
1054:                                                IntegrationUtils
1055:                                                        .getSilentScriptCommentSign(targetOS))) {
1056:                                    boolean insertionFound = false;
1057:                                    int insertionIndex = -1;
1058:
1059:                                    public void onModification(
1060:                                            final AttachSettings attachSettings,
1061:                                            final String lineBreak,
1062:                                            StringBuffer scriptBuffer)
1063:                                            throws ScriptModificationException {
1064:                                    }
1065:
1066:                                    public void onLineRead(
1067:                                            final StringBuffer line)
1068:                                            throws ScriptModificationException {
1069:                                        if (line.toString().trim().startsWith(
1070:                                                asJavaString)) {
1071:                                            line.delete(0, line.length());
1072:                                            //          line.append(asJavaString).append("=\"").append(targetJavaHomePath).append("\""); // NOI18N
1073:                                            line.append(asJavaString).append(
1074:                                                    "=").append(
1075:                                                    getTargetJavaHome()); // NOI18N
1076:                                        }
1077:                                    }
1078:                                }, attachSettings);
1079:            }
1080:
1081:            private void saveDomainScriptFile(
1082:                    final Document domainScriptDocument,
1083:                    final StringBuffer scriptBuffer) {
1084:                try {
1085:                    StringWriter stringWriter = new StringWriter();
1086:                    TransformerFactory transformerFactory = TransformerFactory
1087:                            .newInstance();
1088:                    Transformer transformer = transformerFactory
1089:                            .newTransformer();
1090:                    transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // NOI18N
1091:                    transformer.setOutputProperty(OutputKeys.METHOD, "xml"); // NOI18N
1092:                    transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
1093:                            scriptPublicId);
1094:                    transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
1095:                            scriptSystemId);
1096:                    transformer.setOutputProperty(
1097:                            OutputKeys.OMIT_XML_DECLARATION, "no"); // NOI18N
1098:
1099:                    DOMSource domSource = new DOMSource(domainScriptDocument);
1100:                    StreamResult streamResult = new StreamResult(stringWriter);
1101:
1102:                    transformer.transform(domSource, streamResult);
1103:
1104:                    if (stringWriter.getBuffer().length() > 0) {
1105:                        scriptBuffer.delete(0, scriptBuffer.length());
1106:                        scriptBuffer.append(stringWriter.getBuffer());
1107:                    }
1108:                } catch (Exception e) {
1109:                    e.printStackTrace();
1110:                }
1111:            }
1112:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.