Apache » Cocoon »

  Cocoon JNet
      1.2.2
   homepage

Cocoon JNet 1.2.2

Overview

Cocoon JNet allows the dynamic registration of URLStreamHandler factories with your JVM. That's a feature that isn't supported by Java itself.

Plain Java usage

The class org.apache.cocoon.jnet.DynamicURLStreamHandlerFactory can be used to install more than one URLStreamHandlerFactory and is registered at the JVM by using org.apache.cocoon.jnet.URLStreamHandlerFactoryInstaller.

After registering your own URLStreamHandler, you can use the new protocols for java.net.URL objects:

java.net.URL url = new java.net.URL("myprotocol:/a/b/c");

Spring integration

By using the Cocoon Spring-Configurator all beans of type java.net.URLStreamHandlerFactory can be collected:

<bean id="org.apache.cocoon.jnet.URLHandlerFactoryCollector" 
  class="org.apache.cocoon.jnet.URLHandlerFactoryCollector">
  <property name="urlHandlerFactories">
    <configurator:bean-map type="java.net.URLStreamHandlerFactory" 
      strip-prefix="true" />
  </property>
</bean>

The URLHandlerFactoryCollector is implemented as an around advice. The code that wants to use the registred protocols only has to be wrapped by this advice. The Cocoon Servlet-Service framework uses it to intercept all calls of the service method of any of its servlets:

<aop:config>
  <aop:aspect id="installURL" ref="org.apache.cocoon.jnet.URLHandlerFactoryCollector">
    <aop:pointcut id="servletServiceInvocation"
      expression="execution(* javax.servlet.Servlet.service(..)) and bean(*/embedded)" />
    <aop:around pointcut-ref="servletServiceInvocation" method="installURLHandlers" />
  </aop:aspect>
</aop:config>