1 7 package org.jboss.webservice.encoding.ser; 8 9 11 import org.jboss.axis.description.AttributeDesc; 12 import org.jboss.axis.description.ElementDesc; 13 import org.jboss.axis.description.FieldDesc; 14 import org.jboss.axis.description.TypeDesc; 15 import org.jboss.axis.utils.BeanPropertyDescriptor; 16 import org.jboss.logging.Logger; 17 import org.jboss.mx.util.MBeanServerLocator; 18 import org.jboss.webservice.deployment.BeanXMLMetaData; 19 import org.jboss.webservice.deployment.MetaDataRegistry; 20 21 import javax.management.MBeanServer ; 22 import javax.management.ObjectName ; 23 import javax.xml.namespace.QName ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 28 97 public class MetaDataTypeDesc extends TypeDesc 98 { 99 private final Logger log = Logger.getLogger(MetaDataTypeDesc.class); 101 102 public MetaDataTypeDesc(Class javaClass, QName xmlType, BeanXMLMetaData metaData) 103 { 104 super(javaClass); 105 106 if (javaClass == null) 107 throw new IllegalArgumentException ("javaClass cannot be null"); 108 if (xmlType == null) 109 throw new IllegalArgumentException ("xmlType cannot be null"); 110 111 if (metaData == null) 113 metaData = getServerSideMetaData(xmlType); 114 115 try 116 { 117 if (metaData != null) 118 { 119 setXmlType(xmlType); 120 setupElementDescriptions(metaData); 121 setupElementOrder(metaData); 122 } 123 } 124 catch (RuntimeException e) 125 { 126 log.error("Instanciation error", e); 127 throw e; 128 } 129 } 130 131 139 private BeanXMLMetaData getServerSideMetaData(QName xmlType) 140 { 141 BeanXMLMetaData metaData = null; 142 try 143 { 144 MBeanServer server = MBeanServerLocator.locateJBoss(); 145 ObjectName objectName = new ObjectName ("jboss.ws4ee:service=AxisService"); 146 MetaDataRegistry registry = (MetaDataRegistry)server.getAttribute(objectName, "MetaDataRegistry"); 147 metaData = registry.getTypeMappingMetaData(xmlType); 148 } 149 catch (Exception e) 150 { 151 log.warn("Cannot obtain metaData from AxisService: " + e); 152 } 153 return metaData; 154 } 155 156 private void setupElementDescriptions(BeanXMLMetaData metaData) 157 { 158 Iterator itElDesc = metaData.getElementMetaData(); 160 while (itElDesc.hasNext()) 161 { 162 BeanXMLMetaData.ElementMetaData elMetaData = (BeanXMLMetaData.ElementMetaData)itElDesc.next(); 163 String fieldName = elMetaData.getFieldName(); 164 QName xmlName = elMetaData.getXmlName(); 165 QName xmlType = elMetaData.getXmlType(); 166 boolean asAttribute = elMetaData.isAsAttribute(); 167 boolean asContent = elMetaData.isAsContent(); 168 169 FieldDesc fieldDesc = null; 170 if (asAttribute) 171 fieldDesc = new AttributeDesc(); 172 else 173 { 174 fieldDesc = new ElementDesc(); 175 ((ElementDesc)fieldDesc).setAsContent(asContent); 176 ((ElementDesc)fieldDesc).setItemXmlType(elMetaData.getItemXmlType()); 177 178 Integer minOccurs = elMetaData.getMinOccurs(); 179 if (minOccurs != null) 180 { 181 ((ElementDesc)fieldDesc).setMinOccurs(minOccurs.intValue()); 182 } 183 } 184 185 fieldDesc.setFieldName(fieldName); 186 fieldDesc.setXmlName(xmlName); 187 fieldDesc.setXmlType(xmlType); 188 addFieldDesc(fieldDesc); 189 } 190 } 191 192 private void setupElementOrder(BeanXMLMetaData metaData) 193 { 194 Iterator itElementOrder = metaData.getElementOrder(); 196 if (itElementOrder.hasNext()) 197 { 198 Map bpdMap = getPropertyDescriptorMap(); 199 BeanPropertyDescriptor[] bpdArr = new BeanPropertyDescriptor[bpdMap.size()]; 200 201 int index = 0; 202 if (bpdMap.size() > 0) 203 { 204 ArrayList keys = new ArrayList (bpdMap.keySet()); 205 206 BeanPropertyDescriptor bpd = (BeanPropertyDescriptor)bpdMap.get("class"); 208 if (bpd != null) 209 { 210 bpdArr[index++] = bpd; 211 keys.remove("class"); 212 } 213 214 while (itElementOrder.hasNext()) 216 { 217 String fieldName = (String )itElementOrder.next(); 218 219 bpd = (BeanPropertyDescriptor)bpdMap.get(fieldName); 220 if (bpd != null) 221 { 222 bpdArr[index++] = bpd; 223 keys.remove(fieldName); 224 } 225 } 226 227 Iterator it = keys.iterator(); 229 while (it.hasNext()) 230 { 231 String name = (String )it.next(); 232 bpd = (BeanPropertyDescriptor)bpdMap.get(name); 233 if (bpd != null) 234 bpdArr[index++] = bpd; 235 } 236 237 setPropertyDescriptors(bpdArr); 238 } 239 } 240 } 241 } 242 | Popular Tags |