001: /*
002: * $Id: ObjectPanelModel.java 6115 2006-01-30 04:50:47Z dfs $
003: *
004: * Copyright 2004-2006 Daniel F. Savarese
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.savarese.org/software/ApacheLicense-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: package org.savarese.unicorn.ui;
020:
021: import javax.management.MBeanInfo;
022: import javax.management.AttributeNotFoundException;
023:
024: /**
025: * Interface for adapting objects for use by {@link ObjectPanel}.
026: */
027: public interface ObjectPanelModel<O extends Object> {
028:
029: /**
030: * Sets the object to be adapted to the interface.
031: *
032: * @param obj The object to be adapted.
033: */
034: public void setObject(O obj);
035:
036: /**
037: * Retrieves the object adapted to the interface.
038: *
039: * @return The object adapted to the interface.
040: */
041: public O getObject();
042:
043: /**
044: * Returns a string that identifies the object.
045: *
046: * @return A string that identifies the object.
047: */
048: public String getObjectName();
049:
050: /**
051: * Returns a description of the object.
052: *
053: * @return The a description of the object.
054: */
055: public MBeanInfo getObjectInfo();
056:
057: /**
058: * Determines if the model is in a valid state. A model may be
059: * rendered invalid if it has no object, if an exception is occurs
060: * during a remote invocation operation, or any number of reasons
061: * specific to the model implementation.
062: *
063: * @return True if the model is in a valid state, false if not.
064: */
065: public boolean isValid();
066:
067: /**
068: * Retrieves a named attribute from the adapted object.
069: *
070: * @param attribute The name of the attribute to retrieve.
071: * @return The attribute corresponding to the provided name.
072: * @throws AttributeNotFoundException If the attribute does not exist.
073: * @throws Exception If an error occurs while retrieving the
074: * attribute. An exception may occur while communicating with a
075: * remote object, while using reflection, or other reasons specific
076: * to the model implementation.
077: */
078: public Object getAttribute(String attribute)
079: throws AttributeNotFoundException, Exception;
080:
081: /**
082: * Sets the value of a named attribute of the adapted object.
083: *
084: * @param attribute The name of the attribute to set.
085: * @param value The new value of the attribute.
086: * @throws AttributeNotFoundException If the attribute does not exist.
087: * @throws Exception If an error occurs while retrieving the
088: * attribute. An exception may occur while communicating with a
089: * remote object, while using reflection, or other reasons specific
090: * to the model implementation.
091: */
092: public void setAttribute(String attribute, Object value)
093: throws AttributeNotFoundException, Exception;
094:
095: /**
096: * Invokes an operation of the adapted object and returns its result,
097: * if any.
098: *
099: * @param operation The name of the operation to invoke.
100: * @param params An array of parameters for the operation.
101: * @param types An array containing the types of the operation parameters.
102: * @param signature A string representation of the types (i.e., the
103: * fully qualified class names) of the operation parameters.
104: * @return The result of the operation, if any.
105: * @throws Exception If an unexpected condition arises that prvents
106: * the successful invocation of the operation.
107: */
108: public Object invoke(String operation, Object[] params,
109: Class[] types, String[] signature) throws Exception;
110:
111: /**
112: * Adds an {@link ObjectPanelModelListener} to the model. The
113: * listener is notifiied whenever the model changes.
114: *
115: * @param listener The listener to add.
116: */
117: public void addObjectPanelModelListener(
118: ObjectPanelModelListener<O> listener);
119:
120: /**
121: * Removes an {@link ObjectPanelModelListener} from the model.
122: *
123: * @param listener The listener to remove.
124: */
125: public void removeObjectPanelModelListener(
126: ObjectPanelModelListener<O> listener);
127: }
|