incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1031522 - in /incubator/isis/trunk/core: commons/src/main/java/org/apache/isis/commons/resource/ metamodel/src/main/java/org/apache/isis/metamodel/config/ metamodel/src/test/java/org/apache/isis/metamodel/config/
Date Fri, 05 Nov 2010 11:37:09 GMT
Author: danhaywood
Date: Fri Nov  5 11:37:09 2010
New Revision: 1031522

URL: http://svn.apache.org/viewvc?rev=1031522&view=rev
Log:
added some toString() methods to help debugging in core

Added:
    incubator/isis/trunk/core/metamodel/src/test/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreamsConfigResourceAndPolicyTest.java
Modified:
    incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/commons/resource/ResourceStreamSourceAbstract.java
    incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderFileSystem.java
    incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreams.java

Modified: incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/commons/resource/ResourceStreamSourceAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/commons/resource/ResourceStreamSourceAbstract.java?rev=1031522&r1=1031521&r2=1031522&view=diff
==============================================================================
--- incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/commons/resource/ResourceStreamSourceAbstract.java
(original)
+++ incubator/isis/trunk/core/commons/src/main/java/org/apache/isis/commons/resource/ResourceStreamSourceAbstract.java
Fri Nov  5 11:37:09 2010
@@ -17,49 +17,54 @@
  *  under the License.
  */
 
+package org.apache.isis.commons.resource;
 
