Search in sources :

Example 1 with CacheHelper

use of org.glassfish.web.deployment.runtime.CacheHelper in project Payara by payara.

the class ASCacheHelperClass method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    boolean notApp = false;
    boolean oneWarning = false;
    boolean presentHelper = false;
    try {
        Cache cache = ((SunWebAppImpl) descriptor.getSunDescriptor()).getCache();
        CacheHelper[] helperClasses = null;
        CacheHelper helperClass = null;
        WebProperty[] webProps;
        String name = null;
        String classname = null;
        String[] names = null;
        // to-do vkv# check for class-name attribute.
        if (cache != null)
            helperClasses = cache.getCacheHelper();
        if (cache != null && helperClasses != null && helperClasses.length > 0) {
            names = new String[helperClasses.length];
            for (int rep = 0; rep < helperClasses.length; rep++) {
                helperClass = helperClasses[rep];
                if (helperClass == null)
                    continue;
                int i = rep + 1;
                name = getXPathValue("sun-web-app/cache/cache-helper[" + i + "]/@name");
                classname = getXPathValue("sun-web-app/cache/cache-helper[" + i + "]/@class-name");
                Class hClass = null;
                names[rep] = name;
                if (name != null && name.length() != 0) {
                    // check if the name already exist
                    boolean isDuplicate = false;
                    for (int rep1 = 0; rep1 < rep; rep1++) {
                        if (name.equals(names[rep1])) {
                            isDuplicate = true;
                            break;
                        }
                    }
                    if (isDuplicate) {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-helper] name attribute [ {0} ], must be unique in the entire list of cache-helper.", new Object[] { name }));
                    } else {
                        if (classname != null && classname.length() != 0) {
                            hClass = loadClass(result, classname);
                        }
                        if (hClass != null)
                            presentHelper = true;
                        else
                            presentHelper = false;
                        if (!presentHelper) {
                            addWarningDetails(result, compName);
                            result.warning(smh.getLocalString(getClass().getName() + ".error", "WARNING [AS-WEB cache-helper] " + "name [ {0} ], class not present in the war file.", new Object[] { name }));
                            oneWarning = true;
                        } else {
                            addGoodDetails(result, compName);
                            result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-WEB cache-helper] name  [ {0} ], helper class is valid.", new Object[] { name }));
                        }
                    }
                } else {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-WEB cache-helper] name [ {0} ], either empty or null.", new Object[] { name }));
                    oneFailed = true;
                }
                webProps = helperClass.getWebProperty();
                if (ASWebProperty.checkWebProperties(webProps, result, descriptor, this)) {
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-WEB cache-helper] Atleast one name/value pair is not valid in helper-class of [ {0} ].", new Object[] { descriptor.getName() }));
                }
            }
        // end of for
        } else {
            notApp = true;
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB cache-helper] There is no cache-helper element for the web application", new Object[] { descriptor.getName() }));
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (oneWarning) {
            result.setStatus(Result.WARNING);
        } else if (notApp) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-WEB cache-helper] could not create the cache object"));
    }
    return result;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) CacheHelper(org.glassfish.web.deployment.runtime.CacheHelper) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) Result(com.sun.enterprise.tools.verifier.Result) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Cache(org.glassfish.web.deployment.runtime.Cache)

Example 2 with CacheHelper

use of org.glassfish.web.deployment.runtime.CacheHelper in project Payara by payara.

the class CacheNode method writeDescriptor.

/**
 * write the descriptor class to a DOM tree and return it
 *
 * @param parent node for the DOM tree
 * @param nodeName node name
 * @param descriptor the descriptor to write
 * @return the DOM tree top node
 */
