001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: package java.rmi.activation;
020:
021: import java.io.IOException;
022: import java.io.ObjectInputStream;
023: import java.io.ObjectOutputStream;
024: import java.io.Serializable;
025: import java.lang.reflect.Constructor;
026: import java.rmi.MarshalledObject;
027: import java.rmi.Remote;
028: import java.rmi.RemoteException;
029: import java.rmi.server.RMIClassLoader;
030: import java.rmi.server.RemoteObject;
031: import java.rmi.server.RemoteRef;
032: import java.rmi.server.UID;
033: import org.apache.harmony.rmi.common.RMILog;
034: import org.apache.harmony.rmi.internal.nls.Messages;
035:
036: public class ActivationID implements Serializable {
037: private static final long serialVersionUID = -4608673054848209235L;
038:
039: private static final RMILog rlog = RMILog.getActivationLog();
040:
041: /**
042: * A unique identifier for the object.
043: */
044: private transient UID uid = new UID();
045:
046: /**
047: * A remote reference to the object's activator.
048: */
049: private transient Activator activator;
050:
051: public ActivationID(Activator activator) {
052: super ();
053: this .activator = activator;
054: }
055:
056: public Remote activate(boolean force) throws ActivationException,
057: UnknownObjectException, RemoteException {
058: // rmi.log.00=ActivationID.activate: activator = {0}
059: rlog.log(RMILog.VERBOSE, Messages.getString(
060: "rmi.log.00", activator)); //$NON-NLS-1$
061: try {
062: MarshalledObject stub = activator.activate(this , force);
063: // rmi.log.01=ActivationID.activate:stub={0}
064: rlog.log(RMILog.VERBOSE, Messages.getString(
065: "rmi.log.01", stub)); //$NON-NLS-1$
066: Remote deserialized_stub = (Remote) stub.get();
067: // rmi.log.02=ActivationID.activate: deserialized_stub = {0}
068: rlog.log(RMILog.VERBOSE, Messages.getString(
069: "rmi.log.02", deserialized_stub)); //$NON-NLS-1$
070: // rmi.log.03=<<<<<<<<< ActivationID.activate COMPLETED.
071: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.03")); //$NON-NLS-1$
072: return deserialized_stub;
073: } catch (IOException ioe) {
074: // rmi.0E=An IOException occurred while deserializing the object from its internal representation.
075: throw new RemoteException(Messages.getString("rmi.0E")); //$NON-NLS-1$
076: } catch (ClassNotFoundException cnfe) {
077: // rmi.0F=A ClassNotFoundException occurred while deserializing the object from its internal representation.
078: throw new RemoteException(Messages.getString("rmi.0F")); //$NON-NLS-1$
079: }
080: }
081:
082: @Override
083: public boolean equals(Object obj) {
084: if (obj instanceof ActivationID) {
085: ActivationID castedObj = (ActivationID) obj;
086: boolean p0, p1;
087: p0 = uid.equals(castedObj.uid);
088: p1 = activator.equals(castedObj.activator);
089: return p0 && p1;
090: }
091: return false;
092: }
093:
094: @Override
095: public int hashCode() {
096: return activator.hashCode() ^ uid.hashCode();
097: }
098:
099: private void readObject(ObjectInputStream in) throws IOException,
100: ClassNotFoundException {
101: // rmi.log.06=ActivationID.readObject:
102: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.06")); //$NON-NLS-1$
103: try {
104: uid = (UID) in.readObject();
105: // rmi.log.07=UID={0}
106: rlog.log(RMILog.VERBOSE, Messages.getString(
107: "rmi.log.07", uid)); //$NON-NLS-1$
108: String refType = in.readUTF();
109: // rmi.log.08=refType={0}
110: rlog.log(RMILog.VERBOSE, Messages.getString(
111: "rmi.log.08", refType)); //$NON-NLS-1$
112: Class<?> cl = Class
113: .forName("org.apache.harmony.rmi.remoteref." //$NON-NLS-1$
114: + refType);
115: RemoteRef ref = (RemoteRef) cl.newInstance();
116: // rmi.log.09=ref = {0}
117: rlog.log(RMILog.VERBOSE, Messages.getString(
118: "rmi.log.09", ref)); //$NON-NLS-1$
119: ref.readExternal(in);
120: // rmi.log.0A=readExternal finished successfully.
121: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.0A")); //$NON-NLS-1$
122: Class<?> activator_class = RMIClassLoader.loadClass(
123: (String) null,
124: "org.apache.harmony.rmi.activation.Rmid_Stub"); //$NON-NLS-1$
125: Class[] constructor_parameter_classes = { RemoteRef.class };
126: Constructor<?> constructor = activator_class
127: .getConstructor(constructor_parameter_classes);
128: Object[] constructor_parameters = { ref };
129: activator = (Activator) constructor
130: .newInstance(constructor_parameters);
131: // rmi.log.0B=ActivationID.readObject COMPLETED.
132: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.0B")); //$NON-NLS-1$
133: } catch (Throwable t) {
134: // rmi.09=Unable to deserialize ActivationID: {0}
135: throw new IOException(Messages.getString("rmi.09", t)); //$NON-NLS-1$
136: }
137: }
138:
139: private void writeObject(ObjectOutputStream out)
140: throws IOException, ClassNotFoundException {
141: // rmi.log.0C=ActivationID.writeObject:
142: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.0C")); //$NON-NLS-1$
143: try {
144: out.writeObject(uid);
145: // rmi.log.0D=activator = {0}
146: rlog.log(RMILog.VERBOSE, Messages.getString(
147: "rmi.log.0D", activator)); //$NON-NLS-1$
148: RemoteRef ref = ((RemoteObject) activator).getRef();
149: // rmi.log.09=ref = {0}
150: rlog.log(RMILog.VERBOSE, Messages.getString(
151: "rmi.log.09", ref)); //$NON-NLS-1$
152: String refType = ref.getRefClass(out);
153: // rmi.log.08=refType={0}
154: rlog.log(RMILog.VERBOSE, Messages.getString(
155: "rmi.log.08", refType)); //$NON-NLS-1$
156: out.writeUTF(refType);
157: ref.writeExternal(out);
158: // rmi.log.04=ActivationID.writeObject COMPLETED.
159: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.04")); //$NON-NLS-1$
160: } catch (Throwable t) {
161: // rmi.0A=Unable to serialize ActivationID: {0}
162: throw new IOException(Messages.getString(
163: "rmi.0A", t.getMessage()));//$NON-NLS-1$
164: }
165: }
166:
167: @Override
168: public String toString() {
169: return "ActivationID: [" + uid + "; " + activator + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
170: }
171: }
|