什么是定期从XML文件检查书籍状态的方法的概念,如果状态改变,它将通过RCP提醒?我想创建将执行此操作的任务。 我在JFrame中拥有的主要课程。
这是XmlFile和POJO。
package net.kxyz;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import xyz.libary.Book;
import xyz.libary.DataInterface;
/**
*
* @author kuman
*/
public class XmlDataInterfaceImpl implements DataInterface {
File fXmlFile = new File("baza.xml");
ArrayList<Book> book = new ArrayList<>();
@Override
public void updateBook(Book book2) {
int index = book2.getId();
this.book.get(index).setTitle(book2.getTitle());
this.book.get(index).setAuthor(book2.getAuthor());
this.book.get(index).setYear(book2.getYear());
this.book.get(index).setState(book2.isState());
}
@Override
public ArrayList<Book> getAllBooks() {
//code
return book;
}
public void addBook(Book book2) {
//code
}
@Override
public void deleteBook(Book book) {
//code
}
private void toFile() {
//code
}
}
POJO
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package xyz.libary;
/**
*
* @author kuman
*/
public class Book {
int id;
String title;
String author;
int year;
Boolean state;
public Book() {};
public Book(int id, String title, String author, int year) {
this.id = id ;
this.title = title;
this.author = author;
this.year = year;
this.state = true;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Boolean isState() {
return state;
}
public void setState(Boolean state) {
this.state = state;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public void setState(Object value) {
this.state=(Boolean)(value);
}
}
答案 0 :(得分:0)
您可以创建一个在xyz时间后重复的作业。
final Job job = new Job("Name")
{
@Override
protected IStatus run( final IProgressMonitor monitor )
{
// do something
schedule( delay ) // schedule again after "delay" mili seconds
return status;
}
};
job.schedule();
请参阅https://www.eclipse.org/articles/Article-Concurrency/jobs-api.html或