notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2639 - in development/main/transit/core/handler/src/main/net/dpml/transit: manager model
- From: mcconnell AT dpml.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2639 - in development/main/transit/core/handler/src/main/net/dpml/transit: manager model
- Date: Sat, 21 May 2005 00:26:35 +0000
Author: mcconnell AT dpml.net
Date: Sat May 21 00:26:33 2005
New Revision: 2639
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyChangeEvent.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyListener.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitModel.java
Log:
Add support for active proxy settings configuration.
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
Sat May 21 00:26:33 2005
@@ -0,0 +1,311 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * 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.
+ */
+
+package net.dpml.transit.manager;
+
+import java.io.File;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.BackingStoreException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.EventObject;
+import java.util.EventListener;
+import java.net.PasswordAuthentication;
+
+import net.dpml.transit.model.ProxyModel;
+import net.dpml.transit.model.ProxyListener;
+import net.dpml.transit.model.ProxyChangeEvent;
+import net.dpml.transit.model.ModelException;
+
+import net.dpml.transit.network.RequestIdentifier;
+import net.dpml.transit.event.EventProducer;
+
+/**
+ * The TransitManager class is the default TransitModel implementation.
+ *
+ * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
+ * @version $Id: StandardTransitDirector.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
+ */
+public class ProxyManager extends EventProducer implements ProxyModel,
PreferenceChangeListener
+{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
+ private final Preferences m_preferences;
+ private final Logger m_logger;
+
+ private PasswordAuthentication m_authentication;
+ private RequestIdentifier m_identifier;
+ private String m_excludes;
+
+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
+ public ProxyManager( Logger logger, Preferences prefs )
+ throws NullPointerException
+ {
+ if( null == prefs )
+ {
+ throw new NullPointerException( "prefs" );
+ }
+ if( null == logger )
+ {
+ throw new NullPointerException( "logger" );
+ }
+
+ m_logger = logger;
+ m_preferences = prefs;
+
+ //
+ // setup the proxy settings
+ //
+
+ prefs.addPreferenceChangeListener( this );
+ setupProxyConfiguration( prefs, false );
+ }
+
+ //
------------------------------------------------------------------------
+ // PreferencesChangeListener (listens to changes to the uri attribute)
+ //
------------------------------------------------------------------------
+
+ public void preferenceChange( PreferenceChangeEvent event )
+ {
+ String key = event.getKey();
+ String value = event.getNewValue();
+ Preferences prefs = event.getNode();
+ setupProxyConfiguration( prefs, true );
+ }
+
+ //
------------------------------------------------------------------------
+ // ProxyModel
+ //
------------------------------------------------------------------------
+
+ /**
+ * Returns TRUE if a proxy configuration is enabled.
+ * @return the proxy configuration enabled status
+ */
+ public boolean isProxyEnabled()
+ {
+ return ( m_identifier != null );
+ }
+
+ /**
+ * Return the proxy authentication or null if not defined.
+ * @return the proxy authentication credentials
+ */
+ public PasswordAuthentication getProxyAuthentication()
+ {
+ return m_authentication;
+ }
+
+ /**
+ * Return the proxy host request identifier.
+ * @return the request identifier for the proxy host or null if not
defined.
+ */
+ public RequestIdentifier getProxyRequestIdentifier()
+ {
+ return m_identifier;
+ }
+
+ /**
+ * Return the String identifying the non-proxy hosts.
+ * @return the non-proxied hosts value (possibly null)
+ */
+ public String getProxyExcludes()
+ {
+ return m_excludes;
+ }
+
+ /**
+ * Add a proxy listener to the model.
+ * @param listener the listener to add
+ */
+ public void addProxyListener( ProxyListener listener )
+ {
+ super.addListener( listener );
+ }
+
+ /**
+ * Remove a proxy listener from the model.
+ * @param listener the listener to remove
+ */
+ public void removeProxyListener( ProxyListener listener )
+ {
+ super.removeListener( listener );
+ }
+
+ //
------------------------------------------------------------------------
+ // internal
+ //
------------------------------------------------------------------------
+
+ private void setupProxyConfiguration( Preferences prefs, boolean notify )
+ {
+ if( null != prefs.get( "host", null ) )
+ {
+ m_identifier = resolveRequestIdentifier( prefs );
+ m_authentication = resolveProxyPasswordAuthentication( prefs );
+ m_excludes = resolveProxyExcludes( prefs );
+ }
+ else
+ {
+ m_identifier = null;
+ m_authentication = null;
+ m_excludes = null;
+ }
+ if( notify )
+ {
+ ProxyChangeEvent event =
+ new ProxyChangeEvent( this, m_identifier, m_authentication,
m_excludes );
+ super.enqueueEvent( event );
+ }
+ }
+
+ protected void processEvent( EventObject eventObject )
+ {
+ ProxyChangeEvent event = (ProxyChangeEvent) eventObject;
+ EventListener[] listeners = super.listeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ EventListener listener = listeners[i];
+ if( listener instanceof ProxyListener )
+ {
+ ProxyListener pl = (ProxyListener) listener;
+ try
+ {
+ pl.proxySettingsChanged( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "PluginListener notification error.";
+ m_logger.log( Level.SEVERE, error, e );
+ }
+ }
+ }
+ }
+
+ public void finalize()
+ {
+ if( null != m_preferences )
+ {
+ try
+ {
+ m_preferences.removePreferenceChangeListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
+ }
+ }
+
+ private PasswordAuthentication resolveProxyPasswordAuthentication(
Preferences prefs )
+ {
+ String username = prefs.get( "username", null );
+ if( null != username )
+ {
+ String password = prefs.get( "password", "" );
+ return new PasswordAuthentication( username,
password.toCharArray() );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Resolve the list of host names to be assigned as non-proxied hosts. If
proxy
+ * excludes are defined the string returned contains the host name
(wilcards allowed)
+ * separated by the "|" character. If no proxy excludes are defined the
value returned
+ * shall be null.
+ *
+ * @param prefs a node named 'proxy' containing a child node named
'excludes'
+ * @return a string containing a sequence of excluded hosts (possibly
null)
+ */
+ private String resolveProxyExcludes( Preferences prefs )
+ {
+ Preferences excludes = prefs.node( "excludes" );
+ try
+ {
+ String[] names = excludes.childrenNames();
+ String spec = null;
+ for( int i=0; i<names.length; i++ )
+ {
+ String name = names[i];
+ if( null == spec )
+ {
+ spec = name;
+ }
+ else
+ {
+ spec = spec + "|" + name;
+ }
+ }
+ return spec;
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
+ "Ignoring possible proxy exclude settings due to a
preferences backing store error."
+ + "\nPreferences: " + prefs;
+ getLogger().log( Level.SEVERE, error, e );
+ return null;
+ }
+ }
+
+ private RequestIdentifier resolveRequestIdentifier( Preferences prefs )
+ {
+ String host = prefs.get( "host", null );
+ if( null == host )
+ {
+ return null;
+ }
+ else
+ {
+ String protocol = prefs.get( "protocol", "http" );
+ String scheme = prefs.get( "scheme", null );
+ if( scheme == null )
+ {
+ final String error =
+ "Proxy configuration does not declare a scheme."
+ + "\nPreferences: " + prefs;
+ throw new IllegalArgumentException( error );
+ }
+ String prompt = prefs.get( "prompt", null );
+ if( prompt == null )
+ {
+ final String error =
+ "Proxy configuration does not declare a prompt."
+ + "\nPreferences: " + prefs;
+ throw new IllegalArgumentException( error );
+ }
+ int port = prefs.getInt( "port", 0 );
+ return new RequestIdentifier( host, port, protocol, scheme,
prompt );
+ }
+ }
+
+ private Logger getLogger()
+ {
+ return m_logger;
+ }
+}
+
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
Sat May 21 00:26:33 2005
@@ -26,6 +26,7 @@
import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.RegistryModel;
import net.dpml.transit.model.RepositoryModel;
+import net.dpml.transit.model.ProxyModel;
import net.dpml.transit.model.ModelException;
/**
@@ -43,6 +44,7 @@
private final CacheModel m_cache;
private final RegistryModel m_registry;
private final RepositoryModel m_repository;
+ private final ProxyModel m_proxy;
//
------------------------------------------------------------------------
// constructor
@@ -62,6 +64,7 @@
m_cache = createCacheModel( logger, prefs );
m_registry = createRegistryModel( logger, prefs );
m_repository = createRepositoryModel( logger, prefs );
+ m_proxy = createProxyModel( logger, prefs );
}
//
------------------------------------------------------------------------
@@ -69,6 +72,15 @@
//
------------------------------------------------------------------------
/**
+ * Return the proxy model.
+ * @return the proxy configuration model.
+ */
+ public ProxyModel getProxyModel()
+ {
+ return m_proxy;
+ }
+
+ /**
* Return the cache model.
* @return the cache model
*/
@@ -124,6 +136,13 @@
return new RepositoryManager( log, prefs );
}
+ private ProxyModel createProxyModel( Logger logger, Preferences root )
+ {
+ Preferences prefs = root.node( "proxy" );
+ Logger log = getLogger( logger, "proxy" );
+ return new ProxyManager( log, prefs );
+ }
+
private Logger getLogger( Logger logger, String name )
{
String base = logger.getName();
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyChangeEvent.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyChangeEvent.java
Sat May 21 00:26:33 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * 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.
+ */
+
+package net.dpml.transit.model;
+
+import java.net.URL;
+import java.util.EventObject;
+import java.net.PasswordAuthentication;
+
+import net.dpml.transit.network.RequestIdentifier;
+
+public class ProxyChangeEvent extends EventObject
+{
+ private final RequestIdentifier m_identifier;
+ private final PasswordAuthentication m_authentication;
+ private final String m_excludes;
+
+ public ProxyChangeEvent(
+ ProxyModel model, RequestIdentifier identifier, PasswordAuthentication
auth, String excludes )
+ {
+ super( model );
+ m_identifier = identifier;
+ m_authentication = auth;
+ m_excludes = excludes;
+ }
+
+ public ProxyModel getProxyModel()
+ {
+ return (ProxyModel) super.getSource();
+ }
+
+ public RequestIdentifier getRequestIdentifier()
+ {
+ return m_identifier;
+ }
+
+ public PasswordAuthentication getPasswordAuthentication()
+ {
+ return m_authentication;
+ }
+
+ public String getProxyExcludes()
+ {
+ return m_excludes;
+ }
+}
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyListener.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyListener.java
Sat May 21 00:26:33 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2005 Stephen McConnell
+ *
+ * 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.
+ */
+
+package net.dpml.transit.model;
+
+import java.util.EventListener;
+
+/**
+ * A ContentListener maintains information about the configuration of
+ * content type.
+ */
+public interface ProxyListener extends EventListener
+{
+ /**
+ * Notify a listener of the change to Transit proxy settings.
+ * @param event the proxy change event
+ */
+ void proxySettingsChanged( ProxyChangeEvent event );
+}
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
Sat May 21 00:26:33 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2005 Stephen McConnell
+ *
+ * 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.
+ */
+
+package net.dpml.transit.model;
+
+import java.net.URI;
+import java.net.PasswordAuthentication;
+
+import net.dpml.transit.network.RequestIdentifier;
+
+/**
+ * The ProxyModel is an interface implemented by objects that
+ * manage the configuration of a running transit system.
+ */
+public interface ProxyModel
+{
+ /**
+ * Returns TRUE if a proxy configuration is enabled.
+ * @return the proxy configuration enabled status
+ */
+ boolean isProxyEnabled();
+
+ /**
+ * Return the proxy authentication or null if not defined.
+ * @return the proxy authentication credentials
+ */
+ PasswordAuthentication getProxyAuthentication();
+
+ /**
+ * Return the proxy host request identifier.
+ * @return the request identifier for the proxy host or null if not
defined.
+ */
+ RequestIdentifier getProxyRequestIdentifier();
+
+ /**
+ * Return the String identifying the non-proxy hosts.
+ * @return the non-proxied hosts value (possibly null)
+ */
+ String getProxyExcludes();
+
+ /**
+ * Add a proxy listener to the model.
+ * @param listener the listener to add
+ */
+ void addProxyListener( ProxyListener listener );
+
+ /**
+ * Remove a proxy listener from the model.
+ * @param listener the listener to remove
+ */
+ void removeProxyListener( ProxyListener listener );
+
+}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/TransitModel.java
Sat May 21 00:26:33 2005
@@ -18,15 +18,19 @@
package net.dpml.transit.model;
-import java.net.URI;
-
/**
- * The TransitDirector is an interface implemented by objects that
+ * The TransitModel is an interface implemented by objects that
* manage the configuration of a running transit system.
*/
public interface TransitModel
{
/**
+ * Return the proxy model.
+ * @return the proxy model
+ */
+ ProxyModel getProxyModel();
+
+ /**
* Return the cache model.
* @return the cache director
*/
- svn commit: r2639 - in development/main/transit/core/handler/src/main/net/dpml/transit: manager model, mcconnell, 05/20/2005
Archive powered by MHonArc 2.6.24.