Search in sources :

Example 31 with ChildDefinition

use of eu.esdihumboldt.hale.common.schema.model.ChildDefinition in project hale by halestudio.

the class PropertyResolver method analyzeSpecialQueryChildDefinition.

/**
 * this method searches for the indices given from the querypath inside the
 * instance-definition-tree the indices must be children in order to their
 * appearance in the path. only groups may be between them. the method
 * writes the found paths into the cache
 *
 * @param children a list of Childdefinitions from the rootdefinition of the
 *            instance-definition-tree
 * @param path the list of QNames split up from the original querypath
 * @param qdi the cacheindex produced from the instance root definition and
 *            the querypath
 */
private static void analyzeSpecialQueryChildDefinition(Collection<? extends ChildDefinition<?>> children, List<QName> path, QueryDefinitionIndex qdi) {
    QName current = path.get(0);
    Queue<QueueDefinitionItem> propertyqueue = new LinkedList<QueueDefinitionItem>();
    Iterator<? extends ChildDefinition<?>> childIterator = children.iterator();
    while (childIterator.hasNext()) {
        ChildDefinition<?> child = childIterator.next();
        QueueDefinitionItem queueItem = new QueueDefinitionItem(child, child.getName());
        propertyqueue.add(queueItem);
    }
    while (!propertyqueue.isEmpty()) {
        QueueDefinitionItem currentItem = propertyqueue.poll();
        if (compareQName(current, currentItem.getDefinition().getName()) && isProperty(currentItem.getDefinition())) {
            for (int i = 1; i < path.size(); i++) {
                currentItem = analyzeSubChild(currentItem, path.get(i));
                if (currentItem == null) {
                    break;
                }
            }
            if (currentItem != null) {
                definitioncache.get(qdi).add(currentItem.qNamesToString());
            }
        } else if (isGroup(currentItem.getDefinition())) {
            Iterator<? extends ChildDefinition<?>> tempit;
            tempit = currentItem.getDefinition().asGroup().getDeclaredChildren().iterator();
            while (tempit.hasNext()) {
                ChildDefinition<?> tempdef = tempit.next();
                // a list of lists
                if (currentItem.getLoopQNames().contains(tempdef.getName())) {
                    continue;
                }
                if (currentItem.getQnames().contains(tempdef.getName())) {
                    ArrayList<QName> loops = new ArrayList<QName>();
                    for (int i = currentItem.getQnames().indexOf(tempdef.getName()); i < currentItem.getQnames().size(); i++) {
                        loops.add(currentItem.getQnames().get(i));
                    }
                    currentItem.addLoopQNames(loops);
                    continue;
                }
                QueueDefinitionItem qudi = new QueueDefinitionItem(tempdef, tempdef.getName());
                qudi.addQnames(currentItem.getQnames());
                for (List<QName> loop : currentItem.getLoopQNames()) {
                    qudi.addLoopQNames(loop);
                }
                propertyqueue.add(qudi);
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 32 with ChildDefinition

use of eu.esdihumboldt.hale.common.schema.model.ChildDefinition in project hale by halestudio.

the class PropertyEntityDialog method getObjectFromSelection.

/**
 * @see EntityDialog#getObjectFromSelection(ISelection)
 */
@Override
protected EntityDefinition getObjectFromSelection(ISelection selection) {
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof EntityDefinition) {
            return (EntityDefinition) element;
        }
    }
    if (!selection.isEmpty() && selection instanceof ITreeSelection) {
        // create property definition w/ default contexts
        TreePath path = ((ITreeSelection) selection).getPaths()[0];
        // get parent type
        TypeDefinition type = ((PropertyDefinition) path.getFirstSegment()).getParentType();
        // determine definition path
        List<ChildContext> defPath = new ArrayList<ChildContext>();
        for (int i = 0; i < path.getSegmentCount(); i++) {
            defPath.add(new ChildContext((ChildDefinition<?>) path.getSegment(i)));
        }
        // TODO check if property entity definition is applicable?
        return new PropertyEntityDefinition(type, defPath, ssid, parentType.getFilter());
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Aggregations

ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)32 ArrayList (java.util.ArrayList)20 QName (javax.xml.namespace.QName)19 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)11 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)6 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)6 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)5 DefinitionGroup (eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)5 List (java.util.List)5 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)4 Pair (eu.esdihumboldt.util.Pair)3 LinkedList (java.util.LinkedList)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 TreePath (org.eclipse.jface.viewers.TreePath)3 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)2 InstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)2 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)2 Group (eu.esdihumboldt.hale.common.instance.model.Group)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2