You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by James Carman <ja...@carmanconsulting.com> on 2009/06/16 03:58:10 UTC
ContextFactory switch statements...
In the code for org.apache.webbeans.context.ContextFactory, we currently have:
switch (type.getName())
{
case 0:
context = getRequestContext();
break;
case 1:
context = getSessionContext();
break;
case 2:
context = getApplicationContext();
break;
case 3:
context = getConversationContext();
break;
case 4:
context = getDependentContext();
break;
default:
throw new IllegalArgumentException("There is no such a
standard context with name id=" + type.getName());
}
This should be changed to (the Java language supports switching on enum values):
switch (type)
{
case REQUEST:
context = getRequestContext();
break;
case SESSION:
context = getSessionContext();
break;
case APPLICATION:
context = getApplicationContext();
break;
case CONVERSATION:
context = getConversationContext();
break;
case DEPENDENT:
context = getDependentContext();
break;
default:
throw new IllegalArgumentException("There is no such a
standard context with name id=" + type.getName());
}
This is much more readable.
Re: ContextFactory switch statements...
Posted by Gurkan Erdogdu <gu...@yahoo.com>.
Yes. Please create a jira and attach patch :)
Thanks;
--Gurkan
________________________________
From: James Carman <ja...@carmanconsulting.com>
To: openwebbeans-dev@incubator.apache.org
Sent: Tuesday, June 16, 2009 4:58:10 AM
Subject: ContextFactory switch statements...
In the code for org.apache.webbeans.context.ContextFactory, we currently have:
switch (type.getName())
{
case 0:
context = getRequestContext();
break;
case 1:
context = getSessionContext();
break;
case 2:
context = getApplicationContext();
break;
case 3:
context = getConversationContext();
break;
case 4:
context = getDependentContext();
break;
default:
throw new IllegalArgumentException("There is no such a
standard context with name id=" + type.getName());
}
This should be changed to (the Java language supports switching on enum values):
switch (type)
{
case REQUEST:
context = getRequestContext();
break;
case SESSION:
context = getSessionContext();
break;
case APPLICATION:
context = getApplicationContext();
break;
case CONVERSATION:
context = getConversationContext();
break;
case DEPENDENT:
context = getDependentContext();
break;
default:
throw new IllegalArgumentException("There is no such a
standard context with name id=" + type.getName());
}
This is much more readable.