Java Code Examples for org.apache.tomcat.util.IntrospectionUtils

The following examples show how to use org.apache.tomcat.util.IntrospectionUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Tomcat8-Source-Read   Source File: SetAllPropertiesRule.java    License: MIT License 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        String value = attributes.getValue(i);
        if ( !excludes.containsKey(name)) {
            if (!digester.isFakeAttribute(digester.peek(), name)
                    && !IntrospectionUtils.setProperty(digester.peek(), name, value)
                    && digester.getRulesValidation()) {
                digester.getLogger().warn("[SetAllPropertiesRule]{" + digester.getMatch() +
                        "} Setting property '" + name + "' to '" +
                        value + "' did not find a matching property.");
            }
        }
    }

}
 
Example 2
Source Project: Tomcat8-Source-Read   Source File: SetContextPropertiesRule.java    License: MIT License 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        if ("path".equals(name) || "docBase".equals(name)) {
            continue;
        }
        String value = attributes.getValue(i);
        if (!digester.isFakeAttribute(digester.peek(), name)
                && !IntrospectionUtils.setProperty(digester.peek(), name, value)
                && digester.getRulesValidation()) {
            digester.getLogger().warn("[SetContextPropertiesRule]{" + digester.getMatch() +
                    "} Setting property '" + name + "' to '" +
                    value + "' did not find a matching property.");
        }
    }

}
 
Example 3
Source Project: Tomcat8-Source-Read   Source File: SetNextNamingRule.java    License: MIT License 6 votes vote down vote up
/**
 * Process the end of this element.
 *
 * @param namespace the namespace URI of the matching element, or an
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);

    NamingResourcesImpl namingResources = null;
    if (parent instanceof Context) {
        namingResources = ((Context) parent).getNamingResources();
    } else {
        namingResources = (NamingResourcesImpl) parent;
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(namingResources, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example 4
Source Project: Tomcat8-Source-Read   Source File: ConnectorMBean.java    License: MIT License 6 votes vote down vote up
/**
 * Set the value of a specific attribute of this MBean.
 *
 * @param attribute The identification of the attribute to be set
 *  and the new value
 *
 * @exception AttributeNotFoundException if this attribute is not
 *  supported by this MBean
 * @exception MBeanException if the initializer of an object
 *  throws an exception
 * @exception ReflectionException if a Java reflection exception
 *  occurs when invoking the getter
 */
 @Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
        ReflectionException {

    // Validate the input parameters
    if (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(
                "Attribute is null"), "Attribute is null");
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
        throw new RuntimeOperationsException(
                new IllegalArgumentException("Attribute name is null"),
                "Attribute name is null");
    }

    Connector connector = doGetManagedResource();
    IntrospectionUtils.setProperty(connector, name, String.valueOf(value));
}
 
Example 5
Source Project: Tomcat8-Source-Read   Source File: StoreAppender.java    License: MIT License 6 votes vote down vote up
/**
 * Check if the attribute should be printed.
 * @param desc RegistryDescriptor from this bean
 * @param descriptor PropertyDescriptor from this bean property
 * @param attributeName The attribute name to store
 * @param bean The current bean
 * @param bean2 A default instance of the bean for comparison
 * @return null if the value should be skipped, the value to print otherwise
 */
protected Object checkAttribute(StoreDescription desc, PropertyDescriptor descriptor, String attributeName, Object bean, Object bean2) {
    if (descriptor instanceof IndexedPropertyDescriptor) {
        return null; // Indexed properties are not persisted
    }
    if (!isPersistable(descriptor.getPropertyType())
            || (descriptor.getReadMethod() == null)
            || (descriptor.getWriteMethod() == null)) {
        return null; // Must be a read-write primitive or String
    }
    if (desc.isTransientAttribute(descriptor.getName())) {
        return null; // Skip the specified exceptions
    }
    Object value = IntrospectionUtils.getProperty(bean, descriptor.getName());
    if (value == null) {
        return null; // Null values are not persisted
    }
    Object value2 = IntrospectionUtils.getProperty(bean2, descriptor.getName());
    if (value.equals(value2)) {
        // The property has its default value
        return null;
    }
    return value;
}
 
