List of usage examples for org.springframework.util ObjectUtils nullSafeToString
public static String nullSafeToString(@Nullable short[] array)
From source file:org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.java
/** * Applies synthetic class-path analysis. That is, search the bundle space and the bundle class-path for entries * matching the given path./* w w w. j av a 2 s . c o m*/ * * @param bundle * @param path * @param foundPaths * @throws IOException */ private void findSyntheticClassPathMatchingResource(Bundle bundle, String path, Collection<String> foundPaths) throws IOException { // 1. bundle space lookup OsgiBundleResourcePatternResolver localPatternResolver = new OsgiBundleResourcePatternResolver(bundle); Resource[] foundResources = localPatternResolver.findResources(path); boolean trace = logger.isTraceEnabled(); if (trace) logger.trace("Found synthetic cp resources " + ObjectUtils.nullSafeToString(foundResources)); for (int j = 0; j < foundResources.length; j++) { // assemble only the OSGi paths foundPaths.add(foundResources[j].getURL().getPath()); } // 2. Bundle-Classpath lookup (on the path stripped of the prefix) Collection<String> cpMatchingPaths = findBundleClassPathMatchingPaths(bundle, path); if (trace) logger.trace("Found Bundle-ClassPath matches " + cpMatchingPaths); foundPaths.addAll(cpMatchingPaths); // 3. Required-Bundle is considered already by the dependency resolver }
From source file:org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.java
/** * Searches the bundle classpath (Bundle-Classpath) entries for the given pattern. * /*from w ww . j av a 2s. c o m*/ * @param bundle * @param pattern * @return * @throws IOException */ private Collection<String> findBundleClassPathMatchingPaths(Bundle bundle, String pattern) throws IOException { // list of strings pointing to the matching resources List<String> list = new ArrayList<String>(4); boolean trace = logger.isTraceEnabled(); if (trace) logger.trace("Analyzing " + Constants.BUNDLE_CLASSPATH + " entries for bundle [" + bundle.getBundleId() + "|" + bundle.getSymbolicName() + "]"); // see if there is a bundle class-path defined String[] entries = OsgiHeaderUtils.getBundleClassPath(bundle); if (trace) logger.trace( "Found " + Constants.BUNDLE_CLASSPATH + " entries " + ObjectUtils.nullSafeToString(entries)); // 1. if so, look at the entries for (int i = 0; i < entries.length; i++) { String entry = entries[i]; // make sure to exclude the default entry if (!entry.equals(BUNDLE_DEFAULT_CP)) { // 2. locate resource first from the bundle space (since it might not exist) OsgiBundleResource entryResource = new OsgiBundleResource(bundle, entry); // call the internal method to avoid catching an exception URL url = null; ContextResource res = entryResource.getResourceFromBundleSpace(entry); if (res != null) { url = res.getURL(); } if (trace) logger.trace("Classpath entry [" + entry + "] resolves to [" + url + "]"); // we've got a valid entry so let's parse it if (url != null) { String cpEntryPath = url.getPath(); // is it a jar ? if (entry.endsWith(JAR_EXTENSION)) findBundleClassPathMatchingJarEntries(list, url, pattern); // no, so it must be a folder else findBundleClassPathMatchingFolders(list, bundle, cpEntryPath, pattern); } } } return list; }
From source file:org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.java
/** * Replace the super class implementation to pass in the searchType parameter. * // w w w . jav a 2s . c o m * @see PathMatchingResourcePatternResolver#findPathMatchingResources(String) */ private Resource[] findPathMatchingResources(String locationPattern, int searchType) throws IOException { String rootDirPath = determineRootDir(locationPattern); String subPattern = locationPattern.substring(rootDirPath.length()); Resource[] rootDirResources = getResources(rootDirPath); boolean trace = logger.isTraceEnabled(); if (trace) logger.trace("Found root resources for [" + rootDirPath + "] :" + ObjectUtils.nullSafeToString(rootDirResources)); Set<Resource> result = new LinkedHashSet<Resource>(); for (int i = 0; i < rootDirResources.length; i++) { Resource rootDirResource = rootDirResources[i]; if (isJarResource(rootDirResource)) { result.addAll(doFindPathMatchingJarResources(rootDirResource, subPattern)); } else { result.addAll(doFindPathMatchingFileResources(rootDirResource, subPattern, searchType)); } } if (logger.isTraceEnabled()) { logger.trace("Resolved location pattern [" + locationPattern + "] to resources " + result); } return result.toArray(new Resource[result.size()]); }
From source file:org.eclipse.gemini.blueprint.service.dependency.internal.DefaultMandatoryDependencyManager.java
/** * Discover all the importers for the given exporter. Since the importers are already created before the exporter * instance is created, this method only does filtering based on the mandatory imports. *//* ww w . ja va 2 s .c o m*/ protected void discoverDependentImporterFor(String exporterBeanName, Object exporter) { boolean trace = log.isTraceEnabled(); // determine exporters String[] importerA = BeanFactoryUtils.getTransitiveDependenciesForBean(beanFactory, exporterBeanName, true, OsgiServiceProxyFactoryBean.class); String[] importerB = BeanFactoryUtils.getTransitiveDependenciesForBean(beanFactory, exporterBeanName, true, OsgiServiceCollectionProxyFactoryBean.class); String[] importerNames = StringUtils.concatenateStringArrays(importerA, importerB); // create map of associated importers Map<Object, String> dependingImporters = new LinkedHashMap<Object, String>(importerNames.length); if (trace) log.trace("Exporter [" + exporterBeanName + "] depends (transitively) on the following importers:" + ObjectUtils.nullSafeToString(importerNames)); // first create a listener for the exporter ImporterStateListener listener = new ImporterDependencyListener(exporter); exporterListener.put(exporter, listener); // exclude non-mandatory importers // non-singletons get added only once (as one instance is enough) for (int i = 0; i < importerNames.length; i++) { if (beanFactory.isSingleton(importerNames[i])) { Object importer = beanFactory.getBean(importerNames[i]); // create an importer -> exporter association if (isMandatory(importer)) { dependingImporters.put(importer, importerNames[i]); importerToName.putIfAbsent(importer, importerNames[i]); } else if (trace) log.trace("Importer [" + importerNames[i] + "] is optional; skipping it"); } else if (trace) log.trace("Importer [" + importerNames[i] + "] is a non-singleton; ignoring it"); } if (trace) log.trace("After filtering, exporter [" + exporterBeanName + "] depends on importers:" + dependingImporters.values()); Collection<Object> filteredImporters = dependingImporters.keySet(); // add the importers and their status to the collection synchronized (exporter) { Map<Object, Boolean> importerStatuses = new LinkedHashMap<Object, Boolean>(filteredImporters.size()); for (Iterator<Object> iter = filteredImporters.iterator(); iter.hasNext();) { Object importer = iter.next(); importerStatuses.put(importer, Boolean.valueOf(isSatisfied(importer))); // add the listener after the importer status has been recorded addListener(importer, listener); } exporterToImporterDeps.put(exporter, importerStatuses); if (!checkIfExporterShouldStart(exporter, importerStatuses)) { callUnregisterOnStartup(exporter); } } }
From source file:org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean.java
/** * Publishes the given object as an OSGi service. It simply assembles the classes required for publishing and then * delegates the actual registration to a dedicated method. *//*w w w . j a v a 2 s .c om*/ @Override void registerService() { synchronized (lock) { if (serviceRegistered || !registerService) return; else serviceRegistered = true; } // if we have a nested bean / non-Spring managed object String beanName = (!hasNamedBean ? null : targetBeanName); Dictionary serviceProperties = mergeServiceProperties(this.serviceProperties, beanName); Class<?>[] intfs = interfaces; // filter classes based on visibility ClassLoader beanClassLoader = ClassUtils.getClassLoader(targetClass); Class<?>[] autoDetectedClasses = ClassUtils.getVisibleClasses(interfaceDetector.detect(targetClass), beanClassLoader); if (log.isTraceEnabled()) log.trace("Autoexport mode [" + interfaceDetector + "] discovered on class [" + targetClass + "] classes " + ObjectUtils.nullSafeToString(autoDetectedClasses)); // filter duplicates Set<Class<?>> classes = new LinkedHashSet<Class<?>>(intfs.length + autoDetectedClasses.length); CollectionUtils.mergeArrayIntoCollection(intfs, classes); CollectionUtils.mergeArrayIntoCollection(autoDetectedClasses, classes); Class<?>[] mergedClasses = (Class[]) classes.toArray(new Class[classes.size()]); ServiceRegistration reg = registerService(mergedClasses, serviceProperties); serviceRegistration = new ServiceRegistrationDecorator(reg); safeServiceRegistration.swap(serviceRegistration); resolver.setDecorator(serviceRegistration); resolver.notifyIfPossible(); }
From source file:org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean.java
/** * Registration method./*from w w w. j a v a 2 s . co m*/ * * @param classes * @param serviceProperties * @return the ServiceRegistration */ ServiceRegistration registerService(Class<?>[] classes, final Dictionary serviceProperties) { Assert.notEmpty(classes, "at least one class has to be specified for exporting " + "(if autoExport is enabled then maybe the object doesn't implement any interface)"); // create an array of classnames (used for registering the service) final String[] names = ClassUtils.toStringArray(classes); // sort the names in alphabetical order (eases debugging) Arrays.sort(names); log.info("Publishing service under classes [" + ObjectUtils.nullSafeToString(names) + "]"); ServiceFactory serviceFactory = new PublishingServiceFactory(resolver, classes, (ExportContextClassLoaderEnum.SERVICE_PROVIDER.equals(contextClassLoader)), classLoader, aopClassLoader, bundleContext); if (isBeanBundleScoped()) serviceFactory = new OsgiBundleScope.BundleScopeServiceFactory(serviceFactory); if (System.getSecurityManager() != null) { AccessControlContext acc = SecurityUtils.getAccFrom(beanFactory); final ServiceFactory serviceFactoryFinal = serviceFactory; return AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() { public ServiceRegistration run() { return bundleContext.registerService(names, serviceFactoryFinal, serviceProperties); } }, acc); } else { return bundleContext.registerService(names, serviceFactory, serviceProperties); } }
From source file:org.eclipse.gemini.blueprint.service.importer.support.AbstractOsgiServiceImportFactoryBean.java
/** * Assembles the configuration properties into one unified OSGi filter. Note that this implementation creates the * filter on the first call and caches it afterwards. * //w w w. ja v a2s .c om * @return unified filter based on this factory bean configuration */ public Filter getUnifiedFilter() { if (unifiedFilter != null) { return unifiedFilter; } String filterWithClasses = (!ObjectUtils.isEmpty(interfaces) ? OsgiFilterUtils.unifyFilter(interfaces, filter) : filter); boolean trace = log.isTraceEnabled(); if (trace) log.trace("Unified classes=" + ObjectUtils.nullSafeToString(interfaces) + " and filter=[" + filter + "] in=[" + filterWithClasses + "]"); // add the serviceBeanName/Blueprint component name constraint String nameFilter; if (StringUtils.hasText(serviceBeanName)) { StringBuilder nsFilter = new StringBuilder("(|("); nsFilter.append(OsgiServicePropertiesResolver.BEAN_NAME_PROPERTY_KEY); nsFilter.append("="); nsFilter.append(serviceBeanName); nsFilter.append(")("); nsFilter.append(OsgiServicePropertiesResolver.SPRING_DM_BEAN_NAME_PROPERTY_KEY); nsFilter.append("="); nsFilter.append(serviceBeanName); nsFilter.append(")("); nsFilter.append(OsgiServicePropertiesResolver.BLUEPRINT_COMP_NAME); nsFilter.append("="); nsFilter.append(serviceBeanName); nsFilter.append("))"); nameFilter = nsFilter.toString(); } else { nameFilter = null; } String filterWithServiceBeanName = filterWithClasses; if (nameFilter != null) { StringBuilder finalFilter = new StringBuilder(); finalFilter.append("(&"); finalFilter.append(filterWithClasses); finalFilter.append(nameFilter); finalFilter.append(")"); filterWithServiceBeanName = finalFilter.toString(); } if (trace) log.trace("Unified serviceBeanName [" + ObjectUtils.nullSafeToString(serviceBeanName) + "] and filter=[" + filterWithClasses + "] in=[" + filterWithServiceBeanName + "]"); // create (which implies validation) the actual filter unifiedFilter = OsgiFilterUtils.createFilter(filterWithServiceBeanName); return unifiedFilter; }
From source file:org.eclipse.gemini.blueprint.service.importer.support.StaticServiceProxyCreator.java
/** * Apply 'greedy' proxying by discovering the exposed classes. * /*from www. ja va 2 s . c o m*/ * @param ref * @return */ Class<?>[] discoverProxyClasses(ServiceReference ref) { boolean trace = log.isTraceEnabled(); if (trace) log.trace("Generating greedy proxy for service " + OsgiStringUtils.nullSafeToString(ref)); String[] classNames = OsgiServiceReferenceUtils.getServiceObjectClasses(ref); if (trace) log.trace("Discovered raw classes " + ObjectUtils.nullSafeToString(classNames)); // try to get as many classes as possible Class<?>[] classes = ClassUtils.loadClassesIfPossible(classNames, classLoader); if (trace) log.trace("Visible classes are " + ObjectUtils.nullSafeToString(classes)); // exclude final classes classes = ClassUtils.excludeClassesWithModifier(classes, Modifier.FINAL); if (trace) log.trace("Filtering out final classes; left out with " + ObjectUtils.nullSafeToString(classes)); // remove classes if needed if (interfacesOnlyProxying) { Set<Class<?>> clazzes = new LinkedHashSet<Class<?>>(classes.length); for (int classIndex = 0; classIndex < classes.length; classIndex++) { Class<?> clazz = classes[classIndex]; if (clazz.isInterface()) clazzes.add(clazz); } if (trace) log.trace("Filtering out concrete classes; left out with " + clazzes); classes = (Class[]) clazzes.toArray(new Class[clazzes.size()]); } // remove class duplicates/parents classes = ClassUtils.removeParents(classes); if (trace) log.trace("Filtering out parent classes; left out with " + classes); return classes; }
From source file:org.eclipse.gemini.blueprint.service.importer.support.StaticServiceProxyCreator.java
Class<?>[] getInterfaces(ServiceReference reference) { if (greedyProxying) { Class<?>[] clazzes = discoverProxyClasses(reference); if (log.isTraceEnabled()) log.trace("generating 'greedy' service proxy using classes " + ObjectUtils.nullSafeToString(clazzes) + " over " + ObjectUtils.nullSafeToString(this.classes)); return clazzes; }/* w w w.jav a2 s .co m*/ // no greedy proxy, return just the configured classes return classes; }
From source file:org.eclipse.gemini.blueprint.util.OsgiListenerUtils.java
private static void dispatchServiceRegistrationEvents(ServiceReference[] alreadyRegistered, ServiceListener listener) {//from w w w . j a v a 2 s . com if (log.isTraceEnabled()) log.trace("Calling listener for already registered services: " + ObjectUtils.nullSafeToString(alreadyRegistered)); if (alreadyRegistered != null) { for (int i = 0; i < alreadyRegistered.length; i++) { listener.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, alreadyRegistered[i])); } } }