List of usage examples for java.lang IllegalAccessException getMessage
public String getMessage()
From source file:org.hyperic.lather.util.Latherize.java
public void latherize(boolean xDocletStyle, String outPackage, Class fClass, OutputStream os) throws LatherizeException, IOException { final String INDENT = " "; PrintWriter pWriter;// ww w . ja v a 2 s . c om DynaProperty[] dProps; WrapDynaBean dBean; DynaClass dClass; Object beanInstance; String className, lClassName; try { beanInstance = fClass.newInstance(); } catch (IllegalAccessException exc) { throw new LatherizeException("Illegal access trying to create " + "new instance"); } catch (InstantiationException exc) { throw new LatherizeException("Unable to instantiate: " + exc.getMessage()); } dBean = new WrapDynaBean(beanInstance); dClass = dBean.getDynaClass(); dProps = dClass.getDynaProperties(); pWriter = new PrintWriter(os); className = fClass.getName(); className = className.substring(className.lastIndexOf(".") + 1); lClassName = "Lather" + className; pWriter.println("package " + outPackage + ";"); pWriter.println(); pWriter.println("import " + LatherValue.class.getName() + ";"); pWriter.println("import " + LatherRemoteException.class.getName() + ";"); pWriter.println("import " + LatherKeyNotFoundException.class.getName() + ";"); pWriter.println("import " + fClass.getName() + ";"); pWriter.println(); pWriter.println("public class " + lClassName); pWriter.println(" extends LatherValue"); pWriter.println("{"); for (int i = 0; i < dProps.length; i++) { pWriter.print(" "); if (!this.isLatherStyleProp(dProps[i])) { pWriter.print("// "); } pWriter.println("private static final String " + this.makePropVar(dProps[i]) + " = \"" + dProps[i].getName() + "\";"); } pWriter.println(); pWriter.println(" public " + lClassName + "(){"); pWriter.println(" super();"); pWriter.println(" }"); pWriter.println(); pWriter.println(" public " + lClassName + "(" + className + " v){"); pWriter.println(" super();"); pWriter.println(); for (int i = 0; i < dProps.length; i++) { String propVar = this.makePropVar(dProps[i]); String getter = "v." + this.makeGetter(dProps[i]) + "()"; if (!this.isLatherStyleProp(dProps[i])) { continue; } if (xDocletStyle) { String lName; lName = dProps[i].getName(); lName = lName.substring(0, 1).toLowerCase() + lName.substring(1); pWriter.println(INDENT + "if(v." + lName + "HasBeenSet()){"); pWriter.print(" "); } if (dProps[i].getType().equals(String.class)) { pWriter.println(INDENT + "this.setStringValue(" + propVar + ", " + getter + ");"); } else if (dProps[i].getType().equals(Integer.TYPE)) { pWriter.println(INDENT + "this.setIntValue(" + propVar + ", " + getter + ");"); } else if (dProps[i].getType().equals(Integer.class)) { pWriter.println(INDENT + "this.setIntValue(" + propVar + ", " + getter + ".intValue());"); } else if (dProps[i].getType().equals(Long.TYPE)) { pWriter.println(INDENT + "this.setDoubleValue(" + propVar + ", (double)" + getter + ");"); } else if (dProps[i].getType().equals(Long.class)) { pWriter.println( INDENT + "this.setDoubleValue(" + propVar + ", (double)" + getter + ".longValue());"); } else if (dProps[i].getType().equals(Boolean.TYPE)) { pWriter.println(INDENT + "this.setIntValue(" + propVar + ", " + getter + " ? 1 : 0);"); } else if (dProps[i].getType().equals(Boolean.class)) { pWriter.println( INDENT + "this.setIntValue(" + propVar + ", " + getter + ".booleanValue() ? 1 : 0);"); } else if (dProps[i].getType().equals(Double.TYPE)) { pWriter.println(INDENT + "this.setDoubleValue(" + propVar + ", " + getter + ");"); } else if (dProps[i].getType().equals(Double.class)) { pWriter.println(INDENT + "this.setDoubleValue(" + propVar + ", " + getter + ".doubleValue());"); } else if (dProps[i].getType().equals(byte[].class)) { pWriter.println(INDENT + "this.setByteAValue(" + propVar + ", " + getter + ");"); } else { pWriter.println(INDENT + "this.setObjectValue(" + "DONT KNOW HOW TO HANDLE THIS, " + getter + ");"); } if (xDocletStyle) { pWriter.println(INDENT + "}"); pWriter.println(); } } pWriter.println(" }"); pWriter.println(); pWriter.println(" public " + className + " get" + className + "(){"); pWriter.println(INDENT + className + " r = new " + className + "();"); pWriter.println(); for (int i = 0; i < dProps.length; i++) { String propVar = this.makePropVar(dProps[i]); String setter = "r." + this.makeSetter(dProps[i]) + "("; if (!this.isLatherStyleProp(dProps[i])) { continue; } if (xDocletStyle) { pWriter.println(INDENT + "try {"); pWriter.print(" "); } pWriter.print(INDENT + setter); if (dProps[i].getType().equals(String.class)) { pWriter.println("this.getStringValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Integer.TYPE)) { pWriter.println("this.getIntValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Integer.class)) { pWriter.println("new Integer(this.getIntValue(" + propVar + ")));"); } else if (dProps[i].getType().equals(Long.TYPE)) { pWriter.println("(long)this.getDoubleValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Long.class)) { pWriter.println("new Long((long)this.getDoubleValue(" + propVar + ")));"); } else if (dProps[i].getType().equals(Boolean.TYPE)) { pWriter.println("this.getIntValue(" + propVar + ") == 1 ? " + "true : false);"); } else if (dProps[i].getType().equals(Boolean.class)) { pWriter.println("this.getIntValue(" + propVar + ") == 1 ? " + "Boolean.TRUE : Boolean.FALSE);"); } else if (dProps[i].getType().equals(Double.TYPE)) { pWriter.println("this.getDoubleValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Double.class)) { pWriter.println("new Double(this.getDoubleValue(" + propVar + ")));"); } else if (dProps[i].getType().equals(byte[].class)) { pWriter.println("this.getByteAValue(" + propVar + "));"); } else { pWriter.println("DONT KNOW HOW TO HANDLE " + propVar + "));"); } if (xDocletStyle) { pWriter.println(INDENT + "} catch(LatherKeyNotFoundException " + "exc){}"); pWriter.println(); } } pWriter.println(INDENT + "return r;"); pWriter.println(" }"); pWriter.println(); pWriter.println(" protected void validate()"); pWriter.println(" throws LatherRemoteException"); pWriter.println(" {"); if (!xDocletStyle) { pWriter.println(" try { "); pWriter.println(" this.get" + className + "();"); pWriter.println(" } catch(LatherKeyNotFoundException e){"); pWriter.println(" throw new LatherRemoteException(\"" + "All values not set\");"); pWriter.println(" }"); } pWriter.println(" }"); pWriter.println("}"); pWriter.flush(); }
From source file:no.sesat.search.datamodel.BeanDataObjectInvocationHandler.java
protected Object invokeSupport(final Method m, final Object support, final Object[] args) { Object result = null;/*w w w . j a v a2s.c o m*/ try { // if( !support.getClass().isAssignableFrom(m.getDeclaringClass()) ){ // // try to find method again since m is an override and won't be found as is in support // m = support.getClass().getMethod(m.getName(), m.getParameterTypes()); // } result = m.invoke(support, args); } catch (IllegalAccessException iae) { LOG.info(iae.getMessage(), iae); } catch (IllegalArgumentException iae) { LOG.trace(iae.getMessage()); // }catch(NoSuchMethodException nsme){ // LOG.trace(nsme.getMessage()); } catch (InvocationTargetException ite) { LOG.info(ite.getMessage(), ite); } return result; }
From source file:net.sf.joost.trax.TransformerFactoryImpl.java
/** * Method creates a new Emitter for stx:message output * @param emitterClass the name of the emitter class * @return a <code>StxEmitter</code> * @throws TransformerConfigurationException in case of errors *//*from w w w . j ava 2s.c o m*/ public StxEmitter buildMessageEmitter(String emitterClass) throws TransformerConfigurationException { Object emitter = null; try { emitter = loadClass(emitterClass).newInstance(); if (!(emitter instanceof StxEmitter)) { throw new TransformerConfigurationException(emitterClass + " is not an StxEmitter"); } } catch (InstantiationException ie) { throw new TransformerConfigurationException(ie.getMessage(), ie); } catch (IllegalAccessException ile) { throw new TransformerConfigurationException(ile.getMessage(), ile); } return (StxEmitter) emitter; }
From source file:org.kuali.kfs.module.tem.service.impl.TravelExpenseServiceImpl.java
/** * Copies the parent and nulls out unnecessary fields for a detail line * @see org.kuali.kfs.module.tem.service.TravelExpenseService#createNewDetailForActualExpense(org.kuali.kfs.module.tem.businessobject.ActualExpense) *//* w ww.j a v a2 s . c o m*/ @Override public ActualExpense createNewDetailForActualExpense(ActualExpense parent) { ActualExpense newExpense = new ActualExpense(); try { BeanUtils.copyProperties(newExpense, parent); newExpense.setConvertedAmount(null); newExpense.setExpenseParentId(newExpense.getId()); newExpense.setId(null); newExpense.setNotes(null); newExpense.setExpenseLineTypeCode(null); // evidently, this should be nulled out on detail lines } catch (IllegalAccessException ex) { LOG.error(ex.getMessage(), ex); } catch (InvocationTargetException ex) { LOG.error(ex.getMessage(), ex); } return newExpense; }
From source file:com.ottogroup.bi.spqr.repository.CachedComponentClassLoader.java
/** * Looks up the reference {@link DataComponent}, instantiates it and passes over the provided {@link Properties} * @param name name of component to instantiate (required) * @param version version of component to instantiate (required) * @param properties properties to use for instantiation * @return/*ww w . j a va 2 s. c o m*/ * @throws RequiredInputMissingException thrown in case a required parameter value is missing * @throws ComponentInstantiationFailedException thrown in case the instantiation failed for any reason * @throws UnknownComponentException thrown in case the name and version combination does not reference a managed component */ public MicroPipelineComponent newInstance(final String id, final String name, final String version, final Properties properties) throws RequiredInputMissingException, ComponentInstantiationFailedException, UnknownComponentException { ////////////////////////////////////////////////////////////////////////////////////////// // validate provided input if (StringUtils.isBlank(id)) throw new RequiredInputMissingException("Missing required component id"); if (StringUtils.isBlank(name)) throw new RequiredInputMissingException("Missing required component name"); if (StringUtils.isBlank(version)) throw new RequiredInputMissingException("Missing required component version"); // ////////////////////////////////////////////////////////////////////////////////////////// long start = System.currentTimeMillis(); // generate component key and retrieve the associated descriptor ... if available String componentKey = getManagedComponentKey(name, version); ComponentDescriptor descriptor = this.managedComponents.get(componentKey); if (descriptor == null) throw new UnknownComponentException("Unknown component [name=" + name + ", version=" + version + "]"); // if the descriptor exists, load the referenced component class, create an instance and hand over the properties try { Class<?> messageHandlerClass = loadClass(descriptor.getComponentClass()); MicroPipelineComponent instance = (MicroPipelineComponent) messageHandlerClass.newInstance(); instance.setId(id); long beforeInit = System.currentTimeMillis(); instance.initialize(properties); long endAfterInit = System.currentTimeMillis(); if (logger.isDebugEnabled()) logger.debug("newInstance[name=" + name + ", version=" + version + ", overall=" + (endAfterInit - start) + "ms, instance=" + (beforeInit - start) + "ms, init=" + (endAfterInit - beforeInit) + "ms]"); return instance; } catch (IllegalAccessException e) { throw new ComponentInstantiationFailedException("Failed to instantiate component [name=" + name + ", version=" + version + ", reason=" + e.getMessage()); } catch (InstantiationException e) { throw new ComponentInstantiationFailedException("Failed to instantiate component [name=" + name + ", version=" + version + ", reason=" + e.getMessage()); } catch (ClassNotFoundException e) { throw new ComponentInstantiationFailedException("Failed to instantiate component [name=" + name + ", version=" + version + ", reason=" + e.getMessage()); } catch (ComponentInitializationFailedException e) { throw new ComponentInstantiationFailedException("Failed to instantiate component [name=" + name + ", version=" + version + ", reason=" + e.getMessage()); } }
From source file:org.apache.hadoop.hive.serde2.protobuf.ProtobufSerDe.java
@Override public Object deserialize(Writable blob) throws SerDeException { BytesWritable bw = (BytesWritable) blob; if (bw.getSize() <= 0) { return null; }//w w w . j ava 2s. c o m CodedInputStream cis = CodedInputStream.newInstance(bw.getBytes(), 0, bw.getSize()); Object message = null; try { message = parseFromMethod.invoke(null, cis); } catch (java.lang.IllegalAccessException e) { throw new SerDeException(e.getMessage()); } catch (java.lang.reflect.InvocationTargetException e) { String errmsg = e.getMessage(); Throwable cause = e.getCause(); if (cause instanceof InvalidProtocolBufferException) { errmsg = "__InvalidProtocolBufferException:" + errmsg; } throw new SerDeException(errmsg); } return message; }
From source file:no.sesat.search.datamodel.BeanDataObjectInvocationHandler.java
protected Object invokeSelf(final Method method, final Object[] args) { // try invoking one of our own methods. (Works for example on methods declared by the Object class). Object result = null;//from w ww . j a v a 2 s .c o m // a quick optimisation is to check if there's any method at all with the same name. final Method[] knownMethods = this.getClass().getMethods(); boolean hasSameNameMethod = false; for (Method m : knownMethods) { if (m.getName().equals(method.getName())) { hasSameNameMethod = true; break; } } if (hasSameNameMethod) { try { result = method.invoke(this, args); } catch (IllegalAccessException iae) { LOG.info(iae.getMessage(), iae); } catch (IllegalArgumentException iae) { LOG.debug(iae.getMessage()); } catch (InvocationTargetException ite) { LOG.info(ite.getMessage(), ite); } } return result; }
From source file:de.micromata.genome.util.strings.ReducedReflectionToStringBuilder.java
/** * Append fields in internal.//from w w w .jav a 2 s. co m * * @param clazz the clazz * @return true, if successful */ protected boolean appendFieldsInInternal(Class<?> clazz) { registerObject(getObject()); if (clazz.isArray()) { this.reflectionAppendArray(this.getObject()); return false; } Field[] fields = clazz.getDeclaredFields(); AccessibleObject.setAccessible(fields, true); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; String fieldName = field.getName(); if (this.accept(field) == false) { continue; } try { // Warning: Field.get(Object) creates wrappers objects // for primitive types. Object fieldValue = this.getValue(field); if (isObjectRegistered(fieldValue) == true && field.getType().isPrimitive() == false) { this.getStringBuffer().append(fieldName).append("="); this.appendAsObjectToString(fieldValue); this.getStringBuffer().append(","); } else { this.append(fieldName, fieldValue); } } catch (IllegalAccessException ex) { // this can't happen. Would get a Security exception // instead // throw a runtime exception in case the impossible // happens. throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage()); } } return true; }
From source file:de.forsthaus.webui.security.user.MyUserSettingsCtrl.java
/** * Saves the selected object's current properties. We can get them back if a * modification is canceled./*from ww w . jav a2 s.c o m*/ * * @throws InterruptedException * * @see doResetToInitValues() */ public void doStoreInitValues() throws InterruptedException { if (getSelectedUser() != null) { try { setOriginalUser((SecUser) ZksampleBeanUtils.cloneBean(getSelectedUser())); } catch (IllegalAccessException e) { ZksampleMessageUtils.showErrorMessage(e.getMessage()); } catch (InstantiationException e) { ZksampleMessageUtils.showErrorMessage(e.getMessage()); } catch (InvocationTargetException e) { ZksampleMessageUtils.showErrorMessage(e.getMessage()); } catch (NoSuchMethodException e) { ZksampleMessageUtils.showErrorMessage(e.getMessage()); } } }
From source file:org.jbuilt.utils.ValueClosure.java
public void restoreState(FacesContext context, Object state) { // if we have state if (null == state) { return;/*from w w w .j av a 2 s .c om*/ } Object[] stateStruct = (Object[]) state; Object savedState = stateStruct[0]; String className = stateStruct[1].toString(); ValueExpression result = null; Class toRestoreClass = null; if (null != className) { try { toRestoreClass = loadClass(className, this); } catch (ClassNotFoundException e) { throw new IllegalStateException(e.getMessage()); } if (null != toRestoreClass) { try { result = (ValueExpression) toRestoreClass.newInstance(); } catch (InstantiationException e) { throw new IllegalStateException(e.getMessage()); } catch (IllegalAccessException a) { throw new IllegalStateException(a.getMessage()); } } if (null != result && null != savedState) { // don't need to check transient, since that was // done on the saving side. ((StateHolder) result).restoreState(context, savedState); } } }