Package org.apache.geronimo.web25.deployment.merge

Examples of org.apache.geronimo.web25.deployment.merge.MergeItem


    @Override
    public void merge(ServletType srcServlet, ServletType targetServlet, MergeContext mergeContext) throws DeploymentException {
        String servletName = srcServlet.getServletName().getStringValue();
        for (ParamValueType paramValue : srcServlet.getInitParamArray()) {
            MergeItem existedMergeItem = (MergeItem) mergeContext.getAttribute(createServletInitParamKey(servletName, paramValue.getParamName().getStringValue()));
            if (existedMergeItem == null) {
                targetServlet.addNewInitParam().set(paramValue);
                addServletInitParam(servletName, paramValue, ElementSource.WEB_FRAGMENT, mergeContext.getCurrentJarUrl(), mergeContext);
            } else {
                ParamValueType existedParamValue = (ParamValueType) existedMergeItem.getValue();
                switch (existedMergeItem.getSourceType()) {
                case WEB_XML:
                    continue;
                case WEB_FRAGMENT:
                    if (existedParamValue.getParamValue().getStringValue().equals(paramValue.getParamValue().getStringValue())
                            || existedMergeItem.getBelongedURL().equals(mergeContext.getCurrentJarUrl())) {
                        break;
                    } else {
                        throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateKeyValueMessage("servlet " + servletName, "param-name", paramValue.getParamName().getStringValue(),
                                "param-value", existedParamValue.getParamValue().getStringValue(), existedMergeItem.getBelongedURL(), paramValue.getParamValue().getStringValue(), mergeContext
                                        .getCurrentJarUrl()));
                    }
                case ANNOTATION:
                    //Spec 8.1.n.iii Init params for servlets and filters defined via annotations, will be
                    //overridden in the descriptor if the name of the init param exactly matches
                    //the name specified via the annotation. Init params are additive between the
                    //annotations and descriptors.
                    //In my understanding, the value of init-param should be overridden even if it is merged from annotation before the current web-fragment.xml file
                    existedParamValue.getParamValue().set(paramValue.getParamValue());
                    existedMergeItem.setBelongedURL(mergeContext.getCurrentJarUrl());
                    existedMergeItem.setSourceType(ElementSource.WEB_FRAGMENT);
                }
            }
        }
    }
View Full Code Here


    public static boolean isServletInitParamConfigured(String servletName, String paramName, MergeContext mergeContext) {
        return mergeContext.containsAttribute(createServletInitParamKey(servletName, paramName));
    }

    public static void addServletInitParam(String servletName, ParamValueType paramValue, ElementSource source, String relativeUrl, MergeContext mergeContext) {
        mergeContext.setAttribute(createServletInitParamKey(servletName, paramValue.getParamName().getStringValue()), new MergeItem(paramValue, relativeUrl, source));
    }
View Full Code Here

            String messageDestinationName = messageDestination.getMessageDestinationName().getStringValue();
            if (mergeContext.containsAttribute(createMessageDestinationConfiguredInWebXMLKey(messageDestination.getMessageDestinationName().getStringValue()))) {
                continue;
            }
            if (mergeContext.containsAttribute(createMessageDestinationConfiguredInWebFragmentXMLKey(messageDestinationName))) {
                MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(createMessageDestinationConfiguredInWebFragmentXMLKey(messageDestinationName));
                throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("message-destination", messageDestinationName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
            } else {
                MessageDestinationType newMessageDestination = (MessageDestinationType) webApp.addNewMessageDestination().set(messageDestination);
                mergeContext.setAttribute(createMessageDestinationConfiguredInWebFragmentXMLKey(messageDestinationName), new MergeItem(newMessageDestination, mergeContext.getCurrentJarUrl(),
                        ElementSource.WEB_FRAGMENT));
            }
        }
    }
