Search in sources :

Example 1 with AcsJSourceCreationErrorEx

use of alma.acsErrTypeAlarmSourceFactory.wrappers.AcsJSourceCreationErrorEx in project ACS by ACS-Community.

the class ACSAlarmSystemInterfaceFactory method createSource.

/**
	 * Create a new instance of an alarm system interface.
	 * @param sourceName the source name.
	 * @return the interface instance.
	 * @throws ASIException if the AlarmSystemInterface instance can not be created.
	 */
public static synchronized ACSAlarmSystemInterface createSource(String sourceName) throws ACSASFactoryNotInitedEx, SourceCreationErrorEx {
    if (useACSAlarmSystem == null) {
        Exception e = new IllegalStateException("Factory not initialised");
        throw new AcsJACSASFactoryNotInitedEx(e).toACSASFactoryNotInitedEx();
    }
    if (useACSAlarmSystem) {
        return new ACSAlarmSystemInterfaceProxy(sourceName, logger);
    } else {
        if (source != null) {
            return source;
        }
        try {
            Thread t = Thread.currentThread();
            ClassLoader loader = t.getContextClassLoader();
            Class cl = loader.loadClass("alma.acs.alarmsystem.binding.ACSLaserSource");
            Class[] classes = { String.class, Logger.class };
            Constructor constructor = cl.getConstructor(classes);
            // TODO: take ContainerServicesBase object received in the init method, 
            // and set it on ACSJMSTopicConnectionImpl.containerServices
            // Of course in after the ACS 7.0 release rush, this static field communication 
            // must be replaced with with real calls, or at least the absence of such an object must be detected early.
            source = (ACSAlarmSystemInterface) constructor.newInstance(sourceName, logger);
            return source;
        } catch (Throwable t) {
            System.out.println("ERROR: " + t.getMessage());
            t.printStackTrace();
            throw new AcsJSourceCreationErrorEx(t).toSourceCreationErrorEx();
        }
    }
}
Also used : AcsJACSASFactoryNotInitedEx(alma.acsErrTypeAlarmSourceFactory.wrappers.AcsJACSASFactoryNotInitedEx) Constructor(java.lang.reflect.Constructor) AcsJSourceCreationErrorEx(alma.acsErrTypeAlarmSourceFactory.wrappers.AcsJSourceCreationErrorEx)

Aggregations

AcsJACSASFactoryNotInitedEx (alma.acsErrTypeAlarmSourceFactory.wrappers.AcsJACSASFactoryNotInitedEx)1 AcsJSourceCreationErrorEx (alma.acsErrTypeAlarmSourceFactory.wrappers.AcsJSourceCreationErrorEx)1 Constructor (java.lang.reflect.Constructor)1