List of usage examples for java.lang InstantiationException getMessage
public String getMessage()
From source file:com.moviejukebox.MovieJukebox.java
public static MovieListingPlugin getListingPlugin(String className) { try {/*from w w w .j a v a 2s.com*/ Thread t = Thread.currentThread(); ClassLoader cl = t.getContextClassLoader(); Class<? extends MovieListingPlugin> pluginClass = cl.loadClass(className) .asSubclass(MovieListingPlugin.class); return pluginClass.newInstance(); } catch (InstantiationException ex) { LOG.error("Failed instanciating ListingPlugin: {} - Error: {}", className, ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } catch (IllegalAccessException ex) { LOG.error("Failed accessing ListingPlugin: {} - Error: {}", className, ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } catch (ClassNotFoundException ex) { LOG.error("ListingPlugin class not found: {} - Error: {}", className, ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } LOG.error("No listing plugin will be used."); return new MovieListingPluginBase(); }
From source file:com.moviejukebox.MovieJukebox.java
public static MovieImagePlugin getBackgroundPlugin(String className) { try {/*w ww . j av a 2s .c o m*/ Thread t = Thread.currentThread(); ClassLoader cl = t.getContextClassLoader(); Class<? extends MovieImagePlugin> pluginClass = cl.loadClass(className) .asSubclass(MovieImagePlugin.class); return pluginClass.newInstance(); } catch (InstantiationException ex) { LOG.error("Failed instantiating BackgroundPlugin: {} - Error: {}", className, ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } catch (IllegalAccessException ex) { LOG.error("Failed accessing BackgroundPlugin: {} - Error: {}", className, ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } catch (ClassNotFoundException ex) { LOG.error("BackgroundPlugin class not found: {} - Error: {}", className, ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } LOG.error("Default background plugin will be used instead."); return new DefaultBackgroundPlugin(); }
From source file:jtabwb.launcher.Launcher.java
private ProblemDescription readFromFile(ProofSearchData info, String inputFilename) { try {/*from w w w.ja v a 2 s . c om*/ // get the file File inputFile = new File(inputFilename); if (!inputFile.exists()) { LOG.error(MSG.LAUNCHER.ERROR_MSG.NO_SUCH_FILE, inputFilename); System.exit(1); } // get the reader try { currentConfiguration.selectedReader = currentConfiguration.fileReader.getValue().newInstance(); if (!currentConfiguration.testsetmode) info_preReaderExecutionDetails(); FileReader fir = new FileReader(inputFile); if (!currentConfiguration.testsetmode) LOG.infoNoLn(MSG.LAUNCHER.INFO.PROBLEM_DESCRIPTION_PARSING_BEGIN); // configure problem reader if problem reader configurator is defined if (currentConfiguration.singleExecutionConfigurator != null) currentConfiguration.singleExecutionConfigurator .configProblemReader(currentConfiguration.selectedReader, currentConfiguration); // read problem description info.parsing_problem_start_time = getCurrentTimeMilleseconds(); ProblemDescription problemDescription = currentConfiguration.selectedReader.read(fir); info.parsing_problem_end_time = getCurrentTimeMilleseconds(); if (!currentConfiguration.testsetmode) LOG.info(MSG.LAUNCHER.INFO.PROBLEM_DESCRIPTION_PARSING_END, info.getParsingProblemTime()); problemDescription.setSource(inputFile.getAbsolutePath()); problemDetails_print(problemDescription); return problemDescription; /* * we already tested that a visible nullary constructor exists for this * class when we added them to availableReaders */ } catch (InstantiationException e) { } catch (IllegalAccessException e) { } } catch (IOException e) { LOG.error(MSG.LAUNCHER.ERROR_MSG.IO_EXCEPTION, e.getMessage()); System.exit(1); } catch (ProblemDescriptionException e) { LOG.error(MSG.LAUNCHER.ERROR_MSG.PROBLEM_WRONG_FORMAT, e.getMessage()); System.exit(1); } return null; }
From source file:org.kuali.rice.kns.maintenance.KualiMaintainableImpl.java
/** * Gets list of maintenance sections built from the data dictionary. If the * section contains maintenance fields, construct Row/Field UI objects and * place under Section UI. If section contains a maintenance collection, * call method to build a Section UI which contains rows of Container * Fields./*from w ww .j a v a2 s . c o m*/ * * @return List of org.kuali.ui.Section objects */ public List<Section> getCoreSections(MaintenanceDocument document, Maintainable oldMaintainable) { List<Section> sections = new ArrayList<Section>(); MaintenanceDocumentRestrictions maintenanceRestrictions = KNSServiceLocator .getBusinessObjectAuthorizationService() .getMaintenanceDocumentRestrictions(document, GlobalVariables.getUserSession().getPerson()); MaintenanceDocumentPresentationController maintenanceDocumentPresentationController = (MaintenanceDocumentPresentationController) getDocumentHelperService() .getDocumentPresentationController(document); Set<String> conditionallyRequiredFields = maintenanceDocumentPresentationController .getConditionallyRequiredPropertyNames(document); List<MaintainableSectionDefinition> sectionDefinitions = getMaintenanceDocumentDictionaryService() .getMaintainableSections(getDocumentTypeName()); try { // iterate through section definitions and create Section UI object for (Iterator iter = sectionDefinitions.iterator(); iter.hasNext();) { MaintainableSectionDefinition maintSectionDef = (MaintainableSectionDefinition) iter.next(); List<String> displayedFieldNames = new ArrayList<String>(); if (!maintenanceRestrictions.isHiddenSectionId(maintSectionDef.getId())) { for (Iterator iter2 = maintSectionDef.getMaintainableItems().iterator(); iter2.hasNext();) { MaintainableItemDefinition item = (MaintainableItemDefinition) iter2.next(); if (item instanceof MaintainableFieldDefinition) { displayedFieldNames.add(((MaintainableFieldDefinition) item).getName()); } } Section section = SectionBridge.toSection(maintSectionDef, getBusinessObject(), this, oldMaintainable, getMaintenanceAction(), displayedFieldNames, conditionallyRequiredFields); if (maintenanceRestrictions.isReadOnlySectionId(maintSectionDef.getId())) { section.setReadOnly(true); } // add to section list sections.add(section); } } } catch (InstantiationException e) { LOG.error("Unable to create instance of object class" + e.getMessage()); throw new RuntimeException("Unable to create instance of object class" + e.getMessage()); } catch (IllegalAccessException e) { LOG.error("Unable to create instance of object class" + e.getMessage()); throw new RuntimeException("Unable to create instance of object class" + e.getMessage()); } return sections; }
From source file:edu.duke.cabig.c3pr.web.ajax.StudyAjaxFacade.java
@SuppressWarnings("unchecked") private <T> T buildReduced(T src, List<String> properties) { T dst = null;// ww w.ja v a2 s. c o m try { // it doesn't seem like this cast should be necessary dst = (T) src.getClass().newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } BeanWrapper source = new BeanWrapperImpl(src); BeanWrapper destination = new BeanWrapperImpl(dst); for (String property : properties) { // only for nested props String[] individualProps = property.split("\\."); String temp = ""; for (int i = 0; i < individualProps.length - 1; i++) { temp += (i != 0 ? "." : "") + individualProps[i]; Object o = source.getPropertyValue(temp); if (destination.getPropertyValue(temp) == null) { try { destination.setPropertyValue(temp, o.getClass().newInstance()); } catch (BeansException e) { log.error(e.getMessage()); } catch (InstantiationException e) { log.error(e.getMessage()); } catch (IllegalAccessException e) { log.error(e.getMessage()); } } } // for single and nested props destination.setPropertyValue(property, source.getPropertyValue(property)); } return dst; }
From source file:org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl.java
/** * Constructs the list of rows for the search fields. All properties for the field objects come * from the DataDictionary. To be called by setBusinessObject *//*from w w w .j a va 2 s . c o m*/ protected void setRows() { List<String> lookupFieldAttributeList = null; if (getBusinessObjectMetaDataService().isLookupable(getBusinessObjectClass())) { lookupFieldAttributeList = getBusinessObjectMetaDataService() .getLookupableFieldNames(getBusinessObjectClass()); } if (lookupFieldAttributeList == null) { throw new RuntimeException("Lookup not defined for business object " + getBusinessObjectClass()); } // construct field object for each search attribute List fields = new ArrayList(); try { fields = FieldUtils.createAndPopulateFieldsForLookup(lookupFieldAttributeList, getReadOnlyFieldsList(), getBusinessObjectClass()); } catch (InstantiationException e) { throw new RuntimeException("Unable to create instance of business object class" + e.getMessage()); } catch (IllegalAccessException e) { throw new RuntimeException("Unable to create instance of business object class" + e.getMessage()); } int numCols = getBusinessObjectDictionaryService().getLookupNumberOfColumns(this.getBusinessObjectClass()); this.rows = FieldUtils.wrapFields(fields, numCols); }
From source file:com.evolveum.midpoint.prism.parser.PrismBeanConverter.java
public <T> T unmarshall(MapXNode xnode, Class<T> beanClass) throws SchemaException { if (PolyStringType.class.equals(beanClass)) { PolyString polyString = unmarshalPolyString(xnode); return (T) polyString; // violates the method interface but ... TODO fix it } else if (ProtectedStringType.class.equals(beanClass)) { ProtectedStringType protectedType = new ProtectedStringType(); XNodeProcessorUtil.parseProtectedType(protectedType, xnode, prismContext); return (T) protectedType; } else if (ProtectedByteArrayType.class.equals(beanClass)) { ProtectedByteArrayType protectedType = new ProtectedByteArrayType(); XNodeProcessorUtil.parseProtectedType(protectedType, xnode, prismContext); return (T) protectedType; } else if (SchemaDefinitionType.class.equals(beanClass)) { SchemaDefinitionType schemaDefType = unmarshalSchemaDefinitionType(xnode); return (T) schemaDefType; } else if (prismContext.getSchemaRegistry().determineDefinitionFromClass(beanClass) != null) { return (T) prismContext.getXnodeProcessor().parseObject(xnode).asObjectable(); } else if (XmlAsStringType.class.equals(beanClass)) { // reading a string represented a XML-style content // used e.g. when reading report templates (embedded XML) // A necessary condition: there may be only one map entry. if (xnode.size() > 1) { throw new SchemaException("Map with more than one item cannot be parsed as a string: " + xnode); } else if (xnode.isEmpty()) { return (T) new XmlAsStringType(); } else {// w w w . j av a 2 s .co m Map.Entry<QName, XNode> entry = xnode.entrySet().iterator().next(); DomParser domParser = prismContext.getParserDom(); String value = domParser.serializeToString(entry.getValue(), entry.getKey()); return (T) new XmlAsStringType(value); } } T bean; Set<String> keysToParse; // only these keys will be parsed (null if all) if (SearchFilterType.class.isAssignableFrom(beanClass)) { keysToParse = Collections.singleton("condition"); // TODO fix this BRUTAL HACK - it is here because of c:ConditionalSearchFilterType bean = (T) unmarshalSearchFilterType(xnode, (Class<? extends SearchFilterType>) beanClass); } else { keysToParse = null; try { bean = beanClass.newInstance(); } catch (InstantiationException e) { throw new SystemException("Cannot instantiate bean of type " + beanClass + ": " + e.getMessage(), e); } catch (IllegalAccessException e) { throw new SystemException("Cannot instantiate bean of type " + beanClass + ": " + e.getMessage(), e); } } if (ProtectedDataType.class.isAssignableFrom(beanClass)) { ProtectedDataType protectedDataType = null; if (bean instanceof ProtectedStringType) { protectedDataType = new ProtectedStringType(); } else if (bean instanceof ProtectedByteArrayType) { protectedDataType = new ProtectedByteArrayType(); } else { throw new SchemaException("Unexpected subtype of protected data type: " + bean.getClass()); } XNodeProcessorUtil.parseProtectedType(protectedDataType, xnode, prismContext); return (T) protectedDataType; } for (Entry<QName, XNode> entry : xnode.entrySet()) { QName key = entry.getKey(); if (keysToParse != null && !keysToParse.contains(key.getLocalPart())) { continue; } XNode xsubnode = entry.getValue(); String propName = key.getLocalPart(); Field field = inspector.findPropertyField(beanClass, propName); Method propertyGetter = null; if (field == null) { propertyGetter = inspector.findPropertyGetter(beanClass, propName); } Method elementMethod = null; Object objectFactory = null; if (field == null && propertyGetter == null) { // We have to try to find a more generic field, such as xsd:any or substitution element // check for global element definition first Class objectFactoryClass = inspector.getObjectFactoryClass(beanClass.getPackage()); objectFactory = instantiateObjectFactory(objectFactoryClass); elementMethod = inspector.findElementMethodInObjectFactory(objectFactoryClass, propName); if (elementMethod == null) { // Check for "any" method elementMethod = inspector.findAnyMethod(beanClass); if (elementMethod == null) { String m = "No field " + propName + " in class " + beanClass + " (and no element method in object factory too)"; if (mode == XNodeProcessorEvaluationMode.COMPAT) { LOGGER.warn("{}", m); continue; } else { throw new SchemaException(m); } } unmarshallToAny(bean, elementMethod, key, xsubnode); continue; } field = inspector.lookupSubstitution(beanClass, elementMethod); if (field == null) { // Check for "any" field field = inspector.findAnyField(beanClass); if (field == null) { elementMethod = inspector.findAnyMethod(beanClass); if (elementMethod == null) { String m = "No field " + propName + " in class " + beanClass + " (and no element method in object factory too)"; if (mode == XNodeProcessorEvaluationMode.COMPAT) { LOGGER.warn("{}", m); continue; } else { throw new SchemaException(m); } } unmarshallToAny(bean, elementMethod, key, xsubnode); continue; // throw new SchemaException("No field "+propName+" in class "+beanClass+" (no suitable substitution and no 'any' field)"); } unmarshallToAny(bean, field, key, xsubnode); continue; } } boolean storeAsRawType; if (elementMethod != null) { storeAsRawType = elementMethod.getAnnotation(Raw.class) != null; } else if (propertyGetter != null) { storeAsRawType = propertyGetter.getAnnotation(Raw.class) != null; } else { storeAsRawType = field.getAnnotation(Raw.class) != null; } String fieldName; if (field != null) { fieldName = field.getName(); } else { fieldName = propName; } Method setter = inspector.findSetter(beanClass, fieldName); Method getter = null; boolean wrapInJaxbElement = false; Class<?> paramType = null; if (setter == null) { // No setter. But if the property is multi-value we need to look // for a getter that returns a collection (Collection<Whatever>) getter = inspector.findPropertyGetter(beanClass, fieldName); if (getter == null) { String m = "Cannot find setter or getter for field " + fieldName + " in " + beanClass; if (mode == XNodeProcessorEvaluationMode.COMPAT) { LOGGER.warn("{}", m); continue; } else { throw new SchemaException(m); } } Class<?> getterReturnType = getter.getReturnType(); if (!Collection.class.isAssignableFrom(getterReturnType)) { throw new SchemaException("Cannot find getter for field " + fieldName + " in " + beanClass + " does not return collection, cannot use it to set value"); } Type genericReturnType = getter.getGenericReturnType(); Type typeArgument = getTypeArgument(genericReturnType, "for field " + fieldName + " in " + beanClass + ", cannot determine collection type"); // System.out.println("type argument " + typeArgument); if (typeArgument instanceof Class) { paramType = (Class<?>) typeArgument; } else if (typeArgument instanceof ParameterizedType) { ParameterizedType paramTypeArgument = (ParameterizedType) typeArgument; Type rawTypeArgument = paramTypeArgument.getRawType(); if (rawTypeArgument.equals(JAXBElement.class)) { // This is the case of Collection<JAXBElement<....>> wrapInJaxbElement = true; Type innerTypeArgument = getTypeArgument(typeArgument, "for field " + fieldName + " in " + beanClass + ", cannot determine collection type (inner type argument)"); if (innerTypeArgument instanceof Class) { // This is the case of Collection<JAXBElement<Whatever>> paramType = (Class<?>) innerTypeArgument; } else if (innerTypeArgument instanceof WildcardType) { // This is the case of Collection<JAXBElement<?>> // we need to exctract the specific type from the factory method if (elementMethod == null) { // TODO: TEMPORARY CODE!!!!!!!!!! fix in 3.1 [med] Class objectFactoryClass = inspector.getObjectFactoryClass(beanClass.getPackage()); objectFactory = instantiateObjectFactory(objectFactoryClass); elementMethod = inspector.findElementMethodInObjectFactory(objectFactoryClass, propName); if (elementMethod == null) { throw new IllegalArgumentException( "Wildcard type in JAXBElement field specification and no factory method found for field " + fieldName + " in " + beanClass + ", cannot determine collection type (inner type argument)"); } } Type factoryMethodGenericReturnType = elementMethod.getGenericReturnType(); Type factoryMethodTypeArgument = getTypeArgument(factoryMethodGenericReturnType, "in factory method " + elementMethod + " return type for field " + fieldName + " in " + beanClass + ", cannot determine collection type"); if (factoryMethodTypeArgument instanceof Class) { // This is the case of JAXBElement<Whatever> paramType = (Class<?>) factoryMethodTypeArgument; if (Object.class.equals(paramType) && !storeAsRawType) { throw new IllegalArgumentException("Factory method " + elementMethod + " type argument is Object (and not @Raw) for field " + fieldName + " in " + beanClass + ", property " + propName); } } else { throw new IllegalArgumentException( "Cannot determine factory method return type, got " + factoryMethodTypeArgument + " - for field " + fieldName + " in " + beanClass + ", cannot determine collection type (inner type argument)"); } } else { throw new IllegalArgumentException("Ejha! " + innerTypeArgument + " " + innerTypeArgument.getClass() + " from " + getterReturnType + " from " + fieldName + " in " + propName + " " + beanClass); } } else { // The case of Collection<Whatever<Something>> if (rawTypeArgument instanceof Class) { paramType = (Class<?>) rawTypeArgument; } else { throw new IllegalArgumentException("EH? Eh!? " + typeArgument + " " + typeArgument.getClass() + " from " + getterReturnType + " from " + fieldName + " in " + propName + " " + beanClass); } } } else { throw new IllegalArgumentException( "EH? " + typeArgument + " " + typeArgument.getClass() + " from " + getterReturnType + " from " + fieldName + " in " + propName + " " + beanClass); } } else { Class<?> setterType = setter.getParameterTypes()[0]; if (JAXBElement.class.equals(setterType)) { // TODO some handling for the returned generic parameter types Type[] genericTypes = setter.getGenericParameterTypes(); if (genericTypes.length != 1) { throw new IllegalArgumentException("Too lazy to handle this."); } Type genericType = genericTypes[0]; if (genericType instanceof ParameterizedType) { Type actualType = getTypeArgument(genericType, "add some description"); if (actualType instanceof WildcardType) { if (elementMethod == null) { Class objectFactoryClass = inspector.getObjectFactoryClass(beanClass.getPackage()); objectFactory = instantiateObjectFactory(objectFactoryClass); elementMethod = inspector.findElementMethodInObjectFactory(objectFactoryClass, propName); } // This is the case of Collection<JAXBElement<?>> // we need to exctract the specific type from the factory method if (elementMethod == null) { throw new IllegalArgumentException( "Wildcard type in JAXBElement field specification and no facotry method found for field " + fieldName + " in " + beanClass + ", cannot determine collection type (inner type argument)"); } Type factoryMethodGenericReturnType = elementMethod.getGenericReturnType(); Type factoryMethodTypeArgument = getTypeArgument(factoryMethodGenericReturnType, "in factory method " + elementMethod + " return type for field " + fieldName + " in " + beanClass + ", cannot determine collection type"); if (factoryMethodTypeArgument instanceof Class) { // This is the case of JAXBElement<Whatever> paramType = (Class<?>) factoryMethodTypeArgument; if (Object.class.equals(paramType) && !storeAsRawType) { throw new IllegalArgumentException("Factory method " + elementMethod + " type argument is Object (without @Raw) for field " + fieldName + " in " + beanClass + ", property " + propName); } } else { throw new IllegalArgumentException( "Cannot determine factory method return type, got " + factoryMethodTypeArgument + " - for field " + fieldName + " in " + beanClass + ", cannot determine collection type (inner type argument)"); } } } // Class enclosing = paramType.getEnclosingClass(); // Class clazz = paramType.getClass(); // Class declaring = paramType.getDeclaringClass(); wrapInJaxbElement = true; } else { paramType = setterType; } } if (Element.class.isAssignableFrom(paramType)) { // DOM! throw new IllegalArgumentException("DOM not supported in field " + fieldName + " in " + beanClass); } //check for subclasses??? if (!storeAsRawType && xsubnode.getTypeQName() != null) { Class explicitParamType = getSchemaRegistry().determineCompileTimeClass(xsubnode.getTypeQName()); if (explicitParamType == null) { explicitParamType = XsdTypeMapper.toJavaTypeIfKnown(xsubnode.getTypeQName()); } if (explicitParamType != null) { paramType = explicitParamType; } } if (!(xsubnode instanceof ListXNode) && Object.class.equals(paramType) && !storeAsRawType) { throw new IllegalArgumentException( "Object property (without @Raw) not supported in field " + fieldName + " in " + beanClass); } String paramNamespace = inspector.determineNamespace(paramType); boolean problem = false; Object propValue = null; Collection<Object> propValues = null; if (xsubnode instanceof ListXNode) { ListXNode xlist = (ListXNode) xsubnode; if (setter != null) { try { propValue = convertSinglePropValue(xsubnode, fieldName, paramType, storeAsRawType, beanClass, paramNamespace); } catch (SchemaException e) { problem = processSchemaException(e, xsubnode); } } else { // No setter, we have to use collection getter propValues = new ArrayList<>(xlist.size()); for (XNode xsubsubnode : xlist) { try { propValues.add(convertSinglePropValue(xsubsubnode, fieldName, paramType, storeAsRawType, beanClass, paramNamespace)); } catch (SchemaException e) { problem = processSchemaException(e, xsubsubnode); } } } } else { try { propValue = convertSinglePropValue(xsubnode, fieldName, paramType, storeAsRawType, beanClass, paramNamespace); } catch (SchemaException e) { problem = processSchemaException(e, xsubnode); } } if (setter != null) { try { setter.invoke(bean, prepareValueToBeStored(propValue, wrapInJaxbElement, objectFactory, elementMethod, propName, beanClass)); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new SystemException("Cannot invoke setter " + setter + " on bean of type " + beanClass + ": " + e.getMessage(), e); } } else if (getter != null) { Object getterReturn; Collection<Object> col; try { getterReturn = getter.invoke(bean); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new SystemException("Cannot invoke getter " + getter + " on bean of type " + beanClass + ": " + e.getMessage(), e); } try { col = (Collection<Object>) getterReturn; } catch (ClassCastException e) { throw new SystemException("Getter " + getter + " on bean of type " + beanClass + " returned " + getterReturn + " instead of collection"); } if (propValue != null) { col.add(prepareValueToBeStored(propValue, wrapInJaxbElement, objectFactory, elementMethod, propName, beanClass)); } else if (propValues != null) { for (Object propVal : propValues) { col.add(prepareValueToBeStored(propVal, wrapInJaxbElement, objectFactory, elementMethod, propName, beanClass)); } } else if (!problem) { throw new IllegalStateException("Strange. Multival property " + propName + " in " + beanClass + " produced null values list, parsed from " + xnode); } checkJaxbElementConsistence(col); } else { throw new IllegalStateException("Uh? No setter nor getter."); } } if (prismContext != null && bean instanceof Revivable) { ((Revivable) bean).revive(prismContext); } return bean; }
From source file:org.dasein.persist.PersistentCache.java
protected @Nonnull T toTargetFromMap(@Nonnull String dataStoreVersion, @Nonnull Map<String, Object> dataStoreState) throws PersistenceException { try {/* ww w. j a v a2 s. c om*/ while (!dataStoreVersion.equals(schemaVersion)) { SchemaMapper mapper = getSchemaMapper(dataStoreVersion); if (mapper == null) { break; } dataStoreState = mapper.map(dataStoreVersion, dataStoreState); dataStoreVersion = mapper.getTargetVersion(); } Class<T> targetClass = getTarget(); Class<? extends Object> t = targetClass; T item = targetClass.newInstance(); while (!t.getName().equals(Object.class.getName())) { for (Field field : t.getDeclaredFields()) { int modifiers = field.getModifiers(); if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) { Object value = dataStoreState.get(field.getName()); set(item, field, value); } } t = t.getSuperclass(); } return item; } catch (InstantiationException e) { throw new PersistenceException(e); } catch (IllegalAccessException e) { throw new PersistenceException(e); } catch (RuntimeException e) { logger.error(e.getMessage(), e); throw new PersistenceException(e); } catch (Error e) { logger.error(e.getMessage(), e); throw new PersistenceException(e.getMessage()); } }
From source file:com.tongbanjie.tarzan.rpc.protocol.RpcCommand.java
public CustomHeader decodeCustomHeader(Class<? extends CustomHeader> classHeader) throws RpcCommandException { CustomHeader objectHeader;// w w w . jav a 2s . c om try { objectHeader = classHeader.newInstance(); } catch (InstantiationException e) { return null; } catch (IllegalAccessException e) { return null; } if (MapUtils.isNotEmpty(this.customFields)) { Field[] fields = getClazzFields(classHeader); for (Field field : fields) { String fieldName = field.getName(); Class clazz = field.getType(); if (Modifier.isStatic(field.getModifiers()) || fieldName.startsWith("this")) { continue; } String value = this.customFields.get(fieldName); if (value == null) { continue; } field.setAccessible(true); Object valueParsed; if (clazz.isEnum()) { valueParsed = Enum.valueOf(clazz, value); } else { String type = getCanonicalName(clazz); try { valueParsed = ClassUtils.parseSimpleValue(type, value); } catch (ParseException e) { throw new RpcCommandException("Encode the header failed, the custom field <" + fieldName + "> type <" + getCanonicalName(clazz) + "> parse error:" + e.getMessage()); } } if (valueParsed == null) { throw new RpcCommandException("Encode the header failed, the custom field <" + fieldName + "> type <" + getCanonicalName(clazz) + "> is not supported."); } try { field.set(objectHeader, valueParsed); } catch (IllegalAccessException e) { throw new RpcCommandException( "Encode the header failed, set the value of field < " + fieldName + "> error.", e); } } objectHeader.checkFields(); } return objectHeader; }
From source file:org.vulpe.controller.struts.proxy.VulpeActionInvocation.java
protected void createAction(Map<String, Object> contextMap) { // load action String timerKey = "actionCreate: " + proxy.getActionName(); try {//from ww w.j ava2s. c o m UtilTimerStack.push(timerKey); action = objectFactory.buildAction(proxy.getActionName(), proxy.getNamespace(), proxy.getConfig(), contextMap); } catch (InstantiationException e) { throw new XWorkException("Unable to intantiate Action!", e, proxy.getConfig()); } catch (IllegalAccessException e) { throw new XWorkException("Illegal access to constructor, is it public?", e, proxy.getConfig()); } catch (Exception e) { String gripe = ""; if (proxy == null) { gripe = "Whoa! No ActionProxy instance found in current ActionInvocation. This is bad ... very bad"; } else if (proxy.getConfig() == null) { gripe = "Sheesh. Where'd that ActionProxy get to? I can't find it in the current ActionInvocation!?"; } else if (proxy.getConfig().getClassName() == null) { gripe = "No Action defined for '" + proxy.getActionName() + "' in namespace '" + proxy.getNamespace() + "'"; } else { gripe = "Unable to instantiate Action, " + proxy.getConfig().getClassName() + ", defined for '" + proxy.getActionName() + "' in namespace '" + proxy.getNamespace() + "'"; } gripe += (((" -- " + e.getMessage()) != null) ? e.getMessage() : " [no message in exception]"); throw new XWorkException(gripe, e, proxy.getConfig()); } finally { UtilTimerStack.pop(timerKey); } if (actionEventListener != null) { action = actionEventListener.prepare(action, stack); } }