[
https://issues.apache.org/jira/browse/DIRMINA-874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13162813#comment-13162813
]
Christian Schwarz edited comment on DIRMINA-874 at 12/5/11 2:55 PM:
--------------------------------------------------------------------
>The fact that we can't distinguish between an absent value and a null value
>being one of them, but it can be addressed.
My provided code is not complete due the lack of time! Maybe its a good idea to
have an getter like this:
<T> T getAttribute(AttributeKey<T> key, T default)
Where 'default' is the value to be returned if the key is absent. E.g. the
OSGi-Preferences are based on this principle, and it is very comfortable to
use.
->
http://www.osgi.org/javadoc/r4v42/org/osgi/service/prefs/Preferences.html#get(java.lang.String,
java.lang.String)
was (Author: christian_schwarz):
>The fact that we can't distinguish between an absent value and a null
value being one of them, but it can be addressed.
My provided code is not complete due the lack of time! Maybe its a good idea to
have an getter like this:
<T> T getAttribute(AttributeKey<T> key, T default)
Where 'default' is the value to be returned if the key is absent. E.g. the
OSGi-Preferences are based on this principle, and it is very comfortable to
use.
-> http://www.osgi.org/javadoc/r4v42/org/osgi/service/prefs/Preferences.html
> Typesafe AttributeKeys
> ----------------------
>
> Key: DIRMINA-874
> URL: https://issues.apache.org/jira/browse/DIRMINA-874
> Project: MINA
> Issue Type: Improvement
> Components: Core
> Affects Versions: 3.0.0-M1
> Reporter: Christian Schwarz
> Attachments: mina3.zip
>
>
> In Mina 2 we can add attributes to a session and get them as well. Because
> IoSession#getAttribute(Object key) returns Object we always have to remember
> what attribute type is associated with the key and cast the result to the
> expected type.
> Mina 2 example:
> final static Object KEY = new AttributeKey(SourceClass.class,"myKey");
> ...
> session.set(KEY,"myAttribute");
> String attributeValue= (String)session.get(KEY);
> Instead of using plain Object-keys, the key type should contain information
> about its attributes. The aim is to get type-safe access to attributes.
> Assume we have the following new AttributeKey-Class:
> /**
> * @parmeter T Type of the referenced Attribute
> */
> class AttributeKey<T> {
> public TypesafeAttributeKey(Class<T> attributeType, String attributeKey){
> ...
> }
> }
> The IoSession should have Attribute related accessors like these:
>
> void setAttribute(AttributeKey<T> key, T value);
> T getAttribute(AttributeKey<T> key);
> So in Mina 3 the example could look like this:
> final static AttributeKey<String> KEY = new
> AttributeKey<String>(String.class,"myKey");
> ...
> session.set(KEY,"myAttribute");
> String attributeValue=session.get(KEY);
> These 2 cases won't compile:
> session.set(KEY,new Date());
> Integer attributeValue=session.get(KEY);
> This pattern would simplify the use of Attributes, because the programmer
> don't have to care about the types and can concentrate on more improtant
> things. In my humble opinion the Objekt keys should be removed at all, i
> don't see the purpose for such unspecific keys.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira