Source code: org/mobicents/slee/container/management/jmx/ProfileProvisioningMBeanImpl.java
1 /***************************************************
2 * *
3 * Mobicents: The Open Source VoIP Platform *
4 * *
5 * Distributable under LGPL license. *
6 * See terms of license at gnu.org. *
7 * *
8 ***************************************************/
9 /*
10 * ProfileProvisioningMBeanImpl.java
11 *
12 * Created on 12 nov. 2004
13 *
14 */
15 package org.mobicents.slee.container.management.jmx;
16
17 import java.util.Collection;
18
19 import javax.management.MBeanAttributeInfo;
20 import javax.management.MalformedObjectNameException;
21 import javax.management.NotCompliantMBeanException;
22 import javax.management.ObjectName;
23 import javax.slee.InvalidArgumentException;
24 import javax.slee.TransactionRequiredLocalException;
25 import javax.slee.management.ManagementException;
26 import javax.slee.management.ProfileProvisioningMBean;
27 import javax.slee.management.SleeState;
28 import javax.slee.profile.AttributeNotIndexedException;
29 import javax.slee.profile.AttributeTypeMismatchException;
30 import javax.slee.profile.ProfileAlreadyExistsException;
31 import javax.slee.profile.ProfileSpecificationID;
32 import javax.slee.profile.ProfileTableAlreadyExistsException;
33 import javax.slee.profile.UnrecognizedAttributeException;
34 import javax.slee.profile.UnrecognizedProfileNameException;
35 import javax.slee.profile.UnrecognizedProfileSpecificationException;
36 import javax.slee.profile.UnrecognizedProfileTableNameException;
37 import javax.transaction.SystemException;
38
39 import org.jboss.logging.Logger;
40 import org.jboss.system.ServiceMBeanSupport;
41 import org.mobicents.slee.container.SleeContainer;
42 import org.mobicents.slee.container.management.ProfileSpecificationDescriptorImpl;
43 import org.mobicents.slee.container.profile.SingleProfileException;
44 import org.mobicents.slee.container.profile.SleeProfileManager;
45 import org.mobicents.slee.runtime.transaction.SleeTransactionManager;
46
47 /**
48 * MBean class for profile provisioning through jmx
49 *
50 * @author DERUELLE Jean <a
51 * href="mailto:jean.deruelle@gmail.com">jean.deruelle@gmail.com </a>
52 *
53 */
54 public class ProfileProvisioningMBeanImpl extends ServiceMBeanSupport implements
55 ProfileProvisioningMBean, ProfileProvisioningMBeanImplMBean {
56
57 private static Logger logger;
58
59 //private SleeProfileManager profileManager;
60
61 static {
62 try {
63 logger = Logger.getLogger(ProfileProvisioningMBeanImpl.class);
64
65 } catch (Exception ex) {
66 logger.fatal("error initializing profile provisioning mbean");
67 }
68 }
69
70 public ProfileProvisioningMBeanImpl() throws NotCompliantMBeanException{
71 super(ProfileProvisioningMBean.class);
72 }
73
74 /*
75 * (non-Javadoc)
76 *
77 * @see javax.slee.management.ProfileProvisioningMBean#createProfileTable(javax.slee.profile.ProfileSpecificationID,
78 * java.lang.String)
79 */
80 public void createProfileTable(
81 ProfileSpecificationID profileSpecificationID,
82 String newProfileTableName) throws NullPointerException,
83 UnrecognizedProfileSpecificationException,
84 InvalidArgumentException, ProfileTableAlreadyExistsException,
85 ManagementException {
86 SleeContainer sleeContainer = SleeContainer.lookupFromJndi();
87
88 // check mandated by SLEE TCK test CreateActivityWhileStoppingTest
89 if (!sleeContainer.getSleeState().equals(SleeState.RUNNING)) return;
90
91
92 /*
93 * if(profileManager==null){ this.profileManager = new
94 * SleeProfileManager(serviceContainer.getMBeanServer());
95 * SleeContainer.registerFacilityWithJndi(SleeProfileManager.JNDI_NAME,
96 * profileManager); }
97 */
98 SleeTransactionManager transactionManager = SleeContainer
99 .getTransactionManager();
100 boolean b = false;
101 try {
102 b = transactionManager.requireTransaction();
103 logger.debug("creating new Profile Table " + newProfileTableName
104 + " ...");
105 logger.debug("profile specification ID :"
106 + profileSpecificationID.toString());
107 if(newProfileTableName==null)
108 throw new NullPointerException();
109 if (newProfileTableName.length() < 1) {
110 log.error("InvaidArgument: " + newProfileTableName);
111 throw new InvalidArgumentException();
112 }
113 if (newProfileTableName.indexOf('/') != -1) {
114 log.error("InvaidArgument: " + newProfileTableName);
115 throw new InvalidArgumentException();
116 }
117 if (profileTableHasInvalidCharacters(newProfileTableName)) {
118 log.error("InvaidArgument: " + newProfileTableName);
119 throw new InvalidArgumentException();
120 }
121
122 SleeProfileManager profileManager = SleeProfileManager
123 .getInstance();
124 ProfileSpecificationID profileSpecification;
125 try {
126 profileSpecification = profileManager
127 .findProfileSpecId(newProfileTableName);
128 if(profileSpecification!=null)
129 throw new ProfileTableAlreadyExistsException();
130 } catch (SystemException e1) {
131 String err = "Failed to create profile table, because of failure in findProfuleTable("
132 + newProfileTableName + "). System Exception.";
133 logger.error(err, e1);
134 throw new ManagementException(err, e1);
135 }
136
137 logger.debug("Profile table does not exist -- creating one "
138 + profileSpecificationID.toString());
139
140 //get the profile specification descriptor from the deployment
141 // manager class
142 ProfileSpecificationDescriptorImpl profileSpecificationDescriptor = (ProfileSpecificationDescriptorImpl) sleeContainer
143 .getComponentDescriptor(profileSpecificationID);
144 if(profileSpecificationDescriptor==null)
145 throw new UnrecognizedProfileSpecificationException();
146
147 // switch the context classloader to the DU cl
148 ClassLoader oldClassLoader = Thread.currentThread()
149 .getContextClassLoader();
150
151 try {
152 Thread.currentThread().setContextClassLoader(
153 profileSpecificationDescriptor.getClassLoader());
154
155 profileManager.addProfileTable(newProfileTableName,
156 profileSpecificationDescriptor);
157 } catch (TransactionRequiredLocalException e) {
158 throw new ManagementException("Transaction Manager Failure");
159 } catch (SystemException e) {
160 throw new ManagementException("System-level failure");
161 } catch (ClassNotFoundException e) {
162 throw new ManagementException(
163 "Profile Specification has not been correctly deployed");
164 } catch (Exception e) {
165 throw new ManagementException(e.getMessage(), e);
166 } finally {
167 Thread.currentThread().setContextClassLoader(oldClassLoader);
168 }
169 logger.debug("new Profile Table " + newProfileTableName
170 + " created");
171 } catch (Exception x) {
172 try {
173 transactionManager.setRollbackOnly();
174 } catch (SystemException e) {
175 logger.error("System Exception", e);
176 throw new ManagementException("System Exception", e);
177 }
178 if (x instanceof NullPointerException)
179 throw (NullPointerException) x;
180 else if (x instanceof UnrecognizedProfileSpecificationException)
181 throw (UnrecognizedProfileSpecificationException) x;
182 else if (x instanceof InvalidArgumentException)
183 throw (InvalidArgumentException) x;
184 else if (x instanceof ProfileTableAlreadyExistsException)
185 throw (ProfileTableAlreadyExistsException) x;
186 else if (x instanceof ManagementException)
187 throw (ManagementException) x;
188 else
189 throw new ManagementException("Failed createProfileTable", x);
190 } finally {
191 if (b)
192 try {
193 transactionManager.commit();
194 } catch (SystemException e) {
195 logger.error("System Exception", e);
196 throw new ManagementException("System Exception", e);
197 }
198 }
199 }
200
201 /**
202 * Check if some invalid characters exists in the profile table name
203 *
204 * @param profileTableName
205 * the profile table name to check
206 * @return true if an invalid character is found in the profile table name
207 */
208 private boolean profileTableHasInvalidCharacters(String profileTableName) {
209 for (char invalidChar = 0x0000; invalidChar < 0x001f; invalidChar++) {
210 if(profileTableName.indexOf(invalidChar)!=-1){
211 logger.debug("Profile Table Name " + profileTableName + " "
212 + "contains the following invalid character "
213 + invalidChar);
214 return true;
215 }
216 }
217 if(profileTableName.indexOf('/')!=-1){
218 logger.debug("Profile Table Name " + profileTableName + ""
219 + " contains the following invalid character /");
220 return true;
221 }
222 if(profileTableName.indexOf('\u007f')!=-1){
223 logger.debug("Profile Table Name " + profileTableName + " "
224 + "contains the following invalid character \u007f");
225 return true;
226 }
227 return false;
228 }
229
230 /**
231 * Check if some invalid characters exists in the profile name
232 *
233 * @param profileName
234 * the profile name to check
235 * @return true if an invalid character is found in the profile name
236 */
237 private boolean profileHasInvalidCharacters(String profileName) {
238 for (char invalidChar = 0x0000; invalidChar < 0x001f; invalidChar++) {
239 if(profileName.indexOf(invalidChar)!=-1){
240 logger.debug("Profile Name " + profileName + " "
241 + "contains the following invalid character "
242 + invalidChar);
243 return true;
244 }
245 }
246 if(profileName.indexOf('\u007f')!=-1){
247 logger.debug("Profile Name " + profileName + " "
248 + "contains the following invalid character \u007f");
249 return true;
250 }
251 return false;
252 }
253
254 /*
255 * (non-Javadoc)
256 *
257 * @see javax.slee.management.ProfileProvisioningMBean#removeProfileTable(java.lang.String)
258 */
259 public void removeProfileTable(String profileTableName)
260 throws NullPointerException, UnrecognizedProfileTableNameException,
261 ManagementException {
262 logger.debug("removing Profile Table " + profileTableName +" ...");
263 if(profileTableName==null)
264 throw new NullPointerException();
265
266 SleeContainer sleeContainer = SleeContainer.lookupFromJndi();
267 SleeTransactionManager transactionManager = SleeContainer.getTransactionManager();
268 boolean b = false;
269 boolean rb = true;
270 try {
271 b = transactionManager.requireTransaction();
272
273 // check mandated by SLEE TCK test CreateActivityWhileStoppingTest
274 if (!sleeContainer.getSleeState().equals(SleeState.RUNNING)) return;
275
276 SleeProfileManager profileManager=SleeProfileManager.getInstance();
277 ProfileSpecificationID profileSpecificationID;
278 try {
279 profileSpecificationID = profileManager
280 .findProfileSpecId(profileTableName);
281 } catch (SystemException e) {
282 throw new ManagementException("System-level failure");
283 }
284 if(profileSpecificationID==null)
285 throw new UnrecognizedProfileTableNameException();
286
287 try {
288 profileManager.removeProfileTable(profileTableName);
289 } catch (TransactionRequiredLocalException e) {
290 throw new ManagementException("Transaction Manager Failure");
291 } catch (SystemException e) {
292 throw new ManagementException("System-level failure");
293 }
294 logger.debug("Removed Profile Table " + profileTableName);
295
296 rb = false;
297 } finally {
298 try {
299 if (rb) transactionManager.setRollbackOnly();
300 if (b) transactionManager.commit();
301 } catch (SystemException e) {
302 throw new ManagementException("Failed removeProfileTable( " + profileTableName + ") due to tx commit error", e);
303 }
304 }
305 }
306
307 /*
308 * (non-Javadoc)
309 *
310 * @see javax.slee.management.ProfileProvisioningMBean#getProfileSpecification(java.lang.String)
311 */
312 public ProfileSpecificationID getProfileSpecification(
313 String profileTableName) throws NullPointerException,
314 UnrecognizedProfileTableNameException, ManagementException {
315 logger.debug("trying to get the profile specification for "
316 + profileTableName + " ...");
317 if(profileTableName==null)
318 throw new NullPointerException();
319 SleeProfileManager profileManager = SleeProfileManager
320 .getInstance();
321 ProfileSpecificationID profileSpecificationID;
322 try {
323 profileSpecificationID = profileManager
324 .findProfileSpecId(profileTableName);
325 } catch (SystemException e) {
326 throw new ManagementException("System-level failure");
327 }
328 if(profileSpecificationID==null)
329 throw new UnrecognizedProfileTableNameException();
330 logger.debug("profile specification for " + profileTableName
331 + " found :" + profileSpecificationID);
332
333 return profileSpecificationID;
334 }
335
336 /*
337 * (non-Javadoc)
338 *
339 * @see javax.slee.management.ProfileProvisioningMBean#renameProfileTable(java.lang.String,
340 * java.lang.String)
341 */
342 public void renameProfileTable(String oldProfileTableName,
343 String newProfileTableName) throws NullPointerException,
344 UnrecognizedProfileTableNameException, InvalidArgumentException,
345 ProfileTableAlreadyExistsException, ManagementException {
346 logger.debug("Profile Table " + oldProfileTableName
347 + " to be renamed to " + newProfileTableName);
348 if(newProfileTableName==null)
349 throw new NullPointerException();
350 if(newProfileTableName.length()<1)
351 throw new InvalidArgumentException();
352 if(newProfileTableName.indexOf('/')!=-1)
353 throw new InvalidArgumentException();
354
355 ProfileSpecificationID profileSpecificationID=getProfileSpecification(oldProfileTableName);
356 //get the profile specification descriptor from the deployment manager
357 // class
358 ProfileSpecificationDescriptorImpl profileSpecificationDescriptor=null;
359 SleeContainer serviceContainer = SleeContainer.lookupFromJndi();
360 profileSpecificationDescriptor = (ProfileSpecificationDescriptorImpl) serviceContainer
361 .getComponentDescriptor(profileSpecificationID);
362 if(profileSpecificationDescriptor==null)
363 throw new UnrecognizedProfileTableNameException();
364 /*
365 * profileSpecificationDescriptor=new
366 * ProfileSpecificationDescriptorImpl();
367 * profileSpecificationDescriptor.setCMPInterfaceName(
368 * "gov.nist.slee.container.profile.FooProfileCMP");
369 * profileSpecificationDescriptor.setManagementAbstractClassName(
370 * "gov.nist.slee.container.profile.FooProfileManagementImpl");
371 * profileSpecificationDescriptor.setManagementInterfaceName(
372 * "gov.nist.slee.container.profile.FooProfileManagement");
373 * profileSpecificationDescriptor.setProfileSpecificationID(profileSpecificationID);
374 * profileSpecificationDescriptor.setSingleProfile(true); Map
375 * indexes=new HashMap(); indexes.put("subscriberName","true");
376 * profileSpecificationDescriptor.setProfileIndexes(indexes);
377 */
378 SleeProfileManager profileManager = SleeProfileManager
379 .getInstance();
380 ProfileSpecificationID profileSpecification;
381 try {
382 profileSpecification = profileManager
383 .findProfileSpecId(newProfileTableName);
384 if(profileSpecification!=null)
385 throw new ProfileTableAlreadyExistsException();
386 } catch (SystemException e1) {
387 e1.printStackTrace();
388 throw new ManagementException("System-level failure");
389 }
390
391 try {
392 profileManager.renameProfileTable(oldProfileTableName,
393 newProfileTableName, profileSpecificationDescriptor);
394 } catch (TransactionRequiredLocalException e) {
395 throw new ManagementException("System-level failure");
396 } catch (SystemException e) {
397 throw new ManagementException("System-level failure");
398 } catch (ClassNotFoundException e) {
399 throw new ManagementException("System-level failure");
400 } catch (Exception e) {
401 throw new ManagementException(e.getMessage());
402 }
403 /*
404 * removeProfileTable(oldProfileTableName); try {
405 * profileManager.addProfileTable( newProfileTableName,
406 * profileSpecificationDescriptor); } catch
407 * (TransactionRequiredLocalException e) { throw new
408 * ManagementException("Transaction Manager Failure"); } catch
409 * (SystemException e) { throw new ManagementException("System-level
410 * failure"); }
411 */
412 logger.debug("Profile Table " + oldProfileTableName + " renamed to "
413 + newProfileTableName);
414 }
415
416 /**
417 * @return ObjectName - The default profile MBean object name if the profile table has been created. Otherwise null.
418 *
419 * @see javax.slee.management.ProfileProvisioningMBean#getDefaultProfile(java.lang.String)
420 */
421 public ObjectName getDefaultProfile(String profileTableName)
422 throws NullPointerException, UnrecognizedProfileTableNameException,
423 ManagementException {
424
425 if(profileTableName==null)
426 throw new NullPointerException();
427
428 SleeContainer sleeContainer = SleeContainer.lookupFromJndi();
429 SleeTransactionManager transactionManager = SleeContainer.getTransactionManager();
430 boolean b = false;
431 boolean rb = true;
432 try {
433 b = transactionManager.requireTransaction();
434
435 SleeProfileManager profileManager = SleeProfileManager
436 .getInstance();
437 try {
438 Object profile = profileManager.findDefaultProfile(profileTableName);
439 if( profile == null)
440 throw new UnrecognizedProfileTableNameException();
441 rb = false;
442 ObjectName on = getDefaultProfileObjectName(profileTableName);
443 return on;
444 } catch (MalformedObjectNameException e) {
445 throw new ManagementException("System-level failure", e);
446 } catch (SystemException e) {
447 throw new ManagementException("System-level failure", e);
448 }
449
450 } finally {
451 try {
452 if (rb) transactionManager.setRollbackOnly();
453 if (b) transactionManager.commit();
454 } catch (SystemException e) {
455 throw new ManagementException("Failed removeProfileTable( " + profileTableName + ") due to tx commit error", e);
456 }
457 }
458
459 }
460
461
462 /**
463 * SLEE 1.0 spec, section 14.11: This method gets the JMX Object Name of a
464 * modifiable Profile MBean object. When the Profile MBean object commits
465 * successfully, the SLEE creates and adds a Profile with the name specified
466 * by the newProfileName argument to the Profile Table specified by the
467 * profileTableName argument. Before the Profile MBean object commits, the
468 * Profile name specifed by the newProfileName argument does not exist and
469 * cannot be accessed by SBBs or through the ProfileProvisioningMBean
470 * interface.
471 *
472 * @see javax.slee.management.ProfileProvisioningMBean#createProfile(java.lang.String,
473 * java.lang.String)
474 */
475 public ObjectName createProfile(String profileTableName,
476 String newProfileName) throws NullPointerException,
477 UnrecognizedProfileTableNameException, InvalidArgumentException,
478 ProfileAlreadyExistsException, ManagementException {
479
480 SleeTransactionManager transactionManager = SleeContainer
481 .getTransactionManager();
482 boolean b = false;
483 boolean rb = true;
484
485 ObjectName objectName;
486 try {
487
488 b = transactionManager.requireTransaction();
489
490 String infoStr = "Creating new Profile " + newProfileName
491 + " in profile table " + profileTableName;
492 String errorStr = "Failed " + infoStr;
493 logger.debug(infoStr);
494 if(profileTableName==null)
495 throw new NullPointerException();
496 if(newProfileName==null)
497 throw new NullPointerException();
498 if(newProfileName.length()<1)
499 throw new InvalidArgumentException();
500 if(profileHasInvalidCharacters(newProfileName))
501 throw new InvalidArgumentException();
502 //FIXME As the profile is stored under tree cache the character /
503 // is important so it is replace by a space in the profile name, find a workaround
504 newProfileName=newProfileName.replace('/',' ');
505
506 SleeProfileManager profileManager = SleeProfileManager
507 .getInstance();
508 ProfileSpecificationID profileSpecificationID;
509 try {
510 profileSpecificationID = profileManager
511 .findProfileSpecId(profileTableName);
512 } catch (SystemException e) {
513 throw new ManagementException(errorStr, e);
514 }
515 if(profileSpecificationID==null)
516 throw new UnrecognizedProfileTableNameException(errorStr);
517 Object profile;
518 try {
519 // see if the profile MBean was created, but not committed
520 profile = profileManager.findProfileMBean(profileTableName,
521 newProfileName);
522 if(profile!=null)
523 throw new ProfileAlreadyExistsException(errorStr);
524 // see if the profile MBean was closed/removed, but the profile
525 // itself is still visible in SLEE
526 if (profileManager.isProfileCommitted(profileTableName,
527 newProfileName)) {
528 throw new ProfileAlreadyExistsException(errorStr);
529 }
530 } catch (SystemException e1) {
531 throw new ManagementException(errorStr, e1);
532 }
533 objectName=null;
534 try {
535 // since all validation checks pass, lets try to create the
536 // profile
537 objectName = profileManager.addProfileToProfileTable(
538 profileTableName, newProfileName);
539 } catch (TransactionRequiredLocalException e) {
540 throw new ManagementException(errorStr, e);
541 } catch (SystemException e) {
542 throw new ManagementException(errorStr, e);
543 } catch (SingleProfileException e) {
544 throw new ManagementException(
545 "This profile specification defines "
546 + "that it can exists only a single profile for it and "
547 + "there is already a profile for this specification."
548 + errorStr, e);
549 }
550 logger.debug(infoStr
551 + "DONE. The profile has the following JMX Object Name "
552 + objectName);
553 rb = false;
554 } finally {
555 try {
556 if (rb)
557 transactionManager.setRollbackOnly();
558 if (b)
559 transactionManager.commit();
560 } catch (SystemException e) {
561 logger.error("Failed getProfiles.", e);
562 throw new ManagementException("Failed getProfiles.", e);
563 }
564 }
565 return objectName;
566
567 }
568
569 /*
570 * (non-Javadoc)
571 *
572 * @see javax.slee.management.ProfileProvisioningMBean#removeProfile(java.lang.String,
573 * java.lang.String)
574 */
575 public void removeProfile(String profileTableName, String profileName)
576 throws NullPointerException, UnrecognizedProfileTableNameException,
577 UnrecognizedProfileNameException, ManagementException {
578
579 logger.debug("Removing Profile " + profileName + " from profile table "
580 + profileTableName);
581 if(profileTableName==null)
582 throw new NullPointerException();
583 if(profileName==null)
584 throw new NullPointerException();
585 //FIXME As the profile is stored under jboss cache the character / is
586 //important so it is replace by a space in the profile name, find a
587 // workaround
588 profileName=profileName.replace('/',' ');
589
590 SleeContainer sleeContainer = SleeContainer.lookupFromJndi();
591 SleeTransactionManager transactionManager = SleeContainer.getTransactionManager();
592 boolean b = false;
593 boolean rb = true;
594 try {
595 b = transactionManager.requireTransaction();
596
597 SleeProfileManager profileManager = SleeProfileManager
598 .getInstance();
599 ProfileSpecificationID profileSpecificationID;
600 try {
601 profileSpecificationID = profileManager
602 .findProfileSpecId(profileTableName);
603 } catch (SystemException e) {
604 throw new ManagementException("System-level failure");
605 }
606 if(profileSpecificationID==null)
607 throw new UnrecognizedProfileTableNameException();
608 Object profileMBeanName;
609 profileMBeanName = profileManager.findProfileMBean(profileTableName, profileName);
610 if(profileMBeanName==null)
611 throw new UnrecognizedProfileNameException();
612
613 try {
614 profileManager.removeProfile(profileTableName,profileName);
615 } catch (TransactionRequiredLocalException e) {
616 throw new ManagementException("Transaction Manager Failure");
617 } catch (SystemException e) {
618 throw new ManagementException("System-level failure");
619 }
620 logger.debug("Profile " + profileName + " removed from profile table "
621 + profileTableName);
622
623 rb = false;
624
625 } finally {
626 try {
627 if (rb) transactionManager.setRollbackOnly();
628 if (b) transactionManager.commit();
629 } catch (SystemException e) {
630 throw new ManagementException("Failed removeProfileTable( " + profileTableName + ") due to tx commit error", e);
631 }
632 }
633
634 }
635
636 /*
637 * (non-Javadoc)
638 *
639 * @see javax.slee.management.ProfileProvisioningMBean#getProfile(java.lang.String,
640 * java.lang.String)
641 */
642 public ObjectName getProfile(String profileTableName, String profileName)
643 throws NullPointerException, UnrecognizedProfileTableNameException,
644 UnrecognizedProfileNameException, ManagementException {
645
646 logger.debug("Getting Profile " + profileName + " from profile table "
647 + profileTableName);
648 if(profileTableName==null)
649 throw new NullPointerException();
650 if(profileName==null)
651 throw new NullPointerException();
652 //FIXME As the profile is stored under jboss cache the character / is
653 //important so it is replace by a space in the profile name, find a
654 // workaround
655 profileName=profileName.replace('/',' ');
656
657 SleeContainer sleeContainer = SleeContainer.lookupFromJndi();
658 SleeTransactionManager transactionManager = SleeContainer.getTransactionManager();
659 boolean b = false;
660 boolean rb = true;
661 try {
662 b = transactionManager.requireTransaction();
663
664
665 SleeProfileManager profileManager = SleeProfileManager
666 .getInstance();
667 ProfileSpecificationID profileSpecificationID;
668 try {
669 profileSpecificationID = profileManager
670 .findProfileSpecId(profileTableName);
671 } catch (SystemException e) {
672 throw new ManagementException("System-level failure", e);
673 }
674 if(profileSpecificationID==null)
675 throw new UnrecognizedProfileTableNameException();
676
677 Object profile;
678 try {
679 profile = profileManager.findProfileMBean(profileTableName,
680 profileName);
681 if(profile==null)
682 throw new UnrecognizedProfileNameException(
683 "Profile MBean does not exist.");
684
685 if (!profileManager.isProfileCommitted(profileTableName,
686 profileName)) {
687 throw new UnrecognizedProfileNameException(
688 "Profile has been created but not committed.");
689 }
690 } catch (SystemException e1) {
691 throw new ManagementException("System-level failure", e1);
692 }
693
694
695 ObjectName objectName=null;
696 try {
697 objectName = getProfileObjectName(profileTableName, profileName);
698 } catch (MalformedObjectNameException e2) {
699 throw new ManagementException("System-level failure", e2);
700 } catch (NullPointerException e2) {
701 //should never be caught
702 throw new ManagementException("System-level failure", e2);
703 }
704 logger.debug("Profile " + profileName + " from profile table "
705 + profileTableName + " has the following JMX Object Name "
706 + objectName);
707
708 rb = false;
709
710 return objectName;
711
712 } finally {
713 try {
714 if (rb) transactionManager.setRollbackOnly();
715 if (b) transactionManager.commit();
716 } catch (SystemException e) {
717 throw new ManagementException("Failed removeProfileTable( " + profileTableName + ") due to tx commit error", e);
718 }
719 }
720
721 }
722
723 /**
724 *
725 * Creates a JMX ObjectName for a profile, given its profile name and
726 * profile table name
727 *
728 * @param profileTableName
729 * @param profileName
730 * @return @throws
731 * MalformedObjectNameException
732 */
733 public static ObjectName getProfileObjectName(String profileTableName,
734 String profileName) throws MalformedObjectNameException {
735 ObjectName objectName;
736 String jmxProfileTableObjectName = SleeProfileManager
737 .toValidJmxName(profileTableName);
738 String jmxProfileObjectName = SleeProfileManager
739 .toValidJmxName(profileName);
740 objectName = new ObjectName("slee:" + "profileTableName="
741 + jmxProfileTableObjectName + "," + "type=profile,"
742 + "profile=" + jmxProfileObjectName);
743 return objectName;
744 }
745
746 public static ObjectName getDefaultProfileObjectName(String profileTableName)
747 throws MalformedObjectNameException {
748 return getProfileObjectName(profileTableName, "defaultProfile");
749 }
750 /*
751 * (non-Javadoc)
752 *
753 * @see javax.slee.management.ProfileProvisioningMBean#getProfileTables()
754 */
755 public Collection getProfileTables() throws ManagementException {
756 SleeTransactionManager transactionManager = SleeContainer
757 .getTransactionManager();
758 Collection profileTables = null;
759 boolean b = false;
760 try {
761 b = transactionManager.requireTransaction();
762 SleeProfileManager profileManager = SleeProfileManager
763 .getInstance();
764 profileTables=profileManager.findAllProfileTables();
765 } catch (Exception x) {
766 try {
767 transactionManager.setRollbackOnly();
768 } catch (SystemException e) {
769 logger.error("System Exception", e);
770 throw new ManagementException("System Exception", e);
771 }
772 if (x instanceof ManagementException)
773 throw (ManagementException) x;
774 else
775 throw new ManagementException("Failed createProfileTable", x);
776 } finally {
777 if (b)
778 try {
779 transactionManager.commit();
780 } catch (SystemException e) {
781 logger.error("System Exception", e);
782 throw new ManagementException("System Exception", e);
783 }
784 }
785 return profileTables;
786 }
787
788 /*
789 * (non-Javadoc)
790 *
791 * @see javax.slee.management.ProfileProvisioningMBean#getProfiles(java.lang.String)
792 */
793 public Collection getProfiles(String profileTableName)
794 throws NullPointerException, UnrecognizedProfileTableNameException,
795 ManagementException {
796 SleeTransactionManager transactionManager = SleeContainer
797 .getTransactionManager();
798
799 Collection profiles = null;
800
801 boolean b = false;
802 boolean rb = true;
803 try {
804 b = transactionManager.requireTransaction();
805
806 SleeProfileManager profileManager = SleeProfileManager
807 .getInstance();
808 if(profileTableName==null)
809 throw new NullPointerException();
810 ProfileSpecificationID profileSpecificationID;
811 try {
812 profileSpecificationID = profileManager
813 .findProfileSpecId(profileTableName);
814 } catch (SystemException e) {
815 throw new ManagementException("System-level failure");
816 }
817 if(profileSpecificationID==null)
818 throw new UnrecognizedProfileTableNameException();
819 profiles = profileManager
820 .findAllProfilesByTableName(profileTableName);
821
822 rb = false;
823 } finally {
824 try {
825 if (rb)
826 transactionManager.setRollbackOnly();
827 if (b)
828 transactionManager.commit();
829 } catch (SystemException e) {
830 logger.error("Failed getProfiles.", e);
831 throw new ManagementException("Failed getProfiles.", e);
832 }
833 }
834 return profiles;
835 }
836
837 /*
838 * (non-Javadoc)
839 *
840 * @see javax.slee.management.ProfileProvisioningMBean#getProfilesByIndexedAttribute(java.lang.String,
841 * java.lang.String, java.lang.Object)
842 */
843 public Collection getProfilesByIndexedAttribute(String profileTableName,
844 String attributeName, Object attributeValue)
845 throws NullPointerException, UnrecognizedProfileTableNameException,
846 UnrecognizedAttributeException, AttributeNotIndexedException,
847 AttributeTypeMismatchException, ManagementException {
848
849 SleeTransactionManager transactionManager = SleeContainer
850 .getTransactionManager();
851
852 Collection profiles = null;
853
854 boolean b = false;
855 boolean rb = true;
856 try {
857 b = transactionManager.requireTransaction();
858
859 if(profileTableName==null)
860 throw new NullPointerException();
861 if(attributeName==null)
862 throw new NullPointerException();
863 if(attributeValue==null)
864 throw new NullPointerException();
865
866 SleeProfileManager profileManager = SleeProfileManager
867 .getInstance();
868 ProfileSpecificationID profileSpecification;
869 try {
870 profileSpecification = profileManager
871 .findProfileSpecId(profileTableName);
872 if(profileSpecification==null)
873 throw new UnrecognizedProfileTableNameException();
874 } catch (SystemException e) {
875 throw new ManagementException("System-level failure");
876 }
877
878 try {
879 profiles = profileManager.getProfilesByIndexedAttribute(
880 profileTableName,attributeName,attributeValue, false);
881 } catch (SystemException e1) {
882 throw new ManagementException("System-level failure");
883 }
884 ;
885
886 rb = false;
887 } finally {
888 try {
889 if (rb)
890 transactionManager.setRollbackOnly();
891 if (b)
892 transactionManager.commit();
893 } catch (SystemException e) {
894 logger.error("Failed getProfiles.", e);
895 throw new ManagementException("Failed getProfiles.", e);
896 }
897 }
898 return profiles;
899 }
900
901
902 /**
903 *
904 * start MBean service lifecycle method
905 *
906 */
907 protected void startService() throws Exception {
908 //this.profileManager =
909 // (SleeProfileManager)SleeProfileManager.getInstance();
910 logger.info("ProfileProvisioningMBean has been started");
911 // register service in JNDI
912 //SleeContainer.registerFacilityWithJndi(SleeProfileManager.JNDI_NAME,
913 // profileManager);
914 }
915
916 /**
917 *
918 * stop MBean service lifecycle method
919 *
920 */
921 protected void stopService() throws Exception {
922
923 // unregister the SleeProfileManager service with JNDI
924 //SleeContainer.unregisterFacilityWithJndi(SleeProfileManager.JNDI_NAME);
925
926 //this.profileManager = null;
927 }
928
929 }