polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [4/5] zest-java git commit: api: Initializables can throw Exception
Date Tue, 06 Dec 2016 17:30:11 GMT
api: Initializables can throw Exception


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/ccb54f3a
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/ccb54f3a
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/ccb54f3a

Branch: refs/heads/develop
Commit: ccb54f3a745c318173389b05c1b12355ad67a80a
Parents: 9be87aa
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Dec 5 20:15:59 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Tue Dec 6 09:35:54 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/zest/api/mixin/Initializable.java |  6 ++----
 .../zest/api/mixin/InitializationException.java       | 14 ++------------
 .../org/apache/zest/api/object/ObjectFactory.java     |  5 +++--
 .../org/apache/zest/runtime/composite/MixinModel.java |  4 ++--
 .../org/apache/zest/runtime/object/ObjectModel.java   |  5 +++--
 .../apache/zest/runtime/mixin/InitializableTest.java  |  3 ---
 .../zest/runtime/service/ComplexActivatableTest.java  |  2 --
 .../org/apache/zest/library/alarm/AlarmStatus.java    |  2 --
 .../service/ServiceCircuitBreakerMixin.java           |  2 --
 .../library/rest/client/RequestWriterDelegator.java   |  3 +--
 .../library/rest/client/ResponseReaderDelegator.java  |  3 +--
 .../rest/server/restlet/RequestReaderDelegator.java   |  2 --
 .../rest/server/restlet/ResponseWriterDelegator.java  |  2 --
 .../zest/sample/forum/service/BootstrapData.java      | 13 +------------
 14 files changed, 15 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/core/api/src/main/java/org/apache/zest/api/mixin/Initializable.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/mixin/Initializable.java b/core/api/src/main/java/org/apache/zest/api/mixin/Initializable.java
index 473559f..04c6b91 100644
--- a/core/api/src/main/java/org/apache/zest/api/mixin/Initializable.java
+++ b/core/api/src/main/java/org/apache/zest/api/mixin/Initializable.java
@@ -30,9 +30,7 @@ public interface Initializable
     /**
      * Initialize the fragment
      *
-     * @throws org.apache.zest.api.mixin.InitializationException
-     *          if something went wrong
+     * @throws Exception if something went wrong
      */
-    void initialize()
-        throws InitializationException;
+    void initialize() throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/core/api/src/main/java/org/apache/zest/api/mixin/InitializationException.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/mixin/InitializationException.java
b/core/api/src/main/java/org/apache/zest/api/mixin/InitializationException.java
index 6b3092f..3826779 100644
--- a/core/api/src/main/java/org/apache/zest/api/mixin/InitializationException.java
+++ b/core/api/src/main/java/org/apache/zest/api/mixin/InitializationException.java
@@ -20,7 +20,7 @@
 package org.apache.zest.api.mixin;
 
 /**
- * Thrown when a Fragment or object could not be instantiated.
+ * Thrown when a Fragment or object could not be initialized.
  */
 public class InitializationException
     extends RuntimeException
@@ -31,18 +31,8 @@ public class InitializationException
     {
     }
 
-    public InitializationException( String message )
-    {
-        super( message );
-    }
-
     public InitializationException( String message, Throwable cause )
     {
         super( message, cause );
     }
-
-    public InitializationException( Throwable cause )
-    {
-        super( cause );
-    }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/core/api/src/main/java/org/apache/zest/api/object/ObjectFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/object/ObjectFactory.java b/core/api/src/main/java/org/apache/zest/api/object/ObjectFactory.java
index bb9d7cf..d694c48 100644
--- a/core/api/src/main/java/org/apache/zest/api/object/ObjectFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/object/ObjectFactory.java
@@ -42,9 +42,10 @@ public interface ObjectFactory
     /**
      * Inject an existing instance. Only fields and methods will be called.
      *
-     * @param instance
+     * @param instance instance
+     * @param uses dependencies
      *
-     * @throws ConstructionException
+     * @throws ConstructionException if it was not possible to construct the Object dependencies
      */
     void injectTo( Object instance, Object... uses )
         throws ConstructionException;

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
index cf6af21..621237d 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/MixinModel.java
@@ -139,11 +139,11 @@ public final class MixinModel
             {
                 ( (Initializable) mixin ).initialize();
             }
