You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

IntrospectionHelper.java 67 kB

PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
PR: 19897 Submitted by: Peter Reilly This patch adds the add(Type) to the introspection rules and updates ConditionBase, FilterChain, Path, SelectorBase and TokenFilter to use the new introspection rule. ========================================= = Changed Files ========================================= src/main/org/apache/tools/ant/ProjectHelper.java add two methods used by introspection - getComponentClass and createComponent src/main/org/apache/tools/ant/IntrospectionHelper.java implement addTypeMethods add(Type) src/main/org/apache/tools/ant/filters/TokenFilter.java get TokenFilter to use add(Type) instead of dynamicconfigurator make all nested classes ProjectComponents src/main/org/apache/tools/ant/taskdefs/Delete.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/MatchingTask.java implement an add(FileSelector) method src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java add an add(Condition) method to demostrate use of add(Type) method src/main/org/apache/tools/ant/types/AbstractFileSet.java implement add(FileSelector) src/main/org/apache/tools/ant/types/FilterChain.java use add(ChainableReader) instead of DynamicConfigurator src/main/org/apache/tools/ant/types/Path.java add an add(Path) method src/main/org/apache/tools/ant/types/optional/ScriptFilter.java remove set/get project as parent imlements them now src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java implement the add(FileSelector) method src/main/org/apache/tools/ant/types/selectors/SelectorContainer.java add an add(FileSelector) method ========================================= = New Files ========================================= src/etc/testcases/types/addtype.xml testcases for addtype src/testcases/org/apache/tools/ant/types/AddTypeTest.java test cases for add type git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274635 13f79535-47bb-0310-9956-ffa450edef68
22 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant;
  19. import java.lang.reflect.Constructor;
  20. import java.lang.reflect.InvocationTargetException;
  21. import java.lang.reflect.Method;
  22. import java.util.ArrayList;
  23. import java.util.Collections;
  24. import java.util.Enumeration;
  25. import java.util.Hashtable;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Locale;
  29. import java.util.Map;
  30. import org.apache.tools.ant.types.EnumeratedAttribute;
  31. import org.apache.tools.ant.taskdefs.PreSetDef;
  32. import org.apache.tools.ant.util.StringUtils;
  33. /**
  34. * Helper class that collects the methods a task or nested element
  35. * holds to set attributes, create nested elements or hold PCDATA
  36. * elements.
  37. *
  38. * It contains hashtables containing classes that use introspection
  39. * to handle all the invocation of the project-component specific methods.
  40. *
  41. * This class is somewhat complex, as it implements the O/X mapping between
  42. * Ant XML and Java class instances. This is not the best place for someone new
  43. * to Ant to start contributing to the codebase, as a change here can break the
  44. * entire system in interesting ways. Always run a full test of Ant before checking
  45. * in/submitting changes to this file.
  46. *
  47. * The class is final and has a private constructor.
  48. * To get an instance for a specific (class,project) combination,
  49. * use {@link #getHelper(Project,Class)}.
  50. * This may return an existing version, or a new one
  51. * ...do not make any assumptions about its uniqueness, or its validity after the Project
  52. * instance has finished its build.
  53. *
  54. */
  55. public final class IntrospectionHelper {
  56. /**
  57. * Helper instances we've already created (Class.getName() to IntrospectionHelper).
  58. */
  59. private static final Map HELPERS = new Hashtable();
  60. /**
  61. * Map from primitive types to wrapper classes for use in
  62. * createAttributeSetter (Class to Class). Note that char
  63. * and boolean are in here even though they get special treatment
  64. * - this way we only need to test for the wrapper class.
  65. */
  66. private static final Map PRIMITIVE_TYPE_MAP = new HashMap(8);
  67. // Set up PRIMITIVE_TYPE_MAP
  68. static {
  69. Class[] primitives = {Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
  70. Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE};
  71. Class[] wrappers = {Boolean.class, Byte.class, Character.class, Short.class,
  72. Integer.class, Long.class, Float.class, Double.class};
  73. for (int i = 0; i < primitives.length; i++) {
  74. PRIMITIVE_TYPE_MAP.put (primitives[i], wrappers[i]);
  75. }
  76. }
  77. private static final int MAX_REPORT_NESTED_TEXT = 20;
  78. private static final String ELLIPSIS = "...";
  79. /**
  80. * Map from attribute names to attribute types
  81. * (String to Class).
  82. */
  83. private Hashtable attributeTypes = new Hashtable();
  84. /**
  85. * Map from attribute names to attribute setter methods
  86. * (String to AttributeSetter).
  87. */
  88. private Hashtable attributeSetters = new Hashtable();
  89. /**
  90. * Map from attribute names to nested types
  91. * (String to Class).
  92. */
  93. private Hashtable nestedTypes = new Hashtable();
  94. /**
  95. * Map from attribute names to methods to create nested types
  96. * (String to NestedCreator).
  97. */
  98. private Hashtable nestedCreators = new Hashtable();
  99. /**
  100. * Vector of methods matching add[Configured](Class) pattern.
  101. */
  102. private List addTypeMethods = new ArrayList();
  103. /**
  104. * The method to invoke to add PCDATA.
  105. */
  106. private Method addText = null;
  107. /**
  108. * The class introspected by this instance.
  109. */
  110. private Class bean;
  111. /**
  112. * Sole constructor, which is private to ensure that all
  113. * IntrospectionHelpers are created via {@link #getHelper(Class) getHelper}.
  114. * Introspects the given class for bean-like methods.
  115. * Each method is examined in turn, and the following rules are applied:
  116. * <p>
  117. * <ul>
  118. * <li>If the method is <code>Task.setLocation(Location)</code>,
  119. * <code>Task.setTaskType(String)</code>
  120. * or <code>TaskContainer.addTask(Task)</code>, it is ignored. These
  121. * methods are handled differently elsewhere.
  122. * <li><code>void addText(String)</code> is recognised as the method for
  123. * adding PCDATA to a bean.
  124. * <li><code>void setFoo(Bar)</code> is recognised as a method for
  125. * setting the value of attribute <code>foo</code>, so long as
  126. * <code>Bar</code> is non-void and is not an array type. Non-String
  127. * parameter types always overload String parameter types, but that is
  128. * the only guarantee made in terms of priority.
  129. * <li><code>Foo createBar()</code> is recognised as a method for
  130. * creating a nested element called <code>bar</code> of type
  131. * <code>Foo</code>, so long as <code>Foo</code> is not a primitive or
  132. * array type.
  133. * <li><code>void addConfiguredFoo(Bar)</code> is recognised as a
  134. * method for storing a pre-configured element called
  135. * <code>foo</code> and of type <code>Bar</code>, so long as
  136. * <code>Bar</code> is not an array, primitive or String type.
  137. * <code>Bar</code> must have an accessible constructor taking no
  138. * arguments.
  139. * <li><code>void addFoo(Bar)</code> is recognised as a method for storing
  140. * an element called <code>foo</code> and of type <code>Bar</code>, so
  141. * long as <code>Bar</code> is not an array, primitive or String type.
  142. * <code>Bar</code> must have an accessible constructor taking no
  143. * arguments. This is distinct from the 'addConfigured' idiom in that
  144. * the nested element is added to the parent immediately after it is
  145. * constructed; in practice this means that <code>addFoo(Bar)</code> should
  146. * do little or nothing with its argument besides storing it for later use.
  147. * </ul>
  148. * Note that only one method is retained to create/set/addConfigured/add
  149. * any element or attribute.
  150. *
  151. * @param bean The bean type to introspect.
  152. * Must not be <code>null</code>.
  153. *
  154. * @see #getHelper(Class)
  155. */
  156. private IntrospectionHelper(final Class bean) {
  157. this.bean = bean;
  158. Method[] methods = bean.getMethods();
  159. for (int i = 0; i < methods.length; i++) {
  160. final Method m = methods[i];
  161. final String name = m.getName();
  162. Class returnType = m.getReturnType();
  163. Class[] args = m.getParameterTypes();
  164. // check of add[Configured](Class) pattern
  165. if (args.length == 1 && java.lang.Void.TYPE.equals(returnType)
  166. && ("add".equals(name) || "addConfigured".equals(name))) {
  167. insertAddTypeMethod(m);
  168. continue;
  169. }
  170. // not really user settable properties on tasks/project components
  171. if (org.apache.tools.ant.ProjectComponent.class.isAssignableFrom(bean)
  172. && args.length == 1 && isHiddenSetMethod(name, args[0])) {
  173. continue;
  174. }
  175. // hide addTask for TaskContainers
  176. if (isContainer() && args.length == 1 && "addTask".equals(name)
  177. && org.apache.tools.ant.Task.class.equals(args[0])) {
  178. continue;
  179. }
  180. if ("addText".equals(name) && java.lang.Void.TYPE.equals(returnType)
  181. && args.length == 1 && java.lang.String.class.equals(args[0])) {
  182. addText = methods[i];
  183. } else if (name.startsWith("set") && java.lang.Void.TYPE.equals(returnType)
  184. && args.length == 1 && !args[0].isArray()) {
  185. String propName = getPropertyName(name, "set");
  186. if (attributeSetters.get(propName) != null) {
  187. if (java.lang.String.class.equals(args[0])) {
  188. /*
  189. Ignore method m, as there is an overloaded
  190. form of this method that takes in a
  191. non-string argument, which gains higher
  192. priority.
  193. */
  194. continue;
  195. }
  196. /*
  197. If the argument is not a String and if there
  198. is an overloaded form of this method already defined,
  199. we just override that with the new one.
  200. This mechanism does not guarantee any specific order
  201. in which the methods will be selected: so any code
  202. that depends on the order in which "set" methods have
  203. been defined, is not guaranteed to be selected in any
  204. particular order.
  205. */
  206. }
  207. AttributeSetter as = createAttributeSetter(m, args[0], propName);
  208. if (as != null) {
  209. attributeTypes.put(propName, args[0]);
  210. attributeSetters.put(propName, as);
  211. }
  212. } else if (name.startsWith("create") && !returnType.isArray()
  213. && !returnType.isPrimitive() && args.length == 0) {
  214. String propName = getPropertyName(name, "create");
  215. // Check if a create of this property is already present
  216. // add takes preference over create for CB purposes
  217. if (nestedCreators.get(propName) == null) {
  218. nestedTypes.put(propName, returnType);
  219. nestedCreators.put(propName, new CreateNestedCreator(m));
  220. }
  221. } else if (name.startsWith("addConfigured")
  222. && java.lang.Void.TYPE.equals(returnType) && args.length == 1
  223. && !java.lang.String.class.equals(args[0])
  224. && !args[0].isArray() && !args[0].isPrimitive()) {
  225. try {
  226. Constructor constructor = null;
  227. try {
  228. constructor = args[0].getConstructor(new Class[] {});
  229. } catch (NoSuchMethodException ex) {
  230. constructor = args[0].getConstructor(new Class[] {Project.class});
  231. }
  232. String propName = getPropertyName(name, "addConfigured");
  233. nestedTypes.put(propName, args[0]);
  234. nestedCreators.put(propName, new AddNestedCreator(m,
  235. constructor, AddNestedCreator.ADD_CONFIGURED));
  236. } catch (NoSuchMethodException nse) {
  237. // ignore
  238. }
  239. } else if (name.startsWith("add")
  240. && java.lang.Void.TYPE.equals(returnType) && args.length == 1
  241. && !java.lang.String.class.equals(args[0])
  242. && !args[0].isArray() && !args[0].isPrimitive()) {
  243. try {
  244. Constructor constructor = null;
  245. try {
  246. constructor = args[0].getConstructor(new Class[] {});
  247. } catch (NoSuchMethodException ex) {
  248. constructor = args[0].getConstructor(new Class[] {Project.class});
  249. }
  250. String propName = getPropertyName(name, "add");
  251. if (nestedTypes.get(propName) != null) {
  252. /*
  253. * Ignore this method as there is an addConfigured
  254. * form of this method that has a higher
  255. * priority
  256. */
  257. continue;
  258. }
  259. nestedTypes.put(propName, args[0]);
  260. nestedCreators.put(propName, new AddNestedCreator(m,
  261. constructor, AddNestedCreator.ADD));
  262. } catch (NoSuchMethodException nse) {
  263. // ignore
  264. }
  265. }
  266. }
  267. }
  268. /**
  269. * Certain set methods are part of the Ant core interface to tasks and
  270. * therefore not to be considered for introspection
  271. *
  272. * @param name the name of the set method
  273. * @param type the type of the set method's parameter
  274. * @return true if the given set method is to be hidden.
  275. */
  276. private boolean isHiddenSetMethod(String name, Class type) {
  277. if ("setLocation".equals(name) && org.apache.tools.ant.Location.class.equals(type)) {
  278. return true;
  279. }
  280. if ("setTaskType".equals(name) && java.lang.String.class.equals(type)) {
  281. return true;
  282. }
  283. return false;
  284. }
  285. /**
  286. * Returns a helper for the given class, either from the cache
  287. * or by creating a new instance.
  288. *
  289. * @param c The class for which a helper is required.
  290. * Must not be <code>null</code>.
  291. *
  292. * @return a helper for the specified class
  293. */
  294. public static synchronized IntrospectionHelper getHelper(Class c) {
  295. return getHelper(null, c);
  296. }
  297. /**
  298. * Returns a helper for the given class, either from the cache
  299. * or by creating a new instance.
  300. *
  301. * The method will make sure the helper will be cleaned up at the end of
  302. * the project, and only one instance will be created for each class.
  303. *
  304. * @param p the project instance. Can be null, in which case the helper is not cached.
  305. * @param c The class for which a helper is required.
  306. * Must not be <code>null</code>.
  307. *
  308. * @return a helper for the specified class
  309. */
  310. public static IntrospectionHelper getHelper(Project p, Class c) {
  311. IntrospectionHelper ih = (IntrospectionHelper) HELPERS.get(c.getName());
  312. // If a helper cannot be found, or if the helper is for another
  313. // classloader, create a new IH
  314. if (ih == null || ih.bean != c) {
  315. ih = new IntrospectionHelper(c);
  316. if (p != null) {
  317. // #30162: do *not* cache this if there is no project, as we
  318. // cannot guarantee that the cache will be cleared.
  319. HELPERS.put(c.getName(), ih);
  320. }
  321. }
  322. return ih;
  323. }
  324. /**
  325. * Sets the named attribute in the given element, which is part of the
  326. * given project.
  327. *
  328. * @param p The project containing the element. This is used when files
  329. * need to be resolved. Must not be <code>null</code>.
  330. * @param element The element to set the attribute in. Must not be
  331. * <code>null</code>.
  332. * @param attributeName The name of the attribute to set. Must not be
  333. * <code>null</code>.
  334. * @param value The value to set the attribute to. This may be interpreted
  335. * or converted to the necessary type if the setter method
  336. * doesn't accept an object of the supplied type.
  337. *
  338. * @exception BuildException if the introspected class doesn't support
  339. * the given attribute, or if the setting
  340. * method fails.
  341. */
  342. public void setAttribute(Project p, Object element, String attributeName,
  343. Object value) throws BuildException {
  344. AttributeSetter as = (AttributeSetter) attributeSetters.get(
  345. attributeName.toLowerCase(Locale.US));
  346. if (as == null && value != null) {
  347. if (element instanceof DynamicAttributeNS) {
  348. DynamicAttributeNS dc = (DynamicAttributeNS) element;
  349. String uriPlusPrefix = ProjectHelper.extractUriFromComponentName(attributeName);
  350. String uri = ProjectHelper.extractUriFromComponentName(uriPlusPrefix);
  351. String localName = ProjectHelper.extractNameFromComponentName(attributeName);
  352. String qName = "".equals(uri) ? localName : uri + ":" + localName;
  353. dc.setDynamicAttribute(uri, localName, qName, value.toString());
  354. return;
  355. }
  356. if (element instanceof DynamicAttribute) {
  357. DynamicAttribute dc = (DynamicAttribute) element;
  358. dc.setDynamicAttribute(attributeName.toLowerCase(Locale.US), value.toString());
  359. return;
  360. }
  361. if (attributeName.indexOf(':') >= 0) {
  362. return; // Ignore attribute from unknown uri's
  363. }
  364. String msg = getElementName(p, element)
  365. + " doesn't support the \"" + attributeName + "\" attribute.";
  366. throw new UnsupportedAttributeException(msg, attributeName);
  367. }
  368. try {
  369. as.setObject(p, element, value);
  370. } catch (IllegalAccessException ie) {
  371. // impossible as getMethods should only return public methods
  372. throw new BuildException(ie);
  373. } catch (InvocationTargetException ite) {
  374. throw extractBuildException(ite);
  375. }
  376. }
  377. /**
  378. * Sets the named attribute in the given element, which is part of the
  379. * given project.
  380. *
  381. * @param p The project containing the element. This is used when files
  382. * need to be resolved. Must not be <code>null</code>.
  383. * @param element The element to set the attribute in. Must not be
  384. * <code>null</code>.
  385. * @param attributeName The name of the attribute to set. Must not be
  386. * <code>null</code>.
  387. * @param value The value to set the attribute to. This may be interpreted
  388. * or converted to the necessary type if the setter method
  389. * doesn't just take a string. Must not be <code>null</code>.
  390. *
  391. * @exception BuildException if the introspected class doesn't support
  392. * the given attribute, or if the setting
  393. * method fails.
  394. */
  395. public void setAttribute(Project p, Object element, String attributeName,
  396. String value) throws BuildException {
  397. setAttribute(p, element, attributeName, (Object) value);
  398. }
  399. /**
  400. * Adds PCDATA to an element, using the element's
  401. * <code>void addText(String)</code> method, if it has one. If no
  402. * such method is present, a BuildException is thrown if the
  403. * given text contains non-whitespace.
  404. *
  405. * @param project The project which the element is part of.
  406. * Must not be <code>null</code>.
  407. * @param element The element to add the text to.
  408. * Must not be <code>null</code>.
  409. * @param text The text to add.
  410. * Must not be <code>null</code>.
  411. *
  412. * @exception BuildException if non-whitespace text is provided and no
  413. * method is available to handle it, or if
  414. * the handling method fails.
  415. */
  416. public void addText(Project project, Object element, String text)
  417. throws BuildException {
  418. if (addText == null) {
  419. text = text.trim();
  420. // Element doesn't handle text content
  421. if (text.length() == 0) {
  422. // Only whitespace - ignore
  423. return;
  424. }
  425. // Not whitespace - fail
  426. throw new BuildException(project.getElementName(element)
  427. + " doesn't support nested text data (\"" + condenseText(text) + "\").");
  428. }
  429. try {
  430. addText.invoke(element, new Object[] {text});
  431. } catch (IllegalAccessException ie) {
  432. // impossible as getMethods should only return public methods
  433. throw new BuildException(ie);
  434. } catch (InvocationTargetException ite) {
  435. throw extractBuildException(ite);
  436. }
  437. }
  438. /**
  439. * Utility method to throw a NotSupported exception
  440. *
  441. * @param project the Project instance.
  442. * @param parent the object which doesn't support a requested element
  443. * @param elementName the name of the Element which is trying to be created.
  444. */
  445. public void throwNotSupported(Project project, Object parent, String elementName) {
  446. String msg = project.getElementName(parent)
  447. + " doesn't support the nested \"" + elementName + "\" element.";
  448. throw new UnsupportedElementException(msg, elementName);
  449. }
  450. /**
  451. * Get the specific NestedCreator for a given project/parent/element combination
  452. * @param project ant project
  453. * @param parentUri URI of the parent.
  454. * @param parent the parent class
  455. * @param elementName element to work with. This can contain
  456. * a URI,localname tuple of of the form uri:localname
  457. * @param child the bit of XML to work with
  458. * @return a nested creator that can handle the child elements.
  459. * @throws BuildException if the parent does not support child elements of that name
  460. */
  461. private NestedCreator getNestedCreator(
  462. Project project, String parentUri, Object parent,
  463. String elementName, UnknownElement child) throws BuildException {
  464. String uri = ProjectHelper.extractUriFromComponentName(elementName);
  465. String name = ProjectHelper.extractNameFromComponentName(elementName);
  466. if (uri.equals(ProjectHelper.ANT_CORE_URI)) {
  467. uri = "";
  468. }
  469. if (parentUri.equals(ProjectHelper.ANT_CORE_URI)) {
  470. parentUri = "";
  471. }
  472. NestedCreator nc = null;
  473. if (uri.equals(parentUri) || uri.length() == 0) {
  474. nc = (NestedCreator) nestedCreators.get(name.toLowerCase(Locale.US));
  475. }
  476. if (nc == null) {
  477. nc = createAddTypeCreator(project, parent, elementName);
  478. }
  479. if (nc == null && parent instanceof DynamicElementNS) {
  480. DynamicElementNS dc = (DynamicElementNS) parent;
  481. String qName = child == null ? name : child.getQName();
  482. final Object nestedElement = dc.createDynamicElement(
  483. child == null ? "" : child.getNamespace(), name, qName);
  484. if (nestedElement != null) {
  485. nc = new NestedCreator(null) {
  486. Object create(Project project, Object parent, Object ignore) {
  487. return nestedElement;
  488. }
  489. };
  490. }
  491. }
  492. if (nc == null && parent instanceof DynamicElement) {
  493. DynamicElement dc = (DynamicElement) parent;
  494. final Object nestedElement = dc.createDynamicElement(name.toLowerCase(Locale.US));
  495. if (nestedElement != null) {
  496. nc = new NestedCreator(null) {
  497. Object create(Project project, Object parent, Object ignore) {
  498. return nestedElement;
  499. }
  500. };
  501. }
  502. }
  503. if (nc == null) {
  504. throwNotSupported(project, parent, elementName);
  505. }
  506. return nc;
  507. }
  508. /**
  509. * Creates a named nested element. Depending on the results of the
  510. * initial introspection, either a method in the given parent instance
  511. * or a simple no-arg constructor is used to create an instance of the
  512. * specified element type.
  513. *
  514. * @param project Project to which the parent object belongs.
  515. * Must not be <code>null</code>. If the resulting
  516. * object is an instance of ProjectComponent, its
  517. * Project reference is set to this parameter value.
  518. * @param parent Parent object used to create the instance.
  519. * Must not be <code>null</code>.
  520. * @param elementName Name of the element to create an instance of.
  521. * Must not be <code>null</code>.
  522. *
  523. * @return an instance of the specified element type
  524. * @deprecated since 1.6.x.
  525. * This is not a namespace aware method.
  526. *
  527. * @exception BuildException if no method is available to create the
  528. * element instance, or if the creating method fails.
  529. */
  530. public Object createElement(Project project, Object parent, String elementName)
  531. throws BuildException {
  532. NestedCreator nc = getNestedCreator(project, "", parent, elementName, null);
  533. try {
  534. Object nestedElement = nc.create(project, parent, null);
  535. if (project != null) {
  536. project.setProjectReference(nestedElement);
  537. }
  538. return nestedElement;
  539. } catch (IllegalAccessException ie) {
  540. // impossible as getMethods should only return public methods
  541. throw new BuildException(ie);
  542. } catch (InstantiationException ine) {
  543. // impossible as getMethods should only return public methods
  544. throw new BuildException(ine);
  545. } catch (InvocationTargetException ite) {
  546. throw extractBuildException(ite);
  547. }
  548. }
  549. /**
  550. * returns an object that creates and stores an object
  551. * for an element of a parent.
  552. *
  553. * @param project Project to which the parent object belongs.
  554. * @param parentUri The namespace uri of the parent object.
  555. * @param parent Parent object used to create the creator object to
  556. * create and store and instance of a subelement.
  557. * @param elementName Name of the element to create an instance of.
  558. * @param ue The unknown element associated with the element.
  559. * @return a creator object to create and store the element instance.
  560. */
  561. public Creator getElementCreator(
  562. Project project, String parentUri, Object parent, String elementName, UnknownElement ue) {
  563. NestedCreator nc = getNestedCreator(project, parentUri, parent, elementName, ue);
  564. return new Creator(project, parent, nc);
  565. }
  566. /**
  567. * Indicates whether the introspected class is a dynamic one,
  568. * supporting arbitrary nested elements and/or attributes.
  569. *
  570. * @return <code>true<code> if the introspected class is dynamic;
  571. * <code>false<code> otherwise.
  572. * @since Ant 1.6.3
  573. *
  574. * @see DynamicElement
  575. * @see DynamicElementNS
  576. */
  577. public boolean isDynamic() {
  578. return DynamicElement.class.isAssignableFrom(bean)
  579. || DynamicElementNS.class.isAssignableFrom(bean);
  580. }
  581. /**
  582. * Indicates whether the introspected class is a task container,
  583. * supporting arbitrary nested tasks/types.
  584. *
  585. * @return <code>true<code> if the introspected class is a container;
  586. * <code>false<code> otherwise.
  587. * @since Ant 1.6.3
  588. *
  589. * @see TaskContainer
  590. */
  591. public boolean isContainer() {
  592. return TaskContainer.class.isAssignableFrom(bean);
  593. }
  594. /**
  595. * Indicates if this element supports a nested element of the
  596. * given name.
  597. *
  598. * @param elementName the name of the nested element being checked
  599. *
  600. * @return true if the given nested element is supported
  601. */
  602. public boolean supportsNestedElement(String elementName) {
  603. return supportsNestedElement("", elementName);
  604. }
  605. /**
  606. * Indicate if this element supports a nested element of the
  607. * given name.
  608. *
  609. * @param parentUri the uri of the parent
  610. * @param elementName the name of the nested element being checked
  611. *
  612. * @return true if the given nested element is supported
  613. */
  614. public boolean supportsNestedElement(String parentUri, String elementName) {
  615. if (isDynamic() || addTypeMethods.size() > 0) {
  616. return true;
  617. }
  618. String name = ProjectHelper.extractNameFromComponentName(elementName);
  619. if (!nestedCreators.containsKey(name.toLowerCase(Locale.US))) {
  620. return false;
  621. }
  622. String uri = ProjectHelper.extractUriFromComponentName(elementName);
  623. if (uri.equals(ProjectHelper.ANT_CORE_URI)) {
  624. uri = "";
  625. }
  626. if ("".equals(uri)) {
  627. return true;
  628. }
  629. if (parentUri.equals(ProjectHelper.ANT_CORE_URI)) {
  630. parentUri = "";
  631. }
  632. return uri.equals(parentUri);
  633. }
  634. /**
  635. * Stores a named nested element using a storage method determined
  636. * by the initial introspection. If no appropriate storage method
  637. * is available, this method returns immediately.
  638. *
  639. * @param project Ignored in this implementation.
  640. * May be <code>null</code>.
  641. *
  642. * @param parent Parent instance to store the child in.
  643. * Must not be <code>null</code>.
  644. *
  645. * @param child Child instance to store in the parent.
  646. * Should not be <code>null</code>.
  647. *
  648. * @param elementName Name of the child element to store.
  649. * May be <code>null</code>, in which case
  650. * this method returns immediately.
  651. *
  652. * @exception BuildException if the storage method fails.
  653. */
  654. public void storeElement(Project project, Object parent, Object child,
  655. String elementName) throws BuildException {
  656. if (elementName == null) {
  657. return;
  658. }
  659. NestedCreator ns = (NestedCreator) nestedCreators.get(elementName.toLowerCase(Locale.US));
  660. if (ns == null) {
  661. return;
  662. }
  663. try {
  664. ns.store(parent, child);
  665. } catch (IllegalAccessException ie) {
  666. // impossible as getMethods should only return public methods
  667. throw new BuildException(ie);
  668. } catch (InstantiationException ine) {
  669. // impossible as getMethods should only return public methods
  670. throw new BuildException(ine);
  671. } catch (InvocationTargetException ite) {
  672. throw extractBuildException(ite);
  673. }
  674. }
  675. /**
  676. * Helper method to extract the inner fault from an {@link InvocationTargetException}, and turn
  677. * it into a BuildException. If it is already a BuildException, it is type cast and returned; if
  678. * not a new BuildException is created containing the child as nested text.
  679. * @param ite
  680. * @return the nested exception
  681. */
  682. private static BuildException extractBuildException(InvocationTargetException ite) {
  683. Throwable t = ite.getTargetException();
  684. if (t instanceof BuildException) {
  685. return (BuildException) t;
  686. }
  687. return new BuildException(t);
  688. }
  689. /**
  690. * Returns the type of a named nested element.
  691. *
  692. * @param elementName The name of the element to find the type of.
  693. * Must not be <code>null</code>.
  694. *
  695. * @return the type of the nested element with the specified name.
  696. * This will never be <code>null</code>.
  697. *
  698. * @exception BuildException if the introspected class does not
  699. * support the named nested element.
  700. */
  701. public Class getElementType(String elementName) throws BuildException {
  702. Class nt = (Class) nestedTypes.get(elementName);
  703. if (nt == null) {
  704. throw new UnsupportedElementException("Class "
  705. + bean.getName() + " doesn't support the nested \""
  706. + elementName + "\" element.", elementName);
  707. }
  708. return nt;
  709. }
  710. /**
  711. * Returns the type of a named attribute.
  712. *
  713. * @param attributeName The name of the attribute to find the type of.
  714. * Must not be <code>null</code>.
  715. *
  716. * @return the type of the attribute with the specified name.
  717. * This will never be <code>null</code>.
  718. *
  719. * @exception BuildException if the introspected class does not
  720. * support the named attribute.
  721. */
  722. public Class getAttributeType(String attributeName) throws BuildException {
  723. Class at = (Class) attributeTypes.get(attributeName);
  724. if (at == null) {
  725. throw new UnsupportedAttributeException("Class "
  726. + bean.getName() + " doesn't support the \""
  727. + attributeName + "\" attribute.", attributeName);
  728. }
  729. return at;
  730. }
  731. /**
  732. * Returns the addText method when the introspected
  733. * class supports nested text.
  734. *
  735. * @return the method on this introspected class that adds nested text.
  736. * Cannot be <code>null</code>.
  737. * @throws BuildException if the introspected class does not
  738. * support the nested text.
  739. * @since Ant 1.6.3
  740. */
  741. public Method getAddTextMethod() throws BuildException {
  742. if (!supportsCharacters()) {
  743. throw new BuildException("Class " + bean.getName()
  744. + " doesn't support nested text data.");
  745. }
  746. return addText;
  747. }
  748. /**
  749. * Returns the adder or creator method of a named nested element.
  750. *
  751. * @param elementName The name of the attribute to find the setter
  752. * method of. Must not be <code>null</code>.
  753. * @return the method on this introspected class that adds or creates this
  754. * nested element. Can be <code>null</code> when the introspected
  755. * class is a dynamic configurator!
  756. * @throws BuildException if the introspected class does not
  757. * support the named nested element.
  758. * @since Ant 1.6.3
  759. */
  760. public Method getElementMethod(String elementName) throws BuildException {
  761. Object creator = nestedCreators.get(elementName);
  762. if (creator == null) {
  763. throw new UnsupportedElementException("Class "
  764. + bean.getName() + " doesn't support the nested \""
  765. + elementName + "\" element.", elementName);
  766. }
  767. return ((NestedCreator) creator).method;
  768. }
  769. /**
  770. * Returns the setter method of a named attribute.
  771. *
  772. * @param attributeName The name of the attribute to find the setter
  773. * method of. Must not be <code>null</code>.
  774. * @return the method on this introspected class that sets this attribute.
  775. * This will never be <code>null</code>.
  776. * @throws BuildException if the introspected class does not
  777. * support the named attribute.
  778. * @since Ant 1.6.3
  779. */
  780. public Method getAttributeMethod(String attributeName) throws BuildException {
  781. Object setter = attributeSetters.get(attributeName);
  782. if (setter == null) {
  783. throw new UnsupportedAttributeException("Class "
  784. + bean.getName() + " doesn't support the \""
  785. + attributeName + "\" attribute.", attributeName);
  786. }
  787. return ((AttributeSetter) setter).method;
  788. }
  789. /**
  790. * Returns whether or not the introspected class supports PCDATA.
  791. *
  792. * @return whether or not the introspected class supports PCDATA.
  793. */
  794. public boolean supportsCharacters() {
  795. return addText != null;
  796. }
  797. /**
  798. * Returns an enumeration of the names of the attributes supported by the introspected class.
  799. *
  800. * @return an enumeration of the names of the attributes supported by the introspected class.
  801. * @see #getAttributeMap
  802. */
  803. public Enumeration getAttributes() {
  804. return attributeSetters.keys();
  805. }
  806. /**
  807. * Returns a read-only map of attributes supported by the introspected class.
  808. *
  809. * @return an attribute name to attribute <code>Class</code>
  810. * unmodifiable map. Can be empty, but never <code>null</code>.
  811. * @since Ant 1.6.3
  812. */
  813. public Map getAttributeMap() {
  814. return attributeTypes.isEmpty()
  815. ? Collections.EMPTY_MAP : Collections.unmodifiableMap(attributeTypes);
  816. }
  817. /**
  818. * Returns an enumeration of the names of the nested elements supported
  819. * by the introspected class.
  820. *
  821. * @return an enumeration of the names of the nested elements supported
  822. * by the introspected class.
  823. * @see #getNestedElementMap
  824. */
  825. public Enumeration getNestedElements() {
  826. return nestedTypes.keys();
  827. }
  828. /**
  829. * Returns a read-only map of nested elements supported
  830. * by the introspected class.
  831. *
  832. * @return a nested-element name to nested-element <code>Class</code>
  833. * unmodifiable map. Can be empty, but never <code>null</code>.
  834. * @since Ant 1.6.3
  835. */
  836. public Map getNestedElementMap() {
  837. return nestedTypes.isEmpty()
  838. ? Collections.EMPTY_MAP : Collections.unmodifiableMap(nestedTypes);
  839. }
  840. /**
  841. * Returns a read-only list of extension points supported
  842. * by the introspected class.
  843. * <p>
  844. * A task/type or nested element with void methods named <code>add()<code>
  845. * or <code>addConfigured()</code>, taking a single class or interface
  846. * argument, supports extensions point. This method returns the list of
  847. * all these <em>void add[Configured](type)</em> methods.
  848. *
  849. * @return a list of void, single argument add() or addConfigured()
  850. * <code>Method<code>s of all supported extension points.
  851. * These methods are sorted such that if the argument type of a
  852. * method derives from another type also an argument of a method
  853. * of this list, the method with the most derived argument will
  854. * always appear first. Can be empty, but never <code>null</code>.
  855. * @since Ant 1.6.3
  856. */
  857. public List getExtensionPoints() {
  858. return addTypeMethods.isEmpty()
  859. ? Collections.EMPTY_LIST : Collections.unmodifiableList(addTypeMethods);
  860. }
  861. /**
  862. * Creates an implementation of AttributeSetter for the given
  863. * attribute type. Conversions (where necessary) are automatically
  864. * made for the following types:
  865. * <ul>
  866. * <li>String (left as it is)
  867. * <li>Character/char (first character is used)
  868. * <li>Boolean/boolean
  869. * ({@link Project#toBoolean(String) Project.toBoolean(String)} is used)
  870. * <li>Class (Class.forName is used)
  871. * <li>File (resolved relative to the appropriate project)
  872. * <li>Path (resolve relative to the appropriate project)
  873. * <li>EnumeratedAttribute (uses its own
  874. * {@link EnumeratedAttribute#setValue(String) setValue} method)
  875. * <li>Other primitive types (wrapper classes are used with constructors
  876. * taking String)
  877. * </ul>
  878. *
  879. * If none of the above covers the given parameters, a constructor for the
  880. * appropriate class taking a String parameter is used if it is available.
  881. *
  882. * @param m The method to invoke on the bean when the setter is invoked.
  883. * Must not be <code>null</code>.
  884. * @param arg The type of the single argument of the bean's method.
  885. * Must not be <code>null</code>.
  886. * @param attrName the name of the attribute for which the setter is being
  887. * created.
  888. *
  889. * @return an appropriate AttributeSetter instance, or <code>null</code>
  890. * if no appropriate conversion is available.
  891. */
  892. private AttributeSetter createAttributeSetter(final Method m,
  893. Class arg,
  894. final String attrName) {
  895. // use wrappers for primitive classes, e.g. int and
  896. // Integer are treated identically
  897. final Class reflectedArg = PRIMITIVE_TYPE_MAP.containsKey(arg)
  898. ? (Class) PRIMITIVE_TYPE_MAP.get(arg) : arg;
  899. // simplest case - setAttribute expects String
  900. if (java.lang.String.class.equals(reflectedArg)) {
  901. return new AttributeSetter(m, arg) {
  902. public void set(Project p, Object parent, String value)
  903. throws InvocationTargetException, IllegalAccessException {
  904. m.invoke(parent, (Object[]) new String[] {value});
  905. }
  906. };
  907. }
  908. // char and Character get special treatment - take the first character
  909. if (java.lang.Character.class.equals(reflectedArg)) {
  910. return new AttributeSetter(m, arg) {
  911. public void set(Project p, Object parent, String value)
  912. throws InvocationTargetException, IllegalAccessException {
  913. if (value.length() == 0) {
  914. throw new BuildException("The value \"\" is not a "
  915. + "legal value for attribute \"" + attrName + "\"");
  916. }
  917. m.invoke(parent, (Object[]) new Character[] {new Character(value.charAt(0))});
  918. }
  919. };
  920. }
  921. // boolean and Boolean get special treatment because we have a nice method in Project
  922. if (java.lang.Boolean.class.equals(reflectedArg)) {
  923. return new AttributeSetter(m, arg) {
  924. public void set(Project p, Object parent, String value)
  925. throws InvocationTargetException, IllegalAccessException {
  926. m.invoke(parent, (Object[]) new Boolean[] {
  927. Project.toBoolean(value) ? Boolean.TRUE : Boolean.FALSE });
  928. }
  929. };
  930. }
  931. // Class doesn't have a String constructor but a decent factory method
  932. if (java.lang.Class.class.equals(reflectedArg)) {
  933. return new AttributeSetter(m, arg) {
  934. public void set(Project p, Object parent, String value)
  935. throws InvocationTargetException, IllegalAccessException, BuildException {
  936. try {
  937. m.invoke(parent, new Object[] {Class.forName(value)});
  938. } catch (ClassNotFoundException ce) {
  939. throw new BuildException(ce);
  940. }
  941. }
  942. };
  943. }
  944. // resolve relative paths through Project
  945. if (java.io.File.class.equals(reflectedArg)) {
  946. return new AttributeSetter(m, arg) {
  947. public void set(Project p, Object parent, String value)
  948. throws InvocationTargetException, IllegalAccessException {
  949. m.invoke(parent, new Object[] {p.resolveFile(value)});
  950. }
  951. };
  952. }
  953. // EnumeratedAttributes have their own helper class
  954. if (EnumeratedAttribute.class.isAssignableFrom(reflectedArg)) {
  955. return new AttributeSetter(m, arg) {
  956. public void set(Project p, Object parent, String value)
  957. throws InvocationTargetException, IllegalAccessException, BuildException {
  958. try {
  959. EnumeratedAttribute ea = (EnumeratedAttribute) reflectedArg.newInstance();
  960. ea.setValue(value);
  961. m.invoke(parent, new Object[] {ea});
  962. } catch (InstantiationException ie) {
  963. throw new BuildException(ie);
  964. }
  965. }
  966. };
  967. }
  968. AttributeSetter setter = getEnumSetter(reflectedArg, m, arg);
  969. if (setter != null) {
  970. return setter;
  971. }
  972. if (java.lang.Long.class.equals(reflectedArg)) {
  973. return new AttributeSetter(m, arg) {
  974. public void set(Project p, Object parent, String value)
  975. throws InvocationTargetException, IllegalAccessException, BuildException {
  976. try {
  977. m.invoke(parent, new Object[] {
  978. new Long(StringUtils.parseHumanSizes(value)) });
  979. } catch (InvocationTargetException e) {
  980. throw e;
  981. } catch (IllegalAccessException e) {
  982. throw e;
  983. } catch (Exception e) {
  984. throw new BuildException(e);
  985. }
  986. }
  987. };
  988. }
  989. // worst case. look for a public String constructor and use it
  990. // also supports new Whatever(Project, String) as for Path or Reference
  991. // This is used (deliberately) for all primitives/wrappers other than
  992. // char, boolean, and long.
  993. boolean includeProject;
  994. Constructor c;
  995. try {
  996. // First try with Project.
  997. c = reflectedArg.getConstructor(new Class[] {Project.class, String.class});
  998. includeProject = true;
  999. } catch (NoSuchMethodException nme) {
  1000. // OK, try without.
  1001. try {
  1002. c = reflectedArg.getConstructor(new Class[] {String.class});
  1003. includeProject = false;
  1004. } catch (NoSuchMethodException nme2) {
  1005. // Well, no matching constructor.
  1006. return null;
  1007. }
  1008. }
  1009. final boolean finalIncludeProject = includeProject;
  1010. final Constructor finalConstructor = c;
  1011. return new AttributeSetter(m, arg) {
  1012. public void set(Project p, Object parent, String value)
  1013. throws InvocationTargetException, IllegalAccessException, BuildException {
  1014. try {
  1015. Object[] args = finalIncludeProject
  1016. ? new Object[] {p, value} : new Object[] {value};
  1017. Object attribute = finalConstructor.newInstance(args);
  1018. if (p != null) {
  1019. p.setProjectReference(attribute);
  1020. }
  1021. m.invoke(parent, new Object[] {attribute});
  1022. } catch (InstantiationException ie) {
  1023. throw new BuildException(ie);
  1024. }
  1025. }
  1026. };
  1027. }
  1028. private AttributeSetter getEnumSetter(
  1029. final Class reflectedArg, final Method m, Class arg) {
  1030. Class enumClass = null;
  1031. try {
  1032. enumClass = Class.forName("java.lang.Enum");
  1033. } catch (ClassNotFoundException e) {
  1034. //ignore
  1035. }
  1036. if (enumClass != null && enumClass.isAssignableFrom(reflectedArg)) {
  1037. return new AttributeSetter(m, arg) {
  1038. public void set(Project p, Object parent, String value)
  1039. throws InvocationTargetException, IllegalAccessException,
  1040. BuildException {
  1041. try {
  1042. m.invoke(
  1043. parent, new Object[] {
  1044. reflectedArg.getMethod(
  1045. "valueOf", new Class[] {String.class}).
  1046. invoke(null, new Object[] {value})});
  1047. } catch (InvocationTargetException x) {
  1048. //there is specific logic here for the value
  1049. // being out of the allowed set of enumerations.
  1050. if (x.getTargetException() instanceof IllegalArgumentException) {
  1051. throw new BuildException(
  1052. "'" + value + "' is not a permitted value for "
  1053. + reflectedArg.getName());
  1054. }
  1055. //only if the exception is not an IllegalArgument do we
  1056. // request the
  1057. //BuildException via extractBuildException():
  1058. throw extractBuildException(x);
  1059. } catch (Exception x) {
  1060. //any other failure of invoke() to work.
  1061. throw new BuildException(x);
  1062. }
  1063. }
  1064. };
  1065. }
  1066. return null;
  1067. }
  1068. /**
  1069. * Returns a description of the type of the given element in
  1070. * relation to a given project. This is used for logging purposes
  1071. * when the element is asked to cope with some data it has no way of handling.
  1072. *
  1073. * @param project The project the element is defined in. Must not be <code>null</code>.
  1074. *
  1075. * @param element The element to describe. Must not be <code>null</code>.
  1076. *
  1077. * @return a description of the element type
  1078. */
  1079. private String getElementName(Project project, Object element) {
  1080. return project.getElementName(element);
  1081. }
  1082. /**
  1083. * Extracts the name of a property from a method name by subtracting
  1084. * a given prefix and converting into lower case. It is up to calling
  1085. * code to make sure the method name does actually begin with the
  1086. * specified prefix - no checking is done in this method.
  1087. *
  1088. * @param methodName The name of the method in question. Must not be <code>null</code>.
  1089. * @param prefix The prefix to remove. Must not be <code>null</code>.
  1090. *
  1091. * @return the lower-cased method name with the prefix removed.
  1092. */
  1093. private static String getPropertyName(String methodName, String prefix) {
  1094. return methodName.substring(prefix.length()).toLowerCase(Locale.US);
  1095. }
  1096. /**
  1097. * creator - allows use of create/store external
  1098. * to IntrospectionHelper.
  1099. * The class is final as it has a private constructor.
  1100. */
  1101. public static final class Creator {
  1102. private NestedCreator nestedCreator;
  1103. private Object parent;
  1104. private Project project;
  1105. private Object nestedObject;
  1106. private String polyType;
  1107. /**
  1108. * Creates a new Creator instance.
  1109. * This object is given to the UnknownElement to create
  1110. * objects for sub-elements. UnknownElement calls
  1111. * create to create an object, the object then gets
  1112. * configured and then UnknownElement calls store.
  1113. * SetPolyType may be used to override the type used
  1114. * to create the object with. SetPolyType gets called before create.
  1115. *
  1116. * @param project the current project
  1117. * @param parent the parent object to create the object in
  1118. * @param nestedCreator the nested creator object to use
  1119. */
  1120. private Creator(Project project, Object parent, NestedCreator nestedCreator) {
  1121. this.project = project;
  1122. this.parent = parent;
  1123. this.nestedCreator = nestedCreator;
  1124. }
  1125. /**
  1126. * Used to override the class used to create the object.
  1127. *
  1128. * @param polyType a ant component type name
  1129. */
  1130. public void setPolyType(String polyType) {
  1131. this.polyType = polyType;
  1132. }
  1133. /**
  1134. * Create an object using this creator, which is determined by introspection.
  1135. *
  1136. * @return the created object
  1137. */
  1138. public Object create() {
  1139. if (polyType != null) {
  1140. if (!nestedCreator.isPolyMorphic()) {
  1141. throw new BuildException(
  1142. "Not allowed to use the polymorphic form for this element");
  1143. }
  1144. ComponentHelper helper = ComponentHelper.getComponentHelper(project);
  1145. nestedObject = helper.createComponent(polyType);
  1146. if (nestedObject == null) {
  1147. throw new BuildException("Unable to create object of type " + polyType);
  1148. }
  1149. }
  1150. try {
  1151. nestedObject = nestedCreator.create(project, parent, nestedObject);
  1152. if (project != null) {
  1153. project.setProjectReference(nestedObject);
  1154. }
  1155. return nestedObject;
  1156. } catch (IllegalAccessException ex) {
  1157. throw new BuildException(ex);
  1158. } catch (InstantiationException ex) {
  1159. throw new BuildException(ex);
  1160. } catch (IllegalArgumentException ex) {
  1161. if (polyType == null) {
  1162. throw ex;
  1163. }
  1164. throw new BuildException("Invalid type used " + polyType);
  1165. } catch (InvocationTargetException ex) {
  1166. throw extractBuildException(ex);
  1167. }
  1168. }
  1169. /**
  1170. * @return the real object (used currently only for presetdef).
  1171. */
  1172. public Object getRealObject() {
  1173. return nestedCreator.getRealObject();
  1174. }
  1175. /**
  1176. * Stores the nested element object using a storage method determined by introspection.
  1177. *
  1178. */
  1179. public void store() {
  1180. try {
  1181. nestedCreator.store(parent, nestedObject);
  1182. } catch (IllegalAccessException ex) {
  1183. throw new BuildException(ex);
  1184. } catch (InstantiationException ex) {
  1185. throw new BuildException(ex);
  1186. } catch (IllegalArgumentException ex) {
  1187. if (polyType == null) {
  1188. throw ex;
  1189. }
  1190. throw new BuildException("Invalid type used " + polyType);
  1191. } catch (InvocationTargetException ex) {
  1192. throw extractBuildException(ex);
  1193. }
  1194. }
  1195. }
  1196. /**
  1197. * Internal interface used to create nested elements. Not documented
  1198. * in detail for reasons of source code readability.
  1199. */
  1200. private abstract static class NestedCreator {
  1201. private Method method; // the method called to add/create the nested element
  1202. protected NestedCreator(Method m) {
  1203. method = m;
  1204. }
  1205. Method getMethod() {
  1206. return method;
  1207. }
  1208. boolean isPolyMorphic() {
  1209. return false;
  1210. }
  1211. Object getRealObject() {
  1212. return null;
  1213. }
  1214. abstract Object create(Project project, Object parent, Object child)
  1215. throws InvocationTargetException, IllegalAccessException, InstantiationException;
  1216. void store(Object parent, Object child)
  1217. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1218. // DO NOTHING
  1219. }
  1220. }
  1221. private static class CreateNestedCreator extends NestedCreator {
  1222. CreateNestedCreator(Method m) {
  1223. super(m);
  1224. }
  1225. Object create(Project project, Object parent, Object ignore)
  1226. throws InvocationTargetException, IllegalAccessException {
  1227. return getMethod().invoke(parent, new Object[] {});
  1228. }
  1229. }
  1230. /** Version to use for addXXX and addConfiguredXXX */
  1231. private static class AddNestedCreator extends NestedCreator {
  1232. static final int ADD = 1;
  1233. static final int ADD_CONFIGURED = 2;
  1234. private Constructor constructor;
  1235. private int behavior; // ADD or ADD_CONFIGURED
  1236. AddNestedCreator(Method m, Constructor c, int behavior) {
  1237. super(m);
  1238. this.constructor = c;
  1239. this.behavior = behavior;
  1240. }
  1241. boolean isPolyMorphic() {
  1242. return true;
  1243. }
  1244. Object create(Project project, Object parent, Object child)
  1245. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1246. if (child == null) {
  1247. child = constructor.newInstance(
  1248. constructor.getParameterTypes().length == 0
  1249. ? new Object[] {} : new Object[] {project});
  1250. }
  1251. if (child instanceof PreSetDef.PreSetDefinition) {
  1252. child = ((PreSetDef.PreSetDefinition) child).createObject(project);
  1253. }
  1254. if (behavior == ADD) {
  1255. istore(parent, child);
  1256. }
  1257. return child;
  1258. }
  1259. void store(Object parent, Object child)
  1260. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1261. if (behavior == ADD_CONFIGURED) {
  1262. istore(parent, child);
  1263. }
  1264. }
  1265. private void istore(Object parent, Object child)
  1266. throws InvocationTargetException, IllegalAccessException, InstantiationException {
  1267. getMethod().invoke(parent, new Object[] {child});
  1268. }
  1269. }
  1270. /**
  1271. * Internal interface used to setting element attributes. Not documented
  1272. * in detail for reasons of source code readability.
  1273. */
  1274. private abstract static class AttributeSetter {
  1275. private Method method; // the method called to set the attribute
  1276. private Class type;
  1277. protected AttributeSetter(Method m, Class type) {
  1278. method = m;
  1279. this.type = type;
  1280. }
  1281. void setObject(Project p, Object parent, Object value)
  1282. throws InvocationTargetException, IllegalAccessException, BuildException {
  1283. if (type != null) {
  1284. Class useType = type;
  1285. if (type.isPrimitive()) {
  1286. if (value == null) {
  1287. throw new BuildException(
  1288. "Attempt to set primitive "
  1289. + getPropertyName(method.getName(), "set")
  1290. + " to null on " + parent);
  1291. }
  1292. useType = (Class) PRIMITIVE_TYPE_MAP.get(type);
  1293. }
  1294. if (value == null || useType.isInstance(value)) {
  1295. method.invoke(parent, new Object[] {value});
  1296. return;
  1297. }
  1298. }
  1299. set(p, parent, value.toString());
  1300. }
  1301. abstract void set(Project p, Object parent, String value)
  1302. throws InvocationTargetException, IllegalAccessException, BuildException;
  1303. }
  1304. /**
  1305. * Clears the static cache of on build finished.
  1306. */
  1307. public static void clearCache() {
  1308. HELPERS.clear();
  1309. }
  1310. /**
  1311. * Create a NestedCreator for the given element.
  1312. * @param project owning project
  1313. * @param parent Parent object used to create the instance.
  1314. * @param elementName name of the element
  1315. * @return a nested creator, or null if there is no component of the given name, or it
  1316. * has no matching add type methods
  1317. * @throws BuildException
  1318. */
  1319. private NestedCreator createAddTypeCreator(
  1320. Project project, Object parent, String elementName) throws BuildException {
  1321. if (addTypeMethods.size() == 0) {
  1322. return null;
  1323. }
  1324. ComponentHelper helper = ComponentHelper.getComponentHelper(project);
  1325. MethodAndObject restricted = createRestricted(
  1326. helper, elementName, addTypeMethods);
  1327. MethodAndObject topLevel = createTopLevel(
  1328. helper, elementName, addTypeMethods);
  1329. if (restricted == null && topLevel == null) {
  1330. return null;
  1331. }
  1332. if (restricted != null && topLevel != null) {
  1333. throw new BuildException(
  1334. "ambiguous: type and component definitions for "
  1335. + elementName);
  1336. }
  1337. MethodAndObject methodAndObject
  1338. = restricted != null ? restricted : topLevel;
  1339. Object rObject = methodAndObject.object;
  1340. if (methodAndObject.object instanceof PreSetDef.PreSetDefinition) {
  1341. rObject = ((PreSetDef.PreSetDefinition) methodAndObject.object)
  1342. .createObject(project);
  1343. }
  1344. final Object nestedObject = methodAndObject.object;
  1345. final Object realObject = rObject;
  1346. return new NestedCreator(methodAndObject.method) {
  1347. Object create(Project project, Object parent, Object ignore)
  1348. throws InvocationTargetException, IllegalAccessException {
  1349. if (!getMethod().getName().endsWith("Configured")) {
  1350. getMethod().invoke(parent, new Object[] {realObject});
  1351. }
  1352. return nestedObject;
  1353. }
  1354. Object getRealObject() {
  1355. return realObject;
  1356. }
  1357. void store(Object parent, Object child) throws InvocationTargetException,
  1358. IllegalAccessException, InstantiationException {
  1359. if (getMethod().getName().endsWith("Configured")) {
  1360. getMethod().invoke(parent, new Object[] {realObject});
  1361. }
  1362. }
  1363. };
  1364. }
  1365. /**
  1366. * Inserts an add or addConfigured method into
  1367. * the addTypeMethods array. The array is
  1368. * ordered so that the more derived classes are first.
  1369. * If both add and addConfigured are present, the addConfigured will take priority.
  1370. * @param method the <code>Method</code> to insert.
  1371. */
  1372. private void insertAddTypeMethod(Method method) {
  1373. Class argClass = method.getParameterTypes()[0];
  1374. for (int c = 0; c < addTypeMethods.size(); ++c) {
  1375. Method current = (Method) addTypeMethods.get(c);
  1376. if (current.getParameterTypes()[0].equals(argClass)) {
  1377. if (method.getName().equals("addConfigured")) {
  1378. // add configured replaces the add method
  1379. addTypeMethods.set(c, method);
  1380. }
  1381. return; // Already present
  1382. }
  1383. if (current.getParameterTypes()[0].isAssignableFrom(argClass)) {
  1384. addTypeMethods.add(c, method);
  1385. return; // higher derived
  1386. }
  1387. }
  1388. addTypeMethods.add(method);
  1389. }
  1390. /**
  1391. * Search the list of methods to find the first method
  1392. * that has a parameter that accepts the nested element object.
  1393. * @param paramClass the <code>Class</code> type to search for.
  1394. * @param methods the <code>List</code> of methods to search.
  1395. * @return a matching <code>Method</code>; null if none found.
  1396. */
  1397. private Method findMatchingMethod(Class paramClass, List methods) {
  1398. if (paramClass == null) {
  1399. return null;
  1400. }
  1401. Class matchedClass = null;
  1402. Method matchedMethod = null;
  1403. for (int i = 0; i < methods.size(); ++i) {
  1404. Method method = (Method) methods.get(i);
  1405. Class methodClass = method.getParameterTypes()[0];
  1406. if (methodClass.isAssignableFrom(paramClass)) {
  1407. if (matchedClass == null) {
  1408. matchedClass = methodClass;
  1409. matchedMethod = method;
  1410. } else if (!methodClass.isAssignableFrom(matchedClass)) {
  1411. throw new BuildException("ambiguous: types " + matchedClass.getName() + " and "
  1412. + methodClass.getName() + " match " + paramClass.getName());
  1413. }
  1414. }
  1415. }
  1416. return matchedMethod;
  1417. }
  1418. private String condenseText(final String text) {
  1419. if (text.length() <= MAX_REPORT_NESTED_TEXT) {
  1420. return text;
  1421. }
  1422. int ends = (MAX_REPORT_NESTED_TEXT - ELLIPSIS.length()) / 2;
  1423. return new StringBuffer(text).replace(ends, text.length() - ends, ELLIPSIS).toString();
  1424. }
  1425. private class MethodAndObject {
  1426. private Method method;
  1427. private Object object;
  1428. public MethodAndObject(Method method, Object object) {
  1429. this.method = method;
  1430. this.object = object;
  1431. }
  1432. }
  1433. /**
  1434. *
  1435. */
  1436. private AntTypeDefinition findRestrictedDefinition(
  1437. ComponentHelper helper, String componentName, List methods) {
  1438. AntTypeDefinition definition = null;
  1439. Class matchedDefinitionClass = null;
  1440. List definitions = helper.getRestrictedDefinitions(componentName);
  1441. if (definitions == null) {
  1442. return null;
  1443. }
  1444. for (int i = 0; i < definitions.size(); ++i) {
  1445. AntTypeDefinition d = (AntTypeDefinition) definitions.get(i);
  1446. Class exposedClass = d.getExposedClass(helper.getProject());
  1447. if (exposedClass == null) {
  1448. continue;
  1449. }
  1450. Method method = findMatchingMethod(exposedClass, methods);
  1451. if (method == null) {
  1452. continue;
  1453. }
  1454. if (matchedDefinitionClass != null) {
  1455. throw new BuildException(
  1456. "ambiguous: restricted definitions for "
  1457. + componentName + " "
  1458. + matchedDefinitionClass + " and " + exposedClass);
  1459. }
  1460. matchedDefinitionClass = exposedClass;
  1461. definition = d;
  1462. }
  1463. return definition;
  1464. }
  1465. private MethodAndObject createRestricted(
  1466. ComponentHelper helper, String elementName, List addTypeMethods) {
  1467. Project project = helper.getProject();
  1468. AntTypeDefinition restrictedDefinition =
  1469. findRestrictedDefinition(helper, elementName, addTypeMethods);
  1470. if (restrictedDefinition == null) {
  1471. return null;
  1472. }
  1473. Method addMethod = findMatchingMethod(
  1474. restrictedDefinition.getExposedClass(project), addTypeMethods);
  1475. if (addMethod == null) {
  1476. throw new BuildException(
  1477. "Ant Internal Error - contract mismatch for "
  1478. + elementName);
  1479. }
  1480. Object addedObject = restrictedDefinition.create(project);
  1481. if (addedObject == null) {
  1482. throw new BuildException(
  1483. "Failed to create object " + elementName
  1484. + " of type " + restrictedDefinition.getTypeClass(project));
  1485. }
  1486. return new MethodAndObject(addMethod, addedObject);
  1487. }
  1488. private MethodAndObject createTopLevel(
  1489. ComponentHelper helper, String elementName, List methods) {
  1490. Class clazz = helper.getComponentClass(elementName);
  1491. if (clazz == null) {
  1492. return null;
  1493. }
  1494. Method addMethod = findMatchingMethod(clazz, addTypeMethods);
  1495. if (addMethod == null) {
  1496. return null;
  1497. }
  1498. Object addedObject = helper.createComponent(elementName);
  1499. return new MethodAndObject(addMethod, addedObject);
  1500. }
  1501. }