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.modeling.adapters;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.adaption.SimpleAdapter;
17 import org.simantics.db.exception.AdaptionException;
18 import org.simantics.db.exception.ServiceException;
19 import org.simantics.db.exception.ValidationException;
20 import org.simantics.layer0.Layer0;
21 import org.simantics.modeling.ModelingResources;
23 public class ElementStringAdapter extends SimpleAdapter<String> {
26 public String adapt(ReadGraph g, Resource r) throws ValidationException, ServiceException {
29 ModelingResources mr = ModelingResources.getInstance(g);
31 Resource component = g.getPossibleObject(r, mr.ElementToComponent);
32 if (component != null)
34 StringBuilder sb = new StringBuilder();
35 Layer0 b = Layer0.getInstance(g);
36 String nameName = g.getPossibleRelatedValue(name, b.HasName);
40 for (Resource rType : g.getPrincipalTypes(r)) {
41 String s = g.adapt(rType, String.class);
51 } catch (AdaptionException e) {
53 throw new ValidationException(e);