#217956 - UI Element / User-extensions are not configurable via Selenium Server Configuartion
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * If you wish your version of this file to be governed by only the CDDL
25 * or only the GPL Version 2, indicate your decision by adding
26 * "[Contributor] elects to include this software in this distribution
27 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28 * single choice of license, a recipient has the option to distribute
29 * your version of this file under either the CDDL, the GPL Version 2 or
30 * to extend the choice of license to its licensees as provided above.
31 * However, if you add GPL Version 2 code and therefore, elected the GPL
32 * Version 2 license, then the option applies only if the new code is
33 * made subject to such option by the copyright holder.
37 * Portions Copyrighted 2009 Sun Microsystems, Inc.
39 package org.netbeans.modules.selenium.server;
41 import java.beans.PropertyChangeEvent;
42 import java.lang.reflect.InvocationTargetException;
43 import java.net.URLClassLoader;
44 import java.util.List;
45 import java.util.logging.Level;
46 import java.util.logging.Logger;
47 import org.netbeans.api.server.properties.InstanceProperties;
48 import org.netbeans.api.server.properties.InstancePropertiesManager;
49 import org.openide.nodes.Node;
50 import org.openide.nodes.Node.Property;
51 import org.openide.nodes.Sheet;
52 import org.openide.nodes.Sheet.Set;
53 import org.openide.util.NbBundle;
57 * @author Jindrich Sedek
58 * @author Martin Fousek
60 public class SeleniumProperties {
62 private static Logger LOGGER = Logger.getLogger(SeleniumProperties.class.getName());
64 public static int seleniumDefaultPort = -1;
65 public static final String PORT = "Port"; //NOI18N
66 public static final String START_ON_STARTUP = "Startup"; //NOI18N
67 public static final String FIREFOX_PROFILE = "FirefoxProfile"; //NOI18N
68 public static final String SINGLE_WINDOW = "SingleWindow"; //NOI18N
69 public static final String USER_EXTENSIONS = "UserExtensions"; //NOI18N
71 private static InstanceProperties instanceProps;
72 private static final String NAMESPACE = "Selenium server properties namespace"; //NOI18N
74 static Sheet createSheet() {
75 InstanceProperties props = getInstanceProperties();
76 Sheet sheet = Sheet.createDefault();
77 Set set = sheet.get(Sheet.PROPERTIES);
78 set.put(new ServerIntProperty(PORT, props));
79 set.put(new ServerBoolProperty(START_ON_STARTUP, props));
80 set.put(new ServerStringProperty(FIREFOX_PROFILE, props));
81 set.put(new ServerBoolProperty(SINGLE_WINDOW, props));
82 set.put(new ServerStringProperty(USER_EXTENSIONS, props));
87 * Gets the default server port contained in the Selenium server configuration.
88 * @return default Selenium server port
90 public static int getSeleniumDefaultPort() {
91 if (seleniumDefaultPort == -1) {
93 URLClassLoader urlClassLoader = SeleniumServerRunner.getSeleniumServerClassLoader();
94 Class remoteControlConfiguration = urlClassLoader.loadClass(
95 "org.openqa.selenium.server.RemoteControlConfiguration"); //NOI18N
96 seleniumDefaultPort = remoteControlConfiguration.getDeclaredField(
97 "DEFAULT_PORT").getInt(remoteControlConfiguration); //NOI18N
98 } catch (NoSuchFieldException ex) {
99 LOGGER.log(Level.SEVERE, null, ex);
100 } catch (SecurityException ex) {
101 LOGGER.log(Level.SEVERE, null, ex);
102 } catch (IllegalArgumentException ex) {
103 LOGGER.log(Level.SEVERE, null, ex);
104 } catch (IllegalAccessException ex) {
105 LOGGER.log(Level.SEVERE, null, ex);
106 } catch (ClassNotFoundException ex) {
107 LOGGER.log(Level.SEVERE, null, ex);
110 return seleniumDefaultPort;
113 public static InstanceProperties getInstanceProperties(){
114 if (instanceProps == null){
115 InstancePropertiesManager manager = InstancePropertiesManager.getInstance();
116 synchronized (NAMESPACE){
117 List<InstanceProperties> allProps = manager.getProperties(NAMESPACE);
118 if (!allProps.isEmpty()) {
119 instanceProps = allProps.iterator().next();
121 instanceProps = manager.createProperties(NAMESPACE);
122 instanceProps.putInt(PORT, getSeleniumDefaultPort());
123 instanceProps.putBoolean(START_ON_STARTUP, true);
124 instanceProps.putString(FIREFOX_PROFILE, ""); //NOI18N
125 instanceProps.putBoolean(SINGLE_WINDOW, false);
126 instanceProps.putString(USER_EXTENSIONS, ""); //NOI18N
127 allProps.add(instanceProps);
131 return instanceProps;
134 private static final class ServerBoolProperty extends ServerProperty<Boolean> {
136 public ServerBoolProperty(String propertyName, InstanceProperties props) {
137 super(Boolean.class, propertyName, props);
141 public Boolean getValue() throws IllegalAccessException, InvocationTargetException {
142 return props.getBoolean(getName(), true);
146 public void setValue(Boolean val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
147 Boolean oldValue = getValue();
148 if (oldValue.equals(val)){
151 props.putBoolean(getName(), val);
156 private static final class ServerIntProperty extends ServerProperty<Integer> {
158 public ServerIntProperty(String propertyName, InstanceProperties props) {
159 super(Integer.class, propertyName, props);
163 public Integer getValue() throws IllegalAccessException, InvocationTargetException {
164 return props.getInt(getName(), 0);
168 protected void writeNewValue(Integer val) {
169 props.putInt(getName(), val);
174 private static final class ServerStringProperty extends ServerProperty<String> {
176 public ServerStringProperty(String propertyName, InstanceProperties props) {
177 super(String.class, propertyName, props);
181 public String getValue() throws IllegalAccessException, InvocationTargetException {
182 return props.getString(getName(), ""); //NOI18N
186 protected void writeNewValue(String val) {
187 props.putString(getName(), val);
192 private static abstract class ServerProperty<T> extends Node.Property<T>{
194 protected InstanceProperties props;
196 public ServerProperty(Class<T> type, String propertyName, InstanceProperties props) {
199 setName(propertyName);
200 setDisplayName(NbBundle.getMessage(SeleniumProperties.class, "displayName_" + propertyName));
201 setShortDescription(NbBundle.getMessage(SeleniumProperties.class, "desc_" + propertyName));
205 public boolean canRead() {
210 public boolean canWrite() {
215 public void setValue(T val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
216 T oldValue = getValue();
217 if (oldValue.equals(val)){
221 PropertyChangeEvent evt = new PropertyChangeEvent(this, getName(), oldValue, val);
222 SeleniumServerRunner.getPropertyChangeListener().propertyChange(evt);
225 protected void writeNewValue(T val){}