Libraries updates for extensions methods

Daniel Latrémolière daniel.latremoliere at gmail.com
Mon Aug 13 07:16:31 PDT 2012


Are you planning to update all relevant JDK libraries with extensions 
methods, even parts without parallelism but with large interfaces and 
repetitive methods like org.w3c.dom.*?

A same DOM node can support multiple interfaces like some interfaces of 
DOM Core, DOM Traversal and Range, DOM Load and Store, etc. Many of the 
interfaces have repetitive methods.
It would also allow the big table at the beginning of Node javadoc to be 
written in sub-interface extensions methods and not in implementation 
classes.
It would not be a big change in Java world, but could be seen as cleaner 
code (in my opinion), which is always better, even only when debugging.

Thanks,
Daniel.

|public interface Node {
     // NodeType
     public static final short ELEMENT_NODE = 1;
     public static final short ATTRIBUTE_NODE = 2;
     public static final short TEXT_NODE = 3;
     public static final short CDATA_SECTION_NODE = 4;
     public static final short ENTITY_REFERENCE_NODE = 5;
     public static final short ENTITY_NODE = 6;
     public static final short PROCESSING_INSTRUCTION_NODE = 7;
     public static final short COMMENT_NODE = 8;
     public static final short DOCUMENT_NODE = 9;
     public static final short DOCUMENT_TYPE_NODE = 10;
     public static final short DOCUMENT_FRAGMENT_NODE = 11;
     public static final short NOTATION_NODE = 12;
     public String getNodeName();
     public String getNodeValue() throws DOMException;
     public void setNodeValue(String nodeValue) throws DOMException;
     public short getNodeType();
     public Node getParentNode();
     public NodeList getChildNodes();
     public Node getFirstChild();
     public Node getLastChild();
     public Node getPreviousSibling();
     public Node getNextSibling();
     public NamedNodeMap getAttributes();
     public Document getOwnerDocument();
     public Node insertBefore(Node newChild, Node refChild) throws 
DOMException;
     public Node replaceChild(Node newChild, Node oldChild) throws 
DOMException;
     public Node removeChild(Node oldChild) throws DOMException;
     public Node appendChild(Node newChild) throws DOMException;
     public boolean hasChildNodes();
     public Node cloneNode(boolean deep);
     public void normalize();
     public boolean isSupported(String feature, String version);
     public String getNamespaceURI();
     public String getPrefix();
     public void setPrefix(String prefix) throws DOMException;
     public String getLocalName();
     public boolean hasAttributes();
}|

A subinterface, like an attribute, add new abstract methods:
|public interface Attr extends Node {
     public String getName();
     public boolean getSpecified();
     public String getValue();
     public void setValue(String value) throws DOMException;
     public Element getOwnerElement();
}
|
But Attribute define default behaviour for many superinterface methods 
and this behaviour can be expressed with extension methods:
|public interface Attr extends Node {
     public String getName();
     public boolean getSpecified();
     public String getValue();
     public void setValue(String value) throws DOMException;
     public Element getOwnerElement();
     public default String getNodeName() {
         return getName();
     }
     public ||default ||String getNodeValue() throws DOMException {
||return ||getValue();
     }
     public ||default ||void setNodeValue(String nodeValue) throws 
DOMException {
         setValue(nodeValue);
     }
     public ||default ||short getNodeType() {
         return Node.ATTRIBUTE_NODE;
     }
     public ||default ||Node getParentNode() {
         return getOwnerElement();
     }
     public ||default ||NodeList getChildNodes() {
         return EMPTY_NODE_LIST;
     }
     public ||default ||Node getFirstChild() {
         return null;
     }
     public ||default ||Node getLastChild() {
         return null;
     }
     public ||default ||NamedNodeMap getAttributes() {
         return null;
     }
     public ||default ||Node insertBefore(Node newChild, Node refChild) 
throws DOMException {
         throw new DOMException();
     }
     public ||default ||Node replaceChild(Node newChild, Node oldChild) 
throws DOMException {
         throw new DOMException();
     }
     public ||default ||Node removeChild(Node oldChild) throws 
DOMException {
         throw new DOMException();
     }
     public ||default ||Node appendChild(Node newChild) throws 
DOMException {
         throw new DOMException();
     }
     public ||default ||boolean hasChildNodes() {
         return false;
     }
     public ||default ||void normalize() {
     }
     public ||default ||boolean hasAttributes() {
         return false;
     }
}|


More information about the lambda-dev mailing list