Example usage for org.apache.commons.jxpath.ri.model NodePointer createAttribute

List of usage examples for org.apache.commons.jxpath.ri.model NodePointer createAttribute

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.ri.model NodePointer createAttribute.

Prototype

public NodePointer createAttribute(JXPathContext context, QName name) 

Source Link

Document

Called to create a non-existing attribute

Usage

From source file:org.eclipse.e4.emf.internal.xpath.NullEStructuralFeaturePointer.java

@Override
public NodePointer createPath(JXPathContext context) {
    NodePointer newParent = parent.createPath(context);
    if (isAttribute()) {
        return newParent.createAttribute(context, getName());
    }/*w ww . jav  a  2s .co m*/
    if (parent instanceof NullPointer && parent.equals(newParent)) {
        throw createBadFactoryException(context.getFactory());
    }
    // Consider these two use cases:
    // 1. The parent pointer of NullPropertyPointer is
    //    a PropertyOwnerPointer other than NullPointer. When we call
    //    createPath on it, it most likely returns itself. We then
    //    take a PropertyPointer from it and get the PropertyPointer
    //    to expand the collection for the corresponding property.
    //
    // 2. The parent pointer of NullPropertyPointer is a NullPointer.
    //    When we call createPath, it may return a PropertyOwnerPointer
    //    or it may return anything else, like a DOMNodePointer.
    //    In the former case we need to do exactly what we did in use
    //    case 1.  In the latter case, we simply request that the
    //    non-property pointer expand the collection by itself.
    if (newParent instanceof EStructuralFeatureOwnerPointer) {
        EStructuralFeatureOwnerPointer pop = (EStructuralFeatureOwnerPointer) newParent;
        newParent = pop.getPropertyPointer();
    }
    return newParent.createChild(context, getName(), getIndex());
}

From source file:org.eclipse.e4.emf.internal.xpath.NullEStructuralFeaturePointer.java

@Override
public NodePointer createPath(JXPathContext context, Object value) {
    NodePointer newParent = parent.createPath(context);
    if (isAttribute()) {
        NodePointer pointer = newParent.createAttribute(context, getName());
        pointer.setValue(value);// w ww.jav a 2 s. c  o  m
        return pointer;
    }
    if (parent instanceof NullPointer && parent.equals(newParent)) {
        throw createBadFactoryException(context.getFactory());
    }
    if (newParent instanceof EStructuralFeatureOwnerPointer) {
        EStructuralFeatureOwnerPointer pop = (EStructuralFeatureOwnerPointer) newParent;
        newParent = pop.getPropertyPointer();
    }
    return newParent.createChild(context, getName(), index, value);
}