Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[tm-dev] Programatic Creation of Filters/Pools/References

Hi,

I am trying to programmatically create Filter entries on a server, and it seems to work fine, but as soon as I exit Eclipse and re-launch it seems that all of the Filters on that Server are corrupt, with a NPE being thrown in the error log.

Can anyone help explain how to do this and/or what I am doing wrong?

Here is my code:

String hostName = ... // Get host name
String username = ... // Get username

// Create MyProfile

ISystemRegistry systemRegistry = RSECorePlugin.getTheSystemRegistry();

ISystemProfile myProfile = systemRegistry.getSystemProfile("MyProfile");    
if (myProfile == null) {
  myProfile = systemRegistry.createSystemProfile("MyProfile"true);  
}

// Create the host
IHost host = systemRegistry.getHost(myProfile, hostName);
if (host == null) {
  // Create with SSH to add the SFTP subsystem
  host = systemRegistry.createHost(myProfile.getName(), systemRegistry.getSystemTypeById(IRSESystemType.SYSTEMTYPE_SSH_ONLY_ID), hostName, hostName, "MyProfile Description");
  host.setDefaultUserId(username);
}

for (ISubSystem subSystem : host.getSubSystems()) {
  // Want the SFTP subsystem
  if (subSystem.getName().equals("Sftp Files")) {
    ISubSystemConfiguration config = subSystem.getSubSystemConfiguration();
    // Get the Pool Manager for my profile type
    ISystemFilterPoolManager poolManager = config.getFilterPoolManager(myProfile);
    // Create the new filter Pool for my new filter (returns null if it already exists)
    ISystemFilterPool pool = poolManager.createSystemFilterPool(server.getName()+":ssh.files"true);
    if (pool != null) {
      // Create my new filter, this is a brand new Pool so don't worry checking if it already exists
      pool.createSystemFilter("MyFilter"new String[] {"/path/of/super/secret/resource/"});
      // Add a reference from the SFTP subsystem to my new pool
      subSystem.getFilterPoolReferenceManager().addReferenceToSystemFilterPool(pool);
    }
  }
}  


And here is the NPE after restarting Eclipse:

java.lang.NullPointerException
  at org.eclipse.rse.internal.ui.view.SystemViewFilterPoolReferenceAdapter.getName(SystemViewFilterPoolReferenceAdapter.java:188)
  at org.eclipse.rse.ui.view.AbstractSystemViewAdapter.testAttribute(AbstractSystemViewAdapter.java:1676)
  at org.eclipse.ui.internal.ActionExpression$ObjectStateExpression.preciselyMatches(ActionExpression.java:530)
  at org.eclipse.ui.internal.ActionExpression$ObjectStateExpression.isEnabledFor(ActionExpression.java:499)
  at org.eclipse.ui.internal.ActionExpression$OrExpression.isEnabledFor(ActionExpression.java:582)
  at org.eclipse.ui.internal.ActionExpression$SingleExpression.isEnabledFor(ActionExpression.java:743)
  at org.eclipse.ui.internal.ActionExpression.isEnabledFor(ActionExpression.java:1053)
  at org.eclipse.ui.internal.decorators.DecoratorDefinition.isEnabledFor(DecoratorDefinition.java:282)

Thanks in advance,
Daniel Johnson

Back to the top