AbstractDevice.java 文件源码

java
阅读 21 收藏 0 点赞 0 评论 0

项目:OpenNotification 作者:
public static Device createFromXML(String xml) throws NotificationException {
    Device device = null;
    try {
        Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new StringBufferInputStream(xml));
        NodeList types = document.getElementsByTagName("type");
        if ((types == null) || (types.getLength()<=0)) {
            throw new NotificationException(NotificationException.NOT_ACCEPTABLE, "Device type not specified");
        }
        String type = types.item(0).getFirstChild().getNodeValue();
        BrokerFactory.getLoggingBroker().logDebug("new type="+type);
        device = (Device)Class.forName(type).newInstance();

        device.readXML(document.getElementsByTagName("settings").item(0));
    } catch (Exception anyExc) {
        BrokerFactory.getLoggingBroker().logError(anyExc);
        throw new NotificationException(NotificationException.FAILED, anyExc.getMessage());
    }

    return device;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号