Java 类org.apache.tools.ant.RuntimeConfigurable 实例源码

项目:ant    文件:ProjectHelperImpl.java   
/**
 * 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.ENGLISH);
        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);
    }
}
项目:ant    文件:BaseIfAttribute.java   
/**
 * Get all the attributes in the ant-attribute:param
 * namespace and place them in a map.
 * @param el the element this attribute is in.
 * @return a map of attributes.
 */
protected Map<String, String> getParams(UnknownElement el) {
    Map<String, String> ret = new HashMap<>();
    RuntimeConfigurable rc = el.getWrapper();
    Hashtable<String, Object> attributes = rc.getAttributeMap(); // This does a copy!
    for (Iterator<Map.Entry<String, Object>> i =
        attributes.entrySet().iterator(); i.hasNext();) {
        Map.Entry<String, Object> entry = i.next();
        String key = entry.getKey();
        String value = (String) entry.getValue();
        if (key.startsWith("ant-attribute:param")) {
            int pos = key.lastIndexOf(':');
            ret.put(key.substring(pos + 1),
                el.getProject().replaceProperties(value));
        }
    }
    return ret;
}
项目:ant    文件:MacroDef.java   
/**
 * Convert the nested sequential to an unknown element
 * @return the nested sequential as an unknown element.
 */
public UnknownElement getNestedTask() {
    UnknownElement ret = new UnknownElement("sequential");
    ret.setTaskName("sequential");
    ret.setNamespace("");
    ret.setQName("sequential");
    // stores RuntimeConfigurable as "RuntimeConfigurableWrapper"
    // in ret as side effect
    new RuntimeConfigurable(ret, "sequential"); //NOSONAR
    final int size = nestedSequential.getNested().size();
    for (int i = 0; i < size; ++i) {
        UnknownElement e =
            (UnknownElement) nestedSequential.getNested().get(i);
        ret.addChild(e);
        ret.getWrapper().addChild(e.getWrapper());
    }
    return ret;
}
项目:incubator-netbeans    文件:NbBuildLogger.java   
private static Map<String,String> getAttributeMapOfRuntimeConfigurable(RuntimeConfigurable rc) {
    Map<String, String> m = new HashMap<String, String>();
    if (runtimeConfigurableGetAttributeMap != null) {
        try {
            for (Map.Entry<?,?> entry : ((Map<?,?>) runtimeConfigurableGetAttributeMap.invoke(rc)).entrySet()) {
                m.put(((String) entry.getKey()).toLowerCase(Locale.ENGLISH), (String) entry.getValue());
            }
        } catch (Exception e) {
            LOG.log(Level.WARNING, null, e);
        }
    }
    return m;
}
项目:incubator-netbeans    文件:NbBuildLogger.java   
@SuppressWarnings("unchecked")
private static Enumeration<RuntimeConfigurable> getChildrenOfRuntimeConfigurable(RuntimeConfigurable rc) {
    if (runtimeConfigurableGetChildren != null) {
        try {
            return (Enumeration<RuntimeConfigurable>) runtimeConfigurableGetChildren.invoke(rc);
        } catch (Exception e) {
            LOG.log(Level.WARNING, null, e);
        }
    }
    return Collections.enumeration(Collections.<RuntimeConfigurable>emptySet());
}
项目:incubator-netbeans    文件:NbBuildLogger.java   
private static String getTextOfRuntimeConfigurable(RuntimeConfigurable rc) {
    if (runtimeConfigurableGetText != null) {
        try {
            return ((StringBuffer) runtimeConfigurableGetText.invoke(rc)).toString();
        } catch (Exception e) {
            LOG.log(Level.WARNING, null, e);
        }
    }
    return "";
}
项目:incubator-netbeans    文件:NbBuildLogger.java   
public @Override TaskStructure[] getChildren() {
    verifyRunning();
    List<TaskStructure> structures = new ArrayList<TaskStructure>();
    for (RuntimeConfigurable subrc : NbCollections.iterable(getChildrenOfRuntimeConfigurable(rc))) {
        structures.add(LoggerTrampoline.TASK_STRUCTURE_CREATOR.makeTaskStructure(new TaskStructureImpl(subrc)));
    }
    return structures.toArray(new TaskStructure[structures.size()]);
}
项目:groovy    文件:AntBuilder.java   
protected Object createNode(final Object name, final Map attributes) {

        final Attributes attrs = buildAttributes(attributes);
        String tagName = name.toString();
        String ns = "";

        if (name instanceof QName) {
            QName q = (QName) name;
            tagName = q.getLocalPart();
            ns = q.getNamespaceURI();
        }

        // import can be used only as top level element
        if ("import".equals(name)) {
            antXmlContext.setCurrentTarget(implicitTarget);
        } else if ("target".equals(name) && !insideTask) {
            return onStartTarget(attrs, tagName, ns);
        } else if ("defineTarget".equals(name) && !insideTask) {
            return onDefineTarget(attrs, "target", ns);
        }

        try {
            antElementHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext);
        }
        catch (final SAXParseException e) {
            log.log(Level.SEVERE, "Caught: " + e, e);
        }

        insideTask = true;
        final RuntimeConfigurable wrapper = antXmlContext.getWrapperStack().lastElement();
        return wrapper.getProxy();
    }