-package org.apache.isis.commons.resource;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.apache.log4j.Logger;
-
-public abstract class ResourceStreamSourceAbstract implements ResourceStreamSource {
-	
-	private static Logger LOG = Logger.getLogger(ResourceStreamSourceAbstract.class);
-	
-	public final InputStream readResource(String resourcePath) {
-		
-		try {
-			InputStream resourceStream = doReadResource(resourcePath);
-			if (resourceStream != null) {
-				return resourceStream;
-			}
-			if (LOG.isDebugEnabled()) {
-				LOG.debug("could not load resource path '" + resourcePath + "' from " + getName() );
-			}
-		} catch (IOException e) {
-			if (LOG.isDebugEnabled()) {
-				LOG.debug("could not load resource path '" + resourcePath + "' from " + getName() + ",
exception: " + e.getMessage() );
-			}
-		}
-		return null;
-	}
-	
-	/**
-	 * Mandatory hook method; subclasses can return either <tt>null</tt> or throw
-	 * an exception if the resource could not be found.
-	 */
-	protected abstract InputStream doReadResource(String resourcePath) throws IOException;
-
-	/**
-	 * Default implementation returns <tt>null</tt> (that is, not supported).
-	 */
-	public OutputStream writeResource(String resourcePath) {
-		return null;
-	}
-
-
-}
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.log4j.Logger;
+
+public abstract class ResourceStreamSourceAbstract implements ResourceStreamSource {
+
+    private static Logger LOG = Logger.getLogger(ResourceStreamSourceAbstract.class);
+
+    @Override
+    public final InputStream readResource(String resourcePath) {
+
+        try {
+            InputStream resourceStream = doReadResource(resourcePath);
+            if (resourceStream != null) {
+                return resourceStream;
+            }
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("could not load resource path '" + resourcePath + "' from " + getName());
+            }
+        } catch (IOException e) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("could not load resource path '" + resourcePath + "' from " + getName()
+ ", exception: "
+                    + e.getMessage());
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Mandatory hook method; subclasses can return either <tt>null</tt> or throw
an exception if the resource could not
+     * be found.
+     */
+    protected abstract InputStream doReadResource(String resourcePath) throws IOException;
+
+    /**
+     * Default implementation returns <tt>null</tt> (that is, not supported).
+     */
+    @Override
+    public OutputStream writeResource(String resourcePath) {
+        return null;
+    }
+
+    @Override
+    public String toString() {
+        return getName();
+    }
+}

Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderFileSystem.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderFileSystem.java?rev=1031522&r1=1031521&r2=1031522&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderFileSystem.java
(original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderFileSystem.java
Fri Nov  5 11:37:09 2010
@@ -17,43 +17,38 @@
  *  under the License.
  */
 
-
 package org.apache.isis.metamodel.config;
 
-import org.apache.log4j.Logger;
 import org.apache.isis.commons.resource.ResourceStreamSource;
 import org.apache.isis.commons.resource.ResourceStreamSourceComposite;
 import org.apache.isis.commons.resource.ResourceStreamSourceFileSystem;
+import org.apache.log4j.Logger;
 
 /**
- * Convenience implementation of {@link ConfigurationBuilder} that
- * loads configuration resource from a specified directory (or directories) on the
- * filesystem.
+ * Convenience implementation of {@link ConfigurationBuilder} that loads configuration resource
from a specified
+ * directory (or directories) on the filesystem.
  * 
  * @see ResourceStreamSourceFileSystem
  */
 public class ConfigurationBuilderFileSystem extends ConfigurationBuilderResourceStreams {
 
-	@SuppressWarnings("unused")
-	private static final Logger LOG = Logger
-			.getLogger(ConfigurationBuilderFileSystem.class);
-	
-	private static ResourceStreamSource createResourceStreamSource(
-			String... directories) {
-		ResourceStreamSourceComposite composite = new ResourceStreamSourceComposite();
-		for(String directory: directories) {
-			composite.addResourceStreamSource(
-				new ResourceStreamSourceFileSystem(directory));
-		}
-		return composite;
-	}
-
-	public ConfigurationBuilderFileSystem(String... directories) {
-		super(createResourceStreamSource(directories));
-	}
-
-	public ConfigurationBuilderFileSystem() {
-		super(new ResourceStreamSourceFileSystem(ConfigurationConstants.DEFAULT_CONFIG_DIRECTORY));
-	}
+    @SuppressWarnings("unused")
+    private static final Logger LOG = Logger.getLogger(ConfigurationBuilderFileSystem.class);
+
+    private static ResourceStreamSource createResourceStreamSource(String... directories)
{
+        ResourceStreamSourceComposite composite = new ResourceStreamSourceComposite();
+        for (String directory : directories) {
+            composite.addResourceStreamSource(new ResourceStreamSourceFileSystem(directory));
+        }
+        return composite;
+    }
+
+    public ConfigurationBuilderFileSystem(String... directories) {
+        super(createResourceStreamSource(directories));
+    }
+
+    public ConfigurationBuilderFileSystem() {
+        super(new ResourceStreamSourceFileSystem(ConfigurationConstants.DEFAULT_CONFIG_DIRECTORY));
+    }
 
 }

Modified: incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreams.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreams.java?rev=1031522&r1=1031521&r2=1031522&view=diff
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreams.java
(original)
+++ incubator/isis/trunk/core/metamodel/src/main/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreams.java
Fri Nov  5 11:37:09 2010
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.metamodel.config;
 
 import java.io.IOException;
@@ -26,18 +25,19 @@ import java.util.Enumeration;
 import java.util.List;
 import java.util.Properties;
 
-import org.apache.log4j.Logger;
 import org.apache.isis.commons.exceptions.IsisException;
 import org.apache.isis.commons.resource.ResourceStreamSource;
 import org.apache.isis.commons.resource.ResourceStreamSourceComposite;
 import org.apache.isis.commons.resource.ResourceStreamSourceFileSystem;
 import org.apache.isis.metamodel.config.internal.PropertiesConfiguration;
 import org.apache.isis.metamodel.config.internal.PropertiesReader;
+import org.apache.log4j.Logger;
 
+import com.google.common.base.Objects;
 
 /**
- * Adapter for {@link ConfigurationBuilder}, loading the specified configuration resource
(file) from the
- * given {@link ResourceStreamSource}(s).
+ * Adapter for {@link ConfigurationBuilder}, loading the specified configuration resource
(file) from the given
+ * {@link ResourceStreamSource}(s).
  * 
  * <p>
  * If a property is in multiple configuration resources then the latter resources will overwrite
the former.
@@ -47,8 +47,8 @@ public class ConfigurationBuilderResourc
     private static final Logger LOG = Logger.getLogger(ConfigurationBuilderResourceStreams.class);
 
     static class ConfigurationResourceAndPolicy {
-        private String configurationResource;
-        private NotFoundPolicy notFoundPolicy;
+        private final String configurationResource;
+        private final NotFoundPolicy notFoundPolicy;
 
         public ConfigurationResourceAndPolicy(String configurationResource, NotFoundPolicy
notFoundPolicy) {
             this.configurationResource = configurationResource;
@@ -62,11 +62,17 @@ public class ConfigurationBuilderResourc
         public NotFoundPolicy getNotFoundPolicy() {
             return notFoundPolicy;
         }
+
+        @Override
+        public String toString() {
+            return String.format("%s{%s}", configurationResource, notFoundPolicy);
+        }
     }
 
     private final ResourceStreamSource resourceStreamSource;
 
-    private final List<ConfigurationResourceAndPolicy> configurationResources = new
ArrayList<ConfigurationResourceAndPolicy>();
+    private final List<ConfigurationResourceAndPolicy> configurationResources =
+        new ArrayList<ConfigurationResourceAndPolicy>();
     private final Properties additionalProperties = new Properties();
     private boolean includeSystemProperties = false;
 
@@ -112,6 +118,7 @@ public class ConfigurationBuilderResourc
     // ResourceStreamSource
     // ////////////////////////////////////////////////////////////
 
+    @Override
     public ResourceStreamSource getResourceStreamSource() {
         return resourceStreamSource;
     }
@@ -125,14 +132,15 @@ public class ConfigurationBuilderResourc
      * {@link ResourceStreamSource} available.
      * 
      * <p>
-     * If the configuration resource cannot be found then the provided {@link NotFoundPolicy}
determines
-     * whether an exception is thrown or not.
+     * If the configuration resource cannot be found then the provided {@link NotFoundPolicy}
determines whether an
+     * exception is thrown or not.
      * 
      * <p>
-     * Must be called before {@link #getConfiguration()}; the resource is actually read on
-     * {@link #getConfiguration()}.
+     * Must be called before {@link #getConfiguration()}; the resource is actually read on
{@link #getConfiguration()}.
      */
-    public synchronized void addConfigurationResource(final String configurationResource,
final NotFoundPolicy notFoundPolicy) {
+    @Override
+    public synchronized void addConfigurationResource(final String configurationResource,
+        final NotFoundPolicy notFoundPolicy) {
         configurationResources.add(new ConfigurationResourceAndPolicy(configurationResource,
notFoundPolicy));
         invalidateCache();
     }
@@ -145,6 +153,7 @@ public class ConfigurationBuilderResourc
     /**
      * Adds additional property.
      */
+    @Override
     public synchronized void add(final String key, final String value) {
         if (key == null || value == null) {
             return;
@@ -159,6 +168,7 @@ public class ConfigurationBuilderResourc
     /**
      * Adds additional properties.
      */
+    @Override
     public synchronized void add(final Properties properties) {
         final Enumeration<?> keys = properties.propertyNames();
         while (keys.hasMoreElements()) {
@@ -175,6 +185,7 @@ public class ConfigurationBuilderResourc
     /**
      * Returns the current {@link IsisConfiguration configuration}.
      */
+    @Override
     public synchronized IsisConfiguration getConfiguration() {
         if (cachedConfiguration != null) {
             return cachedConfiguration;
@@ -196,13 +207,13 @@ public class ConfigurationBuilderResourc
         }
     }
 
-    private void loadConfigurationResource(
-            PropertiesConfiguration configuration,
-            ConfigurationResourceAndPolicy configResourceAndPolicy) {
+    private void loadConfigurationResource(PropertiesConfiguration configuration,
+        ConfigurationResourceAndPolicy configResourceAndPolicy) {
         String configurationResource = configResourceAndPolicy.getConfigurationResource();
         NotFoundPolicy notFoundPolicy = configResourceAndPolicy.getNotFoundPolicy();
         if (LOG.isDebugEnabled()) {
-        	LOG.debug("loading configuration resource: " + configurationResource + ", notFoundPolicy:
" + notFoundPolicy);
+            LOG.debug("loading configuration resource: " + configurationResource + ", notFoundPolicy:
"
+                + notFoundPolicy);
         }
         loadConfigurationResource(configuration, configurationResource, notFoundPolicy);
     }
@@ -212,13 +223,11 @@ public class ConfigurationBuilderResourc
      * {@link ResourceStreamSource} available.
      * 
      * <p>
-     * If the configuration resource cannot be found then the provided {@link NotFoundPolicy}
determines
-     * whether an exception is thrown or not.
+     * If the configuration resource cannot be found then the provided {@link NotFoundPolicy}
determines whether an
+     * exception is thrown or not.
      */
-    protected void loadConfigurationResource(
-            final PropertiesConfiguration configuration,
-            final String configurationResource,
-            final NotFoundPolicy notFoundPolicy) {
+    protected void loadConfigurationResource(final PropertiesConfiguration configuration,
+        final String configurationResource, final NotFoundPolicy notFoundPolicy) {
         try {
             PropertiesReader propertiesReader = loadConfigurationResource(resourceStreamSource,
configurationResource);
             addProperties(configuration, propertiesReader.getProperties());
@@ -231,7 +240,7 @@ public class ConfigurationBuilderResourc
         }
         if (notFoundPolicy == NotFoundPolicy.FAIL_FAST) {
             throw new IsisException("failed to load '" + configurationResource + "'; tried
using: "
-                    + resourceStreamSource.getName());
+                + resourceStreamSource.getName());
         } else {
             if (LOG.isInfoEnabled()) {
                 LOG.info("'" + configurationResource + "' not found, but not needed");
@@ -239,9 +248,8 @@ public class ConfigurationBuilderResourc
         }
     }
 
-    private PropertiesReader loadConfigurationResource(
-            ResourceStreamSource resourceStreamSource,
-            final String configurationResource) throws IOException {
+    private PropertiesReader loadConfigurationResource(ResourceStreamSource resourceStreamSource,
+        final String configurationResource) throws IOException {
         return new PropertiesReader(resourceStreamSource, configurationResource);
     }
 
@@ -273,6 +281,7 @@ public class ConfigurationBuilderResourc
     // Injectable
     // ////////////////////////////////////////////////////////////
 
+    @Override
     public void injectInto(Object candidate) {
         if (ConfigurationBuilderAware.class.isAssignableFrom(candidate.getClass())) {
             ConfigurationBuilderAware cast = ConfigurationBuilderAware.class.cast(candidate);
@@ -280,4 +289,10 @@ public class ConfigurationBuilderResourc
         }
     }
 
+    @Override
+    public String toString() {
+        return Objects.toStringHelper(this).add("resourceStream", resourceStreamSource)
+            .add("configResources", configurationResources).toString();
+    }
+
 }

Added: incubator/isis/trunk/core/metamodel/src/test/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreamsConfigResourceAndPolicyTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/core/metamodel/src/test/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreamsConfigResourceAndPolicyTest.java?rev=1031522&view=auto
==============================================================================
--- incubator/isis/trunk/core/metamodel/src/test/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreamsConfigResourceAndPolicyTest.java
(added)
+++ incubator/isis/trunk/core/metamodel/src/test/java/org/apache/isis/metamodel/config/ConfigurationBuilderResourceStreamsConfigResourceAndPolicyTest.java
Fri Nov  5 11:37:09 2010
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.isis.metamodel.config;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ConfigurationBuilderResourceStreamsConfigResourceAndPolicyTest {
+
+    @Test
+    public void toStringWhenNull() throws Exception {
+        ConfigurationBuilderResourceStreams.ConfigurationResourceAndPolicy configurationResourceAndPolicy
=
+            new ConfigurationBuilderResourceStreams.ConfigurationResourceAndPolicy(null,
null);
+        assertThat(configurationResourceAndPolicy.toString(), is("null{null}"));
+    }
+
+    @Test
+    public void toStringWhenConfigResourceNotNull() throws Exception {
+        ConfigurationBuilderResourceStreams.ConfigurationResourceAndPolicy configurationResourceAndPolicy
=
+            new ConfigurationBuilderResourceStreams.ConfigurationResourceAndPolicy("foo.properties",
null);
+        assertThat(configurationResourceAndPolicy.toString(), is("foo.properties{null}"));
+    }
+
+    @Test
+    public void toStringWhenAllSpecified() throws Exception {
+        ConfigurationBuilderResourceStreams.ConfigurationResourceAndPolicy configurationResourceAndPolicy
=
+            new ConfigurationBuilderResourceStreams.ConfigurationResourceAndPolicy("foo.properties",
+                NotFoundPolicy.CONTINUE);
+        assertThat(configurationResourceAndPolicy.toString(), is("foo.properties{CONTINUE}"));
+    }
+
+}



Mime
View raw message