Package org.jboss.web.tomcat.metadata

Examples of org.jboss.web.tomcat.metadata.ContextMetaData


   protected void processContextConfig(String resourceName, boolean 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 = deploymentUnitLocal.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(is, schema));
         }
         finally
         {
            if (is != null)
            {
               try
               {
                  is.close();
               }
               catch (IOException e)
               {
                  // Ignore
               }
            }
         }
      }
      catch (Exception e)
      {
         log.error("XML error parsing: " + resourceName, e);
         ok = false;
         return;
      }
      finally
      {
         SecurityActions.setContextClassLoader(oldCl);
      }

      if (contextMetaData != null)
      {
         try
         {
            if (contextMetaData.getAttributes() != null)
            {
               Iterator<QName> names = 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(context, name.getLocalPart(), value);
               }
            }

            TomcatService.addLifecycleListeners(context, contextMetaData.getListeners());

            // Context/Realm
            if (contextMetaData.getRealm() != null)
            {
               context.setRealm((org.apache.catalina.Realm)TomcatService.getInstance(contextMetaData.getRealm(), null));
            }

            // Context/Valve
            TomcatService.addValves(context, contextMetaData.getValves());

            // Context/InstanceListener
            if (contextMetaData.getInstanceListeners() != null)
            {
               Iterator<String> listeners = contextMetaData.getInstanceListeners().iterator();
               while (listeners.hasNext())
               {
                  context.addInstanceListener(listeners.next());
               }
            }

            // Context/Loader
            if (contextMetaData.getLoader() != null)
            {
               // This probably won't work very well in JBoss
               context.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(manager, store);
                  } catch (Throwable t) {
                     // Ignore
                     log.error("Could not set persistent store", t);
                  }
               }
               context.setManager(manager);
            }

            // Context/Parameter
            if (contextMetaData.getParameters() != null)
            {
               Iterator<ParameterMetaData> parameterMetaDatas = contextMetaData.getParameters().iterator();
               while (parameterMetaDatas.hasNext())
               {
                  ParameterMetaData parameterMetaData = parameterMetaDatas.next();
                  context.addApplicationParameter((org.apache.catalina.deploy.ApplicationParameter)TomcatService.getInstance(parameterMetaData, null));
               }
            }

            // Context/Resources
            if (contextMetaData.getResources() != null)
            {
               context.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());
               context.setSessionCookie(sessionCookie);
            }

            // Context/WrapperLifecycle
            if (contextMetaData.getWrapperLifecycles() != null)
            {
               Iterator<String> listeners = contextMetaData.getWrapperLifecycles().iterator();
               while (listeners.hasNext())
               {
                  context.addWrapperLifecycle(listeners.next());
               }
            }

            // Context/WrapperListeners
            if (contextMetaData.getWrapperListeners() != null)
            {
               Iterator<String> listeners = contextMetaData.getWrapperListeners().iterator();
               while (listeners.hasNext())
               {
                  context.addWrapperListener(listeners.next());
               }
            }

            // Context/Overlay
            if (contextMetaData.getOverlays() != null)
            {
               overlays.addAll(contextMetaData.getOverlays());
            }

         }
         catch (Exception e)
         {
View Full Code Here


      processContextConfig(context.getConfigFile(), true);
   }

   protected void processContextConfig(String resourceName, boolean local)
   {
      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 = deploymentUnitLocal.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(is, schema));
         }
         finally
         {
            if (is != null)
            {
               try
               {
                  is.close();
               }
               catch (IOException e)
               {
                  // Ignore
               }
            }
         }
      }
      catch (Exception e)
      {
         log.error("XML error parsing: " + resourceName, e);
         ok = false;
         return;
      }

      if (contextMetaData != null)
      {
         try
         {
            if (contextMetaData.getAttributes() != null)
            {
               Iterator<QName> names = 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(context, name.getLocalPart(), value);
               }
            }

            TomcatService.addLifecycleListeners(context, contextMetaData.getListeners());

            // Context/Realm
            if (contextMetaData.getRealm() != null)
            {
               context.setRealm((org.apache.catalina.Realm)TomcatService.getInstance(contextMetaData.getRealm(), null));
            }

            // Context/Valve
            TomcatService.addValves(context, contextMetaData.getValves());

            // Context/InstanceListener
            if (contextMetaData.getInstanceListeners() != null)
            {
               Iterator<String> listeners = contextMetaData.getInstanceListeners().iterator();
               while (listeners.hasNext())
               {
                  context.addInstanceListener(listeners.next());
               }
            }

            // Context/Loader
            if (contextMetaData.getLoader() != null)
            {
               // This probably won't work very well in JBoss
               context.setLoader((org.apache.catalina.Loader)TomcatService.getInstance(contextMetaData.getLoader(), "org.apache.catalina.loader.WebappLoader"));
            }

            // Context/Manager
            if (contextMetaData.getManager() != null)
            {
               context.setManager((org.apache.catalina.Manager)TomcatService.getInstance(contextMetaData.getManager(),
                     "org.apache.catalina.session.StandardManager"));
            }

            // Context/Parameter
            if (contextMetaData.getParameters() != null)
            {
               Iterator<ParameterMetaData> parameterMetaDatas = contextMetaData.getParameters().iterator();
               while (parameterMetaDatas.hasNext())
               {
                  ParameterMetaData parameterMetaData = parameterMetaDatas.next();
                  context.addApplicationParameter((org.apache.catalina.deploy.ApplicationParameter)TomcatService.getInstance(parameterMetaData, null));
               }
            }

            // Context/Resources
            if (contextMetaData.getResources() != null)
            {
               context.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());
               context.setSessionCookie(sessionCookie);
            }

         }
         catch (Exception e)
View Full Code Here

TOP

Related Classes of org.jboss.web.tomcat.metadata.ContextMetaData

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.