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.scenegraph.profile.request;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.HashSet;
17 import java.util.List;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.request.ResourceRead2;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.diagram.stubs.DiagramResource;
24 import org.simantics.scenegraph.profile.ProfileUtils;
27 * @author Tuukka Lehtonen
29 public class ProfileEntryResources extends ResourceRead2<Collection<Resource>> {
31 protected DiagramResource DIA;
33 public ProfileEntryResources(Resource profile, Resource entry) {
34 super(profile, entry);
37 protected boolean test(ReadGraph graph, Resource activeProfile, Resource entry) throws DatabaseException {
41 public List<Resource> process(ReadGraph graph, Resource activeProfile, Resource item, List<Resource> result, HashSet<Resource> visited) throws DatabaseException {
42 List<Resource> entries = ProfileUtils.getProfileChildrenFromEntries(graph, item);
43 for (Resource entry : entries) {
44 Resource children = graph.getPossibleObject(entry, DIA.HasEntries);
45 if (children != null) {
46 process(graph, activeProfile, children, result, visited);
48 if (test(graph, activeProfile, entry)) {
49 if (!visited.contains(entry)) {
61 public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
62 this.DIA = DiagramResource.getInstance(graph);
63 return process(graph, resource, resource2, new ArrayList<Resource>(), new HashSet<Resource>());