+ Added class ProxyDeploymentFactory which delegates all calls + to configured delegate. Via urlPattern it is possible to do + precheck of server instance uri. The uri has to mach the pattern + otherwise the instance is rejected as not supported but + the factory. +
++ Designed to be used from XML Layer. +
++ There are two separate api/spi sets in j2eeserver. The devmodules + api/spi is for j2ee development modules (web, j2ee app, etc). The + plugins api/spi is for server plugins. +
+ +urlPattern
attribute as precheck for url the plugin
+ * can handle. Designed to be used via XML layer filesystem.
+ *
+ * The urlPattern
attribute is expected to be regexp string.
+ * If it is present the server instance uri must match the regexp otherwise
+ * {@link #handlesURI(java.lang.String)} will automatically return false
+ * (before querying the delegate).
+ *
+ * @author Petr Hejl
+ */
+public final class ProxyDeploymentFactory implements DeploymentFactory {
+
+ private final Map attributes;
+
+ private final Pattern urlPattern;
+
+ private DeploymentFactory delegate;
+
+ private ProxyDeploymentFactory(Map attributes) {
+ this.attributes = attributes;
+
+ String pattern = (String) attributes.get("urlPattern"); // NOI18N
+ if (pattern != null) {
+ urlPattern = Pattern.compile(pattern);
+ } else {
+ urlPattern = null;
+ }
+ }
+
+ public static ProxyDeploymentFactory create(Map map) {
+ return new ProxyDeploymentFactory(map);
+ }
+
+ @Override
+ public boolean handlesURI(String string) {
+ if (string == null) {
+ return false;
+ }
+ if (urlPattern != null && !urlPattern.matcher(string).matches()) {
+ return false;
+ }
+ return getDelegate().handlesURI(string);
+ }
+
+ @Override
+ public String getProductVersion() {
+ return getDelegate().getProductVersion();
+ }
+
+ @Override
+ public String getDisplayName() {
+ return getDelegate().getDisplayName();
+ }
+
+ @Override
+ public DeploymentManager getDisconnectedDeploymentManager(String string) throws DeploymentManagerCreationException {
+ return getDelegate().getDisconnectedDeploymentManager(string);
+ }
+
+ @Override
+ public DeploymentManager getDeploymentManager(String string, String string1, String string2) throws DeploymentManagerCreationException {
+ return getDelegate().getDeploymentManager(string, string1, string2);
+ }
+
+ private DeploymentFactory getDelegate() {
+ synchronized (this) {
+ if (delegate != null) {
+ return delegate;
+ }
+ }
+
+ DeploymentFactory factory = (DeploymentFactory) attributes.get("delegate"); // NOI18N
+ Parameters.notNull("delegate", factory); // NOI18N
+
+ synchronized (this) {
+ if (delegate == null) {
+ delegate = factory;
+ }
+ return delegate;
+ }
+ }
+}
diff -r 41d5a0f1bef2 j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/api/InstancePropertiesTest.java
--- a/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/api/InstancePropertiesTest.java Wed Feb 17 14:22:39 2010 +0100
+++ b/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/api/InstancePropertiesTest.java Wed Feb 17 20:14:39 2010 +0100
@@ -197,9 +197,8 @@
private static class MockDF extends org.netbeans.tests.j2eeserver.plugin.jsr88.TestDeploymentFactory {
- @Override
- public boolean handlesURI(String arg0) {
- return arg0.startsWith("unknown:");
+ public MockDF() {
+ super("unknown:");
}
}
diff -r 41d5a0f1bef2 j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/spi/UrlPatternTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/j2eeserver/test/unit/src/org/netbeans/modules/j2ee/deployment/plugins/spi/UrlPatternTest.java Wed Feb 17 20:14:39 2010 +0100
@@ -0,0 +1,75 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2010 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.j2ee.deployment.plugins.spi;
+
+import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
+import org.netbeans.modules.j2ee.deployment.impl.ServerRegistryTestBase;
+import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceCreationException;
+import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
+
+/**
+ *
+ * @author Petr Hejl
+ */
+public class UrlPatternTest extends ServerRegistryTestBase {
+
+ private static final String TEST_URL_PREFIX_PERMITTED = "permittedfooservice:";
+
+ private static final String TEST_URL_PREFIX_FORBIDDEN = "forbiddenfooservice:";
+
+ public UrlPatternTest(String name) {
+ super(name);
+ }
+
+ public void testPermittedPattern() throws InstanceCreationException {
+ InstanceProperties.createInstanceProperties(
+ TEST_URL_PREFIX_PERMITTED + "testPermitted", "test", "password", "Permitted instance");
+ }
+
+ public void testForbiddenPattern() throws InstanceCreationException {
+ try {
+ InstanceProperties.createInstanceProperties(
+ TEST_URL_PREFIX_FORBIDDEN + "testForbidden", "test", "password", "Forbidden instance");
+ fail("Forbidden instance registered");
+ } catch (InstanceCreationException ex) {
+ // expected
+ }
+ }
+}
diff -r 41d5a0f1bef2 j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/jsr88/TestDeploymentFactory.java
--- a/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/jsr88/TestDeploymentFactory.java Wed Feb 17 14:22:39 2010 +0100
+++ b/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/jsr88/TestDeploymentFactory.java Wed Feb 17 20:14:39 2010 +0100
@@ -47,14 +47,22 @@
/**
*
- * @author gfink
+ * @author Petr Hejl
*/
public class TestDeploymentFactory implements DeploymentFactory {
-
+
private Map managers = new HashMap();
+ private final String prefix;
+
/** Creates a new instance of DepFactory */
- public TestDeploymentFactory() {
+ protected TestDeploymentFactory(String prefix) {
+ assert prefix != null;
+ this.prefix = prefix;
+ }
+
+ public static TestDeploymentFactory create(Map map) {
+ return new TestDeploymentFactory((String) map.get("prefix"));
}
public synchronized javax.enterprise.deploy.spi.DeploymentManager getDeploymentManager(String str, String str1, String str2) throws javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException {
@@ -84,7 +92,7 @@
}
public boolean handlesURI(String str) {
- return (str != null && str.startsWith("fooservice"));
+ return (str != null && str.startsWith(prefix));
}
}
diff -r 41d5a0f1bef2 j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/layer.xml
--- a/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/layer.xml Wed Feb 17 14:22:39 2010 +0100
+++ b/j2eeserver/test/unit/src/org/netbeans/tests/j2eeserver/plugin/layer.xml Wed Feb 17 20:14:39 2010 +0100
@@ -52,7 +52,8 @@