]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ResourceSpecAttribute.java
Use execDir to choose config and data dir when not forked.
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / execution / ResourceSpecAttribute.java
1 package org.argeo.slc.core.execution;
2
3 import java.io.IOException;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.slc.SlcException;
8 import org.springframework.core.io.Resource;
9
10 /** @deprecated */
11 public class ResourceSpecAttribute extends AbstractSpecAttribute {
12 public final static String TYPE_PATH = "path";
13 public final static String TYPE_URL = "url";
14 public final static String TYPE_STREAM = "stream";
15
16 private Resource resource;
17 private String type = TYPE_PATH;
18
19 private final static Log log = LogFactory
20 .getLog(ResourceSpecAttribute.class);
21
22 public ResourceSpecAttribute() {
23 log
24 .warn(getClass()
25 + " is deprecated and will soon be removed. Please use slcDefault.executionResources instead.");
26 }
27
28 public Object getValue() {
29 return convertResource(resource);
30 }
31
32 public void setResource(Resource resource) {
33 this.resource = resource;
34 }
35
36 public Object convertResource(Resource resource) {
37 try {
38 if (TYPE_PATH.equals(type))
39 return resource.getFile().getCanonicalPath();
40 else if (TYPE_URL.equals(type))
41 return resource.getURL().toString();
42 else if (TYPE_STREAM.equals(type))
43 return resource.getInputStream();
44 else
45 throw new SlcException("Unkown type " + type);
46 } catch (IOException e) {
47 throw new SlcException("Cannot convert resource " + resource, e);
48 }
49 }
50
51 public void setType(String type) {
52 this.type = type;
53 }
54
55 public String getType() {
56 return type;
57 }
58
59 }