ALMA Computing Group

XmlComponentImpl.java

Go to the documentation of this file.
00001 /* 00002 * ALMA - Atacama Large Millimiter Array 00003 * (c) European Southern Observatory, 2002 00004 * Copyright by ESO (in the framework of the ALMA collaboration), 00005 * All rights reserved 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00020 * MA 02111-1307 USA 00021 */ 00022 package alma.demo.XmlComponentImpl; 00023 00024 import java.util.ArrayList; 00025 import java.util.Arrays; 00026 import java.util.Random; 00027 import java.util.logging.Level; 00028 00029 import alma.JContExmplErrTypeTest.XmlComponentErrorEx; 00030 import alma.JContExmplErrTypeTest.wrappers.AcsJXmlComponentErrorEx; 00031 import alma.JavaContainerError.wrappers.AcsJContainerServicesEx; 00032 import alma.acs.component.ComponentImplBase; 00033 import alma.acs.component.ComponentLifecycleException; 00034 import alma.acs.container.ContainerServices; 00035 import alma.demo.ObsProjectTreeJ; 00036 import alma.demo.SchedBlockHolder; 00037 import alma.demo.XmlComponentJ; 00038 import alma.xmljbind.test.obsproposal.ObsProposal; 00039 import alma.xmljbind.test.obsproposal.ObsProposalEntityT; 00040 import alma.xmljbind.test.schedblock.SchedBlock; 00041 import alma.xmljbind.test.schedblock.SchedBlockControlT; 00042 import alma.xmljbind.test.schedblock.SchedBlockEntityT; 00043 00044 00057 public class XmlComponentImpl extends ComponentImplBase implements XmlComponentJ 00058 { 00059 private ArrayList<SchedBlock> m_schedBlockList; 00060 // private float m_radius; 00061 00062 00064 // Implementation of ComponentLifecycle 00065 // (only the parts we don't take from the default impl in ComponentImplBase) 00067 00071 public void initialize(ContainerServices contServices) throws ComponentLifecycleException 00072 { 00073 super.initialize(contServices); 00074 00075 m_schedBlockList = new ArrayList<SchedBlock>(); 00076 00077 try 00078 { 00079 // create a few (incomplete) SchedBlocks 00080 for (int sbCount = 0; sbCount < 10; sbCount++) 00081 { 00082 SchedBlock sb = new SchedBlock(); 00083 00084 SchedBlockEntityT entity = new SchedBlockEntityT(); 00085 m_containerServices.assignUniqueEntityId(entity); 00086 sb.setSchedBlockEntity(entity); 00087 00088 SchedBlockControlT sbCtrl = new SchedBlockControlT(); 00089 sb.setSchedBlockControl(sbCtrl); 00090 sbCtrl.setRepeatCount(sbCount%3); 00091 // sbCtrl.setEntityPartId("X00000008"); // set this on an ObsUnitSet instead... 00092 00093 m_schedBlockList.add(sb); 00094 } 00095 } 00096 catch (AcsJContainerServicesEx e) 00097 { 00098 m_logger.log(Level.WARNING, "failed to initialize list of SchedBlocks. ", e); 00099 m_schedBlockList.clear(); 00100 // throw new ComponentLifecycleException(e); // not required 00101 } 00102 } 00103 00104 00106 // Implementation of XmlComponentJ 00108 00114 public int dumbMethod(String somevalue) 00115 { 00116 return 1234567; 00117 } 00118 00124 public ObsProposal createObsProposal() 00125 { 00126 ObsProposal obsProp = new ObsProposal(); 00127 00128 try 00129 { 00130 ObsProposalEntityT entity = new ObsProposalEntityT(); 00131 m_containerServices.assignUniqueEntityId(entity); 00132 obsProp.setObsProposalEntity(entity); 00133 00134 obsProp.setScientificJustification("peak performance enduring a 24-7-365 schedule."); 00135 } 00136 catch (AcsJContainerServicesEx e) 00137 { 00138 m_logger.log(Level.SEVERE, "failed to create ObsProposal. ", e); 00139 } 00140 00141 return obsProp; 00142 } 00143 00147 public SchedBlock getBestSchedBlock() 00148 { 00149 SchedBlock sb = null; 00150 if (m_schedBlockList.size() > 0) { 00151 Random random = new Random(System.currentTimeMillis()); 00152 int sbIndex = random.nextInt(m_schedBlockList.size()); 00153 00154 sb = m_schedBlockList.get(sbIndex); 00155 } 00156 return sb; 00157 } 00158 00164 public SchedBlock[] getAllSchedBlocks() 00165 { 00166 return m_schedBlockList.toArray(new SchedBlock[0]); 00167 } 00168 00169 00173 public void addNewSchedBlocks(SchedBlock[] newSchedBlocks) 00174 { 00175 m_schedBlockList.addAll(Arrays.asList(newSchedBlocks)); 00176 m_logger.info("successfully added " + newSchedBlocks.length + " SchedBlock instance(s)"); 00177 } 00178 00179 00186 public void xmlInOutMethod(ObsProposal opsPropIn, SchedBlockHolder schedBlockOut) 00187 { 00188 schedBlockOut.value = getBestSchedBlock(); 00189 } 00190 00191 00201 public ObsProjectTreeJ getEntireTreeInAStruct() 00202 { 00203 ObsProjectTreeJ struct = new ObsProjectTreeJ(); 00204 00205 struct.prop = createObsProposal(); 00206 struct.schedBlocks = getAllSchedBlocks(); 00207 00208 return struct; 00209 } 00210 00211 00215 public String sayHello() 00216 { 00217 String ret = ""; 00218 00219 try 00220 { 00221 alma.demo.HelloDemo helloComp = 00222 alma.demo.HelloDemoHelper.narrow(m_containerServices.getComponent("HELLODEMO1")); 00223 ret = helloComp.sayHello(); 00224 m_containerServices.releaseComponent("HELLODEMO1"); 00225 } 00226 catch (Exception e) 00227 { 00228 m_logger.severe("failed to obtain the hello string from the remote component!"); 00229 } 00230 00231 00232 return ret; 00233 } 00234 00235 00241 public void exceptionMethod() throws XmlComponentErrorEx 00242 { 00243 try { 00244 // an internal method that works with native Java exceptions 00245 internalExceptionMethod(); 00246 } catch (AcsJXmlComponentErrorEx e) { 00247 m_logger.info("deliberately created and caught the following exception (trace):"); 00248 e.log(m_logger); 00249 // convert to CORBA-compatible exception 00250 throw e.toXmlComponentErrorEx(); 00251 } 00252 } 00253 00260 public void internalExceptionMethod() throws AcsJXmlComponentErrorEx { 00261 try { 00262 // do something that can throw an exception 00263 throw new NullPointerException("dirty NPE for testing..."); 00264 } catch (NullPointerException npe) { 00265 // this shows how native Java exceptions can be daisy-chained 00266 throw new AcsJXmlComponentErrorEx("use me for container tests", npe); 00267 } 00268 } 00269 00270 00271 00272 // /** 00273 // * @see alma.demo.XmlComponentJ#circumference() 00274 // */ 00275 // public float circumference() 00276 // { 00277 // return (float) (2 * Math.PI * m_radius); 00278 // } 00279 // 00280 // /** 00281 // * @see alma.demo.XmlComponentJ#radius() 00282 // */ 00283 // public float radius() 00284 // { 00285 // return m_radius; 00286 // } 00287 // 00288 // /** 00289 // * @see alma.demo.XmlComponentJ#radius(float) 00290 // */ 00291 // public void radius(float value) 00292 // { 00293 // m_radius = value; 00294 // } 00295 00296 }