Author: simonetripodi
Date: Fri Feb 24 14:07:51 2012
New Revision: 1293260
URL: http://svn.apache.org/viewvc?rev=1293260&view=rev
Log:
[DIRECTMEMORY-71] SerializerFactory#createNewSerializer( Class<S>|String )
should throw appropriate exceptions instead of returning null
Added:
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerNotFoundException.java
(with props)
Modified:
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java
Modified:
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java
URL:
http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java?rev=1293260&r1=1293259&r2=1293260&view=diff
==============================================================================
---
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java
(original)
+++
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java
Fri Feb 24 14:07:51 2012
@@ -19,6 +19,8 @@ package org.apache.directmemory.serializ
* under the License.
*/
+import static java.lang.String.format;
+
import java.util.Iterator;
import static java.util.ServiceLoader.load;
@@ -53,6 +55,7 @@ public final class SerializerFactory
}
public static <S extends Serializer> S createNewSerializer( Class<S>
serializer )
+ throws SerializerNotFoundException
{
Iterator<Serializer> serializers = load( Serializer.class,
serializer.getClassLoader() ).iterator();
@@ -74,15 +77,17 @@ public final class SerializerFactory
}
}
- return null;
+ throw new SerializerNotFoundException( serializer );
}
public static Serializer createNewSerializer( String serializerClassName )
+ throws SerializerNotFoundException
{
return createNewSerializer( serializerClassName,
SerializerFactory.class.getClassLoader() );
}
public static Serializer createNewSerializer( String serializerClassName,
ClassLoader classLoader )
+ throws SerializerNotFoundException
{
Class<?> anonSerializerClass;
try
@@ -91,7 +96,7 @@ public final class SerializerFactory
}
catch ( ClassNotFoundException e )
{
- return null;
+ throw new SerializerNotFoundException( serializerClassName );
}
if ( Serializer.class.isAssignableFrom( anonSerializerClass ) )
@@ -102,7 +107,8 @@ public final class SerializerFactory
return createNewSerializer( serializerClass );
}
- return null;
+ throw new IllegalArgumentException( format( "Class %s is not a valid
Serializer type",
+
anonSerializerClass.getName() ) );
}
/**
Added:
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerNotFoundException.java
URL:
http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerNotFoundException.java?rev=1293260&view=auto
==============================================================================
---
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerNotFoundException.java
(added)
+++
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerNotFoundException.java
Fri Feb 24 14:07:51 2012
@@ -0,0 +1,43 @@
+package org.apache.directmemory.serialization;
+
+/*
+ * 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.
+ */
+
+import static java.lang.String.format;
+
+public final class SerializerNotFoundException
+ extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5095679349348496962L;
+
+ public SerializerNotFoundException( String serializerClassName )
+ {
+ super( format( "Serializer of type '%s' has not been found in the
current ClassLoader" ) );
+ }
+
+ public SerializerNotFoundException( Class<?> serializerType )
+ {
+ this( serializerType.getName() );
+ }
+
+}
Propchange:
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerNotFoundException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerNotFoundException.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerNotFoundException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain