Skip to content
Snippets Groups Projects
Commit f8498c94 authored by Daniel Schmidt's avatar Daniel Schmidt
Browse files

added a lot of comments and got rid of some minor bugs

parent e470cb97
Branches
No related tags found
No related merge requests found
Showing
with 109 additions and 23 deletions
......@@ -7,6 +7,10 @@ import org.neo4j.graphdb.GraphDatabaseService;
import de.chw.sdg.db.Neo4Jdb;
import logging.Logger;
/**
* Manages the database access. This includes starting and stopping in a safe
* manner
*/
public class DatabaseController {
private String path;
private GraphDatabaseService db;
......@@ -35,11 +39,22 @@ public class DatabaseController {
return path;
}
/**
* Stops the current DB instance and sets the path for the next
*
* @param path
* path of next DB
*/
public void setPath(String path) {
stopDB();
this.path = path;
}
/**
* Starts the DB registers shutdown hook
*
* @return Database handle
*/
public GraphDatabaseService startDB() {
if (db == null) {
......
......@@ -5,6 +5,10 @@ import org.neo4j.graphdb.Node;
import de.chw.parallax.java.GeneratorExecutor;
/**
* Wraps SDG2Java, which exports a database node to java code
*
*/
public class ExportController {
GeneratorExecutor generator;
......
......@@ -7,12 +7,17 @@ import java.nio.file.Files;
import logging.Logger;
/**
* Wraps every interaction with the File System, such as deleting or copying a
* directory
*
*/
public class FileSystemController {
private final static String basepath = "tmp";
private final static String BASE_PATH = "tmp";
public static File initializeFolder(String dirName) {
File dbDir = new File(basepath, dirName);
File dbDir = new File(BASE_PATH, dirName);
Logger.info("Initializing DB Folder: " + dbDir.getAbsolutePath());
if (dbDir.exists()) {
deleteDir(dbDir);
......@@ -37,7 +42,7 @@ public class FileSystemController {
public static File copyDirToLocal(final String src) {
File srcFile = new File(src);
File targetFile = new File(basepath, srcFile.getName());
File targetFile = new File(BASE_PATH, srcFile.getName());
if (targetFile.exists()) {
deleteDir(targetFile);
}
......
......@@ -10,9 +10,13 @@ import org.neo4j.graphdb.GraphDatabaseService;
import de.chw.sdg.Sdg;
import logging.Logger;
public class SootController {
/**
* Generates a SDG from given Java code
*
*/
public class Java2SDGController {
private Sdg soot;
private Sdg sdg;
public String[] buildArguments(String pathToJava, String classpath, String mainClass) {
ArrayList<String> args = new ArrayList<String>();
......@@ -73,24 +77,24 @@ public class SootController {
}
public GraphDatabaseService getDB() {
return soot.getGraphDatabaseService();
return sdg.getGraphDatabaseService();
}
public void startUp(String pathToDB) {
soot = new Sdg(pathToDB);
soot.connect();
sdg = new Sdg(pathToDB);
sdg.connect();
soot.deleteContent();
sdg.deleteContent();
}
public void startSoot(String[] args) throws IOException {
public void startJava2SDG(String[] args) throws IOException {
soot.transform(args);
sdg.transform(args);
}
public void startSoot(String javaSrc, String classpath, String mainClass, String pathToDB) throws Exception {
public void startJava2SDG(String javaSrc, String classpath, String mainClass, String pathToDB) throws Exception {
startUp(pathToDB);
startSoot(buildArguments(javaSrc, classpath, mainClass));
startJava2SDG(buildArguments(javaSrc, classpath, mainClass));
}
}
......@@ -19,6 +19,11 @@ import model.ParallelizationPattern;
import model.Pattern;
import model.Query;
/**
* Handles the database queries and code export in a lazy manner and has a cache
* layer to reduce the amount of queries for the database
*
*/
public class LazyQueryController {
private Pattern activeCandidatePattern;
......
......@@ -21,6 +21,11 @@ import model.ParallelizationPattern;
import model.Pattern;
import model.Query;
/**
* Handles the database queries and wraps the result in matches; also generates
* the java code for the update pattern
*
*/
public class QueryController {
public static List<Match> getResultsForPattern(Pattern pattern, boolean applyPP) {
......
......@@ -11,6 +11,10 @@ import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
/**
* Locates a given class in a java project path and returns the files content
*
*/
public class SourceFinder {
private File srcDirectory;
private List<String> srcLines;
......
......@@ -2,6 +2,10 @@ package logging;
import javafx.scene.control.Label;
/**
* Logs into a Label field, to show messages to user
*
*/
public class LabelLogger implements GraphicLogger {
private final Label textField;
......@@ -40,7 +44,7 @@ public class LabelLogger implements GraphicLogger {
}
@Override
public void exception(Throwable exception) {
public void exception(final Throwable exception) {
textField.setText(exception.getMessage());
Logger.exception(exception);
}
......
......@@ -4,6 +4,10 @@ import java.io.PrintStream;
import logging.LoggerInterface.Level;
/**
* Handles the logging
*
*/
public final class Logger {
private Logger() {
......
......@@ -2,6 +2,10 @@ package model;
import java.util.List;
/**
* Represents the candidate pattern machtches for a given pattern
*
*/
public class CandidatePatternMatches {
private final Pattern pattern;
private final List<Match> matches;
......
......@@ -4,6 +4,10 @@ import java.util.Map;
import org.neo4j.graphdb.Node;
/**
* Holds the result of a candidate pattern
*
*/
public class CandidatePatternResult {
private Node displayNode;
......
......@@ -15,6 +15,10 @@ import preferences.PreferenceConstants;
import preferences.Preferences;
import tasks.Java2SDGTask;
/**
* Holds the complete state of the ui.wizard.CompareScreen
*
*/
public class CompareState {
private List<CandidatePatternMatches> patternMatches;
......
......@@ -4,6 +4,11 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* Holds all information regarding a Pattern match, including the candidate and
* update pattern result.
*
*/
public class Match {
private final String matchId = UUID.randomUUID().toString();
private Pattern pattern;
......
......@@ -7,6 +7,10 @@ import java.util.List;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Handles a parallelization pattern and parses the query node in it
*
*/
public class ParallelizationPattern {
private String javaVersion;
......
......@@ -20,6 +20,10 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import logging.Logger;
/**
* Handles everything related to patterns including the parsing of such
*
*/
public class Pattern {
private String name;
......
......@@ -29,9 +29,9 @@ import javafx.collections.ObservableList;
import logging.Logger;
/**
* manages Candidate and Update Patterns
* manages patterns in a list regarding order and active state. Keeps the
* patterns only as reference and does not maintain a local copy.
*
* @author danielschmidt
*
*/
......
......@@ -19,9 +19,8 @@ import logging.Logger;
import preferences.Preferences;
/**
* Manages parsing / var replacement and everything related to queries
*
* @author danielschmidt
* Manages parsing / temporary variable replacement and everything related to
* queries, including parsing and loading from another file
*
*/
......
package preferences;
/**
* The place to store the preference constants
*
*/
public final class PreferenceConstants {
public final static String DEFAULT_PATH = "WIZARD_DEF_PATH", DEFAULT_TARGET_PATH = "EXPERT_TARGET_PATH",
DEFAULT_DB = "EXPERT_DB", DEFAULT_CLASS = "WIZARD_DEF_CLASS", CLASS_PATH = "CLASS_PATH",
......
......@@ -11,6 +11,10 @@ import java.util.Map;
import logging.Logger;
/**
* Handles the preferences as a simple persistent key value store
*
*/
public final class Preferences {
private static Map<String, String> prefs;
......
......@@ -7,9 +7,13 @@ import javafx.concurrent.Task;
import model.CandidatePatternMatches;
import model.PatternList;
/**
* Queries the database to get a list of matched candidate patterns
*
*/
public class CandidatePatternListTask extends Task<Void> {
private ObservableList<String> cpMatches;
private ObservableList<String> candidatePatternMatches;
@Override
protected Void call() {
......@@ -20,10 +24,10 @@ public class CandidatePatternListTask extends Task<Void> {
java.util.List<CandidatePatternMatches> matches = QueryController
.getResultsForPatternList(patterns.getActivePatterns(), false);
cpMatches = FXCollections.observableArrayList();
candidatePatternMatches = FXCollections.observableArrayList();
for (CandidatePatternMatches pm : matches) {
if (pm.getMatches().size() > 0) {
cpMatches.add(pm.getPattern().getName());
candidatePatternMatches.add(pm.getPattern().getName());
}
}
this.updateMessage("Pattern applied!");
......@@ -32,7 +36,7 @@ public class CandidatePatternListTask extends Task<Void> {
}
public ObservableList<String> getMatches() {
return this.cpMatches;
return this.candidatePatternMatches;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment