use of org.omg.CosNaming.NamingContext in project ACS by ACS-Community.
the class AlarmServiceUtils method getNamingContext.
/**
* Get the {@link NamingContext}
*
* @return The {@link NamingContext}
*/
private NamingContext getNamingContext() throws InvalidName {
org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService");
NamingContext context = NamingContextExtHelper.narrow(obj);
if (context == null) {
throw new NullPointerException("Got a null NamingContext");
}
return context;
}
use of org.omg.CosNaming.NamingContext in project ACS by ACS-Community.
the class ClientLogManager method getLogServiceFromNameSarvice.
/**
* Get the log service from the name server. It is used by ACS services that do
* not log into the manager and therefore can't use {@link #getLogService(Manager, int)}.
*
* @param orb The not <code>null</code> ORB
* @return The log service
* @throws InvalidName
*/
protected AcsLogServiceOperations getLogServiceFromNameSarvice(ORB orb) throws InvalidName {
if (orb == null) {
throw new IllegalArgumentException("The ORB can't be null!");
}
org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService");
NamingContext context = NamingContextExtHelper.narrow(obj);
if (context == null) {
throw new NullPointerException("Got a null NamingContext");
}
try {
// try naming service first
NameComponent[] nameComponent = new NameComponent[1];
nameComponent[0] = new NameComponent("Log", "");
org.omg.CORBA.Object logObj = context.resolve(nameComponent);
return AcsLogServiceHelper.narrow(logObj);
} catch (Throwable th) {
System.out.println("Failed to obtain alarm service reference from naming service, trying corbaloc...");
}
String corbaloc = "corbaloc::" + ACSPorts.getIP() + ":" + ACSPorts.getLogPort() + "/Log";
org.omg.CORBA.Object logObj = orb.string_to_object(corbaloc);
return AcsLogServiceHelper.narrow(logObj);
}
use of org.omg.CosNaming.NamingContext in project wildfly by wildfly.
the class EjbIIOPService method rebind.
/**
* (Re)binds an object to a name in a given CORBA naming context, creating
* any non-existent intermediate contexts along the way.
* <p/>
* This method is synchronized on the class object, if multiple services attempt to bind the
* same context name at once it will fail
*
* @param ctx a reference to the COSNaming service.
* @param strName the name under which the CORBA object is to be bound.
* @param obj the CORBA object to be bound.
* @throws Exception if an error occurs while binding the object.
*/
public static synchronized void rebind(final NamingContextExt ctx, final String strName, final org.omg.CORBA.Object obj) throws Exception {
final NameComponent[] name = ctx.to_name(strName);
NamingContext intermediateCtx = ctx;
for (int i = 0; i < name.length - 1; i++) {
final NameComponent[] relativeName = new NameComponent[] { name[i] };
try {
intermediateCtx = NamingContextHelper.narrow(intermediateCtx.resolve(relativeName));
} catch (NotFound e) {
intermediateCtx = intermediateCtx.bind_new_context(relativeName);
}
}
intermediateCtx.rebind(new NameComponent[] { name[name.length - 1] }, obj);
}
use of org.omg.CosNaming.NamingContext in project wildfly by wildfly.
the class CNCtx method callBindOrRebind.
/**
* Performs bind or rebind in the context depending on whether the
* flag rebind is set. The only objects allowed to be bound are of
* types org.omg.CORBA.Object, org.omg.CosNaming.NamingContext.
* You can use a state factory to turn other objects (such as
* Remote) into these acceptable forms.
* <p/>
* Uses the COS Naming apis bind/rebind or
* bind_context/rebind_context.
*
* @param pth NameComponent[] object
* @param obj Object to be bound.
* @param rebind perform rebind ? if true performs a rebind.
* @throws NotFound No objects under the name.
* @throws org.omg.CosNaming.NamingContextPackage.CannotProceed Unable to obtain a continuation context
* @throws org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is already bound to this name.
*/
private void callBindOrRebind(NameComponent[] pth, Name name, java.lang.Object obj, boolean rebind) throws NamingException {
if (_nc == null)
throw IIOPLogger.ROOT_LOGGER.notANamingContext(name.toString());
try {
// Call state factories to convert
obj = NamingManager.getStateToBind(obj, name, this, _env);
if (obj instanceof CNCtx) {
// Use naming context object reference
obj = ((CNCtx) obj)._nc;
}
if (obj instanceof org.omg.CosNaming.NamingContext) {
NamingContext nobj = NamingContextHelper.narrow((org.omg.CORBA.Object) obj);
if (rebind)
_nc.rebind_context(pth, nobj);
else
_nc.bind_context(pth, nobj);
} else if (obj instanceof org.omg.CORBA.Object) {
if (rebind)
_nc.rebind(pth, (org.omg.CORBA.Object) obj);
else
_nc.bind(pth, (org.omg.CORBA.Object) obj);
} else
throw IIOPLogger.ROOT_LOGGER.notACorbaObject();
} catch (BAD_PARAM e) {
// probably narrow() failed?
NamingException ne = new NotContextException(name.toString());
ne.setRootCause(e);
throw ne;
} catch (Exception e) {
throw org.wildfly.iiop.openjdk.naming.jndi.ExceptionMapper.mapException(e, this, pth);
}
}
use of org.omg.CosNaming.NamingContext in project wildfly by wildfly.
the class CNCtx method destroySubcontext.
/**
* Uses the callDestroy function to destroy the context. Destroys
* the current context if name is empty.
*
* @param name JNDI Name
* @throws javax.naming.OperationNotSupportedException when list is invoked
* with a non-null argument
*/
public void destroySubcontext(Name name) throws NamingException {
if (_nc == null)
throw IIOPLogger.ROOT_LOGGER.notANamingContext(name.toString());
NamingContext the_nc = _nc;
NameComponent[] path = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.nameToCosName(name);
if (name.size() > 0) {
try {
javax.naming.Context ctx = (javax.naming.Context) callResolve(path);
CNCtx cnc = (CNCtx) ctx;
the_nc = cnc._nc;
//remove the reference to the context
cnc.close();
} catch (ClassCastException e) {
throw new NotContextException(name.toString());
} catch (CannotProceedException e) {
javax.naming.Context cctx = getContinuationContext(e);
cctx.destroySubcontext(e.getRemainingName());
return;
} catch (NameNotFoundException e) {
if (e.getRootCause() instanceof NotFound && leafNotFound((NotFound) e.getRootCause(), path[path.length - 1])) {
// leaf missing OK
return;
}
throw e;
} catch (NamingException e) {
throw e;
}
}
callDestroy(the_nc);
callUnbind(path);
}
Aggregations