Esempio n. 1
0
CommandParameter::CommandParameter(const QString& id, const QString& name,
                 const SmartPointer<IConfigurationElement>& values,
                 const SmartPointer<ParameterType>& parameterType,
                 const bool optional)
  : name(name)
  , optional(optional)
  , parameterType(parameterType)
  , valuesConfigurationElement(values)
  , id(id)
{
  if (id.isNull())
  {
    throw ctkInvalidArgumentException("Cannot create a parameter with a null id");
  }

  if (name.isNull())
  {
    throw ctkInvalidArgumentException("The name of a parameter cannot be null.");
  }

  if (values.IsNull())
  {
    throw ctkInvalidArgumentException("The values for a parameter cannot be null.");
  }
}
Esempio n. 2
0
 void Preferences::AssertPath_unlocked(const QString& pathName)
 {
   if(pathName.indexOf("//") != -1)
   {
     throw ctkInvalidArgumentException(QString("Illegal // in m_Path m_Name '") + pathName + "'");
   }
   int strLength = pathName.size();
   if(strLength > 1 && pathName[strLength-1] == '/')
   {
     throw ctkInvalidArgumentException(QString("Trailing / in m_Path m_Name '") + pathName + "'");
   }
 }
Esempio n. 3
0
//----------------------------------------------------------------------------
ctkRequirePlugin::ctkRequirePlugin(ctkPluginPrivate* requestor,
                                   const QString& name, const QString& res,
                                   const QString& range)
    : name(name),
      resolution(res.isEmpty() ? ctkPluginConstants::RESOLUTION_MANDATORY : res),
      pluginRange(range.isEmpty() ? ctkVersionRange::defaultVersionRange() : range)
{

    if (resolution != ctkPluginConstants::RESOLUTION_MANDATORY &&
            resolution != ctkPluginConstants::RESOLUTION_OPTIONAL )
    {
        QString what = QString("Invalid directive : '")
                       + ctkPluginConstants::RESOLUTION_DIRECTIVE + ":=" + this->resolution
                       + "' in manifest header '"
                       + ctkPluginConstants::REQUIRE_PLUGIN + ": " + this->name
                       + "' of plugin with id " + requestor->id
                       + " (" + requestor->symbolicName + ")"
                       + ". The value must be either '"
                       + ctkPluginConstants::RESOLUTION_MANDATORY + "' or '"
                       + ctkPluginConstants::RESOLUTION_OPTIONAL  + "'.";
        throw ctkInvalidArgumentException(what);
    }


}
Esempio n. 4
0
void ServiceLocator::RegisterService(const QString& api,
    Object* service) const
{
  if (api.isEmpty())
  {
    throw ctkInvalidArgumentException("The service key cannot be empty");
  }

//  if (!api.isInstance(service))
//  {
//    throw new IllegalArgumentException("The service does not implement the given interface"); //$NON-NLS-1$
//  }

  if (services.find(api) != services.end())
  {
    Object* currentService = services[api];
    services.remove(api);
    if (IDisposable* disposable = dynamic_cast<IDisposable*>(currentService))
    {
      disposable->Dispose();
    }
  }

  if (service)
  {
    services.insert(api, service);
    if (INestable* nestable = dynamic_cast<INestable*>(service))
    {
      if (activated)
      {
        nestable->Activate();
      }
    }
  }
}
Esempio n. 5
0
void Command::AddCommandListener(ICommandListener* commandListener)
{
  if (!commandListener)
  {
    throw ctkInvalidArgumentException("Cannot add a null command listener");
  }
  commandEvents.AddListener(commandListener);
}
Esempio n. 6
0
void Command::AddExecutionListener(IExecutionListener* executionListener)
{
  if (!executionListener)
  {
    throw ctkInvalidArgumentException("Cannot add a null execution listener");
  }
  executionEvents.AddListener(executionListener);
}
 IContributionItem::Pointer Create(IWorkbenchWindow* window) override
 {
   if (window == nullptr)
   {
     throw ctkInvalidArgumentException("window must not be null");
   }
   IContributionItem::Pointer item(new ReopenEditorMenu(window, GetId(), true));
   return item;
 }
 IContributionItem::Pointer Create(IWorkbenchWindow* window) override
 {
   if (window == nullptr)
   {
     throw ctkInvalidArgumentException("window must not be null");
   }
   IContributionItem::Pointer item(new ChangeToPerspectiveMenu(window, GetId()));
   return item;
 }
