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.message.util;
15 import java.net.URISyntaxException;
17 import org.simantics.db.Resource;
18 import org.simantics.db.ResourceSerializer;
19 import org.simantics.db.Session;
20 import org.simantics.db.exception.InvalidResourceReferenceException;
21 import org.simantics.db.service.SerialisationSupport;
22 import org.simantics.message.ReferenceSerializationException;
25 * @author Tuukka Lehtonen
27 public class ResourceSerializerUtil {
29 public static Resource deserialize(Session s, URI data) throws ReferenceSerializationException {
30 SerialisationSupport support = s.getService(SerialisationSupport.class);
31 ResourceSerializer rs = support.getResourceSerializer();
33 return rs.getResource(data.getSchemeSpecificPart());
34 } catch (InvalidResourceReferenceException e) {
35 throw new ReferenceSerializationException(e);
39 public static URI serialize(Session s, Resource r) throws ReferenceSerializationException {
40 SerialisationSupport support = s.getService(SerialisationSupport.class);
41 ResourceSerializer rs = support.getResourceSerializer();
43 return new URI("resource", rs.createRandomAccessId(r), null);
44 } catch (InvalidResourceReferenceException e) {
45 throw new ReferenceSerializationException(e);
46 } catch (URISyntaxException e) {
47 throw new ReferenceSerializationException(e);