Example usage for org.apache.commons.digester Digester pop

List of usage examples for org.apache.commons.digester Digester pop

Introduction

In this page you can find the example usage for org.apache.commons.digester Digester pop.

Prototype

public Object pop() 

Source Link

Document

Pop the top object off of the stack, and return it.

Usage

From source file:com.alibaba.antx.config.descriptor.ConfigDescriptorLoader.java

/** ?validator */
public synchronized Map loadValidatorClasses() {
    Digester digester = loadValidatorPlugins();

    return (Map) digester.pop();
}

From source file:org.eclipse.wb.internal.core.model.description.helpers.FactoryDescriptionHelper.java

/**
 * Adds {@link Rule}'s for factory description parsing.
 *//*www.  j ava 2s . c  o  m*/
private static void addRules(Digester digester, EditorState state, final Class<?> declaringClass) {
    // allMethodsAreFactories flag
    {
        String pattern = "factory/allMethodsAreFactories";
        digester.addRule(pattern, new Rule() {
            @Override
            public void body(String namespace, String name, String text) throws Exception {
                Object list = getDigester().pop();
                Boolean allMethodsAreFactories = (Boolean) getDigester().pop();
                if ("true".equalsIgnoreCase(text)) {
                    allMethodsAreFactories = Boolean.TRUE;
                }
                if ("false".equalsIgnoreCase(text)) {
                    allMethodsAreFactories = Boolean.FALSE;
                }
                getDigester().push(allMethodsAreFactories);
                getDigester().push(list);
            }
        });
    }
    // methods
    {
        String pattern = "factory/method";
        digester.addRule(pattern, new Rule() {
            @Override
            public void begin(String namespace, String name, Attributes attributes) throws Exception {
                FactoryMethodDescription factoryMethodDescription = new FactoryMethodDescription(
                        declaringClass);
                Boolean allMethodsAreFactories = (Boolean) getDigester().peek(1);
                factoryMethodDescription.setFactory(
                        allMethodsAreFactories != null ? allMethodsAreFactories.booleanValue() : true);
                digester.push(factoryMethodDescription);
            }

            @Override
            public void end(String namespace, String name) throws Exception {
                digester.pop();
            }
        });
        digester.addSetProperties(pattern);
        digester.addSetNext(pattern, "add");
        digester.addCallMethod(pattern, "postProcess");
        ComponentDescriptionHelper.addParametersRules(digester, pattern + "/parameter", state);
    }
    // invocation
    {
        String pattern = "factory/method/invocation";
        digester.addRule(pattern, new ObjectCreateRule(CreationInvocationDescription.class));
        digester.addRule(pattern, new SetListedPropertiesRule(new String[] { "signature" }));
        // arguments
        digester.addCallMethod(pattern, "setArguments", 1);
        digester.addCallParam(pattern, 0);
        // add
        digester.addSetNext(pattern, "addInvocation");
    }
    // name text
    {
        String pattern = "factory/method/name";
        digester.addCallMethod(pattern, "setPresentationName", 1);
        digester.addCallParam(pattern, 0);
    }
    // untyped parameters
    {
        String pattern = "factory/method/parameters/parameter";
        digester.addCallMethod(pattern, "addParameter", 2);
        digester.addCallParam(pattern, 0, "name");
        digester.addCallParam(pattern, 1);
    }
}

From source file:org.eclipse.wb.internal.core.model.description.LayoutDescription.java

