]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/OsFileFactoryBean.java
Document and improve execution model
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / OsFileFactoryBean.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.execution;
18
19 import java.io.File;
20
21 import org.springframework.beans.factory.FactoryBean;
22 import org.springframework.core.io.Resource;
23 import org.springframework.util.Assert;
24
25 /** Retrieve an OS File from the given resource. */
26 public class OsFileFactoryBean implements FactoryBean {
27 private ExecutionResources executionResources;
28 private Resource resource;
29 private Boolean overwrite = false;
30
31 /** Return an existing file on the file system. */
32 public Object getObject() throws Exception {
33 Assert.notNull(executionResources, "executionResources is null");
34 Assert.notNull(resource, "resource is null");
35 return executionResources.getAsOsPath(resource, overwrite);
36 }
37
38 /** Return {@link Object} because CGLIB is unable to proxy {@link File}.*/
39 public Class<? extends Object> getObjectType() {
40 return CharSequence.class;
41 }
42
43 public boolean isSingleton() {
44 return false;
45 }
46
47 /** The execution resources object. */
48 public void setExecutionResources(ExecutionResources executionResources) {
49 this.executionResources = executionResources;
50 }
51
52 /** The resource to access. */
53 public void setResource(Resource resource) {
54 this.resource = resource;
55 }
56
57 /**
58 * Whether to overwrite the resource if it already exists. Default is
59 * <code>false</code>.
60 */
61 public void setOverwrite(Boolean overwrite) {
62 this.overwrite = overwrite;
63 }
64
65 }