WSDMArtifactsDirector.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  *
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  *
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.management.wsdm.capabilities;
022 
023 import javax.management.MBeanAttributeInfo;
024 import javax.management.MBeanInfo;
025 import javax.management.MBeanOperationInfo;
026 import javax.management.ObjectName;
027 
028 import org.apache.muse.core.Environment;
029 import org.apache.muse.core.Resource;
030 import org.w3c.dom.Document;
031 import org.w3c.dom.Element;
032 
033 /**
034  * Director used for coordinate the building process of WS-DM artifacts.
035  
036  @author Andrea Gazzarini
037  */
038 class WSDMArtifactsDirector 
039 {
040   private final ObjectName _eventSourceObjectName;
041   private final MBeanInfo _metadata;
042   
043   private final MBeanCapabilityBuilder _capabilityBuilder;
044   private final WsdlBuilder _wsdlBuilder;
045   private final RmdBuilder _rmdBuilder;
046   
047   /**
048    * Builds a new director with the given objectname and (jmx) metadata.
049    
050    @param eventSourceObjectName the object name of the event source mbean.
051    @param metadata the jmx metadata of the corresponding mbean.
052    */
053   WSDMArtifactsDirector(ObjectName eventSourceObjectName, MBeanInfo metadata
054   {
055     this._eventSourceObjectName = eventSourceObjectName;
056     this._metadata = metadata;
057     
058     _wsdlBuilder = new WsdlBuilder();
059     _capabilityBuilder = new MBeanCapabilityBuilder();
060     _rmdBuilder = new RmdBuilder();
061   }
062 
063   /**
064    * Starts the build process of this director.
065    * This method acts as a facade of the whole build process.
066    
067    @throws BuilderException when one step of the build process fails.
068    */
069   void direct() throws BuilderException 
070   {
071     processObjectName();
072     processAttributes()
073     endAttributes();
074     processOperations();
075     endOperations();
076   }
077 
078   /**
079    * Notifiies builder that all the operations metadata have been transmitted.
080    
081    @throws BuilderException when one builder raises an exception during this operation.
082    */
083   private void endOperations() throws BuilderException 
084   {
085     _capabilityBuilder.endOperations();
086     _wsdlBuilder.endOperations();
087     _rmdBuilder.endOperations();
088   }
089 
090   /**
091    * Notifiies builder that all the attributes metadata have been transmitted.
092    
093    @throws BuilderException when one builder raises an exception during this operation.
094    */
095   private void endAttributes() throws BuilderException
096   {
097     _capabilityBuilder.endAttributes();
098     _wsdlBuilder.endAttributes();
099     _rmdBuilder.endAttributes();
100   }
101 
102   /**
103    * Injects event source object name on all builders.
104    
105    @throws BuilderException when one builder raises an exception during this operation.
106    */
107   void processObjectName() throws BuilderException 
108   {
109     _capabilityBuilder.begin(_eventSourceObjectName);
110     _wsdlBuilder.begin(_eventSourceObjectName);
111     _rmdBuilder.begin(_eventSourceObjectName);
112   }
113   
114   /**
115    * Injects attributes metadata on all builders.
116    
117    @throws BuilderException when one builder raises an exception during this operation.
118    */
119   void processAttributes() throws BuilderException 
120   {
121     for (MBeanAttributeInfo attribute : _metadata.getAttributes()) 
122     {
123       _capabilityBuilder.onAttribute(attribute);
124       _wsdlBuilder.onAttribute(attribute);    
125       _rmdBuilder.onAttribute(attribute);
126     }
127   }
128   
129   /**
130    * Injects operations metadata on all builders.
131    
132    @throws BuilderException when one builder raises an exception during this operation.
133    */
134   void processOperations() throws BuilderException
135   {
136     for (MBeanOperationInfo operation : _metadata.getOperations()) 
137     {
138       _capabilityBuilder.onOperation(operation);
139       _wsdlBuilder.onOperation(operation);      
140     }
141   }  
142   
143   /**
144    * Returns the capabilty class.
145    
146    @return the capability class.
147    */
148   Class<MBeanCapability> getCapabilityClass() 
149   {
150     return _capabilityBuilder.getCapabilityClass();
151   }
152 
153   /**
154    * Returns the wsdl.
155    
156    @return the wsdl.
157    */
158   Document getWsdl() 
159   {
160     return _wsdlBuilder.getWsdl();
161   }
162 
163   /**
164    * Returns the resource metadata descriptor containing metadata (rules, constraints, etc)
165    * for the current resource.
166    * The returned object is an array of Element and each of them maps a resource property.
167    
168    @return the resource metadata descriptor (as an array of Element).
169    */
170   Element [] getResourceMetadataDescriptor() 
171   {
172     return _rmdBuilder.getResourceMetadataDescriptor();
173   }
174   
175   /**
176    * Injects the environment on this director.
177    
178    @param environment the QMan environment.
179    */
180   void setEnvironment(Environment environment
181   {
182     _wsdlBuilder.setEnvironment(environment);
183     _capabilityBuilder.setEnvironment(environment);  
184     _rmdBuilder.setEnvironment(environment);
185   }
186 
187   /**
188    * Injectcs the ws resource on this director.
189    
190    @param resource the ws resource.
191    */
192   public void setResource(Resource resource) {
193     _wsdlBuilder.setWsdlPath(resource.getWsdlPath());
194   }
195 }