1 22 package org.jboss.system.metadata; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import javax.management.MalformedObjectNameException ; 28 import javax.management.ObjectName ; 29 30 import org.jboss.dependency.spi.ControllerState; 31 import org.jboss.system.microcontainer.LifecycleDependencyItem; 32 import org.jboss.system.microcontainer.ServiceControllerContext; 33 34 40 public class ServiceDependencyListValueMetaData extends AbstractMetaDataVisitorNode implements ServiceValueMetaData 41 { 42 43 private List <String > dependencies; 44 45 46 private List <ObjectName > objectNames; 47 48 51 public ServiceDependencyListValueMetaData() 52 { 53 } 54 55 60 public ServiceDependencyListValueMetaData(List <String > dependencies) 61 { 62 setDependencies(dependencies); 63 } 64 65 70 public List <String > getDependencies() 71 { 72 if (dependencies == null) 73 { 74 List <String > result = new ArrayList <String >(objectNames.size()); 75 for (ObjectName objectName : objectNames) 76 result.add(objectName.getCanonicalName()); 77 return result; 78 } 79 return dependencies; 80 } 81 82 87 public void setDependencies(List <String > dependencies) 88 { 89 if (dependencies == null) 90 throw new IllegalArgumentException ("Null dependencies"); 91 for (String dependency: dependencies) 92 { 93 if (dependency == null) 94 throw new IllegalArgumentException ("Null dependency in dependencies"); 95 } 96 97 this.dependencies = dependencies; 98 this.objectNames = null; 99 } 100 101 107 public List <ObjectName > getObjectNames() throws MalformedObjectNameException 108 { 109 if (objectNames == null) 110 { 111 List <ObjectName > names = new ArrayList <ObjectName >(dependencies.size()); 112 for (String dependency : dependencies) 113 { 114 if (dependency.trim().length() == 0) 115 throw new MalformedObjectNameException ("Missing object name in depends-list"); 116 ObjectName objectName = new ObjectName (dependency); 117 if (objectName.isPattern()) 118 throw new MalformedObjectNameException ("ObjectName patterns are not allowed in depends-list: " + dependency); 119 names.add(objectName); 120 } 121 objectNames = names; 122 dependencies = null; 123 } 124 return objectNames; 125 } 126 127 132 public void setObjectNames(List <ObjectName > objectNames) 133 { 134 if (objectNames == null) 135 throw new IllegalArgumentException ("Null objectNames"); 136 for (ObjectName objectName: objectNames) 137 { 138 if (objectName == null) 139 throw new IllegalArgumentException ("Null object name in objectNames"); 140 } 141 142 this.objectNames = objectNames; 143 } 144 145 public Object getValue(ServiceValueContext valueContext) throws Exception 146 { 147 return getObjectNames(); 148 } 149 150 public void visit(ServiceMetaDataVisitor visitor) 151 { 152 ServiceControllerContext context = visitor.getControllerContext(); 153 Object name = context.getName(); 154 List <String > list = dependencies; 155 try 156 { 157 List <ObjectName > names = getObjectNames(); 158 list = new ArrayList <String >(names.size()); 159 for (ObjectName objectName : names) 160 list.add(objectName.getCanonicalName()); 161 } 162 catch (MalformedObjectNameException ignored) 163 { 164 } 165 for (String other : list) 166 { 167 visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.CREATE)); 169 visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.START)); 170 } 171 visitor.visit(this); 172 } 173 } 174 | Popular Tags |