项目:ant    文件:AntXMLContext.java   
/**
 * get the current runtime configurable wrapper
 * can return null
 * @return runtime configurable wrapper
 */
public RuntimeConfigurable currentWrapper() {
    if (wStack.size() < 1) {
        return null;
    }
    return (RuntimeConfigurable) wStack.elementAt(wStack.size() - 1);
}
项目:ant    文件:AntXMLContext.java   
/**
 * get the runtime configurable wrapper of the parent project
 * can return null
 * @return runtime configurable wrapper  of the parent project
 */
public RuntimeConfigurable parentWrapper() {
    if (wStack.size() < 2) {
        return null;
    }
    return (RuntimeConfigurable) wStack.elementAt(wStack.size() - 2);
}
项目:ant    文件:AugmentReference.java   
private synchronized void hijackId() {
    if (id == null) {
        RuntimeConfigurable wrapper = getWrapper();
        id = wrapper.getId();
        if (id == null) {
            throw new IllegalStateException(getTaskName() + " attribute 'id' unset");
        }
        wrapper.setAttribute("id", null);
        wrapper.removeAttribute("id");
        wrapper.setElementTag("augmented reference \"" + id + "\"");
    }
}
项目:ant    文件:AugmentReference.java   
/**
 * Needed if two different targets reuse the same instance.
 * @see "https://issues.apache.org/bugzilla/show_bug.cgi?id=50894"
 */
private synchronized void restoreWrapperId() {
    if (id != null) {
        log("restoring augment wrapper " + id, Project.MSG_DEBUG);
        RuntimeConfigurable wrapper = getWrapper();
        wrapper.setAttribute("id", id);
        wrapper.setElementTag(getTaskName());
        id = null;
    }
}
项目:incubator-netbeans    文件:NbBuildLogger.java   
public TaskStructureImpl(RuntimeConfigurable rc) {
    this.rc = rc;
}
项目:ant    文件:ProjectHelperImpl.java   
/**
 * 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;
}
项目:ant-easyant-core    文件:Phase.java   
/**
 * Throws an exception.
 */
public final void addDataType(RuntimeConfigurable r) {
    throw new BuildException(NO_CHILDREN_ALLOWED);
}
项目:ant    文件:ProjectHelper2.java   
/**
 * 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.
 * @param context The current context.
 *
 * @exception SAXParseException if the element doesn't support text
 *
 * @see ProjectHelper#addText(Project,java.lang.Object,char[],int,int)
 */
@Override
public void characters(char[] buf, int start, int count,
                       AntXMLContext context) throws SAXParseException {
    RuntimeConfigurable wrapper = context.currentWrapper();
    wrapper.addText(buf, start, count);
}
项目:ant    文件:ProjectHelperImpl.java   
/**
 * 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 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;
}
项目:ant    文件:ProjectHelperImpl.java   
/**
 * 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);
    }
}
项目:ant    文件:AntXMLContext.java   
/**
 * add a runtime configurable wrapper to the internal stack
 * @param wrapper runtime configurable wrapper
 */
public void pushWrapper(RuntimeConfigurable wrapper) {
    wStack.addElement(wrapper);
}
项目:ant    文件:AntXMLContext.java   
/**
 * access the stack of wrappers
 * @return the stack of wrappers
 */
public Vector<RuntimeConfigurable> getWrapperStack() {
    return wStack;
}