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 org.osgi.framework.*;

public class Main {
    private static final String[] INVALID_COMPOSITE_HEADERS = new String[] { Constants.DYNAMICIMPORT_PACKAGE,
            Constants.FRAGMENT_HOST, Constants.REQUIRE_BUNDLE, Constants.BUNDLE_NATIVECODE,
            Constants.BUNDLE_CLASSPATH, Constants.BUNDLE_ACTIVATOR, Constants.BUNDLE_LOCALIZATION,
            Constants.BUNDLE_ACTIVATIONPOLICY };

    static void validateCompositeManifest(Map compositeManifest) throws BundleException {
        if (compositeManifest == null)
            throw new BundleException("The composite manifest cannot be null.", BundleException.MANIFEST_ERROR); //$NON-NLS-1$
        // check for symbolic name
        if (compositeManifest.get(Constants.BUNDLE_SYMBOLICNAME) == null)
            throw new BundleException("The composite manifest must contain a Bundle-SymbolicName header.", //$NON-NLS-1$
                    BundleException.MANIFEST_ERROR);
        // check for invalid manifests headers
        for (int i = 0; i < INVALID_COMPOSITE_HEADERS.length; i++)
            if (compositeManifest.get(INVALID_COMPOSITE_HEADERS[i]) != null)
                throw new BundleException(
                        "The composite manifest must not contain the header " + INVALID_COMPOSITE_HEADERS[i], //$NON-NLS-1$
                        BundleException.MANIFEST_ERROR);
        // validate manifest version
        String manifestVersion = (String) compositeManifest.get(Constants.BUNDLE_MANIFESTVERSION);
        if (manifestVersion == null) {
            compositeManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$
        } else {
            try {
                Integer parsed = Integer.valueOf(manifestVersion);
                if (parsed.intValue() > 2 || parsed.intValue() < 2)
                    throw new BundleException("Invalid Bundle-ManifestVersion: " + manifestVersion); //$NON-NLS-1$
            } catch (NumberFormatException e) {
                throw new BundleException("Invalid Bundle-ManifestVersion: " + manifestVersion); //$NON-NLS-1$
            }
        }
    }
}