ORBVersionFactory.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.corba.se.spi.orb ;
27
28import com.sun.corba.se.spi.orb.ORBVersion ;
29import com.sun.corba.se.impl.orb.ORBVersionImpl ;
30import org.omg.CORBA.portable.InputStream ;
31import org.omg.CORBA.INTERNAL ;
32
33public class ORBVersionFactory {
34    private ORBVersionFactory() {} ;
35
36    public static ORBVersion getFOREIGN()
37    {
38        return ORBVersionImpl.FOREIGN ;
39    }
40
41    public static ORBVersion getOLD()
42    {
43        return ORBVersionImpl.OLD ;
44    }
45
46    public static ORBVersion getNEW()
47    {
48        return ORBVersionImpl.NEW ;
49    }
50
51    public static ORBVersion getJDK1_3_1_01()
52    {
53        return ORBVersionImpl.JDK1_3_1_01 ;
54    }
55
56    public static ORBVersion getNEWER()
57    {
58        return ORBVersionImpl.NEWER ;
59    }
60
61    public static ORBVersion getPEORB()
62    {
63        return ORBVersionImpl.PEORB ;
64    }
65
66    /** Return the current version of this ORB
67     */
68    public static ORBVersion getORBVersion()
69    {
70        return ORBVersionImpl.PEORB ;
71    }
72
73    public static ORBVersion create( InputStream is )
74    {
75        byte value = is.read_octet() ;
76        return byteToVersion( value ) ;
77    }
78
79    private static ORBVersion byteToVersion( byte value )
80    {
81        /* Throwing an exception here would cause this version to be
82        * incompatible with future versions of the ORB, to the point
83        * that this version could
84        * not even unmarshal objrefs from a newer version that uses
85        * extended versioning.  Therefore, we will simply treat all
86        * unknown versions as the latest version.
87        if (value < 0)
88            throw new INTERNAL() ;
89        */
90
91        /**
92         * Update: If we treat all unknown versions as the latest version
93         * then when we send an IOR with a PEORB version to an ORB that
94         * doesn't know the PEORB version it will treat it as whatever
95         * its idea of the latest version is.  Then, if that IOR is
96         * sent back to the server and compared with the original
97         * the equality check will fail because the versions will be
98         * different.
99         *
100         * Instead, just capture the version bytes.
101         */
102
103        switch (value) {
104            case ORBVersion.FOREIGN : return ORBVersionImpl.FOREIGN ;
105            case ORBVersion.OLD : return ORBVersionImpl.OLD ;
106            case ORBVersion.NEW : return ORBVersionImpl.NEW ;
107            case ORBVersion.JDK1_3_1_01: return ORBVersionImpl.JDK1_3_1_01 ;
108            case ORBVersion.NEWER : return ORBVersionImpl.NEWER ;
109            case ORBVersion.PEORB : return ORBVersionImpl.PEORB ;
110            default : return new ORBVersionImpl(value);
111        }
112    }
113}
114