Sitemap

Sunday, April 5, 2015

UCM: Component to reinitialize UCM components without restarting UCM

Created a helper component to reload the component's glue file, the query file, resource files, and template definition files, so that there is no need of restarting the UCM server while developing the components in development environment.

This component MUST NOT be deployed to customer's instance, and MUST NOT be included in the installation package.

public class UcmHelperService
  extends Service
{
  public static final String STATUS_CODE = "StatusCode";
  public static final String STATUS_MESSAGE = "StatusMessage";
  public static final String STATUS_SUCCESS = "0";
  public static final String STATUS_ERROR = "-1";
  protected static ComponentPackager m_componentPackager;
  
  public void reinitComponents()
  {
    try
    {
      String componentName = this.m_binder.getActiveAllowMissing("ComponentName");
      ComponentLoader.reset();
      ComponentLoader.initDefaults();
      
      ComponentLoader.load();
      IdcSystemLoader.loadComponentData();
      IdcSystemLoader.loadResources();
      if ((null != componentName) && (componentName.trim().length() > 0)) {
        reinitServices(componentName);
      } else {
        IdcSystemLoader.loadServiceData();
      }
      reinitQueries(componentName);
      this.m_binder.putLocal("StatusCode", "0");
    }
    catch (Exception e)
    {
      this.m_binder.putLocal("StatusCode", "-1");
      this.m_binder.putLocal("StatusMessage", e.getLocalizedMessage());
    }
  }
  
  protected static void trace(String message)
  {
    Report.trace("UcmHelperService", message, null);
  }
  
  protected static void traceBinder(DataBinder dataBinder)
  {
    if (dataBinder.getLocalData().isEmpty())
    {
      trace("binder.getLocalData is empty");
    }
    else
    {
      trace("(Sniffer) binder.getLocalData output");
      Iterator it = dataBinder.getLocalData().keySet().iterator();
      while (it.hasNext())
      {
        String key = it.next().toString();
        trace(key + " = " + dataBinder.getLocal(key));
      }
    }
  }
  
  private void reinitServices(String componentName)
    throws ServiceException, DataException
  {
    ServiceManager serviceManager = new ServiceManager();
    ResourceTrace.msg("!csComponentLoadServices");
    ResourceContainer resourcecontainer = new ResourceContainer();
    Vector vector = ComponentLoader.m_services;
    int i = vector.size();
    for (int j = 0; j < i; j++)
    {
      ComponentData componentdata = (ComponentData)vector.elementAt(j);
      if (componentdata.m_componentName.equalsIgnoreCase(componentName)) {
        reinitService(serviceManager, resourcecontainer, componentdata);
      }
    }
  }
  
  private void reinitService(ServiceManager serviceManager, ResourceContainer resourceContainer, ComponentData componentData)
    throws DataException, ServiceException
  {
    String s = componentData.m_file;
    String s1 = "!csComponentLoadSystemServices";
    if (!componentData.m_componentName.equalsIgnoreCase("default")) {
      s1 = LocaleUtils.encodeMessage("csComponentLoadName", null, componentData.m_componentName);
    }
    ResourceTrace.msg(s1);
    ResourceLoader.loadResourceFile(resourceContainer, s);
    Vector vector1 = componentData.m_tables;
    int k = vector1.size();
    for (int l = 0; l < k; l++) {
      serviceManager.addTable(resourceContainer, (String)vector1.elementAt(l), componentData);
    }
  }
  
  private void reinitQueries(String componentName)
    throws DataException, ServiceException
  {
    ResourceContainer resourcecontainer = new ResourceContainer();
    ResourceTrace.msg("!csComponentLoadQueries");
    Vector vector = ComponentLoader.m_queries;
    int j = vector.size();
    for (int k = 0; k < j; k++)
    {
      ComponentData componentdata = (ComponentData)vector.elementAt(k);
      String s9 = componentdata.m_file;
      boolean flag3 = true;
      String s10 = "!csComponentLoadSystemQuery";
      if (!componentdata.m_componentName.equalsIgnoreCase("default")) {
        s10 = LocaleUtils.encodeMessage("csComponentLoadName", null, componentdata.m_componentName);
      }
      if ((componentName == null) || (componentName.trim().equalsIgnoreCase(componentdata.m_componentName)))
      {
        ResourceTrace.msg(s10);
        DataLoader.cacheResourceFile(resourcecontainer, s9);
        Vector vector1 = componentdata.m_tables;
        int l = vector1.size();
        for (int i1 = 0; i1 < l; i1++) {
          QueryUtils.addQueryTable(this.m_workspace, resourcecontainer, (String)vector1.elementAt(i1), flag3, componentdata.m_componentName);
        }
      }
    }
  }

No comments:

Post a Comment