本文整理匯總了Java中com.thoughtworks.xstream.io.xml.DomDriver類的典型用法代碼示例。如果您正苦於以下問題:Java DomDriver類的具體用法?Java DomDriver怎麽用?Java DomDriver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DomDriver類屬於com.thoughtworks.xstream.io.xml包,在下文中一共展示了DomDriver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: DriverEndToEndTestSuite
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
public DriverEndToEndTestSuite() {
super(DriverEndToEndTestSuite.class.getName());
addDriverTest(new BEAStaxDriver());
addDriverTest(new BinaryStreamDriver());
addDriverTest(new Dom4JDriver());
addDriverTest(new DomDriver());
addDriverTest(new JDomDriver());
addDriverTest(new JDom2Driver());
addDriverTest(new KXml2DomDriver());
addDriverTest(new KXml2Driver());
addDriverTest(new StaxDriver());
addDriverTest(new StandardStaxDriver());
addDriverTest(new WstxDriver());
addDriverTest(new XomDriver());
addDriverTest(new Xpp3DomDriver());
addDriverTest(new Xpp3Driver());
addDriverTest(new XppDomDriver());
addDriverTest(new XppDriver());
addDriverTest(new JettisonMappedXmlDriver());
}
示例2: readXMLObject
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
/**
*
* @param filename
* @param doValidate
* @return
*/
public default Object readXMLObject(String filename, boolean doValidate) {
String xmlContents = null;
Object myModelClassInstance = null;
try {
xmlContents = new String(Files.readAllBytes(Paths.get(filename)));
XStream xstream = new XStream(new DomDriver());
customizeXstream(xstream);
myModelClassInstance = xstream.fromXML(xmlContents);
} catch (IOException iOException) {
// do nothing for now
}
return myModelClassInstance;
}
示例3: loadXML
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
public static SPStoryWorldData loadXML(File xmlFile) throws FileNotFoundException {
FileReader reader = new FileReader(xmlFile);
XStream xstream = new XStream(new DomDriver());
xstream.autodetectAnnotations(true);
xstream.alias(SPStoryWorldData.class.getAnnotation(XStreamAlias.class).value(), SPStoryWorldData.class);
Object obj = xstream.fromXML(reader);
try {
reader.close();
} catch (IOException e) {
}
if (!(obj instanceof SPStoryWorldData)) throw new RuntimeException("file " + xmlFile.getAbsolutePath() + " doesn't contain a xml with SPStoryWorldData");
SPStoryWorldData data = (SPStoryWorldData) obj;
data.file = xmlFile.getAbsolutePath();
return data;
}
示例4: readFile
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
/**
* Reads in an XML file describing a fully serialized game.
*/
@Override
public IGame readFile (File xmlFile) throws LoadErrorException {
XStream xstream = new XStream(new DomDriver());
FXConverters.configure(xstream);
xstream.setMode(XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES);
try {
String xml = fileToXMLString(xmlFile);
return (IGame) xstream.fromXML(xml);
}
catch (IOException | UnknownFieldException e) {
// TODO throw a checked error here to make front-end deal with an error if the file is
// corrupted
throw new LoadErrorException("Could not deserialize file: " + xmlFile.getPath());
}
}
示例5: loadRules
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
/**
*
* 加載配置文件
* @return
* @throws Exception
*/
@SuppressWarnings("unchecked")
protected Map<String, Rule> loadRules() throws Exception {
final Map<String, Rule> routerMap = new HashMap<String, Rule>();
if (getRuleConfige() != null) {
final XStream xstream = new XStream(new DomDriver());
xstream.alias("rules", List.class);
xstream.alias("rule", Entity.class);
List<Entity> rules = new ArrayList<Entity>();
rules = (List<Entity>) xstream.fromXML(getRuleConfige().getInputStream());
for (final Entity entity : rules) {
final Rule router = new Rule();
final Class<?> clazz = Class.forName(entity.strategy);
final IStrategy instance = (IStrategy) clazz.newInstance();
instance.initStrategy(entity.tables.split(","));
router.setShardStrategy(instance);
router.setXmlTableParam(entity.tableParam);
router.setFieldParam(entity.field);
makeRouterMap(entity, router, routerMap);
}
}
return routerMap;
}
示例6: main
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
public static void main (String[] args){
Sprite a = new Sprite("bricks.jpg","DA", null, null);
Sprite b = new Sprite("bricks.jpg","eA", null, null);
List<Sprite> sprites = new ArrayList<Sprite>();
sprites.add(a);
sprites.add(b);
XStream mySerializer = new XStream(new DomDriver());
try {
mySerializer.toXML(sprites,new FileOutputStream(new File("game_data/ExampleData.xml")));
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例7: main
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
public static void main (String[] args){
Rectangle r1 = new Rectangle(3,5);
Line l2 = new Line(3,5,6,9);
Rectangle r2 = new Rectangle(7,19);
Rectangle r3 = new Rectangle(3,9);
List<Node> sprites = new ArrayList<Node>();
sprites.add(r1);
sprites.add(l2);
sprites.add(r2);
sprites.add(r3);
XStream mySerializer = new XStream(new DomDriver());
try {
mySerializer.toXML(sprites,new FileOutputStream(new File("game_data/ExampleData.xml")));
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例8: toBean
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
/**
* 將一個xml流轉換為bean實體類
*
* @param type
* @param is
* @return
*/
@SuppressWarnings("unchecked")
public synchronized static <T> T toBean(Class<T> type, InputStream is) {
XStream xmStream = new XStream(new DomDriver());
// 設置可忽略為在javabean類中定義的界麵屬性
xmStream.ignoreUnknownElements();
xmStream.processAnnotations(type);
T obj = null;
try {
obj = (T) xmStream.fromXML(is);
} catch (Exception e) {
Logger.log("===解析xml發生異常:" + e.getMessage());
} finally {
FileUtils.closeIO(is);
}
return obj;
}
示例9: getSpec
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
private <T> T getSpec(URL file) {
try {
XStream xstream = new XStream(new DomDriver());
xstream.autodetectAnnotations(true);
xstream.processAnnotations(Bit.class);
xstream.processAnnotations(BitField.class);
xstream.processAnnotations(Characteristic.class);
xstream.processAnnotations(Enumeration.class);
xstream.processAnnotations(Enumerations.class);
xstream.processAnnotations(Field.class);
xstream.processAnnotations(InformativeText.class);
xstream.processAnnotations(Service.class);
xstream.processAnnotations(Value.class);
xstream.processAnnotations(Reserved.class);
xstream.processAnnotations(Examples.class);
xstream.processAnnotations(CharacteristicAccess.class);
xstream.processAnnotations(Characteristics.class);
xstream.processAnnotations(Properties.class);
xstream.ignoreUnknownElements();
xstream.setClassLoader(Characteristic.class.getClassLoader());
return (T) xstream.fromXML(file);
} catch (Exception e) {
logger.error("Could not read file: " + file, e);
}
return null;
}
示例10: storeData
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
private final void storeData(String topic, String message)
{
//AbstractDriver
System.out.println("message received "+ topic);
XStream dataStreamer = new XStream(new DomDriver() );// DomDriver());
@SuppressWarnings("unchecked")
Map<String, Object> data = (Map<String, Object>)dataStreamer.fromXML(message);
ArrayList<FollowedVariable> dts=this.receivedData.get(topic);
System.out.println("message received "+ topic+" "+data);
if(dts==null)
{
//dts = new FollowedVariable(topic);
//this.receivedData.put(topic,dts);
return;
}
for(FollowedVariable dt:dts)
dt.pushNewData(data);
}
示例11: getEmail
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
private Email getEmail() {
try {
StringBuilder xml = new StringBuilder();
Scanner scanner = new Scanner(new FileReader("email.xml"));
while (scanner.hasNext()) {
xml.append(scanner.next());
}
XStream xStream = new XStream(new DomDriver());
Email email = (Email) xStream.fromXML(xml.toString());
return email;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null,
"Arquivo email.xml não encontrado.",
"Erro",
JOptionPane.ERROR_MESSAGE);
}
return null;
}
示例12: getDatabase
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
/**
* @return O objeto Database.
*/
public static Database getDatabase() {
try {
StringBuilder xml = new StringBuilder();
Scanner scanner = new Scanner(new FileReader("database.xml"));
while (scanner.hasNext()) {
xml.append(scanner.next());
}
XStream xStream = new XStream(new DomDriver());
Database banco = (Database) xStream.fromXML(xml.toString());
return banco;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null,
"Não foi possível estabelecer conexão com o banco.\n\n"
+ "ERRO: Arquivo database.xml não encontrado.",
"Erro de conexão",
JOptionPane.ERROR_MESSAGE);
FrmConfiguraBanco configuraBanco = new FrmConfiguraBanco(null, true);
configuraBanco.setVisible(true);
}
return null;
}
示例13: getDatabase
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
/**
* @return O objeto Database.
*/
public static Database getDatabase() {
try {
StringBuilder xml = new StringBuilder();
Scanner scanner = new Scanner(new FileReader("database.xml"));
while (scanner.hasNext()) {
xml.append(scanner.next());
}
XStream xStream = new XStream(new DomDriver());
Database banco = (Database) xStream.fromXML(xml.toString());
return banco;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null,
"Não foi possível estabelecer conexão com o banco de dados.\n\n"
+ "ERRO: Arquivo database.xml não encontrado.",
"Erro de conexão",
JOptionPane.ERROR_MESSAGE);
FrmConfiguraBanco configuraBanco = new FrmConfiguraBanco(null, true);
configuraBanco.setVisible(true);
}
return null;
}
示例14: loadXStream
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
private static XStream loadXStream() {
XStream xstream = new XStream(new DomDriver("UTF-8")) {
@Override
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new MapperWrapper(next) {
@Override
public boolean shouldSerializeMember(@SuppressWarnings("rawtypes") Class definedIn,
String fieldName) {
if (definedIn == Object.class) {
return false;
}
return super.shouldSerializeMember(definedIn, fieldName);
}
};
}
};
xstream.setMode(XStream.NO_REFERENCES);
return xstream;
}
示例15: getXStream
import com.thoughtworks.xstream.io.xml.DomDriver; //導入依賴的package包/類
public static XStream getXStream() {
if (xstream == null) {
xstream = new XStream(new DomDriver());
xstream.alias("ActionMessage", ActionMessage.class);
xstream.alias("MessageHeader", MessageHeader.class);
xstream.alias("MessageBody", MessageBody.class);
xstream.alias("RemotingMessage", RemotingMessage.class);
xstream.alias("CommandMessage", CommandMessage.class);
xstream.alias("AcknowledgeMessage", AcknowledgeMessage.class);
xstream.alias("ErrorMessage", ErrorMessage.class);
xstream.alias("ASObject", ASObject.class);
xstream.alias("AsyncMessage", AsyncMessage.class);
xstream.alias("DSC", CommandMessageExt.class);
// xstream.alias("DSK", AcknowledgeMessageExt.class);
// Better ASObject Converter
Mapper mapper = xstream.getMapper();
xstream.registerConverter(new ASObjectConverter(mapper));
}
return xstream;
}