List of usage examples for java.lang IllegalArgumentException getCause
public synchronized Throwable getCause()
From source file:org.tango.server.device.StatusImpl.java
/** * Get the status of the device/*from w w w . j a v a 2 s. c o m*/ * * @return the status * @throws DevFailed */ public String updateStatus(final DeviceState state) throws DevFailed { xlogger.entry(); if (getStatusMethod != null) { try { status = (String) getStatusMethod.invoke(businessObject); } catch (final IllegalArgumentException e) { DevFailedUtils.throwDevFailed(e); } catch (final IllegalAccessException e) { DevFailedUtils.throwDevFailed(e); } catch (final InvocationTargetException e) { if (e.getCause() instanceof DevFailed) { throw (DevFailed) e.getCause(); } else { DevFailedUtils.throwDevFailed("INVOCATION_ERROR", ExceptionUtils.getStackTrace(e.getCause()) + " InvocationTargetException"); } } } else { if (status.isEmpty()) { status = "The device is in " + state + " state."; } } StringBuilder statusAlarm = new StringBuilder(); for (final String string : attributeAlarm.values()) { statusAlarm = statusAlarm.append(string); } return status + statusAlarm; }
From source file:org.tango.server.device.StateImpl.java
/** * get the state from the device//www . j av a 2 s . co m * * @return the state * @throws DevFailed */ public DevState updateState() throws DevFailed { xlogger.entry(); Object getState; if (getStateMethod != null) { try { getState = getStateMethod.invoke(businessObject); if (getState != null) { if (getState instanceof DeviceState) { state = ((DeviceState) getState).getDevState(); } else { state = (DevState) getState; } } } catch (final IllegalArgumentException e) { DevFailedUtils.throwDevFailed(e); } catch (final IllegalAccessException e) { DevFailedUtils.throwDevFailed(e); } catch (final InvocationTargetException e) { if (e.getCause() instanceof DevFailed) { throw (DevFailed) e.getCause(); } else { DevFailedUtils.throwDevFailed(e.getCause()); } } } // if (!attributeAlarm.isEmpty()) { // state = DevState.ALARM; // } xlogger.exit(); return state; }
From source file:fr.putnami.pwt.core.service.server.service.CommandExecutorImpl.java
@Override public CommandResponse executeCommand(CommandRequest request) { List<?> argsArray = request.getArgs(); CommandResponse reponse = new CommandResponse(); Throwable thrown = null;// ww w . j a va 2 s . com reponse.setRequestId(request.getRequestId()); try { this.executorLogger.info("execute : " + this.getCommandDefinition()); Object result = this.method.invoke(this.service, argsArray.toArray()); reponse.setResult(Lists.newArrayList(result)); } catch (IllegalArgumentException e) { thrown = e; reponse.setThrown(this.toThrown(CommandService.EXCEPTION_ILLEGAL_ARGUMENT, e)); } catch (IllegalAccessException e) { thrown = e; reponse.setThrown(this.toThrown(CommandService.EXCEPTION_ILLEGAL_ACCESS, e)); } catch (InvocationTargetException e) { thrown = e.getCause(); reponse.setThrown(this.toThrown(CommandService.EXCEPTION_INVOKATION, e.getTargetException())); } if (thrown != null) { this.executorLogger.error("Invokation failled ", thrown); } return reponse; }
From source file:org.tango.server.device.StatusImpl.java
/** * Change status of the device// w ww . j a va 2 s .c o m * * @param status * @throws DevFailed */ public synchronized void statusMachine(final String status, final DeviceState state) throws DevFailed { if (status != null) { logger.debug("Changing status to: {}", status); this.status = status; if (setStatusMethod != null) { try { setStatusMethod.invoke(businessObject, status); } catch (final IllegalArgumentException e) { DevFailedUtils.throwDevFailed(e); } catch (final IllegalAccessException e) { DevFailedUtils.throwDevFailed(e); } catch (final InvocationTargetException e) { if (e.getCause() instanceof DevFailed) { throw (DevFailed) e.getCause(); } else { DevFailedUtils.throwDevFailed(e.getCause()); } } } } }
From source file:org.tango.server.device.StateImpl.java
/** * change state of the device//w ww .j av a 2s . co m * * @param state * @throws DevFailed */ public synchronized void stateMachine(final DeviceState state) throws DevFailed { if (state != null) { this.state = state.getDevState(); if (setStateMethod != null) { logger.debug("Changing state to {}", state); try { if (setStateMethod.getParameterTypes()[0].equals(DeviceState.class)) { setStateMethod.invoke(businessObject, state); } else { setStateMethod.invoke(businessObject, this.state); } } catch (final IllegalArgumentException e) { DevFailedUtils.throwDevFailed(e); } catch (final IllegalAccessException e) { DevFailedUtils.throwDevFailed(e); } catch (final InvocationTargetException e) { if (e.getCause() instanceof DevFailed) { throw (DevFailed) e.getCause(); } else { DevFailedUtils.throwDevFailed(e.getCause()); } } } } }
From source file:org.atm.mvn.run.JavaBootstrap.java
/** * Invoke the main method./*from w w w. ja v a 2 s .c om*/ * * @param mainMethod * The main method * @throws Exception * Exceptions due to invocation. */ protected void invokeMain(Method mainMethod) throws Exception { try { mainMethod.invoke(null, new Object[] { args }); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { if (e.getCause() instanceof Exception) { throw (Exception) e.getCause(); } else if (e.getCause() instanceof Error) { throw (Error) e.getCause(); } else { throw e; } } }
From source file:org.sakaiproject.genericdao.hibernate.CompleteGenericDaoTest.java
/** * Test method for {@link org.sakaiproject.genericdao.hibernate.HibernateCompleteGenericDao#deleteMixedSet(java.util.Set[])}. *//* ww w . j a v a 2s .c o m*/ @Test @SuppressWarnings("unchecked") public void testDeleteMixedSet() { Set deleteSet = new HashSet(); deleteSet.add(gto2); deleteSet.add(gto3); Set[] setArray = new Set[] { deleteSet }; genericDao.deleteMixedSet(setArray); List l = genericDao.findAll(GenericTestObject.class); Assert.assertNotNull(l); Assert.assertEquals(3, l.size()); Assert.assertTrue(!l.contains(gto2)); Assert.assertTrue(!l.contains(gto3)); // Now check that invalid objects cause failure deleteSet = new HashSet(); deleteSet.add(gto1); Set deleteFailSet = new HashSet(); deleteFailSet.add("string"); // non-matching object type deleteFailSet.add("string2"); // non-matching object type setArray = new Set[] { deleteSet, deleteFailSet }; try { genericDao.deleteMixedSet(setArray); Assert.fail("Should have thrown an exception before getting here"); } catch (IllegalArgumentException e) { Assert.assertNotNull(e); } catch (Exception e) { Assert.fail("Threw wrong exception: (" + e.getCause() + "): " + e.getMessage()); } l = genericDao.findAll(GenericTestObject.class); Assert.assertNotNull(l); Assert.assertEquals(3, l.size()); Assert.assertTrue(l.contains(gto1)); Assert.assertTrue(!l.contains(gto2)); Assert.assertTrue(!l.contains(gto3)); }
From source file:org.sakaiproject.genericdao.hibernate.CompleteGenericDaoTest.java
/** * Test method for {@link org.sakaiproject.genericdao.hibernate.HibernateCompleteGenericDao#saveMixedSet(java.util.Set[])}. *//* w w w. j ava 2s. co m*/ @Test @SuppressWarnings("unchecked") public void testSaveMixedSet() { GenericTestObject gtoA = new GenericTestObject("titleA", Boolean.TRUE); GenericTestObject gtoB = new GenericTestObject("titleB", Boolean.FALSE); Set saveSet = new HashSet(); saveSet.add(gtoA); saveSet.add(gtoB); Set[] setArray = new Set[] { saveSet }; genericDao.saveMixedSet(setArray); List l = genericDao.findAll(GenericTestObject.class); Assert.assertNotNull(l); Assert.assertEquals(7, l.size()); Assert.assertTrue(l.contains(gtoA)); Assert.assertTrue(l.contains(gtoB)); // Now check that invalid objects cause failure Set saveFailSet = new HashSet(); saveFailSet.add("string"); // non-matching object type saveFailSet.add("string2"); // non-matching object type GenericTestObject gtoD = new GenericTestObject("titleD", Boolean.TRUE); saveSet = new HashSet(); saveSet.add(gtoD); setArray = new Set[] { saveSet, saveFailSet }; try { genericDao.saveMixedSet(setArray); Assert.fail("Should have thrown an exception before getting here"); } catch (IllegalArgumentException e) { Assert.assertNotNull(e); } catch (Exception e) { Assert.fail("Threw wrong exception: (" + e.getCause() + "): " + e.getMessage()); } l = genericDao.findAll(GenericTestObject.class); Assert.assertNotNull(l); Assert.assertEquals(7, l.size()); Assert.assertTrue(!l.contains(gtoD)); }
From source file:org.sakaiproject.genericdao.hibernate.CompleteGenericDaoTest.java
/** * Test method for {@link org.sakaiproject.genericdao.hibernate.HibernateCompleteGenericDao#saveSet(java.util.Set)}. *//*w w w .j a v a 2 s . c om*/ @Test public void testSaveSet() { GenericTestObject gtoA = new GenericTestObject("titleA", Boolean.TRUE); GenericTestObject gtoB = new GenericTestObject("titleB", Boolean.FALSE); Set<GenericTestObject> saveSet = new HashSet<GenericTestObject>(); saveSet.add(gtoA); saveSet.add(gtoB); genericDao.saveSet(saveSet); List<GenericTestObject> l = genericDao.findAll(GenericTestObject.class); Assert.assertNotNull(l); Assert.assertEquals(7, l.size()); Assert.assertTrue(l.contains(gtoA)); Assert.assertTrue(l.contains(gtoB)); // Now try to cause various Exceptions // test no longer needed // GenericTestObject gtoC = new GenericTestObject("titleC", Boolean.TRUE); // saveSet = new HashSet<GenericTestObject>(); // saveSet.add(gtoC); // saveSet.add("string"); // mixed types // try { // genericDao.saveSet(saveSet); // Assert.fail("Should have thrown an exception before getting here"); // } catch (IllegalArgumentException e) { // Assert.assertNotNull(e); // } catch (Exception e) { // Assert.fail("Threw wrong exception: ("+e.getCause()+"): " + e.getMessage()); // } // // l = genericDao.findAll(GenericTestObject.class); // Assert.assertNotNull(l); // Assert.assertEquals(7, l.size()); // Assert.assertTrue(! l.contains(gtoC)); Set<String> failSaveSet = new HashSet<String>(); failSaveSet.add("string"); // not a persistent type try { genericDao.saveSet(failSaveSet); Assert.fail("Should have thrown an exception before getting here"); } catch (IllegalArgumentException e) { Assert.assertNotNull(e); } catch (Exception e) { Assert.fail("Threw wrong exception: (" + e.getCause() + "): " + e.getMessage()); } l = genericDao.findAll(GenericTestObject.class); Assert.assertNotNull(l); Assert.assertEquals(7, l.size()); }