01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.invocation;
23:
24: import java.io.Serializable;
25: import java.io.ObjectStreamException;
26:
27: /** Type safe enumeration used for to identify the invocation types.
28: *
29: * @author Scott.Stark@jboss.org
30: * @author Christoph.Jung@infor.de
31: * @version $Revision: 57209 $
32: */
33: public final class InvocationType implements Serializable {
34: /** Serial Version Identifier. @since 1.2 */
35: private static final long serialVersionUID = 6460196085190851775L;
36: /** The method-intf names for the InvocationType enums */
37: private static final String[] INTERFACE_NAMES = { "Remote",
38: "Local", "Home", "LocalHome", "ServiceEndpoint" };
39:
40: /** The max ordinal value in use for the InvocationType enums. When you add a
41: * new key enum value you must assign it an ordinal value of the current
42: * MAX_TYPE_ID+1 and update the MAX_TYPE_ID value.
43: */
44: private static final int MAX_TYPE_ID = 4;
45:
46: /** The array of InvocationKey indexed by ordinal value of the key */
47: private static final InvocationType[] values = new InvocationType[MAX_TYPE_ID + 1];
48: public static final InvocationType REMOTE = new InvocationType(
49: "REMOTE", 0);
50: public static final InvocationType LOCAL = new InvocationType(
51: "LOCAL", 1);
52: public static final InvocationType HOME = new InvocationType(
53: "HOME", 2);
54: public static final InvocationType LOCALHOME = new InvocationType(
55: "LOCALHOME", 3);
56: public static final InvocationType SERVICE_ENDPOINT = new InvocationType(
57: "SERVICE_ENDPOINT", 4);
58:
59: private final transient String name;
60:
61: // this is the only value serialized
62: private final int ordinal;
63:
64: private InvocationType(String name, int ordinal) {
65: this .name = name;
66: this .ordinal = ordinal;
67: values[ordinal] = this ;
68: }
69:
70: public String toString() {
71: return name;
72: }
73:
74: /** Get the method-intf name for the type
75: *
76: * @return one of: "Remote", "Local", "Home", "LocalHome", "ServiceEndpoint"
77: */
78: public String toInterfaceString() {
79: return INTERFACE_NAMES[ordinal];
80: }
81:
82: Object readResolve() throws ObjectStreamException {
83: return values[ordinal];
84: }
85: }
|