Zum Inhalt springen

java dom ( XML _Baum)


Empfohlene Beiträge

Geschrieben

Ich habe Probleme um meine gesamten Baum in Java Dom zu erstellen (public void update() ). Ich habe nur bis zum Knoten <ECUsListe/> (Bzw. <AKTORsListe/>,... ). Ich weiss nicht wie es weiter geht.


package view.hw;


import java.awt.BorderLayout;

import java.awt.Component;

import java.awt.event.ActionEvent;

import java.awt.event.KeyEvent;


import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JTabbedPane;

import javax.swing.KeyStroke;


import model.ModelFailureStructure;

import model.ModelGeneralTreeSystem;


import org.w3c.dom.Node;

import org.w3c.dom.NodeList;


import run.StartFA;

import view.TreeSystem;

import controller.ListenerOpen;

import controller.ListenerSave;

import controller.hw.ExitListener;

import data.filebase.FailureModelFile;


public class Editor extends JFrame {


	public static Editor editor = null;


	private static final long serialVersionUID = 1L;


	private Ecu ecu;

	private Aktor aktor;

	private Sensor sensor;

	private Bus bus;

	private Gateway gateway;


	public Editor(Component pane, ModelGeneralTreeSystem mgts,

			ModelFailureStructure mfs, TreeSystem tac) {

		editor = this;

		methode(pane, mgts, mfs, tac);

		this.setTitle("FehlermodellierungsEditor");

		this.setSize(800, 400);

		this.setVisible(true);

		update();

	}


	public void methode(Component pane, ModelGeneralTreeSystem mgts,

			ModelFailureStructure mfs, TreeSystem tac) {

		JMenuItem openItem, exitItem;

		final JMenuItem saveItem;

		JMenuBar menuBar = new JMenuBar();

		setJMenuBar(menuBar);

		setDefaultCloseOperation(EXIT_ON_CLOSE);


		JMenu fileMenu = (JMenu) menuBar.add(new JMenu("File"));

		fileMenu.setMnemonic(KeyEvent.VK_F);

		menuBar.add(fileMenu);


		openItem = new JMenuItem(" Open ", new ImageIcon("./img/open.gif"));

		openItem.setMnemonic(KeyEvent.VK_O);

		openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,

				ActionEvent.CTRL_MASK));

		fileMenu.add(openItem);

		fileMenu.addSeparator();

		saveItem = new JMenuItem(" Save ", new ImageIcon("./img/save1.gif"));

		saveItem.setMnemonic(KeyEvent.VK_S);

		saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,

				ActionEvent.CTRL_MASK));

		fileMenu.add(saveItem);

		fileMenu.addSeparator();

		exitItem = new JMenuItem(" Exit ", new ImageIcon("./img/exit.gif"));

		exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,

				ActionEvent.CTRL_MASK));

		exitItem.setMnemonic(KeyEvent.VK_E);

		fileMenu.add(exitItem);


		ecu = new Ecu();

		aktor = new Aktor();

		sensor = new Sensor();

		bus = new Bus();

		gateway = new Gateway();


		JTabbedPane tp = new JTabbedPane();

		tp.add("    ECU ", ecu.getHauptPanel());

		tp.add("    AKTOR ", aktor.getHauptPanel());

		tp.add("    SENSOR ", sensor.getHauptPanel());

		tp.add("    BUS ", bus.getHauptPanel());

		tp.add("    GATEWAY ", gateway.getHauptPanel());


		this.getContentPane().setLayout(new BorderLayout());

		this.getContentPane().add(menuBar);

		this.getContentPane().add(tp);

		setJMenuBar(menuBar);


		exitItem.addActionListener(new ExitListener());

		openItem.addActionListener(new ListenerOpen(pane, mgts, mfs));

		saveItem.addActionListener(new ListenerSave(tac, (JFrame) pane));

	}


	public void update() {

		FailureModelFile smm = (FailureModelFile) StartFA.factory

				.getSimulinkModel(null);

		Node root = smm.getRootNode();


		// doc = XML-DOKUMENT

		NodeList childList1 = root.getChildNodes();

		boolean existImplementationNode = false;

		boolean ecuExist = false;

		boolean busExist = false;

		boolean sensorExist = false;

		boolean aktorExist = false;

		boolean gatewayExist = false;

		for(int childcount1 = 0; childcount1 < childList1.getLength(); childcount1++) {

			Node child1 = childList1.item(childcount1);

			if (child1.getNodeName().equals("Implementierung")) {

				existImplementationNode = true;

				NodeList childLst2 = child1.getChildNodes();

				for (int childcount2 = 0; childcount2 < childLst2.getLength(); childcount2++) {

					Node child2 = childLst2.item(childcount2);

					if (child2.getNodeName().equals("ECUsListe")) {

						ecuExist = true;

					}

					if (!ecuExist) {

						Node ecuNode = child1.getOwnerDocument().createElement(

								"ECUsListe");

						child1.appendChild(ecuNode);

						ecuExist = true;

					}

					if (child2.getNodeName().equals("AKTORsListe")) {

						aktorExist = true;

					}

					if (!aktorExist) {

						Node aktorNode = child1.getOwnerDocument()

								.createElement("AKTORsListe");

						child1.appendChild(aktorNode);

						aktorExist = true;

					}

					if (child2.getNodeName().equals("SENSORsListe")) {

						sensorExist = true;

					}

					if (!sensorExist) {

						Node sensorNode = child1.getOwnerDocument()

								.createElement("SENSORsListe");

						child1.appendChild(sensorNode);

						sensorExist = true;

					}

					if (child2.getNodeName().equals("BUSsListe")) {

						busExist = true;

					}

					if (!busExist) {

						Node busNode = child1.getOwnerDocument().createElement(

								"BUSsListe");

						child1.appendChild(busNode);

						busExist = true;

					}

					if (child2.getNodeName().equals("GATEWAYsListe")) {

						gatewayExist = true;


					}

					if (!gatewayExist) {

						Node gatewayNode = child1.getOwnerDocument()

								.createElement("GATEWAYsListe");

						child1.appendChild(gatewayNode);

						gatewayExist = true;

					}


				}

			}

			if (!existImplementationNode) {

				Node implementationNode = root.getOwnerDocument()

						.createElement("Implementierung");

				System.out.println("iii;");

				root.appendChild(implementationNode);


				Node ecuNode = implementationNode.getOwnerDocument().createElement("ECUsListe");

				Node aktorNode = implementationNode.getOwnerDocument().createElement(

						"AKTORsListe");

				Node sensorNode = implementationNode.getOwnerDocument().createElement(

						"SENSORsListe");

				Node busNode = implementationNode.getOwnerDocument()

						.createElement("BUSsListe");

				Node gatewayNode = implementationNode.getOwnerDocument().createElement(

						"GATEWAYsListe");

				implementationNode.appendChild(ecuNode);

				implementationNode.appendChild(aktorNode);

				implementationNode.appendChild(sensorNode);

				implementationNode.appendChild(busNode);

				implementationNode.appendChild(gatewayNode);


				existImplementationNode = true;

				ecuExist = true;

				busExist = true;

				sensorExist = true;

				aktorExist = true;

				gatewayExist = true;

			}

			System.out.println("XXX;");


			}

	}

}


