Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.*;
import java.util.Map.Entry;
import java.util.jar.*;

import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.*;

public class Main {
    private static String ELEMENT_SEPARATOR = "; ";
    private static final Object EQUALS_QUOTE = "=\"";

    private static void addExports(Attributes attributes, BundleDescription compositeDesc,
            ExportPackageDescription[] matchingExports) {
        if (matchingExports.length == 0)
            return;
        StringBuffer exportStatement = new StringBuffer();
        for (int i = 0; i < matchingExports.length; i++) {
            if (matchingExports[i].getExporter() == compositeDesc) {
                // the matching export from outside is the composite bundle itself
                // this must be one of our own substitutable exports, it must be ignored (bug 345640)
                continue;
            }
            if (exportStatement.length() > 0)
                exportStatement.append(',');
            getExportFrom(matchingExports[i], exportStatement);
        }
        if (exportStatement.length() > 0)
            attributes.putValue(Constants.EXPORT_PACKAGE, exportStatement.toString());
    }

    private static void getExportFrom(ExportPackageDescription export, StringBuffer exportStatement) {
        exportStatement.append(export.getName()).append(ELEMENT_SEPARATOR);
        exportStatement.append(Constants.VERSION_ATTRIBUTE).append(EQUALS_QUOTE).append(export.getVersion())
                .append('\"');
        addMap(exportStatement, export.getDirectives(), ":="); //$NON-NLS-1$
        addMap(exportStatement, export.getAttributes(), "="); //$NON-NLS-1$
    }

    private static void addMap(StringBuffer manifest, Map values, String assignment) {
        if (values == null)
            return; // nothing to add
        for (Iterator iEntries = values.entrySet().iterator(); iEntries.hasNext();) {
            manifest.append(ELEMENT_SEPARATOR);
            Map.Entry entry = (Entry) iEntries.next();
            manifest.append(entry.getKey()).append(assignment).append('\"');
            Object value = entry.getValue();
            if (value instanceof String[]) {
                String[] strings = (String[]) value;
                for (int i = 0; i < strings.length; i++) {
                    if (i != 0)
                        manifest.append(',');
                    manifest.append(strings[i]);
                }
            } else {
                manifest.append(value);
            }
            manifest.append('\"');
        }
    }
}