Search in sources :

Example 1 with XmlJoinNodes

use of org.eclipse.persistence.oxm.annotations.XmlJoinNodes in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method processXmlJoinNodes.

/**
 * Process XmlJoinNode(s) for a given Property. An
 * org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNode(s) will be
 * created/populated using the annotation, and set on the Property for later
 * processing.
 *
 * It is assumed that for a single join node XmlJoinNode will be used, and
 * for multiple join nodes XmlJoinNodes will be used.
 *
 * @param property
 * Property that may contain @XmlJoinNodes/@XmlJoinNode
 */
private void processXmlJoinNodes(Property property) {
    List<org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode> xmlJoinNodeList;
    org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode xmlJoinNode;
    org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes xmlJoinNodes;
    // handle XmlJoinNodes
    if (helper.isAnnotationPresent(property.getElement(), XmlJoinNodes.class)) {
        xmlJoinNodeList = new ArrayList<>();
        for (XmlJoinNode xmlJN : ((XmlJoinNodes) helper.getAnnotation(property.getElement(), XmlJoinNodes.class)).value()) {
            xmlJoinNode = new org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode();
            xmlJoinNode.setXmlPath(xmlJN.xmlPath());
            xmlJoinNode.setReferencedXmlPath(xmlJN.referencedXmlPath());
            xmlJoinNodeList.add(xmlJoinNode);
        }
        xmlJoinNodes = new org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes();
        xmlJoinNodes.setXmlJoinNode(xmlJoinNodeList);
        property.setXmlJoinNodes(xmlJoinNodes);
    } else // handle XmlJoinNode
    if (helper.isAnnotationPresent(property.getElement(), XmlJoinNode.class)) {
        XmlJoinNode xmlJN = (XmlJoinNode) helper.getAnnotation(property.getElement(), XmlJoinNode.class);
        xmlJoinNode = new org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode();
        xmlJoinNode.setXmlPath(xmlJN.xmlPath());
        xmlJoinNode.setReferencedXmlPath(xmlJN.referencedXmlPath());
        xmlJoinNodeList = new ArrayList<>();
        xmlJoinNodeList.add(xmlJoinNode);
        xmlJoinNodes = new org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes();
        xmlJoinNodes.setXmlJoinNode(xmlJoinNodeList);
        property.setXmlJoinNodes(xmlJoinNodes);
    }
}
Also used : ArrayList(java.util.ArrayList) XmlJoinNodes(org.eclipse.persistence.oxm.annotations.XmlJoinNodes) XmlJoinNode(org.eclipse.persistence.oxm.annotations.XmlJoinNode)

Example 2 with XmlJoinNodes

use of org.eclipse.persistence.oxm.annotations.XmlJoinNodes in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method buildChoiceProperty.

/**
 * Build a new 'choice' property. Here, we flag a new property as a 'choice'
 * and create/set an XmlModel XmlElements object based on the @XmlElements
 * annotation.
 *
 * Validation and building of the XmlElement properties will be done during
 * finalizeProperties in the processChoiceProperty method.
 */
private Property buildChoiceProperty(JavaHasAnnotations javaHasAnnotations) {
    Property choiceProperty = new Property(helper);
    choiceProperty.setChoice(true);
    boolean isIdRef = helper.isAnnotationPresent(javaHasAnnotations, XmlIDREF.class);
    choiceProperty.setIsXmlIdRef(isIdRef);
    // build an XmlElement to set on the Property
    org.eclipse.persistence.jaxb.xmlmodel.XmlElements xmlElements = new org.eclipse.persistence.jaxb.xmlmodel.XmlElements();
    XmlElement[] elements = ((XmlElements) helper.getAnnotation(javaHasAnnotations, XmlElements.class)).value();
    for (XmlElement next : elements) {
        org.eclipse.persistence.jaxb.xmlmodel.XmlElement xmlElement = new org.eclipse.persistence.jaxb.xmlmodel.XmlElement();
        xmlElement.setDefaultValue(next.defaultValue());
        xmlElement.setName(next.name());
        xmlElement.setNamespace(next.namespace());
        xmlElement.setNillable(next.nillable());
        xmlElement.setRequired(next.required());
        xmlElement.setType(next.type().getName());
        xmlElements.getXmlElement().add(xmlElement);
    }
    choiceProperty.setXmlElements(xmlElements);
    // handle XmlElementsJoinNodes
    if (helper.isAnnotationPresent(javaHasAnnotations, XmlElementsJoinNodes.class)) {
        org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes xmlJoinNodes;
        org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode xmlJoinNode;
        List<org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes> xmlJoinNodesList = new ArrayList<>();
        List<org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode> xmlJoinNodeList = null;
        for (XmlJoinNodes xmlJNs : ((XmlElementsJoinNodes) helper.getAnnotation(javaHasAnnotations, XmlElementsJoinNodes.class)).value()) {
            xmlJoinNodeList = new ArrayList<>();
            for (XmlJoinNode xmlJN : xmlJNs.value()) {
                xmlJoinNode = new org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode();
                xmlJoinNode.setXmlPath(xmlJN.xmlPath());
                xmlJoinNode.setReferencedXmlPath(xmlJN.referencedXmlPath());
                xmlJoinNodeList.add(xmlJoinNode);
            }
            if (xmlJoinNodeList.size() > 0) {
                xmlJoinNodes = new org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes();
                xmlJoinNodes.setXmlJoinNode(xmlJoinNodeList);
                xmlJoinNodesList.add(xmlJoinNodes);
            }
        }
        choiceProperty.setXmlJoinNodesList(xmlJoinNodesList);
    }
    return choiceProperty;
}
Also used : XmlElementsJoinNodes(org.eclipse.persistence.oxm.annotations.XmlElementsJoinNodes) ArrayList(java.util.ArrayList) XmlJoinNodes(org.eclipse.persistence.oxm.annotations.XmlJoinNodes) XmlJoinNode(org.eclipse.persistence.oxm.annotations.XmlJoinNode) XmlElements(jakarta.xml.bind.annotation.XmlElements) XmlElement(jakarta.xml.bind.annotation.XmlElement) XmlProperty(org.eclipse.persistence.oxm.annotations.XmlProperty)

Aggregations

ArrayList (java.util.ArrayList)2 XmlJoinNode (org.eclipse.persistence.oxm.annotations.XmlJoinNode)2 XmlJoinNodes (org.eclipse.persistence.oxm.annotations.XmlJoinNodes)2 XmlElement (jakarta.xml.bind.annotation.XmlElement)1 XmlElements (jakarta.xml.bind.annotation.XmlElements)1 XmlElementsJoinNodes (org.eclipse.persistence.oxm.annotations.XmlElementsJoinNodes)1 XmlProperty (org.eclipse.persistence.oxm.annotations.XmlProperty)1