So sieht der XMl-Baum:

<System>

<Implementierung>

<ECUsListe>

<ECU-Name> ecu1 <ECU-Name/>

<FehlerEigenschaften>

<FehlerName = "Falscher Wert">

<FehlerWahrscheinlichkeit> 0.001 </FehlerWahrscheinlichkeit>

</FehlerName>

<FehlerName = "Wert unerwünscht">

<FehlerWahrscheinlichkeit> 0.00018 </FehlerWahrscheinlichkeit>

</FehlerName>

<FehlerName = "Rest">

<FehlerWahrscheinlichkeit> 0.041 </FehlerWahrscheinlichkeit>

</FehlerName>

........

</FehlerEigenschaften>

<ECU-Name> ecu2 <ECU-Name/>

<FehlerEigenschaften>

<FehlerName = "Falscher Wert">

<FehlerWahrscheinlichkeit> 0.001 </FehlerWahrscheinlichkeit>

</FehlerName>

<FehlerName = "Wert unerwünscht">

<FehlerWahrscheinlichkeit> 0.00018 </FehlerWahrscheinlichkeit>

</FehlerName>

<FehlerName = "Rest">

<FehlerWahrscheinlichkeit> 0.041 </FehlerWahrscheinlichkeit>

</FehlerName>

........

</FehlerEigenschaften>

.........

<ECU-Name> .........

</ECUsListe>

+<AKTORsListe/>

+<SENSORsListe/>

+<BUSsListe/>

+<GATEWAYsListe/>

Bsp.:

- <System>

-<Signal>

- .....

- <Implementierung>

- <ECUsListe>

<ECU-Name>ecu1</ECU-Name>

<ECU-Name>ecu64</ECU-Name>

</ECUsListe>

- <AKTORsListe>

<AKTOR-Name>akhfalkhf</AKTOR-Name>

</AKTORsListe>

<SENSORsListe />

<BUSsListe />

<GATEWAYsListe />

</Implementierung>

</System>

Danke vorraus!

Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...