KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > system > metadata > ServiceDependencyListValueMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.system.metadata;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.management.MalformedObjectNameException JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29
30 import org.jboss.dependency.spi.ControllerState;
31 import org.jboss.system.microcontainer.LifecycleDependencyItem;
32 import org.jboss.system.microcontainer.ServiceControllerContext;
33
34 /**
35  * ServiceDependencyListValueMetaData.
36  *
37  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
38  * @version $Revision: 1.1 $
39  */

40 public class ServiceDependencyListValueMetaData extends AbstractMetaDataVisitorNode implements ServiceValueMetaData
41 {
42    /** The dependencies */
43    private List JavaDoc<String JavaDoc> dependencies;
44
45    /** The object names */
46    private List JavaDoc<ObjectName JavaDoc> objectNames;
47    
48    /**
49     * Create a new ServiceDependencyListValueMetaData.
50     */

51    public ServiceDependencyListValueMetaData()
52    {
53    }
54    
55    /**
56     * Create a new ServiceDependencyListValueMetaData.
57     *
58     * @param dependencies the dependencies
59     */

60    public ServiceDependencyListValueMetaData(List JavaDoc<String JavaDoc> dependencies)
61    {
62       setDependencies(dependencies);
63    }
64
65    /**
66     * Get the dependencies.
67     *
68     * @return the dependencies.
69     */

70    public List JavaDoc<String JavaDoc> getDependencies()
71    {
72       if (dependencies == null)
73       {
74          List JavaDoc<String JavaDoc> result = new ArrayList JavaDoc<String JavaDoc>(objectNames.size());
75          for (ObjectName JavaDoc objectName : objectNames)
76             result.add(objectName.getCanonicalName());
77          return result;
78       }
79       return dependencies;
80    }
81
82    /**
83     * Set the dependencies.
84     *
85     * @param dependencies the dependencies.
86     */

87    public void setDependencies(List JavaDoc<String JavaDoc> dependencies)
88    {
89       if (dependencies == null)
90          throw new IllegalArgumentException JavaDoc("Null dependencies");
91       for (String JavaDoc dependency: dependencies)
92       {
93          if (dependency == null)
94             throw new IllegalArgumentException JavaDoc("Null dependency in dependencies");
95       }
96       
97       this.dependencies = dependencies;
98       this.objectNames = null;
99    }
100
101    /**
102     * Get the objectNames.
103     *
104     * @return the objectNames.
105     * @throws MalformedObjectNameException if the list of string was set with an invalid object name
106     */

107    public List JavaDoc<ObjectName JavaDoc> getObjectNames() throws MalformedObjectNameException JavaDoc
108    {
109       if (objectNames == null)
110       {
111          List JavaDoc<ObjectName JavaDoc> names = new ArrayList JavaDoc<ObjectName JavaDoc>(dependencies.size());
112          for (String JavaDoc dependency : dependencies)
113          {
114             if (dependency.trim().length() == 0)
115                throw new MalformedObjectNameException JavaDoc("Missing object name in depends-list");
116             ObjectName JavaDoc objectName = new ObjectName JavaDoc(dependency);
117             if (objectName.isPattern())
118                throw new MalformedObjectNameException JavaDoc("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    /**
128     * Set the objectNames.
129     *
130     * @param objectNames the objectNames.
131     */

132    public void setObjectNames(List JavaDoc<ObjectName JavaDoc> objectNames)
133    {
134       if (objectNames == null)
135          throw new IllegalArgumentException JavaDoc("Null objectNames");
136       for (ObjectName JavaDoc objectName: objectNames)
137       {
138          if (objectName == null)
139             throw new IllegalArgumentException JavaDoc("Null object name in objectNames");
140       }
141
142       this.objectNames = objectNames;
143    }
144
145    public Object JavaDoc getValue(ServiceValueContext valueContext) throws Exception JavaDoc
146    {
147       return getObjectNames();
148    }
149
150    public void visit(ServiceMetaDataVisitor visitor)
151    {
152       ServiceControllerContext context = visitor.getControllerContext();
153       Object JavaDoc name = context.getName();
154       List JavaDoc<String JavaDoc> list = dependencies;
155       try
156       {
157          List JavaDoc<ObjectName JavaDoc> names = getObjectNames();
158          list = new ArrayList JavaDoc<String JavaDoc>(names.size());
159          for (ObjectName JavaDoc objectName : names)
160             list.add(objectName.getCanonicalName());
161       }
162       catch (MalformedObjectNameException JavaDoc ignored)
163       {
164       }
165       for (String JavaDoc other : list)
166       {
167          // TODO visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.CONFIGURED));
168
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