noticefactory.java

来自「opennms得相关源码 请大家看看」· Java 代码 · 共 1,047 行 · 第 1/3 页

JAVA
1,047
字号
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// For more information contact://      OpenNMS Licensing       <license@opennms.org>//      http://www.opennms.org///      http://www.opennms.com///package org.opennms.web.notification;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.sql.Timestamp;import java.util.Date;import java.util.Vector;import org.opennms.core.resource.Vault;import org.opennms.core.utils.ThreadCategory;import org.opennms.web.element.NetworkElementFactory;/** * Encapsulates all querying functionality for notices *  * @author <A HREF="mailto:larry@opennms.org">Lawrence Karnowski </A> * @author <A HREF="http://www.opennms.org/">OpenNMS </A> */public class NoticeFactory extends Object {    /** Convenience class to determine sort style of a query. */    public static class SortStyle extends Object {        /* CORBA-style enumeration */        public static final int _USER = 1;        public static final int _RESPONDER = 2;        public static final int _PAGETIME = 3;        public static final int _RESPONDTIME = 4;        public static final int _NODE = 5;        public static final int _INTERFACE = 6;        public static final int _SERVICE = 7;        public static final int _ID = 8;        public static final SortStyle USER = new SortStyle("USER", _USER);        public static final SortStyle RESPONDER = new SortStyle("RESPONDER", _RESPONDER);        public static final SortStyle PAGETIME = new SortStyle("PAGETIME", _PAGETIME);        public static final SortStyle RESPONDTIME = new SortStyle("RESPONDTIME", _RESPONDTIME);        public static final SortStyle NODE = new SortStyle("NODE", _NODE);        public static final SortStyle INTERFACE = new SortStyle("INTERFACE", _INTERFACE);        public static final SortStyle SERVICE = new SortStyle("SERVICE", _SERVICE);        public static final SortStyle ID = new SortStyle("ID", _ID);        public static final int _REVERSE_USER = 101;        public static final int _REVERSE_RESPONDER = 102;        public static final int _REVERSE_PAGETIME = 103;        public static final int _REVERSE_RESPONDTIME = 104;        public static final int _REVERSE_NODE = 105;        public static final int _REVERSE_INTERFACE = 106;        public static final int _REVERSE_SERVICE = 107;        public static final int _REVERSE_ID = 108;        public static final SortStyle REVERSE_USER = new SortStyle("REVERSE_USER", _REVERSE_USER);        public static final SortStyle REVERSE_RESPONDER = new SortStyle("REVERSE_RESPONDER", _REVERSE_RESPONDER);        public static final SortStyle REVERSE_PAGETIME = new SortStyle("REVERSE_PAGETIME", _REVERSE_PAGETIME);        public static final SortStyle REVERSE_RESPONDTIME = new SortStyle("REVERSE_RESPONDTIME", _REVERSE_RESPONDTIME);        public static final SortStyle REVERSE_NODE = new SortStyle("REVERSE_NODE", _REVERSE_NODE);        public static final SortStyle REVERSE_INTERFACE = new SortStyle("REVERSE_INTERFACE", _REVERSE_INTERFACE);        public static final SortStyle REVERSE_SERVICE = new SortStyle("REVERSE_SERVICE", _REVERSE_SERVICE);        public static final SortStyle REVERSE_ID = new SortStyle("REVERSE_ID", _REVERSE_ID);        protected String name;        protected int id;        private SortStyle(String name, int id) {            this.name = name;            this.id = id;        }        public String toString() {            return ("Notice.SortStyle." + this.name);        }        public String getName() {            return (this.name);        }        public int getId() {            return (this.id);        }    }    /**     * Convenience class to determine what sort of notices to include in a     * query.     */    public static class AcknowledgeType extends Object {        /* CORBA-style enumeration */        public static final int _ACKNOWLEDGED = 1;        public static final int _UNACKNOWLEDGED = 2;        public static final int _BOTH = 3;        public static final AcknowledgeType ACKNOWLEDGED = new AcknowledgeType("ACKNOWLEDGED", _ACKNOWLEDGED);        public static final AcknowledgeType UNACKNOWLEDGED = new AcknowledgeType("UNACKNOWLEDGED", _UNACKNOWLEDGED);        public static final AcknowledgeType BOTH = new AcknowledgeType("BOTH", _BOTH);        protected String name;        protected int id;        private AcknowledgeType(String name, int id) {            this.name = name;            this.id = id;        }        public String toString() {            return ("Notice.AcknowledgeType." + this.name);        }        public String getName() {            return (this.name);        }        public int getId() {            return (this.id);        }    }    /**     * Convenience class to determine what sort of notices to include in a     * query.     */    public interface Filter {        public String getSql();        public String getDescription();        public String getTextDescription();    }    /** Encapsulates all user filtering functionality. */    public static class UserFilter extends Object implements Filter {        public static final String TYPE = "user";        protected String user;        public UserFilter(String user) {            this.user = user;        }        public String getSql() {            return (" notifications.notifyid in (SELECT DISTINCT usersnotified.notifyid FROM usersnotified WHERE usersnotified.userid='" + this.user + "')");        }        public String getDescription() {            return (TYPE + "=" + this.user);        }        public String getTextDescription() {            return this.getDescription();        }        public String toString() {            return ("<NoticeFactory.UserFilter: " + this.getDescription() + ">");        }        public String getUser() {            return (this.user);        }        public boolean equals(Object obj) {            return (this.toString().equals(obj.toString()));        }    }    /** Encapsulates all responder filtering functionality. */    public static class ResponderFilter extends Object implements Filter {        public static final String TYPE = "responder";        protected String responder;        public ResponderFilter(String responder) {            this.responder = responder;        }        public String getSql() {            return (" ANSWEREDBY='" + this.responder + "'");        }        public String getDescription() {            return (TYPE + "=" + this.responder);        }        public String getTextDescription() {            return this.getDescription();        }        public String toString() {            return ("<NoticeFactory.ResponderFilter: " + this.getDescription() + ">");        }        public String getResponder() {            return (this.responder);        }        public boolean equals(Object obj) {            return (this.toString().equals(obj.toString()));        }    }    /** Encapsulates all node filtering functionality. */    public static class NodeFilter extends Object implements Filter {        public static final String TYPE = "node";        protected int nodeId;        public NodeFilter(int nodeId) {            this.nodeId = nodeId;        }        public String getSql() {            return (" NODEID=" + this.nodeId);        }        public String getDescription() {            return (TYPE + "=" + this.nodeId);        }        public String getTextDescription() {            String nodeName = Integer.toString(this.nodeId);            try {                nodeName = NetworkElementFactory.getNodeLabel(this.nodeId);            } catch (SQLException e) {            }            return (TYPE + "=" + nodeName);        }        public String toString() {            return ("<NoticeFactory.NodeFilter: " + this.getDescription() + ">");        }        public int getNodeId() {            return (this.nodeId);        }        public boolean equals(Object obj) {            return (this.toString().equals(obj.toString()));        }    }    /** Encapsulates all interface filtering functionality. */    public static class InterfaceFilter extends Object implements Filter {        public static final String TYPE = "interface";        protected String ipAddress;        public InterfaceFilter(String ipAddress) {            if (ipAddress == null) {                throw new IllegalArgumentException("Cannot take null parameters.");            }            this.ipAddress = ipAddress;        }        public String getSql() {            return (" INTERFACEID='" + this.ipAddress + "'");        }        public String getDescription() {            return (TYPE + "=" + this.ipAddress);        }        public String getTextDescription() {            return this.getDescription();        }        public String toString() {            return ("<NoticeFactory.InterfaceFilter: " + this.getDescription() + ">");        }        public String getIpAddress() {            return (this.ipAddress);        }        public boolean equals(Object obj) {            return (this.toString().equals(obj.toString()));        }    }    /** Encapsulates all service filtering functionality. */    public static class ServiceFilter extends Object implements Filter {        public static final String TYPE = "service";

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?