Skip to content

Commit

Permalink
[ignore] code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter committed Oct 14, 2016
1 parent af6c8d1 commit 971c9f3
Showing 1 changed file with 38 additions and 48 deletions.
86 changes: 38 additions & 48 deletions src/org/exist/repo/ExistRepository.java
Expand Up @@ -44,29 +44,41 @@
*
* @author Florent Georges
* @author Wolfgang Meier
* @author Adam Retter
* @since 2010-09-22
*/
public class ExistRepository extends Observable implements BrokerPoolService {

private final static Logger LOG = LogManager.getLogger(ExistRepository.class);
public final static String EXPATH_REPO_DIR = "expathrepo";

public final static String EXPATH_REPO_DEFAULT = "webapp/WEB-INF/" + EXPATH_REPO_DIR;

public final static Logger LOG = LogManager.getLogger(ExistRepository.class);
/** The wrapped EXPath repository. */
private final Repository myParent;

public ExistRepository(FileSystemStorage storage) throws PackageException {
myParent = new Repository(storage);
public ExistRepository(final FileSystemStorage storage) throws PackageException {
this.myParent = new Repository(storage);
myParent.registerExtension(new ExistPkgExtension());
}

public static ExistRepository getRepository(final Configuration config) throws PackageException {
try {
final Path expathDir = getRepositoryDir(config);

LOG.info("Using directory " + expathDir.toAbsolutePath().toString() + " for expath package repository");
final FileSystemStorage storage = new FileSystemStorage(expathDir.toFile());
return new ExistRepository(storage);
} catch(final IOException ioe) {
throw new PackageException("Unable to access EXPath repository", ioe);
}
}

public Repository getParentRepo() {
return myParent;
}

public Module resolveJavaModule(String namespace, XQueryContext ctxt)
throws XPathException {
// the URI
URI uri;
public Module resolveJavaModule(final String namespace, final XQueryContext ctxt) throws XPathException {
final URI uri;
try {
uri = new URI(namespace);
}
Expand All @@ -89,7 +101,7 @@ public Module resolveJavaModule(String namespace, XQueryContext ctxt)
/**
* Load a module instance from its class name. Check the namespace is consistent.
*/
private Module getModule(String name, String namespace, XQueryContext ctxt)
private Module getModule(final String name, final String namespace, final XQueryContext ctxt)
throws XPathException {
try {
final Class clazz = Class.forName(name);
Expand All @@ -101,17 +113,13 @@ private Module getModule(String name, String namespace, XQueryContext ctxt)
namespace + " - " + ns);
}
return ctxt.loadBuiltInModule(namespace, name);
} catch ( final ClassNotFoundException ex ) {
} catch (final ClassNotFoundException ex) {
throw new XPathException("Cannot find module class from EXPath repository: " + name, ex);
} catch ( final InstantiationException ex ) {
throw new XPathException("Problem instantiating module class from EXPath repository: " + name, ex);
} catch ( final IllegalAccessException ex ) {
} catch (final InstantiationException | InvocationTargetException | IllegalAccessException ex) {
throw new XPathException("Problem instantiating module class from EXPath repository: " + name, ex);
} catch ( final InvocationTargetException ex ) {
throw new XPathException("Problem instantiating module class from EXPath repository: " + name, ex);
} catch ( final ClassCastException ex ) {
} catch (final ClassCastException ex) {
throw new XPathException("The class configured in EXPath repository is not a Module: " + name, ex);
} catch ( final IllegalArgumentException ex ) {
} catch (final IllegalArgumentException ex) {
throw new XPathException("Illegal argument passed to the module ctor", ex);
}
}
Expand All @@ -120,15 +128,15 @@ private Module getModule(String name, String namespace, XQueryContext ctxt)
* Try to instantiate the class using the constructor with a Map parameter,
* or the default constructor.
*/
private Module instantiateModule(Class clazz) throws XPathException,
private Module instantiateModule(final Class<Module> clazz) throws XPathException,
InstantiationException, IllegalAccessException, InvocationTargetException {
try {
final Constructor ctor = clazz.getConstructor(Map.class);
return (Module) ctor.newInstance(EMPTY_MAP);
final Constructor<Module> ctor = clazz.getConstructor(Map.class);
return ctor.newInstance(Collections.emptyMap());
} catch (final NoSuchMethodException ex) {
try {
final Constructor ctor = clazz.getConstructor();
return (Module) ctor.newInstance();
final Constructor<Module> ctor = clazz.getConstructor();
return ctor.newInstance();
}
catch (final NoSuchMethodException exx) {
throw new XPathException("Cannot find suitable constructor " +
Expand All @@ -137,9 +145,8 @@ private Module instantiateModule(Class clazz) throws XPathException,
}
}

public Path resolveXQueryModule(String namespace) throws XPathException {
// the URI
URI uri;
public Path resolveXQueryModule(final String namespace) throws XPathException {
final URI uri;
try {
uri = new URI(namespace);
} catch (final URISyntaxException ex) {
Expand Down Expand Up @@ -173,7 +180,7 @@ public Path resolveXQueryModule(String namespace) throws XPathException {
}

public List<URI> getJavaModules() {
final List<URI> modules = new ArrayList<URI>(13);
final List<URI> modules = new ArrayList<>();
for (final Packages pp : myParent.listPackages()) {
final Package pkg = pp.latest();
final ExistPkgInfo info = (ExistPkgInfo) pkg.getInfo("exist");
Expand All @@ -184,18 +191,6 @@ public List<URI> getJavaModules() {
return modules;
}

public static ExistRepository getRepository(Configuration config) throws PackageException {
try {
final Path expathDir = getRepositoryDir(config);

LOG.info("Using directory " + expathDir.toAbsolutePath().toString() + " for expath package repository");
final FileSystemStorage storage = new FileSystemStorage(expathDir.toFile());
return new ExistRepository(storage);
} catch(final IOException ioe) {
throw new PackageException("Unable to access EXPath repository", ioe);
}
}

public static Path getRepositoryDir(final Configuration config) throws IOException {
final Path dataDir = Optional.ofNullable((Path) config.getProperty(BrokerPool.PROPERTY_DATA_DIR))
.orElse(Paths.get(NativeBroker.DEFAULT_DATA_DIR));
Expand Down Expand Up @@ -227,25 +222,20 @@ private static void moveOldRepo(final Optional<Path> home, final Path newRepo) {
}
}

public void reportAction(Action action, String packageURI) {
public void reportAction(final Action action, final String packageURI) {
notifyObservers(new Notification(action, packageURI));
setChanged();
}

/** The wrapped EXPath repository. */
private Repository myParent;
/** An empty map for constructors expecting a parameter map. */
private static final Map<String, List<Object>> EMPTY_MAP = new HashMap<String, List<Object>>();

public enum Action {
INSTALL, UNINSTALL
}

public final static class Notification {
private Action action;
private String packageURI;
private final Action action;
private final String packageURI;

public Notification(Action action, String packageURI) {
public Notification(final Action action, final String packageURI) {
this.action = action;
this.packageURI = packageURI;
}
Expand Down Expand Up @@ -277,5 +267,5 @@ public String getPackageURI() {
/* */
/* The Initial Developer of the Original Code is Florent Georges. */
/* */
/* Contributor(s): none. */
/* Contributor(s): Wolfgang Meier, Adam Retter */
/* ------------------------------------------------------------------------ */

0 comments on commit 971c9f3

Please sign in to comment.