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.project.adapters;
14 import java.util.Collection;
16 import org.eclipse.core.runtime.CoreException;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.adaption.SimpleAdapter;
20 import org.simantics.db.common.utils.NameUtils;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.exception.ServiceException;
23 import org.simantics.db.exception.ValidationException;
24 import org.simantics.project.IProject;
25 import org.simantics.project.ProjectFeatures;
26 import org.simantics.project.exception.ProjectException;
27 import org.simantics.project.features.IProjectFeature;
28 import org.simantics.project.features.registry.IProjectFeatureExtension;
29 import org.simantics.project.impl.Project;
30 import org.simantics.project.ontology.ProjectResource;
33 * @author Tuukka Lehtonen
35 public class ProjectAdapter extends SimpleAdapter<IProject> {
38 public IProject adapt(ReadGraph g, Resource resource) throws DatabaseException {
39 ProjectResource PROJ = ProjectResource.getInstance(g);
40 if (!g.isInstanceOf(resource, PROJ.Project))
41 throw new ValidationException("Cannot adapt resource " + NameUtils.getSafeName(g, resource) + " to IProject. Resource is not an instance of " + ProjectResource.URIs.Project);
43 Project p = new Project(g.getSession(), resource);
44 //System.out.println("NEW PROJECT: " + p + " ( " + System.identityHashCode(p) + ")");
46 Collection<IProjectFeatureExtension> sorted = ProjectFeatures.getTopologicallySortedFeatures(g, p.get());
47 loadFeatures(g, p, sorted);
49 } catch (ProjectException e) {
50 throw new ValidationException("project feature loading failed", e);
54 private void loadFeatures(ReadGraph g, Project p, Collection<IProjectFeatureExtension> sortedFeatures) throws ProjectException, ValidationException, ServiceException {
55 for (IProjectFeatureExtension feature : sortedFeatures) {
57 IProjectFeature pf = feature.newInstance();
59 } catch (CoreException e) {
60 throw new ValidationException(e);