KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > util > OC4JPluginProperties


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.oc4j.util;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.InetSocketAddress JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26 import java.net.Socket JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30 import org.netbeans.api.java.platform.JavaPlatform;
31 import org.netbeans.api.java.platform.JavaPlatformManager;
32 import org.netbeans.api.java.platform.Specification;
33 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
34 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentManager;
35 import org.netbeans.modules.j2ee.oc4j.customizer.OC4JCustomizerSupport;
36 import org.openide.ErrorManager;
37 import org.openide.filesystems.FileUtil;
38 import org.openide.modules.InstalledFileLocator;
39
40 /**
41  * @author pblaha
42  */

43 public class OC4JPluginProperties {
44     
45     public static final String JavaDoc PROPERTY_DISPLAY_NAME = InstanceProperties.DISPLAY_NAME_ATTR;
46     public static final String JavaDoc PROPERTY_ADMIN_PORT = "adminPort"; //NOI18N
47
public static final String JavaDoc PROPERTY_WEB_SITE = "webSite"; //NOI18N
48
public static final String JavaDoc PROPERTY_OC4J_HOME = "oc4jHome"; //NOI18N
49
public static final String JavaDoc PROPERTY_HOST = "host"; //NOI18N
50
public static final String JavaDoc PROP_JAVA_PLATFORM = "java_platform"; //NOI18N
51
public static final String JavaDoc PROP_JAVADOCS = "javadocs"; // NOI18N
52
public static final String JavaDoc PLAT_PROP_ANT_NAME = "platform.ant.name"; //NOI18N
53

54     private InstanceProperties ip;
55     private OC4JDeploymentManager dm;
56     
57     private static final int DEBUGPORT = 8787;
58     
59     public OC4JPluginProperties(OC4JDeploymentManager dm) {
60         this.dm = dm;
61         ip = InstanceProperties.getInstanceProperties(dm.getUri());
62     }
63     
64     public String JavaDoc getOC4JHomeLocation() {
65         return ip.getProperty(PROPERTY_OC4J_HOME);
66     }
67     
68     public JavaPlatform getJavaPlatform() {
69         String JavaDoc currentJvm = ip.getProperty(PROP_JAVA_PLATFORM);
70         JavaPlatformManager jpm = JavaPlatformManager.getDefault();
71         JavaPlatform[] installedPlatforms = jpm.getPlatforms(null, new Specification("J2SE", null)); // NOI18N
72
for (int i = 0; i < installedPlatforms.length; i++) {
73             String JavaDoc platformName = (String JavaDoc)installedPlatforms[i].getProperties().get(PLAT_PROP_ANT_NAME);
74             if (platformName != null && platformName.equals(currentJvm)) {
75                 return installedPlatforms[i];
76             }
77         }
78         // return default platform if none was set
79
return jpm.getDefaultPlatform();
80     }
81     
82     public InstanceProperties getInstanceProperties() {
83         return ip;
84     }
85     
86     public List JavaDoc<URL JavaDoc> getClasses() {
87         List JavaDoc<URL JavaDoc> list = new ArrayList JavaDoc<URL JavaDoc>();
88         File JavaDoc serverDir = new File JavaDoc(getOC4JHomeLocation());
89         try{
90             for(File JavaDoc file:new File JavaDoc(serverDir, "j2ee/home/applib").listFiles()) {
91                 if(FileUtil.isArchiveFile(file.toURI().toURL()))
92                     list.add(OC4JPluginUtils.fileToUrl(file));
93             }
94             for(File JavaDoc file:new File JavaDoc(serverDir, "j2ee/home/lib").listFiles()) {
95                 if(FileUtil.isArchiveFile(file.toURI().toURL()))
96                     list.add(OC4JPluginUtils.fileToUrl(file));
97             }
98             for(File JavaDoc file:new File JavaDoc(serverDir, "lib").listFiles()) {
99                 if(FileUtil.isArchiveFile(file.toURI().toURL()))
100                     list.add(OC4JPluginUtils.fileToUrl(file));
101             }
102             for(File JavaDoc file:new File JavaDoc(serverDir, "webservices/lib").listFiles()) {
103                 if(FileUtil.isArchiveFile(file.toURI().toURL()))
104                     list.add(OC4JPluginUtils.fileToUrl(file));
105             }
106             for(File JavaDoc file:new File JavaDoc(serverDir, "toplink/jlib").listFiles()) {
107                 if(FileUtil.isArchiveFile(file.toURI().toURL()))
108                     list.add(OC4JPluginUtils.fileToUrl(file));
109             }
110         } catch(MalformedURLException JavaDoc ex) {
111             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
112         }
113         return list;
114     }
115     
116     public List JavaDoc<URL JavaDoc> getJavadocs() {
117         String JavaDoc path = ip.getProperty(PROP_JAVADOCS);
118         if (path == null) {
119             ArrayList JavaDoc<URL JavaDoc> list = new ArrayList JavaDoc<URL JavaDoc>();
120             try {
121                 File JavaDoc j2eeDoc = InstalledFileLocator.getDefault().locate("docs/javaee5-doc-api.zip", null, false); // NOI18N
122
if (j2eeDoc != null) {
123                     list.add(OC4JPluginUtils.fileToUrl(j2eeDoc));
124                 }
125             } catch (MalformedURLException JavaDoc e) {
126                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
127             }
128             return list;
129         }
130         return OC4JCustomizerSupport.tokenizePath(path);
131     }
132     
133     public void setJavadocs(List JavaDoc<URL JavaDoc> path) {
134         ip.setProperty(PROP_JAVADOCS, OC4JCustomizerSupport.buildPath(path));
135         dm.getOC4JPlatform().notifyLibrariesChanged();
136     }
137     
138     public int getDebugPort() {
139         return DEBUGPORT;
140     }
141     
142     public static boolean isRunning(String JavaDoc host, int port) {
143         if(null == host)
144             return false;
145         
146         try {
147             InetSocketAddress JavaDoc isa = new InetSocketAddress JavaDoc(host, port);
148             Socket JavaDoc socket = new Socket JavaDoc();
149             socket.connect(isa, 1);
150             socket.close();
151             return true;
152         } catch (IOException JavaDoc e) {
153             return false;
154         }
155     }
156     
157     public static boolean isRunning(String JavaDoc host, String JavaDoc port) {
158         try {
159             return isRunning(host, Integer.parseInt(port));
160         } catch(NumberFormatException JavaDoc e) {
161             if(OC4JDebug.isEnabled()) {
162                 OC4JDebug.log("org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties", "HOST: " + host);
163                 OC4JDebug.log("org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties", "PORT: " + port);
164             }
165             return false;
166         }
167     }
168 }
Popular Tags