Index: apichanges.xml =================================================================== RCS file: /cvs/j2eeserver/apichanges.xml,v retrieving revision 1.36 diff -u -r1.36 apichanges.xml --- apichanges.xml 4 Oct 2007 07:43:47 -0000 1.36 +++ apichanges.xml 19 Nov 2007 15:44:58 -0000 @@ -109,6 +109,28 @@ + + + + Adding InstanceProperties.createInstanceProperties(String, String, + String, String, Map<String, String>) method. + + + + + + +

+ The InstanceProperties.createInstanceProperties(String, String, String, String) + method does not provide any way how to pass other initial properties + required by the plugin. This is usually needed and workarounded + in many plugins. New method provides additional parameter containing + the any plugin required properties. +

+
+ + +
Index: src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java,v retrieving revision 1.55 diff -u -r1.55 ServerRegistry.java --- src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java 4 Oct 2007 07:44:19 -0000 1.55 +++ src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java 19 Nov 2007 15:44:58 -0000 @@ -292,11 +292,18 @@ * @param username username used by the deployment manager. * @param password password used by the deployment manager. * @param displayName display name wich represents server instance in IDE. + * @param initialProperties any other properties to set during the instance creation. + * If the map contains any of InstanceProperties.URL_ATTR, + * InstanceProperties.USERNAME_ATTR, InstanceProperties.PASSWORD_ATTR + * or InstanceProperties.DISPLAY_NAME_ATTR they will be ignored + * - the explicit parameter values are always used. + * null is accepted. + * * @throws InstanceCreationException when instance with same url is already * registered. */ public void addInstance(String url, String username, String password, - String displayName) throws InstanceCreationException { + String displayName, Map initialproperties) throws InstanceCreationException { // should never have empty url; UI should have prevented this if (url == null || url.equals("")) { //NOI18N Logger.getLogger("global").log(Level.INFO, NbBundle.getMessage(ServerRegistry.class, "MSG_EmptyUrl")); @@ -304,7 +311,7 @@ } checkInstanceAlreadyExists(url); - if (!addInstanceImpl(url, username, password, displayName)) { + if (!addInstanceImpl(url, username, password, displayName, initialproperties)) { throw new InstanceCreationException(NbBundle.getMessage(ServerRegistry.class, "MSG_FailedToCreateInstance", displayName)); } } @@ -344,17 +351,28 @@ /** * Add a new server instance in the server registry. * - * @param url URL to access deployment manager. - * @param username username used by the deployment manager. - * @param password password used by the deployment manager. - * @param displayName display name wich represents server instance in IDE. + * @param url URL to access deployment manager. + * @param username username used by the deployment manager. + * @param password password used by the deployment manager. + * @param displayName display name wich represents server instance in IDE. + * @param initialProperties any other properties to set during the instance creation. + * If the map contains any of InstanceProperties.URL_ATTR, + * InstanceProperties.USERNAME_ATTR, InstanceProperties.PASSWORD_ATTR + * or InstanceProperties.DISPLAY_NAME_ATTR they will be ignored + * - the explicit parameter values are always used. + * null is accepted. * * @return true if the server instance was created successfully, - * false otherwise. + * false otherwise. */ - private synchronized boolean addInstanceImpl(String url, String username, - String password, String displayName) { - if (instancesMap().containsKey(url)) return false; + private synchronized boolean addInstanceImpl(String url, String username, + String password, String displayName, Map initialProperties) { + if (instancesMap().containsKey(url)) { + return false; + } + + Map properties = cleanInitialProperties(initialProperties); + for (Iterator i = serversMap().values().iterator(); i.hasNext();) { Server server = (Server) i.next(); try { @@ -366,8 +384,15 @@ // whether the instance is not corrupted - see #46929 ServerString str = new ServerString(server.getShortName(),url,null); writeInstanceToFile(url,username,password); - if (displayName != null) instance.getInstanceProperties().setProperty( + if (displayName != null) { + instance.getInstanceProperties().setProperty( InstanceProperties.DISPLAY_NAME_ATTR, displayName); + } + + for (Map.Entry entry : properties.entrySet()) { + instance.getInstanceProperties().setProperty(entry.getKey(), entry.getValue()); + } + DeploymentManager manager = server.getDisconnectedDeploymentManager(url); if (manager != null) { fireInstanceListeners(url, true); @@ -387,6 +412,19 @@ } return false; } + + private Map cleanInitialProperties(Map initialProperties) { + if (initialProperties == null) { + return Collections.emptyMap(); + } + + Map properties = new HashMap(initialProperties); + properties.remove(InstanceProperties.URL_ATTR); + properties.remove(InstanceProperties.USERNAME_ATTR); + properties.remove(InstanceProperties.PASSWORD_ATTR); + properties.remove(InstanceProperties.DISPLAY_NAME_ATTR); + return properties; + } public void addInstance(FileObject fo) { String url = (String) fo.getAttribute(URL_ATTR); @@ -394,7 +432,7 @@ String password = (String) fo.getAttribute(PASSWORD_ATTR); String displayName = (String) fo.getAttribute(InstanceProperties.DISPLAY_NAME_ATTR); // System.err.println("Adding instance " + fo); - addInstanceImpl(url, username, password, displayName); + addInstanceImpl(url, username, password, displayName, null); } public Collection getInstances(InstanceListener il) { Index: src/org/netbeans/modules/j2ee/deployment/plugins/api/InstanceProperties.java =================================================================== RCS file: /cvs/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/api/InstanceProperties.java,v retrieving revision 1.22 diff -u -r1.22 InstanceProperties.java --- src/org/netbeans/modules/j2ee/deployment/plugins/api/InstanceProperties.java 4 Oct 2007 07:44:41 -0000 1.22 +++ src/org/netbeans/modules/j2ee/deployment/plugins/api/InstanceProperties.java 19 Nov 2007 15:44:58 -0000 @@ -180,13 +180,40 @@ */ public static InstanceProperties createInstanceProperties(String url, String username, String password, String displayName) throws InstanceCreationException { + + return createInstanceProperties(url, username, password, displayName, null); + } + + /** + * Create new instance and returns instance properties for the server instance. + * + * @param url the url connection string to get the instance deployment manager. + * @param username username which is used by the deployment manager. + * @param password password which is used by the deployment manager. + * @param displayName display name which is used by IDE to represent this + * server instance. + * @param initialProperties any other properties to set during the instance creation. + * If the map contains any of InstanceProperties.URL_ATTR, + * InstanceProperties.USERNAME_ATTR, InstanceProperties.PASSWORD_ATTR + * or InstanceProperties.DISPLAY_NAME_ATTR they will be ignored + * - the explicit parameter values are always used. + * null is accepted. + * + * @return the InstanceProperties object, null if + * instance does not exists. + * @exception InstanceCreationException when instance with same url already + * registered. + * @since 1.34.0 + */ + public static InstanceProperties createInstanceProperties(String url, String username, + String password, String displayName, Map initialProperties) throws InstanceCreationException { ServerRegistry registry = ServerRegistry.getInstance(); - registry.addInstance(url, username, password, displayName); + registry.addInstance(url, username, password, displayName, initialProperties); ServerInstance inst = registry.getServerInstance(url); InstanceProperties ip = inst.getInstanceProperties(); return ip; } - + /** * Returns list of URL strings of all registered instances * @return array of URL strings Index: test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstanceTest.java =================================================================== RCS file: /cvs/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstanceTest.java,v retrieving revision 1.6 diff -u -r1.6 ServerInstanceTest.java --- test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstanceTest.java 4 Oct 2007 07:45:00 -0000 1.6 +++ test/unit/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstanceTest.java 19 Nov 2007 15:44:58 -0000 @@ -69,7 +69,7 @@ // setup ServerRegistry registry = ServerRegistry.getInstance(); String url = "fooservice:testStartStopInstance"; - registry.addInstance(url, "user", "password", "TestInstance"); + registry.addInstance(url, "user", "password", "TestInstance", null); ServerInstance instance = registry.getServerInstance(url); ServerTarget target = instance.getServerTarget("Target 1"); Index: test/unit/src/org/netbeans/modules/j2ee/deployment/impl/TargetServerTest.java =================================================================== RCS file: /cvs/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/impl/TargetServerTest.java,v retrieving revision 1.7 diff -u -r1.7 TargetServerTest.java --- test/unit/src/org/netbeans/modules/j2ee/deployment/impl/TargetServerTest.java 4 Oct 2007 07:45:01 -0000 1.7 +++ test/unit/src/org/netbeans/modules/j2ee/deployment/impl/TargetServerTest.java 19 Nov 2007 15:44:58 -0000 @@ -85,7 +85,7 @@ if (name != null) url += "_"+name; try { - registry.addInstance(url, "user", "password", "TestInstance"); + registry.addInstance(url, "user", "password", "TestInstance", null); } catch (IOException ioe) { throw new RuntimeException(ioe); } server = new ServerString(registry.getServerInstance(url).getServerTarget("Target 1"));