Skip to content

Commit

Permalink
xml without servlet
Browse files Browse the repository at this point in the history
  • Loading branch information
siqq committed Oct 14, 2014
1 parent 4161c24 commit 5a822be
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 369 deletions.
2 changes: 0 additions & 2 deletions Java-Missle/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="forms-1.3.0.jar" sourcepath="forms-1.3.0-src.zip"/>
<classpathentry kind="lib" path="C:/Users/Andrey/Desktop/mysql-connector-java-5.1.33-bin.jar"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="C:/Users/Andrey/Desktop/eclipse-jee-luna-SR1-win32-x86_64/tc/lib/servlet-api.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions Java-Missle/.settings/org.eclipse.ltk.core.refactoring.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
1 change: 0 additions & 1 deletion Java-Missle/.settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="Java-Missle">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="context-root" value="Java-Missle"/>
<property name="java-output-path" value="/Java-Missle/bin"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
3 changes: 0 additions & 3 deletions Java-Missle/WebContent/META-INF/MANIFEST.MF

This file was deleted.

30 changes: 0 additions & 30 deletions Java-Missle/WebContent/WarHtml.html

This file was deleted.

2 changes: 1 addition & 1 deletion Java-Missle/src/main/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void main(String[] args) {
AbstractWarView viewGui = new WarGui();
// new Server();
WarController controller = new WarController(warModel,viewGui);
XMLparser xml = new XMLparser(controller);
XMLparser xml = new XMLparser(controller, warModel);

} catch (ParserConfigurationException e) {
e.printStackTrace();
Expand Down
71 changes: 33 additions & 38 deletions Java-Missle/src/main/XMLparser.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Vector;

import javax.xml.parsers.DocumentBuilder;
Expand All @@ -24,30 +23,29 @@
import war.War;
import war.WarUtility;
import war.controller.WarController;
import war.controller.WarUIEventsListener;

public class XMLparser {
private Vector<Launcher> missileLaunchers = new Vector<>();
private Vector<Destructor> missileDestructors = new Vector<>();
private Vector<Destructor> missileLauncherDestructors = new Vector<>();
private War war;
private WarController controller;

public XMLparser(WarController controller) throws ParserConfigurationException, SAXException,
public XMLparser(WarController controller,War war) throws ParserConfigurationException, SAXException,
IOException {
this.controller = controller;
this.war = war;
readXML();
}

public void readXML() throws ParserConfigurationException, SAXException,
public War readXML() throws ParserConfigurationException, SAXException,
IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Get the DOM Builder
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
InputStream xml_file = ClassLoader
.getSystemResourceAsStream("war2.xml");
.getSystemResourceAsStream("war.xml");
//check if we have xml file
if (xml_file == null) {
return war;
}
Document document = builder.parse(xml_file);
// Load and Parse the XML document
Expand All @@ -72,6 +70,7 @@ public void readXML() throws ParserConfigurationException, SAXException,
}
}
}
return war;
}