Example 6
Source Project: Tomcat8-Source-Read   Source File: FilterBase.java    License: MIT License 6 votes vote down vote up
/**
 * Iterates over the configuration parameters and either logs a warning,
 * or throws an exception for any parameter that does not have a matching
 * setter in this filter.
 *
 * @param filterConfig The configuration information associated with the
 *                     filter instance being initialised
 *
 * @throws ServletException if {@link #isConfigProblemFatal()} returns
 *                          {@code true} and a configured parameter does not
 *                          have a matching setter
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    Enumeration<String> paramNames = filterConfig.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        if (!IntrospectionUtils.setProperty(this, paramName,
                filterConfig.getInitParameter(paramName))) {
            String msg = sm.getString("filterbase.noSuchProperty",
                    paramName, this.getClass().getName());
            if (isConfigProblemFatal()) {
                throw new ServletException(msg);
            } else {
                getLogger().warn(msg);
            }
        }
    }
}
 
Example 7
Source Project: Tomcat8-Source-Read   Source File: Digester.java    License: MIT License 6 votes vote down vote up
public static void replaceSystemProperties() {
    Log log = LogFactory.getLog(Digester.class);
    if (propertySource != null) {
        IntrospectionUtils.PropertySource[] propertySources =
                new IntrospectionUtils.PropertySource[] { propertySource };
        Properties properties = System.getProperties();
        Set<String> names = properties.stringPropertyNames();
        for (String name : names) {
            String value = System.getProperty(name);
            if (value != null) {
                try {
                    String newValue = IntrospectionUtils.replaceProperties(value, null, propertySources, null);
                    if (!value.equals(newValue)) {
                        System.setProperty(name, newValue);
                    }
                } catch (Exception e) {
                    log.warn(sm.getString("digester.failedToUpdateSystemProperty", name, value), e);
                }
            }
        }
    }
}
 
Example 8
Source Project: Tomcat8-Source-Read   Source File: Digester.java    License: MIT License 6 votes vote down vote up
/**
 * Returns an attributes list which contains all the attributes
 * passed in, with any text of form "${xxx}" in an attribute value
 * replaced by the appropriate value from the system property.
 */
private Attributes updateAttributes(Attributes list) {

    if (list.getLength() == 0) {
        return list;
    }

    AttributesImpl newAttrs = new AttributesImpl(list);
    int nAttributes = newAttrs.getLength();
    for (int i = 0; i < nAttributes; ++i) {
        String value = newAttrs.getValue(i);
        try {
            newAttrs.setValue(i, IntrospectionUtils.replaceProperties(value, null, source, getClassLoader()).intern());
        } catch (Exception e) {
            log.warn(sm.getString("digester.failedToUpdateAttributes", newAttrs.getLocalName(i), value), e);
        }
    }

    return newAttrs;
}
 
Example 9
Source Project: Tomcat8-Source-Read   Source File: Digester.java    License: MIT License 6 votes vote down vote up
/**
 * Return a new StringBuilder containing the same contents as the
 * input buffer, except that data of form ${varname} have been
 * replaced by the value of that var as defined in the system property.
 */
private StringBuilder updateBodyText(StringBuilder bodyText) {
    String in = bodyText.toString();
    String out;
    try {
        out = IntrospectionUtils.replaceProperties(in, null, source, getClassLoader());
    } catch (Exception e) {
        return bodyText; // return unchanged data
    }

    if (out == in) {
        // No substitutions required. Don't waste memory creating
        // a new buffer
        return bodyText;
    } else {
        return new StringBuilder(out);
    }
}
 
