001: /*
002: * $Id: AccessDeniedException.java,v 1.17 2007/09/11 12:39:57 agoubard Exp $
003: *
004: * Copyright 2003-2007 Orange Nederland Breedband B.V.
005: * See the COPYRIGHT file for redistribution and use restrictions.
006: */
007: package org.xins.server;
008:
009: /**
010: * Exception that indicates that there is no function matching the request.
011: *
012: * @version $Revision: 1.17 $ $Date: 2007/09/11 12:39:57 $
013: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
014: *
015: * @since XINS 1.0.0
016: */
017: public final class AccessDeniedException extends Exception {
018:
019: /**
020: * The IP address which is denied for the given function. This field may be
021: * <code>null</code>.
022: */
023: private final String _ip;
024:
025: /**
026: * The name of the function which does not grant the access. This field may
027: * be <code>null</code>.
028: */
029: private final String _functionName;
030:
031: /**
032: * The name of the calling convention which does not grant the access.
033: * This field may be <code>null</code>.
034: */
035: private final String _conventionName;
036:
037: /**
038: * Constructs a new <code>AccessDeniedException</code> for the specified
039: * IP address and function name.
040: *
041: * @param ip
042: * the IP address, or <code>null</code>.
043: *
044: * @param functionName
045: * the name of the function, or <code>null</code>.
046: *
047: * @param conventionName
048: * the name of the calling convention, can be <code>null</code>.
049: */
050: AccessDeniedException(String ip, String functionName,
051: String conventionName) {
052: super (createMessage(ip, functionName, conventionName));
053: _ip = ip;
054: _functionName = functionName;
055: _conventionName = conventionName;
056: }
057:
058: /**
059: * Creates the error message for this exception.
060: *
061: * @param ip
062: * the IP address, or <code>null</code>.
063: *
064: * @param functionName
065: * the name of the function, or <code>null</code>.
066: *
067: * @param conventionName
068: * the name of the calling convention, can be <code>null</code>.
069: *
070: * @return
071: * the error message to be used by the constructor, never
072: * <code>null</code>.
073: */
074: private static String createMessage(String ip, String functionName,
075: String conventionName) {
076:
077: String message = null;
078:
079: // Function name and IP address given
080: if (functionName != null && ip != null) {
081: message = "The function \"" + functionName
082: + "\" cannot be accessed from IP address " + ip;
083:
084: // Only IP address given
085: } else if (ip != null) {
086: message = "An unspecified function cannot be accessed from IP address "
087: + ip;
088:
089: // Only function name given
090: } else if (functionName != null) {
091: message = "The function \"" + functionName
092: + "\" cannot be accessed";
093:
094: // Neither function name nor IP address given
095: } else {
096: message = "An unspecified function cannot be accessed";
097: }
098: if (conventionName == null || conventionName.equals("*")) {
099: message += ".";
100: } else {
101: message += " using the calling convention "
102: + conventionName + ".";
103: }
104: return message;
105: }
106:
107: /**
108: * Gets the IP address which is denied for the given function.
109: *
110: * @return
111: * the IP address, or <code>null</code> if no IP address was provided.
112: */
113: public String getIP() {
114: return _ip;
115: }
116:
117: /**
118: * Gets the name of the function which does not grant the access.
119: *
120: * @return
121: * the name of the function, or <code>null</code> if no function name
122: * was provided.
123: */
124: public String getFunctionName() {
125: return _functionName;
126: }
127:
128: /**
129: * Gets the name of the calling convention which does not grant the access.
130: *
131: * @return
132: * the name of the calling convention, or <code>null</code>
133: * if no calling convention name was provided.
134: *
135: * @since XINS 2.1
136: */
137: public String getConventionName() {
138: return _conventionName;
139: }
140: }
|