]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/property/providers/CombinedPropertyProvider.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.layer0.utils / src / org / simantics / layer0 / utils / property / providers / CombinedPropertyProvider.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.layer0.utils.property.providers;
13
14 import java.util.Collection;
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.exception.DatabaseException;
22
23 @Deprecated
24 public class CombinedPropertyProvider implements IPropertyProvider {
25
26     private Map<Resource[], IPropertyProvider> providerMap = new HashMap<Resource[], IPropertyProvider>();
27
28     public void addProvider(ReadGraph graph, IPropertyProvider provider) {
29         for (Resource[] key : provider.provides(graph))
30             providerMap.put(key, provider);
31     }
32
33     @Override
34     public Object get(ReadGraph graph, final Resource resource, Resource... relations) throws DatabaseException {
35         IPropertyProvider provider = providerMap.get(relations);
36         if (provider == null)
37             return null;
38         return provider.get(graph, resource, relations);
39     }
40
41     @Override
42     public Collection<Resource[]> provides(ReadGraph graph) {
43         return providerMap.keySet();
44     }
45
46     @Override
47     public void set(WriteGraph graph, Object value, Resource resource, Resource... relations) throws DatabaseException {
48         IPropertyProvider provider = providerMap.get(relations);
49         if (provider == null)
50             throw new DoesNotHaveProperty();
51         provider.set(graph, value, resource, relations);
52     }
53
54 }