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.enterprise.deploy.spi.status;
023:
024: import java.util.EventObject;
025: import java.io.ObjectStreamField;
026: import java.io.ObjectOutputStream;
027: import java.io.IOException;
028: import java.io.ObjectInputStream;
029:
030: import javax.enterprise.deploy.spi.TargetModuleID;
031:
032: import org.jboss.util.id.SerialVersion;
033:
034: /**
035: * An event describing the progress of a deployment
036: */
037: public class ProgressEvent extends EventObject {
038: /** @since 4.0.2 */
039: static final long serialVersionUID;
040:
041: // Constants -----------------------------------------------------
042: /**
043: * These field names match the j2ee 1.4.1 ri version names
044: */
045: private static final ObjectStreamField[] serialPersistentFields;
046: private static final int STATUS_IDX = 0;
047: private static final int MODULE_ID_IDX = 1;
048:
049: static {
050: if (SerialVersion.version == SerialVersion.LEGACY) {
051: serialVersionUID = 3097551795061550569L;
052: serialPersistentFields = new ObjectStreamField[] {
053: /** @serialField statuscode DeploymentStatus current deployment status */
054: new ObjectStreamField("status", DeploymentStatus.class),
055: /** @serialField targetModuleID TargetModuleID id of the event target */
056: new ObjectStreamField("moduleID", TargetModuleID.class) };
057: } else {
058: // j2ee 1.4.1 RI values
059: serialVersionUID = 7815118532096485937L;
060: serialPersistentFields = new ObjectStreamField[] {
061: /** @serialField statuscode DeploymentStatus current deployment status */
062: new ObjectStreamField("statuscode",
063: DeploymentStatus.class),
064: /** @serialField targetModuleID TargetModuleID id of the event target */
065: new ObjectStreamField("targetModuleID",
066: TargetModuleID.class) };
067: }
068: }
069:
070: // Attributes ----------------------------------------------------
071:
072: /** The deployment status */
073: private DeploymentStatus status;
074: /** The module id */
075: private TargetModuleID moduleID;
076:
077: // Static --------------------------------------------------------
078:
079: // Constructors --------------------------------------------------
080:
081: /**
082: * Create a new progress event
083: *
084: * @param source the source
085: * @param status the deployment status
086: * @param moduleID the module id
087: */
088: public ProgressEvent(Object source, TargetModuleID moduleID,
089: DeploymentStatus status) {
090: super (source);
091: this .status = status;
092: this .moduleID = moduleID;
093: }
094:
095: // Public --------------------------------------------------------
096:
097: /**
098: * Get the target module id
099: *
100: * @return the module id
101: */
102: public TargetModuleID getTargetModuleID() {
103: return moduleID;
104: }
105:
106: /**
107: * Get the deployment status
108: *
109: * @return the deployment status
110: */
111: public DeploymentStatus getDeploymentStatus() {
112: return status;
113: }
114:
115: // Package protected ---------------------------------------------
116:
117: // Protected -----------------------------------------------------
118:
119: // Private -------------------------------------------------------
120: private void readObject(ObjectInputStream ois)
121: throws ClassNotFoundException, IOException {
122: ObjectInputStream.GetField fields = ois.readFields();
123: String name = serialPersistentFields[STATUS_IDX].getName();
124: this .status = (DeploymentStatus) fields.get(name, null);
125: name = serialPersistentFields[MODULE_ID_IDX].getName();
126: this .moduleID = (TargetModuleID) fields.get(name, null);
127: }
128:
129: private void writeObject(ObjectOutputStream oos) throws IOException {
130: // Write j2ee 1.4.1 RI field names
131: ObjectOutputStream.PutField fields = oos.putFields();
132: String name = serialPersistentFields[STATUS_IDX].getName();
133: fields.put(name, status);
134: name = serialPersistentFields[MODULE_ID_IDX].getName();
135: fields.put(name, moduleID);
136: oos.writeFields();
137: }
138:
139: // Inner classes -------------------------------------------------
140: }
|