Java tutorial
//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 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 getImportFrom(ExportPackageDescription export, StringBuffer importStatement) { importStatement.append(export.getName()).append(ELEMENT_SEPARATOR); Version version = export.getVersion(); importStatement.append(Constants.VERSION_ATTRIBUTE).append(EQUALS_QUOTE).append('[').append(version) .append(',').append(new Version(version.getMajor(), version.getMinor(), version.getMicro() + 1)) .append(')').append('\"'); addMap(importStatement, 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('\"'); } } }