Skip to content

Commit

Permalink
File converters should try a little harder.
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Apr 16, 2013
1 parent fa11452 commit 29f3a3c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@

/**
* Converts a {@link File} object to a {@link Resource}
*
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*
*/

@Singleton
public class DirectoryResourceConverter extends AbstractConverter<File, DirectoryResource>
public class DirectoryResourceConverter extends AbstractConverter<Object, DirectoryResource>
{
private final ResourceFactory resourceFactory;

@Inject
public DirectoryResourceConverter(ResourceFactory resourceFactory)
{
super(File.class, DirectoryResource.class);
super(Object.class, DirectoryResource.class);
this.resourceFactory = resourceFactory;
}

@Override
public DirectoryResource convert(File source)
public DirectoryResource convert(Object source)
{
return resourceFactory.create(DirectoryResource.class, source);
File file = null;
if (source instanceof File)
file = (File) source;
else
file = new File(source.toString());
return resourceFactory.create(DirectoryResource.class, file);
}
}
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);
}
}

0 comments on commit 29f3a3c

Please sign in to comment.