1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.scenegraph.profile.request;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
16 import java.util.HashSet;
\r
17 import java.util.List;
\r
19 import org.simantics.db.ReadGraph;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.db.common.request.ResourceRead2;
\r
22 import org.simantics.db.exception.DatabaseException;
\r
23 import org.simantics.diagram.stubs.DiagramResource;
\r
24 import org.simantics.scenegraph.profile.ProfileUtils;
\r
27 * @author Tuukka Lehtonen
\r
29 public class ProfileEntryResources extends ResourceRead2<Collection<Resource>> {
\r
31 protected DiagramResource DIA;
\r
33 public ProfileEntryResources(Resource profile, Resource entry) {
\r
34 super(profile, entry);
\r
37 protected boolean test(ReadGraph graph, Resource activeProfile, Resource entry) throws DatabaseException {
\r
41 public List<Resource> process(ReadGraph graph, Resource activeProfile, Resource item, List<Resource> result, HashSet<Resource> visited) throws DatabaseException {
\r
42 List<Resource> entries = ProfileUtils.getProfileChildrenFromEntries(graph, item);
\r
43 for (Resource entry : entries) {
\r
44 Resource children = graph.getPossibleObject(entry, DIA.HasEntries);
\r
45 if (children != null) {
\r
46 process(graph, activeProfile, children, result, visited);
\r
48 if (test(graph, activeProfile, entry)) {
\r
49 if (!visited.contains(entry)) {
\r
61 public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
\r
62 this.DIA = DiagramResource.getInstance(graph);
\r
63 return process(graph, resource, resource2, new ArrayList<Resource>(), new HashSet<Resource>());
\r