Mój temat przeniesiono do kosza a ja zapytam jeszcze raz bo wtedy nie dostalem odpowiedzi.
Czy ta klasa jest komponentem I chodzi mi o sposob programowania !!! (czytaj programowanie struktualne, obiektowe i komponentowe) np java beans. Jesli nie to co musi zawierac zeby byc komponentem.
Jeszcze raz powtarzam nie chodzi mi o Component (jakim jest jLabel itp) Wiem co to Component!
package pl.toXML.app;
import nu.xom.*;
import java.io.*;
import java.util.*;
public class Zgloszenia {
public String nr, data, imie, nazwisko, sprzet, opis, status;
public Zgloszenia(String nr, String data, String imie, String nazwisko, String sprzet, String opis, String status){
this.nr = nr;
this.data = data;
this.imie = imie;
this.nazwisko = nazwisko;
this.sprzet = sprzet;
this.opis = opis;
this.status = status;
}
//Tworzy element (Element) XML na bazie obiektu Zgloszenie (this):
public Element getXML(){
Element zgloszenie = new Element("zgloszenie");
Element nrid = new Element("nr");
nrid.appendChild(nr);
Element dataid = new Element("data");
dataid.appendChild(data);
Element imieid = new Element("imie");
imieid.appendChild(imie);
Element nazwiskoid = new Element("nazwisko");
nazwiskoid.appendChild(nazwisko);
Element sprzetid = new Element("sprzet");
sprzetid.appendChild(sprzet);
Element opisid = new Element("opis");
opisid.appendChild(opis);
Element statusid = new Element("status");
statusid.appendChild(status);
zgloszenie.appendChild(nrid);
zgloszenie.appendChild(dataid);
zgloszenie.appendChild(imieid);
zgloszenie.appendChild(nazwiskoid);
zgloszenie.appendChild(sprzetid);
zgloszenie.appendChild(opisid);
zgloszenie.appendChild(statusid);
return zgloszenie;
}
//Konstruktor przywracający obiekt Zgloszenie z elementu XML:
public Zgloszenia(Element zgloszenie){
nr = zgloszenie.getFirstChildElement("nr").getValue();
data = zgloszenie.getFirstChildElement("data").getValue();
imie = zgloszenie.getFirstChildElement("imie").getValue();
nazwisko = zgloszenie.getFirstChildElement("nazwisko").getValue();
sprzet = zgloszenie.getFirstChildElement("sprzet").getValue();
opis = zgloszenie.getFirstChildElement("opis").getValue();
status = zgloszenie.getFirstChildElement("status").getValue();
}
public String toString(){return nr + " " + data;}
//Dla czytelności:
public static void format(OutputStream os, Document doc) throws Exception{
Serializer serializer = new Serializer(os,"Windows-1250");
serializer.setIndent(4);
serializer.setMaxLength(60);
serializer.write(doc);
serializer.flush();
}
public static void glowny() throws Exception{
List<Zgloszenia> people = Arrays.asList(
new Zgloszenia("aaaaaa", "Kleks","a","fsfd","fsdfsd","fsdff","sdff"));
//new Zgloszenia(app.Zgloszenie.jPanel1.jTextField1.getText(""), "Kleks","a","","","",""));
System.out.println(people);
Element root = new Element("zgloszenie");
for(Zgloszenia p: people)
root.appendChild(p.getXML());
Document doc = new Document(root);
format(System.out, doc);
format(new BufferedOutputStream(new FileOutputStream(
"zgloszenie.xml")), doc);
}
}