X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.project%2Fsrc%2Forg%2Fsimantics%2Fproject%2Fadapters%2FProjectAdapter.java;fp=bundles%2Forg.simantics.project%2Fsrc%2Forg%2Fsimantics%2Fproject%2Fadapters%2FProjectAdapter.java;h=c22dec333dc0ec30e9e711c5b3bd1033b9d53a4c;hp=441f913ecc0d46cdb2dd0ce83f916666c7fc803c;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.project/src/org/simantics/project/adapters/ProjectAdapter.java b/bundles/org.simantics.project/src/org/simantics/project/adapters/ProjectAdapter.java index 441f913ec..c22dec333 100644 --- a/bundles/org.simantics.project/src/org/simantics/project/adapters/ProjectAdapter.java +++ b/bundles/org.simantics.project/src/org/simantics/project/adapters/ProjectAdapter.java @@ -1,65 +1,65 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.project.adapters; - -import java.util.Collection; - -import org.eclipse.core.runtime.CoreException; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.adaption.SimpleAdapter; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.ServiceException; -import org.simantics.db.exception.ValidationException; -import org.simantics.project.IProject; -import org.simantics.project.ProjectFeatures; -import org.simantics.project.exception.ProjectException; -import org.simantics.project.features.IProjectFeature; -import org.simantics.project.features.registry.IProjectFeatureExtension; -import org.simantics.project.impl.Project; -import org.simantics.project.ontology.ProjectResource; - -/** - * @author Tuukka Lehtonen - */ -public class ProjectAdapter extends SimpleAdapter { - - @Override - public IProject adapt(ReadGraph g, Resource resource) throws DatabaseException { - ProjectResource PROJ = ProjectResource.getInstance(g); - if (!g.isInstanceOf(resource, PROJ.Project)) - throw new ValidationException("Cannot adapt resource " + NameUtils.getSafeName(g, resource) + " to IProject. Resource is not an instance of " + ProjectResource.URIs.Project); - - Project p = new Project(g.getSession(), resource); - //System.out.println("NEW PROJECT: " + p + " ( " + System.identityHashCode(p) + ")"); - try { - Collection sorted = ProjectFeatures.getTopologicallySortedFeatures(g, p.get()); - loadFeatures(g, p, sorted); - return p; - } catch (ProjectException e) { - throw new ValidationException("project feature loading failed", e); - } - } - - private void loadFeatures(ReadGraph g, Project p, Collection sortedFeatures) throws ProjectException, ValidationException, ServiceException { - for (IProjectFeatureExtension feature : sortedFeatures) { - try { - IProjectFeature pf = feature.newInstance(); - p.addFeature(pf); - } catch (CoreException e) { - throw new ValidationException(e); - } - } - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.project.adapters; + +import java.util.Collection; + +import org.eclipse.core.runtime.CoreException; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.adaption.SimpleAdapter; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.exception.ValidationException; +import org.simantics.project.IProject; +import org.simantics.project.ProjectFeatures; +import org.simantics.project.exception.ProjectException; +import org.simantics.project.features.IProjectFeature; +import org.simantics.project.features.registry.IProjectFeatureExtension; +import org.simantics.project.impl.Project; +import org.simantics.project.ontology.ProjectResource; + +/** + * @author Tuukka Lehtonen + */ +public class ProjectAdapter extends SimpleAdapter { + + @Override + public IProject adapt(ReadGraph g, Resource resource) throws DatabaseException { + ProjectResource PROJ = ProjectResource.getInstance(g); + if (!g.isInstanceOf(resource, PROJ.Project)) + throw new ValidationException("Cannot adapt resource " + NameUtils.getSafeName(g, resource) + " to IProject. Resource is not an instance of " + ProjectResource.URIs.Project); + + Project p = new Project(g.getSession(), resource); + //System.out.println("NEW PROJECT: " + p + " ( " + System.identityHashCode(p) + ")"); + try { + Collection sorted = ProjectFeatures.getTopologicallySortedFeatures(g, p.get()); + loadFeatures(g, p, sorted); + return p; + } catch (ProjectException e) { + throw new ValidationException("project feature loading failed", e); + } + } + + private void loadFeatures(ReadGraph g, Project p, Collection sortedFeatures) throws ProjectException, ValidationException, ServiceException { + for (IProjectFeatureExtension feature : sortedFeatures) { + try { + IProjectFeature pf = feature.newInstance(); + p.addFeature(pf); + } catch (CoreException e) { + throw new ValidationException(e); + } + } + } + +}