1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
13 using System
.Collections
;
14 using System
.Diagnostics
;
15 using System
.Text
.RegularExpressions
;
17 public sealed class EndpointFactoryManager
19 internal EndpointFactoryManager(Instance instance
)
22 _factories
= new ArrayList();
25 public void add(EndpointFactory factory
)
29 for(int i
= 0; i
< _factories
.Count
; i
++)
31 EndpointFactory f
= (EndpointFactory
)_factories
[i
];
32 if(f
.type() == factory
.type())
37 _factories
.Add(factory
);
41 public EndpointFactory
get(short type
)
45 for(int i
= 0; i
< _factories
.Count
; i
++)
47 EndpointFactory f
= (EndpointFactory
)_factories
[i
];
57 public EndpointI
create(string str
, bool oaEndpoint
)
61 string s
= str
.Trim();
64 Ice
.EndpointParseException e
= new Ice
.EndpointParseException();
65 e
.str
= "value has no non-whitespace characters";
69 Regex p
= new Regex("([ \t\n\r]+)|$");
71 Debug
.Assert(m
.Success
);
73 string protocol
= s
.Substring(0, m
.Index
);
75 if(protocol
.Equals("default"))
77 protocol
= instance_
.defaultsAndOverrides().defaultProtocol
;
80 for(int i
= 0; i
< _factories
.Count
; i
++)
82 EndpointFactory f
= (EndpointFactory
)_factories
[i
];
83 if(f
.protocol().Equals(protocol
))
85 return f
.create(s
.Substring(m
.Index
+ m
.Length
), oaEndpoint
);
87 // Code below left in place for debugging.
90 EndpointI e = f.create(s.Substring(m.Index + m.Length), oaEndpoint);
91 BasicStream bs = new BasicStream(instance_, true);
93 Buffer buf = bs.getBuffer();
95 short type = bs.readShort();
96 EndpointI ue = new IceInternal.OpaqueEndpointI(type, bs);
97 System.Console.Error.WriteLine("Normal: " + e);
98 System.Console.Error.WriteLine("Opaque: " + ue);
105 // If the stringified endpoint is opaque, create an unknown endpoint,
106 // then see whether the type matches one of the known endpoints.
108 if(protocol
.Equals("opaque"))
110 EndpointI ue
= new OpaqueEndpointI(s
.Substring(m
.Index
+ m
.Length
));
111 for(int i
= 0; i
< _factories
.Count
; i
++)
113 EndpointFactory f
= (EndpointFactory
)_factories
[i
];
114 if(f
.type() == ue
.type())
117 // Make a temporary stream, write the opaque endpoint data into the stream,
118 // and ask the factory to read the endpoint data from that stream to create
119 // the actual endpoint.
121 BasicStream bs
= new BasicStream(instance_
, true);
123 Buffer buf
= bs
.getBuffer();
125 bs
.readShort(); // type
129 return ue
; // Endpoint is opaque, but we don't have a factory for its type.
135 public EndpointI
read(BasicStream s
)
139 short type
= s
.readShort();
141 for(int i
= 0; i
< _factories
.Count
; i
++)
143 EndpointFactory f
= (EndpointFactory
)_factories
[i
];
150 return new OpaqueEndpointI(type
, s
);
154 internal void destroy()
156 for(int i
= 0; i
< _factories
.Count
; i
++)
158 EndpointFactory f
= (EndpointFactory
)_factories
[i
];
164 private readonly Instance instance_
;
165 private readonly ArrayList _factories
;