下面列出了怎么用javax.management.modelmbean.InvalidTargetObjectTypeException的API类实例代码及写法,或者点击链接到github查看源代码。
private Object resolveTargetObject(Descriptor descriptor) throws MBeanException
{
Logger logger = getLogger();
Object target = descriptor.getFieldValue("targetObject");
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObject is: " + target);
if (target == null)
{
target = getManagedResource();
}
else
{
String targetObjectType = (String)descriptor.getFieldValue("targetObjectType");
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObjectType is: " + targetObjectType);
if (targetObjectType == null)
{
// Not defined, assume object reference
targetObjectType = OBJECT_RESOURCE_TYPE;
}
if (!isResourceTypeSupported(targetObjectType)) throw new MBeanException(new InvalidTargetObjectTypeException(targetObjectType));
}
return target;
}
private Object resolveTargetObject(Descriptor descriptor) throws MBeanException
{
Logger logger = getLogger();
Object target = descriptor.getFieldValue("targetObject");
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObject is: " + target);
if (target == null)
{
target = getManagedResource();
}
else
{
String targetObjectType = (String)descriptor.getFieldValue("targetObjectType");
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObjectType is: " + targetObjectType);
if (targetObjectType == null)
{
// Not defined, assume object reference
targetObjectType = OBJECT_RESOURCE_TYPE;
}
if (!isResourceTypeSupported(targetObjectType)) throw new MBeanException(new InvalidTargetObjectTypeException(targetObjectType));
}
return target;
}
protected T doGetManagedResource() throws MBeanException {
try {
@SuppressWarnings("unchecked")
T resource = (T) getManagedResource();
return resource;
} catch (InstanceNotFoundException | RuntimeOperationsException |
InvalidTargetObjectTypeException e) {
throw new MBeanException(e);
}
}
/**
* Sets managed resource to expose and stores its {@link ClassLoader}.
*/
@Override
public void setManagedResource(Object managedResource, String managedResourceType)
throws MBeanException, InstanceNotFoundException, InvalidTargetObjectTypeException {
this.managedResourceClassLoader = managedResource.getClass().getClassLoader();
super.setManagedResource(managedResource, managedResourceType);
}
/**
* Sets managed resource to expose and stores its {@link ClassLoader}.
*/
@Override
public void setManagedResource(Object managedResource, String managedResourceType)
throws MBeanException, InstanceNotFoundException, InvalidTargetObjectTypeException {
this.managedResourceClassLoader = managedResource.getClass().getClassLoader();
super.setManagedResource(managedResource, managedResourceType);
}
public ModelMBean assemble(Object obj, ObjectName name) throws JMException {
ModelMBeanInfo mbi = null;
// use the default provided mbean which has been annotated with JMX
// annotations
LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
mbi = assembler.getMBeanInfo(obj, null, name.toString());
if (mbi == null) {
return null;
}
RequiredModelMBean mbean = new RequiredModelMBean(mbi);
try {
mbean.setManagedResource(obj, "ObjectReference");
} catch (InvalidTargetObjectTypeException e) {
throw new JMException(e.getMessage());
}
// Allows the managed object to send notifications
if (obj instanceof NotificationSenderAware) {
((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
}
return mbean;
}
/**
* Sets managed resource to expose and stores its {@link ClassLoader}.
*/
@Override
public void setManagedResource(Object managedResource, String managedResourceType)
throws MBeanException, InstanceNotFoundException, InvalidTargetObjectTypeException {
this.managedResourceClassLoader = managedResource.getClass().getClassLoader();
super.setManagedResource(managedResource, managedResourceType);
}
/**
* Sets managed resource to expose and stores its {@link ClassLoader}.
*/
@Override
public void setManagedResource(Object managedResource, String managedResourceType)
throws MBeanException, InstanceNotFoundException, InvalidTargetObjectTypeException {
this.managedResourceClassLoader = managedResource.getClass().getClassLoader();
super.setManagedResource(managedResource, managedResourceType);
}
public void setManagedResource(Object resource, String resourceType) throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException
{
if (resource == null) throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_MANAGED_RESOURCE_CANNOT_BE_NULL.toLocalizedString()));
if (!isResourceTypeSupported(resourceType)) throw new InvalidTargetObjectTypeException(resourceType);
Logger logger = getLogger();
if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Setting managed resource to be: " + resource);
m_managedResource = resource;
}
@Override
public ModelMBean assemble(Object obj, ObjectName name) throws JMException {
ModelMBeanInfo mbi = null;
// use the default provided mbean which has been annotated with JMX annotations
LOGGER.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
mbi = assembler.getMBeanInfo(obj, null, name.toString());
if (mbi == null) {
return null;
}
RequiredModelMBean mbean = new RequiredModelMBean(mbi);
try {
mbean.setManagedResource(obj, "ObjectReference");
} catch (InvalidTargetObjectTypeException e) {
throw new JMException(e.getMessage());
}
// Allows the managed object to send notifications
if (obj instanceof NotificationSenderAware) {
((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean));
}
return mbean;
}
public void setManagedResource(Object resource, String resourceType) throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException
{
if (resource == null) throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_MANAGED_RESOURCE_CANNOT_BE_NULL.toLocalizedString()));
if (!isResourceTypeSupported(resourceType)) throw new InvalidTargetObjectTypeException(resourceType);
Logger logger = getLogger();
if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Setting managed resource to be: " + resource);
m_managedResource = resource;
}
void initialise(RMConfiguration config, Conduit c, EndpointReferenceType r,
org.apache.cxf.transport.Destination d,
Message message) {
configuration = config;
conduit = c;
replyTo = r;
createServices();
createEndpoints(d);
setPolicies(message);
if (manager != null && manager.getBus() != null) {
managedEndpoint = new ManagedRMEndpoint(this);
instrumentationManager = manager.getBus().getExtension(InstrumentationManager.class);
if (instrumentationManager != null) {
ModelMBeanAssembler assembler = new ModelMBeanAssembler();
ModelMBeanInfo mbi = assembler.getModelMbeanInfo(managedEndpoint.getClass());
MBeanServer mbs = instrumentationManager.getMBeanServer();
if (mbs == null) {
LOG.log(Level.WARNING, "MBeanServer not available.");
} else {
try {
RequiredModelMBean rtMBean =
(RequiredModelMBean)mbs.instantiate("javax.management.modelmbean.RequiredModelMBean");
rtMBean.setModelMBeanInfo(mbi);
try {
rtMBean.setManagedResource(managedEndpoint, "ObjectReference");
} catch (InvalidTargetObjectTypeException itotex) {
throw new JMException(itotex.getMessage());
}
ObjectName name = managedEndpoint.getObjectName();
instrumentationManager.register(rtMBean, name);
modelMBean = rtMBean;
} catch (JMException jmex) {
LOG.log(Level.WARNING, "Registering ManagedRMEndpoint failed.", jmex);
}
}
}
}
}
private void register(Object obj, ObjectName name, ModelMBeanInfo mbi, boolean forceRegistration)
throws JMException {
RequiredModelMBean rtMBean =
(RequiredModelMBean)mbs.instantiate("javax.management.modelmbean.RequiredModelMBean");
rtMBean.setModelMBeanInfo(mbi);
try {
rtMBean.setManagedResource(obj, "ObjectReference");
} catch (InvalidTargetObjectTypeException itotex) {
throw new JMException(itotex.getMessage());
}
registerMBeanWithServer(rtMBean, persist(name), forceRegistration);
}
public JmxBuilderModelMBean(Object objectRef) throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException {
super.setManagedResource(objectRef, "ObjectReference");
}
@Override
public void setManagedResource(Object mr, String mr_type) throws MBeanException, RuntimeOperationsException,
InstanceNotFoundException, InvalidTargetObjectTypeException {
}
/**
* Get the instance handle of the object against which we execute
* all methods in this ModelMBean management interface.
*
* @return the backend managed object
* @exception InstanceNotFoundException if the managed resource object
* cannot be found
* @exception InvalidTargetObjectTypeException if the managed resource
* object is of the wrong type
* @exception MBeanException if the initializer of the object throws
* an exception
* @exception RuntimeOperationsException if the managed resource or the
* resource type is <code>null</code> or invalid
*/
public Object getManagedResource()
throws InstanceNotFoundException, InvalidTargetObjectTypeException,
MBeanException, RuntimeOperationsException {
if (resource == null)
throw new RuntimeOperationsException
(new IllegalArgumentException("Managed resource is null"),
"Managed resource is null");
return resource;
}
/**
* Get the instance handle of the object against which we execute
* all methods in this ModelMBean management interface.
*
* @exception InstanceNotFoundException if the managed resource object
* cannot be found
* @exception InvalidTargetObjectTypeException if the managed resource
* object is of the wrong type
* @exception MBeanException if the initializer of the object throws
* an exception
* @exception RuntimeOperationsException if the managed resource or the
* resource type is <code>null</code> or invalid
*/
public Object getManagedResource()
throws InstanceNotFoundException, InvalidTargetObjectTypeException,
MBeanException, RuntimeOperationsException {
if (resource == null)
throw new RuntimeOperationsException
(new IllegalArgumentException("Managed resource is null"),
"Managed resource is null");
return resource;
}
/**
* Get the instance handle of the object against which we execute
* all methods in this ModelMBean management interface.
*
* @exception InstanceNotFoundException if the managed resource object
* cannot be found
* @exception InvalidTargetObjectTypeException if the managed resource
* object is of the wrong type
* @exception MBeanException if the initializer of the object throws
* an exception
* @exception RuntimeOperationsException if the managed resource or the
* resource type is <code>null</code> or invalid
*/
public Object getManagedResource()
throws InstanceNotFoundException, InvalidTargetObjectTypeException,
MBeanException, RuntimeOperationsException {
if (resource == null)
throw new RuntimeOperationsException
(new IllegalArgumentException("Managed resource is null"),
"Managed resource is null");
return resource;
}