1 22 package org.jboss.naming; 23 24 import javax.naming.NamingException ; 25 26 import org.jboss.system.ServiceMBean; 27 import org.jboss.system.ServiceMBeanSupport; 28 29 38 public class NamingAlias 39 extends ServiceMBeanSupport 40 implements NamingAliasMBean 41 { 42 private String fromName; 43 private String toName; 44 45 public NamingAlias() 46 { 47 this(null, null); 48 } 49 50 public NamingAlias(final String fromName, final String toName) 51 { 52 this.fromName = fromName; 53 this.toName = toName; 54 } 55 56 64 public String getFromName() 65 { 66 return fromName; 67 } 68 69 77 public void setFromName(String name) throws NamingException 78 { 79 removeLinkRef(fromName); 80 this.fromName = name; 81 createLinkRef(); 82 } 83 84 94 public String getToName() 95 { 96 return toName; 97 } 98 99 109 public void setToName(String name) throws NamingException 110 { 111 this.toName = name; 112 113 createLinkRef(); 114 } 115 116 protected void startService() throws Exception 117 { 118 if( fromName == null ) 119 throw new IllegalStateException ("fromName is null"); 120 if( toName == null ) 121 throw new IllegalStateException ("toName is null"); 122 createLinkRef(); 123 } 124 125 protected void stopService() throws Exception 126 { 127 removeLinkRef(fromName); 128 } 129 130 private void createLinkRef() throws NamingException 131 { 132 if( super.getState() == ServiceMBean.STARTING || super.getState() == ServiceMBean.STARTED ) 133 Util.createLinkRef(fromName, toName); 134 } 135 136 139 private void removeLinkRef(String name) throws NamingException 140 { 141 if(super.getState() == ServiceMBean.STOPPING) 142 Util.removeLinkRef(name); 143 } 144 } 145 | Popular Tags |