/**
Expand All @@ -90,17 +89,18 @@ private void addLauncherToArray(Node launcher, Node rootNode)
boolean isHidden = Boolean.parseBoolean(launcher
.getAttributes().getNamedItem("isHidden")
.getNodeValue());
missileLaunchers.add(new Launcher(id, isHidden , controller.getWarListeners()));
// missileLaunchers.add(new Launcher(id, isHidden,controller.getWarListeners()));
controller.addLauncherToUI(id);
} else {
String type = launcher.getAttributes().getNamedItem("type")
.getNodeValue();
if ((rootNode.getNodeName().equals("missileDestructors"))) {
missileDestructors.add(new Destructor(
id, type, new Vector<AbstractMissile>()));
// missileDestructors.add(new Destructor(id, type, new Vector<AbstractMissile>()));

controller.addDestructorToUI(id, type);
} else {
missileLauncherDestructors
.add(new Destructor(id, type,
new Vector<AbstractMissile>()));
// missileLauncherDestructors.add(new Destructor(id, type,new Vector<AbstractMissile>()));
controller.addDestructorToUI(id, type);
}
}
}
Expand All @@ -122,17 +122,18 @@ private void addMissileToArray(Node missile, int index) {
// missile list
String destination = missile.getAttributes()
.getNamedItem("destination").getNodeValue();
int launchtime = Integer.parseInt(missile.getAttributes()
.getNamedItem("launchTime").getNodeValue());
int flytime = Integer.parseInt(missile.getAttributes()
.getNamedItem("flyTime").getNodeValue());
int damage = Integer.parseInt(missile.getAttributes()
.getNamedItem("damage").getNodeValue());
String launchtime = missile.getAttributes()
.getNamedItem("launchTime").getNodeValue();
String flytime =missile.getAttributes()
.getNamedItem("flyTime").getNodeValue();
String damage = missile.getAttributes()
.getNamedItem("damage").getNodeValue();

// get the launcher and add missile to it
Launcher launcher = missileLaunchers.get(index / 2);
launcher.addMissile(id, destination, launchtime, flytime,
damage);
Launcher launcher = war.getMissileLaunchers().get(index / 2);
// missileLaunchers.get(index / 2);
controller.addMissileToUI(id, destination, damage, flytime, launcher.getLauncherId());
// launcher.addMissile(id, destination, launchtime, flytime,damage);
break;
case "destructdMissile":
// case 2 it is a missle to destruct missles need
Expand All @@ -141,11 +142,11 @@ private void addMissileToArray(Node missile, int index) {
.getAttributes().getNamedItem("destructAfterLaunch")
.getNodeValue());
// get the destructor and then add missile destructor to it
Destructor destructor_m = missileDestructors
.get(index / 2);
Missile target_m = WarUtility.getMissileById(id, controller.getWarModel());
DestructedMissile destructedM = new DestructedMissile(target_m,
destructAfterLaunch, destructor_m, destructor_m.getFileHandler(), controller.getWarListeners());
Destructor destructor_m = war.getMissileDestructors().get(index / 2);
// missileDestructors.get(index / 2);
Missile target_m = WarUtility.getMissileById(id, war);
DestructedMissile destructedM = new DestructedMissile(target_m,destructAfterLaunch, destructor_m, destructor_m.getFileHandler(),controller.getWarListeners());

destructor_m.addDestructMissile(destructedM);
break;
case "destructedLanucher":
Expand All @@ -155,20 +156,14 @@ private void addMissileToArray(Node missile, int index) {
.getNamedItem("destructTime").getNodeValue());
// get the destructor and then add missile launcher destructor
// to it
Destructor destructor_l = missileLauncherDestructors
.get(index / 2);
Launcher target_l = WarUtility.getLauncherById(id, controller.getWarModel());
Destructor destructor_l = war.getMissileLauncherDestructors().get(index / 2);
Launcher target_l = WarUtility.getLauncherById(id, war);
DestructedLanucher destructedL = new DestructedLanucher(target_l,
destructTime, destructor_l, destructor_l.getFileHandler() , controller.getWarListeners());
destructTime, destructor_l, destructor_l.getFileHandler(),controller.getWarListeners());
destructor_l.addDestructMissile(destructedL);
break;
}
}
}

public Vector<Launcher> getMissileLaunchers() {
return missileLaunchers;
}


}
67 changes: 0 additions & 67 deletions Java-Missle/src/servlet/IdfControlServlet.java

This file was deleted.

4 changes: 2 additions & 2 deletions Java-Missle/src/war.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
</launcher>
</missileLaunchers>
<missileDestructors>
<destructor id="D201" type="kipat barzel">
<destructor id="D201" type="Iron Dome">
<destructdMissile id="M1" destructAfterLaunch="4"></destructdMissile>
<destructdMissile id="M3" destructAfterLaunch="7"></destructdMissile>
<destructdMissile id="M4" destructAfterLaunch="2"></destructdMissile>
</destructor>
<destructor id="D202" type="kipat barzel">
<destructor id="D202" type="Iron Dome">
<destructdMissile id="M2" destructAfterLaunch="3"></destructdMissile>
</destructor>
</missileDestructors>
Expand Down
14 changes: 6 additions & 8 deletions Java-Missle/src/war/War.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Vector<Destructor> getMissileLauncherDestructors() {
}

public void addLauncherDestructor(Destructor desctructor) {
this.missileLauncherDestructors.add(desctructor);
missileLauncherDestructors.add(desctructor);
fireAddLauncherDestructorEvent(desctructor);
desctructor.start();
}
Expand All @@ -111,7 +111,7 @@ public void fireAddLauncherDestructorEvent(Destructor desctructor) {
}

public void addMissileDestructor(Destructor desctructor) {
this.missileDestructors.add(desctructor);
missileDestructors.add(desctructor);
fireAddMissileDestructorEvent(desctructor);
desctructor.start();
}
Expand Down Expand Up @@ -188,18 +188,16 @@ public void addLauncher(String id) throws Exception {



public void addDestructor(String id, String type) throws SecurityException, IOException {
public void addDestructor(String id, String type) throws SecurityException, IOException {

if (WarUtility.getDestructorById(id, this, type) != null) {
// tell controller the id already exists
}
if (type.equals("Plane") || type.equals("Ship")) {
Destructor desctructor = new Destructor(
id, type, new Vector<AbstractMissile>());
if (type.equals("plane") || type.equals("ship")) {
Destructor desctructor = new Destructor(id, type, new Vector<AbstractMissile>());
addLauncherDestructor(desctructor);
} else if (type.equals("Iron Dome")) {
Destructor desctructor = new Destructor(
id, type, new Vector<AbstractMissile>());
Destructor desctructor = new Destructor(id, type, new Vector<AbstractMissile>());
addMissileDestructor(desctructor);
}
WarDBConnection.addNewDestructor(id, type);
Expand Down
Loading

0 comments on commit 5a822be

Please sign in to comment.