1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.common.request;
14 import java.util.Collection;
15 import java.util.HashSet;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.layer0.Layer0;
22 public class PossibleIndexRoot extends ResourceRead<Resource> {
24 public PossibleIndexRoot(Resource resource) {
29 public Resource perform(ReadGraph graph) throws DatabaseException {
31 Layer0 L0 = Layer0.getInstance(graph);
33 if (graph.isInstanceOf(resource, L0.IndexRoot))
36 Collection<Resource> parents = new HashSet<Resource>(graph.getObjects(resource, L0.IsOwnedBy));
37 Resource parent = parents.size() == 1 ? parents.iterator().next() : null;
40 if(resource.equals(parent))
45 if(parents.size() > 1) {
46 // Maybe we have a case where there is ConsistsOf and HasProperty that is incorrectly classified as IsComposedOf
47 parent = graph.getPossibleObject(resource, L0.PartOf);
52 parent = graph.getPossibleObject(resource, L0.HasObjectInverse);
54 if(parent == null) return null;
58 return graph.syncRequest(new PossibleIndexRoot(parent));