-            catch( InitializationException e )
+            catch( Exception e )
             {
                 List<Class<?>> compositeType = compositeInstance.types().collect(
Collectors.toList() );
                 String message = "Unable to initialize " + mixinClass + " in composite "
+ compositeType;
-                throw new ConstructionException( message, e );
+                throw new ConstructionException( new InitializationException( message, e
) );
             }
         }
         return mixin;

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java
index e35b840..554a026 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/object/ObjectModel.java
@@ -134,9 +134,10 @@ public final class ObjectModel
             {
                 ( (Initializable) instance ).initialize();
             }
-            catch( InitializationException e )
+            catch( Exception e )
             {
-                throw new ConstructionException( "Unable to initialize " + objectType, e
);
+                String message = "Unable to initialize " + objectType;
+                throw new ConstructionException( new InitializationException( message, e
) );
             }
         }
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/core/runtime/src/test/java/org/apache/zest/runtime/mixin/InitializableTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/mixin/InitializableTest.java
b/core/runtime/src/test/java/org/apache/zest/runtime/mixin/InitializableTest.java
index 87df3a9..c3f7a6c 100644
--- a/core/runtime/src/test/java/org/apache/zest/runtime/mixin/InitializableTest.java
+++ b/core/runtime/src/test/java/org/apache/zest/runtime/mixin/InitializableTest.java
@@ -23,7 +23,6 @@ package org.apache.zest.runtime.mixin;
 import org.junit.Test;
 import org.apache.zest.api.composite.TransientComposite;
 import org.apache.zest.api.mixin.Initializable;
-import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.mixin.Mixins;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
@@ -72,7 +71,6 @@ public class InitializableTest
         boolean ok = false;
 
         public void initialize()
-            throws InitializationException
         {
             ok = true;
         }
@@ -89,7 +87,6 @@ public class InitializableTest
         boolean ok = false;
 
         public void initialize()
-            throws InitializationException
         {
             ok = true;
         }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/core/runtime/src/test/java/org/apache/zest/runtime/service/ComplexActivatableTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/service/ComplexActivatableTest.java
b/core/runtime/src/test/java/org/apache/zest/runtime/service/ComplexActivatableTest.java
index b396a32..c8ada7c 100644
--- a/core/runtime/src/test/java/org/apache/zest/runtime/service/ComplexActivatableTest.java
+++ b/core/runtime/src/test/java/org/apache/zest/runtime/service/ComplexActivatableTest.java
@@ -23,7 +23,6 @@ import org.junit.Test;
 import org.apache.zest.api.activation.ActivatorAdapter;
 import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.mixin.Initializable;
-import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.mixin.Mixins;
 import org.apache.zest.api.property.Property;
 import org.apache.zest.api.service.ServiceComposite;
@@ -83,7 +82,6 @@ public class ComplexActivatableTest
         private SuperType me;
 
         public void initialize()
-                throws InitializationException
         {
             me.greeting().set( "Hello" );
         }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/libraries/alarm/src/main/java/org/apache/zest/library/alarm/AlarmStatus.java
----------------------------------------------------------------------
diff --git a/libraries/alarm/src/main/java/org/apache/zest/library/alarm/AlarmStatus.java
b/libraries/alarm/src/main/java/org/apache/zest/library/alarm/AlarmStatus.java
index a4f9ee9..51a3463 100644
--- a/libraries/alarm/src/main/java/org/apache/zest/library/alarm/AlarmStatus.java
+++ b/libraries/alarm/src/main/java/org/apache/zest/library/alarm/AlarmStatus.java
@@ -26,7 +26,6 @@ import java.util.ResourceBundle;
 import org.apache.zest.api.common.Optional;
 import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.mixin.Initializable;
