notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2728 - development/main/transit/core/handler/src/main/net/dpml/transit/builder
- From: mcconnell AT dpml.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2728 - development/main/transit/core/handler/src/main/net/dpml/transit/builder
- Date: Sun, 05 Jun 2005 18:13:26 -0400
Author: mcconnell AT dpml.net
Date: Sun Jun 5 18:13:26 2005
New Revision: 2728
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/AbstractStorageHome.java
Log:
Added:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/AbstractStorageHome.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/AbstractStorageHome.java
Sun Jun 5 18:13:26 2005
@@ -0,0 +1,174 @@
+/*
+ * 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.builder;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.MalformedURLException;
+import java.util.Date;
+import java.util.prefs.Preferences;
+import java.util.prefs.BackingStoreException;
+
+import net.dpml.transit.model.Logger;
+
+/**
+ * Utility class that provides support for the creation of URI and URL
+ * values from preference attributes.
+ */
+class AbstractStorageHome
+{
+ private Preferences m_prefs;
+ private boolean m_policy;
+ private Logger m_logger;
+ private Date m_creation;
+
+ public AbstractStorageHome( Preferences prefs, Logger logger, Date
creation, boolean policy )
+ {
+ m_prefs = prefs;
+ m_policy = policy;
+ m_creation = creation;
+ m_logger = logger;
+ }
+
+ public boolean getStoragePolicy()
+ {
+ return m_policy;
+ }
+
+ public Preferences getPreferences()
+ {
+ return m_prefs;
+ }
+
+ public Date getCreationDate()
+ {
+ return m_creation;
+ }
+
+ public Logger getLogger()
+ {
+ return m_logger;
+ }
+
+ public URI getURI( String key ) throws BuilderException
+ {
+ Preferences prefs = getPreferences();
+ String path = prefs.get( key, null );
+ try
+ {
+ if( null == path )
+ {
+ return null;
+ }
+ else
+ {
+ return new URI( path );
+ }
+ }
+ catch( URISyntaxException e )
+ {
+ final String error =
+ "Invalid URI attribute value."
+ + "\nPreferences: " + prefs
+ + "\nAttribute: " + key
+ + "\nValue: " + path;
+ throw new BuilderException( error, e );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to construct a uri."
+ + "\nPreferences: " + prefs
+ + "\nAttribute: " + key
+ + "\nValue: " + path;
+ throw new BuilderException( error, e );
+ }
+ }
+
+ public void setURI( String key, URI uri )
+ {
+ if( null == uri )
+ {
+ getPreferences().remove( key );
+ }
+ else
+ {
+ String ascii = uri.toASCIIString();
+ getPreferences().put( key, ascii );
+ }
+ }
+
+ public URL getURL( String key ) throws BuilderException
+ {
+ Preferences prefs = getPreferences();
+ String path = prefs.get( key, null );
+ try
+ {
+ if( null == path )
+ {
+ return null;
+ }
+ else
+ {
+ return new URL( path );
+ }
+ }
+ catch( MalformedURLException e )
+ {
+ final String error =
+ "Invalid URL attribute value."
+ + "\nPreferences: " + prefs
+ + "\nAttribute: " + key
+ + "\nValue: " + path;
+ throw new BuilderException( error, e );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to construct url."
+ + "\nPreferences: " + prefs
+ + "\nAttribute: " + key
+ + "\nValue: " + path;
+ throw new BuilderException( error, e );
+ }
+ }
+
+ public void setURL( String key, URL url )
+ {
+ if( null == url )
+ {
+ getPreferences().remove( key );
+ }
+ else
+ {
+ try
+ {
+ String path = url.toString();
+ URI uri = new URI( path );
+ String ascii = uri.toASCIIString();
+ getPreferences().put( key, ascii );
+ }
+ catch( Exception e )
+ {
+ getPreferences().put( key, url.toString() );
+ }
+ }
+ }
+}
+
- svn commit: r2728 - development/main/transit/core/handler/src/main/net/dpml/transit/builder, mcconnell, 06/05/2005
Archive powered by MHonArc 2.6.24.