Permalink
Browse files

View->XML using JAXB annotations.

  • Loading branch information...
1 parent 25c758e commit e4731ff769f7f8f39e8a359549d10f29f06c6587 @cderoove committed Jan 29, 2013
@@ -6,6 +6,11 @@
import java.util.ArrayList;
import java.util.Collections;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
@@ -17,7 +22,12 @@
import com.google.common.collect.Iterables;
import com.google.common.hash.HashCode;
+@XmlRootElement
public class QName {
+
+ public QName() {
+ this("");
+ }
public static QName forBinding(ITypeBinding apiType) {
return new QName(apiType.getBinaryName());
@@ -36,6 +46,8 @@ public static QName forMemberBinding(IMethodBinding mb, ITypeBinding tb) {
}
private ArrayList<UqName> components;
+
+ @XmlAttribute
private String identifier;
public QName(Iterable<String> i) {
@@ -1,14 +1,23 @@
package exapus.model.view;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
import exapus.model.forest.Direction;
import exapus.model.forest.Member;
import exapus.model.forest.PackageLayer;
import exapus.model.forest.PackageTree;
import exapus.model.forest.QName;
import exapus.model.forest.Ref;
+@XmlRootElement
public class ScopedSelection extends Selection {
+ public ScopedSelection() {
+ //only to be used by JAXB
+ }
+
public ScopedSelection(QName name, Scope scope, String tag) {
super();
this.name = name;
@@ -25,13 +34,13 @@ public ScopedSelection(QName name) {
this(name, Scope.PREFIX_SCOPE);
}
-
private Scope scope;
-
+
private QName name;
private String tag;
+ @XmlElement
public String getTag() {
return tag;
}
@@ -151,6 +160,7 @@ public void setScope(Scope scope) {
this.scope = scope;
}
+ @XmlElement
public QName getQName() {
return name;
}
@@ -1,10 +1,14 @@
package exapus.model.view;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
import exapus.model.forest.Member;
import exapus.model.forest.PackageLayer;
import exapus.model.forest.PackageTree;
import exapus.model.forest.Ref;
+@XmlRootElement
public abstract class Selection {
public abstract boolean matchPackageTree(PackageTree packageTree);
@@ -1,10 +1,14 @@
package exapus.model.view;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
import exapus.model.forest.Member;
import exapus.model.forest.PackageLayer;
import exapus.model.forest.PackageTree;
import exapus.model.forest.Ref;
+@XmlRootElement
public class UniversalSelection extends Selection {
private static UniversalSelection current = new UniversalSelection();
@@ -13,7 +17,8 @@ public static UniversalSelection getCurrent() {
return current;
}
- private UniversalSelection() {
+ public UniversalSelection() {
+ //only to be used by JAXB
}
@Override
@@ -5,6 +5,13 @@
import java.util.ArrayList;
import java.util.List;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
import org.eclipse.jface.viewers.StructuredSelection;
import exapus.model.details.GraphDetails;
@@ -16,7 +23,12 @@
import exapus.model.view.graphbuilder.GraphBuilder;
import exapus.model.view.graphdrawer.GraphDrawer;
+@XmlRootElement(name = "view")
public class View {
+
+ public View() {
+ //only to be used by jaxb
+ }
public View(String n, Perspective p) {
name = n;
@@ -42,8 +54,14 @@ public View(String n, Perspective p) {
private Perspective perspective;
+ @XmlElementWrapper(name="APISelection")
+ @XmlElements({ @XmlElement(name="Universal", type=UniversalSelection.class),
+ @XmlElement(name="ScopedSelection", type=ScopedSelection.class)})
private List<Selection> apiselection;
+ @XmlElementWrapper(name="ProjectSelection")
+ @XmlElements({ @XmlElement(name="Universal", type=UniversalSelection.class),
+ @XmlElement(name="ScopedSelection", type=ScopedSelection.class)})
private List<Selection> projectselection;
private MetricType metricType;
@@ -64,6 +82,7 @@ public boolean sealed() {
return sealed;
}
+ @XmlElement
public String getSourceViewName() {
return sourceViewName;
}
@@ -73,6 +92,7 @@ public void setSourceViewName(String n) {
makeDirty();
}
+ @XmlElement
public Perspective getPerspective() {
return perspective;
}
@@ -137,6 +157,7 @@ protected void makeDependentViewsDirty() {
v.makeDirty();
}
+ @XmlElement
public String getName() {
return name;
}
@@ -0,0 +1,25 @@
+package exapus.model.view;
+
+import java.io.File;
+import java.io.PrintStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+
+public class ViewWriter {
+
+ private View view;
+
+ public ViewWriter(View view) {
+ this.view = view;
+ }
+
+ public void write(PrintStream s) throws JAXBException {
+ JAXBContext context = JAXBContext.newInstance(View.class);
+ Marshaller m = context.createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ m.marshal(view, s);
+ }
+
+}

0 comments on commit e4731ff

Please sign in to comment.