commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx OperationTag.java ServerTag.java JMXTagLibrary.java ObjectNameConverter.java package.html RegisterTag.java
Date Thu, 20 Mar 2003 17:12:41 GMT
jstrachan    2003/03/20 09:12:41

  Added:       jelly/jelly-tags/jmx/src/test/org/apache/commons/jelly/tags/jmx
                        example.jelly suite.jelly DummyMBean.java
                        TestJelly.java Dummy.java
               jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx
                        OperationTag.java ServerTag.java JMXTagLibrary.java
                        ObjectNameConverter.java package.html
                        RegisterTag.java
  Log:
  Initial checkin of the JellyMBean library which is a simple Jelly alternative to MLETs or
the Ant tasks in Commons Modeler which allows beans to be composed into services and then
registered in JMX servers
  
  Revision  Changes    Path
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/test/org/apache/commons/jelly/tags/jmx/example.jelly
  
  Index: example.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <server xmlns="jelly:jmx">
  	<!--
  		|| define some common MBean types
  		-->
  	<beandef name="dummyMBean" className="org.apache.commons.jelly.tags.jmx.Dummy"/>
  	
  	<!-- 
  		|| Register the MBeans 
  		|| Attributes can be set on MBeans using 
  		|| XML attributes or nested elements
  		-->
  	<register name="Examples:type=short">
  		<dummyMBean name="Short version"/>
  		<operation name="doSomething"/>
  	</register>				
  		
  	<register name="Examples:type=long">
  		<mbean class="org.apache.commons.jelly.tags.jmx.Dummy" name="Longer version"/>
  		<operation name="doSomething"/>
  	</register>				
  		
  	<register name="Naming:type=rmiregistry">
  		<mbean class="mx4j.tools.naming.NamingService"/>
  		<operation name="start"/>
  	</register>
  		
  	<register name="Adaptor:protocol=JRMP">
  		<mbean class="mx4j.adaptor.rmi.jrmp.JRMPAdaptor" JNDIName="jrmp"/>
  		<operation name="start"/>
  	</register>
  		
  </server>
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/test/org/apache/commons/jelly/tags/jmx/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <test:suite 
  	xmlns:j="jelly:core"
  	xmlns="jelly:jmx"
  	xmlns:test="jelly:junit"
  	xmlns:log="jelly:log">
  
  	<test:case name="foo">
  	</test:case>
  	
  </test:suite>
  
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/test/org/apache/commons/jelly/tags/jmx/DummyMBean.java
  
  Index: DummyMBean.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/jmx/src/test/org/apache/commons/jelly/tags/jmx/DummyMBean.java,v
1.1 2003/03/20 17:12:40 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/20 17:12:40 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: DummyMBean.java,v 1.1 2003/03/20 17:12:40 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.jmx;
  
  /**
   * A dummy MBean interface 
   * @author James Strachan
   */
  public interface DummyMBean {
      int getCount();
      String getName();
      void setCount(int count);
      void setName(String name);
      
      void doSomething();
      
  }
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/test/org/apache/commons/jelly/tags/jmx/TestJelly.java
  
  Index: TestJelly.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/jmx/src/test/org/apache/commons/jelly/tags/jmx/TestJelly.java,v