View Full Code Here

    @Override
    public void merge(WebFragmentType webFragment, WebAppType webApp, MergeContext mergeContext) throws DeploymentException {
        for (ResourceRefType srcResourceRef : webFragment.getResourceRefArray()) {
            String resourceRefName = srcResourceRef.getResRefName().getStringValue();
            String resourceRefKey = createResourceRefKey(resourceRefName);
            MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(resourceRefKey);
            if (mergeItem != null) {
                if (mergeItem.isFromWebFragment()) {
                    throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("resource-ref", resourceRefName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
                } else if (mergeItem.isFromWebXml() && !isResourceRefInjectTargetsConfiguredInInitialWebXML(resourceRefName, mergeContext)) {
                    //Merge InjectTarget
                    ResourceRefType resourceRef = (ResourceRefType) mergeItem.getValue();
                    for (InjectionTargetType injectTarget : srcResourceRef.getInjectionTargetArray()) {
                        String resourceRefInjectTargetKey = createResourceRefInjectTargetKey(resourceRefName, injectTarget.getInjectionTargetClass().getStringValue(), injectTarget
                                .getInjectionTargetName().getStringValue());
                        if (!mergeContext.containsAttribute(resourceRefInjectTargetKey)) {
                            resourceRef.addNewInjectionTarget().set(injectTarget);
                            mergeContext.setAttribute(resourceRefInjectTargetKey, Boolean.TRUE);
                        }
                    }
                }
            } else {
                ResourceRefType targetResourceRef = (ResourceRefType) webApp.addNewResourceRef().set(srcResourceRef);
                mergeContext.setAttribute(resourceRefKey, new MergeItem(targetResourceRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
                for (InjectionTargetType injectionTarget : targetResourceRef.getInjectionTargetArray()) {
                    mergeContext.setAttribute(createResourceRefInjectTargetKey(resourceRefName, injectionTarget.getInjectionTargetClass().getStringValue(), injectionTarget.getInjectionTargetName()
                            .getStringValue()), Boolean.TRUE);
                }
            }
View Full Code Here

    @Override
    public void preProcessWebXmlElement(WebAppType webApp, MergeContext mergeContext) throws DeploymentException {
        for (ResourceRefType resourceRef : webApp.getResourceRefArray()) {
            String resourceRefName = resourceRef.getResRefName().getStringValue();
            mergeContext.setAttribute(createResourceRefKey(resourceRefName), new MergeItem(resourceRef, null, ElementSource.WEB_XML));
            //Create an attribute tag to indicate whether injectTarget is configured in web.xml file
            if (resourceRef.getInjectionTargetArray().length > 0) {
                mergeContext.setAttribute(createResourceRefInjectTargetConfiguredInWebXMLKey(resourceRefName), Boolean.TRUE);
            }
            for (InjectionTargetType injectionTarget : resourceRef.getInjectionTargetArray()) {
View Full Code Here

    public void merge(WebFragmentType webFragment, WebAppType webApp, MergeContext mergeContext) throws DeploymentException {
        LocaleEncodingMappingListType targetLocaleEncodingMappingList = null;
        for (LocaleEncodingMappingListType localeEncodingMappingList : webFragment.getLocaleEncodingMappingListArray()) {
            for (LocaleEncodingMappingType localeEncodingMapping : localeEncodingMappingList.getLocaleEncodingMappingArray()) {
                String localeEncodingMappingKey = createLocaleEncodingMappingKey(localeEncodingMapping.getLocale());
                MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(localeEncodingMappingKey);
                if (mergeItem != null && mergeItem.isFromWebFragment() && !mergeItem.getValue().equals(localeEncodingMapping.getEncoding())) {
                    throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateKeyValueMessage("locale-encoding-mapping", "locale", localeEncodingMapping.getLocale(), "encoding",
                            (String) mergeItem.getValue(), mergeItem.getBelongedURL(), localeEncodingMapping.getLocale(), mergeContext.getCurrentJarUrl()));
                }
                if (targetLocaleEncodingMappingList == null) {
                    targetLocaleEncodingMappingList = webApp.getLocaleEncodingMappingListArray().length > 0 ? webApp.getLocaleEncodingMappingListArray(0) : webApp.addNewLocaleEncodingMappingList();
                }
                targetLocaleEncodingMappingList.addNewLocaleEncodingMapping().set(localeEncodingMapping);
                mergeContext.setAttribute(localeEncodingMappingKey, new MergeItem(localeEncodingMapping.getEncoding(), mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
            }
        }
    }
View Full Code Here

            for (int i = 1, iLength = localeEncodingMappingLists.length; i < iLength; i++) {
                webApp.removeLocaleEncodingMappingList(1);
            }
        }
        for (LocaleEncodingMappingType localeEncodingMapping : webApp.getLocaleEncodingMappingListArray(0).getLocaleEncodingMappingArray()) {
            context.setAttribute(createLocaleEncodingMappingKey(localeEncodingMapping.getLocale()), new MergeItem(localeEncodingMapping.getEncoding(), null, ElementSource.WEB_XML));
        }
    }
View Full Code Here

            }
        }
    }

    private boolean mergeSingleAttribute(MergeContext mergeContext, String elementName, String key, String value, String jarUrl, ElementSource elementSource) throws DeploymentException {
        MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(key);
        if (mergeItem != null) {
            if (mergeItem.getSourceType().equals(ElementSource.WEB_FRAGMENT)) {
                if (!mergeItem.getValue().equals(value)) {
                    throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateValueMessage("session-config", elementName, (String) mergeItem.getValue(), mergeItem.getBelongedURL(),
                            value, jarUrl));
                }
            }
            return false;
        } else {
            mergeContext.setAttribute(key, new MergeItem(value, jarUrl, elementSource));
            return elementSource.equals(ElementSource.WEB_FRAGMENT);
        }
    }
View Full Code Here

            if (isMimeMappingConfiguredInWebXML(extension, mergeContext)) {
                continue;
            }
            String jarUrl = mergeContext.getCurrentJarUrl();
            String qualifedMimeMappingName = createMimeMappingConfiguredInWebFragmentXMLKey(extension);
            MergeItem existedMimeMapping = (MergeItem) mergeContext.getAttribute(qualifedMimeMappingName);
            if (existedMimeMapping == null) {
                mergeContext.setAttribute(qualifedMimeMappingName, new MergeItem(mimeMapping.getMimeType().getStringValue(), jarUrl, ElementSource.WEB_FRAGMENT));
                webApp.addNewMimeMapping().set(mimeMapping);
            } else if (!mimeMapping.getMimeType().getStringValue().equals(existedMimeMapping.getValue())) {
                throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateKeyValueMessage("mime-mapping", "extension", extension, "mime-type", (String) existedMimeMapping.getValue(), existedMimeMapping
                        .getBelongedURL(), mimeMapping.getMimeType().getStringValue(), jarUrl));
            }
        }
    }
