01: package org.jivesoftware.openfire.server;
02:
03: import org.jivesoftware.util.cache.CacheSizes;
04: import org.jivesoftware.util.cache.Cacheable;
05: import org.jivesoftware.util.cache.ExternalizableUtil;
06:
07: import java.io.Externalizable;
08: import java.io.IOException;
09: import java.io.ObjectInput;
10: import java.io.ObjectOutput;
11:
12: /**
13: * Holds the configuration when connecting to/from a remote server. The configuration specifies
14: * if incoming or outgoing connections are allowed to the remote server and the port to use
15: * when creating an outgoing connection.
16: *
17: * @author Gaston Dombiak
18: */
19: public class RemoteServerConfiguration implements Cacheable,
20: Externalizable {
21:
22: private String domain;
23:
24: private Permission permission;
25:
26: private int remotePort;
27:
28: public RemoteServerConfiguration() {
29: }
30:
31: public RemoteServerConfiguration(String domain) {
32: this .domain = domain;
33: }
34:
35: public String getDomain() {
36: return domain;
37: }
38:
39: public Permission getPermission() {
40: return permission;
41: }
42:
43: public void setPermission(Permission permission) {
44: this .permission = permission;
45: }
46:
47: public int getRemotePort() {
48: return remotePort;
49: }
50:
51: public void setRemotePort(int remotePort) {
52: this .remotePort = remotePort;
53: }
54:
55: public int getCachedSize() {
56: // Approximate the size of the object in bytes by calculating the size
57: // of each field.
58: int size = 0;
59: size += CacheSizes.sizeOfObject(); // overhead of object
60: size += CacheSizes.sizeOfString(domain); // domain
61: size += CacheSizes.sizeOfInt(); // remotePort
62: return size;
63: }
64:
65: public void writeExternal(ObjectOutput out) throws IOException {
66: ExternalizableUtil.getInstance().writeSafeUTF(out, domain);
67: ExternalizableUtil.getInstance().writeBoolean(out,
68: permission != null);
69: if (permission != null) {
70: ExternalizableUtil.getInstance().writeInt(out,
71: permission.ordinal());
72: }
73: ExternalizableUtil.getInstance().writeInt(out, remotePort);
74: }
75:
76: public void readExternal(ObjectInput in) throws IOException,
77: ClassNotFoundException {
78: domain = ExternalizableUtil.getInstance().readSafeUTF(in);
79: if (ExternalizableUtil.getInstance().readBoolean(in)) {
80: permission = Permission.values()[ExternalizableUtil
81: .getInstance().readInt(in)];
82: }
83: remotePort = ExternalizableUtil.getInstance().readInt(in);
84: }
85:
86: public enum Permission {
87: /**
88: * The XMPP entity is allowed to connect to the server.
89: */
90: allowed,
91:
92: /**
93: * The XMPP entity is NOT allowed to connect to the server.
94: */
95: blocked;
96: }
97: }
|