@Override
public Node writeDescriptor(Node parent, String nodeName, Cache descriptor) {
    Element cache = (Element) super.writeDescriptor(parent, nodeName, descriptor);
    // cache-helpers*
    CacheHelper[] cacheHelpers = descriptor.getCacheHelper();
    if (cacheHelpers != null && cacheHelpers.length > 0) {
        CacheHelperNode chn = new CacheHelperNode();
        for (int i = 0; i < cacheHelpers.length; i++) {
            chn.writeDescriptor(cache, RuntimeTagNames.CACHE_HELPER, cacheHelpers[i]);
        }
    }
    WebPropertyNode wpn = new WebPropertyNode();
    // default-helper?
    DefaultHelper dh = descriptor.getDefaultHelper();
    if (dh != null && dh.getWebProperty() != null) {
        Node dhn = appendChild(cache, RuntimeTagNames.DEFAULT_HELPER);
        wpn.writeDescriptor(dhn, RuntimeTagNames.PROPERTY, dh.getWebProperty());
    }
    // property*
    wpn.writeDescriptor(cache, RuntimeTagNames.PROPERTY, descriptor.getWebProperty());
    // cache-mapping
    CacheMapping[] mappings = descriptor.getCacheMapping();
    if (mappings != null && mappings.length > 0) {
        CacheMappingNode cmn = new CacheMappingNode();
        for (int i = 0; i < mappings.length; i++) {
            cmn.writeDescriptor(cache, RuntimeTagNames.CACHE_MAPPING, mappings[i]);
        }
    }
    // max-entries, timeout-in-seconds, enabled
    setAttribute(cache, RuntimeTagNames.MAX_ENTRIES, (String) descriptor.getAttributeValue(Cache.MAX_ENTRIES));
    setAttribute(cache, RuntimeTagNames.TIMEOUT_IN_SECONDS, (String) descriptor.getAttributeValue(Cache.TIMEOUT_IN_SECONDS));
    setAttribute(cache, RuntimeTagNames.ENABLED, (String) descriptor.getAttributeValue(Cache.ENABLED));
    return cache;
}
Also used : DefaultHelper(org.glassfish.web.deployment.runtime.DefaultHelper) CacheHelper(org.glassfish.web.deployment.runtime.CacheHelper) Element(org.w3c.dom.Element) XMLElement(com.sun.enterprise.deployment.node.XMLElement) Node(org.w3c.dom.Node) RuntimeDescriptorNode(com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode) CacheMapping(org.glassfish.web.deployment.runtime.CacheMapping)

Example 3 with CacheHelper

use of org.glassfish.web.deployment.runtime.CacheHelper in project Payara by payara.

the class ASCacheMapping method validCacheHelperRef.

boolean validCacheHelperRef(String helperRef, Cache cache) {
    boolean valid = false;
    if (helperRef.length() != 0) {
        CacheHelper[] helperClasses = null;
        CacheHelper helperClass = null;
        String name = null;
        if (cache != null) {
            helperClasses = cache.getCacheHelper();
        }
        if (cache != null && helperClasses != null) {
            for (int rep = 0; rep < helperClasses.length; rep++) {
                helperClass = helperClasses[rep];
                if (helperClass == null)
                    continue;
                int i = rep + 1;
                name = getXPathValue("sun-web-app/cache/cache-helper[" + i + "]/@name");
                if (helperRef.equals(name)) {
                    valid = true;
                    break;
                }
            }
        }
    }
    return valid;
}
Also used : CacheHelper(org.glassfish.web.deployment.runtime.CacheHelper)

Aggregations

CacheHelper (org.glassfish.web.deployment.runtime.CacheHelper)3 XMLElement (com.sun.enterprise.deployment.node.XMLElement)1 RuntimeDescriptorNode (com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode)1 Result (com.sun.enterprise.tools.verifier.Result)1 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)1 Cache (org.glassfish.web.deployment.runtime.Cache)1 CacheMapping (org.glassfish.web.deployment.runtime.CacheMapping)1 DefaultHelper (org.glassfish.web.deployment.runtime.DefaultHelper)1 SunWebAppImpl (org.glassfish.web.deployment.runtime.SunWebAppImpl)1 WebProperty (org.glassfish.web.deployment.runtime.WebProperty)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1