Revision: 7770
Author: victormote
Date: 2006-07-08 11:04:47 -0700 (Sat, 08 Jul 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7770&view=rev
Log Message:
-----------
Add new Factory-only implementation, per Vincent Hennebert's request.
Added Paths:
-----------
trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java
Added: trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java (rev 0)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 18:04:47 UTC (rev 7770)
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2006 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+$Id$
+ */
+
+/* Known contributors:
+ * Vincent Hennebert (original author)
+ */
+
+package org.foray.common.url;
+
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+
+/**
+ * An implementation of {#link ProtocolHandlerRegistry} which does not attempt
+ * to use the "java.protocol.handler.pkgs" property to register new
+ * URLStreamHandlers, but instead attempts to use only a
+ * {@link URLStreamHandlerFactory}.
+ */
+public class FactoryProtocolRegistration
+ implements ProtocolRegistrationStrategy {
+
+ public FactoryProtocolRegistration() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registerProtocolHandler(String protocol,
+ URLStreamHandler handler) {
+ /* Get the Factory instance. */
+ FOrayURLStreamHandlerFactory factory =
+ FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory();
+
+ if (factory == null) {
+ /* If factory is null, it is because something got registered in
+ * URL.setURLStreamHandlerFactory(URLStreamHandlerFactory)
+ * before our FOrayURLStreamHandlerFactory could register.
+ * There is nothing that can be done. */
+ return;
+ }
+
+ /* See if this protocol is already registered with the factory. */
+ URLStreamHandler registeredHandler = factory.createURLStreamHandler(
+ protocol);
+ if (registeredHandler != null) {
+ /* If already registed, that one is the one being used, and there
+ * is no way to change it. If it has in fact not yet been used,
+ * then registering this now would make the new one used instead
+ * of the old one. However, until we have some indication that this
+ * would be the "right" thing to do, we will not. */
+ return;
+ }
+
+ /* Register the protocol with the Factory. */
+ factory.registerProtocol(protocol, handler);
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java
___________________________________________________________________
Name: svn:keywords
+ "Author Id Rev Date URL"
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|