com.webobjects.webservices.support.xml
Class WOStringKeyMap
java.lang.Object
|
+--java.util.AbstractMap
|
+--java.util.HashMap
|
+--com.webobjects.webservices.support.xml.WOStringKeyMap
- All Implemented Interfaces:
- Cloneable, Map, NSKeyValueCoding, NSKeyValueCodingAdditions, Serializable
- public class WOStringKeyMap
- extends HashMap
- implements NSKeyValueCoding, NSKeyValueCodingAdditions
This class is a subclass of java.util.HashMap
designed to generate XML in which
the element name is the key's value and the element's content is the object mapped to the key.
Since a typical HashMap supports keys of any type, it generates XML with key value pairs and
synthetic element names. The WOStringKeyMap only accepts keys of type java.lang.String
which
contain only characters valid in an XML element name.
This class also implements the NSKeyValueCoding interface.
- See Also:
- Serialized Form
Methods inherited from class java.util.HashMap |
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values |
WOStringKeyMap
public WOStringKeyMap()
WOStringKeyMap
public WOStringKeyMap(int capacity)
WOStringKeyMap
public WOStringKeyMap(Map m)
WOStringKeyMap
public WOStringKeyMap(NSDictionary d)
- Create a WOStringKeyMap and initialize values from
d
. If NSKeyValueCoding.NullValue
appears as a value in d
, it will be replaced with null
.
- Parameters:
d
- an NSDictionary
dictionary
public NSDictionary dictionary()
- Create and return an NSDictionary containing the keys and values in the receiver. If there
are any
null
values in the receiver, they will be replaced by NSKeyValueCoding.NullValue.
- Returns:
- an NSDictionary
takeValueForKey
public void takeValueForKey(Object value,
String key)
- Description copied from interface:
NSKeyValueCoding
- Sets the value for the property identified by
key
to value
.
The default implementation provided by NSKeyValueCoding.DefaultImplementation
works as follows:
- Searches for a public accessor method of the form
set
Key, and invokes it if there is one.
- If a public accessor method is not found, searches for a
private accessor method of the form
_set
Key,
and invokes it if there is one.
- If an accessor method is not found and the static method
canAccessFieldsDirectly
returns true
, searches for a
field based on key
and sets its value directly.
For the key "lastName", this would be _lastName
, _isLastName
, lastName
, or isLastName
.
- If the type of the
value
argument is not compatible with the underlying field or method parameter, the default implementation will make an effort to
convert between different Java numeric types (Integer, Double, BigDecimal, etc) as well as between Boolean and Number (true = 1, false = 0). If any other
conversion would be necessary, an exception is thrown.
- If neither an accessor method nor a field is found,
it is an error condition. It invokes
handleTakeValueForUnboundKey
if the object implements NSKeyValueCoding.ErrorHandling or throws
NSKeyValueCoding.UnknownKeyException if the object does not.
Note: : The default implementations
have significant performance optimizations. To benefit from them,
implement NSKeyValueCoding on a custom class as shown above by using
the methods in NSKeyValueCoding. DefaultImplementation, or if
your class inherits from an WebObjects class that implements
NSKeyValueCoding, do not override the inherited implementation.
Using a custom implementation incurs significant
performance penalties.
- Specified by:
takeValueForKey
in interface NSKeyValueCoding
- Following copied from interface:
com.webobjects.foundation.NSKeyValueCoding
- Parameters:
value
- the new value for the property named by key
key
- identifies the property to change- Throws:
NSKeyValueCoding.UnknownKeyException
- if key
cannot be found on the object this method was invoked upon.- See Also:
NSKeyValueCoding.NullValue
,
NSKeyValueCoding.valueForKey(java.lang.String)
,
NSKeyValueCoding.DefaultImplementation
,
NSKeyValueCoding.ErrorHandling
,
NSKeyValueCoding.ErrorHandling.handleTakeValueForUnboundKey(java.lang.Object, java.lang.String)
takeValueForKeyPath
public void takeValueForKeyPath(Object value,
String keyPath)
- Description copied from interface:
NSKeyValueCodingAdditions
- Sets the value for the property identified by
keyPath
to value
. A key path has the form relationship.property
(with one or more relationships); for example "movieRole.roleName"
or "movieRole.talent.lastName". The default implementation of
this method (provided by NSKeyValueCodingAdditions.DefaultImplementation)
gets the destination object for each relationship using valueForKey
,
and sends the final object a takeValueForKey
message with value
and property
.
- Specified by:
takeValueForKeyPath
in interface NSKeyValueCodingAdditions
- Following copied from interface:
com.webobjects.foundation.NSKeyValueCodingAdditions
- Parameters:
value
- the property identified by keyPath
is set to thiskeyPath
- identifies the property of an object- See Also:
NSKeyValueCoding.takeValueForKey(java.lang.Object, java.lang.String)
,
NSKeyValueCodingAdditions.valueForKeyPath(java.lang.String)
,
NSKeyValueCodingAdditions.DefaultImplementation
valueForKey
public Object valueForKey(String key)
- Description copied from interface:
NSKeyValueCoding
- Retrieves the value of the property named by
key
.
The default implementation provided by NSKeyValueCoding.DefaultImplementation
works as follows:
- Searches for a public accessor method based on
key
. For
example, with a key of "lastName", the method looks for a method named
getLastName, lastName, or isLastName.
- If a public accessor method is not found, searches for a private
accessor method based on key (a method preceded by an underbar).
For example, with a key of "lastName", the method
looks for a method named _getLastName, _lastName, or _isLastName
- If an accessor method is not found and the static method
canAccessFieldsDirectly
returns true
, the method searches
for a field based on key
and returns its value
directly. For the key "lastName", this would be _lastName, _isLastName, lastName, or isLastName.
- If neither an accessor method nor a field is found,
the method invokes handleQueryWithUnboundKey (defined in
NSKeyValueCoding.ErrorHandling).
Note: The default implementations have significant performance optimizations.
To benefit from them, implement NSKeyValueCoding on a custom
class as shown above by using the methods in
NSKeyValueCoding.DefaultImplementation, or if
your class inherits from an WebObjects class that implements
NSKeyValueCoding, do not override the inherited implementation.
Using a custom implementation incurs significant performance
penalties.
- Specified by:
valueForKey
in interface NSKeyValueCoding
- Following copied from interface:
com.webobjects.foundation.NSKeyValueCoding
- Parameters:
key
- identifies the property to retrieve- Returns:
- the value of the property identified by
key
. Depending on the object you invoke this method upon, null
may be replaced with NullValue
- Throws:
NSKeyValueCoding.UnknownKeyException
- if key
cannot be found on the object this method was invoked upon.- See Also:
NSKeyValueCoding.NullValue
,
NSKeyValueCoding.takeValueForKey(java.lang.Object, java.lang.String)
,
NSKeyValueCoding.DefaultImplementation
,
NSKeyValueCoding.ErrorHandling
,
NSKeyValueCoding.ErrorHandling.handleQueryWithUnboundKey(java.lang.String)
valueForKeyPath
public Object valueForKeyPath(String keyPath)
- Description copied from interface:
NSKeyValueCodingAdditions
- Retrieves the value of a property of the object at the end of the key path (a key path is a string of the form "key1.key2").
A key path has the form relationship.property
(with one or more relationships); for example "movieRole.roleName"
or "movieRole.talent.lastName". The default implementation of this
method (provided by NSKeyValueCodingAdditions.DefaultImplementation)
gets the destination object for each relationship using
valueForKey
,
and returns the result of a valueForKey
message to the final
object.
- Specified by:
valueForKeyPath
in interface NSKeyValueCodingAdditions
- Following copied from interface:
com.webobjects.foundation.NSKeyValueCodingAdditions
- Parameters:
keyPath
- the keypath to evaluate- Returns:
- the value for the derived property identified by
keyPath
- See Also:
NSKeyValueCoding.valueForKey(java.lang.String)
,
NSKeyValueCodingAdditions.takeValueForKeyPath(java.lang.Object, java.lang.String)
,
NSKeyValueCodingAdditions.DefaultImplementation
Copyright © 2003 Apple Computer, Inc.