Methods Summary |
---|
static java.lang.Object[] | MergeAttributesWithAnotherMbean(java.lang.String[][] maplist1, java.lang.String[] attributes1, java.lang.String[][] maplist2, java.lang.String[] attributes2, java.lang.String relativeXPath2, java.lang.String attrNamesPrefix2)This method allows to append another bean attributes (usually child ones) to base attributes;
so for MBean user they all will be as base
int size = 0;
if(maplist1!=null)
size += maplist1.length;
if(maplist2!=null)
size += maplist2.length;
String[][] new_maplist = new String[size][];
String[] new_attributes = new String[size];
String[] mapelem;
int i = 0;
if(maplist1!=null)
for(i=0; i<maplist1.length; i++)
{
new_maplist[i] = (String[])maplist1[i].clone();
new_attributes[i] = attributes1[i];
}
if(maplist2!=null)
for(int j=0; j<maplist2.length; j++)
{
mapelem = (String[])maplist2[j].clone();
new_attributes[i+j] = attributes2[j];
if(attrNamesPrefix2!=null)
{
mapelem[0] = attrNamesPrefix2 + mapelem[0];
new_attributes[i+j] = attrNamesPrefix2 + attributes2[j].trim();
}
mapelem[1] = relativeXPath2 + "/" + mapelem[1];
new_maplist[i+j] = mapelem;
}
return new Object[]{new_maplist, new_attributes};
|
public static java.lang.String | convertName(java.lang.String name)Convert a DTD name into a bean name:
Any - or _ character is removed. The letter following - and _
is changed to be upper-case.
If the user mixes upper-case and lower-case, the case is not
changed.
If the Word is entirely in upper-case, the word is changed to
lower-case (except the characters following - and _)
The first letter is always upper-case.
CharacterIterator ci;
StringBuffer n = new StringBuffer();
boolean up = true;
boolean keepCase = false;
char c;
ci = new StringCharacterIterator(name);
c = ci.first();
// If everything is uppercase, we'll lowercase the name.
while (c != CharacterIterator.DONE)
{
if (Character.isLowerCase(c))
{
keepCase = true;
break;
}
c = ci.next();
}
c = ci.first();
while (c != CharacterIterator.DONE)
{
if (c == '-" || c == '_")
up = true;
else
{
if (up)
c = Character.toUpperCase(c);
else
if (!keepCase)
c = Character.toLowerCase(c);
n.append(c);
up = false;
}
c = ci.next();
}
return n.toString();
|
private java.util.Hashtable | createAttrsDescriptors(java.lang.String[][] attrs)
Hashtable ht = new Hashtable();
if (attrs != null)
{
for(int i=0; i<attrs.length; i++)
{
ht.put(attrs[i][0],
new AttrDescriptor(attrs[i][1]));
}
}
return ht;
|
public com.sun.enterprise.admin.AdminContext | getAdminContext()
return m_AdminContext;
|
private java.lang.String[] | getAllAttributeNames()
if(m_Attrs==null )
return null;
Enumeration keys = m_Attrs.keys();
ArrayList list = new ArrayList();
while(keys.hasMoreElements())
{
list.add(keys.nextElement());
}
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", (Class[])null);
props = (ElementProperty[])method.invoke(baseBean, (Object[])null);
String[] names = new String[props.length];
for(int i=0; i<props.length; i++)
{
if(bAddPropertyPrefix)
names[i] = ConfigAttributeName.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(attrName==null || 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;
|
public java.lang.Object | getAttribute(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(ConfigAttributeName.PROPERTY_NAME_PREFIX);
if(ai==null && !isProperty)
{
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 getPropertyElementValue(externalName.substring(ConfigAttributeName.PROPERTY_NAME_PREFIX.length()));
}
else
{
AttrDescriptor descr = getDescriptor(externalName);
ConfigBean bean = getConfigBean(externalName);
String value = null;
if(descr.isElement())
{
//it looks that now we have no Elements with values
//value = descr.getNode().getContent();
String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_not_implemented_for_xml" );
throw new MBeanException(new MBeanConfigException( msg ));
}
else
{
value = bean.getRawAttributeValue(descr.getAttributeName());
//value = descr.getNode().getRawAttributeValue(descr.getAttributeName());
}
sLogger.log(Level.FINEST, MSG_BASE_GOT_ATTRIBUTE, new Object[]{externalName,value, MBeanEasyConfig.convertStringValueToProperType(value, ai.getType())});
return MBeanEasyConfig.convertStringValueToProperType(value, ai.getType());
}
}
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.AttributeList | getAttributes(java.lang.String[] attributeNames)Gets MBean's attribute values.
AttributeList attrs = new AttributeList();
for(int i=0; i<attributeNames.length; i++)
{
// try
{
if(attributeNames[i].length()==0)
{
String[] names = getAllAttributeNames();
if(names!=null)
attrs.addAll(getAttributes(names));
}
else
{
if(attributeNames[i].equals(ConfigAttributeName.PROPERTY_NAME_PREFIX))
{
String[] names = getAllPropertyNames(true);
if(names!=null)
attrs.addAll(getAttributes(names));
}
else
{
try
{
Object value = getAttribute(attributeNames[i]);
attrs.add(new Attribute(attributeNames[i], 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 (Throwable t)
// {
// }
}
return attrs;
|
public com.sun.enterprise.config.ConfigBean | getBaseConfigBean()Get base node Config Bean;
try
{
return getConfigBeanByXPath(m_BasePath);
}
catch (Exception e)
{
return null;
}
|
public java.lang.String | getBasePath()Get path to base node; all attributes pathes are defined relatively this node.
return m_BasePath;
|
public com.sun.enterprise.config.ConfigBean | getConfigBean(java.lang.String externalName)Get ConfigBean object which contains correspondent attribute.
//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.ConfigBean | getConfigBeanByXPath(java.lang.String xPath)Get ConfigBean object which binded to ConfigNode with given XPath.
sLogger.log(Level.FINEST, MSG_GET_CONFBEANBYXPATH, xPath);
return ConfigBeansFactory.getConfigBeanByXPath(m_configContext, xPath);
|
private static java.lang.Class | getConfigBeanClass(java.lang.String xPath)
// get ConfigBean classname from XPath
String beanName = ConfigBeansFactory.getConfigBeanNameByXPath(xPath);
//getting the class object
try
{
Class cl = Class.forName("com.sun.enterprise.config.serverbeans."+beanName);
return cl;
}
catch(Exception e)
{
return null;
}
|
public com.sun.enterprise.config.ConfigContext | getConfigContext()
return m_configContext;
|
public com.sun.enterprise.admin.server.core.mbean.config.naming.ConfigMBeanNamingInfo | getConfigMBeanNamingInfo()
return m_MBeanNamingInfo;
|
public java.lang.Object | 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 MBeanEasyConfig.convertStringValueToProperType(value, ai.getType());
}
/* 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.server.core.mbean.config.ConfigMBeanBase$AttrDescriptor | getDescriptor(java.lang.String externalName)
return (AttrDescriptor)m_Attrs.get(externalName);
|
protected java.lang.Class | getImplementingClass()Abstract method that subclasses have to implement. This is the way for
invoke method to work, through reflection.
return ( this.getClass() );
|
protected java.lang.Object | getImplementingMBean()Reflection requires the implementing object.
return ( this );
|
public javax.management.MBeanInfo | getMBeanInfo()Get MBeanInfo MBean description object (required dynamic MBean method).
return m_MBeanInfo;
|
public java.lang.Object | getPropertyElementValue(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;
try
{
Method method = cl.getDeclaredMethod("getElementPropertyByName", new Class[]{Class.forName("java.lang.String")});
prop = (ElementProperty)method.invoke(baseBean, new Object[]{propertyName});
}
catch (Exception e)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute.undefined_properties_in_base_element", propertyName );
throw new MBeanException(new MBeanConfigException( msg ));
}
if(prop==null) {
String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_properties_not_found_in_base_element", propertyName );
throw new MBeanException(new MBeanConfigException( msg ));
}
return prop.getValue();
|
public java.lang.String | getServerInstanceName()
return m_ServerInstanceName;
|
public void | initialize(com.sun.enterprise.admin.server.core.mbean.config.naming.ConfigMBeanNamingInfo namingInfo)Binds MBean with Config Bean
String instanceName = namingInfo.getServerInstanceName();
ConfigContext configContext;
if (m_AdminContext != null) {
configContext = m_AdminContext.getAdminConfigContext();
} else {
try
{
InstanceEnvironment instanceEnvironment = new InstanceEnvironment(instanceName);
//String fileUrl = instanceEnvironment.getConfigFilePath();
/*Everything should be set in the backup file*/
String fileUrl = instanceEnvironment.getConfigFilePath();
configContext = ConfigFactory.createConfigContext(fileUrl);
}
catch(ConfigException e)
{
//e.printStackTrace();
String msg = localStrings.getString( "admin.server.core.mbean.config.error_locating_server_node", e.getMessage() );
throw new MBeanConfigException( msg );
}
}
sLogger.log(Level.FINEST, MSG_LOG_CONF_CTX, new Object[] {
this.getClass().getName(), new Long(configContext.hashCode())});
m_ServerInstanceName = instanceName;
m_configContext = configContext;
m_MBeanNamingInfo = namingInfo;
m_BasePath = namingInfo.getXPath();
|
public void | initialize(java.lang.String mbeanType, java.lang.String[] locations)
ConfigMBeanNamingInfo namingInfo;
try
{
namingInfo = new ConfigMBeanNamingInfo(mbeanType, locations);
}
catch (MBeanConfigException mce)
{
throw mce;
}
catch (Exception e)
{
throw new MBeanConfigException(e.getMessage());
}
initialize(namingInfo);
|
public void | initialize(java.lang.String dottedName)
ConfigMBeanNamingInfo namingInfo;
try
{
namingInfo = new ConfigMBeanNamingInfo(dottedName);
}
catch (MBeanConfigException mce)
{
throw mce;
}
catch (Exception e)
{
throw new MBeanConfigException(e.getMessage());
}
initialize(namingInfo);
|
public void | initialize(javax.management.ObjectName objectName)
ConfigMBeanNamingInfo namingInfo;
try
{
namingInfo = new ConfigMBeanNamingInfo(objectName);
}
catch (MBeanConfigException mce)
{
throw mce;
}
catch (Exception e)
{
throw new MBeanConfigException(e.getMessage());
}
initialize(namingInfo);
|
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;
/*
* New for 8.0
*/
return ( super.invoke(methodName, methodParams, methodSignature) );
|
public void | setAdminContext(com.sun.enterprise.admin.AdminContext adminContext)
m_AdminContext = adminContext;
|
public void | setAttribute(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(ConfigAttributeName.PROPERTY_NAME_PREFIX);
if(ai==null && !isProperty)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_undefined_attribute", externalName );
throw new AttributeNotFoundException( msg );
}
if(ai!=null && !ai.isWritable())
{
String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_attribute_not_writable", externalName );
throw new MBeanException(new MBeanConfigException( msg ));
}
try
{
if(isProperty)
{
boolean bAllowsEmptyValue = true;
if(ai!=null)
{
AttrDescriptor descr = getDescriptor(externalName);
if(descr!=null)
{
bAllowsEmptyValue = descr.isEmptyValueAllowed();
}
}
// set property value
setPropertyElementValue(new Attribute(externalName.substring(ConfigAttributeName.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());
String msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_not_implemented_for_xml" );
throw new MBeanException(new MBeanConfigException( msg ));
// descr.getNode().setContent(value.toString());
// m_configContext.flush();
}
else
{
//descr.getNode().setAttribute(descr.getAttributeName(), value.toString());
if(value==null || (value.equals("") && !descr.isEmptyValueAllowed()) )
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();
Iterator it = attrList.iterator();
while (it.hasNext())
{
try
{
Attribute attribute = (Attribute) it.next();
setAttribute(attribute);
attrs.add(attribute);
}
catch (MBeanException mbe)
{
}
catch (AttributeNotFoundException anfe)
{
}
catch (NullPointerException npe)
{
}
}
return attrs;
|
public void | setDescriptions(java.lang.String[][] attrsMapList, java.lang.String[] attrDescriptions, java.lang.String[] operDescriptions)Sets Config MBean description data (this method usually is calling from the child class constructor)
m_Attrs = createAttrsDescriptors(attrsMapList);
MBeanEasyConfig easyConfig = new MBeanEasyConfig(getClass(), attrDescriptions, operDescriptions, null);
m_MBeanInfo = easyConfig.getMBeanInfo();
|
public void | setPropertyElementValue(javax.management.Attribute attr, boolean bAllowsEmptyValue)Sets MBean's property value.
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;
try
{
Method method = cl.getDeclaredMethod("getElementPropertyByName", new Class[]{Class.forName("java.lang.String")});
prop = (ElementProperty)method.invoke(baseBean, new Object[]{propertyName});
}
catch (Exception e)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_undefined_properties_in_base_element", propertyName );
throw new MBeanException(new MBeanConfigException( msg ));
}
if(prop==null && value!=null && (bAllowsEmptyValue || !value.equals("")))
{
prop = new ElementProperty();
prop.setName(propertyName);
prop.setValue(value);
try
{
Method method = cl.getDeclaredMethod("addElementProperty", new Class[]{prop.getClass()});
method.invoke(baseBean, new Object[]{prop});
}
catch (Exception e)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.setproperty_invoke_error", propertyName );
throw new MBeanException(new MBeanConfigException( msg ));
}
}
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)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.setproperty_could_not_remove_propery", propertyName );
throw new MBeanException(new MBeanConfigException( msg ));
}
}
else
prop.setValue(value);
}
try
{
m_configContext.flush();
}
catch (ConfigException e)
{
throw new MBeanException(new MBeanConfigException(e.getMessage()));
}
|