Search in sources :

Example 1 with ConstraintField

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

the class CacheMappingNode method writeDescriptor.

/**
 * write the descriptor class to a DOM tree and return it
 *
 * @param parent node for the DOM tree
 * @param node name
 * @param the descriptor to write
 * @return the DOM tree top node
 */
public Node writeDescriptor(Node parent, String nodeName, CacheMapping descriptor) {
    Node cacheMapping = super.writeDescriptor(parent, nodeName, descriptor);
    if (descriptor.getServletName() != null) {
        appendTextChild(cacheMapping, RuntimeTagNames.SERVLET_NAME, descriptor.getServletName());
    } else {
        appendTextChild(cacheMapping, RuntimeTagNames.URL_PATTERN, descriptor.getURLPattern());
    }
    // cache-helper-ref
    appendTextChild(cacheMapping, RuntimeTagNames.CACHE_HELPER_REF, (String) descriptor.getValue(CacheMapping.CACHE_HELPER_REF));
    // dispatcher*
    String[] dispatchers = descriptor.getDispatcher();
    if (dispatchers != null) {
        for (int i = 0; i < dispatchers.length; i++) {
            appendTextChild(cacheMapping, RuntimeTagNames.DISPATCHER, dispatchers[i]);
        }
    }
    // timeout?
    Element timeout = (Element) forceAppendTextChild(cacheMapping, RuntimeTagNames.TIMEOUT, (String) descriptor.getValue(CacheMapping.TIMEOUT));
    // timeout attributes
    String name = descriptor.getAttributeValue(CacheMapping.TIMEOUT, CacheMapping.NAME);
    if (name != null) {
        setAttribute(timeout, RuntimeTagNames.NAME, name);
    }
    String scope = descriptor.getAttributeValue(CacheMapping.TIMEOUT, CacheMapping.SCOPE);
    if (scope != null) {
        setAttribute(timeout, RuntimeTagNames.SCOPE, scope);
    }
    // refresh-field?,
    if (descriptor.isRefreshField()) {
        Element refreshField = (Element) appendChild(cacheMapping, RuntimeTagNames.REFRESH_FIELD);
        setAttribute(refreshField, RuntimeTagNames.NAME, (String) descriptor.getAttributeValue(CacheMapping.REFRESH_FIELD, CacheMapping.NAME));
        setAttribute(refreshField, RuntimeTagNames.SCOPE, (String) descriptor.getAttributeValue(CacheMapping.REFRESH_FIELD, CacheMapping.SCOPE));
    }
    // http-method*
    String[] httpMethods = descriptor.getHttpMethod();
    if (httpMethods != null) {
        for (int i = 0; i < httpMethods.length; i++) {
            appendTextChild(cacheMapping, RuntimeTagNames.HTTP_METHOD, httpMethods[i]);
        }
    }
    // key-field*
    if (descriptor.sizeKeyField() > 0) {
        for (int i = 0; i < descriptor.sizeKeyField(); i++) {
            if (descriptor.isKeyField(i)) {
                Element keyField = (Element) appendChild(cacheMapping, RuntimeTagNames.KEY_FIELD);
                setAttribute(keyField, RuntimeTagNames.NAME, (String) descriptor.getAttributeValue(CacheMapping.KEY_FIELD, i, CacheMapping.NAME));
                setAttribute(keyField, RuntimeTagNames.SCOPE, (String) descriptor.getAttributeValue(CacheMapping.KEY_FIELD, i, CacheMapping.SCOPE));
            }
        }
    }
    // constraint-field*
    if (descriptor.sizeConstraintField() > 0) {
        ConstraintField[] constraintFields = descriptor.getConstraintField();
        ConstraintFieldNode cfn = new ConstraintFieldNode();
        cfn.writeDescriptor(cacheMapping, RuntimeTagNames.CONSTRAINT_FIELD, constraintFields);
    }
    return cacheMapping;
}
Also used : ConstraintField(org.glassfish.web.deployment.runtime.ConstraintField) Node(org.w3c.dom.Node) RuntimeDescriptorNode(com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode) Element(org.w3c.dom.Element) XMLElement(com.sun.enterprise.deployment.node.XMLElement)

Example 2 with ConstraintField

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

the class ASCacheMappingFieldConstraint method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    boolean notApp = false;
    boolean doneAtleastOnce = false;
    try {
        Cache cache = ((SunWebAppImpl) descriptor.getSunDescriptor()).getCache();
        CacheMapping[] cacheMapp = null;
        String servletName;
        String urlPattern;
        ConstraintField[] fieldConstraints = null;
        String mappingFor = null;
        if (cache != null) {
            cacheMapp = cache.getCacheMapping();
        }
        if (cache != null && cacheMapp != null && cacheMapp.length != 0) {
            for (int rep = 0; rep < cacheMapp.length; rep++) {
                servletName = cacheMapp[rep].getServletName();
                urlPattern = cacheMapp[rep].getURLPattern();
                if (servletName != null)
                    mappingFor = servletName;
                else
                    mappingFor = urlPattern;
                fieldConstraints = cacheMapp[rep].getConstraintField();
                if (fieldConstraints != null && fieldConstraints.length != 0) {
                    for (int rep1 = 0; rep1 < fieldConstraints.length; rep1++) {
                        if (fieldConstraints[rep1] != null) {
                            doneAtleastOnce = true;
                            if (checkFieldConstraint(fieldConstraints[rep1], result, mappingFor, descriptor, compName)) {
                            // nothing more required
                            } else {
                                oneFailed = true;
                                addErrorDetails(result, compName);
                                result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-mapping] List of field-constraint in cache-mapping for [ {0} ] is not proper,  within the web archive/(gf/)sun-web.xml of [ {1} ].", new Object[] { mappingFor, descriptor.getName() }));
                            }
                        }
                    }
                // end of for(int rep1=0;rep1 < fieldConstraints.length;rep1++)
                }
            }
        // end of for(int rep=0;rep < cacheMapp.length;rep++)
        } else {
            notApp = true;
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (notApp || !doneAtleastOnce) {
            result.setStatus(Result.NOT_APPLICABLE);
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB cache-mapping ] constraint-field not defined in [ {0} ].", new Object[] { descriptor.getName() }));
        } else {
            result.setStatus(Result.PASSED);
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-mapping] could not create the cache object"));
    }
    return result;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) ConstraintField(org.glassfish.web.deployment.runtime.ConstraintField) CacheMapping(org.glassfish.web.deployment.runtime.CacheMapping) Cache(org.glassfish.web.deployment.runtime.Cache)

Aggregations

ConstraintField (org.glassfish.web.deployment.runtime.ConstraintField)2 XMLElement (com.sun.enterprise.deployment.node.XMLElement)1 RuntimeDescriptorNode (com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode)1 Cache (org.glassfish.web.deployment.runtime.Cache)1 CacheMapping (org.glassfish.web.deployment.runtime.CacheMapping)1 SunWebAppImpl (org.glassfish.web.deployment.runtime.SunWebAppImpl)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1