Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * JBoss, Home of Professional Open Source.
    * Copyright 2008, Red Hat Middleware LLC, and individual contributors
    * as indicated by the @author tags. See the copyright.txt file in the
    * distribution for a full listing of individual contributors.
    *
    * This is free software; you can redistribute it and/or modify it
    * under the terms of the GNU Lesser General Public License as
    * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.jboss.web.tomcat.service.deployers;
  
  // $Id: JBossContextConfig.java 104399 2010-05-03 20:50:38Z remy.maucherat@jboss.com $
  
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  
 
 @SuppressWarnings("unchecked")
 public class JBossContextConfig extends ContextConfig
 {
 
 
    public static ThreadLocal<KernelkernelLocal = new ThreadLocal<Kernel>();
 
 
    private static Logger log = Logger.getLogger(JBossContextConfig.class);
 
    private Set<Stringoverlays = new HashSet<String>();
    
    private boolean runDestroy = false;

   

Creates a new instance of JBossContextConfig.

 
    public JBossContextConfig()
    {
       super();
       try
       {
          Map authMap = this.getAuthenticators();
          if (authMap.size() > 0)
              = authMap;
       }
       catch (Exception e)
       {
          .debug("Failed to load the customized authenticators"e);
       }
    }
 
    public void lifecycleEvent(LifecycleEvent event) {
       if (event.getType().equals(.)) {
          // Invoke ServletContainerInitializer
          Map<ServletContainerInitializerSet<Class<?>>> handlesTypes = (Map<ServletContainerInitializerSet<Class<?>>>) 
          if (scis != null)
          {
             for (ServletContainerInitializer sci : scis)
             {
                try
                {
                   sci.onStartup(handlesTypes.get(sci), .getServletContext());
                }
                catch (Throwable t)
                {
                   .error("Error calling onStartup for servlet container initializer: " + sci.getClass().getName(), t);
                    = false;
                }
             }
          }
          // Post order
          List<Stringorder = (List<String>) 
          {
          }
       }
       super.lifecycleEvent(event);
    }
    
    protected void applicationWebConfig()
    {
    }
 
    protected void defaultWebConfig()
    {
       JBossWebMetaData sharedJBossWebMetaData = (JBossWebMetaData)
       if (sharedJBossWebMetaData != null)
       {
          processWebMetaData(sharedJBossWebMetaData);
       }
 
       ServletContext servletContext = .getServletContext();
       Kernel kernel = .get();
       DeploymentUnit unit = .get();
       .debug("Setting MC attributes, kernel: " + kernel + ", unit: " + unit);
       servletContext.setAttribute(.kernel);
       servletContext.setAttribute(DeploymentUnit.class.getName(), unit);
    }
 
    protected void processWebMetaData(JBossWebMetaData metaData)
    {
       if ( instanceof StandardContext)
       {
          ((StandardContext)).setReplaceWelcomeFiles(true);
       }
 
       // Version
       .setVersion(metaData.getVersion());
 
       // SetPublicId
       if (metaData.is30())
          .setPublicId("/javax/servlet/resources/web-app_3_0.dtd");
       else if (metaData.is25())
          .setPublicId("/javax/servlet/resources/web-app_2_5.dtd");
       else if (metaData.is24())
          .setPublicId("/javax/servlet/resources/web-app_2_4.dtd");
       else if (metaData.is23())
       else
       
       // Display name
       DescriptionGroupMetaData dg = metaData.getDescriptionGroup();
       if (dg != null)
       {
          String displayName = dg.getDisplayName();
          if (displayName != null)
          {
             .setDisplayName(displayName);
          }
       }
 
       // Distributable
       if (metaData.getDistributable() != null)
          .setDistributable(true);
 
       // Error pages
       List<ErrorPageMetaDataerrorPages = metaData.getErrorPages();
       if (errorPages != null)
       {
          for (ErrorPageMetaData value : errorPages)
          {
             org.apache.catalina.deploy.ErrorPage errorPage = new org.apache.catalina.deploy.ErrorPage();
             errorPage.setErrorCode(value.getErrorCode());
             errorPage.setExceptionType(value.getExceptionType());
             errorPage.setLocation(value.getLocation());
             .addErrorPage(errorPage);
          }
       }
 
       // Filter definitions
       FiltersMetaData filters = metaData.getFilters();
       if (filters != null)
       {
          for (FilterMetaData value : filters)
          {
             org.apache.catalina.deploy.FilterDef filterDef = new org.apache.catalina.deploy.FilterDef();
             filterDef.setFilterName(value.getName());
             filterDef.setFilterClass(value.getFilterClass());
             if (value.getInitParam() != null)
                for (ParamValueMetaData param : value.getInitParam())
                {
                   filterDef.addInitParameter(param.getParamName(), param.getParamValue());
                }
             filterDef.setAsyncSupported(value.isAsyncSupported());
             .addFilterDef(filterDef);
          }
       }
 
       // Filter mappings
       List<FilterMappingMetaDatafiltersMappings = metaData.getFilterMappings();
       if (filtersMappings != null)
       {
          for (FilterMappingMetaData value : filtersMappings)
          {
             org.apache.catalina.deploy.FilterMap filterMap = new org.apache.catalina.deploy.FilterMap();
             filterMap.setFilterName(value.getFilterName());
             List<StringservletNames = value.getServletNames();
             if (servletNames != null)
             {
                for (String name : servletNames)
                   filterMap.addServletName(name);
             }
             List<StringurlPatterns = value.getUrlPatterns();
             if (urlPatterns != null)
             {
                for (String pattern : urlPatterns)
                   filterMap.addURLPattern(pattern);
             }
             List<DispatcherTypedispatchers = value.getDispatchers();
             if (dispatchers != null)
             {
                for (DispatcherType type : dispatchers)
                   filterMap.setDispatcher(type.name());
             }
             .addFilterMap(filterMap);
          }
       }
 
       // Listeners
       List<ListenerMetaDatalisteners = metaData.getListeners();
       if (listeners != null)
       {
          for (ListenerMetaData value : listeners)
          {
             .addApplicationListener(value.getListenerClass());
          }
       }
 
       // Login configuration
       LoginConfigMetaData loginConfig = metaData.getLoginConfig();
       if (loginConfig != null)
       {
          org.apache.catalina.deploy.LoginConfig loginConfig2 = new org.apache.catalina.deploy.LoginConfig();
          loginConfig2.setAuthMethod(loginConfig.getAuthMethod());
          loginConfig2.setRealmName(loginConfig.getRealmName());
          if (loginConfig.getFormLoginConfig() != null)
          {
             loginConfig2.setLoginPage(loginConfig.getFormLoginConfig().getLoginPage());
             loginConfig2.setErrorPage(loginConfig.getFormLoginConfig().getErrorPage());
          }
          .setLoginConfig(loginConfig2);
       }
 
       // MIME mappings
       List<MimeMappingMetaDatamimes = metaData.getMimeMappings();
       if (mimes != null)
       {
          for (MimeMappingMetaData value : mimes)
          {
             .addMimeMapping(value.getExtension(), value.getMimeType());
          }
       }
 
       // Security constraints
       List<SecurityConstraintMetaDatascs = metaData.getSecurityConstraints();
       if (scs != null)
       {
          for (SecurityConstraintMetaData value : scs)
          {
             org.apache.catalina.deploy.SecurityConstraint constraint = new org.apache.catalina.deploy.SecurityConstraint();
             TransportGuaranteeType tg = value.getTransportGuarantee();
             constraint.setUserConstraint(tg.name());
             AuthConstraintMetaData acmd = value.getAuthConstraint();
             constraint.setAuthConstraint(acmd != null);
             if (acmd != null)
             {
                if (acmd.getRoleNames() != null)
                   for (String role : acmd.getRoleNames())
                   {
                      constraint.addAuthRole(role);
                   }
             }
             WebResourceCollectionsMetaData wrcs = value.getResourceCollections();
             if (wrcs != null)
             {
                for (WebResourceCollectionMetaData wrc : wrcs)
                {
                   org.apache.catalina.deploy.SecurityCollection collection2 = new org.apache.catalina.deploy.SecurityCollection();
                   collection2.setName(wrc.getName());
                   List<Stringmethods = wrc.getHttpMethods();
                   if (methods != null)
                   {
                      for (String method : wrc.getHttpMethods())
                      {
                         collection2.addMethod(method);
                      }
                   }
                   List<StringmethodOmissions = wrc.getHttpMethodOmissions();
                   if (methodOmissions != null)
                   {
                      for (String method : wrc.getHttpMethodOmissions())
                      {
                         collection2.addMethodOmission(method);
                      }
                   }
                   List<Stringpatterns = wrc.getUrlPatterns();
                   if (patterns != null)
                   {
                      for (String pattern : patterns)
                      {
                         collection2.addPattern(pattern);
                      }
                   }
                   constraint.addCollection(collection2);
                }
             }
             .addConstraint(constraint);
          }
       }
 
       // Security roles
       SecurityRolesMetaData roles = metaData.getSecurityRoles();
       if (roles != null)
       {
          for (SecurityRoleMetaData value : roles)
          {
             .addSecurityRole(value.getRoleName());
          }
       }
 
       // Servlet
       JBossServletsMetaData servlets = metaData.getServlets();
       if (servlets != null)
       {
          for (JBossServletMetaData value : servlets)
          {
             org.apache.catalina.Wrapper wrapper = .createWrapper();
             wrapper.setName(value.getName());
             wrapper.setServletClass(value.getServletClass());
             if (value.getJspFile() != null)
             {
                wrapper.setJspFile(value.getJspFile());
             }
             wrapper.setLoadOnStartup(value.getLoadOnStartupInt());
             if (value.getRunAs() != null)
             {
                wrapper.setRunAs(value.getRunAs().getRoleName());
             }
             List<ParamValueMetaDataparams = value.getInitParam();
             if (params != null)
             {
                for (ParamValueMetaData param : params)
                {
                   wrapper.addInitParameter(param.getParamName(), param.getParamValue());
                }
             }
             SecurityRoleRefsMetaData refs = value.getSecurityRoleRefs();
             if (refs != null)
             {
                for (SecurityRoleRefMetaData ref : refs)
                {
                   wrapper.addSecurityReference(ref.getRoleName(), ref.getRoleLink());
                }
             }
             wrapper.setAsyncSupported(value.isAsyncSupported());
             wrapper.setEnabled(value.isEnabled());
             // Multipart configuration
             if (value.getMultipartConfig() != null)
             {
                MultipartConfigMetaData multipartConfigMetaData = value.getMultipartConfig();
                Multipart multipartConfig = new Multipart();
                multipartConfig.setLocation(multipartConfigMetaData.getLocation());
                multipartConfig.setMaxRequestSize(multipartConfigMetaData.getMaxRequestSize());
                multipartConfig.setMaxFileSize(multipartConfigMetaData.getMaxFileSize());
                multipartConfig.setFileSizeThreshold(multipartConfigMetaData.getFileSizeThreshold());
                wrapper.setMultipartConfig(multipartConfig);
              }
             .addChild(wrapper);
          }
       }
 
       // Servlet mapping
       List<ServletMappingMetaDatasmappings = metaData.getServletMappings();
       if (smappings != null)
       {
          for (ServletMappingMetaData value : smappings)
          {
             List<StringurlPatterns = value.getUrlPatterns();
             if (urlPatterns != null)
             {
                for (String pattern : urlPatterns)
                   .addServletMapping(patternvalue.getServletName());
             }
          }
       }
 
       // JSP Config
       JspConfigMetaData config = metaData.getJspConfig();
       if (config != null)
       {
          // JSP Property groups
          List<JspPropertyGroupMetaDatagroups = config.getPropertyGroups();
          if (groups != null)
          {
             for (JspPropertyGroupMetaData group : groups)
             {
                org.apache.catalina.deploy.JspPropertyGroup jspPropertyGroup = 
                   new org.apache.catalina.deploy.JspPropertyGroup();
                for (String pattern : group.getUrlPatterns())
                {
                   jspPropertyGroup.addUrlPattern(pattern);
                }
                jspPropertyGroup.setElIgnored(group.getElIgnored());
                jspPropertyGroup.setPageEncoding(group.getPageEncoding());
                jspPropertyGroup.setScriptingInvalid(group.getScriptingInvalid());
                jspPropertyGroup.setIsXml(group.getIsXml());
                if (group.getIncludePreludes() != null)
                {
                   for (String includePrelude : group.getIncludePreludes())
                   {
                      jspPropertyGroup.addIncludePrelude(includePrelude);
                   }
                }
                if (group.getIncludeCodas() != null)
                {
                   for (String includeCoda : group.getIncludeCodas())
                   {
                      jspPropertyGroup.addIncludeCoda(includeCoda);
                   }
                }
                jspPropertyGroup.setDeferredSyntaxAllowedAsLiteral(group.getDeferredSyntaxAllowedAsLiteral());
                jspPropertyGroup.setTrimDirectiveWhitespaces(group.getTrimDirectiveWhitespaces());
                jspPropertyGroup.setDefaultContentType(group.getDefaultContentType());
                jspPropertyGroup.setBuffer(group.getBuffer());
                jspPropertyGroup.setErrorOnUndeclaredNamespace(group.getErrorOnUndeclaredNamespace());
                .addJspPropertyGroup(jspPropertyGroup);
             }
          }
          // Taglib
          List<TaglibMetaDatataglibs = config.getTaglibs();
          if (taglibs != null)
          {
             for (TaglibMetaData taglib : taglibs)
             {
                .addTaglib(taglib.getTaglibUri(), taglib.getTaglibLocation());
             }
          }
       }
 
       // Locale encoding mapping
       LocaleEncodingsMetaData locales = metaData.getLocalEncodings();
       if (locales != null)
       {
          for (LocaleEncodingMetaData value : locales.getMappings())
          {
             .addLocaleEncodingMappingParameter(value.getLocale(), value.getEncoding());
          }
       }
 
       // Welcome files
       WelcomeFileListMetaData welcomeFiles = metaData.getWelcomeFileList();
       if (welcomeFiles != null)
       {
          for (String value : welcomeFiles.getWelcomeFiles())
             .addWelcomeFile(value);
       }
 
       // Session timeout
       SessionConfigMetaData scmd = metaData.getSessionConfig();
       if (scmd != null)
       {
          .setSessionTimeout(scmd.getSessionTimeout());
          if (scmd.getSessionTrackingModes() != null)
          {
             for (SessionTrackingModeType stmt : scmd.getSessionTrackingModes())
             {
                .addSessionTrackingMode(stmt.toString());
             }
          }
          if (scmd.getCookieConfig() != null)
          {
             CookieConfigMetaData value = scmd.getCookieConfig();
             org.apache.catalina.deploy.SessionCookie cookieConfig = 
                new org.apache.catalina.deploy.SessionCookie();
             cookieConfig.setName(value.getName());
             cookieConfig.setDomain(value.getDomain());
             cookieConfig.setPath(value.getPath());
             cookieConfig.setComment(value.getComment());
             cookieConfig.setHttpOnly(value.getHttpOnly());
             cookieConfig.setSecure(value.getSecure());
             cookieConfig.setMaxAge(value.getMaxAge());
             .setSessionCookie(cookieConfig);
          }
       }
    }

   

Retrieves the map of authenticators according to the settings made available by TomcatService.

Returns:
a Map containing the authenticator that must be used for each authentication method.
Throws:
java.lang.Exception if an error occurs while getting the authenticators.
 
    protected Map getAuthenticators() throws Exception
    {
       Map authenticators = new HashMap();
       ClassLoader tcl = Thread.currentThread().getContextClassLoader();
 
       Properties authProps = this.getAuthenticatorsFromJndi();
       if (authProps != null)
       {
          Set keys = authProps.keySet();
          Iterator iter = keys != null ? keys.iterator() : null;
          while (iter != null && iter.hasNext())
          {
             String key = (String)iter.next();
             String authenticatorStr = (String)authProps.get(key);
             Class authClass = tcl.loadClass(authenticatorStr);
             authenticators.put(keyauthClass.newInstance());
          }
       }
       if (.isTraceEnabled())
          .trace("Authenticators plugged in::" + authenticators);
       return authenticators;
    }

   

Get the key-pair of authenticators from the JNDI.

Returns:
a Properties object containing the authenticator class name for each authentication method.
Throws:
javax.naming.NamingException if an error occurs while looking up the JNDI.
 
    {
       return (Properties)new InitialContext().lookup("TomcatAuthenticators");
    }

   
Process the context parameters. Let a user application override the sharedMetaData values.
 
    protected void processContextParameters()
    {
       JBossWebMetaData local = .get();
       JBossWebMetaData shared = (JBossWebMetaData)
       
       if (shared == null)
          return;
 
       Map<StringStringoverrideParams = new HashMap<StringString>();
 
       List<ParamValueMetaDataparams = local.getContextParams();
       if (params != null)
       {
          for (ParamValueMetaData param : params)
          {
             overrideParams.put(param.getParamName(), param.getParamValue());
          }
       }
       params = shared.getContextParams();
       if (params != null)
       {
          for (ParamValueMetaData param : params)
          {
             if (overrideParams.get(param.getParamName()) == null)
             {
                overrideParams.put(param.getParamName(), param.getParamValue());
             }
          }
       }
 
       for (String key : overrideParams.keySet())
       {
          .addParameter(keyoverrideParams.get(key));
       }
 
    }

   
Process a "init" event for this Context.
 
    protected void init()
    {
 
       .setConfigured(false);
        = true;
 
       if (!.getOverride())
       {
          processContextConfig("context.xml"false);
       }
       // This should come from the deployment unit
       processContextConfig("WEB-INF/context.xml"true);
 
    }
 
    protected void processContextConfig(String resourceNameboolean local)
    {
       ClassLoader oldCl = SecurityActions.getContextClassLoader();
       SecurityActions.setContextClassLoader(this.getClass().getClassLoader());
       
       ContextMetaData contextMetaData = null;
       try
       {
          SchemaBinding schema = JBossXBBuilder.build(ContextMetaData.class);
          Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
          u.setSchemaValidation(false);
          u.setValidation(false);
          u.setEntityResolver(new JBossEntityResolver());
          
          InputStream is = null;
          try
          {
             if (local)
             {
                DeploymentUnit localUnit = .get();
                if (localUnit instanceof VFSDeploymentUnit)
                {
                   VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit)localUnit;
                   VirtualFile vf = vfsUnit.getFile(resourceName);
                   if (vf != null)
                      is = vf.openStream();
                }
             }
 
             if (is == null)
                is = getClass().getClassLoader().getResourceAsStream(resourceName);
 
             if (is != null)
                contextMetaData = ContextMetaData.class.cast(u.unmarshal(isschema));
          }
          finally
          {
             if (is != null)
             {
                try
                {
                   is.close();
                }
                catch (IOException e)
                {
                   // Ignore
                }
             }
          }
       }
       catch (Exception e)
       {
          .error("XML error parsing: " + resourceNamee);
           = false;
          return;
       }
       finally
       {
          SecurityActions.setContextClassLoader(oldCl);
       }
 
       if (contextMetaData != null)
       {
          try
          {
             if (contextMetaData.getAttributes() != null)
             {
                Iterator<QNamenames = contextMetaData.getAttributes().keySet().iterator();
                while (names.hasNext())
                {
                   QName name = names.next();
                   String value = (String)contextMetaData.getAttributes().get(name);
                   // FIXME: This should be done by XB
                   value = StringPropertyReplacer.replaceProperties(value);
                   IntrospectionUtils.setProperty(name.getLocalPart(), value);
                }
             }
 
             TomcatService.addLifecycleListeners(contextMetaData.getListeners());
 
             // Context/Realm
             if (contextMetaData.getRealm() != null)
             {
                .setRealm((org.apache.catalina.Realm)TomcatService.getInstance(contextMetaData.getRealm(), null));
             }
 
             // Context/Valve
             TomcatService.addValves(contextMetaData.getValves());
 
             // Context/InstanceListener
             if (contextMetaData.getInstanceListeners() != null)
             {
                Iterator<Stringlisteners = contextMetaData.getInstanceListeners().iterator();
                while (listeners.hasNext())
                {
                   .addInstanceListener(listeners.next());
                }
             }
 
             // Context/Loader
             if (contextMetaData.getLoader() != null)
             {
                // This probably won't work very well in JBoss
                .setLoader((org.apache.catalina.Loader)TomcatService.getInstance(contextMetaData.getLoader(), "org.apache.catalina.loader.WebappLoader"));
             }
 
             // Context/Manager
             if (contextMetaData.getManager() != null)
             {
                Manager manager = initManager(contextMetaData.getManager());
                
                if (contextMetaData.getManager().getStore() != null)
                {
                   org.apache.catalina.Store store = (org.apache.catalina.Store)TomcatService.getInstance
                      (contextMetaData.getManager().getStore(), null);
                   try {
                      org.apache.catalina.session.PersistentManagerBase.class.getMethod("setStore"org.apache.catalina.Store.class)
                         .invoke(managerstore);
                   } catch (Throwable t) {
                      // Ignore
                      .error("Could not set persistent store"t);
                   }
                }
                .setManager(manager);
             }
 
             // Context/Parameter
             if (contextMetaData.getParameters() != null)
             {
                Iterator<ParameterMetaDataparameterMetaDatas = contextMetaData.getParameters().iterator();
                while (parameterMetaDatas.hasNext())
                {
                   ParameterMetaData parameterMetaData = parameterMetaDatas.next();
                   .addApplicationParameter((org.apache.catalina.deploy.ApplicationParameter)TomcatService.getInstance(parameterMetaDatanull));
                }
             }
 
             // Context/Resources
             if (contextMetaData.getResources() != null)
             {
                .setResources((javax.naming.directory.DirContext)TomcatService.getInstance(contextMetaData.getResources(),
                      "org.apache.naming.resources.FileDirContext"));
             }
 
             // Context/SessionCookie
             if (contextMetaData.getSessionCookie() != null)
             {
                SessionCookie sessionCookie = new SessionCookie();
                sessionCookie.setComment(contextMetaData.getSessionCookie().getComment());
                sessionCookie.setDomain(contextMetaData.getSessionCookie().getDomain());
                sessionCookie.setHttpOnly(contextMetaData.getSessionCookie().getHttpOnly());
                sessionCookie.setPath(contextMetaData.getSessionCookie().getPath());
                sessionCookie.setSecure(contextMetaData.getSessionCookie().getSecure());
                .setSessionCookie(sessionCookie);
             }
 
             // Context/WrapperLifecycle
             if (contextMetaData.getWrapperLifecycles() != null)
             {
                Iterator<Stringlisteners = contextMetaData.getWrapperLifecycles().iterator();
                while (listeners.hasNext())
                {
                   .addWrapperLifecycle(listeners.next());
                }
             }
 
             // Context/WrapperListeners
             if (contextMetaData.getWrapperListeners() != null)
             {
                Iterator<Stringlisteners = contextMetaData.getWrapperListeners().iterator();
                while (listeners.hasNext())
                {
                   .addWrapperListener(listeners.next());
                }
             }
 
             // Context/Overlay
             if (contextMetaData.getOverlays() != null)
             {
                .addAll(contextMetaData.getOverlays());
             }
 
          }
          catch (Exception e)
          {
             .error("Error processing: " + resourceNamee);
              = false;
          }
       }
    }
 
    protected void destroy()
    {
       if ()
       {
          super.destroy();
       }
    }

   
