ENOEHT's Java Source Code Series (2) - Integrated Factory

zhaozj2021-02-16  52

Package org.kyle.net.svr.sample;

Public Class IntegrationFactory

{

Public integrationFactory ()

{

}

Public Static IListener Createlistener (Genprofile Gencfg)

{

Ilistener ilistener = null;

Try {

/ / Create a corresponding instance according to the class name set in the configuration file

IListener = (ilistener) instantiateit (Gencfg.getListenerImpl ());

}

Catch (Exception E) {

Debug.info ("Listener Class Not Found!");

// If the specified class does not exist, create an instance using the default class, and because the interface is referenced in the program, it provides a reference to the default class. It is required to compile mainclass when compiling. No need to compile separately. Default class

IListener = new SampleListenerImpl ();

}

Return IListener;

}

/ / Get the instance of the class according to the name of the class

Public Static Object Instantiateit (String Clsname)

Throws ClassNotFoundException,

ClassCastException,

InstantiationException,

ILLEGALACCESSEXCEPTION

{

Class CLS = Class.Forname (clsname);

Return CLS.NEWINSTANCE ();

}

}

Add: listener = org.kyle.net.svr.sample.sampleListenerImpl

转载请注明原文地址:https://www.9cbs.com/read-21324.html

New Post(0)