summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2002-07-18 03:41:46 +0000
committerMark Spruiell <mes@zeroc.com>2002-07-18 03:41:46 +0000
commit67301daff371397dafcd3668008c26fbc8f8656f (patch)
treee0bb6db520a16ce6f944bc58014ef6edd6517c66 /java
parentadded missing file (diff)
downloadice-67301daff371397dafcd3668008c26fbc8f8656f.tar.bz2
ice-67301daff371397dafcd3668008c26fbc8f8656f.tar.xz
ice-67301daff371397dafcd3668008c26fbc8f8656f.zip
align with C++ for facet path
Diffstat (limited to 'java')
-rw-r--r--java/src/IceInternal/ReferenceFactory.java142
-rw-r--r--java/src/IceInternal/StringUtil.java78
2 files changed, 176 insertions, 44 deletions
diff --git a/java/src/IceInternal/ReferenceFactory.java b/java/src/IceInternal/ReferenceFactory.java
index f5575ec1f4a..56fd4f7a771 100644
--- a/java/src/IceInternal/ReferenceFactory.java
+++ b/java/src/IceInternal/ReferenceFactory.java
@@ -68,49 +68,78 @@ public final class ReferenceFactory
}
public Reference
- create(String str)
+ create(String s)
{
- String s = str.trim();
- if(s.length() == 0)
+ final String delim = " \t\n\r";
+
+ int beg;
+ int end = 0;
+
+ beg = StringUtil.findFirstNotOf(s, delim, end);
+ if(beg == -1)
{
throw new Ice.ProxyParseException();
}
- int colon = s.indexOf(':');
- if(colon == -1)
- colon = s.indexOf('@');
-
- String init;
- if(colon == -1)
+ end = StringUtil.findFirstOf(s, delim + ":@", beg);
+ if(end == -1)
{
- init = s;
+ end = s.length();
}
- else
+
+ if(beg == end)
{
- init = s.substring(0, colon);
+ throw new Ice.ProxyParseException();
}
- String[] arr = init.split("[ \t\n\r]+");
- Ice.Identity ident = Ice.Util.stringToIdentity(arr[0]);
- String[] facet = new String[0];
+ Ice.Identity ident = Ice.Util.stringToIdentity(s.substring(beg, end));
+ java.util.ArrayList facet = new java.util.ArrayList();
int mode = Reference.ModeTwoway;
boolean secure = false;
boolean compress = false;
String adapter = "";
- int i = 1;
- while(i < arr.length)
+ while(true)
{
- String option = arr[i++];
+ beg = StringUtil.findFirstNotOf(s, delim, end);
+ if(beg == -1)
+ {
+ break;
+ }
+
+ if(s.charAt(beg) == ':' || s.charAt(beg) == '@')
+ {
+ break;
+ }
+
+ end = StringUtil.findFirstOf(s, delim + ":@", beg);
+ if(end == -1)
+ {
+ end = s.length();
+ }
+
+ if(beg == end)
+ {
+ break;
+ }
+
+ String option = s.substring(beg, end);
if(option.length() != 2 || option.charAt(0) != '-')
{
throw new Ice.ProxyParseException();
}
String argument = null;
- if(i < arr.length && arr[i].charAt(0) != '-')
+ int argumentBeg = StringUtil.findFirstNotOf(s, delim, end);
+ if(argumentBeg != -1 && s.charAt(argumentBeg) != '-')
{
- argument = arr[i++];
+ beg = argumentBeg;
+ end = StringUtil.findFirstOf(s, delim + ":@", beg);
+ if(end == -1)
+ {
+ end = s.length();
+ argument = s.substring(beg, end);
+ }
}
//
@@ -126,8 +155,24 @@ public final class ReferenceFactory
throw new Ice.EndpointParseException();
}
- // TODO: For Mark.
- //facet = argument;
+ //
+ // TODO: Escape for whitespace and slashes.
+ //
+ int argBeg = 0;
+ while(argBeg < argument.length())
+ {
+ int argEnd = argument.indexOf('/', argBeg);
+ if(argEnd == -1)
+ {
+ facet.add(argument.substring(argBeg));
+ }
+ else
+ {
+ facet.add(argument.substring(argBeg, argEnd));
+ ++argEnd;
+ }
+ argBeg = argEnd;
+ }
break;
}
@@ -137,7 +182,6 @@ public final class ReferenceFactory
{
throw new Ice.EndpointParseException();
}
-
mode = Reference.ModeTwoway;
break;
}
@@ -148,7 +192,6 @@ public final class ReferenceFactory
{
throw new Ice.EndpointParseException();
}
-
mode = Reference.ModeOneway;
break;
}
@@ -159,7 +202,6 @@ public final class ReferenceFactory
{
throw new Ice.EndpointParseException();
}
-
mode = Reference.ModeBatchOneway;
break;
}
@@ -170,7 +212,6 @@ public final class ReferenceFactory
{
throw new Ice.EndpointParseException();
}
-
mode = Reference.ModeDatagram;
break;
}
@@ -181,7 +222,6 @@ public final class ReferenceFactory
{
throw new Ice.EndpointParseException();
}
-
mode = Reference.ModeBatchDatagram;
break;
}
@@ -192,7 +232,6 @@ public final class ReferenceFactory
{
throw new Ice.EndpointParseException();
}
-
secure = true;
break;
}
@@ -203,7 +242,6 @@ public final class ReferenceFactory
{
throw new Ice.EndpointParseException();
}
-
compress = true;
break;
}
@@ -216,21 +254,20 @@ public final class ReferenceFactory
}
java.util.ArrayList endpoints = new java.util.ArrayList();
-
- if(colon != -1)
- {
- if(s.charAt(colon) == ':')
+ if(beg != -1)
+ {
+ if(s.charAt(beg) == ':')
{
- final int len = s.length();
- int end = colon;
- while(end < len && s.charAt(end) == ':')
- {
- int beg = end + 1;
+ end = beg;
+
+ while(end < s.length() && s.charAt(end) == ':')
+ {
+ beg = end + 1;
end = s.indexOf(':', beg);
if(end == -1)
{
- end = len;
+ end = s.length();
}
String es = s.substring(beg, end);
@@ -238,20 +275,37 @@ public final class ReferenceFactory
endpoints.add(endp);
}
}
- else if(s.charAt(colon) == '@')
+ else if(s.charAt(beg) == '@')
{
- init = s.substring(colon + 1, s.length()).trim();
- arr = init.split("[ \t\n\r]+");
- adapter = arr[0];
+ beg = StringUtil.findFirstNotOf(s, delim, beg + 1);
+ if(beg == -1)
+ {
+ beg = end + 1;
+ }
+
+ end = StringUtil.findFirstOf(s, delim, beg);
+ if(end == -1)
+ {
+ end = s.length();
+ }
+
+ adapter = s.substring(beg, end);
+ if(adapter.length() == 0)
+ {
+ throw new Ice.ProxyParseException();
+ }
}
}
Endpoint[] endp = new Endpoint[endpoints.size()];
endpoints.toArray(endp);
+ String[] fac = new String[facet.size()];
+ facet.toArray(fac);
+
RouterInfo routerInfo = _instance.routerManager().get(getDefaultRouter());
LocatorInfo locatorInfo = _instance.locatorManager().get(getDefaultLocator());
- return create(ident, facet, mode, secure, compress, adapter, endp, routerInfo, locatorInfo, null);
+ return create(ident, fac, mode, secure, compress, adapter, endp, routerInfo, locatorInfo, null);
}
public Reference
diff --git a/java/src/IceInternal/StringUtil.java b/java/src/IceInternal/StringUtil.java
new file mode 100644
index 00000000000..8a64798de37
--- /dev/null
+++ b/java/src/IceInternal/StringUtil.java
@@ -0,0 +1,78 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// Mutable Realms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+package IceInternal;
+
+public final class StringUtil
+{
+ //
+ // Return the index of the first character in str to
+ // appear in match, starting from 0. Returns -1 if none is
+ // found.
+ //
+ public static int
+ findFirstOf(String str, String match)
+ {
+ return findFirstOf(str, match, 0);
+ }
+
+ //
+ // Return the index of the first character in str to
+ // appear in match, starting from start. Returns -1 if none is
+ // found.
+ //
+ public static int
+ findFirstOf(String str, String match, int start)
+ {
+ final int len = str.length();
+ for(int i = start; i < len; i++)
+ {
+ char ch = str.charAt(i);
+ if(match.indexOf(ch) != -1)
+ {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ //
+ // Return the index of the first character in str which does
+ // not appear in match, starting from 0. Returns -1 if none is
+ // found.
+ //
+ public static int
+ findFirstNotOf(String str, String match)
+ {
+ return findFirstNotOf(str, match, 0);
+ }
+
+ //
+ // Return the index of the first character in str which does
+ // not appear in match, starting from start. Returns -1 if none is
+ // found.
+ //
+ public static int
+ findFirstNotOf(String str, String match, int start)
+ {
+ final int len = str.length();
+ for(int i = start; i < len; i++)
+ {
+ char ch = str.charAt(i);
+ if(match.indexOf(ch) == -1)
+ {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+}