Search in sources :

Example 1 with XmlNamedSubgraph

use of org.eclipse.persistence.jaxb.xmlmodel.XmlNamedSubgraph in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method processSubgraphs.

private Map<String, List<CoreAttributeGroup>> processSubgraphs(List<XmlNamedSubgraph> subgraphs) {
    Map<String, List<CoreAttributeGroup>> subgroups = new HashMap<>();
    // Iterate through once and create all the AttributeGroups
    for (XmlNamedSubgraph next : subgraphs) {
        String type = next.getType();
        if (type == null) {
            type = "java.lang.Object";
        }
        AttributeGroup group = new AttributeGroup(next.getName(), type, false);
        if (subgroups.containsKey(group.getName())) {
            List<CoreAttributeGroup> groups = subgroups.get(group.getName());
            groups.add(group);
        } else {
            List<CoreAttributeGroup> groups = new ArrayList<>(1);
            groups.add(group);
            subgroups.put(group.getName(), groups);
        }
    }
    // Iterate through a second time to populate the groups and set up links.
    for (XmlNamedSubgraph next : subgraphs) {
        List<XmlNamedAttributeNode> attributeNodes = next.getXmlNamedAttributeNode();
        List<CoreAttributeGroup> attributeGroups = subgroups.get(next.getName());
        if (attributeGroups != null) {
            for (CoreAttributeGroup group : attributeGroups) {
                String typeName = next.getType();
                if (typeName == null) {
                    typeName = "java.lang.Object";
                }
                if (group.getTypeName().equals(typeName)) {
                    for (XmlNamedAttributeNode attributeNode : attributeNodes) {
                        if (attributeNode.getSubgraph() == null || attributeNode.getSubgraph().length() == 0) {
                            group.addAttribute(attributeNode.getName());
                        } else {
                            List<CoreAttributeGroup> nestedGroups = subgroups.get(attributeNode.getSubgraph());
                            if (nestedGroups == null || nestedGroups.size() == 0) {
                            // TODO: Exception or check for root level ones on target class
                            } else {
                                group.addAttribute(attributeNode.getName(), nestedGroups.get(0));
                            }
                        }
                    }
                }
            }
        }
    }
    return subgroups;
}
Also used : CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) HashMap(java.util.HashMap) XmlNamedAttributeNode(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedAttributeNode) XmlNamedSubgraph(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedSubgraph) AttributeGroup(org.eclipse.persistence.queries.AttributeGroup) CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 2 with XmlNamedSubgraph

use of org.eclipse.persistence.jaxb.xmlmodel.XmlNamedSubgraph in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method setupAttributeGroups.

private void setupAttributeGroups(JavaClass javaClass) {
    TypeInfo info = this.typeInfo.get(javaClass.getQualifiedName());
    XMLDescriptor descriptor = (XMLDescriptor) info.getDescriptor();
    if (!info.getObjectGraphs().isEmpty()) {
        for (XmlNamedObjectGraph next : info.getObjectGraphs()) {
            AttributeGroup group = descriptor.getAttributeGroup(next.getName());
            Map<String, List<CoreAttributeGroup>> subgraphs = processSubgraphs(next.getXmlNamedSubgraph());
            for (XmlNamedAttributeNode nextAttributeNode : next.getXmlNamedAttributeNode()) {
                if (nextAttributeNode.getSubgraph() == null || nextAttributeNode.getSubgraph().length() == 0) {
                    group.addAttribute(nextAttributeNode.getName());
                } else {
                    List<CoreAttributeGroup> nestedGroups = subgraphs.get(nextAttributeNode.getSubgraph());
                    if (nestedGroups == null || nestedGroups.isEmpty()) {
                        Property property = info.getProperties().get(nextAttributeNode.getName());
                        if (property == null) {
                            // if there's no property associated with the attributeNode, just ignore it
                            continue;
                        }
                        JavaClass cls = property.getActualType();
                        TypeInfo referenceType = typeInfo.get(cls.getQualifiedName());
                        if (referenceType != null) {
                            AttributeGroup targetGroup = (AttributeGroup) referenceType.getDescriptor().getAttributeGroup(nextAttributeNode.getSubgraph());
                            group.addAttribute(nextAttributeNode.getName(), targetGroup);
                        } else {
                        // TODO: Exception
                        }
                    } else {
                        if (nestedGroups.size() == 1) {
                            group.addAttribute(nextAttributeNode.getName(), nestedGroups.get(0));
                        } else {
                            group.addAttribute(nextAttributeNode.getName(), nestedGroups);
                        }
                    }
                }
            }
            for (XmlNamedSubgraph nextSubclass : next.getXmlNamedSubclassGraph()) {
                AttributeGroup subclassGroup = new AttributeGroup(next.getName(), nextSubclass.getType(), true);
                group.getSubClassGroups().put(nextSubclass.getType(), subclassGroup);
                for (XmlNamedAttributeNode nextAttributeNode : nextSubclass.getXmlNamedAttributeNode()) {
                    if (nextAttributeNode.getSubgraph() == null || nextAttributeNode.getSubgraph().length() == 0) {
                        subclassGroup.addAttribute(nextAttributeNode.getName());
                    } else {
                        List<CoreAttributeGroup> nestedGroups = subgraphs.get(nextAttributeNode.getSubgraph());
                        if (nestedGroups == null || nestedGroups.isEmpty()) {
                            Property property = info.getProperties().get(nextAttributeNode.getName());
                            JavaClass cls = property.getActualType();
                            TypeInfo referenceType = typeInfo.get(cls.getQualifiedName());
                            if (referenceType != null) {
                                AttributeGroup targetGroup = (AttributeGroup) referenceType.getDescriptor().getAttributeGroup(nextAttributeNode.getSubgraph());
                                subclassGroup.addAttribute(nextAttributeNode.getName(), targetGroup);
                            } else {
                            // TODO: Exception
                            }
                        } else {
                            if (nestedGroups.size() == 1) {
                                subclassGroup.addAttribute(nextAttributeNode.getName(), nestedGroups.get(0));
                            } else {
                                subclassGroup.addAttribute(nextAttributeNode.getName(), nestedGroups);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) XmlNamedObjectGraph(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedObjectGraph) XmlNamedAttributeNode(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedAttributeNode) AttributeGroup(org.eclipse.persistence.queries.AttributeGroup) CoreAttributeGroup(org.eclipse.persistence.core.queries.CoreAttributeGroup) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) XmlNamedSubgraph(org.eclipse.persistence.jaxb.xmlmodel.XmlNamedSubgraph) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Aggregations

ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 CoreAttributeGroup (org.eclipse.persistence.core.queries.CoreAttributeGroup)2 XmlNamedAttributeNode (org.eclipse.persistence.jaxb.xmlmodel.XmlNamedAttributeNode)2 XmlNamedSubgraph (org.eclipse.persistence.jaxb.xmlmodel.XmlNamedSubgraph)2 AttributeGroup (org.eclipse.persistence.queries.AttributeGroup)2 HashMap (java.util.HashMap)1 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)1 XmlNamedObjectGraph (org.eclipse.persistence.jaxb.xmlmodel.XmlNamedObjectGraph)1 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)1