KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > profiler > api > ProfilerServerSettings


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.deployment.profiler.api;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.api.java.platform.JavaPlatform;
25 import org.openide.filesystems.FileObject;
26 import org.openide.filesystems.FileUtil;
27
28 /**
29  * Settings that will be used for profiled server startup.
30  *
31  * @author sherold
32  */

33 public final class ProfilerServerSettings {
34
35     private JavaPlatform javaPlatform;
36     private String JavaDoc[] jvmArgs;
37     private String JavaDoc[] env;
38
39     /**
40      * Creates new ProfilerServerSettings.
41      *
42      * @param javaPlatform Java platform used to run profiled server.
43      * @param jvmArgs array of extra JVM arguments used for starting profiled
44      * server.
45      * @param env array of <code>name=value</code> pairs of extra variables
46      * to be set for profiled server environment.
47      */

48     public ProfilerServerSettings(JavaPlatform javaPlatform, String JavaDoc[] jvmArgs, String JavaDoc[] env) {
49         if (javaPlatform == null) {
50             throw new NullPointerException JavaDoc("The javaPlatform argument must not be null."); // NOI18N
51
}
52         if (jvmArgs == null) {
53             throw new NullPointerException JavaDoc("The jvmArgs argument must not be null."); // NOI18N
54
}
55         if (env == null) {
56             throw new NullPointerException JavaDoc("The env argument must not be null."); // NOI18N
57
}
58         this.javaPlatform = javaPlatform;
59         this.jvmArgs = jvmArgs;
60         this.env = env;
61     }
62
63     /**
64      * Gets the Java platform that will be used for starting the profiled server.
65      *
66      * @return Java platform that will be used for starting the profiled server.
67      */

68     public JavaPlatform getJavaPlatform() {
69         return javaPlatform;
70     }
71
72     /**
73      * Gets the extra arguments that will be used for starting the profiled server.
74      *
75      * @return array of extra arguments that will be used for starting the profiled
76      * server
77      */

78     public String JavaDoc[] getJvmArgs() {
79         return jvmArgs;
80     }
81
82     /**
83      * Gets extra variables that will be set for profiled server environment.
84      *
85      * @return array of <code>name=value</code> pairs describing extra variables
86      * that will be set for profiled server environment
87      */

88     public String JavaDoc[] getEnv() {
89         return env;
90     }
91     
92     /**
93      * Tests this ProfilerServerSettings for equality with the given object.
94      *
95      * @param o The object to be compared with this ProfilerServerSettings.
96      *
97      * @return <code>true</code> if the other ProfilerServerSettings instance
98      * defines the same settings; false otherwise.
99      */

100     public boolean equals(Object JavaDoc o) {
101         if (o == this) {
102         return true;
103     }
104         if (!(o instanceof ProfilerServerSettings)) {
105             return false;
106         }
107         ProfilerServerSettings other = (ProfilerServerSettings)o;
108         FileObject javaHome = (FileObject)javaPlatform.getInstallFolders().iterator().next();
109         FileObject otherJavaHome = (FileObject)other.javaPlatform.getInstallFolders().iterator().next();
110         if (!FileUtil.toFile(javaHome).equals(FileUtil.toFile(otherJavaHome))) {
111             return false;
112         }
113         if (jvmArgs.length != other.jvmArgs.length) {
114             return false;
115         }
116         List JavaDoc jvmArgsList = Arrays.asList(jvmArgs);
117         for (int i = 0; i < other.jvmArgs.length; i++) {
118             if (!jvmArgsList.contains(other.jvmArgs[i])) {
119                 return false;
120             }
121         }
122         if (env.length != other.env.length) {
123             return false;
124         }
125         List JavaDoc envList = Arrays.asList(env);
126         for (int i = 0; i < other.env.length; i++) {
127             if (!envList.contains(other.env[i])) {
128                 return false;
129             }
130         }
131         return true;
132     }
133     
134     public int hashCode() {
135         int result = 17;
136         FileObject javaHome = (FileObject)javaPlatform.getInstallFolders().iterator().next();
137         result = 37 * result + FileUtil.toFile(javaHome).hashCode();
138         String JavaDoc[] jvmArgsTmp = (String JavaDoc[])jvmArgs.clone();
139         Arrays.sort(jvmArgsTmp);
140         for (int i = 0; i < jvmArgsTmp.length; i++) {
141             result = 37 * result + jvmArgsTmp[i].hashCode();
142         }
143         String JavaDoc[] envTmp = (String JavaDoc[])env.clone();
144         Arrays.sort(envTmp);
145         for (int i = 0; i < envTmp.length; i++) {
146             result = 37 * result + envTmp[i].hashCode();
147         }
148         return result;
149     }
150     
151     public String JavaDoc toString() {
152         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
153         buffer.append("ProfilerServerSettings [\n"); // NOI18N
154
buffer.append(" javaPlatform: " + javaPlatform.getDisplayName() + "\n"); // NOI18N
155
buffer.append(" jvmarg: "); // NOI18N // NOI18N
156
for (int i = 0; i < jvmArgs.length; i++) {
157             buffer.append(jvmArgs[i] + " "); // NOI18N
158
}
159         buffer.append("\n"); // NOI18N
160
buffer.append(" env: "); // NOI18N
161
for (int i = 0; i < env.length; i++) {
162             buffer.append(env[i] + " "); // NOI18N
163
}
164         buffer.append("]"); // NOI18N
165
return buffer.toString();
166     }
167 }
168
Popular Tags