-import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.mixin.Mixins;
 import org.apache.zest.api.property.Property;
 import org.apache.zest.api.value.ValueComposite;
@@ -99,7 +98,6 @@ public interface AlarmStatus extends ValueComposite
 
         @Override
         public void initialize()
-            throws InitializationException
         {
             if( state.creationDate().get() == null )
             {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/libraries/circuitbreaker/src/main/java/org/apache/zest/library/circuitbreaker/service/ServiceCircuitBreakerMixin.java
----------------------------------------------------------------------
diff --git a/libraries/circuitbreaker/src/main/java/org/apache/zest/library/circuitbreaker/service/ServiceCircuitBreakerMixin.java
b/libraries/circuitbreaker/src/main/java/org/apache/zest/library/circuitbreaker/service/ServiceCircuitBreakerMixin.java
index a00e764..0a01ddd 100644
--- a/libraries/circuitbreaker/src/main/java/org/apache/zest/library/circuitbreaker/service/ServiceCircuitBreakerMixin.java
+++ b/libraries/circuitbreaker/src/main/java/org/apache/zest/library/circuitbreaker/service/ServiceCircuitBreakerMixin.java
@@ -21,7 +21,6 @@ package org.apache.zest.library.circuitbreaker.service;
 
 import org.apache.zest.api.injection.scope.Uses;
 import org.apache.zest.api.mixin.Initializable;
-import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.service.ServiceDescriptor;
 import org.apache.zest.library.circuitbreaker.CircuitBreaker;
 
@@ -40,7 +39,6 @@ public class ServiceCircuitBreakerMixin
 
     @Override
     public void initialize()
-            throws InitializationException
     {
         circuitBreaker = descriptor.metaInfo( CircuitBreaker.class );
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/RequestWriterDelegator.java
----------------------------------------------------------------------
diff --git a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/RequestWriterDelegator.java
b/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/RequestWriterDelegator.java
index d96af5c..cd985d6 100644
--- a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/RequestWriterDelegator.java
+++ b/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/RequestWriterDelegator.java
@@ -25,7 +25,6 @@ import java.util.List;
 import java.util.ResourceBundle;
 import org.apache.zest.api.injection.scope.Structure;
 import org.apache.zest.api.mixin.Initializable;
-import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.structure.Module;
 import org.apache.zest.library.rest.client.spi.RequestWriter;
 import org.restlet.Request;
@@ -48,7 +47,7 @@ public class RequestWriterDelegator
    private Module module;
 
     @Override
-   public void initialize() throws InitializationException
+   public void initialize()
    {
       Logger logger = LoggerFactory.getLogger( getClass() );
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/ResponseReaderDelegator.java
----------------------------------------------------------------------
diff --git a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/ResponseReaderDelegator.java
b/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/ResponseReaderDelegator.java
index c018a39..c9926aa 100644
--- a/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/ResponseReaderDelegator.java
+++ b/libraries/rest-client/src/main/java/org/apache/zest/library/rest/client/ResponseReaderDelegator.java
@@ -25,7 +25,6 @@ import java.util.List;
 import java.util.ResourceBundle;
 import org.apache.zest.api.injection.scope.Structure;
 import org.apache.zest.api.mixin.Initializable;
-import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.structure.Module;
 import org.apache.zest.library.rest.client.spi.ResponseReader;
 import org.restlet.Response;
@@ -45,7 +44,7 @@ public class ResponseReaderDelegator
    private Module module;
 
    @Override
-   public void initialize() throws InitializationException
+   public void initialize()
    {
       Logger logger = LoggerFactory.getLogger( getClass() );
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java
b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java
index 61447d8..cd35901 100644
--- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java
+++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/RequestReaderDelegator.java
@@ -28,7 +28,6 @@ import org.apache.zest.api.identity.Identity;
 import org.apache.zest.api.identity.StringIdentity;
 import org.apache.zest.api.injection.scope.Service;
 import org.apache.zest.api.injection.scope.Structure;
-import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.service.ServiceReference;
 import org.apache.zest.api.structure.Module;
 import org.apache.zest.library.rest.server.spi.RequestReader;
@@ -50,7 +49,6 @@ public class RequestReaderDelegator
     Module module;
 
     public void init( @Service Iterable<ServiceReference<RequestReader>> requestReaderReferences
)
-        throws InitializationException
     {
         Logger logger = LoggerFactory.getLogger( getClass() );
         Identity requestreaderdelegator = new StringIdentity("requestreaderdelegator");

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java
b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java
index 66a17d3..ea5c77c 100644
--- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java
+++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/restlet/ResponseWriterDelegator.java
@@ -27,7 +27,6 @@ import org.apache.zest.api.identity.Identity;
 import org.apache.zest.api.identity.StringIdentity;
 import org.apache.zest.api.injection.scope.Service;
 import org.apache.zest.api.injection.scope.Structure;
-import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.service.ServiceReference;
 import org.apache.zest.api.structure.Module;
 import org.apache.zest.library.rest.server.spi.ResponseWriter;
@@ -47,7 +46,6 @@ public class ResponseWriterDelegator
     Module module;
 
     public void init( @Service Iterable<ServiceReference<ResponseWriter>> resultWriters
)
-        throws InitializationException
     {
         Logger logger = LoggerFactory.getLogger( getClass() );
         Identity responsewriterdelegator = new StringIdentity( "responsewriterdelegator"
);

http://git-wip-us.apache.org/repos/asf/zest-java/blob/ccb54f3a/samples/forum/src/main/java/org/apache/zest/sample/forum/service/BootstrapData.java
----------------------------------------------------------------------
diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/service/BootstrapData.java
b/samples/forum/src/main/java/org/apache/zest/sample/forum/service/BootstrapData.java
index 42153d5..bfba693 100644
--- a/samples/forum/src/main/java/org/apache/zest/sample/forum/service/BootstrapData.java
+++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/service/BootstrapData.java
@@ -22,13 +22,11 @@ package org.apache.zest.sample.forum.service;
 import org.apache.zest.api.activation.ActivatorAdapter;
 import org.apache.zest.api.activation.Activators;
 import org.apache.zest.api.injection.scope.Structure;
-import org.apache.zest.api.mixin.InitializationException;
 import org.apache.zest.api.mixin.Mixins;
 import org.apache.zest.api.service.ServiceComposite;
 import org.apache.zest.api.service.ServiceReference;
 import org.apache.zest.api.unitofwork.NoSuchEntityException;
 import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
 import org.apache.zest.api.unitofwork.UnitOfWorkFactory;
 import org.apache.zest.sample.forum.data.entity.Forums;
 import org.apache.zest.sample.forum.data.entity.Users;
@@ -41,14 +39,12 @@ import org.apache.zest.sample.forum.data.entity.Users;
 public interface BootstrapData
     extends ServiceComposite
 {
-
     void insertInitialData()
         throws Exception;
 
     class Activator
         extends ActivatorAdapter<ServiceReference<BootstrapData>>
     {
-
         @Override
         public void afterActivation( ServiceReference<BootstrapData> activated )
             throws Exception
@@ -87,14 +83,7 @@ public interface BootstrapData
                 unitOfWork.newEntity( Users.class, Users.USERS_ID );
             }
 
-            try
-            {
-                unitOfWork.complete();
-            }
-            catch( UnitOfWorkCompletionException e )
-            {
-                throw new InitializationException( e );
-            }
+            unitOfWork.complete();
         }
     }
 }


Mime
View raw message