use of org.omg.CORBA.UNKNOWN in project narayana by jbosstm.
the class Services method getService.
public org.omg.CORBA.Object getService(String serviceName, Object[] params, int mechanism) throws org.omg.CORBA.ORBPackage.InvalidName, IOException, SystemException {
org.omg.CORBA.Object objRef = null;
switch(mechanism) {
case RESOLVE_INITIAL_REFERENCES:
{
try {
objRef = _orb.orb().resolve_initial_references(serviceName);
} catch (SystemException ex) {
throw ex;
} catch (InvalidName exp) {
throw exp;
} catch (Exception e) {
if (opLogger.logger.isTraceEnabled()) {
opLogger.logger.trace("Services.getService - resolve_initial_references on " + serviceName + " failed: " + e.toString());
}
throw new InvalidName();
}
}
break;
case NAME_SERVICE:
{
String kind = ((params == null) ? null : (String) params[0]);
try {
org.omg.CORBA.Object nsRef = _orb.orb().resolve_initial_references(Services.nameService);
NamingContext ncRef = NamingContextHelper.narrow(nsRef);
// bind the Object Reference in Naming
NameComponent nc = new NameComponent(serviceName, kind);
NameComponent[] path = { nc };
objRef = ncRef.resolve(path);
} catch (SystemException ex) {
throw ex;
} catch (UserException e) {
throw new org.omg.CORBA.ORBPackage.InvalidName();
}
}
break;
case CONFIGURATION_FILE:
{
String cosservicesRoot = opPropertyManager.getOrbPortabilityEnvironmentBean().getInitialReferencesRoot();
String configLocation = opPropertyManager.getOrbPortabilityEnvironmentBean().getInitialReferencesFile();
String configFile = cosservicesRoot + File.separatorChar + configLocation;
LineNumberReader input;
try {
input = new LineNumberReader(new FileReader(configFile));
} catch (FileNotFoundException e) {
if (opLogger.logger.isTraceEnabled()) {
opLogger.logger.trace("Services.getService could not open config file " + configFile);
}
throw new InvalidName();
}
String ior = null;
try {
boolean finished = false;
while ((ior == null) && !finished) {
String line = input.readLine();
if (line == null)
finished = true;
else {
int occur = line.indexOf(serviceName);
if (// should be first on line
occur == 0)
// +1 for space separator
ior = line.substring(serviceName.length() + 1);
}
}
input.close();
} catch (SystemException ex) {
input.close();
throw ex;
} catch (Exception e) {
opLogger.i18NLogger.warn_Services_unexpectedexception("Services.getService", e);
input.close();
throw new UNKNOWN();
}
if (ior == null) {
opLogger.i18NLogger.warn_Services_servicenotfound(serviceName, configFile);
throw new InvalidName();
} else {
try {
objRef = _orb.orb().string_to_object(ior);
} catch (Exception e) {
objRef = null;
}
}
}
break;
case FILE:
{
try {
String fileDir = opPropertyManager.getOrbPortabilityEnvironmentBean().getFileDir();
File f = null;
if (fileDir != null && fileDir.length() != 0)
f = new File(fileDir + File.separator + serviceName);
else
f = new File(serviceName);
FileInputStream ifile = new FileInputStream(f);
int size = (int) f.length();
byte[] b = new byte[size];
ifile.read(b);
ifile.close();
String objString = new String(b, StandardCharsets.UTF_8);
objRef = _orb.orb().string_to_object(objString);
objString = null;
} catch (SystemException ex) {
throw ex;
} catch (FileNotFoundException e) {
throw new InvalidName();
}
}
break;
case NAMED_CONNECT:
{
opLogger.i18NLogger.warn_Services_unsupportedoption("NAMED_CONNECT");
throw new BAD_PARAM();
}
}
return objRef;
}
Aggregations