Migrate TLD metadata to Catalina. This is separate, and is not subject to the order defined.
 
    protected void applicationTldConfig()
    {
       
       Map<StringTldMetaDatatldMetaDataMap = .get();
       if (tldMetaDataMap == null)
       {
          return;
       }
       
       ArrayList<TagLibraryInfotagLibraries = new ArrayList<TagLibraryInfo>();
 
       Iterator<StringlocationInterator = tldMetaDataMap.keySet().iterator();
       while (locationInterator.hasNext())
       {
          String relativeLocation = null;
          String jarPath = null;
          
          String location = locationInterator.next();
          TldMetaData tldMetaData = tldMetaDataMap.get(location);
          if (!location.startsWith("shared:"))
          {
             relativeLocation = "/" + location.substring(TldMetaData.class.getName().length() + 1);
             if (relativeLocation.startsWith("/WEB-INF/lib/"))
             {
                int pos = relativeLocation.indexOf('/'"/WEB-INF/lib/".length());
                if (pos > 0)
                {
                   jarPath = relativeLocation.substring(pos);
                   if (jarPath.startsWith("/"))
                   {
                      jarPath = jarPath.substring(1);
                   }
                   relativeLocation = relativeLocation.substring(0, pos);
                }
             }
          }
 
          TagLibraryInfo tagLibraryInfo = new TagLibraryInfo();
          tagLibraryInfo.setTlibversion(tldMetaData.getTlibVersion());
          if (tldMetaData.getJspVersion() == null)
             tagLibraryInfo.setJspversion(tldMetaData.getVersion());
          else
             tagLibraryInfo.setJspversion(tldMetaData.getJspVersion());
          tagLibraryInfo.setShortname(tldMetaData.getShortName());
          tagLibraryInfo.setUri(tldMetaData.getUri());
          if (tldMetaData.getDescriptionGroup() != null)
          {
             tagLibraryInfo.setInfo(tldMetaData.getDescriptionGroup().getDescription());
          }
          // Listener
          if (tldMetaData.getListeners() != null)
          {
             for (ListenerMetaData listener : tldMetaData.getListeners())
             {
                tagLibraryInfo.addListener(listener.getListenerClass());
             }
          }
          // Validator
          if (tldMetaData.getValidator() != null)
          {
             TagLibraryValidatorInfo tagLibraryValidatorInfo = new TagLibraryValidatorInfo();
             tagLibraryValidatorInfo.setValidatorClass(tldMetaData.getValidator().getValidatorClass());
             if (tldMetaData.getValidator().getInitParams() != null)
             {
                for (ParamValueMetaData paramValueMetaData : tldMetaData.getValidator().getInitParams())
                {
                   tagLibraryValidatorInfo.addInitParam(paramValueMetaData.getParamName(), paramValueMetaData.getParamValue());
                }
             }
             tagLibraryInfo.setValidator(tagLibraryValidatorInfo);
          }
          // Tag
          if (tldMetaData.getTags() != null)
          {
             for (TagMetaData tagMetaData : tldMetaData.getTags())
             {
                TagInfo tagInfo = new TagInfo();
                tagInfo.setTagName(tagMetaData.getName());
                tagInfo.setTagClassName(tagMetaData.getTagClass());
                tagInfo.setTagExtraInfo(tagMetaData.getTeiClass());
                if (tagMetaData.getBodyContent() != null)
                   tagInfo.setBodyContent(tagMetaData.getBodyContent().toString());
                tagInfo.setDynamicAttributes(tagMetaData.getDynamicAttributes());
                // Description group
                if (tagMetaData.getDescriptionGroup() != null)
                {
                   DescriptionGroupMetaData descriptionGroup = tagMetaData.getDescriptionGroup();
                   if (descriptionGroup.getIcons() != null && descriptionGroup.getIcons().value() != null
                         && (descriptionGroup.getIcons().value().length > 0))
                   {
                      Icon icon = descriptionGroup.getIcons().value()[0];
                      tagInfo.setLargeIcon(icon.largeIcon());
                      tagInfo.setSmallIcon(icon.smallIcon());
                  }
                  tagInfo.setInfoString(descriptionGroup.getDescription());
                  tagInfo.setDisplayName(descriptionGroup.getDisplayName());
               }
               // Variable
               if (tagMetaData.getVariables() != null)
               {
                  for (VariableMetaData variableMetaData : tagMetaData.getVariables())
                  {
                     TagVariableInfo tagVariableInfo = new TagVariableInfo();
                     tagVariableInfo.setNameGiven(variableMetaData.getNameGiven());
                     tagVariableInfo.setNameFromAttribute(variableMetaData.getNameFromAttribute());
                     tagVariableInfo.setClassName(variableMetaData.getVariableClass());
                     tagVariableInfo.setDeclare(variableMetaData.getDeclare());
                     if (variableMetaData.getScope() != null)
                        tagVariableInfo.setScope(variableMetaData.getScope().toString());
                     tagInfo.addTagVariableInfo(tagVariableInfo);
                  }
               }
               // Attribute
               if (tagMetaData.getAttributes() != null)
               {
                  for (AttributeMetaData attributeMetaData : tagMetaData.getAttributes())
                  {
                     TagAttributeInfo tagAttributeInfo = new TagAttributeInfo();
                     tagAttributeInfo.setName(attributeMetaData.getName());
                     tagAttributeInfo.setType(attributeMetaData.getType());
                     tagAttributeInfo.setReqTime(attributeMetaData.getRtexprvalue());
                     tagAttributeInfo.setRequired(attributeMetaData.getRequired());
                     tagAttributeInfo.setFragment(attributeMetaData.getFragment());
                     if (attributeMetaData.getDeferredValue() != null) {
                        tagAttributeInfo.setDeferredValue("true");
                        tagAttributeInfo.setExpectedTypeName(attributeMetaData.getDeferredValue().getType());
                     }
                     else
                     {
                        tagAttributeInfo.setDeferredValue("false");
                     }
                     if (attributeMetaData.getDeferredMethod() != null)
                     {
                        tagAttributeInfo.setDeferredMethod("true");
                        tagAttributeInfo.setMethodSignature(attributeMetaData.getDeferredMethod().getMethodSignature());
                     }
                     else
                     {
                        tagAttributeInfo.setDeferredMethod("false");
                     }
                     tagInfo.addTagAttributeInfo(tagAttributeInfo);
                  }
               }
               tagLibraryInfo.addTagInfo(tagInfo);
            }
         }
         // Tag files
         if (tldMetaData.getTagFiles() != null)
         {
            for (TagFileMetaData tagFileMetaData : tldMetaData.getTagFiles())
            {
               TagFileInfo tagFileInfo = new TagFileInfo();
               tagFileInfo.setName(tagFileMetaData.getName());
               tagFileInfo.setPath(tagFileMetaData.getPath());
               tagLibraryInfo.addTagFileInfo(tagFileInfo);
            }
         }
         // Function
         if (tldMetaData.getFunctions() != null)
         {
            for (FunctionMetaData functionMetaData : tldMetaData.getFunctions())
            {
               FunctionInfo functionInfo = new FunctionInfo();
               functionInfo.setName(functionMetaData.getName());
               functionInfo.setFunctionClass(functionMetaData.getFunctionClass());
               functionInfo.setFunctionSignature(functionMetaData.getFunctionSignature());
               tagLibraryInfo.addFunctionInfo(functionInfo);
            }
         }
         
         if (jarPath == null && relativeLocation == null)
         {
            .addJspTagLibrary(tagLibraryInfo);
         }
         else if (jarPath == null)
         {
            tagLibraryInfo.setLocation("");
            tagLibraryInfo.setPath(relativeLocation);
            tagLibraries.add(tagLibraryInfo);
            .addJspTagLibrary(tagLibraryInfo);
            .addJspTagLibrary(relativeLocationtagLibraryInfo);
         }
         else
         {
            tagLibraryInfo.setLocation(relativeLocation);
            tagLibraryInfo.setPath(jarPath);
            tagLibraries.add(tagLibraryInfo);
            .addJspTagLibrary(tagLibraryInfo);
            if (jarPath.equals("META-INF/taglib.tld"))
            {
               .addJspTagLibrary(relativeLocationtagLibraryInfo);
            }
         }
      }
      // Add additional TLDs URIs from explicit web config
      String taglibs[] = .findTaglibs();
      for (int i = 0; i < taglibs.lengthi++) {
          String uri = taglibs[i];
          String path = .findTaglib(taglibs[i]);
          String location = "";
          if (path.indexOf(':') == -1 && !path.startsWith("/")) {
              path = "/WEB-INF/" + path;
          }
          if (path.endsWith(".jar")) {
              location = path;
              path = "META-INF/taglib.tld";
          }
          for (int j = 0; j < tagLibraries.size(); j++) {
              TagLibraryInfo tagLibraryInfo = tagLibraries.get(j);
              if (tagLibraryInfo.getLocation().equals(location) && tagLibraryInfo.getPath().equals(path)) {
                  .addJspTagLibrary(uritagLibraryInfo);
              }
          }
      }
   }
   {
      // Do nothing here
   }
   
   protected void createFragmentsOrder()
   {
      // Do nothing here
   }
   protected void applicationExtraDescriptorsConfig()
   {
      // Do nothing here
   }
   protected void resolveAnnotations(JBossAnnotationsMetaData annotations)
   {
      if (annotations != null)
      {
         for (AnnotationMetaData annotation : annotations)
         {
            String className = annotation.getClassName();
            Container wrappers[] = .findChildren();
            for (int i = 0; i < wrappers.lengthi++) {
                Wrapper wrapper = (Wrapperwrappers[i];
                if (className.equals(wrapper.getServletClass()))
                {
                   
                   // Merge @RunAs
                   if (annotation.getRunAs() != null && wrapper.getRunAs() == null)
                   {
                      wrapper.setRunAs(annotation.getRunAs().getRoleName());
                   }
                   // Merge @MultipartConfig
                   if (annotation.getMultipartConfig() != null && wrapper.getMultipartConfig() == null)
                   {
                      MultipartConfigMetaData multipartConfigMetaData = annotation.getMultipartConfig();
                      Multipart multipartConfig = new Multipart();
                      multipartConfig.setLocation(multipartConfigMetaData.getLocation());
                      multipartConfig.setMaxRequestSize(multipartConfigMetaData.getMaxRequestSize());
                      multipartConfig.setMaxFileSize(multipartConfigMetaData.getMaxFileSize());
                      multipartConfig.setFileSizeThreshold(multipartConfigMetaData.getFileSizeThreshold());
                      wrapper.setMultipartConfig(multipartConfig);
                   }
                   // Merge @ServletSecurity
                   if (annotation.getServletSecurity() != null && wrapper.getServletSecurity() == null)
                   {
                      ServletSecurityMetaData servletSecurityAnnotation = annotation.getServletSecurity();
                      Collection<HttpMethodConstraintElementmethodConstraints = null;
                      
                      EmptyRoleSemantic emptyRoleSemantic =  .;
                      if (servletSecurityAnnotation.getEmptyRoleSemantic() != null)
                      {
                         emptyRoleSemantic = EmptyRoleSemantic.valueOf(servletSecurityAnnotation.getEmptyRoleSemantic().toString());
                      }
                      TransportGuarantee transportGuarantee = .;
                      if (servletSecurityAnnotation.getTransportGuarantee() != null)
                      {
                         transportGuarantee = TransportGuarantee.valueOf(servletSecurityAnnotation.getTransportGuarantee().toString());
                      }
                      String[] roleNames = servletSecurityAnnotation.getRolesAllowed().toArray(new String[0]);
                      HttpConstraintElement constraint = new HttpConstraintElement(emptyRoleSemantictransportGuaranteeroleNames);
                      
                      if (servletSecurityAnnotation.getHttpMethodConstraints() != null)
                      {
                         methodConstraints = new HashSet<HttpMethodConstraintElement>();
                         for (HttpMethodConstraintMetaData annotationMethodConstraint : 
                            servletSecurityAnnotation.getHttpMethodConstraints())
                         {
                            emptyRoleSemantic =  .;
                            if (annotationMethodConstraint.getEmptyRoleSemantic() != null)
                            {
                               emptyRoleSemantic = EmptyRoleSemantic.valueOf(annotationMethodConstraint.getEmptyRoleSemantic().toString());
                            }
                            transportGuarantee = .;
                            if (annotationMethodConstraint.getTransportGuarantee() != null)
                            {
                               transportGuarantee = TransportGuarantee.valueOf(annotationMethodConstraint.getTransportGuarantee().toString());
                            }
                            roleNames = annotationMethodConstraint.getRolesAllowed().toArray(new String[0]);
                            HttpConstraintElement constraint2 = 
                               new HttpConstraintElement(emptyRoleSemantictransportGuaranteeroleNames);
                            HttpMethodConstraintElement methodConstraint = 
                               new HttpMethodConstraintElement(annotationMethodConstraint.getMethod(), constraint2);
                            methodConstraints.add(methodConstraint);
                         }
                      }
                      
                      ServletSecurityElement servletSecurity = new ServletSecurityElement(constraintmethodConstraints);
                      wrapper.setServletSecurity(servletSecurity);
                   }
                   
                }
            }
         }
      }
   }
   protected Manager initManager(ManagerMetaData managerMetaDatathrows Exception,
   {
      JBossWebMetaData webMetaData = .get();
      
      String defaultManagerClass = webMetaData.getDistributable() == null 
            ? StandardManager.class.getName() : JBossCacheManager.class.getName();      
      Manager manager = (Manager)TomcatService.getInstance(managerMetaDatadefaultManagerClass);
      
      if (manager instanceof AbstractJBossManager)
      {
         // TODO next 10+ lines just to create a 'name' that the AbstractJBossManager
         // impls don't even use
         Host host = null;
         Container container = ;
         while (host == null && container != null)
         {
            container = container.getParent();
            if (container instanceof Host)
            {
               host = (Hostcontainer;
            }
         }
         String hostName = host.getName();
         String name = "//" + ((hostName == null) ? "localhost" : hostName) + webMetaData.getContextRoot();
         
         try
         {
            ((AbstractJBossManagermanager).init(namewebMetaData);
         }
         catch (ClusteringNotSupportedException e)
         {
            if (managerMetaData.getClassName() == null)
            {  
               // JBAS-3513 Just log a WARN, not an ERROR
               .warn("Failed to setup clustering, clustering disabled. ClusteringNotSupportedException: " + e.getMessage());
               manager = (Manager)TomcatService.getInstance(managerMetaDataStandardManager.class.getName());
            }
            else
            {
               throw e;
            }
         }
         catch (NoClassDefFoundError ncdf)
         {
            if (managerMetaData.getClassName() == null)
            {  
               // JBAS-3513 Just log a WARN, not an ERROR
               .debug("Classes needed for clustered webapp unavailable"ncdf);
               .warn("Failed to setup clustering, clustering disabled. NoClassDefFoundError: " + ncdf.getMessage());
               manager = (Manager)TomcatService.getInstance(managerMetaDataStandardManager.class.getName());
            }
            else
            {
               throw ncdf;
            }
            
         }
      }
      return manager;
   }
   
   protected void completeConfig() {
      JBossWebMetaData metaData = .get();
      
      // Process Servlet API related annotations that were dependent on Servlet declarations
      if ( && (metaData != null))
      {
         // Resolve type specific annotations to their corresponding Servlet components
         metaData.resolveAnnotations();
         // Same process for Catalina
         resolveAnnotations(metaData.getAnnotations());
      }
      if ()
      {
         resolveServletSecurity();
      }
      if ()
      {
         validateSecurityRoles();
      }
      
      if ( && (metaData != null))
      {
         // Resolve run as
         metaData.resolveRunAs();
      }
      // Configure an authenticator if we need one
      if ()
      {
         authenticatorConfig();
      }
      // Find and configure overlays
      DeploymentUnit deploymentUnit = .get();
      if ( && (deploymentUnit != null)) {
         Set<VirtualFileoverlays = (Set<VirtualFile>) 
         if (overlays != null)
         {
            if (.getResources() instanceof ProxyDirContext) {
               ProxyDirContext resources = (ProxyDirContext.getResources();
               for (VirtualFile overlay : overlays)
               {
                  // JBAS-7832: Replaced with FileDirContext for now
                  //VFSDirContext vfsDirContext = new VFSDirContext(overlay);
                  //resources.addOverlay(vfsDirContext);
                  FileDirContext dirContext = new FileDirContext();
                  try
                  {
                     dirContext.setDocBase(overlay.getPhysicalFile().getAbsolutePath());
                     resources.addOverlay(dirContext);
                  }
                  catch (IOException e)
                  {
                     .error(.getString("contextConfig.noOverlay".getName()), e);
                      = false;
                     break;
                  }
               }
            }
            else if (overlays.size() > 0)
            {
               // Error, overlays need a ProxyDirContext to compose results
               .error(.getString("contextConfig.noOverlay".getName()));
                = false;
            }
         }
      }
      
      // Add other overlays, if any
      if ()
      {
         for (String overlay : )
         {
            if (.getResources() instanceof ProxyDirContext)
            {
               ProxyDirContext resources = (ProxyDirContext.getResources();
               FileDirContext dirContext = new FileDirContext();
               dirContext.setDocBase(overlay);
               resources.addOverlay(dirContext);
            }
         }
      }
      // Make our application unavailable if problems were encountered
      if (!) {
         .error(.getString("contextConfig.unavailable"));
         .setConfigured(false);
      }
   }
New to GrepCode? Check out our FAQ X