Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ****************************************************************************
- // **
- // ** Spieler.java
- // ** Description
- // **
- // ****************************************************************************
- package de.fussballmanager.data;
- // ============================================================================
- // IMPLEMENTATION REQUIRED IMPORTS
- // ============================================================================
- import org.w3c.dom.Attr;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- // ============================================================================
- // IMPLEMENTATION CLASS BODY
- // ============================================================================
- public class Spieler {
- // ========================================================================
- // IMPLEMENTATION PRIVATE CONSTANTS
- // ========================================================================
- // ========================================================================
- // IMPLEMENTATION PUBLIC CONSTANTS
- // ========================================================================
- // ========================================================================
- // IMPLEMENTATION PRIVATE DATA
- // ========================================================================
- // spieler specific instance variables
- private String name;
- // instance variables for easy reading and writing of xml
- private String filename;
- private Node spielerNodeXML;
- // ========================================================================
- // IMPLEMENTATION PUBLIC DATA
- // ========================================================================
- // ========================================================================
- // IMPLEMENTATION PRIVATE METHODS
- // ========================================================================
- private void parseSpielerXML(Node spielerNodeXML) {
- // store the node that belongs to the mannschaft
- this.spielerNodeXML = spielerNodeXML;
- // get the attributes of the mannschaft node and extract what we need
- try {
- NamedNodeMap spielerAttributes = this.spielerNodeXML.getAttributes();
- this.name = spielerAttributes.getNamedItem("name").getTextContent();
- } catch (NullPointerException npEx) {
- System.err.println("Error while parsing " + this.filename
- + " while reading the attributes of a spieler.");
- System.err.println("There are missing spieler attributes.");
- System.err.println("Required attributes are: \"name\".");
- System.exit(4);
- }
- }
- // ========================================================================
- // IMPLEMENTATION PUBLIC METHODS
- // ========================================================================
- public Spieler(String filename, Node spielerNodeXML) {
- // store the filename to this liga's xml file
- this.filename = filename;
- // parse the node and extract all informations we need
- this.parseSpielerXML(spielerNodeXML);
- }
- // getters/setters
- public String getName() {
- return this.name;
- }
- public void setName(String name) {
- Attr attribute = (Attr) this.spielerNodeXML.getAttributes().getNamedItem(
- "name");
- attribute.setValue(name);
- this.name = name;
- }
- }
- // ****************************************************************************
- // **
- // ** Spieler.java
- // **
- // ****************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement