コード例 #1
0
        public EndpointI create(string str, bool oaEndpoint)
        {
            string[]? arr = IceUtilInternal.StringUtil.splitString(str, " \t\r\n");
            if (arr == null)
            {
                throw new System.FormatException("mismatched quote");
            }

            if (arr.Length == 0)
            {
                throw new System.FormatException("value has no non-whitespace characters");
            }

            List <string> v        = new List <string>(arr);
            string        protocol = v[0];

            v.RemoveAt(0);

            if (protocol.Equals("default"))
            {
                protocol = _communicator.defaultsAndOverrides().defaultProtocol;
            }

            EndpointFactory factory = null;

            lock (this)
            {
                for (int i = 0; i < _factories.Count; i++)
                {
                    EndpointFactory f = _factories[i];
                    if (f.protocol().Equals(protocol))
                    {
                        factory = f;
                    }
                }
            }

            if (factory != null)
            {
                EndpointI e = factory.create(v, oaEndpoint);
                if (v.Count > 0)
                {
                    throw new System.FormatException($"unrecognized argument `{v[0]}' in endpoint `{str}'");
                }
                return(e);

                // Code below left in place for debugging.

                /*
                 * EndpointI e = f.create(s.Substring(m.Index + m.Length), oaEndpoint);
                 * BasicStream bs = new BasicStream(_instance, true);
                 * e.streamWrite(bs);
                 * Buffer buf = bs.getBuffer();
                 * buf.b.position(0);
                 * short type = bs.readShort();
                 * EndpointI ue = new IceInternal.OpaqueEndpointI(type, bs);
                 * System.Console.Error.WriteLine("Normal: " + e);
                 * System.Console.Error.WriteLine("Opaque: " + ue);
                 * return e;
                 */
            }

            //
            // If the stringified endpoint is opaque, create an unknown endpoint,
            // then see whether the type matches one of the known endpoints.
            //
            if (protocol.Equals("opaque"))
            {
                EndpointI ue = new OpaqueEndpointI(v);
                if (v.Count > 0)
                {
                    throw new System.FormatException($"unrecognized argument `{v[0]}' in endpoint `{str}'");
                }
                factory = get(ue.type());
                if (factory != null)
                {
                    //
                    // Make a temporary stream, write the opaque endpoint data into the stream,
                    // and ask the factory to read the endpoint data from that stream to create
                    // the actual endpoint.
                    //
                    Ice.OutputStream os = new Ice.OutputStream(_communicator, Ice.Util.currentProtocolEncoding);
                    os.WriteShort(ue.type());
                    ue.streamWrite(os);
                    Ice.InputStream iss =
                        new Ice.InputStream(_communicator, Ice.Util.currentProtocolEncoding, os.GetBuffer(), true);
                    iss.pos(0);
                    iss.ReadShort(); // type
                    iss.StartEncapsulation();
                    EndpointI e = factory.read(iss);
                    iss.EndEncapsulation();
                    return(e);
                }
                return(ue); // Endpoint is opaque, but we don't have a factory for its type.
            }

            return(null);
        }