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: /**
020: * @author Mikhail A. Markov
021: * @version $Revision: 1.7.4.3 $
022: */package java.rmi.server;
023:
024: import java.io.IOException;
025: import java.net.ServerSocket;
026: import java.net.Socket;
027:
028: import org.apache.harmony.rmi.internal.nls.Messages;
029: import org.apache.harmony.rmi.transport.DefaultRMISocketFactory;
030:
031: /**
032: * @com.intel.drl.spec_ref
033: *
034: * @author Mikhail A. Markov
035: * @version $Revision: 1.7.4.3 $
036: */
037: public abstract class RMISocketFactory implements
038: RMIClientSocketFactory, RMIServerSocketFactory {
039:
040: /*
041: * Global RMISocketFactory set by user application and null
042: * if default RMISocketFactory is used.
043: */
044: private static RMISocketFactory globalRsf = null;
045:
046: /*
047: * Global RMIFailureHandler set by user application.
048: */
049: private static RMIFailureHandler globalRfh = null;
050:
051: /*
052: * Default RMISocketFactory.
053: */
054: private static RMISocketFactory defaultRsf = null;
055:
056: /**
057: * @com.intel.drl.spec_ref
058: */
059: public RMISocketFactory() {
060: }
061:
062: /**
063: * @com.intel.drl.spec_ref
064: */
065: public abstract Socket createSocket(String host, int port)
066: throws IOException;
067:
068: /**
069: * @com.intel.drl.spec_ref
070: */
071: public abstract ServerSocket createServerSocket(int port)
072: throws IOException;
073:
074: /**
075: * @com.intel.drl.spec_ref
076: */
077: public static synchronized void setSocketFactory(
078: RMISocketFactory rsf) throws IOException, SecurityException {
079: SecurityManager mgr = System.getSecurityManager();
080:
081: if (mgr != null) {
082: mgr.checkSetFactory();
083: }
084:
085: if (globalRsf == null) {
086: // rmi.1F=RMISocketFactory has been already set.
087: throw new IOException(Messages.getString("rmi.1F")); //$NON-NLS-1$
088: }
089: globalRsf = rsf;
090: }
091:
092: /**
093: * @com.intel.drl.spec_ref
094: */
095: public static synchronized RMISocketFactory getSocketFactory() {
096: return globalRsf;
097: }
098:
099: /**
100: * @com.intel.drl.spec_ref
101: */
102: public static synchronized RMISocketFactory getDefaultSocketFactory() {
103: if (defaultRsf == null) {
104: defaultRsf = new DefaultRMISocketFactory();
105: }
106: return defaultRsf;
107: }
108:
109: /**
110: * @com.intel.drl.spec_ref
111: */
112: public static synchronized void setFailureHandler(
113: RMIFailureHandler rfh) throws SecurityException {
114: SecurityManager mgr = System.getSecurityManager();
115:
116: if (mgr != null) {
117: mgr.checkSetFactory();
118: }
119: globalRfh = rfh;
120: }
121:
122: /**
123: * @com.intel.drl.spec_ref
124: */
125: public static synchronized RMIFailureHandler getFailureHandler() {
126: return globalRfh;
127: }
128: }
|