|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| RelativeClassResourceStreamFactory.java | 25% | 60% | 55.6% | 51.4% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Joey and its relative products are published under the terms
|
|
| 3 |
* of the Apache Software License.
|
|
| 4 |
*/
|
|
| 5 |
/*
|
|
| 6 |
* Created on 2003/12/15
|
|
| 7 |
*/
|
|
| 8 |
package org.asyrinx.brownie.core.io.sf;
|
|
| 9 |
|
|
| 10 |
import java.io.File;
|
|
| 11 |
import java.io.IOException;
|
|
| 12 |
import java.io.InputStream;
|
|
| 13 |
|
|
| 14 |
import org.asyrinx.brownie.core.io.FileConstants;
|
|
| 15 |
import org.asyrinx.brownie.core.io.PathPointer;
|
|
| 16 |
import org.asyrinx.brownie.core.lang.ClassUtils;
|
|
| 17 |
import org.asyrinx.brownie.core.lang.InvocationInfo;
|
|
| 18 |
import org.asyrinx.brownie.core.lang.StringUtils;
|
|
| 19 |
|
|
| 20 |
/**
|
|
| 21 |
* @author akima
|
|
| 22 |
*/
|
|
| 23 |
public class RelativeClassResourceStreamFactory extends |
|
| 24 |
ClassResourceStreamFactory {
|
|
| 25 |
|
|
| 26 |
/**
|
|
| 27 |
*
|
|
| 28 |
*/
|
|
| 29 | 1 |
public RelativeClassResourceStreamFactory() {
|
| 30 | 1 |
this(null, null); |
| 31 |
|
|
| 32 |
} |
|
| 33 |
|
|
| 34 |
/**
|
|
| 35 |
* @param classLoader
|
|
| 36 |
*/
|
|
| 37 | 0 |
public RelativeClassResourceStreamFactory(ClassLoader classLoader) {
|
| 38 | 0 |
this(classLoader, null); |
| 39 |
} |
|
| 40 |
|
|
| 41 |
/**
|
|
| 42 |
* @param classLoader
|
|
| 43 |
*/
|
|
| 44 | 0 |
public RelativeClassResourceStreamFactory(String classToBeCalled) {
|
| 45 | 0 |
this(null, classToBeCalled); |
| 46 |
} |
|
| 47 |
|
|
| 48 |
/**
|
|
| 49 |
* @param classLoader
|
|
| 50 |
*/
|
|
| 51 | 1 |
public RelativeClassResourceStreamFactory(ClassLoader classLoader,
|
| 52 |
String classToBeCalled) {
|
|
| 53 | 1 |
super(classLoader != null ? classLoader : Thread.currentThread() |
| 54 |
.getContextClassLoader()); |
|
| 55 | 1 |
this.classToBeCalled = StringUtils.isEmpty(classToBeCalled) ? RelativeClassResourceStreamFactory.class |
| 56 |
.getName() |
|
| 57 |
: classToBeCalled; |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
private final String classToBeCalled;
|
|
| 61 |
|
|
| 62 |
/**
|
|
| 63 |
* This method must be overrided because of InvocationInfo
|
|
| 64 |
*
|
|
| 65 |
* @see org.asyrinx.io.sf.AbstractFileStreamFactory#newInput(java.lang.Object)
|
|
| 66 |
*/
|
|
| 67 | 0 |
public InputStream newInput(Object key) throws IOException { |
| 68 | 0 |
if (key instanceof File) { |
| 69 | 0 |
return newInput((File) key);
|
| 70 | 0 |
} else if (key instanceof String) { |
| 71 | 0 |
return newInput((String) key);
|
| 72 |
} else {
|
|
| 73 | 0 |
throw keyClassMismatch(key);
|
| 74 |
} |
|
| 75 |
} |
|
| 76 |
|
|
| 77 |
/**
|
|
| 78 |
* This method must be overrided because of InvocationInfo
|
|
| 79 |
*
|
|
| 80 |
* @see org.asyrinx.io.sf.AbstractFileStreamFactory#newInput(java.io.File)
|
|
| 81 |
*/
|
|
| 82 | 5 |
public InputStream newInput(File file) throws IOException { |
| 83 | 5 |
return newInput(file.getPath());
|
| 84 |
} |
|
| 85 |
|
|
| 86 |
/**
|
|
| 87 |
* @see org.asyrinx.io.sf.ClassResourceStreamFactory#newInput(java.lang.String)
|
|
| 88 |
*/
|
|
| 89 | 5 |
public InputStream newInput(String fileName) throws IOException { |
| 90 | 5 |
return super.newInput(toFilePath(fileName)); |
| 91 |
} |
|
| 92 |
|
|
| 93 | 5 |
public String toFilePath(String fileName) {
|
| 94 | 5 |
final InvocationInfo invocationInfo = new InvocationInfo(
|
| 95 |
classToBeCalled); |
|
| 96 | 5 |
final String resPath = StringUtils.replace(invocationInfo |
| 97 |
.getClassName(), ClassUtils.PACKAGE_DELIM, |
|
| 98 |
FileConstants.FILE_SPARATOR_SLASH); |
|
| 99 | 5 |
final PathPointer pointer = new PathPointer(resPath);
|
| 100 | 5 |
pointer.goUp(); |
| 101 | 5 |
pointer.moveTo(fileName); |
| 102 | 5 |
String realPath = pointer.getPath(); |
| 103 | 5 |
return realPath;
|
| 104 |
} |
|
| 105 |
|
|
| 106 |
/**
|
|
| 107 |
* @return
|
|
| 108 |
*/
|
|
| 109 | 0 |
public String getClassToBeCalled() {
|
| 110 | 0 |
return classToBeCalled;
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
} |
|
||||||||||