You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2011/04/01 01:15:09 UTC
svn commit: r1087480 - in
/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal:
IOOperation.java TapestryInternalUtils.java
Author: hlship
Date: Thu Mar 31 23:15:08 2011
New Revision: 1087480
URL: http://svn.apache.org/viewvc?rev=1087480&view=rev
Log:
TAP5-73: Add an IOOperation interface (like Runnable, but throws IOException) and a utility method to execute such an operation with an OperationTracker
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/IOOperation.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/IOOperation.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/IOOperation.java?rev=1087480&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/IOOperation.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/IOOperation.java Thu Mar 31 23:15:08 2011
@@ -0,0 +1,27 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// 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 org.apache.tapestry5.internal;
+
+import java.io.IOException;
+
+/**
+ * An operation that may throw an IOException.
+ *
+ * @asince 5.3.0
+ */
+public interface IOOperation
+{
+ void perform() throws IOException;
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java?rev=1087480&r1=1087479&r2=1087480&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java Thu Mar 31 23:15:08 2011
@@ -31,7 +31,9 @@ import org.apache.tapestry5.PropertyCond
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.func.F;
import org.apache.tapestry5.func.Mapper;
+import org.apache.tapestry5.internal.util.Holder;
import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.ioc.Orderable;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
@@ -597,4 +599,29 @@ public class TapestryInternalUtils
return dotx < 0 ? "" : fileName.substring(dotx + 1);
}
+
+ /** Performs an operation and re-throws the IOException that may occur. */
+ public static void performIO(OperationTracker tracker, String description, final IOOperation operation)
+ throws IOException
+ {
+ final Holder<IOException> exceptionHolder = Holder.create();
+
+ tracker.run(description, new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ operation.perform();
+ }
+ catch (IOException ex)
+ {
+ exceptionHolder.put(ex);
+ }
+ }
+ });
+
+ if (exceptionHolder.hasValue())
+ throw exceptionHolder.get();
+ }
}