Search in sources :

Example 51 with UNKNOWN

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;
}
Also used : NameComponent(org.omg.CosNaming.NameComponent) FileNotFoundException(java.io.FileNotFoundException) BAD_PARAM(org.omg.CORBA.BAD_PARAM) NamingContext(org.omg.CosNaming.NamingContext) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) LineNumberReader(java.io.LineNumberReader) SystemException(org.omg.CORBA.SystemException) InvalidName(org.omg.CORBA.ORBPackage.InvalidName) FileReader(java.io.FileReader) UserException(org.omg.CORBA.UserException) UNKNOWN(org.omg.CORBA.UNKNOWN) File(java.io.File)

Aggregations

UNKNOWN (org.omg.CORBA.UNKNOWN)51 SystemException (org.omg.CORBA.SystemException)32 BAD_PARAM (org.omg.CORBA.BAD_PARAM)27 Coordinator (org.omg.CosTransactions.Coordinator)15 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)14 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)13 BadParametersException (com.cosylab.acs.maci.BadParametersException)13 CoreException (com.cosylab.acs.maci.CoreException)13 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)13 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)12 Unavailable (org.omg.CosTransactions.Unavailable)11 Any (org.omg.CORBA.Any)9 Object (org.omg.CORBA.Object)8 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)7 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)6 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)6 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)6 TRANSACTION_REQUIRED (org.omg.CORBA.TRANSACTION_REQUIRED)6 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)6