You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by ol...@apache.org on 2012/02/22 23:27:37 UTC
svn commit: r1292552 -
/incubator/directmemory/trunk/server/directmemory-server-client/src/main/java/org/apache/directmemory/server/client/AbstractDirectMemoryHttpClient.java
Author: olamy
Date: Wed Feb 22 22:27:36 2012
New Revision: 1292552
URL: http://svn.apache.org/viewvc?rev=1292552&view=rev
Log:
use switch case rather than if else if etcc..
Modified:
incubator/directmemory/trunk/server/directmemory-server-client/src/main/java/org/apache/directmemory/server/client/AbstractDirectMemoryHttpClient.java
Modified: incubator/directmemory/trunk/server/directmemory-server-client/src/main/java/org/apache/directmemory/server/client/AbstractDirectMemoryHttpClient.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/server/directmemory-server-client/src/main/java/org/apache/directmemory/server/client/AbstractDirectMemoryHttpClient.java?rev=1292552&r1=1292551&r2=1292552&view=diff
==============================================================================
--- incubator/directmemory/trunk/server/directmemory-server-client/src/main/java/org/apache/directmemory/server/client/AbstractDirectMemoryHttpClient.java (original)
+++ incubator/directmemory/trunk/server/directmemory-server-client/src/main/java/org/apache/directmemory/server/client/AbstractDirectMemoryHttpClient.java Wed Feb 22 22:27:36 2012
@@ -55,32 +55,26 @@ public abstract class AbstractDirectMemo
protected byte[] getPutContent( DirectMemoryCacheRequest request )
throws DirectMemoryCacheException
{
- // TODO handle various exchange model json raw etc..
- if ( request.getExchangeType() == ExchangeType.JSON )
+ switch ( request.getExchangeType() )
{
- return writer.generateJsonRequest( request ).getBytes();
- }
- else if ( request.getExchangeType() == ExchangeType.JAVA_SERIALIZED_OBJECT )
- {
- try
- {
- return request.getSerializer().serialize( request.getObject() );
- }
- catch ( IOException e )
- {
- throw new DirectMemoryCacheException( e.getMessage(), e );
- }
- }
- else if ( request.getExchangeType() == ExchangeType.TEXT_PLAIN )
- {
- log.error( "{} not implemented yet", ExchangeType.TEXT_PLAIN.getContentType() );
- throw new NotImplementedException();// );
- }
- else
- {
- log.error( "exchange type unknown {}", request.getExchangeType() );
- throw new DirectMemoryCacheException( "exchange type unknown " + request.getExchangeType() );
+ case JSON:
+ return writer.generateJsonRequest( request ).getBytes();
+ case JAVA_SERIALIZED_OBJECT:
+ try
+ {
+ return request.getSerializer().serialize( request.getObject() );
+ }
+ catch ( IOException e )
+ {
+ throw new DirectMemoryCacheException( e.getMessage(), e );
+ }
+ case TEXT_PLAIN:
+ log.error( "{} not implemented yet", ExchangeType.TEXT_PLAIN.getContentType() );
+ throw new NotImplementedException();
+ default:
+ log.error( "exchange type unknown {}", request.getExchangeType() );
+ throw new DirectMemoryCacheException( "exchange type unknown " + request.getExchangeType() );
}
}
@@ -88,46 +82,41 @@ public abstract class AbstractDirectMemo
throws DirectMemoryCacheException
{
- if ( request.getExchangeType() == ExchangeType.JSON )
- {
- return parser.buildResponse( inputStream );
- }
- else if ( request.getExchangeType() == ExchangeType.JAVA_SERIALIZED_OBJECT )
- {
- try
- {
- DirectMemoryCacheResponse response = new DirectMemoryCacheResponse();
- response.setResponse( request.getSerializer().deserialize( IOUtils.toByteArray( inputStream ),
- request.getObjectClass() ) );
- return response;
-
- }
- catch ( IOException e )
- {
- throw new DirectMemoryCacheException( e.getMessage(), e );
- }
- catch ( ClassNotFoundException e )
- {
- throw new DirectMemoryCacheException( e.getMessage(), e );
- }
- catch ( IllegalAccessException e )
- {
- throw new DirectMemoryCacheException( e.getMessage(), e );
- }
- catch ( InstantiationException e )
- {
- throw new DirectMemoryCacheException( e.getMessage(), e );
- }
- }
- else if ( request.getExchangeType() == ExchangeType.TEXT_PLAIN )
- {
- log.error( "{} not implemented yet", ExchangeType.TEXT_PLAIN.getContentType() );
- throw new NotImplementedException();// );
- }
- else
+ switch ( request.getExchangeType() )
{
- log.error( "exchange type unknown {}", request.getExchangeType() );
- throw new DirectMemoryCacheException( "exchange type unknown " + request.getExchangeType() );
+ case JSON:
+ return parser.buildResponse( inputStream );
+ case JAVA_SERIALIZED_OBJECT:
+ try
+ {
+ DirectMemoryCacheResponse response = new DirectMemoryCacheResponse();
+ response.setResponse( request.getSerializer().deserialize( IOUtils.toByteArray( inputStream ),
+ request.getObjectClass() ) );
+ return response;
+
+ }
+ catch ( IOException e )
+ {
+ throw new DirectMemoryCacheException( e.getMessage(), e );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ throw new DirectMemoryCacheException( e.getMessage(), e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new DirectMemoryCacheException( e.getMessage(), e );
+ }
+ catch ( InstantiationException e )
+ {
+ throw new DirectMemoryCacheException( e.getMessage(), e );
+ }
+ case TEXT_PLAIN:
+ log.error( "{} not implemented yet", ExchangeType.TEXT_PLAIN.getContentType() );
+ throw new NotImplementedException();
+ default:
+ log.error( "exchange type unknown {}", request.getExchangeType() );
+ throw new DirectMemoryCacheException( "exchange type unknown " + request.getExchangeType() );
}