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