/** * Get the definition class. * @param project the current project. * @return the type of the definition. */ @Override public Class<?> getTypeClass(Project project) { return parent.getTypeClass(project); }
/** * Get the exposed class for this * definition. This will be a proxy class * (adapted class) if there is an adapter * class and the definition class is not * assignable from the assignable class. * @param project the current project. * @return the exposed class - may return null if unable to load the class */ public Class<?> getExposedClass(Project project) { if (adaptToClass != null) { Class<?> z = getTypeClass(project); if (z == null || adaptToClass.isAssignableFrom(z)) { return z; } } return (adapterClass == null) ? getTypeClass(project) : adapterClass; }
/** * Check if definition is a valid definition--it may be a * definition of an optional task that does not exist. * @param def the definition to test. * @return true if exposed type of definition is present. */ private boolean validDefinition(AntTypeDefinition def) { return !(def.getTypeClass(project) == null || def.getExposedClass(project) == null); }
/** * Equality method for this definition (assumes the names are the same). * * @param other another definition. * @param project the project the definition. * @return true if the definitions are the same. */ public boolean sameDefinition(AntTypeDefinition other, Project project) { return (other != null && other.getClass() == getClass() && other.getTypeClass(project).equals(getTypeClass(project)) && other.getExposedClass(project).equals(getExposedClass(project)) && other.restrict == restrict && other.adapterClass == adapterClass && other.adaptToClass == adaptToClass); }
/** * Returns the current type definition hashtable. The returned hashtable is * "live" and so should not be modified. * * @return a map of from type name to implementing class * (String to Class). */ public Hashtable<String, Class<?>> getDataTypeDefinitions() { synchronized (typeClassDefinitions) { synchronized (antTypeTable) { if (rebuildTypeClassDefinitions) { typeClassDefinitions.clear(); antTypeTable.entrySet().stream() .filter(e -> e.getValue().getExposedClass(project) != null && !Task.class.isAssignableFrom(e.getValue().getExposedClass(project))) .forEach(e -> typeClassDefinitions.put(e.getKey(), e.getValue().getTypeClass(project))); rebuildTypeClassDefinitions = false; } } } return typeClassDefinitions; }
/** * Returns the current task definition hashtable. The returned hashtable is * "live" and so should not be modified. Also, the returned table may be * modified asynchronously. * * @return a map of from task name to implementing class * (String to Class). */ public Hashtable<String, Class<?>> getTaskDefinitions() { synchronized (taskClassDefinitions) { synchronized (antTypeTable) { if (rebuildTaskClassDefinitions) { taskClassDefinitions.clear(); antTypeTable.entrySet().stream() .filter(e -> e.getValue().getExposedClass(project) != null && Task.class.isAssignableFrom(e.getValue().getExposedClass(project))) .forEach(e -> taskClassDefinitions.put(e.getKey(), e.getValue().getTypeClass(project))); rebuildTaskClassDefinitions = false; } } } return taskClassDefinitions; }
/** * Create a component object based on * its definition. * @return the component as an <code>Object</code>. */ private Object icreate(Project project) { Class<?> c = getTypeClass(project); if (c == null) { return null; } Object o = createAndSet(project, c); if (adapterClass == null || (adaptToClass != null && adaptToClass.isAssignableFrom(o.getClass()))) { return o; } TypeAdapter adapterObject = (TypeAdapter) createAndSet( project, adapterClass); adapterObject.setProxy(o); return adapterObject; }
/** * Checks if the attributes are correct. * <ul> * <li>if the class can be created.</li> * <li>if an adapter class can be created</li> * <li>if the type is assignable from adapter</li> * <li>if the type can be used with the adapter class</li> * </ul> * @param project the current project. */ public void checkClass(Project project) { if (clazz == null) { clazz = getTypeClass(project); if (clazz == null) { throw new BuildException( "Unable to create class for " + getName()); } } // check adapter if (adapterClass != null && (adaptToClass == null || !adaptToClass.isAssignableFrom(clazz))) { TypeAdapter adapter = (TypeAdapter) createAndSet( project, adapterClass); adapter.checkProxyClass(clazz); } }
private MethodAndObject createRestricted( final ComponentHelper helper, final String elementName, final List<Method> addTypeMethods) { final Project project = helper.getProject(); final AntTypeDefinition restrictedDefinition = findRestrictedDefinition(helper, elementName, addTypeMethods); if (restrictedDefinition == null) { return null; } final Method addMethod = findMatchingMethod( restrictedDefinition.getExposedClass(project), addTypeMethods); if (addMethod == null) { throw new BuildException("Ant Internal Error - contract mismatch for " + elementName); } final Object addedObject = restrictedDefinition.create(project); if (addedObject == null) { throw new BuildException( "Failed to create object " + elementName + " of type " + restrictedDefinition.getTypeClass(project)); } return new MethodAndObject(addMethod, addedObject); }