private IvyTag typedefedTag()

in org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java [233:306]


    private IvyTag typedefedTag(String tagName, final Class<?> clazz) {
        return new IvyTag(tagName) {
            // we lazy load children, since we may have a loop in children (chain can contain chain)
            // causing a stack overflow if we try to recursively add typedefed children
            private boolean init = false;
            public List<IvyTagAttribute> getAttributes() {
                init();
                return super.getAttributes();
            }

            public List<IvyTag> getChilds() {
                init();
                return super.getChilds();
            }

            public boolean hasChild() {
                init();
                return super.hasChild();
            }

            private void init() {
                if (!init) {
                    try {
                        for (Method m : clazz.getMethods()) {
                            if (m.getName().startsWith("create")
                                    && m.getParameterTypes().length == 0
                                    && isSupportedChildType(m.getReturnType())) {
                                String name = StringUtils
                                    .uncapitalize(m.getName().substring("create".length()));
                                if (name.length() == 0) {
                                    continue;
                                }
                                addChildIvyTag(typedefedTag(name, m.getReturnType()));
                            } else if (m.getName().startsWith("add")
                                    && m.getParameterTypes().length == 1
                                    && isSupportedChildType(m.getParameterTypes()[0])
                                    && Void.TYPE.equals(m.getReturnType())) {
                                String name = StringUtils.uncapitalize(m.getName().substring(
                                    m.getName().startsWith("addConfigured") ? "addConfigured"
                                            .length() : "add".length()));
                                if (name.length() == 0) {
                                    addTypedefChildren(this, getChildClasses(typedefClasses, m
                                            .getParameterTypes()[0]));
                                } else {
                                    addChildIvyTag(typedefedTag(name, m.getParameterTypes()[0]));
                                }
                            } else if (m.getName().startsWith("set")
                                    && Void.TYPE.equals(m.getReturnType())
                                    && m.getParameterTypes().length == 1
                                    && isSupportedAttributeType(m.getParameterTypes()[0])) {
                                IvyTagAttribute att = new IvyTagAttribute(StringUtils
                                        .uncapitalize(m.getName().substring("set".length())));
                                if (m.getParameterTypes()[0] == boolean.class) {
                                    att.setValueProvider(IvyBooleanTagAttribute.VALUE_PROVIDER);
                                }
                                addAttribute(att);
                            }
                        }
                    } catch (NoClassDefFoundError e) {
                        // we catch this because listing methods may raise a NoClassDefFoundError
                        // if the class relies on a dependency which is not available in classpath
                        getSettings().logError(
                            "impossible to init tag for " + clazz + ": " + e,
                            null);
                    } catch (Exception e) {
                        getSettings().logError(
                            "error occurred while initializing tag for " + clazz + ": " + e,
                            e);
                    }
                    init = true;
                }
            }
        };
    }