private String[] getBundleNamePrefixes(Class<? extends Connector> connector) { // figure out the message catalog.. ConnectorClass configOpts = connector.getAnnotation(ConnectorClass.class); String[] paths = null; if (configOpts != null) { paths = configOpts.messageCatalogPaths(); } if (paths == null || paths.length == 0) { String pkage = ReflectionUtil.getPackage(connector); String messageCatalog = pkage + ".Messages"; paths = new String[] {messageCatalog}; } for (int i = 0; i < paths.length; i++) { paths[i] = "/" + paths[i].replace('.', '/'); } return paths; }
/** Final pass - create connector infos. */ private List<ConnectorInfo> createConnectorInfo( Bundle parsed, List<ManifestEntry> manifestEnties) { List<ConnectorInfo> rv = new ArrayList<ConnectorInfo>(); Enumeration<URL> classFiles = parsed.findEntries("/", "*.class", true); List<URL> propertyFiles = Collections.list(parsed.findEntries("/", "*.properties", true)); String frameworkVersion = null; String bundleName = null; String bundleVersion = null; for (ManifestEntry entry : manifestEnties) { if (ConnectorManifestScanner.ATT_FRAMEWORK_VERSION.equals(entry.getKey())) { frameworkVersion = entry.getValue(); } else if (ConnectorManifestScanner.ATT_BUNDLE_NAME.equals(entry.getKey())) { bundleName = entry.getValue(); } else if (ConnectorManifestScanner.ATT_BUNDLE_VERSION.equals(entry.getKey())) { bundleVersion = entry.getValue(); } } if (FrameworkUtil.getFrameworkVersion().compareTo(Version.parse(frameworkVersion)) < 0) { String message = "Bundle " + parsed.getLocation() + " requests an unrecognized framework version " + frameworkVersion + " but available is " + FrameworkUtil.getFrameworkVersion().getVersion(); throw new ConfigurationException(message); } if (StringUtil.isBlank(bundleName) || StringUtil.isBlank(bundleVersion)) { return rv; } while (classFiles.hasMoreElements()) { Class<?> connectorClass = null; ConnectorClass options = null; String name = classFiles.nextElement().getFile(); String className = name.substring(1, name.length() - ".class".length()); className = className.replace('/', '.'); try { connectorClass = parsed.loadClass(className); options = connectorClass.getAnnotation(ConnectorClass.class); } catch (Throwable e) { // probe for the class. this might not be an error since it // might be from a bundle // fragment ( a bundle only included by other bundles ). // However, we should definitely warn logger.warn( "Unable to load class {} from bundle {}. Class will be ignored and will not be listed in list of connectors.", new Object[] {className, parsed.getLocation()}, e); } if (connectorClass != null && options != null) { if (!Connector.class.isAssignableFrom(connectorClass)) { throw new ConfigurationException( "Class " + connectorClass + " does not implement " + Connector.class.getName()); } final LocalConnectorInfoImpl info = new LocalConnectorInfoImpl(); info.setConnectorClass(connectorClass.asSubclass(Connector.class)); try { info.setConnectorConfigurationClass(options.configurationClass()); info.setConnectorDisplayNameKey(options.displayNameKey()); info.setConnectorCategoryKey(options.categoryKey()); info.setConnectorKey( new ConnectorKey(bundleName, bundleVersion, connectorClass.getName())); ConnectorMessagesImpl messages = loadMessageCatalog(propertyFiles, parsed, info.getConnectorClass()); info.setMessages(messages); info.setDefaultAPIConfiguration(createDefaultAPIConfiguration(info)); rv.add(info); } catch (final NoClassDefFoundError e) { logger.warn( "Unable to load configuration class of connector {} from bundle {}. Class will be ignored and will not be listed in list of connectors.", logger.isDebugEnabled() ? new Object[] {connectorClass, parsed.getLocation(), e} : new Object[] {connectorClass, parsed.getLocation()}); } catch (final TypeNotPresentException e) { logger.warn( "Unable to load configuration class of connector {} from bundle {}. Class will be ignored and will not be listed in list of connectors.", logger.isDebugEnabled() ? new Object[] {connectorClass, parsed.getLocation(), e} : new Object[] {connectorClass, parsed.getLocation()}); } } } return rv; }