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 // **********************************************************************
12 public final class EndpointFactoryManager
14 EndpointFactoryManager(Instance instance
)
19 public synchronized void
20 add(EndpointFactory factory
)
22 for(int i
= 0; i
< _factories
.size(); i
++)
24 EndpointFactory f
= _factories
.get(i
);
25 if(f
.type() == factory
.type())
30 _factories
.add(factory
);
33 public synchronized EndpointFactory
36 for(int i
= 0; i
< _factories
.size(); i
++)
38 EndpointFactory f
= _factories
.get(i
);
47 public synchronized EndpointI
48 create(String str
, boolean oaEndpoint
)
50 String s
= str
.trim();
53 Ice
.EndpointParseException e
= new Ice
.EndpointParseException();
54 e
.str
= "value has no non-whitespace characters";
58 java
.util
.regex
.Pattern p
= java
.util
.regex
.Pattern
.compile("([ \t\n\r]+)|$");
59 java
.util
.regex
.Matcher m
= p
.matcher(s
);
63 String protocol
= s
.substring(0, m
.start());
65 if(protocol
.equals("default"))
67 protocol
= _instance
.defaultsAndOverrides().defaultProtocol
;
70 for(int i
= 0; i
< _factories
.size(); i
++)
72 EndpointFactory f
= _factories
.get(i
);
73 if(f
.protocol().equals(protocol
))
75 return f
.create(s
.substring(m
.end()), oaEndpoint
);
77 // Code below left in place for debugging.
80 EndpointI e = f.create(s.substring(m.end()), oaEndpoint);
81 BasicStream bs = new BasicStream(_instance, true, false);
83 java.nio.ByteBuffer buf = bs.getBuffer();
85 short type = bs.readShort();
86 EndpointI ue = new IceInternal.OpaqueEndpointI(type, bs);
87 System.err.println("Normal: " + e);
88 System.err.println("Opaque: " + ue);
95 // If the stringified endpoint is opaque, create an unknown endpoint,
96 // then see whether the type matches one of the known endpoints.
98 if(protocol
.equals("opaque"))
100 EndpointI ue
= new OpaqueEndpointI(s
.substring(m
.end()));
101 for(int i
= 0; i
< _factories
.size(); i
++)
103 EndpointFactory f
= _factories
.get(i
);
104 if(f
.type() == ue
.type())
107 // Make a temporary stream, write the opaque endpoint data into the stream,
108 // and ask the factory to read the endpoint data from that stream to create
109 // the actual endpoint.
111 BasicStream bs
= new BasicStream(_instance
, true, false);
113 Buffer buf
= bs
.getBuffer();
115 bs
.readShort(); // type
119 return ue
; // Endpoint is opaque, but we don't have a factory for its type.
125 public synchronized EndpointI
128 short type
= s
.readShort();
130 for(int i
= 0; i
< _factories
.size(); i
++)
132 EndpointFactory f
= _factories
.get(i
);
138 return new OpaqueEndpointI(type
, s
);
144 for(int i
= 0; i
< _factories
.size(); i
++)
146 EndpointFactory f
= _factories
.get(i
);
152 private Instance _instance
;
153 private java
.util
.List
<EndpointFactory
> _factories
= new java
.util
.ArrayList
<EndpointFactory
>();