ALMA Computing Group

ErrorSystemImpl.java

Go to the documentation of this file.
00001 package alma.demo.ErrorSystemComp; 00002 00003 import java.lang.NullPointerException; 00004 import alma.acs.component.ComponentImplBase; 00005 import alma.demo.ErrorSystemOperations; 00006 import alma.ErrorSystemExample.ErrorSystemExampleEx; 00007 import alma.ErrorSystemExample.NothingCanBeScheduledErrorEx; 00008 import alma.ErrorSystemExample.PipelineProcessingRequestErrorEx; 00009 import alma.ErrorSystemExample.wrappers.AcsJErrorSystemExampleEx; 00010 import alma.ErrorSystemExample.wrappers.AcsJNothingCanBeScheduledErrorEx; 00011 import alma.ErrorSystemExample.wrappers.AcsJPipelineProcessingRequestErrorEx; 00012 00013 00014 public class ErrorSystemImpl 00015 extends ComponentImplBase 00016 implements ErrorSystemOperations { 00017 00018 00019 public ErrorSystemImpl() { 00020 } 00021 00023 // IDL Methods 00025 00026 public void tryToScheduleSomething() throws NothingCanBeScheduledErrorEx { 00027 00028 String schedblock = null; 00029 try { 00030 if(schedblock != null) { 00031 //Schedule it! 00032 } else { 00033 throw new NullPointerException("Can't scheduled a null SB!"); 00034 } 00035 } catch (NullPointerException e) { 00036 //Create the wrapper class for the NothingCanBeScheduledErrorEx using the 00037 //exception that was caught. 00038 AcsJNothingCanBeScheduledErrorEx e2 = new AcsJNothingCanBeScheduledErrorEx(e); 00039 // use the method in the generated wrapper class to prepare our regular error 00040 // for CORBA transport. Basically allowing all the information of what it is and 00041 // where it came from and why it happened to be retained after its been sent 00042 // over CORBA 00043 throw e2.toNothingCanBeScheduledErrorEx(); 00044 } 00045 } 00046 public void tryToProcessSomething() throws PipelineProcessingRequestErrorEx { 00047 //Trying to process something. 00048 try { 00049 //To process something there must have been something scheduled. 00050 //Since there was nothing scheduled the Nothing can be scheduled error was thrown 00051 tryToScheduleSomething(); 00052 //Since we threw an exception that has the base class of type ErrorSystemExample 00053 //we will show that we can catch it here. 00054 } catch(NothingCanBeScheduledErrorEx e) { 00055 //Create one of the wrapper-classes using the caught exception. 00056 AcsJPipelineProcessingRequestErrorEx e2 = new AcsJPipelineProcessingRequestErrorEx(e); 00057 // use the method in the generated wrapper class to prepare our regular error 00058 // for CORBA transport. Basically allowing all the information of what it is and 00059 // where it came from and why it happened to be retained after its been sent 00060 // over CORBA 00061 throw e2.toPipelineProcessingRequestErrorEx(); 00062 } 00063 } 00064 00065 public void usingWrapperClasses1() throws NothingCanBeScheduledErrorEx { 00066 //In this method I want to show how you can use the base-class 00067 //wrapper-class 00068 try { 00069 throw new AcsJNothingCanBeScheduledErrorEx("Couldn't scheduled due to bad weather!"); 00070 } catch(AcsJErrorSystemExampleEx e){ 00071 throw ((AcsJNothingCanBeScheduledErrorEx)e).toNothingCanBeScheduledErrorEx(); 00072 } 00073 } 00074 public void usingWrapperClasses2() { 00075 //In this method I want to show how you can use the base-class 00076 //wrapper-class 00077 try { 00078 throw new AcsJNothingCanBeScheduledErrorEx("Testing printStackTrace!"); 00079 } catch(AcsJErrorSystemExampleEx e){ 00080 e.printStackTrace(); 00081 } 00082 } 00083 00084 }