KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.management.MalformedObjectNameException JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import org.jboss.dependency.spi.ControllerState;
28 import org.jboss.system.microcontainer.LifecycleDependencyItem;
29 import org.jboss.system.microcontainer.ServiceControllerContext;
30
31 /**
32  * ServiceDependencyMetaData.
33  *
34  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
35  * @version $Revision: 1.1 $
36  */

37 public class ServiceDependencyMetaData extends AbstractMetaDataVisitorNode
38 {
39    /** The dependency */
40    private String JavaDoc iDependOn;
41
42    /** The dependency */
43    private ObjectName JavaDoc iDependOnObjectName;
44
45    /**
46     * Get the iDependOn.
47     *
48     * @return the iDependOn.
49     */

50    public String JavaDoc getIDependOn()
51    {
52       if (iDependOn == null)
53          return iDependOnObjectName.getCanonicalName();
54       return iDependOn;
55    }
56
57    /**
58     * Set the iDependOn.
59     *
60     * @param iDependOn the iDependOn.
61     */

62    public void setIDependOn(String JavaDoc iDependOn)
63    {
64       if (iDependOn == null)
65          throw new IllegalArgumentException JavaDoc("Null iDependOn");
66       this.iDependOn = iDependOn;
67       this.iDependOnObjectName = null;
68    }
69
70    /**
71     * Get the iDependOn.
72     *
73     * @return the iDependOn.
74     * @throws MalformedObjectNameException if the string was set with an invalid object name
75     */

76    public ObjectName JavaDoc getIDependOnObjectName() throws MalformedObjectNameException JavaDoc
77    {
78       if (iDependOnObjectName == null)
79       {
80          if (iDependOn.trim().length() == 0)
81             throw new MalformedObjectNameException JavaDoc("Missing object name in depends");
82          ObjectName JavaDoc objectName = new ObjectName JavaDoc(iDependOn);
83          if (objectName.isPattern())
84             throw new MalformedObjectNameException JavaDoc("ObjectName patterns are not allowed in depends: " + iDependOn);
85          iDependOnObjectName = objectName;
86          iDependOn = null;
87       }
88       return iDependOnObjectName;
89    }
90
91    /**
92     * Set the iDependOn.
93     *
94     * @param iDependOn the iDependOn.
95     */

96    public void setIDependOnObjectName(ObjectName JavaDoc iDependOn)
97    {
98       if (iDependOn == null)
99          throw new IllegalArgumentException JavaDoc("Null iDependOn");
100       this.iDependOnObjectName = iDependOn;
101    }
102
103    public void visit(ServiceMetaDataVisitor visitor)
104    {
105       ServiceControllerContext context = visitor.getControllerContext();
106       Object JavaDoc name = context.getName();
107       Object JavaDoc other = iDependOn;
108       try
109       {
110          other = getIDependOnObjectName().getCanonicalName();
111       }
112       catch (MalformedObjectNameException JavaDoc ignored)
113       {
114       }
115       visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.CREATE));
116       visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.START));
117       visitor.visit(this);
118    }
119 }
120
Popular Tags