Advanced Customization > Services and Infrastructure Customization > System Configuration Collector Plugin > Creating a System Configuration Collector Plugin > Procedures – Creating a Custom Plugin > Implementing the Plugin
  
Implementing the Plugin
Implementation of a plugin is code that will do the actual work for the plugin. The main steps are to ensure a plugin is correctly initialized (see the design step above) and adheres to the required interface. The final step is providing the necessary method implementations for the plugin to carry out its work.
1. Plugin initialization:
During plugin construction, the object should initialize its MBean attributes (again, all plugins are MBeans). Using the example from the design phase we can expand on the constructor method:
public CustomPlugin() throws NotCompliantMBeanException {
super(null);
// super(PluginMBean.class);
initializeMBeanAttributes();
}

private void initializeMBeanAttributes() {
if (logger.isDebugEnabled()) {
logger.debug("Initializing " + CUSTOM_PLUGIN_NAME + " Plugin.");
}

// set the plugin display name
setDisplayName(CUSTOM_PLUGIN_NAME);
// set the plugin description
setDescription(CUSTOM_PLUGIN_DESCRIPTION);
// set the plugin MBean name
setMBeanName("TomcatConfigProperties");
// set the plugin enumerated type
setPluginType(PluginType.MISC);
// set the plugin version number
setPluginVersion("1.0");
// set whether the plugin relies on database
// administrator credentials
setDbCredentialsNeeded(false);
// set whether the plugin operates on each
// cluster node
setClusterAware(true);
// set whether the plugin relies on file
// date ranges for data collection
setDateRangeUsed(false);
// set whether the plugin should compress the
// output of its data collection
setCompressOutput(false);
}
Here the constructor has been expanded to include a private method that initializes all the plugin attributes including the MBean values that are exposed.
The value of the setMBeanName parameter should be a properly formed MBean Object Name. To avoid potential MBean loader issues, it is recommend to avoid using spaces in the string name. For complete details regarding MBean Object Name syntax refer toAdditional Resources – Related Websites.
2. Plugin collect(…) methods:
The bulk of the plugin work is contained in the collect(…) methods and the implementation details are left for the plugin developer to implement. See Sample Code for examples.
In advanced plugins the work is generally sufficiently large for the collect(…) methods such that it is reasonable to implement helper Java classes and private helper methods. This will allow the plugin to have more discrete methods for easier maintenance. The implementation of any helper method is solely based on the plugin and the developer’s discretion, and therefore is also specific and left for the particular implementer of the plugin. Refer to Customization Points for greater detail regarding the collect(…) methods.
3. Plugin localization:
As Windchill is a distributed application with the potential to have clients in different locales it is highly recommended that any Java Strings that are externalized in a plugin should be localized.
The strings of note are the plugin name and plugin description. These values are presented to the user in the System Configuration Collector UI.
The com.ptc.customersupport.plugins.* packages contain numerous *Resource.java files that are referenced throughout many of the plugins, and found in the same packages. These *Resource.java files contain public String reference values that are localized and read during MBean plugin initialization.
However, it is not always possible or feasible to localize Java strings. If the values are not localized the values used are those entered and compiled into the class files; in the above cases, English.
Using our example from CustomPlugin we add a new plugin member variable:
private static ResourceBundle RESOURCE =
ResourceBundle.getBundle(
CustomPluginResource.class.getName());
This will be our reference to where our localized Java strings reside. Our CustomPlugin can then make use of this reference to retrieve the localized values. The refactored setDisplayName(string) and setDescription(string) methods become:
// set the localized plugin display name
setDisplayName(MBeanUtilities.formatMessage(
RESOURCE.getString(
CustomPluginResource.CUSTOM_PLUGIN_NAME)));
// set the localized plugin description
setDescription(MBeanUtilities.formatMessage(
RESOURCE.getString(
CustomPluginResource.CUSTOM_PLUGIN_DESC)));
The localized Strings CUSTOM_PLUGIN_NAME and CUSTOM_PLUGIN_DESC are retrieved from the correctly localized class file.
NOTE: The localized plugin Strings are based on the server locale as the localized plugin strings are read from the server during plugin initialization. The localized values will display according to server locale and not the client locale in the System Configuration Collector UI.
For more information on how to properly localize Windchill strings see Internationalization and Localization.