Esempio n. 9
0
void Command::Define(const QString& name, const QString& description,
                     const CommandCategory::Pointer category,
                     const QList<IParameter::Pointer>& parameters,
                     const ParameterType::Pointer& returnType,
                     const QString& helpContextId)
{
  if (name == "")
  {
    throw ctkInvalidArgumentException("The name of a command cannot be empty");
  }

  if (!category)
  {
    throw ctkInvalidArgumentException("The category of a command cannot be null");
  }

  const bool definedChanged = !this->defined;
  this->defined = true;

  const bool nameChanged = this->name != name;
  this->name = name;

  const bool descriptionChanged = this->description != description;
  this->description = description;

  const bool categoryChanged = this->category != category;
  this->category = category;

  const bool parametersChanged = !CommandUtils::Equals(this->parameters,
                                                       parameters);
  this->parameters = parameters;

  const bool returnTypeChanged = this->returnType != returnType;
  this->returnType = returnType;

  const bool helpContextIdChanged = this->helpContextId != helpContextId;
  this->helpContextId = helpContextId;

  CommandEvent::Pointer event(new CommandEvent(Command::Pointer(this), categoryChanged,
                                               definedChanged, descriptionChanged, false, nameChanged,
                                               parametersChanged, returnTypeChanged, helpContextIdChanged));
  this->FireCommandChanged(event);
}
Esempio n. 10
0
SlaveHandlerService::SlaveHandlerService(IHandlerService* parentHandlerService,
                    const SmartPointer<Expression>& defaultExpression)
  : defaultExpression(defaultExpression)
  , parent(parentHandlerService)
{
  if (parentHandlerService == nullptr)
  {
    throw ctkInvalidArgumentException("The parent handler service cannot be null");
  }
}
Esempio n. 11
0
ctkEAAbstractAdapter::ctkEAAbstractAdapter(ctkEventAdmin* admin)
 : admin_(0)
{
  if (admin == 0)
  {
    throw ctkInvalidArgumentException("EventAdmin must not be null");
  }

  admin_.testAndSetOrdered(0, admin);
}
Esempio n. 12
0
void Command::RemoveCommandListener(ICommandListener *commandListener)
{
  if (!commandListener)
  {
    throw ctkInvalidArgumentException(
          "Cannot remove a null command listener");
  }

  commandEvents.RemoveListener(commandListener);
}
Esempio n. 13
0
void ParameterType::FireParameterTypeChanged(const SmartPointer<
    ParameterTypeEvent> event)
{
  if (!event)
  {
    throw ctkInvalidArgumentException("Cannot send a null event to listeners.");
  }

  parameterTypeEvents.parameterTypeChanged(event);
}
ParameterValueConverterProxy::ParameterValueConverterProxy(
    const SmartPointer<IConfigurationElement>& converterConfigurationElement)
  : converterConfigurationElement(converterConfigurationElement)
{
  if (converterConfigurationElement.IsNull())
  {
    throw ctkInvalidArgumentException(
        "converterConfigurationElement must not be null");
  }
}
void AbstractHandlerWithState::AddState(const QString& stateId, const SmartPointer<State>& state)
{
  if (state.IsNull())
  {
    throw ctkInvalidArgumentException("Cannot add a null state");
  }

  states.insert(stateId, state);
  state->AddListener(this);
  HandleStateChange(state, Object::Pointer(0));
}
Esempio n. 16
0
//----------------------------------------------------------------------------
QObject* ctkPluginContext::getService(const ctkServiceReference& reference)
{
  Q_D(ctkPluginContext);
  d->isPluginContextValid();

  if (!reference)
  {
    throw ctkInvalidArgumentException("Default constructed ctkServiceReference is not a valid input to getService()");
  }
  ctkServiceReference internalRef(reference);
  return internalRef.d_func()->getService(d->plugin->q_func());
}
Esempio n. 17
0
HandlerService::HandlerService(ICommandService* commandService,
                               IEvaluationService* evaluationService,
                               IServiceLocator* locator)
  : commandService(commandService)
  , handlerAuthority(new HandlerAuthority(commandService, locator))
  , handlerPersistence(new HandlerPersistence(this, evaluationService))
{
  if (commandService == nullptr)
  {
    throw ctkInvalidArgumentException("A handler service requires a command service");
  }
}
Esempio n. 18
0
//----------------------------------------------------------------------------
void ctkPluginPrivate::checkManifestHeaders()
{
  symbolicName = archive->getAttribute(ctkPluginConstants::PLUGIN_SYMBOLICNAME);

  if (symbolicName.isEmpty())
  {
    throw ctkInvalidArgumentException(QString("ctkPlugin has no symbolic name, location=") +
                                      location);
  }

  QString mpv = archive->getAttribute(ctkPluginConstants::PLUGIN_VERSION);
  if (!mpv.isEmpty())
  {
    try
    {
      version = ctkVersion(mpv);
    }
    catch (const std::exception& e)
    {
      throw ctkInvalidArgumentException(QString("ctkPlugin does not specify a valid ") +
                                        ctkPluginConstants::PLUGIN_VERSION + " header. Got exception: " + e.what());
    }
  }

  QSharedPointer<ctkPlugin> snp = fwCtx->plugins->getPlugin(symbolicName, version);
  // TBD! Should we allow update to same version?
  if (!snp.isNull() && snp->d_func() != this)
  {
    throw ctkInvalidArgumentException(QString("Plugin with same symbolic name and version is already installed (")
                                      + symbolicName + ", " + version.toString() + ")");
  }

  QString ap = archive->getAttribute(ctkPluginConstants::PLUGIN_ACTIVATIONPOLICY);
  if (ctkPluginConstants::ACTIVATION_EAGER == ap)
  {
    eagerActivation = true;
  }

}
void RegistryObjectReferenceMap::Put(int key, const SmartPointer<RegistryObject>& value)
{
  if (value.IsNull())
    throw ctkInvalidArgumentException("null values not allowed");

  Purge();

  ReferenceMapType::Iterator i = references.find(key);
  if (i != references.end())
  {
    delete *i;
  }
  references.insert(key, NewEntry(value));
}
void AbstractHandlerWithState::RemoveState(const QString& stateId)
{
  if (stateId.isNull())
  {
    throw ctkInvalidArgumentException("Cannot remove a null state");
  }

  QHash<QString,State::Pointer>::iterator i = states.find(stateId);
  if (i != states.end())
  {
    (*i)->RemoveListener(this);
    states.erase(i);
  }
}
Esempio n. 21
0
void Command::FireCommandChanged(const CommandEvent::ConstPointer commandEvent)
{
  if (!commandEvent)
  {
    throw ctkInvalidArgumentException("Cannot fire a null event");
  }

  try
  {
    commandEvents.commandChanged(commandEvent);
  }
  catch (...)
  {
    //TODO log exceptions?
  }
}
Esempio n. 22
0
//----------------------------------------------------------------------------
bool ctkPluginContext::connectPluginListener(const QObject* receiver, const char* slot,
                                             Qt::ConnectionType type)
{
  Q_D(ctkPluginContext);
  d->isPluginContextValid();
  // TODO check permissions for a direct connection
  if (type == Qt::DirectConnection || type == Qt::BlockingQueuedConnection)
  {
    return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedDirect(ctkPluginEvent)), slot, type);
  }
  else if (type == Qt::QueuedConnection)
  {
    return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedQueued(ctkPluginEvent)), slot, type);
  }
  else
  {
    throw ctkInvalidArgumentException("Only Qt::DirectConnection, Qt::QueuedConnection, or Qt::BlockingQueuedConnection are allowed as type argument.");
  }
}
Esempio n. 23
0
bool
ExtensionsParser::parseManifest(QXmlReader* reader, QXmlInputSource* in,
                                const QString& manifestName, RegistryObjectManager* registryObjects,
                                const SmartPointer<RegistryContribution>& currentNamespace,
                                QTranslator* translator)
{
  QTime start;
  this->resources = translator;
  this->objectManager = registryObjects;
  //initialize the parser with this object
  this->contribution = currentNamespace;
  if (registry->Debug())
    start.start();

  if (reader == nullptr)
  {
    cumulativeTime += start.elapsed();
    throw ctkInvalidArgumentException("XML Reader not available");
  }

  locationName = manifestName;
  reader->setContentHandler(this);
  reader->setDeclHandler(this);
  reader->setDTDHandler(this);
  reader->setEntityResolver(this);
  reader->setErrorHandler(this);
  reader->setLexicalHandler(this);
  bool success  = reader->parse(in);

  if (registry->Debug())
  {
    cumulativeTime += start.elapsed();
    BERRY_INFO << "Cumulative parse time so far : " << cumulativeTime;
  }

  return success;
}