⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 projecthelperimpl.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
         * @param parentHandler The handler which should be restored to the         *                      parser at the end of the element.         *                      Must not be <code>null</code>.         *         * @param container     Container for the element.         *                      Must not be <code>null</code>.         *         * @param parentWrapper Wrapper for the parent element, if any.         *                      May be <code>null</code>.         *         * @param target        Target this element is part of.         *                      Must not be <code>null</code>.         */        public TaskHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler,                           TaskContainer container,                           RuntimeConfigurable parentWrapper, Target target) {            super(helperImpl, parentHandler);            this.container = container;            this.parentWrapper = parentWrapper;            this.target = target;        }        /**         * Initialisation routine called after handler creation         * with the element name and attributes. This configures         * the element with its attributes and sets it up with         * its parent container (if any). Nested elements are then         * added later as the parser encounters them.         *         * @param tag Name of the element which caused this handler         *            to be created. Must not be <code>null</code>.         *         * @param attrs Attributes of the element which caused this         *              handler to be created. Must not be <code>null</code>.         *         * @exception SAXParseException in case of error (not thrown in         *                              this implementation)         */        public void init(String tag, AttributeList attrs) throws SAXParseException {            try {                task = helperImpl.project.createTask(tag);            } catch (BuildException e) {                // swallow here, will be thrown again in                // UnknownElement.maybeConfigure if the problem persists.            }            if (task == null) {                task = new UnknownElement(tag);                task.setProject(helperImpl.project);                //XXX task.setTaskType(tag);                task.setTaskName(tag);            }            task.setLocation(new Location(helperImpl.locator));            helperImpl.configureId(task, attrs);            task.setOwningTarget(target);            container.addTask(task);            task.init();            wrapper = task.getRuntimeConfigurableWrapper();            wrapper.setAttributes(attrs);            if (parentWrapper != null) {                parentWrapper.addChild(wrapper);            }        }        /**         * Adds text to the task, using the wrapper.         *         * @param buf A character array of the text within the element.         *            Will not be <code>null</code>.         * @param start The start element in the array.         * @param count The number of characters to read from the array.         */        public void characters(char[] buf, int start, int count) {            wrapper.addText(buf, start, count);        }        /**         * Handles the start of an element within a target. Task containers         * will always use another task handler, and all other tasks         * will always use a nested element handler.         *         * @param name The name of the element being started.         *            Will not be <code>null</code>.         * @param attrs Attributes of the element being started.         *              Will not be <code>null</code>.         *         * @exception SAXParseException if an error occurs when initialising         *                              the appropriate child handler         */        public void startElement(String name, AttributeList attrs) throws SAXParseException {            if (task instanceof TaskContainer) {                // task can contain other tasks - no other nested elements possible                new TaskHandler(helperImpl, this, (TaskContainer) task,                    wrapper, target).init(name, attrs);            } else {                new NestedElementHandler(helperImpl, this, task,                    wrapper, target).init(name, attrs);            }        }    }    /**     * Handler for all nested properties.     */    static class NestedElementHandler extends AbstractHandler {        /** Parent object (task/data type/etc). */        private Object parent;        /** The nested element itself. */        private Object child;        /**         * Wrapper for the parent element, if any. The wrapper for this         * element will be added to this wrapper as a child.         */        private RuntimeConfigurable parentWrapper;        /**         * Wrapper for this element which takes care of actually configuring         * the element, if a parent wrapper is provided.         * Otherwise the configuration is performed with the configure method.         * @see ProjectHelper#configure(Object,AttributeList,Project)         */        private RuntimeConfigurable childWrapper = null;        /** Target this element is part of, if any. */        private Target target;        /**         * Constructor.         *         * @param parentHandler The handler which should be restored to the         *                      parser at the end of the element.         *                      Must not be <code>null</code>.         *         * @param parent        Parent of this element (task/data type/etc).         *                      Must not be <code>null</code>.         *         * @param parentWrapper Wrapper for the parent element, if any.         *                      Must not be <code>null</code>.         *         * @param target        Target this element is part of.         *                      Must not be <code>null</code>.         */        public NestedElementHandler(ProjectHelperImpl helperImpl,                                    DocumentHandler parentHandler,                                    Object parent,                                    RuntimeConfigurable parentWrapper,                                    Target target) {            super(helperImpl, parentHandler);            if (parent instanceof TypeAdapter) {                this.parent = ((TypeAdapter) parent).getProxy();            } else {                this.parent = parent;            }            this.parentWrapper = parentWrapper;            this.target = target;        }        /**         * Initialisation routine called after handler creation         * with the element name and attributes. This configures         * the element with its attributes and sets it up with         * its parent container (if any). Nested elements are then         * added later as the parser encounters them.         *         * @param propType Name of the element which caused this handler         *            to be created. Must not be <code>null</code>.         *         * @param attrs Attributes of the element which caused this         *              handler to be created. Must not be <code>null</code>.         *         * @exception SAXParseException in case of error, such as a         *            BuildException being thrown during configuration.         */        public void init(String propType, AttributeList attrs) throws SAXParseException {            Class parentClass = parent.getClass();            IntrospectionHelper ih =                IntrospectionHelper.getHelper(helperImpl.project, parentClass);            try {                String elementName = propType.toLowerCase(Locale.US);                if (parent instanceof UnknownElement) {                    UnknownElement uc = new UnknownElement(elementName);                    uc.setProject(helperImpl.project);                    ((UnknownElement) parent).addChild(uc);                    child = uc;                } else {                    child = ih.createElement(helperImpl.project, parent, elementName);                }                helperImpl.configureId(child, attrs);                childWrapper = new RuntimeConfigurable(child, propType);                childWrapper.setAttributes(attrs);                parentWrapper.addChild(childWrapper);            } catch (BuildException exc) {                throw new SAXParseException(exc.getMessage(), helperImpl.locator, exc);            }        }        /**         * Adds text to the element, using the wrapper.         *         * @param buf A character array of the text within the element.         *            Will not be <code>null</code>.         * @param start The start element in the array.         * @param count The number of characters to read from the array.         */        public void characters(char[] buf, int start, int count) {            childWrapper.addText(buf, start, count);        }        /**         * Handles the start of an element within this one. Task containers         * will always use a task handler, and all other elements         * will always use another nested element handler.         *         * @param name The name of the element being started.         *            Will not be <code>null</code>.         * @param attrs Attributes of the element being started.         *              Will not be <code>null</code>.         *         * @exception SAXParseException if an error occurs when initialising         *                              the appropriate child handler         */        public void startElement(String name, AttributeList attrs) throws SAXParseException {            if (child instanceof TaskContainer) {                // taskcontainer nested element can contain other tasks - no other                // nested elements possible                new TaskHandler(helperImpl, this, (TaskContainer) child,                    childWrapper, target).init(name, attrs);            } else {                new NestedElementHandler(helperImpl, this, child,                    childWrapper, target).init(name, attrs);            }        }    }    /**     * Handler for all data types directly subordinate to project or target.     */    static class DataTypeHandler extends AbstractHandler {        /** Parent target, if any. */        private Target target;        /** The element being configured. */        private Object element;        /** Wrapper for this element, if it's part of a target. */        private RuntimeConfigurable wrapper = null;        /**         * Constructor with a target specified.         *         * @param parentHandler The handler which should be restored to the         *                      parser at the end of the element.         *                      Must not be <code>null</code>.         *         * @param target The parent target of this element.         *               Must not be <code>null</code>.         */        public DataTypeHandler(ProjectHelperImpl helperImpl,                               DocumentHandler parentHandler, Target target) {            super(helperImpl, parentHandler);            this.target = target;        }        /**         * Initialisation routine called after handler creation         * with the element name and attributes. This configures         * the element with its attributes and sets it up with         * its parent container (if any). Nested elements are then         * added later as the parser encounters them.         *         * @param propType Name of the element which caused this handler         *            to be created. Must not be <code>null</code>.         *         * @param attrs Attributes of the element which caused this         *              handler to be created. Must not be <code>null</code>.         *         * @exception SAXParseException in case of error, such as a         *            BuildException being thrown during configuration.         */        public void init(String propType, AttributeList attrs) throws SAXParseException {            try {                element = helperImpl.project.createDataType(propType);                if (element == null) {                    throw new BuildException("Unknown data type " + propType);                }                wrapper = new RuntimeConfigurable(element, propType);                wrapper.setAttributes(attrs);                target.addDataType(wrapper);            } catch (BuildException exc) {                throw new SAXParseException(exc.getMessage(), helperImpl.locator, exc);            }        }        /**         * Adds text to the using the wrapper.         *         * @param buf A character array of the text within the element.         *            Will not be <code>null</code>.         * @param start The start element in the array.         * @param count The number of characters to read from the array.         *         * @see ProjectHelper#addText(Project,Object,char[],int,int)         */        public void characters(char[] buf, int start, int count) {            wrapper.addText(buf, start, count);        }        /**         * Handles the start of an element within this one.         * This will always use a nested element handler.         *         * @param name The name of the element being started.         *            Will not be <code>null</code>.         * @param attrs Attributes of the element being started.         *              Will not be <code>null</code>.         *         * @exception SAXParseException if an error occurs when initialising         *                              the child handler         */        public void startElement(String name, AttributeList attrs) throws SAXParseException {            new NestedElementHandler(helperImpl, this, element, wrapper, target).init(name, attrs);        }    }    /**     * Scans an attribute list for the <code>id</code> attribute and     * stores a reference to the target object in the project if an     * id is found.     * <p>     * This method was moved out of the configure method to allow     * it to be executed at parse time.     *     * @see #configure(Object,AttributeList,Project)     */    private void configureId(Object target, AttributeList attr) {        String id = attr.getValue("id");        if (id != null) {            project.addReference(id, target);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -