Let's Put It All Together
There are also three steps to creating your own protocol handler:

Figure 2. The relationship between the three getContent methods. The URL.getContent, URLConnection.getContent, and ContentHandler.getContent.
Note: Remember that a protocol handler is in connection with a content handler, so, you have to know what content handlers are and how do they work.
As you can see from Figure 2, the starting point of the discussion is the URL class. More precisely, the URL object indicates the resource that is accessed. In the TestProtocolHandler example, the URL is specified like this:
URL url=new URL("xy:X//localhost/image.xy");
The xy:X//localhost/image.xy path is parsed by the URL class only for extracting the protocol name. In this case, the result of parsing indicates the xy protocol, a total unknown protocol. After the URL class finds out the protocol name, it localizes the appropriate protocol handler by looking into the sun.net.www.protocol... packages. Because the xy protocol doesn't have a default protocol handler, there are two solutions for helping the URL class to find the xy protocol handler:
- Put the
xy protocol handler into the sun.net.www.protocol.xy package (for an automatic install).
- Call
createURLStreamHandler and setURLStreamHandlerFactory (for a manual install).
The TestProtocolHandler example implements the both solutions.
Strong Network Application Support
Content and protocol handlers are just one aspect of Java's strong network application support. You can use content and protocol handlers to create your own Internet browserand not just an Internet browser for already known protocols, but an Internet browser supporting your own protocols.
| Home / Articles
/ Creating Content and Protocol Handlers in Java, Part 2 / 1 / 2 / 3 / |
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|