From: Scott M S. <st...@us...> - 2004-03-26 04:07:39
|
User: starksm Date: 04/03/25 19:56:48 Modified: jboss.net/src/main/org/jboss/net/jmx/server Constants.java MBeanProvider.java Log: Fix the code formatting in this module Revision Changes Path 1.6 +4 -3 contrib/jboss.net/src/main/org/jboss/net/jmx/server/Constants.java Index: Constants.java =================================================================== RCS file: /cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/jmx/server/Constants.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Constants.java 27 Aug 2003 04:30:02 -0000 1.5 +++ Constants.java 26 Mar 2004 03:56:48 -0000 1.6 @@ -5,7 +5,7 @@ * See terms of license at gnu.org. */ -// $Id: Constants.java,v 1.5 2003/08/27 04:30:02 patriot1burke Exp $ +// $Id: Constants.java,v 1.6 2004/03/26 03:56:48 starksm Exp $ package org.jboss.net.jmx.server; @@ -15,10 +15,11 @@ * Some Constants for the jmx server package * @author <a href="mailto:Chr...@in...">Christoph G. Jung</a> * @since 1. October 2001 - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ -public interface Constants extends org.jboss.net.axis.server.Constants { +public interface Constants extends org.jboss.net.axis.server.Constants +{ static final Category LOG = Category.getInstance(Constants.class.getPackage().getName()); 1.17 +199 -94 contrib/jboss.net/src/main/org/jboss/net/jmx/server/MBeanProvider.java Index: MBeanProvider.java =================================================================== RCS file: /cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/jmx/server/MBeanProvider.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- MBeanProvider.java 23 Mar 2004 14:33:48 -0000 1.16 +++ MBeanProvider.java 26 Mar 2004 03:56:48 -0000 1.17 @@ -5,11 +5,12 @@ * See terms of license at gnu.org. */ -// $Id: MBeanProvider.java,v 1.16 2004/03/23 14:33:48 essington Exp $ +// $Id: MBeanProvider.java,v 1.17 2004/03/26 03:56:48 starksm Exp $ package org.jboss.net.jmx.server; // axis package + import org.apache.axis.AxisFault; import org.apache.axis.Message; import org.apache.axis.MessageContext; @@ -34,6 +35,7 @@ // sax & jaxrpc import org.xml.sax.SAXException; + import javax.wsdl.Definition; import javax.wsdl.factory.WSDLFactory; import javax.xml.soap.SOAPException; @@ -84,10 +86,11 @@ * </p> * @created 1. Oktober 2001, 16:38 * @author <a href="mailto:Chr...@in...">Christoph G. Jung</a> - * @version $Revision: 1.16 $ + * @version $Revision: 1.17 $ */ -public class MBeanProvider extends BasicProvider { +public class MBeanProvider extends BasicProvider +{ // // Attributes @@ -114,7 +117,8 @@ /** * Constructor MBeanProvider */ - public MBeanProvider() { + public MBeanProvider() + { } // @@ -126,9 +130,11 @@ * @see org.apache.axis.providers.BasicProvider#initServiceDesc(SOAPService, MessageContext) */ public void initServiceDesc(SOAPService service, MessageContext msgCtx) - throws AxisFault { + throws AxisFault + { // here comes the reflective part - try { + try + { // first some option preparation String allowedMethods = (String) service.getOption(allowedMethodsOption); @@ -162,25 +168,28 @@ completeField.setAccessible(true); completeField.set(serviceDesc, Boolean.TRUE); Class implClass = - org.jboss.util.Classes.loadClass(info.getClassName(),msgCtx.getClassLoader()); + org.jboss.util.Classes.loadClass(info.getClassName(), msgCtx.getClassLoader()); serviceDesc.setImplClass(implClass); serviceDesc.setTypeMapping( (TypeMapping) service.getTypeMappingRegistry().getTypeMapping( org.apache.axis.Constants.URI_DEFAULT_SOAP_ENC)); // first inspect operations MBeanOperationInfo[] operations = info.getOperations(); - for (int count = 0; count < operations.length; count++) { + for (int count = 0; count < operations.length; count++) + { String operationName = operations[count].getName(); // is this method exposed? if (allowedMethods != null && allowedMethods.equals("*") || allowedMethods.indexOf(operationName + " ") != -1 || allowedMethods.indexOf(" " + operationName) != -1 - || allowedMethods.equals(operationName)) { + || allowedMethods.equals(operationName)) + { // yes, we build an operation description OperationDesc opDesc = new OperationDesc(); // check overloading, if already present, attach the method count - if (methodData.containsKey(operationName)) { + if (methodData.containsKey(operationName)) + { operationName = operationName + count; } opDesc.setName(operationName); @@ -191,11 +200,12 @@ MBeanParameterInfo[] parameters = operations[count].getSignature(); Class[] parameterTypes = new Class[parameters.length]; - for (int count2 = 0; count2 < parameters.length; count2++) { + for (int count2 = 0; count2 < parameters.length; count2++) + { ParameterDesc param = new ParameterDesc(); param.setName("arg" + count2); parameterTypes[count2] = - forName(parameters[count2].getType(),msgCtx.getClassLoader()); + forName(parameters[count2].getType(), msgCtx.getClassLoader()); param.setJavaType(parameterTypes[count2]); param.setTypeQName( forName( @@ -204,7 +214,7 @@ opDesc.addParameter(param); } opDesc.setReturnClass( - forName(operations[count].getReturnType(),msgCtx.getClassLoader())); + forName(operations[count].getReturnType(), msgCtx.getClassLoader())); opDesc.setReturnType( forName( opDesc.getReturnClass(), @@ -215,27 +225,33 @@ } // for // next we do attribute processing MBeanAttributeInfo[] attributes = info.getAttributes(); - for (int count = 0; count < attributes.length; count++) { + for (int count = 0; count < attributes.length; count++) + { String attributeName = attributes[count].getName(); // is the attribute readable? if (attributes[count].isReadable() && allowedReadAttributes != null && (allowedReadAttributes.equals("*") - || allowedReadAttributes.indexOf(attributeName + " ") != -1 - || allowedReadAttributes.indexOf(" " + attributeName) != -1 - || allowedReadAttributes.equals(attributeName))) { + || allowedReadAttributes.indexOf(attributeName + " ") != -1 + || allowedReadAttributes.indexOf(" " + attributeName) != -1 + || allowedReadAttributes.equals(attributeName))) + { OperationDesc opDesc = new OperationDesc(); - if (attributes[count].getType().equals("boolean")) { + if (attributes[count].getType().equals("boolean")) + { opDesc.setName("is" + attributeName); - } else { + } + else + { opDesc.setName("get" + attributeName); } - if (methodData.containsKey(opDesc.getName())) { + if (methodData.containsKey(opDesc.getName())) + { opDesc.setName(opDesc.getName() + count + "A"); } opDesc.setElementQName(new QName("", opDesc.getName())); attributeData.put(opDesc.getName(), attributes[count]); - opDesc.setReturnClass(forName(attributes[count].getType(),msgCtx.getClassLoader())); + opDesc.setReturnClass(forName(attributes[count].getType(), msgCtx.getClassLoader())); opDesc.setReturnType( forName( opDesc.getReturnClass(), @@ -246,19 +262,21 @@ if (attributes[count].isWritable() && allowedWriteAttributes != null && (allowedWriteAttributes.equals("*") - || allowedWriteAttributes.indexOf(attributeName + " ") != -1 - || allowedWriteAttributes.indexOf(" " + attributeName) != -1 - || allowedWriteAttributes.equals(attributeName))) { + || allowedWriteAttributes.indexOf(attributeName + " ") != -1 + || allowedWriteAttributes.indexOf(" " + attributeName) != -1 + || allowedWriteAttributes.equals(attributeName))) + { OperationDesc opDesc = new OperationDesc(); opDesc.setName("set" + attributeName); - if (methodData.containsKey(opDesc.getName())) { + if (methodData.containsKey(opDesc.getName())) + { opDesc.setName(opDesc.getName() + count + "A"); } opDesc.setElementQName(new QName("", opDesc.getName())); attributeData.put(opDesc.getName(), attributes[count]); ParameterDesc p = new ParameterDesc(); p.setName("arg0"); - p.setJavaType(forName(attributes[count].getType(),msgCtx.getClassLoader())); + p.setJavaType(forName(attributes[count].getType(), msgCtx.getClassLoader())); p.setTypeQName( forName(p.getJavaType(), serviceDesc.getTypeMapping())); opDesc.addParameter(p); @@ -267,54 +285,92 @@ serviceDesc.addOperationDesc(opDesc); } // if } // for - } catch (InstanceNotFoundException e) { + } + catch (InstanceNotFoundException e) + { throw new AxisFault(Constants.NO_MBEAN_INSTANCE, e); - } catch (IntrospectionException e) { + } + catch (IntrospectionException e) + { throw new AxisFault(Constants.INTROSPECTION_EXCEPTION, e); - } catch (ReflectionException e) { + } + catch (ReflectionException e) + { throw new AxisFault(Constants.INTROSPECTION_EXCEPTION, e); - } catch (ClassNotFoundException e) { + } + catch (ClassNotFoundException e) + { throw new AxisFault(Constants.INTROSPECTION_EXCEPTION, e); - } catch (MalformedObjectNameException e) { + } + catch (MalformedObjectNameException e) + { throw new AxisFault(Constants.WRONG_OBJECT_NAME, e); - } catch (IllegalAccessException e) { + } + catch (IllegalAccessException e) + { throw new AxisFault(Constants.INTROSPECTION_EXCEPTION, e); - } catch (NoSuchFieldException e) { + } + catch (NoSuchFieldException e) + { throw new AxisFault(Constants.INTROSPECTION_EXCEPTION, e); - } + } } /** resolve string-based jmx types */ - protected Class forName(String string, ClassLoader loader) throws ClassNotFoundException { - if ("void".equals(string)) { + protected Class forName(String string, ClassLoader loader) throws ClassNotFoundException + { + if ("void".equals(string)) + { return void.class; - } else if ("boolean".equals(string)) { + } + else if ("boolean".equals(string)) + { return boolean.class; - } else if ("float".equals(string)) { + } + else if ("float".equals(string)) + { return float.class; - } else if ("double".equals(string)) { + } + else if ("double".equals(string)) + { return double.class; - } else if ("int".equals(string)) { + } + else if ("int".equals(string)) + { return int.class; - } else if ("long".equals(string)) { + } + else if ("long".equals(string)) + { return long.class; - } else if ("short".equals(string)) { + } + else if ("short".equals(string)) + { return short.class; - } else if ("byte".equals(string)) { + } + else if ("byte".equals(string)) + { return byte.class; - } else if ("char".equals(string)) { + } + else if ("char".equals(string)) + { return char.class; - } else { - return org.jboss.util.Classes.loadClass(string,loader); + } + else + { + return org.jboss.util.Classes.loadClass(string, loader); } } - + /** resolve string-based jmx types */ protected QName forName(Class clazz, TypeMapping tm) - throws ClassNotFoundException { - if (void.class.equals(clazz)) { + throws ClassNotFoundException + { + if (void.class.equals(clazz)) + { return null; - } else { + } + else + { return tm.getTypeQName(clazz); } } @@ -322,7 +378,8 @@ /** * Invoke is called to do the actual work of the Handler object. */ - public void invoke(MessageContext msgContext) throws AxisFault { + public void invoke(MessageContext msgContext) throws AxisFault + { // the options of the service String serviceName = msgContext.getTargetService(); // dissect the message @@ -331,59 +388,76 @@ Message resMsg = msgContext.getResponseMessage(); SOAPEnvelope resEnv = (resMsg == null) - ? new SOAPEnvelope() - : (SOAPEnvelope) resMsg.getSOAPEnvelope(); + ? new SOAPEnvelope() + : (SOAPEnvelope) resMsg.getSOAPEnvelope(); // copied code from RobJ, duh? - if (msgContext.getResponseMessage() == null) { + if (msgContext.getResponseMessage() == null) + { resMsg = new Message(resEnv); msgContext.setResponseMessage(resMsg); } // navigate the bodies Iterator allBodies = reqEnv.getBodyElements().iterator(); - while (allBodies.hasNext()) { + while (allBodies.hasNext()) + { Object nextBody = allBodies.next(); - if (nextBody instanceof RPCElement) { + if (nextBody instanceof RPCElement) + { RPCElement body = (RPCElement) nextBody; String mName = body.getMethodName(); List args = null; - try { + try + { args = body.getParams(); - } catch (SAXException e) { + } + catch (SAXException e) + { throw new AxisFault(Constants.EXCEPTION_OCCURED, e); } Object result = null; - try { + try + { MBeanAttributeInfo attr = (MBeanAttributeInfo) attributeData.get(mName); - if (attr != null) { - if (mName.startsWith("get") || mName.startsWith("is")) { + if (attr != null) + { + if (mName.startsWith("get") || mName.startsWith("is")) + { result = server.getAttribute(name, attr.getName()); - } else { + } + else + { RPCParam p = (RPCParam) args.get(0); Object arg = JavaUtils.convert( p.getValue(), - forName(attr.getType(),msgContext.getClassLoader())); + forName(attr.getType(), msgContext.getClassLoader())); server.setAttribute( name, new Attribute(attr.getName(), arg)); result = null; } - } else { + } + else + { MBeanOperationInfo meth = (MBeanOperationInfo) methodData.get(mName); MBeanParameterInfo[] params = meth.getSignature(); Object[] arguments = new Object[params.length]; String[] classNames = new String[params.length]; - for (int count2 = 0; count2 < params.length; count2++) { + for (int count2 = 0; count2 < params.length; count2++) + { classNames[count2] = params[count2].getType(); - if (args.size() > count2) { + if (args.size() > count2) + { RPCParam param = (RPCParam) args.get(count2); arguments[count2] = JavaUtils.convert( param.getValue(), - forName(classNames[count2],msgContext.getClassLoader())); - } else { + forName(classNames[count2], msgContext.getClassLoader())); + } + else + { arguments[count2] = null; } } @@ -400,21 +474,35 @@ resEnv.addBodyElement(resBody); resEnv.setEncodingStyle( org.apache.axis.Constants.URI_DEFAULT_SOAP_ENC); - } catch (InstanceNotFoundException e) { + } + catch (InstanceNotFoundException e) + { throw new AxisFault(Constants.NO_MBEAN_INSTANCE, e); - } catch (AttributeNotFoundException e) { + } + catch (AttributeNotFoundException e) + { throw new AxisFault(Constants.NO_SUCH_ATTRIBUTE, e); - } catch (InvalidAttributeValueException e) { + } + catch (InvalidAttributeValueException e) + { throw new AxisFault(Constants.INVALID_ARGUMENT, e); - } catch (MBeanException e) { + } + catch (MBeanException e) + { throw new AxisFault(Constants.MBEAN_EXCEPTION, e); - } catch (ClassNotFoundException e) { + } + catch (ClassNotFoundException e) + { throw new AxisFault(Constants.CLASS_NOT_FOUND, e); - } catch (ReflectionException e) { + } + catch (ReflectionException e) + { throw new AxisFault( Constants.EXCEPTION_OCCURED, e.getTargetException()); - } catch (SOAPException e) { + } + catch (SOAPException e) + { throw new AxisFault(Constants.EXCEPTION_OCCURED, e); } } // if @@ -422,44 +510,52 @@ } /** generate wsdl document from meta-data */ - public void generateWSDL(MessageContext msgCtx) throws AxisFault { + public void generateWSDL(MessageContext msgCtx) throws AxisFault + { SOAPService service = msgCtx.getService(); //ServiceDesc serviceDesc = service.getInitializedServiceDesc(msgCtx); JavaServiceDesc serviceDesc = (JavaServiceDesc) service.getInitializedServiceDesc(msgCtx); // check whether there is an http action header present - if (msgCtx != null) { + if (msgCtx != null) + { boolean isSoapAction = msgCtx.getProperty(Constants.ACTION_HANDLER_PRESENT_PROPERTY) - == Boolean.TRUE; + == Boolean.TRUE; // yes, then loop through the operation descriptions for (Iterator alloperations = serviceDesc.getOperations().iterator(); - alloperations.hasNext(); - ) { + alloperations.hasNext(); + ) + { OperationDesc opDesc = (OperationDesc) alloperations.next(); // and add a soap action tag with the name of the service opDesc.setSoapAction(isSoapAction ? service.getName() : null); } } - try { + try + { // Location URL is whatever is explicitly set in the MC String locationUrl = msgCtx.getStrProp(MessageContext.WSDLGEN_SERV_LOC_URL); - if (locationUrl == null) { + if (locationUrl == null) + { // If nothing, try what's explicitly set in the ServiceDesc locationUrl = serviceDesc.getEndpointURL(); } - if (locationUrl == null) { + if (locationUrl == null) + { // If nothing, use the actual transport URL locationUrl = msgCtx.getStrProp(MessageContext.TRANS_URL); } // Interface namespace is whatever is explicitly set String interfaceNamespace = msgCtx.getStrProp(MessageContext.WSDLGEN_INTFNAMESPACE); - if (interfaceNamespace == null) { + if (interfaceNamespace == null) + { // If nothing, use the default namespace of the ServiceDesc interfaceNamespace = serviceDesc.getDefaultNamespace(); } - if (interfaceNamespace == null) { + if (interfaceNamespace == null) + { // If nothing still, use the location URL determined above interfaceNamespace = locationUrl; } @@ -474,7 +570,8 @@ String targetNamespace = (String) service.getOption( JavaProvider.OPTION_WSDL_TARGETNAMESPACE); - if (targetNamespace == null || targetNamespace.length() == 0) { + if (targetNamespace == null || targetNamespace.length() == 0) + { targetNamespace = interfaceNamespace; } emitter.setIntfNamespace(targetNamespace); @@ -485,21 +582,24 @@ org.apache.axis.Constants.URI_DEFAULT_SOAP_ENC)); emitter.setDefaultTypeMapping( (TypeMapping) msgCtx - .getTypeMappingRegistry() - .getDefaultTypeMapping()); + .getTypeMappingRegistry() + .getDefaultTypeMapping()); String wsdlPortType = (String) service.getOption(JavaProvider.OPTION_WSDL_PORTTYPE); String wsdlServiceElement = (String) service.getOption(JavaProvider.OPTION_WSDL_SERVICEELEMENT); String wsdlServicePort = (String) service.getOption(JavaProvider.OPTION_WSDL_SERVICEPORT); - if (wsdlPortType != null && wsdlPortType.length() > 0) { + if (wsdlPortType != null && wsdlPortType.length() > 0) + { emitter.setPortTypeName(wsdlPortType); } - if (wsdlServiceElement != null && wsdlServiceElement.length() > 0) { + if (wsdlServiceElement != null && wsdlServiceElement.length() > 0) + { emitter.setServiceElementName(wsdlServiceElement); } - if (wsdlServicePort != null && wsdlServicePort.length() > 0) { + if (wsdlServicePort != null && wsdlServicePort.length() > 0) + { emitter.setServicePortName(wsdlServicePort); } Definition def = emitter.getWSDL(); @@ -519,10 +619,14 @@ field.setAccessible(true); ((Types) field.get(emitter)).insertTypesFragment(doc); msgCtx.setProperty("WSDL", doc); - } catch (NoClassDefFoundError e) { + } + catch (NoClassDefFoundError e) + { log.info(Messages.getMessage("toAxisFault00"), e); throw new AxisFault(e.toString(), e); - } catch (Exception e) { + } + catch (Exception e) + { log.info(Messages.getMessage("toAxisFault00"), e); throw AxisFault.makeFault(e); } @@ -531,7 +635,8 @@ /** * TODO called when a fault occurs to 'undo' whatever 'invoke' did. */ - public void undo(MessageContext msgContext) { + public void undo(MessageContext msgContext) + { // unbelievable this foresight } } |