View Full Code Here

    @Override
    public void merge(WebFragmentType webFragment, WebAppType webApp, MergeContext mergeContext) throws DeploymentException {
        for (PersistenceContextRefType srcPersistenceContextRef : webFragment.getPersistenceContextRefArray()) {
            String persistenceContextRefName = srcPersistenceContextRef.getPersistenceContextRefName().getStringValue();
            String persistenceContextRefKey = createPersistenceContextRefKey(persistenceContextRefName);
            MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(persistenceContextRefKey);
            if (mergeItem != null) {
                if (mergeItem.isFromWebFragment()) {
                    throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("persistence-context-ref", persistenceContextRefName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
                } else if (mergeItem.isFromWebXml() && !isPersistenceContextRefInjectTargetsConfiguredInInitialWebXML(persistenceContextRefName, mergeContext)) {
                    //Merge InjectTarget
                    PersistenceContextRefType persistenceContextRef = (PersistenceContextRefType) mergeItem.getValue();
                    for (InjectionTargetType injectTarget : srcPersistenceContextRef.getInjectionTargetArray()) {
                        String persistenceContextRefInjectTargetKey = createPersistenceContextRefInjectTargetKey(persistenceContextRefName, injectTarget.getInjectionTargetClass().getStringValue(), injectTarget
                                .getInjectionTargetName().getStringValue());
                        if (!mergeContext.containsAttribute(persistenceContextRefInjectTargetKey)) {
                            persistenceContextRef.addNewInjectionTarget().set(injectTarget);
                            mergeContext.setAttribute(persistenceContextRefInjectTargetKey, Boolean.TRUE);
                        }
                    }
                }
            } else {
                PersistenceContextRefType targetPersistenceContextRef = (PersistenceContextRefType) webApp.addNewPersistenceContextRef().set(srcPersistenceContextRef);
                mergeContext.setAttribute(persistenceContextRefKey, new MergeItem(targetPersistenceContextRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
                for (InjectionTargetType injectionTarget : targetPersistenceContextRef.getInjectionTargetArray()) {
                    mergeContext.setAttribute(createPersistenceContextRefInjectTargetKey(persistenceContextRefName, injectionTarget.getInjectionTargetClass().getStringValue(), injectionTarget.getInjectionTargetName()
                            .getStringValue()), Boolean.TRUE);
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.geronimo.web25.deployment.merge.MergeItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.