/** * Returns non-empty {@code Optional<String>}, if the given {@code String} is non-empty after * applying trim() operation. * * @param str input {@code String}. * @return {@code Optional<String>}, if the given {@code String} is non-empty after * applying trim() operation. If not an empty {@code Optional<String>} will be returned. */ public static Optional<String> getNonEmptyStringAfterTrim(String str) { if (isNullOrEmptyAfterTrim(str)) { return Optional.empty(); } return Optional.of(str.trim()); } }
/** * Extracts the "objectClass" manifest element attribute from the give {@code ManifestElement}. * * @param manifestElement {@code ManifestElement} from which the "objectClass" is to be extracted. * @return the value of the "objectClass" attribute. */ private static String getObjectClassName(ManifestElement manifestElement) { return getNonEmptyStringAfterTrim(manifestElement.getAttribute(OBJECT_CLASS)) .orElseThrow(() -> new StartOrderResolverException("objectClass cannot be empty. " + "Bundle-SymbolicName: " + manifestElement.getBundle().getSymbolicName())); }
/** * Read configuration files and set ports and host names */ public void loadConfigurations() throws ConfigurationException { // Get the hostname that Carbon runs on String andesConfigHostAddress = DataHolder.getInstance().getConfigProvider() .getConfigurationObject(TransportConfiguration.class).getAmqpConfiguration().getBindAddress(); //AndesConfigurationManager.readValue(AndesConfiguration.TRANSPORTS_AMQP_BIND_ADDRESS); if (StringUtils.isNullOrEmpty(andesConfigHostAddress)) { try { hostname = InetAddress.getByName(andesConfigHostAddress).getHostAddress(); } catch (UnknownHostException e) { hostname = CARBON_DEFAULT_HOSTNAME; } } // Read Qpid broker amqpPort from configuration file amqpPort = readPortFromConfig(); // Read Qpid broker SSL amqpPort from configuration file amqpSSLPort = readSSLPortFromConfig(); // Read MQTT amqpPort from configuration file mqttPort = readMQTTPortFromConfig(); // Read MQTT ssl port value from configuation file mqttSSLPort = readMQTTSSLPortFromConfig(); }
public MSF4JClient.Builder<T> addErrorResponseMapper(RestErrorResponseMapper... responseMappers) { Arrays.stream(responseMappers).forEach(rm -> { Arrays.stream(rm.getClass().getMethods()). filter(method -> !StringUtils.isNullOrEmptyAfterTrim(rm.getExceptionKey())). findAny(). ifPresent(method -> { if (errorCodeExceptionMap.containsKey(rm.getExceptionKey())) { log.warn("RestErrorResponseMapper has already been added for the given exception key " + "'{}'", rm.getExceptionKey()); } errorCodeExceptionMap.put(rm.getExceptionKey(), rm.getExceptionClass()); }); }); return this; }
String componentKey = getNonEmptyStringAfterTrim((String) reference.getProperty(COMPONENT_NAME)) .orElseThrow(() -> new StartOrderResolverException(COMPONENT_NAME + " value is missing in " + "the services registered with the key " + serviceInterfaceClassName + ", " + String capabilityName = getNonEmptyStringAfterTrim((String) reference.getProperty(CAPABILITY_NAME)) .orElseThrow(() -> new StartOrderResolverException(CAPABILITY_NAME + " value is missing in " + "the services registered with the key " + serviceInterfaceClassName + ", " +
/** * Create a {@code StartupComponent} from he manifest element. * * @param manifestElement {@code ManifestElement} from which the {@code StartupComponent} is created. * @return the created {@code StartupComponent}. */ static StartupComponent getStartupComponent(ManifestElement manifestElement) { String componentName = getNonEmptyStringAfterTrim(manifestElement.getAttribute(COMPONENT_NAME)) .orElseThrow( () -> new StartOrderResolverException(COMPONENT_NAME + " attribute value is missing in " + manifestElement.getManifestHeaderName() + " header of bundle(" + manifestElement.getBundle().getSymbolicName() + ":" + manifestElement.getBundle().getVersion() + ")")); String requiredServices = getNonEmptyStringAfterTrim(manifestElement.getAttribute(REQUIRED_SERVICE)) .orElseThrow( () -> new StartOrderResolverException(REQUIRED_SERVICE + " attribute value is missing in " + manifestElement.getManifestHeaderName() + " header of bundle(" + manifestElement.getBundle().getSymbolicName() + ":" + manifestElement.getBundle().getVersion() + ")")); String[] requiredServiceArray = requiredServices.split(CAPABILITY_NAME_SPLIT_CHAR); List<String> requiredServicesList = Arrays.asList(requiredServiceArray) .stream() .map(String::trim) .collect(Collectors.toList()); StartupComponent startupComponent = new StartupComponent(componentName, manifestElement.getBundle()); startupComponent.addRequiredServices(requiredServicesList); return startupComponent; }
static List<OSGiServiceCapability> getOSGiServiceCapabilities(ManifestElement manifestElement) { int serviceCount = getNonEmptyStringAfterTrim(manifestElement.getAttribute(SERVICE_COUNT)) .map(serviceCountStr -> { try { getNonEmptyStringAfterTrim(manifestElement.getAttribute(REQUIRED_BY_COMPONENT_NAME)) .ifPresent(requiredByComponentNameStr -> { osgiServiceCapability.setDirectDependency(false); getNonEmptyStringAfterTrim(manifestElement.getAttribute(DEPENDENT_COMPONENT_NAME)) .ifPresent(requiredByComponentNameStr -> { osgiServiceCapability.setDirectDependency(false);
static CapabilityProviderCapability getCapabilityProviderCapability(ManifestElement manifestElement) { // Processing CapabilityProvider OSGi service String providedCapabilityName = getNonEmptyStringAfterTrim(manifestElement.getAttribute(CAPABILITY_NAME)) .orElseThrow( () -> new StartOrderResolverException(CAPABILITY_NAME + " attribute value is missing in " + manifestElement.getManifestHeaderName() + " header of bundle(" + manifestElement.getBundle().getSymbolicName() + ":" + manifestElement.getBundle().getVersion() + ")")); return new CapabilityProviderCapability( getObjectClassName(manifestElement), Capability.CapabilityType.OSGi_SERVICE, Capability.CapabilityState.EXPECTED, providedCapabilityName, manifestElement.getBundle()); }