KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > Installer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.ide;
21
22 import java.io.File JavaDoc;
23 import javax.enterprise.deploy.spi.factories.DeploymentFactory JavaDoc;
24 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
25 import org.netbeans.modules.j2ee.sun.api.ServerLocationManager;
26 import org.netbeans.modules.j2ee.sun.ide.j2ee.ui.DomainCreator;
27 import org.netbeans.modules.j2ee.sun.ide.j2ee.PluginProperties;
28 import org.openide.modules.ModuleInstall;
29 import org.openide.util.NbPreferences;
30 import org.openide.windows.WindowManager;
31
32 public class Installer extends ModuleInstall {
33     
34     private static DeploymentFactory JavaDoc facadeDF = null;
35     
36     private static final String JavaDoc PROP_FIRST_RUN = "first_run";
37     
38     /** Factory method to create DeploymentFactory for s1as.
39      */

40     public static synchronized Object JavaDoc create() {
41         if (facadeDF == null){
42             //this is our JSR88 factory lazy init, only when needed via layer.
43
PluginProperties.configureDefaultServerInstance();
44             facadeDF = new org.netbeans.modules.j2ee.sun.ide.dm.SunDeploymentFactory();
45         }
46         return facadeDF;
47     }
48     
49     public void restored() {
50         WindowManager.getDefault().invokeWhenUIReady(new PrepareEnvironment());
51     }
52         
53     public void close() {
54     }
55     
56     public void uninstalled() {
57     }
58     
59     private static class PrepareEnvironment implements Runnable JavaDoc {
60         public void run() {
61             // if the domain hasn't been created successfully previously
62
if (!NbPreferences.forModule(DomainCreator.class).getBoolean(PROP_FIRST_RUN, false)) {
63                 String JavaDoc prop = System.getProperty(ServerLocationManager.INSTALL_ROOT_PROP_NAME);
64                 
65                 if (null != prop && prop.trim().length() > 0) {
66                     // There is a possible root directory for the AS
67
File JavaDoc propFile = new File JavaDoc(prop);
68                     ClassLoader JavaDoc cl = ServerLocationManager.getNetBeansAndServerClassLoader(propFile);
69                     if (null != cl && !propFile.canWrite()) {
70                         createDomainAndRecord(propFile);
71                     }
72                 }
73             }
74         }
75     }
76
77     static private void createDomainAndRecord(final File JavaDoc propFile) {
78         // The root directory is valid
79
// Domain can be created
80
InstanceProperties ip = DomainCreator.createPersonalDefaultDomain(propFile.getAbsolutePath());
81             // Sets domain creation performed flag to true
82
NbPreferences.forModule(DomainCreator.class).putBoolean(PROP_FIRST_RUN, true);
83     }
84 }
85
Popular Tags