diff --git a/src/gr/spinellis/umlgraph/doclet/OptionProvider.java b/src/gr/spinellis/umlgraph/doclet/OptionProvider.java
new file mode 100644
index 0000000..69aba79
--- /dev/null
+++ b/src/gr/spinellis/umlgraph/doclet/OptionProvider.java
@@ -0,0 +1,11 @@
+package gr.spinellis.umlgraph.doclet;
+
+import com.sun.javadoc.ClassDoc;
+
+public interface OptionProvider {
+ public Options getOptionsFor(ClassDoc cd);
+
+ public Options getOptionsFor(String name);
+
+ public Options getGlobalOptions();
+}
diff --git a/src/gr/spinellis/umlgraph/doclet/Options.java b/src/gr/spinellis/umlgraph/doclet/Options.java
index e659c04..ac4cd7e 100644
--- a/src/gr/spinellis/umlgraph/doclet/Options.java
+++ b/src/gr/spinellis/umlgraph/doclet/Options.java
@@ -33,7 +33,7 @@ import java.util.regex.PatternSyntaxException;
* @version $Revision$
* @author Diomidis Spinellis
*/
-class Options implements Cloneable {
+class Options implements Cloneable, OptionProvider {
private Vector hidePatterns;
PrintWriter w;
boolean showQualified;
@@ -335,5 +335,24 @@ class Options implements Cloneable {
}
return false;
}
+
+
+ /*
+ * OptionProvider methods
+ */
+
+ public Options getOptionsFor(ClassDoc cd) {
+ Options localOpt = (Options) this.clone();
+ localOpt.setOptions(cd);
+ return localOpt;
+ }
+
+ public Options getOptionsFor(String name) {
+ return this;
+ }
+
+ public Options getGlobalOptions() {
+ return this;
+ }
}
diff --git a/src/gr/spinellis/umlgraph/doclet/View.java b/src/gr/spinellis/umlgraph/doclet/View.java
index 4e871fa..b5be711 100644
--- a/src/gr/spinellis/umlgraph/doclet/View.java
+++ b/src/gr/spinellis/umlgraph/doclet/View.java
@@ -30,82 +30,103 @@ import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.Tag;
/**
- * Contains the definition of a View. A View is a set of option overrides
- * that will lead to the creation of a UML class diagram. Multiple views can
- * be defined on the same source tree, effectively allowing to create multiple
+ * Contains the definition of a View. A View is a set of option overrides that
+ * will lead to the creation of a UML class diagram. Multiple views can be
+ * defined on the same source tree, effectively allowing to create multiple
* class diagram out of it.
* @author wolf
- *
+ *
*/
-class View {
+class View implements OptionProvider {
Map optionOverrides = new LinkedHashMap();
- ArrayList globalOptions = new ArrayList();
ClassDoc viewDoc;
-
+ Options baseOptions;
+
/**
* Builds a view given the class that contains its definition
* @param c
* @throws PatternSyntaxException
*/
- public View(ClassDoc c) throws PatternSyntaxException {
+ public View(ClassDoc c, Options generalOptions) throws PatternSyntaxException {
this.viewDoc = c;
+ this.baseOptions = (Options) generalOptions.clone();
Tag[] tags = c.tags();
String currPattern = null;
+ // parse options, get the global ones, and build a map of the
+ // pattern matched overrides
List patternOptions = new ArrayList();
+ List globalOptions = new ArrayList();
for (int i = 0; i < tags.length; i++) {
- if(tags[i].name().equals("@match")) {
- if(currPattern != null) {
- String[][] options = patternOptions.toArray(new String[patternOptions.size()][]);
+ if (tags[i].name().equals("@match")) {
+ if (currPattern != null) {
+ String[][] options = patternOptions
+ .toArray(new String[patternOptions.size()][]);
optionOverrides.put(Pattern.compile(currPattern), options);
}
currPattern = tags[i].text();
- } else if(tags[i].name().equals("@opt")) {
+ patternOptions.clear();
+ } else if (tags[i].name().equals("@opt")) {
String[] opts = StringUtil.tokenize(tags[i].text());
opts[0] = "-" + opts[0];
- if(currPattern == null) {
+ if (currPattern == null) {
globalOptions.add(opts);
} else {
patternOptions.add(opts);
}
- }
+ }
}
- if(currPattern != null) {
+ if (currPattern != null) {
String[][] options = patternOptions.toArray(new String[patternOptions.size()][]);
optionOverrides.put(Pattern.compile(currPattern), options);
}
- }
-
- /**
- * Applies global view overrides.
- * If not output tag has been specified, the view name will be used as the output file name.
- */
- public void applyOverrides(Options o) {
+
+ // apply the view global options
boolean outputSet = false;
for (String[] opts : globalOptions) {
- if(opts[0].equals("-output"))
+ if (opts[0].equals("-output"))
outputSet = true;
- o.setOption(opts);
+ baseOptions.setOption(opts);
}
- if(!outputSet)
- o.setOption(new String[] {"-output", viewDoc.name() + ".dot"});
+ if (!outputSet)
+ baseOptions.setOption(new String[] { "-output", viewDoc.name() + ".dot" });
}
/**
* Applies local view overrides
*/
- public void applyOverrides(Options o, ClassDoc c) {
- String className = c.toString();
+ private void applyOverrides(Options o, String className) {
for (Iterator> iter = optionOverrides.entrySet().iterator(); iter
.hasNext();) {
Map.Entry mapEntry = iter.next();
Pattern regex = mapEntry.getKey();
Matcher matcher = regex.matcher(className);
if (matcher.matches()) {
- String[][] overrides = mapEntry.getValue(); // the first element is in fact the pattern
+ String[][] overrides = mapEntry.getValue();
for (int i = 0; i < overrides.length; i++) {
o.setOption(overrides[i]);
}
}
}
}
+
+ // ----------------------------------------------------------------
+ // OptionProvider methods
+ // ----------------------------------------------------------------
+
+ public Options getOptionsFor(ClassDoc cd) {
+ Options localOpt = (Options) baseOptions.clone();
+ localOpt.setOptions(cd);
+ applyOverrides(localOpt, cd.toString());
+ return localOpt;
+ }
+
+ public Options getOptionsFor(String name) {
+ Options localOpt = (Options) baseOptions.clone();
+ applyOverrides(localOpt, name);
+ return localOpt;
+ }
+
+ public Options getGlobalOptions() {
+ return baseOptions;
+ }
}
diff --git a/src/org/umlgraph/doclet/OptionProvider.java b/src/org/umlgraph/doclet/OptionProvider.java
new file mode 100644
index 0000000..69aba79
--- /dev/null
+++ b/src/org/umlgraph/doclet/OptionProvider.java
@@ -0,0 +1,11 @@
+package gr.spinellis.umlgraph.doclet;
+
+import com.sun.javadoc.ClassDoc;
+
+public interface OptionProvider {
+ public Options getOptionsFor(ClassDoc cd);
+
+ public Options getOptionsFor(String name);
+
+ public Options getGlobalOptions();
+}
diff --git a/src/org/umlgraph/doclet/Options.java b/src/org/umlgraph/doclet/Options.java
index e659c04..ac4cd7e 100644
--- a/src/org/umlgraph/doclet/Options.java
+++ b/src/org/umlgraph/doclet/Options.java
@@ -33,7 +33,7 @@ import java.util.regex.PatternSyntaxException;
* @version $Revision$
* @author Diomidis Spinellis
*/
-class Options implements Cloneable {
+class Options implements Cloneable, OptionProvider {
private Vector hidePatterns;
PrintWriter w;
boolean showQualified;
@@ -335,5 +335,24 @@ class Options implements Cloneable {
}
return false;
}
+
+
+ /*
+ * OptionProvider methods
+ */
+
+ public Options getOptionsFor(ClassDoc cd) {
+ Options localOpt = (Options) this.clone();
+ localOpt.setOptions(cd);
+ return localOpt;
+ }
+
+ public Options getOptionsFor(String name) {
+ return this;
+ }
+
+ public Options getGlobalOptions() {
+ return this;
+ }
}
diff --git a/src/org/umlgraph/doclet/View.java b/src/org/umlgraph/doclet/View.java
index 4e871fa..b5be711 100644
--- a/src/org/umlgraph/doclet/View.java
+++ b/src/org/umlgraph/doclet/View.java
@@ -30,82 +30,103 @@ import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.Tag;
/**
- * Contains the definition of a View. A View is a set of option overrides
- * that will lead to the creation of a UML class diagram. Multiple views can
- * be defined on the same source tree, effectively allowing to create multiple
+ * Contains the definition of a View. A View is a set of option overrides that
+ * will lead to the creation of a UML class diagram. Multiple views can be
+ * defined on the same source tree, effectively allowing to create multiple
* class diagram out of it.
* @author wolf
- *
+ *
*/
-class View {
+class View implements OptionProvider {
Map optionOverrides = new LinkedHashMap();
- ArrayList globalOptions = new ArrayList();
ClassDoc viewDoc;
-
+ Options baseOptions;
+
/**
* Builds a view given the class that contains its definition
* @param c
* @throws PatternSyntaxException
*/
- public View(ClassDoc c) throws PatternSyntaxException {
+ public View(ClassDoc c, Options generalOptions) throws PatternSyntaxException {
this.viewDoc = c;
+ this.baseOptions = (Options) generalOptions.clone();
Tag[] tags = c.tags();
String currPattern = null;
+ // parse options, get the global ones, and build a map of the
+ // pattern matched overrides
List patternOptions = new ArrayList();
+ List globalOptions = new ArrayList();
for (int i = 0; i < tags.length; i++) {
- if(tags[i].name().equals("@match")) {
- if(currPattern != null) {
- String[][] options = patternOptions.toArray(new String[patternOptions.size()][]);
+ if (tags[i].name().equals("@match")) {
+ if (currPattern != null) {
+ String[][] options = patternOptions
+ .toArray(new String[patternOptions.size()][]);
optionOverrides.put(Pattern.compile(currPattern), options);
}
currPattern = tags[i].text();
- } else if(tags[i].name().equals("@opt")) {
+ patternOptions.clear();
+ } else if (tags[i].name().equals("@opt")) {
String[] opts = StringUtil.tokenize(tags[i].text());
opts[0] = "-" + opts[0];
- if(currPattern == null) {
+ if (currPattern == null) {
globalOptions.add(opts);
} else {
patternOptions.add(opts);
}
- }
+ }
}
- if(currPattern != null) {
+ if (currPattern != null) {
String[][] options = patternOptions.toArray(new String[patternOptions.size()][]);
optionOverrides.put(Pattern.compile(currPattern), options);
}
- }
-
- /**
- * Applies global view overrides.
- * If not output tag has been specified, the view name will be used as the output file name.
- */
- public void applyOverrides(Options o) {
+
+ // apply the view global options
boolean outputSet = false;
for (String[] opts : globalOptions) {
- if(opts[0].equals("-output"))
+ if (opts[0].equals("-output"))
outputSet = true;
- o.setOption(opts);
+ baseOptions.setOption(opts);
}
- if(!outputSet)
- o.setOption(new String[] {"-output", viewDoc.name() + ".dot"});
+ if (!outputSet)
+ baseOptions.setOption(new String[] { "-output", viewDoc.name() + ".dot" });
}
/**
* Applies local view overrides
*/
- public void applyOverrides(Options o, ClassDoc c) {
- String className = c.toString();
+ private void applyOverrides(Options o, String className) {
for (Iterator> iter = optionOverrides.entrySet().iterator(); iter
.hasNext();) {
Map.Entry mapEntry = iter.next();
Pattern regex = mapEntry.getKey();
Matcher matcher = regex.matcher(className);
if (matcher.matches()) {
- String[][] overrides = mapEntry.getValue(); // the first element is in fact the pattern
+ String[][] overrides = mapEntry.getValue();
for (int i = 0; i < overrides.length; i++) {
o.setOption(overrides[i]);
}
}
}
}
+
+ // ----------------------------------------------------------------
+ // OptionProvider methods
+ // ----------------------------------------------------------------
+
+ public Options getOptionsFor(ClassDoc cd) {
+ Options localOpt = (Options) baseOptions.clone();
+ localOpt.setOptions(cd);
+ applyOverrides(localOpt, cd.toString());
+ return localOpt;
+ }
+
+ public Options getOptionsFor(String name) {
+ Options localOpt = (Options) baseOptions.clone();
+ applyOverrides(localOpt, name);
+ return localOpt;
+ }
+
+ public Options getGlobalOptions() {
+ return baseOptions;
+ }
}