View Javadoc

1   /* $Id: MBeanOperationBase.java 4012 2005-12-14 18:08:08Z dbernstein $
2    *
3    * (Created on Dec 12, 2005
4    *
5    * Copyright (C) 2005 Internet Archive.
6    *  
7    * This file is part of the Heritrix Cluster Controller (crawler.archive.org).
8    *  
9    * HCC is free software; you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser Public License as published by
11   * the Free Software Foundation; either version 2.1 of the License, or
12   * any later version.
13   * 
14   * Heritrix is distributed in the hope that it will be useful, 
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU Lesser Public License for more details.
18   * 
19   * You should have received a copy of the GNU Lesser Public License
20   * along with Heritrix; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22   */
23  package org.archive.hcc.util.jmx;
24  
25  import javax.management.MBeanException;
26  import javax.management.MBeanParameterInfo;
27  import javax.management.ReflectionException;
28  import javax.management.openmbean.OpenMBeanOperationInfo;
29  
30  public abstract class MBeanOperationBase implements
31          MBeanOperation {
32  
33      private OpenMBeanOperationInfo info;
34  
35      public MBeanOperationBase(OpenMBeanOperationInfo info) {
36          this.info = info;
37      }
38  
39      public OpenMBeanOperationInfo getInfo() {
40          return this.info;
41      }
42  
43      public boolean matches(String name, String[] signature) {
44          if (!name.equals(this.info.getName())) {
45              return false;
46          }
47          MBeanParameterInfo[] infoSignature = this.info.getSignature();
48          if (signature.length != infoSignature.length) {
49              return false;
50          }
51  
52          for (int i = 0; i < signature.length; i++) {
53              boolean namesMatch = signature[i]
54                      .equals(infoSignature[i].getType());
55              if (!namesMatch) {
56                  return false;
57              }
58          }
59  
60          return true;
61  
62      }
63  
64      public boolean validate(String name, Object[] parameters, String[] signature) {
65          if (!name.equals(this.info.getName())) {
66              return false;
67          }
68          MBeanParameterInfo[] infoSignature = this.info.getSignature();
69          if (signature.length != infoSignature.length) {
70              return false;
71          }
72  
73          for (int i = 0; i < signature.length; i++) {
74              boolean namesMatch = signature[i]
75                      .equals(infoSignature[i].getName());
76              boolean typesMatch = parameters[i].getClass().getName().equals(
77                      infoSignature[i].getType());
78  
79              if (!namesMatch || !typesMatch) {
80                  return false;
81              }
82          }
83  
84          return true;
85  
86      }
87  
88      public MBeanInvocation createInvocation(
89              Object[] parameters,
90              String[] signature) throws MBeanException, ReflectionException {
91  
92          return getInvocation(parameters);
93      }
94  
95      protected abstract MBeanInvocation getInvocation(Object[] params);
96  
97  }