RmdBuilder.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 java.util.ArrayList;
024 import java.util.List;
025 
026 import javax.management.MBeanAttributeInfo;
027 import javax.management.MBeanOperationInfo;
028 import javax.management.ObjectName;
029 
030 import org.apache.muse.core.Environment;
031 import org.apache.muse.util.xml.XmlUtils;
032 import org.apache.muse.ws.resource.metadata.WsrmdConstants;
033 import org.apache.qpid.management.Names;
034 import org.apache.qpid.qman.debug.WsdlDebugger;
035 import org.w3c.dom.Element;
036 
037 /**
038  * Resource Metadata Descriptor Builder.
039  * It is used for build the metadata descriptor for properties of the 
040  * incoming jmx object. 
041  
042  @author Andrea Gazzarini
043  */
044 class RmdBuilder implements IArtifactBuilder
045 {
046   private List<Element> _metadataDescriptor = new ArrayList<Element>();
047   
048   ObjectName _objectName;
049   
050   /**
051    * Nothing to be done here on this builder. 
052    * Simply logs a message indicating the target object name.
053    
054    @param objectName the jmx name of the object that is going to be processed.
055    */
056   public void begin(ObjectName objectName)
057   {
058     this._objectName = objectName;
059   }
060   
061   /**
062    * Nothing to be done here on this builder. 
063    
064    @throws BuilderException never.
065    */
066   public void endAttributes()
067   {
068     // N.A. for this builder.
069   }
070   
071   /**
072    * Nothing to be done here on this builder. 
073    
074    @throws BuilderException never.
075    */
076   public void endOperations()
077   {
078     // N.A. for this builder.
079   }
080 
081   /**
082    * Process a single attribute metadata.
083    * An attribute (that is, a property) represented by the corresponding incoming 
084    * attribute metadata will generate an wsrmd:Property xml element with the constraints
085    * (initial values, static values, allowed values) contained on the metadata.
086    
087    @param attributeMetadata the attribute (jmx) metadata.
088    */
089   public void onAttribute(MBeanAttributeInfo attributeMetadata)
090   {
091     Element property = XmlUtils.createElement(WsrmdConstants.PROPERTY_QNAME);
092     property.setAttribute(Names.NAME_ATTRIBUTE, Names.PREFIX+":"+attributeMetadata.getName());
093     property.setAttribute(Names.MODIFIABILITY, 
094         attributeMetadata.isWritable() 
095           ? Names.READ_WRITE 
096           : Names.READ_ONLY);
097     property.setAttribute(Names.MUTABILITY,Names.MUTABLE);
098     
099     WsdlDebugger.debug(_objectName, property);
100     
101     _metadataDescriptor.add(property);
102   }
103 
104   /**
105    * Nothing to be done here on this builder. 
106    
107    @throws BuilderException never.
108    */  
109   public void onOperation(MBeanOperationInfo operation)
110   {
111     // N.A. for this builder
112   }
113 
114   /**
115    * Nothing to be done here on this builder. 
116    
117    @throws BuilderException never.
118    */
119   public void setEnvironment(Environment environment
120   {
121     // N.A. for this builder
122   }
123 
124   /**
125    * Nothing to be done here on this builder. 
126    
127    @throws BuilderException never.
128    */
129   public Element[] getResourceMetadataDescriptor() 
130   {
131     Element [] properties = _metadataDescriptor.toArray(new Element[0]);
132     return properties;
133   }
134 }