private void loadDescription() throws Exception {
    // prepare resource
    String resourcePath = m_layoutClassName.replace('.', '/') + ".wbp-component.xml";
    ResourceInfo resourceInfo = DescriptionHelper.getResourceInfo(resourcePath, m_toolkit.getId());
    if (resourceInfo == null) {
        DesignerPlugin.log("Not found resource " + m_layoutClassName.replace('.', '/') + ".wbp-component.xml"
                + " in bundle " + m_toolkit.getId());
        return;//from w w  w . jav a  2 s .c om
    }
    Digester digester;
    // prepare digester
    {
        digester = new Digester();
        digester.setLogger(new NoOpLog());
        digester.addRule("component/creation", new Rule() {
            @Override
            public void begin(String namespace, String name, Attributes attributes) throws Exception {
                final String id = attributes.getValue("id");
                digester.push(id != null ? id : StringUtils.EMPTY);
            }

            @Override
            public void end(String namespace, String name) throws Exception {
                digester.pop();
            }
        });
        digester.addRule("component/creation/source", new Rule() {
            @Override
            public void body(String namespace, String name, String text) throws Exception {
                final String id = (String) digester.peek();
                if (id.equals(m_creationId)) {
                    m_source = text;
                }
            }
        });
    }
    // do parse
    InputStream is = resourceInfo.getURL().openStream();
    try {
        digester.parse(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:org.eclipse.wb.internal.swing.ams.model.property.ConfigurationReader.java

private static List<PropertyGroup> parsePropertyGroups(InputStream input) throws Exception {
    final List<PropertyGroup> groups = Lists.newArrayList();
    // prepare Digester
    Digester digester;
    {//w ww.j a va  2s  .  c  om
        digester = new Digester();
        digester.setLogger(new NoOpLog());
        // groups/group
        {
            String pattern = "groups/group";
            digester.addRule(pattern, new Rule() {
                @Override
                public void begin(String namespace, String element, Attributes attributes) throws Exception {
                    // prepare required name
                    String name = attributes.getValue("name");
                    Assert.isNotNull(name, Messages.ConfigurationReader_errGroup_noNameAttribute);
                    // prepare optional description
                    String description = attributes.getValue("description");
                    Assert.isNotNull(name, Messages.ConfigurationReader_errGroup_noDescriptionAttribute);
                    // prepare optional category
                    PropertyCategory category = null;
                    {
                        String categoryString = attributes.getValue("category");
                        if (categoryString != null) {
                            category = PropertyCategory.get(categoryString, null);
                        }
                    }
                    // add group
                    PropertyGroup group = new PropertyGroup(name, description, category);
                    digester.push(group);
                    groups.add(group);
                }

                @Override
                public void end(String namespace, String name) throws Exception {
                    digester.pop();
                    super.end(namespace, name);
                }
            });
        }
        // groups/group/property
        {
            String pattern = "groups/group/property";
            digester.addRule(pattern, new Rule() {
                @Override
                public void begin(String namespace, String name, Attributes attributes) throws Exception {
                    // prepare required name
                    String propertyName = attributes.getValue("name");
                    Assert.isNotNull(propertyName, Messages.ConfigurationReader_errProperty_noNameAttribute);
                    // prepare optional category
                    PropertyCategory category = null;
                    {
                        String categoryString = attributes.getValue("category");
                        if (categoryString != null) {
                            category = PropertyCategory.get(categoryString, null);
                        }
                    }
                    // add property
                    PropertyGroup group = (PropertyGroup) digester.peek();
                    group.addProperty(new PropertyConfiguration(propertyName, category));
                }
            });
        }
        // groups/group/other-properties
        {
            String pattern = "groups/group/other-properties";
            digester.addRule(pattern, new Rule() {
                @Override
                public void begin(String namespace, String name, Attributes attributes) throws Exception {
                    PropertyGroup group = (PropertyGroup) digester.peek();
                    group.addProperty(new PropertyConfiguration(null, null));
                }
            });
        }
    }
    // read XML
    try {
        digester.push(groups);
        digester.parse(input);
    } finally {
        IOUtils.closeQuietly(input);
    }
    // done
    return groups;
}

From source file:org.eclipse.wb.internal.xwt.parser.XwtDescriptionRulesProvider.java

/**
 * Parses {@link StylePropertyEditor} specification for constructor parameter and remember it as
 * arbitrary value in {@link ComponentDescription}.
 *//*www  .  j av  a2  s .  c om*/
private void addRule_forStylePropertyEditor(Digester digester, final EditorContext context) {
    String pattern = "component/constructors/constructor/parameter/editor";
    digester.addRule(pattern, new Rule() {
        @Override
        public void begin(String namespace, String name, Attributes attributes) throws Exception {
            String editorId = attributes.getValue("id");
            PropertyEditor editor = DescriptionPropertiesHelper.getConfigurableEditor(editorId);
            digester.push(new PropertyEditorDescription(context, editor));
        }

        @Override
        public void end(String namespace, String name) throws Exception {
            // prepare editor
            PropertyEditor configuredEditor;
            {
                PropertyEditorDescription description = (PropertyEditorDescription) digester.pop();
                configuredEditor = description.getConfiguredEditor();
            }
            // remember editor
            if (configuredEditor instanceof StylePropertyEditor) {
                ComponentDescription componentDescription = (ComponentDescription) digester.peek();
                Class<StylePropertyEditor> key = StylePropertyEditor.class;
                // XXX
                /*if (componentDescription.getArbitraryValue(key) == null)*/ {
                    componentDescription.putArbitraryValue(key, configuredEditor);
                }
            }
        }
    });
    ComponentDescriptionHelper.addConfigurableObjectParametersRules(digester, pattern);
}