public class AdapterFactory extends Object
19
1
0
7
8
4
300
105
By extending the StringAdapter and overriding its normal behavior we can
create a custom Date formatter:
public static class CustomDateAdapter extends StringAdapter {
protected String getStringValue() {
Date date = (Date)getPropertyValue();
return DateFormat.getTimeInstance( DateFormat.FULL ).format( date );
}
}
Producing output like:
12:02:54 AM CDT
The StringAdapter (which is normally invoked only to adapt String values)
is a useful base for these kinds of customizations and can produce
structured XML output as well as plain text by setting its parseStringAsXML()
property to true.
See provided examples.| Constructor and Description |
|---|
AdapterFactory() |
| Modifier and Type | Method and Description |
|---|---|
Document |
adaptDocument(String propertyName,
Object propertyValue)
Create a top level Document adapter for the specified Java object.
|
Node |
adaptNode(AdapterNode parent,
String propertyName,
Object value)
Create an Node adapter for a child element.
|
Node |
adaptNullValue(AdapterNode parent,
String propertyName)
Create an appropriate adapter for a null value.
|
Class |
getAdapterForValue(Object value) |
NamedNodeMap |
proxyNamedNodeMap(AdapterNode parent,
NamedNodeMap nnm) |
Node |
proxyNode(AdapterNode parent,
Node node)
Construct a proxy adapter for a value that is an existing DOM Node.
|
void |
registerAdapterType(Class type,
Class adapterType)
Register an adapter type for a Java class type.
|
public void registerAdapterType(Class type, Class adapterType)
type - the Java class type which is to be handled by the adapter.adapterType - The adapter class, which implements AdapterNode.public Document adaptDocument(String propertyName, Object propertyValue) throws IllegalAccessException, InstantiationException
propertyName - The name of the root document elementIllegalAccessExceptionInstantiationExceptionpublic Node adaptNode(AdapterNode parent, String propertyName, Object value)
adaptDocument( String, Object )public Node proxyNode(AdapterNode parent, Node node)
public NamedNodeMap proxyNamedNodeMap(AdapterNode parent, NamedNodeMap nnm)
public Node adaptNullValue(AdapterNode parent, String propertyName)
parent - propertyName - Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.