2012-09-04 22:56:05 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*******************************************************************************/
|
|
|
|
package com.ibm.wala.classLoader;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import com.ibm.wala.util.collections.NonNullSingletonIterator;
|
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
|
|
|
import com.ibm.wala.util.debug.UnimplementedError;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A module which is a wrapper around a file in the filesystem
|
|
|
|
*/
|
|
|
|
public abstract class FileModule implements Module, ModuleEntry {
|
|
|
|
|
|
|
|
private final File file;
|
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
private final Module container;
|
|
|
|
|
|
|
|
public FileModule(File f, Module container) throws IllegalArgumentException {
|
2012-09-04 22:56:05 +00:00
|
|
|
if (f == null) {
|
|
|
|
throw new IllegalArgumentException("f is null");
|
|
|
|
}
|
|
|
|
this.file = f;
|
2013-06-25 15:53:58 +00:00
|
|
|
this.container = container;
|
2012-09-04 22:56:05 +00:00
|
|
|
if (!f.exists()) {
|
|
|
|
throw new IllegalArgumentException("bad file " + f.getAbsolutePath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getAbsolutePath() {
|
|
|
|
return file.getAbsolutePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @see com.ibm.wala.classLoader.Module#getEntries()
|
|
|
|
*/
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public Iterator<ModuleEntry> getEntries() {
|
|
|
|
return new NonNullSingletonIterator<ModuleEntry>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return file.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (o == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (o.getClass().equals(getClass())) {
|
|
|
|
FileModule other = (FileModule) o;
|
|
|
|
return getName().equals(other.getName());
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @see com.ibm.wala.classLoader.ModuleEntry#getName()
|
|
|
|
*/
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public String getName() {
|
|
|
|
return file.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @see com.ibm.wala.classLoader.ModuleEntry#getInputStream()
|
|
|
|
*/
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public InputStream getInputStream() {
|
|
|
|
try {
|
|
|
|
if (!file.exists()) {
|
|
|
|
System.err.println("PANIC: File does not exist! " + file);
|
|
|
|
}
|
|
|
|
return new FileInputStream(file);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
Assertions.UNREACHABLE("could not read " + file);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @see com.ibm.wala.classLoader.ModuleEntry#isModuleFile()
|
|
|
|
*/
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public boolean isModuleFile() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Returns the file.
|
|
|
|
*/
|
|
|
|
public File getFile() {
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public Module asModule() throws UnimplementedError {
|
|
|
|
Assertions.UNREACHABLE("implement me");
|
|
|
|
return null;
|
|
|
|
}
|
2013-06-25 15:53:58 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Module getContainer() {
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2012-09-04 22:56:05 +00:00
|
|
|
}
|