All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gemstone.gemfire.management.internal.web.shell.support.HttpInvocationHandler Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You
 * may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. See accompanying
 * LICENSE file.
 */
package com.gemstone.gemfire.management.internal.web.shell.support;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javax.management.ObjectName;

import com.gemstone.gemfire.management.internal.web.shell.HttpOperationInvoker;

/**
 * The HttpInvocationHandler class is an implementation of InvocationHandler serving as a proxy that uses HTTP remoting
 * for the actual method invocation on the target resource.
 * 

* @author John Blum * @see java.lang.reflect.InvocationHandler * @see javax.management.ObjectName * @see com.gemstone.gemfire.management.internal.web.shell.HttpOperationInvoker * @since 7.5 */ @SuppressWarnings("unused") public class HttpInvocationHandler implements InvocationHandler { private final HttpOperationInvoker operationInvoker; private final ObjectName objectName; public HttpInvocationHandler(final HttpOperationInvoker operationInvoker, final ObjectName objectName) { assert operationInvoker != null : "The HTTP-based OperationInvoker cannot be null!"; assert objectName != null : "The ObjectName of the resource on which the operation is invoked cannot be null!"; this.operationInvoker = operationInvoker; this.objectName = objectName; } protected final ObjectName getObjectName() { return objectName; } protected final HttpOperationInvoker getOperationInvoker() { return operationInvoker; } protected boolean isAttributeAccessor(final Method method) { final String methodName = method.getName(); return (methodName.startsWith("get") || methodName.startsWith("is")); } protected String getAttributeName(final Method method) { final String methodName = method.getName(); // the attribute accessor method name either begins with 'get' or 'is' as defined by the JMX specification final int beginIndex = (methodName.startsWith("get") ? 3 : 2); return methodName.substring(beginIndex); } protected String getResourceName() { return getObjectName().getCanonicalName(); } protected String[] getSignature(final Method method) { final List signature = new ArrayList(); for (final Class parameterType : method.getParameterTypes()) { signature.add(parameterType.getName()); } return signature.toArray(new String[signature.size()]); } @Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if (isAttributeAccessor(method)) { return getOperationInvoker().getAttribute(getResourceName(), getAttributeName(method)); } else { return getOperationInvoker().invoke(getResourceName(), method.getName(), args, getSignature(method)); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy