--- projects/cms/source/util/uk/org/iscream/cms/util/ReferenceManager.java 2000/12/11 16:38:09 1.5 +++ projects/cms/source/util/uk/org/iscream/cms/util/ReferenceManager.java 2000/12/12 17:13:22 1.6 @@ -19,7 +19,7 @@ import uk.ac.ukc.iscream.core.*; * a component. * * @author $Author: ajm $ - * @version $Id: ReferenceManager.java,v 1.5 2000/12/11 16:38:09 ajm Exp $ + * @version $Id: ReferenceManager.java,v 1.6 2000/12/12 17:13:22 ajm Exp $ */ public class ReferenceManager { @@ -28,23 +28,16 @@ public class ReferenceManager { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.5 $"; + public final String REVISION = "$Revision: 1.6 $"; //---STATIC METHODS--- /** - * This creates the single instance of the ReferenceManager by - * calling the private constructor. If it is called twice, - * it detects an instance already exits and throws an exception. - * - * @param args the args to be passed to the ORB - * @param name the name of the component that will use this singleton - * - * @return a reference to the ReferenceManager - * - * @throws AlreadyInitialisedException if this method has already been called + * TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! + * @deprecated should know longer use this method to construct a refman */ public static ReferenceManager init(String[] args, String name) throws AlreadyInitialisedException { + System.out.println("LEGACY CALL - SORT THIS OUT! name=" + name); if (_instance != null) { throw new AlreadyInitialisedException("init has already been called"); } @@ -56,13 +49,14 @@ public class ReferenceManager { * This returns a reference to the single instance of the * ReferenceManager. * - * @return a reference to the ReferenceManager + * This creates the single instance of the ReferenceManager + * if it does not exist by calling the private constructor. * - * @throws NotInitialisedException if the reference manager has not been initialised + * @return a reference to the ReferenceManager */ - public static ReferenceManager getInstance() throws NotInitialisedException { + public static ReferenceManager getInstance() { if (_instance == null) { - throw new NotInitialisedException("attempt to obtain reference when not initialised"); + _instance = new ReferenceManager(); } return _instance; } @@ -72,11 +66,17 @@ public class ReferenceManager { /** * This is a private constructor * This ensures that the system performs according to a Singleton design pattern - * - * @param args the args to be passed to the ORB - * @param name the name of the component that will use this singleton */ + private ReferenceManager() { + _orb = ORB.init(new String[] {}, null); + } + + /** + * TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! + * @deprecated should know longer use this method to construct a refman + */ private ReferenceManager(String[] args, String name) { + System.out.println("LEGACY CALL - SORT THIS OUT! name=" + name); _orb = ORB.init(args, null); _name = name; } @@ -97,13 +97,13 @@ public class ReferenceManager { try { objRef = getNS().resolve(getNS().to_name(name)); } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) { - throw new Error("\nCRITICAL:Naming Service Cannot Proceed - when resolving reference to " + name + "!\n" + + dieWithError("\nCRITICAL:Naming Service Cannot Proceed - when resolving reference to " + name + "!\n" + " Please check with your CORBA naming service provider."); } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) { - throw new Error("\nCRITICAL:Invalid Name - when resolving reference to " + name + "!\n" + + dieWithError("\nCRITICAL:Invalid Name - when resolving reference to " + name + "!\n" + " Please check with your CORBA naming service provider."); } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) { - throw new Error("\nCRITICAL:Not Found - when resolving reference to " + name + "!\n" + + dieWithError("\nCRITICAL:Not Found - when resolving reference to " + name + "!\n" + " Please check that this component is running."); } return objRef; @@ -112,7 +112,7 @@ public class ReferenceManager { /** * Binds a given servant with the given name * to the naming service. - * This will throw a Error if there is an error + * Calls the dieWithError()! * * @param objRef a reverence to the servant object * @param name the name to bind to the naming service with @@ -121,22 +121,22 @@ public class ReferenceManager { try { getNS().bind(getNS().to_name(name), getRootPOA().servant_to_reference(objRef)); } catch (org.omg.PortableServer.POAPackage.WrongPolicy e) { - throw new Error("\nCRITICAL:Wrong POA Policy - when binding " + name + "!\n" + + dieWithError("\nCRITICAL:Wrong POA Policy - when binding " + name + "!\n" + " This indicates an error with your ORB."); } catch (org.omg.PortableServer.POAPackage.ServantNotActive e) { - throw new Error("\nCRITICAL:ServantNotActive - when binding " + name + "!\n" + + dieWithError("\nCRITICAL:ServantNotActive - when binding " + name + "!\n" + " This indicates an error with your ORB."); } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) { - throw new Error("\nCRITICAL:Invalid Name - when binding " + name + "!\n" + + dieWithError("\nCRITICAL:Invalid Name - when binding " + name + "!\n" + " Please check with your CORBA naming service provider."); } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) { - throw new Error("\nCRITICAL:Naming Service Cannot Proceed - when binding " + name + "!\n" + + dieWithError("\nCRITICAL:Naming Service Cannot Proceed - when binding " + name + "!\n" + " Please check with your CORBA naming service provider."); } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) { - throw new Error("\nCRITICAL:Naming Service Not Found - when binding " + name + "!\n" + + dieWithError("\nCRITICAL:Naming Service Not Found - when binding " + name + "!\n" + " Please check with your CORBA naming service provider."); } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound e) { - throw new Error("\nCRITICAL:Already Bound - when binding " + name + "!\n" + + dieWithError("\nCRITICAL:Already Bound - when binding " + name + "!\n" + " Another component with this name is already running."); } } @@ -149,7 +149,7 @@ public class ReferenceManager { try { getRootPOA().the_POAManager().activate(); } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive e) { - throw new Error("\nCRITICAL:POA Set Inactive - when trying to activate POA!\n" + + dieWithError("\nCRITICAL:POA Set Inactive - when trying to activate POA!\n" + " This indicates an error with your ORB."); } } @@ -158,14 +158,41 @@ public class ReferenceManager { * Overrides the {@link java.lang.Object#toString() Object.toString()} * method to provide clean logging (every class should have this). * + * This uses the uk.ac.ukc.iscream.util.NameFormat class + * to format the toString() + * * @return the name of this class and its CVS revision */ public String toString() { - return getName() + "{" + getClass().getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; + return FormatName.getName( + null, + this.getClass().getName(), + REVISION); } //---PRIVATE METHODS--- + /** + * If there are any CORBA errors this method is called with the + * error message. + * + * Currently this prints the error, on the local err stream. Will + * print to the logger if one is available. + * + * ANY CALLS TO THIS METHOD CAUSE + * THE SYSTEM TO EXIT WITH A NON + * ZERO CODE! + * + * @param message the error message to die with + */ + private void dieWithError(String message) { + System.err.println(message); + if (_logger != null) { + _logger.write(toString(), Logger.FATAL, message); + } + System.exit(1); + } + //---ACCESSOR/MUTATOR METHODS--- /** @@ -189,7 +216,7 @@ public class ReferenceManager { try { objRef = getORB().resolve_initial_references("RootPOA"); } catch (org.omg.CORBA.ORBPackage.InvalidName e) { - throw new Error("\nCRITICAL:Unable to resolve reference to the RootPOA!\n" + + dieWithError("\nCRITICAL:Unable to resolve reference to the RootPOA!\n" + " This indicates an error with your ORB."); } _rootPOA = POAHelper.narrow(objRef); @@ -209,14 +236,14 @@ public class ReferenceManager { try { objRef = getORB().resolve_initial_references("NameService"); } catch (org.omg.CORBA.ORBPackage.InvalidName e) { - throw new Error("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" + + dieWithError("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" + " Please check with your CORBA naming service provider."); } _ns = NamingContextExtHelper.narrow(objRef); } // check we managed to talk to the naming service if (_ns == null) { - throw new Error("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" + + dieWithError("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" + " Please check with your CORBA naming service provider."); } return _ns; @@ -234,7 +261,7 @@ public class ReferenceManager { } // check we managed to talk to the configuration manager if (_cm == null) { - throw new Error("\nCRITICAL:Unable to resolve reference to the Configuration Manager!\n" + + dieWithError("\nCRITICAL:Unable to resolve reference to the Configuration Manager!\n" + " Please check with your CORBA naming service provider."); } return _cm; @@ -255,19 +282,23 @@ public class ReferenceManager { /** * Sets the reference to the name - * + * TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! + * @deprecated not stored in the refman any more - see Template.class * @param the new name */ public void setName(String name) { + System.out.println("LEGACY CALL - SORT THIS OUT! name=" + name); _name = name; } /** * Returns a reference to the name - * + * TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! + * @deprecated not stored in the refman any more - see Template.class * @return the reference this class holds */ public String getName() { + System.out.println("LEGACY CALL - SORT THIS OUT! name=" + _name); return _name; } @@ -300,6 +331,8 @@ public class ReferenceManager { /** * The name + * TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! + * @deprecated not stored in the refman any more - see Template.class */ private String _name;