Example 10
Source Project: Tomcat8-Source-Read   Source File: SetNextRule.java    License: MIT License 6 votes vote down vote up
/**
 * Process the end of this element.
 *
 * @param namespace the namespace URI of the matching element, or an
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call [NULL PARENT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example 11
Source Project: Tomcat8-Source-Read   Source File: TesterInjectionServlet.java    License: MIT License 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    resp.setContentType("text/plain");
    resp.setCharacterEncoding("UTF-8");

    String injectionName = req.getParameter("injectionName");

    PrintWriter pw = resp.getWriter();
    pw.print(IntrospectionUtils.getProperty(this, injectionName));

    // The property should tyake precedence over the field and this should
    // be null
    if (getProperty2a() != null) {
        pw.println();
        pw.print(getProperty2a());
    }
}
 
Example 12
Source Project: Tomcat7.0.67   Source File: SetAllPropertiesRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        String value = attributes.getValue(i);
        if ( !excludes.containsKey(name)) {
            if (!digester.isFakeAttribute(digester.peek(), name) 
                    && !IntrospectionUtils.setProperty(digester.peek(), name, value) 
                    && digester.getRulesValidation()) {
                digester.getLogger().warn("[SetAllPropertiesRule]{" + digester.getMatch() +
                        "} Setting property '" + name + "' to '" +
                        value + "' did not find a matching property.");
            }
        }
    }

}
 
Example 13
Source Project: Tomcat7.0.67   Source File: SetContextPropertiesRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        if ("path".equals(name) || "docBase".equals(name)) {
            continue;
        }
        String value = attributes.getValue(i);
        if (!digester.isFakeAttribute(digester.peek(), name) 
                && !IntrospectionUtils.setProperty(digester.peek(), name, value) 
                && digester.getRulesValidation()) {
            digester.getLogger().warn("[SetContextPropertiesRule]{" + digester.getMatch() +
                    "} Setting property '" + name + "' to '" +
                    value + "' did not find a matching property.");
        }
    }

}
 
Example 14
Source Project: Tomcat7.0.67   Source File: SetNextNamingRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);

    NamingResources namingResources = null;
    if (parent instanceof Context) {
        namingResources = ((Context) parent).getNamingResources();
    } else {
        namingResources = (NamingResources) parent;
    }
    
    // Call the specified method
    IntrospectionUtils.callMethod1(namingResources, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example 15
Source Project: Tomcat7.0.67   Source File: FilterBase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    Enumeration<String> paramNames = filterConfig.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        if (!IntrospectionUtils.setProperty(this, paramName,
                filterConfig.getInitParameter(paramName))) {
            String msg = sm.getString("filterbase.noSuchProperty",
                    paramName, this.getClass().getName());
            if (isConfigProblemFatal()) {
                throw new ServletException(msg);
            } else {
                getLogger().warn(msg);
            }
        }
    }    
}
 
Example 16
Source Project: Tomcat7.0.67   Source File: SetRootRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.root;
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call [NULL ROOT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example 17
Source Project: Tomcat7.0.67   Source File: Digester.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns an attributes list which contains all the attributes
 * passed in, with any text of form "${xxx}" in an attribute value
 * replaced by the appropriate value from the system property.
 */
private Attributes updateAttributes(Attributes list) {

    if (list.getLength() == 0) {
        return list;
    }
    
    AttributesImpl newAttrs = new AttributesImpl(list);
    int nAttributes = newAttrs.getLength();
    for (int i = 0; i < nAttributes; ++i) {
        String value = newAttrs.getValue(i);
        try {
            String newValue = 
                IntrospectionUtils.replaceProperties(value, null, source);
            if (value != newValue) {
                newAttrs.setValue(i, newValue);
            }
        }
        catch (Exception e) {
            // ignore - let the attribute have its original value
        }
    }

    return newAttrs;

}
 
Example 18
Source Project: Tomcat7.0.67   Source File: Digester.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return a new StringBuilder containing the same contents as the
 * input buffer, except that data of form ${varname} have been
 * replaced by the value of that var as defined in the system property.
 */
private StringBuilder updateBodyText(StringBuilder bodyText) {
    String in = bodyText.toString();
    String out;
    try {
        out = IntrospectionUtils.replaceProperties(in, null, source);
    } catch(Exception e) {
        return bodyText; // return unchanged data
    }

    if (out == in)  {
        // No substitutions required. Don't waste memory creating
        // a new buffer
        return bodyText;
    } else {
        return new StringBuilder(out);
    }
}
 
Example 19
Source Project: Tomcat7.0.67   Source File: SetTopRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    
    if (digester.log.isDebugEnabled()) {
        if (child == null) {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call [NULL CHILD]." +
                    methodName + "(" + parent + ")");
        } else {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call " + child.getClass().getName() + "." +
                    methodName + "(" + parent + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(child, methodName,
            parent, paramType, digester.getClassLoader());

}
 
Example 20
Source Project: Tomcat7.0.67   Source File: SetNextRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call [NULL PARENT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());
            
}
 
Example 21
Source Project: tomcatsrc   Source File: SetAllPropertiesRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        String value = attributes.getValue(i);
        if ( !excludes.containsKey(name)) {
            if (!digester.isFakeAttribute(digester.peek(), name) 
                    && !IntrospectionUtils.setProperty(digester.peek(), name, value) 
                    && digester.getRulesValidation()) {
                digester.getLogger().warn("[SetAllPropertiesRule]{" + digester.getMatch() +
                        "} Setting property '" + name + "' to '" +
                        value + "' did not find a matching property.");
            }
        }
    }

}
 
Example 22
Source Project: tomcatsrc   Source File: SetContextPropertiesRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        if ("path".equals(name) || "docBase".equals(name)) {
            continue;
        }
        String value = attributes.getValue(i);
        if (!digester.isFakeAttribute(digester.peek(), name) 
                && !IntrospectionUtils.setProperty(digester.peek(), name, value) 
                && digester.getRulesValidation()) {
            digester.getLogger().warn("[SetContextPropertiesRule]{" + digester.getMatch() +
                    "} Setting property '" + name + "' to '" +
                    value + "' did not find a matching property.");
        }
    }

}
 
