ManagedConfigBeanpublic class ManagedConfigBean extends Object
Fields Summary |
---|
public final String | PROPERTY_NAME_PREFIX | public final String | SYSTEM_PROPERTY_NAME_PREFIX | public static final Logger | _sLogger | private static final String | MSG_BASE_GET_ATTRIBUTE | private static final String | MSG_BASE_SET_ATTRIBUTE | private static final String | MSG_BASE_GOT_ATTRIBUTE | private static final String | MSG_BASE_GET_PROPERTY | private static final String | MSG_BASE_GET_PROPERTIES | private static final String | MSG_BASE_SET_PROPERTY | private static final String | MSG_BASE_GET_DEF_ATTR_VALUE | private static final String | MSG_GET_CONFBEANBYXPATH | private static final String | MSG_BASE_GET_CUSTOM_PROPERTIESLIST | private com.sun.enterprise.config.ConfigBean | m_baseConfigBean | private MBeanInfo | m_mbeanInfo | private com.sun.enterprise.admin.meta.MBeanRegistry | m_registry | private com.sun.enterprise.config.ConfigContext | m_configContext | private static com.sun.enterprise.util.i18n.StringManager | localStrings |
Constructors Summary |
---|
public ManagedConfigBean(DynamicMBean mbean, com.sun.enterprise.config.ConfigBean cb, com.sun.enterprise.admin.meta.MBeanRegistry registry)
this(mbean.getMBeanInfo(), cb, registry);
| public ManagedConfigBean(MBeanInfo mbeanInfo, com.sun.enterprise.config.ConfigBean cb, com.sun.enterprise.admin.meta.MBeanRegistry registry)
m_baseConfigBean = cb;
m_mbeanInfo = mbeanInfo;
m_configContext = cb.getConfigContext();
m_registry = registry;
| public ManagedConfigBean(com.sun.enterprise.config.ConfigBean cb, com.sun.enterprise.admin.meta.MBeanRegistry registry, String domainName)
this(cb, null, registry, domainName);
| public ManagedConfigBean(com.sun.enterprise.config.ConfigBean cb, String xpath, com.sun.enterprise.admin.meta.MBeanRegistry registry, String domainName)
if(xpath==null)
xpath = cb.getAbsoluteXPath("");
MBeanRegistryEntry entry = registry.findMBeanRegistryEntryByXPath(xpath);
MBeanNamingDescriptor descr = entry.getNamingDescriptor();
String[] parms = descr.extractParmListFromXPath(xpath);
MBeanNamingInfo namingInfo = new MBeanNamingInfo(descr, descr.getType(), parms);
m_mbeanInfo = (MBeanInfo)entry.createMBeanInfo(namingInfo, domainName);
m_baseConfigBean = cb;
m_configContext = cb.getConfigContext();
m_registry = registry;
|
Methods Summary |
---|
private void | addArrayToList(java.util.ArrayList list, java.lang.Object[] objects)
if(objects!=null)
for(int i=0; i<objects.length; i++) {
list.add(objects[i]);
}
| public void | addChildBean(java.lang.String childName, com.sun.enterprise.config.ConfigBean bean, boolean bOnlyOneChildPossible)
Class clBase = m_baseConfigBean.getClass();
Method method;
if(bOnlyOneChildPossible)
method = clBase.getDeclaredMethod("set"+ConfigMBeanHelper.convertTagName(childName), new Class[]{bean.getClass()});
else
method = clBase.getDeclaredMethod("add"+ConfigMBeanHelper.convertTagName(childName), new Class[]{bean.getClass()});
method.invoke(m_baseConfigBean, new Object[]{bean});
| void | collectChildrenObjectNames(com.sun.enterprise.config.ConfigBean bean, java.util.ArrayList arr)
try
{
ConfigBean[] beans = bean.getAllChildBeans();
for(int i=0; i<beans.length; i++)
{
collectChildrenObjectNames(beans[i], arr);
}
}
catch(Exception e)
{
}
try
{
ObjectName name = (ObjectName)ConfigMBeanHelper.converConfigBeansToObjectNames(m_registry, (ModelMBeanInfo)m_mbeanInfo, (Object)bean);
if(name!=null)
arr.add(name);
}
catch(Exception e)
{
}
| public com.sun.enterprise.config.ConfigBean | createChildByType(java.lang.String childName, javax.management.AttributeList childValues, java.util.Properties props, boolean bOnlyOneChildPossible)
//First. Create standalone bean of child type with Attributes and Properties set
ConfigBean bean = createChildByType(childName, childValues, props);
if(bean==null)
return null;
// Now, connect it to papa bean
addChildBean(childName, bean, bOnlyOneChildPossible);
return bean;
| public com.sun.enterprise.config.ConfigBean | createChildByType(java.lang.String childName, javax.management.AttributeList childValues, java.util.Properties props)
if(m_baseConfigBean==null)
return null;
String xpath = MBeanHelper.getXPathPattern( (ModelMBeanInfo)m_mbeanInfo) +
ServerXPathHelper.XPATH_SEPARATOR + childName;
Class cl = ConfigMBeanHelper.getConfigBeanClass(xpath);
ConfigBean bean = (ConfigBean)cl.newInstance();
MBeanRegistryEntry regEntry = m_registry.findMBeanRegistryEntryByXPathPattern(xpath);
if(childValues!=null)
for(int i=0; i<childValues.size(); i++)
{
Attribute attr = (Attribute)childValues.get(i);
if( (attr.getValue()==null || attr.getValue().equals("")))
{
//empty value set bypass if not allowed in the registry
boolean bEmptyValueAllowed = false;
try {
// analyze registry_Entry emptyValueAllowed (if mentioned)
bEmptyValueAllowed = regEntry.isAttributeEmptyValueAllowed(attr.getName());
} catch (MBeanMetaException mme)
{
//field not found in registry
}
if(!bEmptyValueAllowed)
continue; //skip set of empty value
}
if(attr.getValue()==null)
bean.setAttributeValue(MBeanMetaHelper.mapToConfigBeanAttributeName(attr.getName()), (String)attr.getValue());
else
bean.setAttributeValue(MBeanMetaHelper.mapToConfigBeanAttributeName(attr.getName()), ""+attr.getValue());
}
if(props!=null && props.size()>0)
{
final Enumeration e = props.propertyNames();
ArrayList propsList = new ArrayList();
while (e.hasMoreElements())
{
ElementProperty ep = new ElementProperty();
String key = (String)e.nextElement();
ep.setName(key);
ep.setValue(props.getProperty(key));
propsList.add(ep);
}
if(propsList.size()>0)
{
ElementProperty eps[] = (ElementProperty[])propsList.toArray(
new ElementProperty[propsList.size()]);
bean.setValue("ElementProperty", eps);
}
}
return bean;
| public void | deleteSelf()
if(m_baseConfigBean==null)
return;
String xpath = null;
//try {
xpath = m_baseConfigBean.getAbsoluteXPath(null);
xpath = ServerXPathHelper.getParentXPath(xpath);
ConfigContext ctx = getConfigContext(); //com.sun.enterprise.admin.config.BaseConfigMBean.getConfigContext(); //FIXME: this method should not be in MBEAN
ConfigBean parent = ConfigBeansFactory.getConfigBeanByXPath(ctx, xpath);
parent.removeChild(m_baseConfigBean);
//} catch(Exception e)
//{
//FIXME:temporary solution
// System.out.println("Exception during deleteSelf() xpath="+xpath);
//}
| private java.lang.String[] | getAllAttributeNames()
MBeanInfo mbi = m_mbeanInfo;
if(mbi==null )
return null;
MBeanAttributeInfo[] ai = mbi.getAttributes();
if(ai==null || ai.length==0)
return null;
ArrayList list = new ArrayList();
if(ai!=null)
for(int i=0; i<ai.length; i++)
{
String name = ai[i].getName();
if(!name.equals("modelerType")) //FIXME: temporary
list.add(name);
}
return (String[])list.toArray(new String[list.size()]);
| private java.lang.String[] | getAllPropertyNames(boolean bAddPropertyPrefix)
ConfigBean baseBean = getBaseConfigBean();
Class cl = baseBean.getClass();
ElementProperty[] props;
try {
Method method = cl.getDeclaredMethod("getElementProperty");
props = (ElementProperty[])method.invoke(baseBean);
String[] names = new String[props.length];
for(int i=0; i<props.length; i++) {
if(bAddPropertyPrefix)
names[i] = PROPERTY_NAME_PREFIX+props[i].getName();
else
names[i] = props[i].getName();
}
return names;
}
catch (java.lang.NoSuchMethodException nsme) {
return null;
}
catch (java.lang.IllegalAccessException iae) {
return null;
}
catch (java.lang.reflect.InvocationTargetException ite) {
return null;
}
| private java.lang.String[] | getAllSystemPropertyNames(boolean bAddPropertyPrefix)
ConfigBean baseBean = getBaseConfigBean();
Class cl = baseBean.getClass();
SystemProperty[] props;
try {
Method method = cl.getDeclaredMethod("getSystemProperty");
props = (SystemProperty[])method.invoke(baseBean);
String[] names = new String[props.length];
for(int i=0; i<props.length; i++) {
if(bAddPropertyPrefix)
names[i] = SYSTEM_PROPERTY_NAME_PREFIX+props[i].getName();
else
names[i] = props[i].getName();
}
return names;
}
catch (java.lang.NoSuchMethodException nsme) {
return null;
}
catch (java.lang.IllegalAccessException iae) {
return null;
}
catch (java.lang.reflect.InvocationTargetException ite) {
return null;
}
| private javax.management.MBeanAttributeInfo | getAttrInfo(java.lang.String attrName)
if(m_mbeanInfo==null )
return null;
MBeanAttributeInfo[] ai = m_mbeanInfo.getAttributes();
if(ai!=null)
for(int i=0; i<ai.length; i++) {
String name = ai[i].getName();
if(attrName.equals(ai[i].getName()))
return ai[i];
}
return null; //FIXME
| public java.lang.Object | getAttribute(javax.management.modelmbean.ModelMBeanAttributeInfo attrInfo, java.lang.String externalName)Gets MBean's attribute value.
_sLogger.log(Level.FINEST, MSG_BASE_GET_ATTRIBUTE, externalName);
MBeanAttributeInfo ai = getAttrInfo(externalName);
boolean isProperty = externalName.startsWith(PROPERTY_NAME_PREFIX);
boolean isSystemProperty = externalName.startsWith(SYSTEM_PROPERTY_NAME_PREFIX);
boolean isArray = false;
if(externalName.equals("modelerType"))
return null;
if(ai==null && !isProperty && !isSystemProperty) {
String msg = localStrings.getString( "admin.server.core.mbean.config.attribute_not_defined", externalName );
throw new AttributeNotFoundException( msg );
}
if(ai!=null && !ai.isReadable()) {
String msg = localStrings.getString( "admin.server.core.mbean.config.attribute_not_readable", externalName );
throw new AttributeNotFoundException( msg );
}
// try {
if(isProperty)
{
// get property value
return getPropertyValue(externalName.substring(PROPERTY_NAME_PREFIX.length()));
}
else if(isSystemProperty)
{
// get system property value
return getSystemPropertyValue(externalName.substring(SYSTEM_PROPERTY_NAME_PREFIX.length()));
}
else
{
AttrDescriptor descr = getDescriptor(externalName);
ConfigBean bean = getConfigBean(externalName);
Object value = null;
if(descr.isElement())
{
//it looks that now we have no Elements with values
//value = descr.getNode().getContent();
wrapAndThrowMBeanException(null, "getattribute_not_implemented_for_xml", externalName);
}
else
{
if(ai.getType().startsWith("[")) //array
{
Class cl = bean.getClass();
try
{
Method method = cl.getMethod("getValues", new Class[]{Class.forName("java.lang.String")});
value = method.invoke(bean, new Object[]{ConfigBean.camelize(descr.getAttributeName())});
}
catch (Exception e)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_invocation_error", externalName );
throw MBeanHelper.extractAndWrapTargetException(e, msg);
}
}
else
{
value = bean.getAttributeValue(descr.getAttributeName());
}
//value = descr.getNode().getAttributeValue(descr.getAttributeName());
}
_sLogger.log(Level.FINEST, MSG_BASE_GOT_ATTRIBUTE, new Object[]
{externalName,value});
return value;
}
// }
// catch (MBeanConfigException e) {
// String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_attribute_exception", externalName, e.getMessage() );
// throw new MBeanException(new MBeanConfigException( msg ));
// }
| public javax.management.MBeanAttributeInfo | getAttributeInfo(java.lang.String attrName)
attrName = MBeanMetaHelper.mapToMBeanAttributeName(attrName);
return (ModelMBeanAttributeInfo)
MBeanHelper.findMatchingAttributeInfo(m_mbeanInfo, attrName);
| public javax.management.AttributeList | getAttributes(java.lang.String[] attributeNames)Gets MBean's attribute values.
ArrayList names = getSimpleAttributeNames(attributeNames);
AttributeList attrs = new AttributeList();
for(int i=0; i<names.size(); i++) {
try {
String name = MBeanMetaHelper.mapToMBeanAttributeName((String)names.get(i));
Object value = getAttribute(null, name); //FIXME
attrs.add(new Attribute(name, value));
} catch (MBeanException ce) {
// attrs.add(new Attribute(attributeNames[i], null));
} catch (AttributeNotFoundException ce) {
// attrs.add(new Attribute(attributeNames[i], null));
} catch (NullPointerException npe) //ConfigBean returns this exception by many reasons
{
// attrs.add(new Attribute(attributeNames[i], null));
} catch (IllegalArgumentException iae) //ConfigBean returns this exception by many reasons
{
// attrs.add(new Attribute(attributeNames[i], null));
}
}
return attrs;
| public com.sun.enterprise.config.ConfigBean | getBaseConfigBean()Get base node Config Bean;
return m_baseConfigBean;
| public com.sun.enterprise.config.ConfigBean | getChildElementByName(java.lang.String methodName, java.lang.String name)Gets MBean's child element.
ConfigBean baseBean = getBaseConfigBean();
Class cl = baseBean.getClass();
ConfigBean bean;
try
{
Method method = cl.getDeclaredMethod(methodName, new Class[]{Class.forName("java.lang.String")});
return (ConfigBean)method.invoke(baseBean, new Object[]{name});
}
catch (Exception e)
{
wrapAndThrowMBeanException(e, "getattribute.undefined_childelement_in_base_element", name );
return null; //just to avoid compiling err
}
| public com.sun.enterprise.config.ConfigBean | getConfigBean(java.lang.String externalName)Get ConfigBean object which contains correspondent attribute.
//in 8.0 we support only base config bean attributes and properties access
return m_baseConfigBean;
/*7.0 //this method can be overriten in child class (temporary until Config static method getBeanByXPath will be ready)
AttrDescriptor descr = getDescriptor(externalName);
try
{
return descr.getConfigBean();
}
catch (Exception e)
{
return null;
}
*/
| public com.sun.enterprise.config.ConfigContext | getConfigContext()public static ManagedConfigBean getManagedConfigBean(cb
/****************************************************************************************************************
return m_configContext;
| public com.sun.enterprise.admin.meta.naming.MBeanNamingInfo | getConfigMBeanNamingInfo()
return null; //FIXME return m_MBeanNamingInfo;
| public java.lang.Object | getDefaulCustomProperties(java.lang.String propertyName)
_sLogger.log(Level.FINEST, MSG_BASE_GET_CUSTOM_PROPERTIESLIST, propertyName);
return null; //can be overriden
| public java.lang.String | getDefaultAttributeValue(java.lang.String externalName)Gets MBean's attribute default value or null (if def value is not defined).
_sLogger.log(Level.FINEST, MSG_BASE_GET_DEF_ATTR_VALUE, externalName);
MBeanAttributeInfo ai = getAttrInfo(externalName);
if(ai==null) {
String msg = localStrings.getString( "admin.server.core.mbean.config.getdefaultattribute_undefined_attribute", externalName );
throw new AttributeNotFoundException( msg );
}
// try
{
AttrDescriptor descr = getDescriptor(externalName);
String value = descr.getDefaultValue();
return value;
}
/* catch (ConfigException e)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.getdefaultattributevalue_exception_for_externalname_basexpath", externalName, m_BasePath, e.getMessage() );
throw new MBeanException(new ConfigException( msg ));
}
*/
| private com.sun.enterprise.admin.config.ManagedConfigBean$AttrDescriptor | getDescriptor(java.lang.String externalName)
try {
return new AttrDescriptor(externalName); //FIXME
} catch (MBeanConfigException mbce)
{
return null;
}
// return (AttrDescriptor)m_Attrs.get(externalName);
| public javax.management.AttributeList | getProperties()
_sLogger.log(Level.FINEST, MSG_BASE_GET_PROPERTIES);
ConfigBean baseBean = getBaseConfigBean();
Class cl = baseBean.getClass();
ElementProperty[] props = null;
try {
Method method = cl.getDeclaredMethod("getElementProperty");
props = (ElementProperty[])method.invoke(baseBean);
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "getattribute.undefined_properties_in_base_element" );
}
if(props==null) {
return new AttributeList();
}
AttributeList list = new AttributeList();
for(int i=0; i<props.length; i++)
{
list.add(new Attribute(props[i].getName(), props[i].getValue()));
}
return list;
| public java.lang.Object | getPropertyValue(java.lang.String propertyName)Gets MBean's property value.
_sLogger.log(Level.FINEST, MSG_BASE_GET_PROPERTY, propertyName);
ConfigBean baseBean = getBaseConfigBean();
Class cl = baseBean.getClass();
ElementProperty prop = null;
try {
Method method = cl.getDeclaredMethod("getElementPropertyByName", new Class[]{Class.forName("java.lang.String")});
prop = (ElementProperty)method.invoke(baseBean, new Object[]{propertyName});
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "getattribute.undefined_properties_in_base_element");
}
if(prop==null) {
wrapAndThrowMBeanException(null, "getattribute_properties_not_found_in_base_element", propertyName );
}
return prop.getValue();
| protected java.util.ArrayList | getSimpleAttributeNames(java.lang.String[] attributeNames)Gets MBean's attribute values.
ArrayList simpleNames = new ArrayList();
for(int i=0; i<attributeNames.length; i++) {
if(attributeNames[i].length()==0) {
addArrayToList(simpleNames, getAllAttributeNames());
}
else if(attributeNames[i].equals(PROPERTY_NAME_PREFIX)) {
addArrayToList(simpleNames, getAllPropertyNames(true));
}
else if(attributeNames[i].equals(SYSTEM_PROPERTY_NAME_PREFIX)) {
addArrayToList(simpleNames, getAllSystemPropertyNames(true));
}
else {
simpleNames.add(attributeNames[i]);
}
}
return simpleNames;
| public javax.management.AttributeList | getSystemProperties()
_sLogger.log(Level.FINEST, MSG_BASE_GET_PROPERTIES);
ConfigBean baseBean = getBaseConfigBean();
Class cl = baseBean.getClass();
SystemProperty[] props = null;
try {
Method method = cl.getDeclaredMethod("getSystemProperty");
props = (SystemProperty[])method.invoke(baseBean);
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "getattribute.undefined_properties_in_base_element" );
}
if(props==null) {
return new AttributeList();
}
AttributeList list = new AttributeList();
for(int i=0; i<props.length; i++)
{
list.add(new Attribute(props[i].getName(), props[i].getValue()));
}
return list;
| public java.lang.Object | getSystemPropertyValue(java.lang.String propertyName)Gets MBean's system property value.
_sLogger.log(Level.FINEST, MSG_BASE_GET_PROPERTY, propertyName);
ConfigBean baseBean = getBaseConfigBean();
Class cl = baseBean.getClass();
SystemProperty prop = null;
try {
Method method = cl.getDeclaredMethod("getSystemPropertyByName", new Class[]{Class.forName("java.lang.String")});
prop = (SystemProperty)method.invoke(baseBean, new Object[]{propertyName});
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "getattribute.undefined_properties_in_base_element");
}
if(prop==null) {
wrapAndThrowMBeanException(null, "getattribute_properties_not_found_in_base_element", propertyName );
}
return prop.getValue();
| public java.lang.Object | invoke(java.lang.String methodName, java.lang.Object[] methodParams, java.lang.String[] methodSignature)Every resource MBean should override this method to execute specific
operations on the MBean.
return null;
| public java.lang.Object | invokeOperation(javax.management.modelmbean.ModelMBeanOperationInfo opInfo, java.lang.Object[] params, java.lang.String[] signature)
Descriptor descr = opInfo.getDescriptor();
String opName = opInfo.getName();
String child = (String)descr.getFieldValue(MBeanMetaConstants.CHILD_FIELD_NAME);
String multi = (String)descr.getFieldValue(MBeanMetaConstants.MULTI_FIELD_NAME);
boolean bOnlyOne = true;
if(multi!=null && multi.length()>0 &&
multi.charAt(0)=='t")
bOnlyOne = false;
if(child!=null && opName.startsWith("create"))
{
ConfigBean bean = createChildByType(child, (AttributeList)params[0], null, bOnlyOne);
ObjectName objectName = ConfigMBeanHelper.getChildObjectName(m_registry, (ModelMBeanInfo)m_mbeanInfo, bean);
m_registry.notifyRegisterMBean(objectName, getConfigContext());
return objectName;
}
if(child!=null && opName.startsWith("remove"))
{
removeChild(opName, opInfo, params, child);
return null;
}
//Generic Config invoker
Object ret = MBeanHelper.invokeOperationInBean(opInfo, this, params);
if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
{
return ret;
}
boolean bNamesListOp = false;
String modifiedOpName = opName;
if(!bOnlyOne && child!=null &&
opName.startsWith("get") &&
opName.endsWith(MBeanMetaConstants.GET_LISTNAMES_OP_SUFFIX))
{
bNamesListOp = true;
modifiedOpName = opName.substring(0, opName.length()-
MBeanMetaConstants.GET_LISTNAMES_OP_SUFFIX.length());
}
ret = MBeanHelper.invokeOperationInBean(modifiedOpName, opInfo,
this.getBaseConfigBean(), params);
if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
{
if(ret==null && "javax.management.ObjectName".equals(opInfo.getReturnType()))
{
String parentName = "";
parentName = this.getBaseConfigBean().getClass().getName();
int last = parentName.lastIndexOf('.");
if(last>=0 && last<(parentName.length()-1))
parentName = parentName.substring(last+1);
String elemName = "";
if(params!=null && params.length==1 && params[0] instanceof String)
elemName = (String)params[0];
String msg;
if(child!=null)
msg = localStrings.getString( "admin.server.core.mbean.config.element_not_found", new Object[]{parentName, child, elemName});
else
msg = localStrings.getString( "admin.server.core.mbean.config.oper_element_not_found", new Object[]{parentName, modifiedOpName, elemName});
throw new MBeanConfigInstanceNotFoundException(msg);
}
if(ret!=null)
{
if(bNamesListOp && (ret instanceof ConfigBean[]))
{
return (Object)ConfigMBeanHelper.getChildNamesList(
(ConfigBean[])ret);
}
else
{
ret = ConfigMBeanHelper.converConfigBeansToObjectNames(m_registry,
(ModelMBeanInfo)m_mbeanInfo, ret);
if(ret instanceof ConfigBean)
return (Object)ConfigMBeanHelper.getChildObjectName(m_registry,
(ModelMBeanInfo)m_mbeanInfo, (ConfigBean)ret);
if(ret instanceof ConfigBean[])
return (Object)ConfigMBeanHelper.getChildObjectNames(m_registry,
(ModelMBeanInfo)m_mbeanInfo, (ConfigBean[])ret);
}
}
return ret;
}
return MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT;
| private static boolean | isEmptyValueAllowed(javax.management.MBeanAttributeInfo ai)
if(ai!=null && (ai instanceof ModelMBeanAttributeInfo))
{
try {
Descriptor descr = ((ModelMBeanAttributeInfo)ai).getDescriptor();
String strAllowed = (String)descr.getFieldValue(MBeanMetaConstants.EMPTYVALUEALLOWED_FIELD_NAME);
if(Boolean.valueOf(strAllowed).booleanValue())
return true;
} catch(Exception e)
{
}
}
return false;
| void | removeChild(java.lang.String opName, javax.management.MBeanOperationInfo opInfo, java.lang.Object[] params, java.lang.String childTag)
MBeanOperationInfo getInfo = new MBeanOperationInfo("get"+opName.substring("remove".length()),
"",
opInfo.getSignature(),
"java.lang.Object",
MBeanOperationInfo.INFO);
Object ret = MBeanHelper.invokeOperationInBean(getInfo, this.getBaseConfigBean(), params);
if(ret==null)
{
String parentName = "";
parentName = this.getBaseConfigBean().getClass().getName();
int last = parentName.lastIndexOf('.");
if(last>=0 && last<(parentName.length()-1))
parentName = parentName.substring(last+1);
String elemName = "";
if(params!=null && params.length==1 && params[0] instanceof String)
elemName = "\""+(String)params[0]+"\"";
wrapAndThrowMBeanException(null, "element_not_found", new Object[]{parentName, childTag, elemName});
}
if(ret==MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
{
String elemName = "";
if(params.length==1 && params[0] instanceof String)
elemName = (String)params[0];
wrapAndThrowMBeanException(null, "remove_get_invocation",
new Object[]{opName, elemName} );
}
ArrayList arr = new ArrayList();
collectChildrenObjectNames((ConfigBean)ret, arr);
//remove bean
m_baseConfigBean.removeChild((ConfigBean)ret);
//now is time for unregister
MBeanServer server = null;
try {
server = (MBeanServer)(MBeanServerFactory.findMBeanServer(null)).get(0);
} catch(Exception e) {}; //try-catch for AdminTest only
for(int i=0; i<arr.size(); i++)
{
ObjectName objectName = (ObjectName)arr.get(i);
try
{
if(server.isRegistered(objectName))
server.unregisterMBean(objectName);
else
//just to unregister dotted name
m_registry.notifyUnregisterMBean(objectName, getConfigContext());
}
catch (Throwable t)
{
_sLogger.fine("!!!!!!!!!!!!!! Can not unregister MBean: "+objectName);
}
}
| public void | setAttribute(javax.management.modelmbean.ModelMBeanAttributeInfo attrInfo, javax.management.Attribute attr)Sets MBean's attribute value.
String externalName = attr.getName();
Object value = attr.getValue();
_sLogger.log(Level.FINEST, MSG_BASE_SET_ATTRIBUTE, new Object[]{externalName, value});
MBeanAttributeInfo ai = getAttrInfo(externalName);
boolean isProperty = externalName.startsWith(PROPERTY_NAME_PREFIX);
boolean isSystemProperty = externalName.startsWith(SYSTEM_PROPERTY_NAME_PREFIX);
if(ai==null && !isProperty && !isSystemProperty) {
String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_undefined_attribute", externalName );
throw new AttributeNotFoundException( msg );
}
if(ai!=null && !ai.isWritable()) {
wrapAndThrowMBeanException(null, "setattribute_attribute_not_writable", externalName );
}
// try {
if(isProperty)
{
boolean bAllowsEmptyValue = isEmptyValueAllowed(ai);
// set property value
setElementProperty(new Attribute(externalName.substring(PROPERTY_NAME_PREFIX.length()), value), bAllowsEmptyValue);
return;
}
else if(isSystemProperty)
{
boolean bAllowsEmptyValue = isEmptyValueAllowed(ai);
// set system property value
setSystemProperty(new Attribute(externalName.substring(SYSTEM_PROPERTY_NAME_PREFIX.length()), value), bAllowsEmptyValue);
return;
}
else
{ //normal attribute
// check type (now only for exception)
// left check for Verifyer now (bug #4725686)
// MBeanEasyConfig.convertStringValueToProperType(value.toString(), ai.getType());
AttrDescriptor descr = getDescriptor(externalName);
ConfigBean bean = getConfigBean(externalName);
if(descr.isElement())
{
//it looks that now we have no Elements with values
//bean.set???Value(descr.getAttributeName(), value.toString());
wrapAndThrowMBeanException(null, "not_supported_attribute_type", externalName );
// descr.getNode().setContent(value.toString());
// m_configContext.flush();
}
else
{
if(ai.getType().startsWith("[")) //array
{
bean.setValue(ConfigBean.camelize(descr.getAttributeName()), (Object[])value);
/* Class cl = bean.getClass();
try
{
Method method = cl.getMethod("setValue", new Class[]{Class.forName("java.lang.String"),(new Object[0]).getClass()});
method.invoke(bean, new Object[]{ConfigBean.camelize(descr.getAttributeName()),value});
}
catch (Exception e)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_invocation_error", externalName );
throw MBeanHelper.extractAndWrapTargetException(e, msg);
}
*/
}
else
{
//descr.getNode().setAttribute(descr.getAttributeName(), value.toString());
if(value==null || (value.equals("") && !isEmptyValueAllowed(ai)) )
bean.setAttributeValue(descr.getAttributeName(), null);
else
bean.setAttributeValue(descr.getAttributeName(), value.toString());
// m_configContext.flush();
}
}
}
// }
// catch (MBeanConfigException mce)
// {
// String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_attribute_exception", externalName, mce.getMessage() );
// throw new MBeanException(new MBeanConfigException( msg ));
// }
// catch (ConfigException e) {
// String msg = localStrings.getString( "admin.server.core.mbean.config.setAttribute_exception_for_externalname_basexpath", externalName, /*m_BasePath,*/ e.getMessage() );
// throw new MBeanException(new MBeanConfigException( msg ));
// }
| public javax.management.AttributeList | setAttributes(javax.management.AttributeList attrList)Sets the values of several MBean's attributes.
AttributeList attrs = new AttributeList();
AttributeList deferredAttrs = new AttributeList();
Iterator it = attrList.iterator();
while (it.hasNext()) {
Attribute attribute = (Attribute) it.next();
attribute = new Attribute(MBeanMetaHelper.mapToMBeanAttributeName(attribute.getName()), attribute.getValue());
try {
setAttribute(null, attribute); //FIXME: attrInfos?
attrs.add(attribute);
} catch (MBeanException mbe) {
} //ignored according to JMX spec
catch (AttributeNotFoundException anfe) {
} //ignored according to JMX spec
catch (NullPointerException npe) {
} //ignored according to JMX spec (comes from s2b)
catch (AdminValidationException ave) {
if(it.hasNext()) //if last - reordering will not help
{
//possibly attributes ordering problem
//let's try this attribute later
deferredAttrs.add(attribute);
} else {
throw ave;
}
}
}
//now let's try deferred attributes
while(deferredAttrs.size()>0) {
AttributeList newDeferredAttrs = new AttributeList();
it = deferredAttrs.iterator();
while (it.hasNext()) {
Attribute attribute = (Attribute) it.next();
try {
setAttribute(null, attribute); //FIXME: attrInfos?
attrs.add(attribute);
} catch (MBeanException mbe) {
} //ignored according to JMX spec
catch (AttributeNotFoundException anfe) {
} //ignored according to JMX spec
catch (AdminValidationException ave) {
if(it.hasNext()) //if last - reordering will not help
{
//possibly attributes ordering problem
//let's try this attribute later
newDeferredAttrs.add(attribute);
} else {
throw ave;
}
}
}
deferredAttrs = newDeferredAttrs;
newDeferredAttrs = null;
}
return attrs;
| private void | setElementProperty(javax.management.Attribute attr, boolean bAllowsEmptyValue)
String propertyName = attr.getName();
String value = (String)attr.getValue();
_sLogger.log(Level.FINEST, MSG_BASE_SET_PROPERTY, new Object[]{propertyName, value});
ConfigBean baseBean = getBaseConfigBean();
Class cl = baseBean.getClass();
ElementProperty prop = null;
try {
Method method = cl.getDeclaredMethod("getElementPropertyByName", new Class[]{Class.forName("java.lang.String")});
prop = (ElementProperty)method.invoke(baseBean, new Object[]{propertyName});
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "setattribute_undefined_properties_in_base_element", propertyName );
}
if(prop==null && value!=null && (bAllowsEmptyValue || !value.equals(""))) {
prop = new ElementProperty();
prop.setName(propertyName);
if(ConfigMBeanHelper.PROPERTY_SPECIAL_EMPTY_VALUE.equals(value))
prop.setValue("");
else
prop.setValue(value);
try {
Method method = cl.getDeclaredMethod("addElementProperty", new Class[]{prop.getClass()});
method.invoke(baseBean, new Object[]{prop});
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "setproperty_invoke_error", propertyName );
}
}
else {
if(value==null || (!bAllowsEmptyValue && value.equals(""))) {
try {
Method method = cl.getDeclaredMethod("removeElementProperty", new Class[]{prop.getClass()});
method.invoke(baseBean, new Object[]{prop});
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "setproperty_could_not_remove_propery", propertyName );
}
}
else
{
if(ConfigMBeanHelper.PROPERTY_SPECIAL_EMPTY_VALUE.equals(value))
prop.setValue("");
else
prop.setValue(value);
}
}
| public void | setProperty(javax.management.Attribute attr)Sets MBean's property value.
setElementProperty(attr, false);
| public void | setSystemProperty(javax.management.Attribute attr)Sets MBean's system property value.
setSystemProperty(attr, false);
| private void | setSystemProperty(javax.management.Attribute attr, boolean bAllowsEmptyValue)
String propertyName = attr.getName();
String value = (String)attr.getValue();
_sLogger.log(Level.FINEST, MSG_BASE_SET_PROPERTY, new Object[]{propertyName, value});
ConfigBean baseBean = getBaseConfigBean();
Class cl = baseBean.getClass();
SystemProperty prop=null;
try {
Method method = cl.getDeclaredMethod("getSystemPropertyByName", new Class[]{Class.forName("java.lang.String")});
prop = (SystemProperty)method.invoke(baseBean, new Object[]{propertyName});
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "setattribute_undefined_properties_in_base_element", propertyName );
}
if(prop==null && value!=null && (bAllowsEmptyValue || !value.equals(""))) {
prop = new SystemProperty();
prop.setName(propertyName);
if(ConfigMBeanHelper.PROPERTY_SPECIAL_EMPTY_VALUE.equals(value))
prop.setValue("");
else
prop.setValue(value);
try {
Method method = cl.getDeclaredMethod("addSystemProperty", new Class[]{prop.getClass()});
method.invoke(baseBean, new Object[]{prop});
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "setproperty_invoke_error", propertyName );
}
}
else {
if(value==null || (!bAllowsEmptyValue && value.equals(""))) {
try {
Method method = cl.getDeclaredMethod("removeSystemProperty", new Class[]{prop.getClass()});
method.invoke(baseBean, new Object[]{prop});
}
catch (Exception e) {
wrapAndThrowMBeanException(e, "setproperty_could_not_remove_propery", propertyName );
}
}
else
{
if(ConfigMBeanHelper.PROPERTY_SPECIAL_EMPTY_VALUE.equals(value))
prop.setValue("");
else
prop.setValue(value);
}
}
/*
try {
m_configContext.flush();
}
catch (ConfigException e) {
throw new MBeanException(new MBeanConfigException(e.getMessage()));
}
*/
| private void | uncatchValidationException(java.lang.Exception e)
if(e instanceof AdminValidationException)
throw (AdminValidationException)e;
if(e instanceof InvocationTargetException)
{
Throwable t = ((InvocationTargetException)e).getTargetException();
if(t instanceof AdminValidationException)
throw (AdminValidationException)t;
}
| private void | wrapAndThrowMBeanException(java.lang.Exception e, java.lang.String strSuffix)
wrapAndThrowMBeanException(e, strSuffix, null);
| private void | wrapAndThrowMBeanException(java.lang.Exception e, java.lang.String strSuffix, java.lang.Object val)
if(e!=null)
uncatchValidationException(e);
String msg;
if(val instanceof Object[])
msg = localStrings.getString( "admin.server.core.mbean.config."+strSuffix, (Object[])val );
else
msg = localStrings.getString( "admin.server.core.mbean.config."+strSuffix, val );
throw new MBeanException(new MBeanConfigException( msg ));
|
|