Improved the hierarchy of inheritance...

This commit is contained in:
Pascal Koenig
2011-10-05 19:42:34 +02:00
parent a022c05ee6
commit 379e9fb591
15 changed files with 176 additions and 174 deletions

View File

@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Wed Oct 05 13:06:09 CEST 2011
build.number=22
#Wed Oct 05 19:32:58 CEST 2011
build.number=30

View File

@@ -3,55 +3,28 @@
*/
package de.sockenklaus.XmlStats.Objects;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.nidefawl.Achievements.AchievementListData;
/**
* @author socrates
*
*/
public class Achievement extends Elem {
public class Achievement extends NodeList {
private Elem name;
private Elem description;
private Elem category;
private Elem stat;
private Elem value;
private Elem maxawards;
private Elem commands;
private Boolean enabled;
public Achievement(){
super("achievement");
}
public Achievement(AchievementListData ach){
super("achievement");
this.name = new Elem("name", ach.getName());
this.description = new Elem("description", ach.getDescription());
this.category = new Elem("category", ach.getCategory());
this.stat = new Elem("stat", ach.getKey());
this.value = new Elem("value", ach.getValue());
this.maxawards = new Elem("maxawards", ach.getMaxawards());
this.commands = new Elem("commands", ach.commands.toString());
this.enabled = ach.isEnabled();
}
protected Achievement(){
}
public Element getXml(Document doc){
Element result = doc.createElement("achievement");
result.setAttribute("enabled", this.enabled ?"true":"false");
result.appendChild(this.name.getXml(doc));
result.appendChild(this.description.getXml(doc));
result.appendChild(this.category.getXml(doc));
result.appendChild(this.stat.getXml(doc));
result.appendChild(this.value.getXml(doc));
result.appendChild(this.maxawards.getXml(doc));
result.appendChild(this.commands.getXml(doc));
return result;
this.childNodes.add(new NodeText("name", ach.getName()));
this.childNodes.add(new NodeText("description", ach.getDescription()));
this.childNodes.add(new NodeText("category", ach.getCategory()));
this.childNodes.add(new NodeText("stat", ach.getKey()));
this.childNodes.add(new NodeText("value", ach.getValue()));
this.childNodes.add(new NodeText("maxawards", ach.getMaxawards()));
this.childNodes.add(new NodeText("commands", ach.commands.toString()));
this.attributes.put("enabled", String.valueOf(ach.isEnabled()));
}
}

View File

@@ -3,12 +3,8 @@
*/
package de.sockenklaus.XmlStats.Objects;
import java.util.ArrayList;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.nidefawl.Achievements.AchievementListData;
import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
@@ -18,10 +14,9 @@ import de.sockenklaus.XmlStats.Datasource.AchievementsDS;
*
*/
public class Achievements extends Array {
//protected ArrayList<Achievement> childNodes;
public Achievements(){
super();
super("achievements");
AchievementsDS ads = new AchievementsDS();
HashMap<String, AchievementListData> achList = ads.getAchievementsList();
@@ -30,15 +25,4 @@ public class Achievements extends Array {
this.childNodes.add(new Achievement(achList.get(achName)));
}
}
public Element getXml(Document doc){
Element result = doc.createElement("achievements");
result.setAttribute("count", this.getCountStr());
for(Elem ach : this.childNodes){
result.appendChild(ach.getXml(doc));
}
return result;
}
}

View File

@@ -3,11 +3,18 @@
*/
package de.sockenklaus.XmlStats.Objects;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* @author socrates
*
*/
public abstract class Array extends Elem{
public abstract class Array extends NodeList {
public Array(String tagName){
super(tagName);
}
public int getCountInt(){
return this.childNodes.size();
@@ -16,4 +23,10 @@ public abstract class Array extends Elem{
public String getCountStr(){
return String.valueOf(this.childNodes.size());
}
public Element getXml(Document doc){
this.attributes.put("count", String.valueOf(this.childNodes.size()));
return super.getXml(doc);
}
}

View File

@@ -12,6 +12,14 @@ import org.w3c.dom.Element;
*/
public class Categories extends Array {
/**
* @param tagName
*/
public Categories() {
super("categories");
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see de.sockenklaus.XmlStats.Objects.Array#getXml(org.w3c.dom.Document)
*/

View File

@@ -1,81 +0,0 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import java.util.ArrayList;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* @author socrates
*
*/
public class Elem {
protected String textContent;
protected String elemName;
protected ArrayList<Elem> childNodes;
protected Elem(){
this.childNodes = new ArrayList<Elem>();
}
protected Elem(String elemName){
this();
this.elemName = elemName;
}
protected Elem(String elemName, String textContent){
this(elemName);
this.textContent = textContent;
}
protected Elem(String elemName, Integer intContent){
this(elemName);
this.textContent = intContent.toString();
}
protected Element addXmlChild(String elemName, String text, Document doc){
Element result = doc.createElement(elemName);
result.setTextContent(text);
return result;
}
protected Element addXmlChild(String elemName, int value, Document doc){
Element result = doc.createElement(elemName);
result.setTextContent(String.valueOf(value));
return result;
}
/**
* @param doc
* @return
*/
public Element getXml(Document doc){
Element result = doc.createElement(this.elemName);
if(!this.textContent.isEmpty()) result.setTextContent(this.textContent);
for (Elem child : this.childNodes){
result.appendChild(child.getXml(doc));
}
return result;
}
public void setTextContent(String content){
this.textContent = content;
}
public void addChild(Elem child){
this.childNodes.add(child);
}
public Elem getFirstChild(){
if (this.childNodes.size() > 0) return this.childNodes.get(0);
else throw new IndexOutOfBoundsException();
}
}

View File

@@ -5,13 +5,12 @@ package de.sockenklaus.XmlStats.Objects;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* @author socrates
*
*/
public class Item extends Elem {
public class Item extends Node {
/* (non-Javadoc)
* @see de.sockenklaus.XmlStats.Objects.Elem#getXml(org.w3c.dom.Document)

View File

@@ -12,6 +12,14 @@ import org.w3c.dom.Element;
*/
public class Items extends Array {
/**
* @param tagName
*/
public Items() {
super("items");
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see de.sockenklaus.XmlStats.Objects.Array#getXml(org.w3c.dom.Document)
*/

View File

@@ -0,0 +1,43 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import de.sockenklaus.XmlStats.XmlStats;
/**
* @author socrates
*
*/
public abstract class Node {
protected String tagName;
protected HashMap<String, String> attributes;
public Node(){
this.attributes = new HashMap<String, String>();
XmlStats.LogDebug("Casting the constructor of Node()");
}
public void setAttribute(String name, String value){
this.attributes.put(name, value);
}
public Element getXml(Document doc){
XmlStats.LogDebug("Casting the first level getXml()");
Element result = doc.createElement(this.tagName);
for(String attrName : this.attributes.keySet()){
result.setAttribute(attrName, this.attributes.get(attrName));
}
return result;
}
}

View File

@@ -0,0 +1,36 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import java.util.ArrayList;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* @author socrates
*
*/
public abstract class NodeList extends Node {
protected ArrayList<Node> childNodes;
public NodeList(String tagName){
this.childNodes = new ArrayList<Node>();
this.tagName = tagName;
}
public void addChild(Node child){
this.childNodes.add(child);
}
public Element getXml(Document doc){
Element result = super.getXml(doc);
for(Node node : this.childNodes){
result.appendChild(node.getXml(doc));
}
return result;
}
}

View File

@@ -0,0 +1,38 @@
/**
*
*/
package de.sockenklaus.XmlStats.Objects;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* @author socrates
*
*/
public class NodeText extends Node {
protected String textContent;
public NodeText(String tagName){
this.tagName = tagName;
}
public NodeText(String tagName, String textContent){
this(tagName);
this.textContent = textContent;
}
public NodeText(String tagName, Integer intContent) {
this(tagName);
this.textContent = intContent.toString();
}
public Element getXml(Document doc){
Element result = super.getXml(doc);
if (!this.textContent.isEmpty()) result.setTextContent(this.textContent);
return result;
}
}

View File

@@ -5,13 +5,12 @@ package de.sockenklaus.XmlStats.Objects;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* @author socrates
*
*/
public class User extends Elem {
public class User extends Node {
private String name;

View File

@@ -3,9 +3,6 @@
*/
package de.sockenklaus.XmlStats.Objects;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import de.sockenklaus.XmlStats.XmlStats;
/**
@@ -14,22 +11,10 @@ import de.sockenklaus.XmlStats.XmlStats;
*/
public class UserAchievement extends Achievement {
private String name;
private int count;
public UserAchievement(String paName, com.nidefawl.Achievements.Achievement achievement){
this.name = paName;
this.count = achievement.getCount();
this.childNodes.add(new NodeText("name", paName));
this.childNodes.add(new NodeText("count", achievement.getCount()));
XmlStats.LogDebug("UserAchievement-const castet.");
}
public Element getXml(Document doc){
Element result = doc.createElement("achievement");
result.appendChild(this.addXmlChild("name", this.name, doc));
result.appendChild(this.addXmlChild("count", this.count, doc));
return result;
}
}

View File

@@ -33,15 +33,4 @@ public class UserAchievements extends Achievements {
}
else throw new XmlStatsException("The given username is not valid.");
}
public Element getXml(Document doc){
Element result = doc.createElement("achievements");
result.setAttribute("count", this.getCountStr());
for(Elem ach : this.childNodes){
result.appendChild(ach.getXml(doc));
}
return result;
}
}

View File

@@ -12,6 +12,14 @@ import org.w3c.dom.Element;
*/
public class Users extends Array {
/**
* @param tagName
*/
public Users() {
super("users");
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see de.sockenklaus.XmlStats.Objects.Elem#getXml(org.w3c.dom.Document)
*/