[jboss-cvs] JBossAS SVN: r100852 - trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 11 00:20:09 EST 2010


Author: bstansberry at jboss.com
Date: 2010-02-11 00:20:08 -0500 (Thu, 11 Feb 2010)
New Revision: 100852

Modified:
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand/OnDemandContextProfileManager.java
Log:
[JBAS-7713] Minor improvements

Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand/OnDemandContextProfileManager.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand/OnDemandContextProfileManager.java	2010-02-11 04:38:42 UTC (rev 100851)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/ondemand/OnDemandContextProfileManager.java	2010-02-11 05:20:08 UTC (rev 100852)
@@ -31,6 +31,7 @@
 import org.jboss.logging.Logger;
 import org.jboss.profileservice.spi.NoSuchProfileException;
 import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileFactory;
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.profileservice.spi.ProfileService;
 import org.jboss.profileservice.spi.metadata.ProfileMetaData;
@@ -41,7 +42,6 @@
 import org.jboss.system.server.profile.repository.metadata.BasicSubProfileMetaData;
 import org.jboss.system.server.profile.repository.metadata.HotDeploymentProfileSourceMetaData;
 import org.jboss.system.server.profile.repository.metadata.ImmutableProfileSourceMetaData;
-import org.jboss.system.server.profileservice.repository.AbstractProfileFactory;
 
 /**
  * {@link ContextDemandListener} that creates and registers a {@link ProfileService}
@@ -69,7 +69,7 @@
    /** The profile service */
    private ProfileService profileService;
    /** The factory for creating profiles */
-   private AbstractProfileFactory profileFactory;
+   private ProfileFactory profileFactory;
    /** Integration hook into JBoss Web */
    private OnDemandContextIntegrator contextIntegrator;
    
@@ -145,16 +145,10 @@
       // start out with a fresh list
       uriList.clear();
    
-      for(int n = 0; n < list.size(); n ++)
+      for(URI uri : list)
       {
-         URI uri = list.get(n);
-         if (uri == null)
+         if( uri != null && uriList.add(uri) == true )
          {
-            throw new IllegalArgumentException("list element["+n+"] is null");
-         }
-
-         if( uriList.add(uri) == true )
-         {
             log.debug("Added URI: " + uri);
          }  
       }
@@ -244,20 +238,24 @@
     * {@link ProfileKey#getName() name} portion of
     * the on-demand @{link Profile}'s {@link #getProfileKey() ProfileKey}.
     * 
-    * @return the name, or <code>null</code> if not set
+    * @return the name, or <code>null</code> if not set and 
+    *         {@link #setContextName(String) contextName} is also unset.
     */
    public String getProfileName()
    {
       if (profileName == null)
       {
-         if ("".equals(contextName))
+         if (contextName != null)
          {
-            profileName = DEFAULT_ROOT_WAR_PROFILE_NAME;
+            if ("".equals(contextName))
+            {
+               profileName = DEFAULT_ROOT_WAR_PROFILE_NAME;
+            }
+            else
+            {
+               profileName = contextName + ".war";
+            }
          }
-         else
-         {
-            profileName = contextName + ".war";
-         }
       }
       return profileName;
    }
@@ -358,7 +356,7 @@
     * 
     * @throws IllegalArgumentException if <code>profileFactory</code> is <code>null</code>
     */
-   public void setProfileFactory(AbstractProfileFactory profileFactory)
+   public void setProfileFactory(ProfileFactory profileFactory)
    {
       if (profileFactory == null)
       {
@@ -481,6 +479,11 @@
          throw new IllegalStateException("Must configure contextName");
       }
       
+      if (uriList.size() == 0)
+      {
+         throw new IllegalStateException("Must configure URIList");
+      }
+      
       URI[] rootURIs = uriList.toArray(new URI[uriList.size()]);
       // TODO add dependencies on bootstrap profiles 
       String[] rootSubProfiles = new String[0];
@@ -510,7 +513,16 @@
     */
    public void stop() throws Exception
    {      
-      ProfileKey profKey = getProfileKey();
+      ProfileKey profKey = null;
+      try
+      {
+         profKey = getProfileKey();
+      }
+      catch (IllegalStateException e)
+      {
+         return;
+      }
+      
       if (profileService != null &&  profKey != null)
       {
          try
@@ -527,6 +539,13 @@
          {
             log.warn("Could not unregister unknown profile " + profKey);
          }
+         finally
+         {
+            if (this.contextIntegrator != null)
+            {
+               this.contextIntegrator.removeContextDemandListener(this);
+            }
+         }
       }
    }
 
@@ -544,6 +563,8 @@
     * 
     * @return the key. Will not return <code>null</code>
     * 
+    * @throws IllegalStateException if {@link #getProfileName()} returns <code>null</code>
+    * 
     * @see #getProfileDomain() 
     * @see #getProfileServer() 
     * @see #getProfileName()
@@ -552,6 +573,11 @@
    {
       if (this.profileKey == null)
       {
+         String name = getProfileName();
+         if (name == null)
+         {
+            throw new IllegalStateException("Must configure profileName or contextName before calling getProfileKey()");
+         }
          this.profileKey = new ProfileKey(getProfileDomain(), getProfileServer(), getProfileName());
       }
       return this.profileKey;
@@ -629,11 +655,11 @@
       ProfileKey profKey = getProfileKey();
       if (this.profileService.getActiveProfileKeys().contains(profKey) == false)
       {         
-         this.profileService.activateProfile(getProfileKey());
+         this.profileService.activateProfile(profKey);
          if (validate)
          {
             // Validate if the activation was successful
-            this.profileService.validateProfile(getProfileKey());
+            this.profileService.validateProfile(profKey);
          }
          
          this.activated = true;
@@ -641,6 +667,7 @@
       else
       {
          log.warn("Profile " + profKey + " is already activated");
+         this.activated = true;
       }
       
    }




More information about the jboss-cvs-commits mailing list