Example 23
Source Project: tomcatsrc   Source File: SetNextNamingRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);

    NamingResources namingResources = null;
    if (parent instanceof Context) {
        namingResources = ((Context) parent).getNamingResources();
    } else {
        namingResources = (NamingResources) parent;
    }
    
    // Call the specified method
    IntrospectionUtils.callMethod1(namingResources, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example 24
Source Project: tomcatsrc   Source File: FilterBase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    Enumeration<String> paramNames = filterConfig.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        if (!IntrospectionUtils.setProperty(this, paramName,
                filterConfig.getInitParameter(paramName))) {
            String msg = sm.getString("filterbase.noSuchProperty",
                    paramName, this.getClass().getName());
            if (isConfigProblemFatal()) {
                throw new ServletException(msg);
            } else {
                getLogger().warn(msg);
            }
        }
    }    
}
 
Example 25
Source Project: tomcatsrc   Source File: SetRootRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.root;
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call [NULL ROOT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example 26
Source Project: tomcatsrc   Source File: Digester.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns an attributes list which contains all the attributes
 * passed in, with any text of form "${xxx}" in an attribute value
 * replaced by the appropriate value from the system property.
 */
private Attributes updateAttributes(Attributes list) {

    if (list.getLength() == 0) {
        return list;
    }
    
    AttributesImpl newAttrs = new AttributesImpl(list);
    int nAttributes = newAttrs.getLength();
    for (int i = 0; i < nAttributes; ++i) {
        String value = newAttrs.getValue(i);
        try {
            String newValue = 
                IntrospectionUtils.replaceProperties(value, null, source);
            if (value != newValue) {
                newAttrs.setValue(i, newValue);
            }
        }
        catch (Exception e) {
            // ignore - let the attribute have its original value
        }
    }

    return newAttrs;

}
 
Example 27
Source Project: tomcatsrc   Source File: Digester.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return a new StringBuilder containing the same contents as the
 * input buffer, except that data of form ${varname} have been
 * replaced by the value of that var as defined in the system property.
 */
private StringBuilder updateBodyText(StringBuilder bodyText) {
    String in = bodyText.toString();
    String out;
    try {
        out = IntrospectionUtils.replaceProperties(in, null, source);
    } catch(Exception e) {
        return bodyText; // return unchanged data
    }

    if (out == in)  {
        // No substitutions required. Don't waste memory creating
        // a new buffer
        return bodyText;
    } else {
        return new StringBuilder(out);
    }
}
 
Example 28
Source Project: tomcatsrc   Source File: SetTopRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    
    if (digester.log.isDebugEnabled()) {
        if (child == null) {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call [NULL CHILD]." +
                    methodName + "(" + parent + ")");
        } else {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call " + child.getClass().getName() + "." +
                    methodName + "(" + parent + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(child, methodName,
            parent, paramType, digester.getClassLoader());

}
 
Example 29
Source Project: tomcatsrc   Source File: SetNextRule.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call [NULL PARENT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());
            
}
 
Example 30
Source Project: Tomcat8-Source-Read   Source File: WebappClassLoaderBase.java    License: MIT License 5 votes vote down vote up
/**
 * Clear references.
 */
protected void clearReferences() {

    // De-register any remaining JDBC drivers
    clearReferencesJdbc();

    // Stop any threads the web application started
    clearReferencesThreads();

    // Clear any references retained in the serialization caches
    if (clearReferencesObjectStreamClassCaches) {
        clearReferencesObjectStreamClassCaches();
    }

    // Check for leaks triggered by ThreadLocals loaded by this class loader
    if (clearReferencesThreadLocals) {
        checkThreadLocalsForLeaks();
    }

    // Clear RMI Targets loaded by this class loader
    if (clearReferencesRmiTargets) {
        clearReferencesRmiTargets();
    }

     // Clear the IntrospectionUtils cache.
    IntrospectionUtils.clear();

    // Clear the classloader reference in common-logging
    if (clearReferencesLogFactoryRelease) {
        org.apache.juli.logging.LogFactory.release(this);
    }

    // Clear the classloader reference in the VM's bean introspector
    java.beans.Introspector.flushCaches();

    // Clear any custom URLStreamHandlers
    TomcatURLStreamHandlerFactory.release(this);
}