diff -ruNP -X exclude jboss-4.0.1RC2-src/build/build.xml jboss-4.0.1RC2-src.changed/build/build.xml --- jboss-4.0.1RC2-src/build/build.xml 2004-11-29 16:54:36.000000000 +0000 +++ jboss-4.0.1RC2-src.changed/build/build.xml 2004-12-01 14:27:44.607055521 +0000 @@ -1100,6 +1100,7 @@ + @@ -1156,6 +1157,7 @@ + diff -ruNP -X exclude jboss-4.0.1RC2-src/management/src/etc/jsr77-service.xml jboss-4.0.1RC2-src.changed/management/src/etc/jsr77-service.xml --- jboss-4.0.1RC2-src/management/src/etc/jsr77-service.xml 2003-08-27 05:31:12.000000000 +0100 +++ jboss-4.0.1RC2-src.changed/management/src/etc/jsr77-service.xml 2004-12-01 14:27:53.265931420 +0000 @@ -19,6 +19,7 @@ jboss.jca:service=ConnectionFactoryDeployer jboss.web:service=WebServer jboss:service=Mail + jboss:service=URL jboss.mq:service=DestinationManager jboss:service=Naming jboss:service=TransactionManager diff -ruNP -X exclude jboss-4.0.1RC2-src/management/src/main/org/jboss/management/j2ee/LocalJBossServerDomain.java jboss-4.0.1RC2-src.changed/management/src/main/org/jboss/management/j2ee/LocalJBossServerDomain.java --- jboss-4.0.1RC2-src/management/src/main/org/jboss/management/j2ee/LocalJBossServerDomain.java 2004-04-20 10:17:12.000000000 +0100 +++ jboss-4.0.1RC2-src.changed/management/src/main/org/jboss/management/j2ee/LocalJBossServerDomain.java 2004-12-01 14:27:53.265931420 +0000 @@ -99,6 +99,10 @@ */ private ObjectName mailService; /** + * The name of the URL Resource service + */ + private ObjectName urlService; + /** * The name of the RMI_IIOP service */ private ObjectName rmiiiopService; @@ -327,6 +331,24 @@ } /** + * @return The URL Resource service mbean name + * @jmx:managed-attribute + */ + public ObjectName getURLService() + { + return urlService; + } + + /** + * @param name The JavaMail service mbean name + * @jmx:managed-attribute + */ + public void setURLService(ObjectName name) + { + this.urlService = name; + } + + /** * @return The UserTransaction service mbean name * @jmx:managed-attribute */ diff -ruNP -X exclude jboss-4.0.1RC2-src/server/src/etc/conf/default/jboss-service.xml jboss-4.0.1RC2-src.changed/server/src/etc/conf/default/jboss-service.xml --- jboss-4.0.1RC2-src/server/src/etc/conf/default/jboss-service.xml 2004-10-26 15:57:40.000000000 +0100 +++ jboss-4.0.1RC2-src.changed/server/src/etc/conf/default/jboss-service.xml 2004-12-01 14:27:53.266931290 +0000 @@ -27,6 +27,7 @@ jboss.jca:service=ConnectionFactoryDeployer jboss.web:service=WebServer jboss:service=Mail + jboss:service=URL jboss.mq:service=DestinationManager jboss:service=Naming jboss:service=TransactionManager diff -ruNP -X exclude jboss-4.0.1RC2-src/varia/build.xml jboss-4.0.1RC2-src.changed/varia/build.xml --- jboss-4.0.1RC2-src/varia/build.xml 2004-11-29 16:53:59.000000000 +0000 +++ jboss-4.0.1RC2-src.changed/varia/build.xml 2004-12-01 14:27:53.267931160 +0000 @@ -392,6 +392,14 @@ + + + + + + + diff -ruNP -X exclude jboss-4.0.1RC2-src/varia/src/etc/url-service.xml jboss-4.0.1RC2-src.changed/varia/src/etc/url-service.xml --- jboss-4.0.1RC2-src/varia/src/etc/url-service.xml 1970-01-01 01:00:00.000000000 +0100 +++ jboss-4.0.1RC2-src.changed/varia/src/etc/url-service.xml 2004-12-01 14:27:53.268931030 +0000 @@ -0,0 +1,25 @@ + + + + + + + + + + + + java:/Urls + + + + + + + + + + + diff -ruNP -X exclude jboss-4.0.1RC2-src/varia/src/main/org/jboss/urls/URLService.java jboss-4.0.1RC2-src.changed/varia/src/main/org/jboss/urls/URLService.java --- jboss-4.0.1RC2-src/varia/src/main/org/jboss/urls/URLService.java 1970-01-01 01:00:00.000000000 +0100 +++ jboss-4.0.1RC2-src.changed/varia/src/main/org/jboss/urls/URLService.java 2004-12-01 14:27:53.269930901 +0000 @@ -0,0 +1,273 @@ +/*************************************** + * * + * JBoss: The OpenSource J2EE WebOS * + * * + * Distributable under LGPL license. * + * See terms of license at gnu.org. * + * * + ***************************************/ + +package org.jboss.urls; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.Name; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; + +import org.jboss.system.ServiceMBeanSupport; +import org.jboss.system.server.ServerConfigLocator; +import org.jboss.util.Strings; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * MBean that gives support for J2EE URL Resource references. Object of class java.net.URL will be bound + * in JNDI with the name provided with method {@link #setJNDIName}. + * + * @jmx:mbean name="jboss:type=Service,service=URL" + * extends="org.jboss.system.ServiceMBean" + * + * @version $Revision$ + * @author Phil Cornelius + */ + +public class URLService extends ServiceMBeanSupport implements URLServiceMBean { + + public static final String BASE_JNDI_NAME = "java:/Urls"; + + /** The server's home dir as a string (for making file:// urls). */ + protected String serverHome; + private Element bindings; + private String baseJndiName = BASE_JNDI_NAME; + + /** Object Name of the JSR-77 representant of this service + * got a feeling this is needed */ + ObjectName mURL; + + /** save bindings here */ + Map ourBindings = null; + + + /** The JNDI name under which java.net.URL objects are bound. + * + * @jmx:managed-attribute + */ + public void setBaseJNDIName(final String name) + { + baseJndiName = name; + } + + /** + * @jmx:managed-attribute + */ + public String getBaseJNDIName() + { + return baseJndiName; + } + + /** + * URL Resource bindings defined in the service file. + * + * @jmx:managed-attribute + */ + public Element getBindings() + { + return bindings; + } + + /** + * URL Resource bindings defined in the service file. + * + * @jmx:managed-attribute + */ + public void setBindings(final Element element) + { + bindings = element; + } + + protected ObjectName getObjectName(MBeanServer server, ObjectName name) + throws MalformedObjectNameException + { + return name == null ? OBJECT_NAME : name; + } + + protected void startService() throws Exception + { + + Map urls = getURLBindings(); + + bind(urls); + + // now make the properties available + ourBindings = urls; + } + + protected Map getURLBindings() throws Exception + { + boolean debug = log.isDebugEnabled(); + + Map urlBindings = new HashMap(); + if (bindings == null) + { + log.warn("No bindings specified; using empty bindings map"); + return urlBindings; + } + + NodeList list = bindings.getElementsByTagName("urlbinding"); + int len = list.getLength(); + + for (int i = 0; i < len; i++) + { + Node node = list.item(i); + + switch (node.getNodeType()) + { + case Node.ELEMENT_NODE: + Element child = (Element) node; + String jndiName; + URL resURL; + + // get the name + if (child.hasAttribute("jndi-name")) + { + jndiName = child.getAttribute("jndi-name"); + } + else + { + log.warn("Ignoring invalid element; missing 'jndi-name' attribute: " + child); + break; + } + + // get the res-url + if (child.hasAttribute("res-url")) + { + try { + resURL = Strings.toURL(child.getAttribute("res-url")); + } catch (MalformedURLException e) { + resURL = Strings.toURL(child.getAttribute("res-url"), serverHome); + } + + } + else + { + log.warn("Ignoring invalid element; missing 'res-url' attribute: " + child); + break; + } + + if (debug) + { + log.debug("setting url binding " + jndiName + "=" + resURL); + } + urlBindings.put(jndiName, resURL); + break; + + case Node.COMMENT_NODE: + // ignore + break; + + default: + log.debug("ignoring unsupported node type: " + node); + break; + } + } + + if (debug) + { + log.debug("Using url bindings: " + urlBindings); + } + + return urlBindings; + } + + protected void stopService() throws Exception + { + unbind(); + } + + private void bind(Map urls) throws NamingException + { + String baseBindName = getBaseJNDIName(); + + + // set up the base context + Context ctx = new InitialContext(); + try + { + Name n = ctx.getNameParser("").parse(baseBindName); + while (n.size() > 0) + { + String ctxName = n.get(0); + try + { + ctx = (Context) ctx.lookup(ctxName); + } + catch (NameNotFoundException e) + { + ctx = ctx.createSubcontext(ctxName); + } + n = n.getSuffix(1); + } + + // bind each of the URLs into the base context + Iterator iter = urls.keySet().iterator(); + while (iter.hasNext()) { + String ctxName = (String) iter.next(); + ctx.bind(ctxName, urls.get(ctxName)); + } + } + finally + { + ctx.close(); + } + + log.info("URL resources bound to " + baseBindName); + } + + private void unbind() throws NamingException + { + String bindName = getBaseJNDIName(); + + if (bindName != null) + { + InitialContext ctx = new InitialContext(); + try + { + ctx.unbind(bindName); + } + finally + { + ctx.close(); + } + log.info("URL resources bound to '" + getBaseJNDIName() + "' removed from JNDI"); + } + } + + /////////////////////////////////////////////////////////////////////////// + // ServiceMBeanSupport Overrides // + /////////////////////////////////////////////////////////////////////////// + + /** + * Setup our reference to the server's home directory. This is done + * here because one or more attribute setters makes use of this value. + */ + public ObjectName preRegister(final MBeanServer server, final ObjectName name) + throws Exception + { + // get server's home for relative paths, need this for making urls + serverHome = ServerConfigLocator.locate().getServerHomeDir().getPath(); + + return super.preRegister(server, name); + } + +}