private void detectNegation(final String askQuery) throws MultiException { // official w3c sparql negation forms final String[] negationForms = new String[] {"not exists", "!exists", "minus", "not in", "not bound"}; MultiException.ExceptionStack exceptionStack = null; for (final String negationForm : negationForms) { try { if (askQuery.toLowerCase().contains(negationForm)) { throw new NotAvailableException("Found negation keyword: " + negationForm); } } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not parse ontologyChange from query string, because of negation phrase in query string! Certain determination of " + "trigger changes criteria can't be guarantee. Select manual criteria for this trigger!", exceptionStack); }
public static String resolveVariable(final String variable, final VariableProvider... providers) throws MultiException { MultiException.ExceptionStack exceptionStack = null; for (VariableProvider provider : providers) { try { return provider.getValue(variable); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(VariableProcessor.class, ex, exceptionStack); continue; } } MultiException.checkAndThrow("Could not resolve Variable[" + variable + "]!", exceptionStack); throw new AssertionError("Fatal error during variable resolving."); } }
public final void registerUnits(final Collection<UnitConfig> unitConfigs) throws CouldNotPerformException, InterruptedException { MultiException.ExceptionStack exceptionStack = null; for (UnitConfig unitConfig : unitConfigs) { try { registerUnit(unitConfig); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not register all hosted units of " + this, exceptionStack); }
/** * Method executes the input function without argument and returns the result. If the input function provokes an * exception it will be stacked on the input exceptionStack object and NULL will be returned. Check the * exceptionStack in this case. * * @param function represents a function without any argument and produces an result. * @param source of the function. Can be ignored by NULL. * @param exceptionStack is used to bundle possible exception. If NULL a new exceptionStack will be created. * @param <R> is the type of the result to the function. * @return the result of the function with type R. Returns null if an exception occurs. Check exceptionStack. */ static <R> R get(final Supplier<R> function, final Object source, ExceptionStack exceptionStack) { try { exceptionStack = initializeIfNull(exceptionStack); return function.getSupplier(); } catch (Exception e) { MultiException.push(source, new Exception(e.toString()), exceptionStack); } return null; }
/** * Method executes the input function given as argument and returns the result. If an exception is provoked by * execution, it will be stacked on the input exceptionStack and NULL will be returned. Check exceptionStack. * * @param function represents a function with one argument and produces an result. * @param funcArg is the single argument of the function. * @param source is the source of the function. Can be ignored by NULL. * @param exceptionStack is used to bundle possible exception. If NULL a new exceptionStack will be created. * @param <T> is the type of the argument to the function. * @param <R> is the type of the result to the function. * @return the result of the function with type R. Returns null if an exception occurs. Check exceptionStack. */ static <T, R> R apply(final Function<T, R> function, final T funcArg, final Object source, ExceptionStack exceptionStack) { try { exceptionStack = initializeIfNull(exceptionStack); return function.applyFunction(funcArg); } catch (Exception e) { MultiException.push(source, new Exception(e.toString()), exceptionStack); } return null; }
private void initMethods(final LocalServer localServer) throws NotAvailableException, CouldNotPerformException { MultiException.ExceptionStack exceptionStack = null; synchronized (participantLock) { for (Entry<String, Callback> entry : localMethodStack.entrySet()) { try { localServer.addMethod(entry.getKey(), entry.getValue()); } catch (RSBException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("Could not register all methods!", exceptionStack); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); } } }
/** * Method executes the input function given as argument and returns the result. If an exception is provoked by * execution, it will be stacked on the input exceptionStack and NULL will be returned. Check exceptionStack. * * @param function represents a function with one argument and produces an result. * @param funcArgOne is the first argument of the function. * @param funcArgTwo is the second argument of the function. * @param source is the source of the function. Can be ignored by NULL. * @param exceptionStack is used to bundle possible exception. If NULL a new exceptionStack will be created. * @param <T> is the type of the first argument to the function. * @param <U> is the type of the second argument to the function. * @param <R> is the type of the result to the function. * @return the result of the function with type R. Returns null if an exception occurs. Check exceptionStack. */ static <T, U, R> R apply(final BiFunction<T, U, R> function, final T funcArgOne, final U funcArgTwo, final Object source, ExceptionStack exceptionStack) { try { exceptionStack = initializeIfNull(exceptionStack); return function.applyBiFunction(funcArgOne, funcArgTwo); } catch (Exception e) { MultiException.push(source, new Exception(e.toString()), exceptionStack); } return null; }
public Collection<GenericUnitPanel<RS>> add(final Collection<String> unitLabelList) throws InitializationException, InterruptedException { final List<GenericUnitPanel<RS>> unitPanelList = new ArrayList<>(); MultiException.ExceptionStack exceptionStack = null; try { // create and add unit panels. for (String unitLabel : unitLabelList) { try { unitPanelList.addAll(add(unitLabel)); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not add all units!", exceptionStack); } catch (MultiException ex) { throw new InitializationException(this, ex); } return unitPanelList; }
@Override public void activate() throws InterruptedException, CouldNotPerformException { super.activate(); MultiException.ExceptionStack exceptionStack = null; synchronized (unitMapLock) { for (AbstractUnitController unit : unitMap.values()) { try { unit.activate(); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } } MultiException.checkAndThrow("Could not activate all hosted units of " + this, exceptionStack); }
@Override public void deactivate() throws InterruptedException, CouldNotPerformException { super.deactivate(); MultiException.ExceptionStack exceptionStack = null; synchronized (unitMapLock) { for (AbstractUnitController unit : unitMap.values()) { try { unit.deactivate(); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } } MultiException.checkAndThrow("Could not deactivate all hosted units of " + this, exceptionStack); }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getDeleteStateRelation(final List<ServiceType> serviceTypes) { final List<RdfTriple> triples = new ArrayList<>(); MultiException.ExceptionStack exceptionStack = null; for (final ServiceType serviceType : serviceTypes) { try { triples.add(getDeleteStateRelation(serviceType)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely services!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
/** * Method ensures that one or multiple object reference(s) passed as a parameter to the calling method is/are not * null. Possible NotAvailableException is stacked and returned. By using one object reference use the single * version method to be able to specify the content if exception is thrown. * * @param source is the source of the reference(s). Can be ignored by NULL. * @param exceptionStack is used to bundle possible exception. If NULL a new exceptionStack will be created. * @param objects are the reference objects, which should be checked. * @return the exceptionStack with or without new exception entry. */ static ExceptionStack multipleCheckNotNull(final Object source, ExceptionStack exceptionStack, final Object... objects) { exceptionStack = initializeIfNull(exceptionStack); for (int i = 0; i < objects.length; i++) { try { checkNotNull(objects[i], "Parameter " + i + " in argument array is null!"); } catch (NotAvailableException e) { MultiException.push(source, e, exceptionStack); } } return exceptionStack; }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getDeleteUnitInstances(final List<UnitConfig> unitConfigs) { final List<RdfTriple> triples = new ArrayList<>(); MultiException.ExceptionStack exceptionStack = null; for (final UnitConfig unitConfig : unitConfigs) { try { triples.add(getDeleteUnitInstance(unitConfig)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely units!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
/** * Method ensures that one or multiple object reference(s) passed as a parameter to the calling method is/are not * null. Throws Exception otherwise. * * @param source is the source of the reference(s). Can be ignored by NULL. * @param objects are the reference parameter, which should be checked. * @throws MultiException is thrown in case at least one reference parameter is NULL. */ static void multipleCheckNotNullAndThrow(final Object source, final Object... objects) throws MultiException { final ExceptionStack exceptionStack = new ExceptionStack(); for (int i = 0; i < objects.length; i++) { try { checkNotNull(objects[i], "Parameter " + i + " in argument array is null!"); } catch (NotAvailableException e) { MultiException.push(source, e, exceptionStack); } } MultiException.checkAndThrow("Input is invalid.", exceptionStack); }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getDeleteProviderServiceInstances(final List<ServiceType> serviceTypes) { MultiException.ExceptionStack exceptionStack = null; final List<RdfTriple> triples = new ArrayList<>(); for (final ServiceType serviceType : serviceTypes) { try { final String serviceName = StringModifier.firstCharToLowerCase(StringModifier.getServiceTypeName(serviceType)); triples.add(new RdfTriple(serviceName, OntExpr.IS_A.getName(), null)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely services!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getDeleteStateInstances(final List<ServiceType> serviceTypes) { MultiException.ExceptionStack exceptionStack = null; final List<RdfTriple> triples = new ArrayList<>(); for (final ServiceType serviceType : serviceTypes) { try { final String stateName = StringModifier.firstCharToLowerCase(Services.getServiceStateName(serviceType)); triples.add(new RdfTriple(stateName, OntExpr.IS_A.getName(), null)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely states!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
public final void registerUnitsById(final Collection<String> unitIds) throws CouldNotPerformException, InterruptedException { CachedUnitRegistryRemote.waitForData(); MultiException.ExceptionStack exceptionStack = null; for (String unitId : unitIds) { try { registerUnit(Registries.getUnitRegistry(true).getUnitConfigById(unitId)); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } MultiException.checkAndThrow("Could not register all hosted units of " + this, exceptionStack); }
private List<RdfTriple> getInsertProviderServiceRelation(final UnitConfig unitConfig) { final List<RdfTriple> triples = new ArrayList<>(); MultiException.ExceptionStack exceptionStack = null; for (final ServiceConfig serviceConfig : unitConfig.getServiceConfigList()) { try { final String serviceTypeName = StringModifier.firstCharToLowerCase(StringModifier.getServiceTypeName(serviceConfig.getServiceDescription().getType())); triples.add(new RdfTriple(unitConfig.getId(), OntProp.PROVIDER_SERVICE.getName(), serviceTypeName)); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely services!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
/** * {@inheritDoc} */ @Override public List<RdfTriple> getInsertStateInstances() { MultiException.ExceptionStack exceptionStack = null; final List<RdfTriple> triples = new ArrayList<>(); for (final ServiceType serviceType : ServiceType.values()) { if (serviceType.equals(ServiceType.UNKNOWN)) { continue; } try { final String stateName = StringModifier.firstCharToLowerCase(Services.getServiceStateName(serviceType)); triples.add(new RdfTriple(stateName, OntExpr.IS_A.getName(), OntCl.STATE.getName())); } catch (NotAvailableException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("There are incompletely stateTypes!", exceptionStack); } catch (MultiException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.ERROR); } return triples; }
private void initServiceSimulators(final UnitController unitController) throws InitializationException, InterruptedException { try { final MultiException.ExceptionStack exceptionStack = new MultiException.ExceptionStack(); for (final ServiceDescription serviceDescription : unitController.getUnitTemplate().getServiceDescriptionList()) { try { serviceSimulatorList.add(serviceSimulatorFactory.newInstance(unitController, serviceDescription.getType())); } catch (final CouldNotPerformException ex) { MultiException.push(this, ex, exceptionStack); } } try { MultiException.checkAndThrow("Could not init all service simulators!", exceptionStack); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, LOGGER); } } catch (CouldNotPerformException ex) { throw new InitializationException(this, ex); } }