📄 elementadapter.java
字号:
}
try {
this.propertyMethods.add(getWrapped().getClass().getMethod("name",null));
} catch (NoSuchMethodException e) {
log.debug("Enum doesn't have name method. Huh?",e);
}
}
}
/**
* The JavaBean object wrapped by this Element Node.
*/
private Object wrapped;
/**
* The Parent-JavaBean from which the JavaBean object will be instantiated.
*/
private Object parentOfWrapped;
/**
* The method in the Parent-JavaBean which will create the JavaBean object.
*/
private Method methodToCreateWrapped;
/**
* Needed for any children requests.
*/
protected NodeList nodeListAdapter = null;
/**
*/
protected DOMAdapter config;
private ElementAdapter(Object parentOfWrapped, Method methodToCreateWrapped,
String name, Node parent, int ordinal, DOMAdapter config)
{
super(parent, ordinal);
this.nodeName = name;
this.config = config;
this.parentOfWrapped = parentOfWrapped;
this.methodToCreateWrapped = methodToCreateWrapped;
if (parentOfWrapped != null)
log.debug("Created ElementAdapter for object with parent "
+ parentOfWrapped.getClass().getName() + " of type "
+ methodToCreateWrapped.getReturnType() + ", named:" + name);
}
/**
*/
protected ElementAdapter(Object wrapme, String name, Node parent, int ordinal, DOMAdapter config)
{
super(parent, ordinal);
this.nodeName = name;
this.config = config;
setWrapped(wrapme);
if (wrapme != null)
log.debug("Created ElementAdapter for object of type " + wrapme.getClass().getName() + ", named:" + name);
}
public Object getWrapped()
{
if(wrapped != null)
return wrapped;
if(parent != null && methodToCreateWrapped != null)
{
try
{
setWrapped(methodToCreateWrapped.invoke(parentOfWrapped, emptyArgList));
return wrapped;
}
catch (InvocationTargetException ex)
{
// TODO: Is this the best error message we can report?
ex.printStackTrace();
String message = "InvocationTargetException when invoking " + methodToCreateWrapped + ": " + ex.getTargetException();
throw new RuntimeException(message);
}
catch (Exception ex)
{
// This should never happen because we chose the method for its
// public access and no args.
ex.printStackTrace();
String message = "Exception when invoking " + methodToCreateWrapped + ": " + ex;
throw new RuntimeException(message);
}
}
return null;
}
public void setWrapped(Object wrapped)
{
this.wrapped = wrapped;
}
/**
*/
protected NodeList getNodeListAdapter()
{
if (this.nodeListAdapter == null)
{
if (getWrapped() == null)
{
log.debug("NodeList: returning new Empty_List");
this.nodeListAdapter = EmptyNodeListAdapter.EMPTY_LIST;
}
else if (getWrapped().getClass().isArray())
{
log.debug("NodeList: returning new CollectionNodeListAdapter(base Array)");
this.nodeListAdapter = new CollectionNodeListAdapter(getWrapped());
}
else if (getWrapped() instanceof Collection)
{
log.debug("NodeList: returning new CollectionNodeListAdapter (base Colleciton)");
this.nodeListAdapter = new CollectionNodeListAdapter((Collection)getWrapped());
}
else if (getWrapped() instanceof Map)
{
log.debug("NodeList: returning new MapNodeListAdapter");
this.nodeListAdapter = new MapNodeListAdapter((Map)getWrapped());
}
else if (getWrapped() instanceof Node)
{
log.debug("NodeList: returning new NodeNodeListAdapter");
this.nodeListAdapter = new NodeNodeListAdapter();
}
else if (this.config.shouldConvertToString(getWrapped()))
{
log.debug("NodeList: returning new ToStringNodeListAdapter");
this.nodeListAdapter = new ToStringNodeListAdapter();
}
else if (enumClass!=null && enumClass.isInstance(getWrapped())){
log.debug("NodeList: returning new EnumNodeListAdapter");
this.nodeListAdapter = new EnumNodeListAdapter();
} else {
log.debug("NodeList: returning new MethodNodeListAdapter");
this.nodeListAdapter = new MethodNodeListAdapter();
}
}
return this.nodeListAdapter;
}
/**
*/
public short getNodeType()
{
if (log.isDebugEnabled())
log.debug(this.nodeName + ": getNodeType()");
return ELEMENT_NODE;
}
/**
*/
public String getNodeName()
{
if (log.isDebugEnabled())
log.debug(this.nodeName + ": getNodeName()");
return this.nodeName;
}
/**
* Element nodes do not have node values.
*/
public String getNodeValue() throws DOMException
{
if (log.isDebugEnabled())
log.debug(this.nodeName + ": getNodeValue()");
return null;
}
/**
* Introspect our object and see what child nodes are appropriate.
*/
public NodeList getChildNodes()
{
if (log.isDebugEnabled())
log.debug(this.nodeName + ": getChildNodes()");
return this.getNodeListAdapter();
}
/**
*/
public NamedNodeMap getAttributes()
{
if (log.isDebugEnabled())
log.debug(this.nodeName + ": getAttributes()");
return new NamedNodeMapUnimplemented() {
public int getLength() { return 0; }
};
}
/**
* Since we don't have namespaces, this is the same as getNodeName().
*/
public String getLocalName()
{
if (log.isDebugEnabled())
log.debug(this.nodeName + ": getLocalName()");
return this.getNodeName();
}
public String getBaseURI() {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public short compareDocumentPosition(Node other) throws DOMException {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public String getTextContent() throws DOMException {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public void setTextContent(String textContent) throws DOMException {
//To change body of implemented methods use File | Settings | File Templates.
}
public boolean isSameNode(Node other) {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public String lookupPrefix(String namespaceURI) {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public boolean isDefaultNamespace(String namespaceURI) {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public String lookupNamespaceURI(String prefix) {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public boolean isEqualNode(Node arg) {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public Object getFeature(String feature, String version) {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public Object setUserData(String key, Object data, UserDataHandler handler) {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
public Object getUserData(String key) {
log.info("UnsupportedOperationException Thrown");
throw new UnsupportedOperationException();
}
/**
* @return null if there are no children.
*/
public Node getFirstChild()
{
if (log.isDebugEnabled())
log.debug(this.nodeName + ": getFirstChild()");
NodeList list = this.getNodeListAdapter();
if (list.getLength() > 0)
return this.getNodeListAdapter().item(0);
else
return null;
}
/**
* @return null if there are no children.
*/
public Node getLastChild()
{
if (log.isDebugEnabled())
log.debug(this.nodeName + ": getLastChild()");
NodeList list = this.getNodeListAdapter();
if (list.getLength() > 0)
return list.item(list.getLength()-1);
else
return null;
}
/**
*/
public boolean hasChildNodes()
{
if (log.isDebugEnabled())
log.debug(this.nodeName + ": hasChildNodes()");
NodeList list = this.getNodeListAdapter();
if (list.getLength() > 0)
return true;
else
return false;
}
/**
* The name of the element. For example, in:
* <pre> <elementExample
* id="demo"> ... </elementExample> , </pre>
* <code>tagName</code> has
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -