List of usage examples for java.lang Class getModifiers
@HotSpotIntrinsicCandidate public native int getModifiers();
From source file:adalid.core.Operation.java
void initialiseFields(Class<?> clazz) { Class<?> c;/*from w w w .j a v a 2 s . c om*/ int d, r; String name; Class<?> type; int modifiers; boolean restricted; Object o; int depth = depth(); int round = round(); Class<?>[] classes = new Class<?>[] { Parameter.class, Expression.class }; Class<?> dac = getClass(); Class<?> top = Operation.class; int i = ArrayUtils.indexOf(classes, clazz); if (i != ArrayUtils.INDEX_NOT_FOUND) { c = classes[i]; for (Field field : XS1.getFields(dac, top)) { field.setAccessible(true); logger.trace(field); name = field.getName(); type = field.getType(); if (!c.isAssignableFrom(type)) { continue; } modifiers = type.getModifiers(); if (type.isInterface() && Expression.class.isAssignableFrom(type)) { restricted = false; } else { restricted = Modifier.isAbstract(modifiers); } restricted = restricted || !Modifier.isPublic(modifiers); if (restricted) { continue; } modifiers = field.getModifiers(); restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); if (restricted) { continue; } String errmsg = "failed to create a new instance of field \"" + field + "\" at " + this; try { o = field.get(this); if (o == null) { logger.debug(message(type, name, o, depth, round)); o = XS1.initialiseField(this, field); if (o == null) { logger.debug(message(type, name, o, depth, round)); // throw new RuntimeException(message(type, name, o, depth, round)); } else { logger.debug(message(type, name, o, depth, round)); field.set(this, o); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new InstantiationRuntimeException(errmsg, ex); } } } }
From source file:com.github.dozermapper.core.MappingProcessor.java
private Object mapArrayToArray(Object srcObj, Object srcCollectionValue, FieldMap fieldMap, Object destObj) { Class destEntryType = fieldMap.getDestFieldType(destObj.getClass()).getComponentType(); Class srcEntryType = srcCollectionValue.getClass().getComponentType(); int size = Array.getLength(srcCollectionValue); CopyByReferenceContainer copyByReferences = globalConfiguration.getCopyByReferences(); boolean isPrimitiveArray = CollectionUtils.isPrimitiveArray(srcCollectionValue.getClass()); boolean isFinal = Modifier.isFinal(srcEntryType.getModifiers()); boolean isCopyByReference = copyByReferences.contains(srcEntryType); if (destEntryType.isAssignableFrom(srcEntryType) && isFinal && (isPrimitiveArray || isCopyByReference)) { return addArrayContentCopy(fieldMap, size, srcCollectionValue, destObj, destEntryType); } else if (isPrimitiveArray) { return addToPrimitiveArray(srcObj, fieldMap, size, srcCollectionValue, destObj, destEntryType); } else {//from w w w. j a v a2s .co m List<?> list = Arrays.asList((Object[]) srcCollectionValue); List<?> returnList; if (!destEntryType.getName().equals(BASE_CLASS)) { returnList = addOrUpdateToList(srcObj, fieldMap, list, destObj, destEntryType); } else { returnList = addOrUpdateToList(srcObj, fieldMap, list, destObj, null); } return CollectionUtils.convertListToArray(returnList, destEntryType); } }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadKnowledgeImporters() { String ipack = this.getClass().getPackage().getName() + ".importers"; for (Class<?> cls : MiscUtilities.findSubclasses(IKnowledgeImporter.class, ipack, getClassLoader())) { /*//from ww w . j a v a2s. com * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof org.integratedmodelling.thinklab.interfaces.annotations.KnowledgeLoader) { String fmt = ((org.integratedmodelling.thinklab.interfaces.annotations.KnowledgeLoader) annotation) .format(); KBoxManager.get().registerImporterClass(fmt, cls); break; } } } }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadTransformations() throws ThinklabException { String ipack = this.getClass().getPackage().getName() + ".transformations"; for (Class<?> cls : MiscUtilities.findSubclasses(ITransformation.class, ipack, getClassLoader())) { /*// w w w . ja v a2s . c o m * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof DataTransformation) { String name = ((DataTransformation) annotation).id(); try { TransformationFactory.get().registerTransformation(name, (ITransformation) cls.newInstance()); } catch (Exception e) { throw new ThinklabValidationException(e); } break; } } } }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadListingProviders() throws ThinklabException { String ipack = this.getClass().getPackage().getName() + ".commands"; for (Class<?> cls : MiscUtilities.findSubclasses(IListingProvider.class, ipack, getClassLoader())) { /*/*from w w w . ja v a2s . c o m*/ * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof ListingProvider) { String name = ((ListingProvider) annotation).label(); String sname = ((ListingProvider) annotation).itemlabel(); try { CommandManager.get().registerListingProvider(name, sname, (IListingProvider) cls.newInstance()); } catch (Exception e) { throw new ThinklabValidationException(e); } break; } } } }
From source file:org.structr.module.JarConfigurationProvider.java
@Override public Class getRelationshipEntityClass(final String name) { Class relationClass = AbstractRelationship.class; if ((name != null) && (name.length() > 0)) { synchronized (SchemaService.class) { relationClass = relationshipEntityClassCache.get(name); if (relationClass == null) { for (String possiblePath : relationshipPackages) { if (possiblePath != null) { try { Class nodeClass = Class.forName(possiblePath + "." + name); if (!Modifier.isAbstract(nodeClass.getModifiers())) { relationshipEntityClassCache.put(name, nodeClass); // first match wins return nodeClass; }/* w w w. jav a 2 s. c o m*/ } catch (ClassNotFoundException ex) { // ignore } } } } } } return relationClass; }
From source file:org.structr.module.JarConfigurationProvider.java
@Override public Class getNodeEntityClass(final String simpleName) { Class nodeEntityClass = GenericNode.class; if ((simpleName != null) && (!simpleName.isEmpty())) { synchronized (SchemaService.class) { nodeEntityClass = nodeEntityClassCache.get(simpleName); if (nodeEntityClass == null) { for (String possiblePath : nodeEntityPackages) { if (possiblePath != null) { try { Class nodeClass = Class.forName(possiblePath + "." + simpleName); if (!Modifier.isAbstract(nodeClass.getModifiers())) { nodeEntityClassCache.put(simpleName, nodeClass); nodeEntityClass = nodeClass; // first match wins break; }/*from w w w .ja v a 2 s.co m*/ } catch (ClassNotFoundException ex) { // ignore } } } } } } return nodeEntityClass; }
From source file:com.github.helenusdriver.driver.impl.ClassInfoImpl.java
/** * Instantiates a new <code>ClassInfo</code> object. * * @author paouelle/* www . j ava 2 s .com*/ * * @param mgr the non-<code>null</code> statement manager * @param clazz the class of POJO for which to get a class info object for * @throws NullPointerException if <code>clazz</code> is <code>null</code> * @throws IllegalArgumentException if <code>clazz</code> doesn't represent * a valid POJO class */ ClassInfoImpl(StatementManagerImpl mgr, Class<T> clazz) { this(mgr, clazz, Entity.class); org.apache.commons.lang3.Validate.isTrue(!Modifier.isAbstract(clazz.getModifiers()), "entity class '%s', cannot be abstract", clazz.getSimpleName()); }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadPersistentClasses() throws ThinklabPluginException { String ipack = this.getClass().getPackage().getName() + ".implementations"; for (Class<?> cls : MiscUtilities.findSubclasses(IPersistentObject.class, ipack, getClassLoader())) { String ext = null;/*from w w w. j a v a 2 s.c om*/ /* * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; /* * lookup implemented concept */ for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof PersistentObject) { ext = ((PersistentObject) annotation).extension(); if (ext.equals("__NOEXT__")) ext = null; break; } } PersistenceManager.get().registerSerializableClass(cls, ext); } }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadCommandHandlers() throws ThinklabException { String ipack = this.getClass().getPackage().getName() + ".commands"; for (Class<?> cls : MiscUtilities.findSubclasses(ICommandHandler.class, ipack, getClassLoader())) { /*/*from w w w . j a v a 2 s . com*/ * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; /* * lookup implemented concept */ for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof ThinklabCommand) { String name = ((ThinklabCommand) annotation).name(); String description = ((ThinklabCommand) annotation).description(); CommandDeclaration declaration = new CommandDeclaration(name, description); String retType = ((ThinklabCommand) annotation).returnType(); if (!retType.equals("")) declaration.setReturnType(KnowledgeManager.get().requireConcept(retType)); String[] aNames = ((ThinklabCommand) annotation).argumentNames().split(","); String[] aTypes = ((ThinklabCommand) annotation).argumentTypes().split(","); String[] aDesc = ((ThinklabCommand) annotation).argumentDescriptions().split(","); for (int i = 0; i < aNames.length; i++) { if (!aNames[i].isEmpty()) declaration.addMandatoryArgument(aNames[i], aDesc[i], aTypes[i]); } String[] oaNames = ((ThinklabCommand) annotation).optionalArgumentNames().split(","); String[] oaTypes = ((ThinklabCommand) annotation).optionalArgumentTypes().split(","); String[] oaDesc = ((ThinklabCommand) annotation).optionalArgumentDescriptions().split(","); String[] oaDefs = ((ThinklabCommand) annotation).optionalArgumentDefaultValues().split(","); for (int i = 0; i < oaNames.length; i++) { if (!oaNames[i].isEmpty()) declaration.addOptionalArgument(oaNames[i], oaDesc[i], oaTypes[i], oaDefs[i]); } String[] oNames = ((ThinklabCommand) annotation).optionNames().split(","); String[] olNames = ((ThinklabCommand) annotation).optionLongNames().split(","); String[] oaLabel = ((ThinklabCommand) annotation).optionArgumentLabels().split(","); String[] oTypes = ((ThinklabCommand) annotation).optionTypes().split(","); String[] oDesc = ((ThinklabCommand) annotation).optionDescriptions().split(","); for (int i = 0; i < oNames.length; i++) { if (!oNames[i].isEmpty()) declaration.addOption(oNames[i], olNames[i], (oaLabel[i].equals("") ? null : oaLabel[i]), oDesc[i], oTypes[i]); } try { CommandManager.get().registerCommand(declaration, (ICommandHandler) cls.newInstance()); } catch (Exception e) { throw new ThinklabValidationException(e); } break; } } } }