org.apache.openejb.jee.WebApp Maven / Gradle / Ivy
The newest version!
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.openejb.jee;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* web-common_3_0.xsd
*
* Java class for web-appType complex type.
*
* The following schema fragment specifies the expected content contained within this class.
*
*
* <complexType name="web-appType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <choice maxOccurs="unbounded" minOccurs="0">
* <element name="module-name" type="{http://java.sun.com/xml/ns/javaee}string" minOccurs="0"/>
* <group ref="{http://java.sun.com/xml/ns/javaee}web-commonType"/>
* <element name="absolute-ordering" type="{http://java.sun.com/xml/ns/javaee}absoluteOrderingType"/>
* </choice>
* <attGroup ref="{http://java.sun.com/xml/ns/javaee}web-common-attributes"/>
* </restriction>
* </complexContent>
* </complexType>
*
*/
@XmlRootElement(name = "web-app")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "web-appType", propOrder = {
"descriptions",
"displayNames",
"icon",
"distributable",
"contextParam",
"filter",
"filterMapping",
"listener",
"servlet",
"servletMapping",
"sessionConfig",
"mimeMapping",
"welcomeFileList",
"errorPage",
//In web-app-2.3.dtd
"taglib",
"jspConfig",
"securityConstraint",
"loginConfig",
"securityRole",
"localeEncodingMappingList",
"envEntry",
"ejbRef",
"ejbLocalRef",
"serviceRef",
"resourceRef",
"resourceEnvRef",
"messageDestinationRef",
"persistenceContextRef",
"persistenceUnitRef",
"postConstruct",
"preDestroy",
"messageDestination",
"absoluteOrdering",
"dataSource",
"moduleName"
})
public class WebApp implements WebCommon, Lifecycle, NamedModule {
@XmlTransient
private String contextRoot;
@XmlTransient
protected TextMap description = new TextMap();
@XmlTransient
protected TextMap displayName = new TextMap();
@XmlElement(name = "icon", required = true)
protected LocalCollection icon = new LocalCollection();
protected List distributable;
@XmlElement(name = "context-param")
protected List contextParam;
protected List filter;
@XmlElement(name = "filter-mapping")
protected List filterMapping;
protected List listener;
protected List servlet;
@XmlElement(name = "servlet-mapping")
protected List servletMapping;
@XmlElement(name = "session-config")
protected List sessionConfig;
@XmlElement(name = "mime-mapping")
protected List mimeMapping;
@XmlElement(name = "welcome-file-list")
protected List welcomeFileList;
//in web-app-2.3.dtd, not in any schema
// @XmlElement(name = "taglib")
// protected List taglib;
@XmlElement(name = "error-page")
protected List errorPage;
@XmlElement(name = "jsp-config")
protected List jspConfig;
@XmlElement(name = "security-constraint")
protected List securityConstraint;
@XmlElement(name = "login-config")
protected List loginConfig;
@XmlElement(name = "security-role")
protected List securityRole;
@XmlElement(name = "locale-encoding-mapping-list")
protected List localeEncodingMappingList;
@XmlElement(name = "env-entry", required = true)
protected KeyedCollection envEntry;
@XmlElement(name = "ejb-ref", required = true)
protected KeyedCollection ejbRef;
@XmlElement(name = "ejb-local-ref", required = true)
protected KeyedCollection ejbLocalRef;
@XmlElement(name = "service-ref", required = true)
protected KeyedCollection serviceRef;
@XmlElement(name = "resource-ref", required = true)
protected KeyedCollection resourceRef;
@XmlElement(name = "resource-env-ref", required = true)
protected KeyedCollection resourceEnvRef;
@XmlElement(name = "message-destination-ref", required = true)
protected KeyedCollection messageDestinationRef;
@XmlElement(name = "persistence-context-ref", required = true)
protected KeyedCollection persistenceContextRef;
@XmlElement(name = "persistence-unit-ref", required = true)
protected KeyedCollection persistenceUnitRef;
@XmlElement(name = "data-source", required = true)
protected KeyedCollection dataSource;
@XmlElement(name = "post-construct", required = true)
protected List postConstruct;
@XmlElement(name = "pre-destroy", required = true)
protected List preDestroy;
@XmlElement(name = "message-destination", required = true)
protected List messageDestination;
@XmlElement(name = "module-name")
protected String moduleName;
@XmlElement(name = "absolute-ordering")
protected AbsoluteOrdering absoluteOrdering;
@XmlAttribute
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlID
protected String id;
@XmlAttribute(name = "metadata-complete")
protected Boolean metadataComplete;
@XmlAttribute(required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
protected String version = "3.0";
@Override
public String getJndiConsumerName() {
return contextRoot;
}
@Override
public String getContextRoot() {
return contextRoot;
}
@Override
public void setContextRoot(final String contextRoot) {
this.contextRoot = contextRoot;
}
@Override
@XmlElement(name = "description", required = true)
public Text[] getDescriptions() {
return description.toArray();
}
@Override
public void setDescriptions(final Text[] text) {
description.set(text);
}
@Override
public String getDescription() {
return description.get();
}
@Override
@XmlElement(name = "display-name", required = true)
public Text[] getDisplayNames() {
return displayName.toArray();
}
@Override
public void setDisplayNames(final Text[] text) {
displayName.set(text);
}
@Override
public String getDisplayName() {
return displayName.get();
}
@Override
public Collection getIcons() {
if (icon == null) {
icon = new LocalCollection();
}
return icon;
}
@Override
public Map getIconMap() {
if (icon == null) {
icon = new LocalCollection();
}
return icon.toMap();
}
@Override
public Icon getIcon() {
return icon.getLocal();
}
@Override
public List getDistributable() {
if (distributable == null) {
distributable = new ArrayList();
}
return this.distributable;
}
@Override
public List getContextParam() {
if (contextParam == null) {
contextParam = new ArrayList();
}
return this.contextParam;
}
@Override
public List getFilter() {
if (filter == null) {
filter = new ArrayList();
}
return this.filter;
}
@Override
public List getFilterMapping() {
if (filterMapping == null) {
filterMapping = new ArrayList();
}
return this.filterMapping;
}
@Override
public List getListener() {
if (listener == null) {
listener = new ArrayList();
}
return this.listener;
}
@Override
public List getServlet() {
if (servlet == null) {
servlet = new ArrayList();
}
return this.servlet;
}
@Override
public List getServletMapping() {
if (servletMapping == null) {
servletMapping = new ArrayList();
}
return this.servletMapping;
}
@Override
public List getSessionConfig() {
if (sessionConfig == null) {
sessionConfig = new ArrayList();
}
return this.sessionConfig;
}
@Override
public List getMimeMapping() {
if (mimeMapping == null) {
mimeMapping = new ArrayList();
}
return this.mimeMapping;
}
@Override
public List getWelcomeFileList() {
if (welcomeFileList == null) {
welcomeFileList = new ArrayList();
}
return this.welcomeFileList;
}
@Override
public List getErrorPage() {
if (errorPage == null) {
errorPage = new ArrayList();
}
return this.errorPage;
}
@Override
public List getJspConfig() {
if (jspConfig == null) {
jspConfig = new ArrayList();
}
return this.jspConfig;
}
@Override
public List getSecurityConstraint() {
if (securityConstraint == null) {
securityConstraint = new ArrayList();
}
return this.securityConstraint;
}
@Override
public List getLoginConfig() {
if (loginConfig == null) {
loginConfig = new ArrayList();
}
return this.loginConfig;
}
@Override
public List getSecurityRole() {
if (securityRole == null) {
securityRole = new ArrayList();
}
return this.securityRole;
}
@Override
public List getLocaleEncodingMappingList() {
if (localeEncodingMappingList == null) {
localeEncodingMappingList = new ArrayList();
}
return this.localeEncodingMappingList;
}
public Collection getEnvEntry() {
if (envEntry == null) {
envEntry = new KeyedCollection();
}
return this.envEntry;
}
public Map getEnvEntryMap() {
if (envEntry == null) {
envEntry = new KeyedCollection();
}
return this.envEntry.toMap();
}
public Collection getEjbRef() {
if (ejbRef == null) {
ejbRef = new KeyedCollection();
}
return this.ejbRef;
}
public Map getEjbRefMap() {
if (ejbRef == null) {
ejbRef = new KeyedCollection();
}
return this.ejbRef.toMap();
}
public Collection getEjbLocalRef() {
if (ejbLocalRef == null) {
ejbLocalRef = new KeyedCollection();
}
return this.ejbLocalRef;
}
public Map getEjbLocalRefMap() {
if (ejbLocalRef == null) {
ejbLocalRef = new KeyedCollection();
}
return this.ejbLocalRef.toMap();
}
public Collection getServiceRef() {
if (serviceRef == null) {
serviceRef = new KeyedCollection();
}
return this.serviceRef;
}
public Map getServiceRefMap() {
if (serviceRef == null) {
serviceRef = new KeyedCollection();
}
return this.serviceRef.toMap();
}
public Collection getResourceRef() {
if (resourceRef == null) {
resourceRef = new KeyedCollection();
}
return this.resourceRef;
}
public Map getResourceRefMap() {
if (resourceRef == null) {
resourceRef = new KeyedCollection();
}
return this.resourceRef.toMap();
}
public Collection getResourceEnvRef() {
if (resourceEnvRef == null) {
resourceEnvRef = new KeyedCollection();
}
return this.resourceEnvRef;
}
public Map getResourceEnvRefMap() {
if (resourceEnvRef == null) {
resourceEnvRef = new KeyedCollection();
}
return this.resourceEnvRef.toMap();
}
public Collection getMessageDestinationRef() {
if (messageDestinationRef == null) {
messageDestinationRef = new KeyedCollection();
}
return this.messageDestinationRef;
}
public Map getMessageDestinationRefMap() {
if (messageDestinationRef == null) {
messageDestinationRef = new KeyedCollection();
}
return this.messageDestinationRef.toMap();
}
public Collection getPersistenceContextRef() {
if (persistenceContextRef == null) {
persistenceContextRef = new KeyedCollection();
}
return this.persistenceContextRef;
}
public Map getPersistenceContextRefMap() {
if (persistenceContextRef == null) {
persistenceContextRef = new KeyedCollection();
}
return this.persistenceContextRef.toMap();
}
public Collection getPersistenceUnitRef() {
if (persistenceUnitRef == null) {
persistenceUnitRef = new KeyedCollection();
}
return this.persistenceUnitRef;
}
public Map getPersistenceUnitRefMap() {
if (persistenceUnitRef == null) {
persistenceUnitRef = new KeyedCollection();
}
return this.persistenceUnitRef.toMap();
}
public void addPostConstruct(final String method) {
throw new UnsupportedOperationException();
}
@Override
public List getPostConstruct() {
if (postConstruct == null) {
postConstruct = new ArrayList();
}
return this.postConstruct;
}
public void addPreDestroy(final String method) {
throw new UnsupportedOperationException();
}
@Override
public List getPreDestroy() {
if (preDestroy == null) {
preDestroy = new ArrayList();
}
return this.preDestroy;
}
@Override
public List getMessageDestination() {
if (messageDestination == null) {
messageDestination = new ArrayList();
}
return this.messageDestination;
}
@Override
public String getId() {
return id;
}
@Override
public void setId(final String value) {
this.id = value;
}
@Override
public Boolean isMetadataComplete() {
return metadataComplete != null && metadataComplete;
}
@Override
public void setMetadataComplete(final Boolean value) {
this.metadataComplete = value;
}
@Override
public String getVersion() {
return version;
}
@Override
public void setVersion(final String value) {
this.version = value;
}
public Collection getDataSource() {
if (dataSource == null) {
dataSource = new KeyedCollection();
}
return this.dataSource;
}
public Map getDataSourceMap() {
if (dataSource == null) {
dataSource = new KeyedCollection();
}
return this.dataSource.toMap();
}
public AbsoluteOrdering getAbsoluteOrdering() {
return absoluteOrdering;
}
public void setAbsoluteOrdering(final AbsoluteOrdering absoluteOrdering) {
this.absoluteOrdering = absoluteOrdering;
}
public String getModuleName() {
return moduleName;
}
public void setModuleName(final String moduleName) {
this.moduleName = moduleName;
}
//compatibility with web-app-2.3.dtd
@XmlElement(name = "taglib")
public Taglib getTaglib() {
return null;
}
public void setTaglib(final Taglib taglib) {
final List jspConfigs = getJspConfig();
if (jspConfigs.isEmpty()) {
jspConfigs.add(new JspConfig());
}
jspConfigs.get(0).getTaglib().add(taglib);
}
public Map contextParamsAsMap() {
final Map map = new HashMap();
if (contextParam != null) {
for (final ParamValue pv : contextParam) {
map.put(pv.getParamName(), pv.getParamValue());
}
}
return map;
}
public List getServletMappings(final String servletName) {
if (servletMapping == null || servletName == null) {
return Collections.emptyList();
}
for (final ServletMapping mapping : servletMapping) {
if (servletName.equals(mapping.getServletName())) {
return mapping.getUrlPattern();
}
}
return Collections.emptyList();
}
public List getFilterMappings(final String filterName) {
if (filterMapping == null || filterName == null) {
return Collections.emptyList();
}
for (final FilterMapping mapping : filterMapping) {
if (filterName.equals(mapping.getFilterName())) {
return mapping.getUrlPattern();
}
}
return Collections.emptyList();
}
private Servlet findServlet(final String name) {
for (final Servlet s : getServlet()) {
if (name.equals(s.getServletName())) {
return s;
}
}
return null;
}
public WebApp addServlet(final String name, final String clazz, final String... mappings) {
final Servlet servletToAdd = new Servlet();
servletToAdd.setServletName(name);
servletToAdd.setServletClass(clazz);
if (mappings != null && mappings.length > 0) {
final ServletMapping sm = new ServletMapping();
sm.setServletName(name);
for (final String mapping : mappings) {
if (servletMapping == null) {
servletMapping = new ArrayList();
}
sm.getUrlPattern().add(mapping);
}
servletMapping.add(sm);
}
getServlet().add(servletToAdd);
return this;
}
public WebApp addServletMapping(final String servletName, final String mapping) {
for (final ServletMapping s : getServletMapping()) {
if (servletName.equals(s.getServletName())) {
s.getUrlPattern().add(mapping);
return this;
}
}
final ServletMapping sm = new ServletMapping();
sm.setServletName(servletName);
sm.getUrlPattern().add(mapping);
getServletMapping().add(sm);
return this;
}
public WebApp addInitParam(final String servletName, final String name, final String value) {
final ParamValue paramValue = new ParamValue();
paramValue.setParamName(name);
paramValue.setParamValue(value);
findServlet(servletName).getInitParam().add(paramValue);
return this;
}
public WebApp addFilter(final String name, final String clazz, final String... mappings) {
final Filter newFilter = new Filter();
newFilter.setFilterName(name);
newFilter.setFilterClass(clazz);
if (mappings != null && mappings.length > 0) {
final FilterMapping sm = new FilterMapping();
sm.setFilterName(name);
for (final String mapping : mappings) {
if (filterMapping == null) {
filterMapping = new ArrayList();
}
sm.getUrlPattern().add(mapping);
}
filterMapping.add(sm);
}
getFilter().add(newFilter);
return this;
}
public WebApp addFilterInitParam(final String filterName, final String name, final String value) {
final ParamValue paramValue = new ParamValue();
paramValue.setParamName(name);
paramValue.setParamValue(value);
findFilter(filterName).getInitParam().add(paramValue);
return this;
}
private Filter findFilter(final String filterName) {
for (final Filter s : getFilter()) {
if (filterName.equals(s.getFilterName())) {
return s;
}
}
return null;
}
public WebApp contextRoot(final String root) {
setContextRoot(root);
return this;
}
public WebApp addListener(final String classname) {
final Listener l = new Listener();
l.setListenerClass(classname);
getListener().add(l);
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy