Author: baranowb
Date: Mon Mar 23 02:28:10 2009
New Revision: 5154

Modified:
trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileContextImpl.java trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileLocalObjectConcreteImpl.java trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileMBeanConcrete.java trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileTableConcrete.java trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileTableConcreteImpl.java trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/SleeProfileManagement.java

Log:
Commit so we can be in sync with Alex
changes:
- add methods to ProfileTableConcrete + impl
- fill SleeProfileManagement class with essentioals
- filling mgmt methods so profiles will work :)

Modified: trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileContextImpl.java
==============================================================================
--- trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileContextImpl.java (original) +++ trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileContextImpl.java Mon Mar 23 02:28:10 2009
@@ -87,7 +87,7 @@

                doGeneralChecks();
                try {
- ProfileTable pt = this.profileTable.getProfileManagement().getProfileTable(profileTableName, null); + ProfileTable pt = this.profileTable.getProfileManagement().getProfileTable(profileTableName);
                        return pt;
                } catch (Exception e) {
                        throw new SLEEException("Failed to obtain profile 
table.", e);

Modified: trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileLocalObjectConcreteImpl.java
==============================================================================
--- trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileLocalObjectConcreteImpl.java (original) +++ trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileLocalObjectConcreteImpl.java Mon Mar 23 02:28:10 2009
@@ -83,7 +83,7 @@
        public ProfileTable getProfileTable() throws SLEEException {
                ProfileTable pt = null;
                try {
- pt = this.sleeProfileManagement.getProfileTable(profileTableName, this.profileSpecificationId);
+                       pt = 
this.sleeProfileManagement.getProfileTable(profileTableName);
                } catch (Exception e) {
                        throw new SLEEException("Failed to obtain ProfileTable 
interface.", e);
                }
@@ -184,8 +184,8 @@
                }

                try {
- ProfileTableConcrete profileTable = (ProfileTableConcrete) this.sleeProfileManagement.getProfileTable(profileTableName, this.profileSpecificationId);
-                       this.profileObject = 
profileTable.assignProfileObject(profileName);
+ ProfileTableConcrete profileTable = (ProfileTableConcrete) this.sleeProfileManagement.getProfileTable(profileTableName); + this.profileObject = profileTable.assignProfileObject(profileName,false);
                        // Set flag that SLEE component interacts with it. this 
is false
                        // only in
                        // case of JMX client
@@ -244,8 +244,7 @@

                public void execute() {
                        try {
- ProfileTableConcrete profileTable = (ProfileTableConcrete) sleeProfileManagement.getProfileTable(profileTableName, profileSpecificationId);
-                               
profileTable.deassignProfileObject(getProfileObject());
+ ProfileTableConcrete profileTable = (ProfileTableConcrete) sleeProfileManagement.getProfileTable(profileTableName);
                                removeProfileObject();

                        } catch (Exception e) {

Modified: trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileMBeanConcrete.java
==============================================================================
--- trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileMBeanConcrete.java (original) +++ trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileMBeanConcrete.java Mon Mar 23 02:28:10 2009
@@ -102,6 +102,10 @@
                }
        }

+       /**
+        * This method commits profile. See descritpion - profile becomes 
visible
+        * for slee ONLY when its commited.
+        */
public void commitProfile() throws InvalidStateException, ProfileVerificationException, ManagementException {

                Thread t = Thread.currentThread();
@@ -435,6 +439,13 @@
                        if (!this.profileObject.isWriteable())
                                throw new InvalidStateException();

+                       //FIXME:
+//                     if(!commited)
+//                     {
+//                             REMOVE
+//                     }
+                       
+                       
                        this.profileObject.profileLoad();
                        this.profileObject.setWriteable(false);
                        if (logger.isDebugEnabled()) {

Modified: trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileTableConcrete.java
==============================================================================
--- trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileTableConcrete.java (original) +++ trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileTableConcrete.java Mon Mar 23 02:28:10 2009
@@ -1,14 +1,32 @@
 package org.mobicents.slee.container.profile;

+import java.util.Collection;
+
+import javax.management.ObjectName;
+import javax.slee.InvalidArgumentException;
+import javax.slee.SLEEException;
+import javax.slee.TransactionRequiredLocalException;
 import javax.slee.management.ProfileTableNotification;
+import javax.slee.profile.AttributeNotIndexedException;
+import javax.slee.profile.AttributeTypeMismatchException;
+import javax.slee.profile.ProfileAlreadyExistsException;
+import javax.slee.profile.ProfileID;
+import javax.slee.profile.ProfileSpecificationID;
 import javax.slee.profile.ProfileTable;
+import javax.slee.profile.ProfileTableActivity;
+import javax.slee.profile.UnrecognizedAttributeException;
 import javax.slee.profile.UnrecognizedProfileNameException;
+import javax.transaction.SystemException;
+
+import org.mobicents.slee.container.component.ProfileSpecificationComponent;
+import org.mobicents.slee.runtime.cache.ProfileTableCacheData;

 /**
  *
  * Start time:16:36:52 2009-03-13<br>
  * Project: mobicents-jainslee-server-core<br>
- * Extension to profile table interface defined
+ * Extension to profile table interface defined FIXME: checkl if all methods
+ * should be mandatory in TX
  *
* @author <a href="mailto:[email protected]";>baranowb - Bartosz Baranowski
  *         </a>
@@ -21,15 +39,54 @@
        public ProfileTableNotification getProfileTableNotification();

        public String getProfileTableName();
-       
+
+       public ProfileSpecificationComponent getProfileSpecificationComponent();
+
        /**
- * This method assigns PO to existing profile, otherwise it throws exception
-        * @param profileName - valid, existing profile profile name
+        * This method assigns PO to existing profile, otherwise it throws
+        * exception. In case of bool flag set to true it also tries to create
+        *
+        * @param profileName
+        *            - valid, existing profile profile name
         * @return
         * @throws UnrecognizedProfileNameException
         */
- public ProfileObject assignProfileObject(String profileName) throws UnrecognizedProfileNameException; + public ProfileObject assignProfileObject(String profileName, boolean create) throws UnrecognizedProfileNameException, ProfileAlreadyExistsException;

        public void deassignProfileObject(ProfileObject profileObject);
+
+       public ProfileTableActivity getActivity();
+
+       public Collection<ProfileID> getProfilesIDs();
+
+ public ProfileID getProfileByIndexedAttribute(String attributeName, Object attributeValue) throws UnrecognizedAttributeException, AttributeNotIndexedException, AttributeTypeMismatchException,
+                       SLEEException;
+
+ public Collection<ProfileID> getProfilesByIndexedAttribute(String attributeName, Object attributeValue) throws UnrecognizedAttributeException, AttributeNotIndexedException,
+                       AttributeTypeMismatchException, SLEEException;
+
+       public Object findProfileMBean(String newProfileName);
+
+       public boolean isProfileCommitted(String newProfileName) throws 
Exception;
+
+ public ObjectName addProfile(String newProfileName, boolean isDefault) throws TransactionRequiredLocalException, NullPointerException, SingleProfileException, InvalidArgumentException, ProfileAlreadyExistsException;
+
+       public ObjectName getProfileMBean(String profileName, boolean 
isDefault);
+
+       /**
+        * Returns JMX MBean name of usage mbean
+        *
+        * @return
+        * @throws InvalidArgumentException
+        *             - confusing exception name, however it is thrown when 
this
+        *             tables specs does not define Usage parameters
+        */
+       public ObjectName getUsageMBeanName() throws InvalidArgumentException;
+
+       public Collection<String> getProfileNames();
+
+       public void removeProfileTable();
+
+       public void rename(String newProfileTableName);

 }

Modified: trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileTableConcreteImpl.java
==============================================================================
--- trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileTableConcreteImpl.java (original) +++ trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/ProfileTableConcreteImpl.java Mon Mar 23 02:28:10 2009
@@ -1,19 +1,43 @@
 package org.mobicents.slee.container.profile;

+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.util.Collection;

+import javax.management.InstanceAlreadyExistsException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
 import javax.slee.CreateException;
+import javax.slee.InvalidArgumentException;
 import javax.slee.SLEEException;
 import javax.slee.TransactionRequiredLocalException;
 import javax.slee.management.ProfileTableNotification;
+import javax.slee.profile.AttributeNotIndexedException;
+import javax.slee.profile.AttributeTypeMismatchException;
 import javax.slee.profile.ProfileAlreadyExistsException;
+import javax.slee.profile.ProfileID;
 import javax.slee.profile.ProfileLocalObject;
 import javax.slee.profile.ProfileSpecificationID;
+import javax.slee.profile.ProfileTableActivity;
 import javax.slee.profile.ReadOnlyProfileException;
+import javax.slee.profile.UnrecognizedAttributeException;
 import javax.slee.profile.UnrecognizedProfileNameException;
+import javax.transaction.SystemException;

+import org.apache.log4j.Logger;
+import org.jboss.system.ServiceMBeanSupport;
 import org.mobicents.slee.container.SleeContainer;
import org.mobicents.slee.container.component.ProfileSpecificationComponent;
+import org.mobicents.slee.container.management.SleeProfileManager;
+import org.mobicents.slee.container.management.jmx.ProfileProvisioningMBeanImpl;
+import org.mobicents.slee.runtime.activity.ActivityContext;
+import org.mobicents.slee.runtime.activity.ActivityContextHandle;
+import org.mobicents.slee.runtime.activity.ActivityContextHandlerFactory;
+import org.mobicents.slee.runtime.activity.ActivityType;
+import org.mobicents.slee.runtime.facilities.profile.ProfileTableActivityHandle; +import org.mobicents.slee.runtime.facilities.profile.ProfileTableActivityImpl;
 import org.mobicents.slee.runtime.transaction.SleeTransactionManager;

 /**
@@ -32,13 +56,19 @@
        public static final int _UNICODE_RANGE_START = 0x0020;
        public static final int _UNICODE_RANGE_END = 0x007e;
        public static final int _UNICODE_SLASH = 0x002f;
-       
-       
+
+ private static Logger logger = Logger.getLogger(ProfileTableConcreteImpl.class);
+
        private SleeProfileManagement sleeProfileManagement = null;
        private String profileTableName = null;
        private ProfileTableNotification profileTableNotification = null;
        private SleeContainer sleeContainer = null;
        private ProfileSpecificationID profileSpecificationId;
+
+       // Closely related
+
+       private ActivityContext profileTableActivityContext = null;
+
public ProfileTableConcreteImpl(SleeProfileManagement sleeProfileManagement, String profileTableName, ProfileSpecificationID profileSpecificationId) {
                super();

@@ -49,8 +79,17 @@
                this.profileTableName = profileTableName;
this.profileTableNotification = new ProfileTableNotification(this.profileTableName);
                this.sleeContainer = 
this.sleeProfileManagement.getSleeContainer();
-               this.profileSpecificationId= profileSpecificationId;
+               this.profileSpecificationId = profileSpecificationId;
+
+       }
+
+       public void register() {
+ this.profileTableActivityContext = sleeContainer.getActivityContextFactory().createActivityContext( + ActivityContextHandlerFactory.createProfileTableActivityContextHandle(new ProfileTableActivityHandle(profileTableName)));
+       }

+       public void deregister() {
+               this.profileTableActivityContext.end();
        }

        public SleeProfileManagement getProfileManagement() {
@@ -62,48 +101,55 @@
                return this.profileTableName;
        }

+       public ProfileSpecificationComponent getProfileSpecificationComponent() 
{
+ return this.sleeProfileManagement.getProfileSpecificationComponent(this.profileSpecificationId);
+       }
+
        public ProfileTableNotification getProfileTableNotification() {
                return this.profileTableNotification;
        }

+       public ProfileTableActivity getActivity() {
+ return (ProfileTableActivity) this.profileTableActivityContext.getActivityContextHandle().getActivity();
+       }
+
+       public Collection<ProfileID> getProfilesIDs() {
+               return null;
+       }
+
public ProfileLocalObject create(String profileName) throws NullPointerException, IllegalArgumentException, TransactionRequiredLocalException, ReadOnlyProfileException,
                        ProfileAlreadyExistsException, CreateException, 
SLEEException {

-               
                // Its transactional method
                SleeTransactionManager txMgr = 
sleeContainer.getTransactionManager();
                txMgr.mandateTransaction();
-               
+
                validateProfileName(profileName);
-               
+
                // FIXME add check for profile existency, this can be done only 
when we
                // have JPA ?
ProfileSpecificationComponent component = this.sleeProfileManagement.getProfileSpecificationComponent(this.profileSpecificationId);
-               if(component == null)
-               {
- throw new SLEEException("Could not find profile specification "+this.profileSpecificationId+" for profile table: "+this.profileTableName);
+               if (component == null) {
+ throw new SLEEException("Could not find profile specification " + this.profileSpecificationId + " for profile table: " + this.profileTableName);
                }
                if (component.getDescriptor().getReadOnly()) {
throw new ReadOnlyProfileException("Profile Specification declares profile to be read only.");
                }

-               
-               
-               
                // Pool p = 
sleeProfileManagement.getPool(this.profileTableName);
-               //ProfileObjec po = p.borrowObject();
+               // ProfileObjec po = p.borrowObject();

-               ProfileObject po = new 
ProfileObject(this,profileSpecificationId);
-               //FIXME: those should be done by pool;
+               ProfileObject po = new ProfileObject(this, 
profileSpecificationId);
+               // FIXME: those should be done by pool;
                po.setProfileName(profileName);
                po.setProfileContext(new ProfileContextImpl(this));
                po.setState(ProfileObjectState.POOLED);
-               
+
                po.profilePostCreate();
                po.setState(ProfileObjectState.READY);
-               //FIXME: add action to transaction to passivate this object?
-               //FIXME: add ProfileLocalObject, somehow
-               
+               // FIXME: add action to transaction to passivate this object?
+               // FIXME: add ProfileLocalObject, somehow
+
                return null;
        }

@@ -114,7 +160,8 @@
        /**
         *
         * @param profielName
-        * @param allowNull - this is used only for default profile.
+        * @param allowNull
+        *            - this is used only for default profile.
         * @return
         * @throws NullPointerException
         * @throws TransactionRequiredLocalException
@@ -124,126 +171,319 @@
                // TODO Auto-generated method stub
                return null;
        }
-       
- public Collection findAll() throws TransactionRequiredLocalException, SLEEException {
-               // TODO Auto-generated method stub
-               return null;
-       }

- public ProfileLocalObject findProfileByAttribute(String arg0, Object arg1) throws NullPointerException, IllegalArgumentException, TransactionRequiredLocalException, SLEEException {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
- public Collection findProfilesByAttribute(String arg0, Object arg1) throws NullPointerException, IllegalArgumentException, TransactionRequiredLocalException, SLEEException { + public Collection findAll() throws TransactionRequiredLocalException, SLEEException {
                // TODO Auto-generated method stub
                return null;
        }

public boolean remove(String profileName) throws NullPointerException, ReadOnlyProfileException, TransactionRequiredLocalException, SLEEException {
-               if(profileName == null)
-               {
+               if (profileName == null) {
                        throw new NullPointerException("Profile name must not be 
null");
                }
-               
+
                SleeTransactionManager txMgr = 
sleeContainer.getTransactionManager();
                txMgr.mandateTransaction();
-               
+
ProfileSpecificationComponent component = this.sleeProfileManagement.getProfileSpecificationComponent(this.profileSpecificationId);
-               if(component == null)
-               {
+               if (component == null) {
                        throw new SLEEException("No defined profiel 
specification.");
                }
-               
-               if(component.getDescriptor().getReadOnly())
-               {
- throw new ReadOnlyProfileException("Profile specification: "+this.profileSpecificationId +", is read only.");
+
+               if (component.getDescriptor().getReadOnly()) {
+ throw new ReadOnlyProfileException("Profile specification: " + this.profileSpecificationId + ", is read only.");
                }
-               
-               //FIXME: add this
-               //if(profileExists)
+
+               // FIXME: add this
+               // if(profileExists)
                {
-//                     ProfileObject po = new 
ProfileObject(this,profileSpecificationId);
-//                     //FIXME: those should be done by pool;
-//                     po.setProfileName(profileName);
-//                     po.setProfileContext(new ProfileContextImpl(this));
-//                     po.setState(ProfileObjectState.POOLED);
-//                     
-//                     po.profileLoad();
-//                     po.setState(ProfileObjectState.READY);
-//                     po.profileRemove();
-//                     po.setState(ProfileObjectState.POOLED);
+                       // ProfileObject po = new
+                       // ProfileObject(this,profileSpecificationId);
+                       // //FIXME: those should be done by pool;
+                       // po.setProfileName(profileName);
+                       // po.setProfileContext(new ProfileContextImpl(this));
+                       // po.setState(ProfileObjectState.POOLED);
+                       //                      
+                       // po.profileLoad();
+                       // po.setState(ProfileObjectState.READY);
+                       // po.profileRemove();
+                       // po.setState(ProfileObjectState.POOLED);
                }
-               
+
                return false;
        }
-       
-       
- public static void validateProfileName(String profileName) throws IllegalArgumentException, NullPointerException
-       {
+
+ public static void validateProfileName(String profileName) throws IllegalArgumentException, NullPointerException {
                if (profileName == null) {
                        throw new NullPointerException("ProfileName must not be 
null");
                }
-               if(profileName.length()==0)
-               {
+               if (profileName.length() == 0) {
throw new IllegalArgumentException("Profile name must not be empty, see section 10.2.4 of JSLEE 1.1 specs");
                }
-               
-               for(int i = 0;i<profileName.length();i++)
-               {
-                       Character c=  profileName.charAt(i);
+
+               for (int i = 0; i < profileName.length(); i++) {
+                       Character c = profileName.charAt(i);
                        int unicodeCode = c.charValue();
- if(c.isLetterOrDigit(c.charValue()) || (_UNICODE_RANGE_START<=c && c<=_UNICODE_RANGE_END))
-                       {
-                               //fine
-                       }else
-                       {
- throw new IllegalArgumentException("Profile name contains illegal character, name: "+profileName+", at index: "+i); + if (c.isLetterOrDigit(c.charValue()) || (_UNICODE_RANGE_START <= c && c <= _UNICODE_RANGE_END)) {
+                               // fine
+                       } else {
+ throw new IllegalArgumentException("Profile name contains illegal character, name: " + profileName + ", at index: " + i);
                        }
                }
-               
+
        }
-       
- public static void validateProfileTableName(String profileTableName) throws IllegalArgumentException, NullPointerException
-       {
+
+ public static void validateProfileTableName(String profileTableName) throws IllegalArgumentException, NullPointerException {
                if (profileTableName == null) {
                        throw new NullPointerException("ProfileTableName must not be 
null");
                }
-               if(profileTableName.length()==0)
-               {
+               if (profileTableName.length() == 0) {
throw new IllegalArgumentException("ProfileTableName must not be empty, see section 10.2.4 of JSLEE 1.1 specs");
                }
-               
-               for(int i = 0;i<profileTableName.length();i++)
-               {
-                       Character c=  profileTableName.charAt(i);
+
+               for (int i = 0; i < profileTableName.length(); i++) {
+                       Character c = profileTableName.charAt(i);
                        int unicodeCode = c.charValue();
- if( (c.isLetterOrDigit(c.charValue()) || (_UNICODE_RANGE_START<=c && c<=_UNICODE_RANGE_END)) && unicodeCode!=_UNICODE_SLASH)
-                       {
-                               //fine
-                       }else
-                       {
- throw new IllegalArgumentException("ProfileTableName contains illegal character, name: "+profileTableName+", at index: "+i); + if ((c.isLetterOrDigit(c.charValue()) || (_UNICODE_RANGE_START <= c && c <= _UNICODE_RANGE_END)) && unicodeCode != _UNICODE_SLASH) {
+                               // fine
+                       } else {
+ throw new IllegalArgumentException("ProfileTableName contains illegal character, name: " + profileTableName + ", at index: " + i);
                        }
                }
        }

-       
-       
-       
        // ##################
        // # Helper methods #
        // ##################
-       
- public ProfileObject assignProfileObject(String profileName) throws UnrecognizedProfileNameException
-       {
+
+       /**
+        *
+        * Creates a JMX ObjectName for a profile, given its profile name and
+        * profile table name
+        *
+        * @param profileTableName
+        * @param profileName
+        * @return
+        * @throws MalformedObjectNameException
+        */
+ public static ObjectName getProfileObjectName(String profileTableName, String profileName) throws MalformedObjectNameException {
+               ObjectName objectName;
+               String jmxProfileTableObjectName = 
toValidJmxName(profileTableName);
+               String jmxProfileObjectName = toValidJmxName(profileName);
+ objectName = new ObjectName("slee:" + "profileTableName=" + jmxProfileTableObjectName + "," + "type=profile," + "profile=" + jmxProfileObjectName);
+               return objectName;
+       }
+
+ public static ObjectName getDefaultProfileObjectName(String profileTableName) throws MalformedObjectNameException {
+               return getProfileObjectName(profileTableName, "defaultProfile");
+       }
+
+       /**
+        *
+        * @param jmxName
+        * @return
+        */
+       public static String toValidJmxName(String jmxName) {
+               String jmxObjectName = replace(jmxName, "\\", "");
+               jmxObjectName = replace(jmxObjectName, "\"", "\\\"");
+               jmxObjectName = replace(jmxObjectName, "*", "\\*");
+               jmxObjectName = replace(jmxObjectName, "?", "\\?");
+               char car = 0x0027;
+               char car2 = 0x0060;
+               jmxObjectName = replace(jmxObjectName, "" + car, "");
+               jmxObjectName = replace(jmxObjectName, "" + car2, "");
+               // FIXME causing problems to invoke operations on Mbean through 
jboss
+               // web console
+               // the quotes are causing html problems
+               // if removed some tests are not passing
+               jmxObjectName = ObjectName.quote(jmxObjectName);
+               return jmxObjectName;
+
+       }
+
+ public static String replace(String str, String strToReplace, String newStr) {
+               String string = "";
+ java.util.StringTokenizer st = new java.util.StringTokenizer(str, strToReplace);
+               while (st.hasMoreTokens()) {
+                       string = string.concat(st.nextToken());
+                       if (st.hasMoreTokens())
+                               string = string + newStr;
+               }
+               if (string.length() < 1)
+                       return str;
+               else
+                       return string;
+       }
+
+       /**
+        * This method
+        * <ul>
+        * <li>creates profile if it does not exist
+        * <li>creates and registers MBean
+        * </ul>
+        *
+        * For execution of those task it switches CL to profiel specs CL.
+        */
+ public ObjectName addProfile(String newProfileName, boolean isDefault) throws TransactionRequiredLocalException, NullPointerException, SingleProfileException, InvalidArgumentException,
+                       SLEEException, ProfileAlreadyExistsException {
+
+               // switch the context classloader to the component cl
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+               ObjectName objectName = null;
+               this.sleeContainer.getTransactionManager().mandateTransaction();
+               try {
+ ProfileSpecificationComponent component = this.sleeContainer.getComponentRepositoryImpl().getComponentByID(this.profileSpecificationId);
+                       if (component == null) {
+ throw new SLEEException("No such component for: " + this.profileSpecificationId + ", possibly we are beeing removed.");
+                       }
+ Thread.currentThread().setContextClassLoader(component.getClassLoader());
+
+                       // FIXME: add check for existncy of profile or remove 
exception from
+                       // throws clause
+
+ ProfileObject allocated = this.assignProfileObject(newProfileName, true);
+
+                       if (isDefault) {
+                               allocated.profileInitialize();
+                               allocated.profileStore();
+                               if (!component.isSlee11())
+                                       allocated.profileVerify();
+
+                       } else {
+                               // FIXME: copy the attribute values from the 
default profile
+
+ if (component.getDescriptor().isSingleProfile() && isProfileCommitted(null)) {
+                                       this.deassignProfileObject(allocated);
+ throw new SingleProfileException("Profile Specification indicates that this is single profile, can not create more than one: " + profileSpecificationId);
+                               }
+                               if (component.isSlee11())
+                                       allocated.profilePostCreate();
+                       }
+
+                       // Add MBean
+ Class concreteProfileMBeanClass = component.getProfileMBeanConcreteImplClass(); + Constructor con = concreteProfileMBeanClass.getConstructor(ProfileObject.class);
+                       // FIXME: this must be StandardMBean ?
+ ServiceMBeanSupport profileMBean = (ServiceMBeanSupport) con.newInstance(allocated);
+                       if (isDefault) {
+                               objectName = 
getDefaultProfileObjectName(profileTableName);
+                       } else {
+                               objectName = 
getProfileObjectName(profileTableName, newProfileName);
+                       }
+
+                       if (logger.isDebugEnabled())
+ logger.debug("[instantiateProfile]Registering " + "following profile MBean with object name " + objectName);
+                       
sleeContainer.getMBeanServer().registerMBean(profileMBean, objectName);
+
+               } catch (InstanceAlreadyExistsException e) {
+
+ throw new SLEEException("ProfileMBean with name: " + objectName + " already registered.", e);
+               } catch (MBeanRegistrationException e) {
+
+ throw new SLEEException("ProfileMBean with name: " + objectName + " already registered.", e);
+               } catch (NotCompliantMBeanException e) {
+ throw new SLEEException("ProfileMBean with name: " + objectName + " generated class is not correct.", e);
+               } catch (MalformedObjectNameException e) {
+ throw new SLEEException("ProfileMBean object name: " + objectName + " can not be created, its bad.", e);
+               } catch (IllegalArgumentException e) {
+ throw new SLEEException("Failed to create ProfileMBean, object name: " + objectName + ".", e);
+               } catch (InstantiationException e) {
+ throw new SLEEException("Failed to create ProfileMBean, object name: " + objectName + ".", e);
+               } catch (IllegalAccessException e) {
+ throw new SLEEException("Failed to create ProfileMBean, object name: " + objectName + ".", e);
+               } catch (InvocationTargetException e) {
+ throw new SLEEException("Failed to create ProfileMBean, object name: " + objectName + ".", e);
+               } catch (SecurityException e) {
+ throw new SLEEException("Failed to create ProfileMBean, object name: " + objectName + ".", e);
+               } catch (NoSuchMethodException e) {
+ throw new SLEEException("Failed to create ProfileMBean, object name: " + objectName + ".", e);
+               } finally {
+                       
Thread.currentThread().setContextClassLoader(oldClassLoader);
+               }
+
+               return null;
+       }
+
+ public ProfileLocalObject findProfileByAttribute(String arg0, Object arg1) throws NullPointerException, IllegalArgumentException, TransactionRequiredLocalException, SLEEException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+ public Collection findProfilesByAttribute(String arg0, Object arg1) throws NullPointerException, IllegalArgumentException, TransactionRequiredLocalException, SLEEException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+ public ProfileID getProfileByIndexedAttribute(String attributeName, Object attributeValue) throws UnrecognizedAttributeException, AttributeNotIndexedException, AttributeTypeMismatchException,
+                       SLEEException {
+
+               // THis can be invoked only on 1.0 profiles
+               return null;
+       }
+
+ public Collection<ProfileID> getProfilesByIndexedAttribute(String attributeName, Object attributeValue) throws UnrecognizedAttributeException, AttributeNotIndexedException,
+                       AttributeTypeMismatchException, SLEEException {
+               // THis can be invoked only on 1.0 profiles
+               return null;
+       }
+
+ public ProfileObject assignProfileObject(String profileName, boolean create) throws UnrecognizedProfileNameException, ProfileAlreadyExistsException {
+               // TODO Auto-generated method stub
                return null;
        }

+       /**
+        * Returns object into pooled state
+        */
        public void deassignProfileObject(ProfileObject profileObject) {
+
+               // FIXME: add pool :)
+
+               profileObject.getProfileConcrete().profilePassivate();
+               profileObject.setState(ProfileObjectState.POOLED);
+       }
+
+       public Object findProfileMBean(String profileName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public ObjectName getProfileMBean(String profileName, boolean 
isDefault) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public Collection<String> getProfileNames() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public ObjectName getUsageMBeanName() throws InvalidArgumentException {
                // TODO Auto-generated method stub
-               
+               return null;
+       }
+
+       /**
+        * Determines if profile is in back end storage == visible to other
+        * compoenents than MBean, if null is passed as argumetn it must check 
for
+        * any other than defualt?
+        */
+       public boolean isProfileCommitted(String profileName) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       /**
+        * Triggers remove operation on this profile table.
+        */
+       public void removeProfileTable() {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void rename(String newProfileTableName) {
+               // TODO Auto-generated method stub
+
        }
-       

 }

Modified: trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/SleeProfileManagement.java
==============================================================================
--- trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/SleeProfileManagement.java (original) +++ trunk/servers/jain-slee/core/jar/src/main/java/org/mobicents/slee/container/profile/SleeProfileManagement.java Mon Mar 23 02:28:10 2009
@@ -1,18 +1,36 @@
 package org.mobicents.slee.container.profile;

+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.management.ObjectName;
 import javax.slee.SLEEException;
+import javax.slee.TransactionRequiredLocalException;
+import javax.slee.management.DeploymentException;
 import javax.slee.profile.ProfileSpecificationID;
 import javax.slee.profile.ProfileTable;
+import javax.slee.profile.UnrecognizedProfileSpecificationException;
 import javax.slee.profile.UnrecognizedProfileTableNameException;
+import javax.transaction.SystemException;

+import org.apache.log4j.Logger;
 import org.mobicents.slee.container.SleeContainer;
import org.mobicents.slee.container.component.ProfileSpecificationComponent; +import org.mobicents.slee.container.deployment.profile.SleeProfileClassCodeGenerator;
+import org.mobicents.slee.runtime.cache.ProfileTableCacheData;
+import org.mobicents.slee.runtime.transaction.SleeTransactionManager;
+
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;

 /**
  *
  * Start time:16:56:21 2009-03-13<br>
  * Project: mobicents-jainslee-server-core<br>
- * Class that manages ProfileSpecification, profile tables, ProfileObjects. It is responsible for seting up profile specification env, creating + * Class that manages ProfileSpecification, profile tables, ProfileObjects. It
+ * is responsible for setting up profile specification env.
  *
* @author <a href="mailto:[email protected]";>baranowb - Bartosz Baranowski
  *         </a>
@@ -20,13 +38,95 @@
  */
 public class SleeProfileManagement {

-       
+ private static final Logger logger = Logger.getLogger(SleeProfileManagement.class); + private final static SleeProfileClassCodeGenerator sleeProfileClassCodeGenerator = new SleeProfileClassCodeGenerator();
        private SleeContainer sleeContainer = null;
-       
- public ProfileTable getProfileTable(String profileTableName, ProfileSpecificationID profileSpecificationID) throws SLEEException,UnrecognizedProfileTableNameException{
+       private SleeTransactionManager sleeTransactionManager = null;
+
+       /**
+ * This map contains mapping - profieltable name ---> profile table concrete + * object. see 10.2.4 section of JSLEE 1.1 specs - there can be only single
+        * profile profile table in SLEE container
+        *
+        */
+       private ConcurrentHashMap nameToProfileTableMap = new 
ConcurrentHashMap();
+
+       public SleeProfileManagement(SleeContainer sleeContainer) {
+               super();
+               if (sleeContainer == null)
+                       throw new NullPointerException("Parameter must not be 
null");
+               this.sleeContainer = sleeContainer;
+               this.sleeTransactionManager = 
this.sleeContainer.getTransactionManager();
+
+       }
+
+       /**
+        * Installs profile into container, creates default profile and reads
+ * backend storage to search for other profiles - it creates MBeans for all
+        *
+        * @param component
+        * @throws DeploymentException
+        *             - this exception is thrown in case of error FIXME: on 
check
+        *             to profile - if we have one profile table active and we
+ * encounter another, what shoudl happen? is there auto init for
+        *             all in back end memory?
+        */
+ public void installProfile(ProfileSpecificationComponent component) throws DeploymentException {
+
+               if (logger.isDebugEnabled()) {
+                       logger.debug("Installing " + component);
+               }
+
+               // FIXME:
+               this.sleeTransactionManager.mandateTransaction();
+ final SleeTransactionManager sleeTransactionManager = sleeContainer.getTransactionManager();
+               sleeTransactionManager.mandateTransaction();
+
+               // change classloader
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+               try {
+ Thread.currentThread().setContextClassLoader(component.getClassLoader());
+
+                       this.sleeProfileClassCodeGenerator.process(component);
+
+                       this.createJndiSpace();
+               } catch (DeploymentException de) {
+                       throw de;
+               } catch (Throwable t) {
+ throw new DeploymentException("Bad throwable, possible bug - this should be handled properly.", t);
+               } finally {
+                       
Thread.currentThread().setContextClassLoader(oldClassLoader);
+               }
+
+       }
+
+       public void uninstallProfile(ProfileSpecificationComponent component) {
                // TODO Auto-generated method stub
-               //FIXME: do we need spec ID to get profile table?
-               return null;
+
+       }
+
+       /**
+        * This creates
+        */
+       private void createJndiSpace() throws DeploymentException {
+
+       }
+
+ public ProfileTableConcrete getProfileTable(String profileTableName) throws SLEEException, UnrecognizedProfileTableNameException {
+
+               try {
+ ProfileTableConcrete ptc = (ProfileTableConcrete) this.nameToProfileTableMap.get(profileTableName);
+                       if (ptc == null)
+                               throw new 
UnrecognizedProfileTableNameException();
+
+                       // FIXME: add activity check to see if we are beeing 
removed ?
+
+                       return ptc;
+               } catch (UnrecognizedProfileTableNameException e) {
+                       throw e;
+               } catch (Exception e) {
+ throw new SLEEException("Failed to fetch ProfileTable due to unknown error, please report.", e);
+               }
        }

        public SleeContainer getSleeContainer() {
@@ -34,13 +134,37 @@
        }

public ProfileSpecificationComponent getProfileSpecificationComponent(ProfileSpecificationID profileSpecificationId) {
-               // TODO Auto-generated method stub
+               // FIXME: we posbily dont need this.
+ return this.sleeContainer.getComponentRepositoryImpl().getComponentByID(profileSpecificationId);
+       }
+
+ public ProfileTableConcrete addProfileTable(ProfileTableConcrete profileTable, ProfileSpecificationComponent component) throws TransactionRequiredLocalException, SystemException,
+                       ClassNotFoundException {
                return null;
+
+       }
+
+       public Collection<String> getDeclaredProfileTableNames() {
+ return Collections.unmodifiableCollection(this.nameToProfileTableMap.keySet());
+       }
+
+ public Collection<String> getDeclaredProfileTableNames(ProfileSpecificationID id) throws UnrecognizedProfileSpecificationException {
+
+ if (this.sleeContainer.getComponentRepositoryImpl().getComponentByID(id) == null) { + throw new UnrecognizedProfileSpecificationException("No such profile specification: " + id);
+               }
+               ArrayList<String> names = new ArrayList<String>();
+
+               // FIXME: this will fail if done async to change, is this ok ?
+               Iterator<String> it = 
this.nameToProfileTableMap.keySet().iterator();
+               while (it.hasNext()) {
+                       String name = it.next();
+ if (((ProfileTableConcrete) this.nameToProfileTableMap.get(name)).getProfileSpecificationComponent().getProfileSpecificationID().equals(id)) {
+                               names.add(name);
+                       }
+               }
+
+               return names;
        }

-       
-       
-       
-       
-       
 }

Reply via email to