public static Set processHeader()

in spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ConsumerHeaderProcessor.java [78:191]


    public static Set<WeavingData> processHeader(String consumerHeaderName, String consumerHeader) throws Exception {
        if (SpiFlyConstants.REQUIRE_CAPABILITY.equals(consumerHeaderName)) {
            return processRequireCapabilityHeader(consumerHeader);
        }

        Set<WeavingData> weavingData = new HashSet<WeavingData>();

        for (PathElement element : HeaderParser.parseHeader(consumerHeader)) {
            List<BundleDescriptor> allowedBundles = new ArrayList<BundleDescriptor>();
            String name = element.getName().trim();

            String className;
            String methodName;
            MethodRestriction methodRestriction;
            boolean serviceLoader = false;

            int hashIdx = name.indexOf('#');
            if (hashIdx > 0) {
                className = name.substring(0, hashIdx);
                int braceIdx = name.substring(hashIdx).indexOf('(');
                if (braceIdx > 0) {
                    methodName = name.substring(hashIdx + 1, hashIdx + braceIdx);
                    ArgRestrictions argRestrictions = new ArgRestrictions();
                    int closeIdx = name.substring(hashIdx).indexOf(')');
                    if (closeIdx > 0) {
                        String classes = name.substring(hashIdx + braceIdx + 1, hashIdx + closeIdx).trim();
                        if (classes.length() > 0) {
                            if (classes.indexOf('[') > 0) {
                                int argNumber = 0;
                                for (String s : classes.split(",")) {
                                    int idx = s.indexOf('[');
                                    int end = s.indexOf(']', idx);
                                    if (idx > 0 && end > idx) {
                                        argRestrictions.addRestriction(argNumber, s.substring(0, idx), s.substring(idx + 1, end));
                                    } else {
                                        argRestrictions.addRestriction(argNumber, s);
                                    }
                                    argNumber++;
                                }
                            } else {
                                String[] classNames = classes.split(",");
                                for (int i = 0; i < classNames.length; i++) {
                                    argRestrictions.addRestriction(i, classNames[i]);
                                }
                            }
                        } else {
                            argRestrictions = null;
                        }
                    }
                    methodRestriction = new MethodRestriction(methodName, argRestrictions);
                } else {
                    methodName = name.substring(hashIdx + 1);
                    methodRestriction = new MethodRestriction(methodName);
                }
            } else {
                if ("*".equalsIgnoreCase(name)) {
                    serviceLoader = true;
                    className = ServiceLoader.class.getName();
                    methodName = "load";
                    ArgRestrictions argRestrictions = new ArgRestrictions();
                    argRestrictions.addRestriction(0, Class.class.getName());
                    methodRestriction = new MethodRestriction(methodName, argRestrictions);
                } else {
                    throw new IllegalArgumentException("Must at least specify class name and method name: " + name);
                }
            }


            String bsn = element.getAttribute("bundle");
            if (bsn != null) {
                bsn = bsn.trim();
                if (bsn.length() > 0) {
                    for (String s : bsn.split("\\|")) {
                        int colonIdx = s.indexOf(':');
                        if (colonIdx > 0) {
                            String sn = s.substring(0, colonIdx);
                            String versionSfx = s.substring(colonIdx + 1);
                            if (versionSfx.startsWith("version=")) {
                                allowedBundles.add(new BundleDescriptor(sn,
                                        Version.parseVersion(versionSfx.substring("version=".length()))));
                            } else {
                                allowedBundles.add(new BundleDescriptor(sn));
                            }
                        } else {
                            allowedBundles.add(new BundleDescriptor(s));
                        }
                    }
                }
            }

            String bid = element.getAttribute("bundleId");
            if (bid != null) {
                bid = bid.trim();
                if (bid.length() > 0) {
                    for (String s : bid.split("\\|")) {
                        allowedBundles.add(new BundleDescriptor(Long.parseLong(s)));
                    }
                }
            }

            weavingData.add(createWeavingData(className, methodName, methodRestriction, allowedBundles));

            if (serviceLoader) {
                className = ServiceLoader.class.getName();
                methodName = "load";
                ArgRestrictions argRestrictions = new ArgRestrictions();
                argRestrictions.addRestriction(0, Class.class.getName());
                argRestrictions.addRestriction(1, ClassLoader.class.getName());
                methodRestriction = new MethodRestriction(methodName, argRestrictions);
                weavingData.add(createWeavingData(className, methodName, methodRestriction, allowedBundles));
            }
        }
        return weavingData;
    }