001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.management.modelmbean;
023:
024: import java.io.IOException;
025: import java.io.ObjectInputStream;
026: import java.io.ObjectOutputStream;
027: import java.io.ObjectStreamField;
028:
029: import org.jboss.mx.util.Serialization;
030:
031: /**
032: * Thrown when unrecognizable target object type is set to a Model MBean
033: * instance
034: *
035: * @see javax.management.modelmbean.ModelMBean
036: *
037: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
038: * @author <a href="mailto:adrian.brock@happeningtimes.com">Adrian Brock</a>.
039: * @version $Revision: 57200 $
040: *
041: * <p><b>Revisions:</b>
042: * <p><b>20020715 Adrian Brock:</b>
043: * <ul>
044: * <li> Serialization
045: * </ul>
046: */
047: public class InvalidTargetObjectTypeException extends Exception {
048: // Attributes ----------------------------------------------------
049: private Exception exception = null;
050:
051: // Static --------------------------------------------------------
052:
053: private static final long serialVersionUID;
054: private static final ObjectStreamField[] serialPersistentFields;
055:
056: static {
057: switch (Serialization.version) {
058: case Serialization.V1R0:
059: serialVersionUID = 3711724570458346634L;
060: serialPersistentFields = new ObjectStreamField[] {
061: new ObjectStreamField("msgStr", String.class),
062: new ObjectStreamField("relatedExcept",
063: Exception.class), };
064: break;
065: default:
066: serialVersionUID = 1190536278266811217L;
067: serialPersistentFields = new ObjectStreamField[] { new ObjectStreamField(
068: "exception", Exception.class), };
069: }
070: }
071:
072: // Constructors --------------------------------------------------
073: public InvalidTargetObjectTypeException() {
074: super ();
075: }
076:
077: public InvalidTargetObjectTypeException(String s) {
078: super (s);
079: }
080:
081: public InvalidTargetObjectTypeException(Exception e, String s) {
082: super (s);
083: this .exception = e;
084: }
085:
086: // Object overrides ----------------------------------------------
087:
088: /**
089: * Returns a string representation of this exception. The returned string
090: * contains this exception name, message and a string representation of the
091: * target exception if it has been set.
092: *
093: * @return string representation of this exception
094: */
095: public String toString() {
096: return "InvalidTargetObjectTypeException: "
097: + getMessage()
098: + ((exception == null) ? "" : " Cause: "
099: + exception.toString());
100: }
101:
102: // Private -------------------------------------------------------
103:
104: private void readObject(ObjectInputStream ois) throws IOException,
105: ClassNotFoundException {
106: switch (Serialization.version) {
107: case Serialization.V1R0:
108: ObjectInputStream.GetField getField = ois.readFields();
109: exception = (Exception) getField.get("relatedExcept", null);
110: break;
111: default:
112: ois.defaultReadObject();
113: }
114: }
115:
116: private void writeObject(ObjectOutputStream oos) throws IOException {
117: switch (Serialization.version) {
118: case Serialization.V1R0:
119: ObjectOutputStream.PutField putField = oos.putFields();
120: putField.put("msgStr", getMessage());
121: putField.put("relatedExcept", exception);
122: oos.writeFields();
123: break;
124: default:
125: oos.defaultWriteObject();
126: }
127: }
128: }
|