List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:org.metaworks.dwr.MetaworksMapConverter.java
@SuppressWarnings("unchecked") public Object convertInbound(Class<?> paramType, InboundVariable data) throws ConversionException { if (data.isNull()) { return null; }/*w w w . j a v a 2 s . c o m*/ String value = data.getValue(); // If the text is null then the whole bean is null if (value.trim().equals(ProtocolConstants.INBOUND_NULL)) { return null; } if (!value.startsWith(ProtocolConstants.INBOUND_MAP_START) || !value.endsWith(ProtocolConstants.INBOUND_MAP_END)) { log.warn("Expected object while converting data for " + paramType.getName() + " in " + data.getContext().getCurrentProperty() + ". Passed: " + value); throw new ConversionException(paramType, "Data conversion error. See logs for more details."); } value = value.substring(1, value.length() - 1); try { // Maybe we ought to check that the paramType isn't expecting a more // distinct type of Map and attempt to create that? Map<Object, Object> map; // If paramType is concrete then just use whatever we've got. if (!paramType.isInterface() && !Modifier.isAbstract(paramType.getModifiers())) { // If there is a problem creating the type then we have no way // of completing this - they asked for a specific type and we // can't create that type. I don't know of a way of finding // subclasses that might be instaniable so we accept failure. map = (Map<Object, Object>) paramType.newInstance(); } else { map = new HashMap<Object, Object>(); } // Get the extra type info Property parent = data.getContext().getCurrentProperty(); Property keyProp = parent.createChild(0); keyProp = converterManager.checkOverride(keyProp); Class<?> keyType = keyProp.getPropertyType(); Property valProp = parent.createChild(1); valProp = converterManager.checkOverride(valProp); Class<?> valType = valProp.getPropertyType(); // We should put the new object into the working map in case it // is referenced later nested down in the conversion process. data.getContext().addConverted(data, paramType, map); InboundContext incx = data.getContext(); // Loop through the property declarations StringTokenizer st = new StringTokenizer(value, ","); int size = st.countTokens(); for (int i = 0; i < size; i++) { String token = st.nextToken(); if (token.trim().length() == 0) { continue; } int colonpos = token.indexOf(ProtocolConstants.INBOUND_MAP_ENTRY); if (colonpos == -1) { throw new ConversionException(paramType, "Missing " + ProtocolConstants.INBOUND_MAP_ENTRY + " in object description: {1}" + token); } // Convert the value part of the token by splitting it into the // type and value (as passed in by Javascript) String valStr = token.substring(colonpos + 1).trim(); String[] splitIv = ConvertUtil.splitInbound(valStr); String splitIvValue = splitIv[ConvertUtil.INBOUND_INDEX_VALUE]; String splitIvType = splitIv[ConvertUtil.INBOUND_INDEX_TYPE]; InboundVariable valIv = new InboundVariable(incx, null, splitIvType, splitIvValue); valIv.dereference(); /////// added start /////// Class orgValType = valType; try { Map<String, String> tokens = extractInboundTokens(valIv.getValue()); String refName = tokens.get("__className"); if (refName != null) { refName = refName.split(":")[1]; String className = data.getContext().getInboundVariable(refName).getFormField().getString(); try { valType = Thread.currentThread().getContextClassLoader().loadClass(className); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } /////// added end /////// Object val = converterManager.convertInbound(valType, valIv, valProp); ////// added start//// valType = orgValType; ////// added end ///// // Keys (unlike values) do not have type info passed with them // Could we have recursive key? - I don't think so because keys // must be strings in Javascript String keyStr = token.substring(0, colonpos).trim(); //String[] keySplit = LocalUtil.splitInbound(keyStr); //InboundVariable keyIv = new InboundVariable(incx, splitIv[LocalUtil.INBOUND_INDEX_TYPE], splitIv[LocalUtil.INBOUND_INDEX_VALUE]); InboundVariable keyIv = new InboundVariable(incx, null, ProtocolConstants.TYPE_STRING, keyStr); keyIv.dereference(); Object key = converterManager.convertInbound(keyType, keyIv, keyProp); map.put(key, val); } return map; } catch (ConversionException ex) { throw ex; } catch (Exception ex) { throw new ConversionException(paramType, ex); } }
From source file:it.uniroma2.sag.kelp.data.representation.structure.StructureElementFactory.java
/** * Retrieves all the implementations of the class * <code>StructureElement</code> included in the current project * /*from w w w .j a v a2s . co m*/ * @return a Map of pairs StructureElement type identifier - * StructureElement class */ private Map<String, Class<? extends StructureElement>> discoverAllStructureElementImplementations() throws InstantiationException, IllegalAccessException { Reflections reflections = new Reflections("it"); Set<Class<? extends StructureElement>> classes = reflections.getSubTypesOf(StructureElement.class); HashMap<String, Class<? extends StructureElement>> implementatios = new HashMap<String, Class<? extends StructureElement>>(); for (Class<? extends StructureElement> implementation : classes) { if (Modifier.isAbstract(implementation.getModifiers())) { continue; } String structureElementAbbreviation = getStructureElementIdentifier(implementation); implementatios.put(structureElementAbbreviation, implementation); } return implementatios; }
From source file:ca.uhn.fhir.rest.method.BaseOutcomeReturningMethodBindingWithResourceParam.java
@SuppressWarnings("unchecked") public BaseOutcomeReturningMethodBindingWithResourceParam(Method theMethod, FhirContext theContext, Class<?> theMethodAnnotation, Object theProvider) { super(theMethod, theContext, theMethodAnnotation, theProvider); ResourceParameter resourceParameter = null; int index = 0; for (IParameter next : getParameters()) { if (next instanceof ResourceParameter) { resourceParameter = (ResourceParameter) next; if (resourceParameter.getMode() != ResourceParameter.Mode.RESOURCE) { continue; }/* www. j a v a 2 s .c om*/ if (myResourceType != null) { throw new ConfigurationException( "Method " + theMethod.getName() + " on type " + theMethod.getDeclaringClass() + " has more than one @ResourceParam. Only one is allowed."); } myResourceType = resourceParameter.getResourceType(); myResourceParameterIndex = index; } else if (next instanceof ConditionalParamBinder) { myConditionalUrlIndex = index; } index++; } if ((myResourceType == null || Modifier.isAbstract(myResourceType.getModifiers())) && (theProvider instanceof IResourceProvider)) { myResourceType = ((IResourceProvider) theProvider).getResourceType(); } if (myResourceType == null) { throw new ConfigurationException("Unable to determine resource type for method: " + theMethod); } myResourceName = theContext.getResourceDefinition(myResourceType).getName(); myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); if (myIdParamIndex != null) { myIdParamType = (Class<? extends IIdType>) theMethod.getParameterTypes()[myIdParamIndex]; } if (resourceParameter == null) { throw new ConfigurationException("Method " + theMethod.getName() + " in type " + theMethod.getDeclaringClass().getCanonicalName() + " does not have a resource parameter annotated with @" + ResourceParam.class.getSimpleName()); } }
From source file:org.force66.beantester.valuegens.ValueGeneratorFactory.java
public ValueGenerator<?> forClass(Class<?> targetClass) { Validate.notNull(targetClass, "Null class not allowed"); ValueGenerator<?> generator = registeredGeneratorMap.get(targetClass); if (generator == null) { for (ValueGenerator<?> gen : STOCK_GENERATORS) { if (gen.canGenerate(targetClass)) { registeredGeneratorMap.put(targetClass, gen); return gen; }/* www.j a v a2 s . c o m*/ } } else { return generator; } if (targetClass.isInterface()) { InterfaceValueGenerator gen = new InterfaceValueGenerator(targetClass); this.registerGenerator(targetClass, gen); return gen; } else if (Modifier.isAbstract(targetClass.getModifiers())) { return null; // generator not possible on abstract classes } else if (targetClass.isEnum()) { return registerGenericGenerator(targetClass, targetClass.getEnumConstants()); } else if (targetClass.isArray()) { ArrayValueGenerator gen = new ArrayValueGenerator(targetClass, this); this.registerGenerator(targetClass, gen); return gen; } else if (Class.class.equals(targetClass)) { return registerGenericGenerator(targetClass, new Object[] { Object.class }); } else { return registerGenericGenerator(targetClass, new Object[] { InstantiationUtils.safeNewInstance(this, targetClass) }); } }
From source file:org.impalaframework.command.basic.ModuleDefinitionAwareClassFilter.java
public boolean accept(File pathname) { if (!super.accept(pathname)) { return false; }/* w w w. j a va 2 s. c om*/ if (pathname.isDirectory()) { return true; } if (rootCanonicalPath == null) { throw new ConfigurationException("root canonical path not set"); } String canonicalPath = null; try { canonicalPath = pathname.getCanonicalPath(); } catch (IOException e) { logger.error("Could not read canonical path for " + pathname, e); return false; } String relativePath = canonicalPath.substring(rootCanonicalPath.length()); relativePath = relativePath.replace(File.separator, "."); relativePath = relativePath.replace("/", "."); relativePath = relativePath.substring(0, relativePath.length() - ".class".length()); if (relativePath.startsWith(".")) { relativePath = relativePath.substring(1); } //create a classloader pointing to the supplied root file location ModuleClassLoader classLoader = new ModuleClassLoader(new File[] { this.rootFile }); Class<?> forName = null; try { forName = Class.forName(relativePath, false, classLoader); if (forName.isInterface()) { return false; } int mods = forName.getModifiers(); if (Modifier.isAbstract(mods)) { return false; } if (ModuleDefinitionSource.class.isAssignableFrom(forName)) { return true; } } catch (ClassNotFoundException e) { logger.error("Unable to resolve class associated with path " + pathname, e); } return false; }
From source file:alluxio.shell.AlluxioShell.java
/** * Uses reflection to get all the {@link ShellCommand} classes and store them in a map. *//*from w ww .j av a 2 s.com*/ private void loadCommands() { String pkgName = ShellCommand.class.getPackage().getName(); Reflections reflections = new Reflections(pkgName); for (Class<? extends ShellCommand> cls : reflections.getSubTypesOf(ShellCommand.class)) { // Only instantiate a concrete class if (!Modifier.isAbstract(cls.getModifiers())) { ShellCommand cmd; try { cmd = CommonUtils.createNewClassInstance(cls, new Class[] { Configuration.class, FileSystem.class }, new Object[] { mConfiguration, mFileSystem }); } catch (Exception e) { throw Throwables.propagate(e); } mCommands.put(cmd.getCommandName(), cmd); } } }
From source file:org.pentaho.reporting.engine.classic.core.metadata.ExpressionRegistry.java
public void registerExpression(final ExpressionMetaData metaData) { if (metaData == null) { throw new NullPointerException(); }//w w w .j a va2 s . c om final Class type = metaData.getExpressionType(); final int modifiers = type.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { throw new IllegalArgumentException("Expression-Implementation cannot be abstract or an interface."); } this.backend.put(type.getName(), metaData); }
From source file:org.apache.asterix.om.typecomputer.TypeComputerTest.java
@Test public void test() throws Exception { // Several exceptional type computers. Set<String> exceptionalTypeComputers = new HashSet<>(); exceptionalTypeComputers.add("InjectFailureTypeComputer"); exceptionalTypeComputers.add("RecordAddFieldsTypeComputer"); exceptionalTypeComputers.add("OpenRecordConstructorResultType"); exceptionalTypeComputers.add("RecordRemoveFieldsTypeComputer"); exceptionalTypeComputers.add("ClosedRecordConstructorResultType"); exceptionalTypeComputers.add("LocalAvgTypeComputer"); exceptionalTypeComputers.add("BooleanOnlyTypeComputer"); exceptionalTypeComputers.add("AMissingTypeComputer"); exceptionalTypeComputers.add("NullableDoubleTypeComputer"); exceptionalTypeComputers.add("RecordMergeTypeComputer"); exceptionalTypeComputers.add("BooleanOrMissingTypeComputer"); // Tests all usual type computers. Reflections reflections = new Reflections("org.apache.asterix.om.typecomputer", new SubTypesScanner(false)); Set<Class<? extends IResultTypeComputer>> classes = reflections.getSubTypesOf(IResultTypeComputer.class); for (Class<? extends IResultTypeComputer> c : classes) { if (exceptionalTypeComputers.contains(c.getSimpleName()) || Modifier.isAbstract(c.getModifiers())) { continue; }/*from w ww . j a va 2 s . c o m*/ System.out.println("Test type computer: " + c.getName()); Assert.assertTrue(testTypeComputer(c)); } }
From source file:io.konik.utils.RandomInvoiceGenerator.java
public Object populteData(Class<?> root, String name) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { Object rootObj;/*ww w .j a va2 s.c o m*/ if (isLeafType(root)) {//final type return generatePrimitveValue(root, name); } rootObj = createNewInstance(root); // get method and populate each of them Method[] methods = root.getMethods(); for (Method method : methods) { int methodModifiers = method.getModifiers(); Class<?> methodParameter = null; if (Modifier.isAbstract(methodModifiers) || method.isSynthetic()) continue; if (method.getName().startsWith("add")) { methodParameter = method.getParameterTypes()[0]; if (methodParameter != null && !methodParameter.isArray() && (methodParameter.isInterface() || Modifier.isAbstract(methodParameter.getModifiers()))) { continue; } } //getter else if (method.getName().startsWith("get") && !Collection.class.isAssignableFrom(method.getReturnType()) && !method.getName().equals("getClass") && !Modifier.isAbstract(methodModifiers)) { methodParameter = method.getReturnType(); } else { continue;// next on setter } if (methodParameter == null || methodParameter.isInterface()) { continue; } Object popultedData = populteData(methodParameter, method.getName()); setValue(rootObj, method, popultedData); } return rootObj; }
From source file:main.server.DemoPageProvider.java
public DemoPageProvider(ServletContext sc) { pageDir = new File(System.getProperty("user.dir", ""), "war/WEB-INF/pages"); if (!pageDir.isDirectory()) { pageDir = new File(sc.getRealPath("WEB-INF/pages")); useSession = true;/*from w w w . j av a 2 s .co m*/ log.info("Saving pages to session: " + pageDir); } else { log.info("Loading and saving pages from " + pageDir); } // discover our classes (in a real app they would be Spring beans or // something similar) ClassFinder cf = new ClassFinder(sc, "main"); // find all PortletFactory's and alias them so fully qualified class // names don't end up in the XML for (Class cls : cf.findClasses("$Factory", PortletFactory.class)) { log.info("Portlet factory: " + cls.getName()); xmlIO.alias(cls); } // create an instance of each DataProvider for (Class cls : cf.findClasses("DataProvider", WidgetDataProvider.class)) { int mod = cls.getModifiers(); if (!Modifier.isAbstract(mod) && !Modifier.isInterface(mod)) { log.info("Data provider: " + cls.getName()); try { add((WidgetDataProvider) cls.newInstance()); } catch (Exception e) { log.error(e, e); } } } }