001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.geoserver.platform;
006:
007: import java.lang.reflect.Method;
008:
009: /**
010: * An operation descriptor providing metadata about a service operation.
011: * <p>
012: * An operation is identified by an id,service pair. Two operation
013: * descriptors are considred equal if they have the same id, service pair.
014: * </p>
015: *
016: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
017: */
018: public final class Operation {
019: /**
020: * Unique identifier withing service of the operation.
021: */
022: final String id;
023:
024: /**
025: * Service this operation is a component of.
026: */
027: final Service service;
028:
029: /**
030: * The method implementing the operation
031: */
032: final Method method;
033:
034: /**
035: * Parameters of the operation
036: */
037: final Object[] parameters;
038:
039: /**
040: * Creates a new operation descriptor.
041: *
042: * @param id Id of the operation, must not be <code>null</code>
043: * @param service The service containing the operation, must not be <code>null</code>
044: * @param method THe method implementing the operation.
045: * @param parameters The parameters of the operation, may be <code>null</code>
046: *
047: */
048: public Operation(String id, Service service, Method method,
049: Object[] parameters) {
050: this .id = id;
051: this .service = service;
052: this .method = method;
053: this .parameters = parameters;
054:
055: if (id == null) {
056: throw new NullPointerException("id");
057: }
058:
059: if (service == null) {
060: throw new NullPointerException("service");
061: }
062: }
063:
064: /**
065: * @return The id of the operation.
066: */
067: public String getId() {
068: return id;
069: }
070:
071: /**
072: * @return The service implementing the operation.
073: */
074: public Service getService() {
075: return service;
076: }
077:
078: /**
079: * @return The method implementing the operation.
080: */
081: public Method getMethod() {
082: return method;
083: }
084:
085: /**
086: * @return The parameters supplied to the operation
087: */
088: public Object[] getParameters() {
089: return parameters;
090: }
091:
092: public boolean equals(Object obj) {
093: if (obj == null) {
094: return false;
095: }
096:
097: if (!(obj instanceof Operation)) {
098: return false;
099: }
100:
101: Operation other = (Operation) obj;
102:
103: if (!id.equals(other.id)) {
104: return false;
105: }
106:
107: if (!service.equals(other.service)) {
108: return false;
109: }
110:
111: return true;
112: }
113:
114: public int hashCode() {
115: return (id.hashCode() * 17) + service.hashCode();
116: }
117:
118: public String toString() {
119: return "Operation( " + id + ", " + service.getId() + " )";
120: }
121: }
|