use of org.omg.CosNaming.NameComponent in project wildfly by wildfly.
the class CNNameParser method insStringToStringifiedComps.
/**
* Converts an INS-syntax string name into a Vector in which
* each element of the vector contains a stringified form of
* a NameComponent.
*/
private static Vector insStringToStringifiedComps(String str) throws InvalidNameException {
int len = str.length();
Vector components = new Vector(10);
char[] id = new char[len];
char[] kind = new char[len];
int idCount, kindCount;
boolean idMode;
for (int i = 0; i < len; ) {
// reset for new component
idCount = kindCount = 0;
// always start off parsing id
idMode = true;
while (i < len) {
if (str.charAt(i) == compSeparator) {
break;
} else if (str.charAt(i) == escapeChar) {
if (i + 1 >= len) {
throw IIOPLogger.ROOT_LOGGER.unescapedCharacter(str);
} else if (isMeta(str.charAt(i + 1))) {
// skip escape and let meta through
++i;
if (idMode) {
id[idCount++] = str.charAt(i++);
} else {
kind[kindCount++] = str.charAt(i++);
}
} else {
throw IIOPLogger.ROOT_LOGGER.invalidEscapedCharacter(str);
}
} else if (idMode && str.charAt(i) == kindSeparator) {
// just look for the first kindSeparator
// skip kind separator
++i;
idMode = false;
} else {
if (idMode) {
id[idCount++] = str.charAt(i++);
} else {
kind[kindCount++] = str.charAt(i++);
}
}
}
components.addElement(stringifyComponent(new NameComponent(new String(id, 0, idCount), new String(kind, 0, kindCount))));
if (i < len) {
// skip separator
++i;
}
}
return components;
}
use of org.omg.CosNaming.NameComponent in project wildfly by wildfly.
the class ExceptionMapper method tryFed.
private static NamingException tryFed(NotFound e, CNCtx ctx, NameComponent[] inputName) throws NamingException {
NameComponent[] rest = ((NotFound) e).rest_of_name;
if (debug) {
}
// If one of those is not found, you get "aa" as 'rest'.
if (rest.length == 1 && inputName != null) {
// Check that we're not talking to 1.2/1.3 Sun tnameserv
NameComponent lastIn = inputName[inputName.length - 1];
if (rest[0].id.equals(lastIn.id) && rest[0].kind != null && rest[0].kind.equals(lastIn.kind)) {
// Might be legit
} else {
// Due to 1.2/1.3 bug that always returns single-item 'rest'
NamingException ne = new NameNotFoundException();
ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
ne.setRootCause(e);
throw ne;
}
}
// Fixed in 1.4; perform calculations based on correct (1.4) behavior
// Calculate the components of the name that has been resolved
NameComponent[] resolvedName = null;
int len = 0;
if (inputName != null && (inputName.length >= rest.length)) {
if (e.why == NotFoundReason.not_context) {
// First component of rest is found but not a context; keep it
// as part of resolved name
len = inputName.length - (rest.length - 1);
// Remove resolved component from rest
if (rest.length == 1) {
// No more remaining
rest = null;
} else {
NameComponent[] tmp = new NameComponent[rest.length - 1];
System.arraycopy(rest, 1, tmp, 0, tmp.length);
rest = tmp;
}
} else {
len = inputName.length - rest.length;
}
if (len > 0) {
resolvedName = new NameComponent[len];
System.arraycopy(inputName, 0, resolvedName, 0, len);
}
}
// Create CPE and set common fields
CannotProceedException cpe = new CannotProceedException();
cpe.setRootCause(e);
if (rest != null && rest.length > 0) {
cpe.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
}
cpe.setEnvironment(ctx._env);
// Lookup resolved name to get resolved object
final java.lang.Object resolvedObj = (resolvedName != null) ? ctx.callResolve(resolvedName) : ctx;
if (resolvedObj instanceof javax.naming.Context) {
// obj is a context and child is not found
// try getting its nns dynamically by constructing
// a Reference containing obj.
RefAddr addr = new RefAddr("nns") {
public java.lang.Object getContent() {
return resolvedObj;
}
private static final long serialVersionUID = 669984699392133792L;
};
Reference ref = new Reference("java.lang.Object", addr);
// Resolved name has trailing slash to indicate nns
CompositeName cname = new CompositeName();
// add trailing slash
cname.add("");
cpe.setResolvedObj(ref);
cpe.setAltName(cname);
cpe.setAltNameCtx((javax.naming.Context) resolvedObj);
return cpe;
} else {
// Not a context, use object factory to transform object.
Name cname = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(resolvedName);
java.lang.Object resolvedObj2;
try {
resolvedObj2 = NamingManager.getObjectInstance(resolvedObj, cname, ctx, ctx._env);
} catch (NamingException ge) {
throw ge;
} catch (Exception ge) {
NamingException ne = IIOPLogger.ROOT_LOGGER.errorGeneratingObjectViaFactory();
ne.setRootCause(ge);
throw ne;
}
// If a context, continue operation with context
if (resolvedObj2 instanceof javax.naming.Context) {
cpe.setResolvedObj(resolvedObj2);
} else {
// Add trailing slash
cname.add("");
cpe.setAltName(cname);
// Create nns reference
final java.lang.Object rf2 = resolvedObj2;
RefAddr addr = new RefAddr("nns") {
public java.lang.Object getContent() {
return rf2;
}
private static final long serialVersionUID = -785132553978269772L;
};
Reference ref = new Reference("java.lang.Object", addr);
cpe.setResolvedObj(ref);
cpe.setAltNameCtx(ctx);
}
return cpe;
}
}
use of org.omg.CosNaming.NameComponent in project wildfly by wildfly.
the class CorbaNamingContext method rebind_context.
public void rebind_context(NameComponent[] nc, NamingContext obj) throws NotFound, CannotProceed, InvalidName {
if (this.destroyed)
throw new CannotProceed();
if (nc == null || nc.length == 0)
throw new InvalidName();
if (obj == null)
throw new org.omg.CORBA.BAD_PARAM();
Name n = new Name(nc);
Name ctx = n.ctxName();
NameComponent nb = n.baseNameComponent();
if (ctx == null) {
// the name is bound, but it is bound to an object - the client should have been using rebind().
if (this.names.containsKey(n))
throw new NotFound(NotFoundReason.not_context, new NameComponent[] { nb });
// try to remove an existing context binding.
org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.contexts.remove(n);
if (ref != null) {
ref._release();
// remove the old context from the implementation cache.
String oid = this.getObjectOID(ref);
if (oid != null)
contextImpls.remove(oid);
}
this.contexts.put(n, obj);
IIOPLogger.ROOT_LOGGER.debugf("Bound context: %s", n.baseNameComponent().id);
} else {
// rebind in the correct context
NameComponent[] ncx = new NameComponent[] { nb };
org.omg.CORBA.Object context = this.resolve(ctx.components());
// try first to call the context implementation object directly.
String contextOID = this.getObjectOID(context);
CorbaNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
if (jbossContext != null)
jbossContext.rebind_context(ncx, obj);
else
NamingContextExtHelper.narrow(context).rebind_context(ncx, obj);
}
}
use of org.omg.CosNaming.NameComponent in project wildfly by wildfly.
the class CorbaNamingContext method bind.
//======================================= NamingContextOperation Methods ==================================//
public void bind(NameComponent[] nc, org.omg.CORBA.Object obj) throws NotFound, CannotProceed, InvalidName, AlreadyBound {
if (this.destroyed)
throw new CannotProceed();
if (nc == null || nc.length == 0)
throw new InvalidName();
if (obj == null)
throw new org.omg.CORBA.BAD_PARAM();
Name n = new Name(nc);
Name ctx = n.ctxName();
NameComponent nb = n.baseNameComponent();
if (ctx == null) {
if (this.names.containsKey(n)) {
// if the name is still in use, try to ping the object
org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.names.get(n);
if (isDead(ref)) {
rebind(n.components(), obj);
return;
}
throw new AlreadyBound();
} else if (this.contexts.containsKey(n)) {
// if the name is still in use, try to ping the object
org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.contexts.get(n);
if (isDead(ref))
unbind(n.components());
throw new AlreadyBound();
}
if ((this.names.put(n, obj)) != null)
throw new CannotProceed(_this(), n.components());
IIOPLogger.ROOT_LOGGER.debugf("Bound name: %s", n);
} else {
NameComponent[] ncx = new NameComponent[] { nb };
org.omg.CORBA.Object context = this.resolve(ctx.components());
// try first to call the context implementation object directly.
String contextOID = this.getObjectOID(context);
CorbaNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
if (jbossContext != null)
jbossContext.bind(ncx, obj);
else
NamingContextExtHelper.narrow(context).bind(ncx, obj);
}
}
use of org.omg.CosNaming.NameComponent in project wildfly by wildfly.
the class CorbaNamingContext method unbind.
public void unbind(NameComponent[] nc) throws NotFound, CannotProceed, InvalidName {
if (this.destroyed)
throw new CannotProceed();
if (nc == null || nc.length == 0)
throw new InvalidName();
Name n = new Name(nc);
Name ctx = n.ctxName();
NameComponent nb = n.baseNameComponent();
if (ctx == null) {
if (this.names.containsKey(n)) {
org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.names.remove(n);
ref._release();
IIOPLogger.ROOT_LOGGER.debugf("Unbound: %s", n);
} else if (this.contexts.containsKey(n)) {
org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.contexts.remove(n);
ref._release();
// remove the context from the implementation cache.
String oid = this.getObjectOID(ref);
if (oid != null)
contextImpls.remove(oid);
IIOPLogger.ROOT_LOGGER.debugf("Unbound: %s", n);
} else {
IIOPLogger.ROOT_LOGGER.failedToUnbindObject(n);
throw new NotFound(NotFoundReason.not_context, n.components());
}
} else {
NameComponent[] ncx = new NameComponent[] { nb };
org.omg.CORBA.Object context = this.resolve(ctx.components());
// try first to call the context implementation object directly.
String contextOID = this.getObjectOID(context);
CorbaNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
if (jbossContext != null)
jbossContext.unbind(ncx);
else
NamingContextExtHelper.narrow(context).unbind(ncx);
}
}
Aggregations