1.1 2003/03/20 17:12:40 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/20 17:12:40 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: TestJelly.java,v 1.1 2003/03/20 17:12:40 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.jmx;
  
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.tags.junit.JellyTestSuite;
  
  /** 
   * A helper class to run jelly test cases as part of Ant's JUnit tests
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class TestJelly extends JellyTestSuite {
  
      public static void main( String[] args ) throws Exception {
          TestRunner.run( suite() );
      }
      
      public static TestSuite suite() throws Exception {
          return createTestSuite(TestJelly.class, "suite.jelly");        
      }
  }
  
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/test/org/apache/commons/jelly/tags/jmx/Dummy.java
  
  Index: Dummy.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/jmx/src/test/org/apache/commons/jelly/tags/jmx/Dummy.java,v
1.1 2003/03/20 17:12:40 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/20 17:12:40 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: Dummy.java,v 1.1 2003/03/20 17:12:40 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.jmx;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * A dummy MBean used for the demo
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class Dummy implements DummyMBean {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(Dummy.class);
      
      private String name = "James";
      private int count;
      
      public void doSomething() {
          ++count;
          log.info("Do something! on: " + this);
      }
      
      public String toString() {
          return super.toString() + "[name=" + name + "]";
      }
  
      
      // Properties
      //-------------------------------------------------------------------------
      
      /**
       * @return int
       */
      public int getCount() {
          return count;
      }
  
      /**
       * @return String
       */
      public String getName() {
          return name;
      }
  
      /**
       * Sets the count.
       * @param count The count to set
       */
      public void setCount(int count) {
          this.count = count;
      }
  
      /**
       * Sets the name.
       * @param name The name to set
       */
      public void setName(String name) {
          this.name = name;
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/OperationTag.java
  
  Index: OperationTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/OperationTag.java,v
1.1 2003/03/20 17:12:41 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/20 17:12:41 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: OperationTag.java,v 1.1 2003/03/20 17:12:41 jstrachan Exp $
   */
  
  package org.apache.commons.jelly.tags.jmx;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.management.ObjectName;
  
  import org.apache.commons.jelly.JellyTagException;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.impl.CollectionTag;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * Registers a JavaBean or JMX MBean with a server..
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class OperationTag extends TagSupport implements CollectionTag {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(OperationTag.class);
  
      private String name;
      private Object arguments;    
      private List argList = null;
      private String[] parameters;
  
      public OperationTag() {
      }
  
      
      // CollectionTag interface
      //-------------------------------------------------------------------------        
           
      public void addItem(Object value) {
          if (argList == null) {
              argList = new ArrayList();
          }
          argList.add(value);
      }
      
      // Tag interface
      //-------------------------------------------------------------------------        
           
      public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException
{
          if (name == null) {
              throw new MissingAttributeException("name");
          }
          
          RegisterTag registerTag = (RegisterTag) findAncestorWithClass(RegisterTag.class);
          if (registerTag == null) {
              throw new JellyTagException("This class must be nested inside a <register>
tag");
          }
          Object bean = null;
          try {
              invokeBody(output);
  
              ObjectName objectName = registerTag.getName();
              registerTag.getServer().invoke(objectName, getName(), getArgumentArray(), getParameters());

          } 
          catch (JellyTagException e) {
              throw e;                
          } 
          catch (Exception e) {
              throw new JellyTagException("Failed to register bean: " + bean, e);        
       
          } 
          finally {
              argList = null;
          }
  	}
  
      
      // Properties
      //-------------------------------------------------------------------------        
           
      
     
  
      /**
       * @return Object
       */
      public Object getArguments() {
          return arguments;
      }
  
      /**
       * @return String
       */
      public String getName() {
          return name;
      }
  
      /**
       * @return String[]
       */
      public String[] getParameters() {
          return parameters;
      }
  
      /**
       * Sets the arguments.
       * @param arguments The arguments to set
       */
      public void setArguments(Object arguments) {
          this.arguments = arguments;
      }
  
      /**
       * Sets the name.
       * @param name The name to set
       */
      public void setName(String name) {
          this.name = name;
      }
  
      /**
       * Sets the parameters.
       * @param parameters The parameters to set
       */
      public void setParameters(String[] parameters) {
          this.parameters = parameters;
      }
  
      // Implementation methods
      //-------------------------------------------------------------------------
      
      /**
       * Converts the argument property into an Object[] or converts the list of
       * added argument objects (added via child tags) to an Object[] or
       * return an empty argument array.
       */
      protected Object[] getArgumentArray() {
          Object arg = getArguments();
          if (arg != null) {
              if (arg instanceof Object[]) {
                  return (Object[]) arg;
              }
              else {
                  return new Object[] { arg };
              }
          }
          else if (argList != null) {
              return argList.toArray();
          }
          else {
              return new Object[0];
          }
      }
  }
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/ServerTag.java
  
  Index: ServerTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/ServerTag.java,v
1.1 2003/03/20 17:12:41 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/20 17:12:41 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: ServerTag.java,v 1.1 2003/03/20 17:12:41 jstrachan Exp $
   */
  
  package org.apache.commons.jelly.tags.jmx;
  
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  
  import org.apache.commons.jelly.JellyTagException;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * Binds a Java bean to the given named Jelly tag so that the attributes of
   * the tag set the bean properties..
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class ServerTag extends TagSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(ServerTag.class);
  
      private MBeanServer server;
      
      public ServerTag() {
      }
      
      // Tag interface
      //-------------------------------------------------------------------------        
           
      public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException
{
          
          // force the creation of a Server
          MBeanServer server = getServer();
  
          // allow children to register beans        
          invokeBody(output);
  	}
  
      
      // Properties
      //-------------------------------------------------------------------------        
           
      /**
       * @return MBeanServer
       */
      public MBeanServer getServer() {
          if (server == null) {
              server = createServer();
          }
          return server;
      }
  
      /**
       * Sets the server.
       * @param server The server to set
       */
      public void setServer(MBeanServer server) {
          this.server = server;
      }
  
      
      
      // Implementation methods
      //-------------------------------------------------------------------------        
           
      /**
       * Factory method to lazily create an MBeanServer if none is supplied
       * 
       * @return MBeanServer
       */
      protected MBeanServer createServer() {
          return MBeanServerFactory.newMBeanServer();
      }
  
  }
  
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/JMXTagLibrary.java
  
  Index: JMXTagLibrary.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/JMXTagLibrary.java,v
1.1 2003/03/20 17:12:41 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/20 17:12:41 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: JMXTagLibrary.java,v 1.1 2003/03/20 17:12:41 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.jmx;
  
  import javax.management.ObjectName;
  
  import org.apache.commons.beanutils.ConvertUtils;
  import org.apache.commons.jelly.tags.bean.BeanTag;
  import org.apache.commons.jelly.tags.bean.BeanTagLibrary;
  
  
  /** 
   * A Tag library for creating an instantiating Java Beans and MBeans
   * and registering them with JMX. Support for setting JMX attributes 
   * and invoking JMX operations is also supported. 
   *
   * @author 
   * @version $Revision: 1.1 $
   */
  public class JMXTagLibrary extends BeanTagLibrary {
  
      static {
          // register the various beanutils Converters from Strings to various JMX types 
          ConvertUtils.register( new ObjectNameConverter(), ObjectName.class );
      }
          
      public JMXTagLibrary() {
          registerTag("mbean", BeanTag.class);
          registerTag("operation", OperationTag.class);
          registerTag("register", RegisterTag.class);
          registerTag("server", ServerTag.class);
      }
  }
  
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/ObjectNameConverter.java
  
  Index: ObjectNameConverter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/ObjectNameConverter.java,v
1.1 2003/03/20 17:12:41 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/20 17:12:41 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: ObjectNameConverter.java,v 1.1 2003/03/20 17:12:41 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.jmx;
  
  import javax.management.MalformedObjectNameException;
  import javax.management.ObjectName;
  
  import org.apache.commons.beanutils.ConversionException;
  import org.apache.commons.beanutils.Converter;
  
  /** 
   * A Converter that turns Strings into JMX ObjectName objects
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class ObjectNameConverter implements Converter {
  
      private static final ObjectNameConverter instance =
          new ObjectNameConverter();
  
      public static ObjectNameConverter getInstance() {
          return instance;
      }
  
      //-------------------------------------------------------------------------
      public Object convert(Class type, Object value) {
          try {
              if (value == null) {
                  return new ObjectName("");
              }
              else {
                  return new ObjectName(value.toString());
              }
          }
          catch (MalformedObjectNameException e) {
              throw new ConversionException(
                  "Could not convert: "
                      + value
                      + " into ObjectName. Reason: "
                      + e,
                  e);
          }
      }
  }
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>
    	A tag library for creating beans and MBeans and registering them with a JMX Server in
a similar way
    	to the Ant tasks in Jakarta Commons Modeler
    </p>
    
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/RegisterTag.java
  
  Index: RegisterTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/jmx/src/java/org/apache/commons/jelly/tags/jmx/RegisterTag.java,v
1.1 2003/03/20 17:12:41 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/20 17:12:41 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: RegisterTag.java,v 1.1 2003/03/20 17:12:41 jstrachan Exp $
   */
  
  package org.apache.commons.jelly.tags.jmx;
  
  import javax.management.InstanceAlreadyExistsException;
  import javax.management.MBeanRegistrationException;
  import javax.management.MBeanServer;
  import javax.management.NotCompliantMBeanException;
  import javax.management.ObjectName;
  
  import org.apache.commons.jelly.JellyTagException;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.impl.CollectionTag;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * Registers a JavaBean or JMX MBean with a server..
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class RegisterTag extends TagSupport implements CollectionTag {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(RegisterTag.class);
  
      private ObjectName name;    
      private MBeanServer server;
  
      public RegisterTag() {
      }
  
      
      // CollectionTag interface
      //-------------------------------------------------------------------------        
           
      public void addItem(Object bean) throws JellyTagException {
          try {
              register(server, bean);            
          } 
          catch (Exception e) {
              throw new JellyTagException("Failed to register bean: " + bean, e);        
       
          } 
      }
      
      // Tag interface
      //-------------------------------------------------------------------------        
           
      public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException
{
          if (name == null) {
              throw new MissingAttributeException("name");
          }
          if (server == null) {
              ServerTag serverTag = (ServerTag) findAncestorWithClass(ServerTag.class);
              if (serverTag == null) {
                  throw new JellyTagException("This class must be nested inside a <server>
tag");
              }
              server = serverTag.getServer();
          }
          invokeBody(output);
  	}
  
      
      // Properties
      //-------------------------------------------------------------------------        
           
      
     
      /**
       * @return ObjectName
       */
      public ObjectName getName() {
          return name;
      }
  
      /**
       * Sets the name.
       * @param name The name to set
       */
      public void setName(ObjectName name) {
          this.name = name;
      }
  
      /**
       * @return MBeanServer
       */
      public MBeanServer getServer() {
          return server;
      }
  
      /**
       * Sets the MBeanServer. If this attribute is not supplied then the parent &lt;server&gt;
tag
       * is used to get the MBeanServer instance to use.
       * 
       * @param server The MBeanServer to register the mbeans with.
       */
      public void setServer(MBeanServer server) {
          this.server = server;
      }
  
      // Implementation methods
      //-------------------------------------------------------------------------   
                       
      /**
       * Registers the given bean with the MBeanServer
       */
      protected void register(MBeanServer server, Object bean) throws InstanceAlreadyExistsException,
MBeanRegistrationException, NotCompliantMBeanException {
          server.registerMBean(bean, getName());
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message