-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File converters should try a little harder.
- Loading branch information
1 parent
fa11452
commit 29f3a3c
Showing
2 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
resources/impl/src/main/java/org/jboss/forge/resource/converter/FileResourceConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.resource.converter; | ||
|
||
import java.io.File; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.jboss.forge.convert.AbstractConverter; | ||
import org.jboss.forge.resource.FileResource; | ||
import org.jboss.forge.resource.Resource; | ||
import org.jboss.forge.resource.ResourceFactory; | ||
|
||
/** | ||
* Converts a {@link File} object to a {@link Resource} | ||
* | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
*/ | ||
|
||
@Singleton | ||
@SuppressWarnings("rawtypes") | ||
public class FileResourceConverter extends AbstractConverter<Object, FileResource> | ||
{ | ||
private final ResourceFactory resourceFactory; | ||
|
||
@Inject | ||
public FileResourceConverter(ResourceFactory resourceFactory) | ||
{ | ||
super(Object.class, FileResource.class); | ||
this.resourceFactory = resourceFactory; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public FileResource convert(Object source) | ||
{ | ||
File file = null; | ||
if (source instanceof File) | ||
file = (File) source; | ||
else | ||
file = new File(source.toString()); | ||
return resourceFactory.create(FileResource.class, file); | ||
} | ||
} |