Java Code Examples for org.osgi.framework.Constants#DYNAMICIMPORT_PACKAGE

The following examples show how to use org.osgi.framework.Constants#DYNAMICIMPORT_PACKAGE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BundlePackages.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Parse the dynamic import attribute
 */

void parseDynamicImports(final String s) {
  for (final HeaderEntry he : Util
      .parseManifestHeader(Constants.DYNAMICIMPORT_PACKAGE, s, false, true,
                           false)) {
    if (he.getDirectives().containsKey(Constants.RESOLUTION_DIRECTIVE)) {
      throw new IllegalArgumentException(Constants.DYNAMICIMPORT_PACKAGE +
                                         " entry illegal contains a " +
                                         Constants.RESOLUTION_DIRECTIVE +
                                         " directive.");
    }
    ImportPkg tmpl = null;
    for (String key : he.getKeys()) {
      if (key.equals("*")) {
        key = EMPTY_STRING;
      } else if (key.endsWith(".*")) {
        key = key.substring(0, key.length() - 1);
      } else if (key.endsWith(".")) {
        throw new IllegalArgumentException(Constants.DYNAMICIMPORT_PACKAGE +
                                           " entry ends with '.': " + key);
      } else if (key.indexOf("*") != -1) {
        throw new IllegalArgumentException(Constants.DYNAMICIMPORT_PACKAGE +
                                         " entry contains a '*': " + key);
      }
      if (tmpl != null) {
        dImportPatterns.add(new ImportPkg(tmpl, key));
      } else {
        tmpl = new ImportPkg(key, he, this, true);
        dImportPatterns.add(tmpl);
      }
    }
  }
}
 
Example 2
Source File: BundleImpl.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
WovenClassImpl(final String clazzName, final byte[] bytes,
		final Revision revision, final ProtectionDomain domain) {
	this.bytes = bytes;
	this.clazzName = clazzName;
	this.dynamicImportRequirements = new ArrayList<BundleRequirement>();
	this.dynamicImports = new ArrayList<String>() {

		/**
		 * 
		 */
		private static final long serialVersionUID = 975783807443126126L;

		@Override
		public boolean add(final String dynImport) {
			checkDynamicImport(dynImport);

			return super.add(dynImport);
		}

		@Override
		public boolean addAll(
				final Collection<? extends String> c) {
			for (final String dynImport : c) {
				checkDynamicImport(dynImport);
			}

			return super.addAll(c);
		}

		private void checkDynamicImport(final String dynImport)
				throws IllegalArgumentException {
			try {
				final String[] literals = Utils
						.splitString(dynImport, ';');

				if (literals[0].contains(";")) {
					throw new IllegalArgumentException(dynImport);
				}

				final ParseResult parseResult = Utils
						.parseLiterals(literals, 1);
				final HashMap<String, String> dirs = parseResult
						.getDirectives();

				dirs.put(Namespace.REQUIREMENT_FILTER_DIRECTIVE,
						Utils.createFilter(
								PackageNamespace.PACKAGE_NAMESPACE,
								literals[0],
								parseResult.getLatter()));
				dirs.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE,
						PackageNamespace.RESOLUTION_DYNAMIC);

				dirs.put(Concierge.DIR_INTERNAL, literals[0]);

				final BundleRequirement req = new BundleRequirementImpl(
						revision,
						PackageNamespace.PACKAGE_NAMESPACE, dirs,
						null, Constants.DYNAMICIMPORT_PACKAGE + ' '
								+ dynImport);

				dynamicImportRequirements.add(req);
			} catch (final BundleException be) {
				throw new IllegalArgumentException(
						"Unvalid dynamic import " + dynImport);
			}
		}

	};
	this.domain = domain;
}
 
Example 3
Source File: Fragment.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @param gen
 *          The bundle generation of this fragment.
 * @param headerEntry
 *          the fragment-host manifest header describing this fragment.
 */
Fragment(final BundleGeneration gen, final HeaderEntry headerEntry) {
  this.gen = gen;
  this.hostName = headerEntry.getKey();

  if (gen.archive.getAttribute(Constants.BUNDLE_ACTIVATOR) != null) {
    throw new IllegalArgumentException("A fragment bundle can not have a Bundle-Activator.");
  }

  final Map<String,String>dirs = headerEntry.getDirectives();
  String extension = dirs.get(Constants.EXTENSION_DIRECTIVE);
  if (Constants.SYSTEM_BUNDLE_SYMBOLICNAME.equals(hostName)
        || BundleGeneration.KNOPFLERFISH_SYMBOLICNAME.equals(hostName)) {
    if (extension != null) {
      if (!Constants.EXTENSION_FRAMEWORK.equals(extension)
          && !Constants.EXTENSION_BOOTCLASSPATH.equals(extension)) {
        // an extension bundle must target the system bundle.
        throw new IllegalArgumentException("An extension bundle must target "
            + "the system bundle(" + Constants.SYSTEM_BUNDLE_SYMBOLICNAME + " or "
            + BundleGeneration.KNOPFLERFISH_SYMBOLICNAME + ")");
      }
    } else {
      extension = Constants.EXTENSION_FRAMEWORK;
    }

    if (gen.archive.getAttribute(Constants.IMPORT_PACKAGE) != null
        || gen.archive.getAttribute(Constants.REQUIRE_BUNDLE) != null
        || gen.archive.getAttribute(Constants.BUNDLE_NATIVECODE) != null
        || gen.archive.getAttribute(Constants.DYNAMICIMPORT_PACKAGE) != null
        || gen.archive.getAttribute(Constants.BUNDLE_ACTIVATOR) != null) {
      throw new IllegalArgumentException("An extension bundle cannot specify: "
          + Constants.IMPORT_PACKAGE + ", " + Constants.REQUIRE_BUNDLE + ", "
          + Constants.BUNDLE_NATIVECODE + ", " + Constants.DYNAMICIMPORT_PACKAGE + " or "
          + Constants.BUNDLE_ACTIVATOR);
    }

    if (!gen.bundle.fwCtx.props.getBooleanProperty(Constants.SUPPORTS_FRAMEWORK_EXTENSION)
        && Constants.EXTENSION_FRAMEWORK.equals(extension)) {
      throw new UnsupportedOperationException(
          "Framework extension bundles are not supported "
              + "by this framework. Consult the documentation");
    }
    if (!gen.bundle.fwCtx.props.getBooleanProperty(Constants.SUPPORTS_BOOTCLASSPATH_EXTENSION)
        && Constants.EXTENSION_BOOTCLASSPATH.equals(extension)) {
      throw new UnsupportedOperationException(
          "Bootclasspath extension bundles are not supported "
              + "by this framework. Consult the documentation");
    }
  } else {
    if (extension != null) {
      throw new IllegalArgumentException("Did not recognize directive "
          + Constants.EXTENSION_DIRECTIVE + ":=" + extension + ".");
    }
  }
  this.extension = extension;

  final String range = (String) headerEntry.getAttributes()
      .remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
  this.versionRange = range == null ? null : new VersionRange(range);

  this.attributes = headerEntry.getAttributes();
  final Filter filter = toFilter();
  if (null!=filter) {
    dirs.put(Constants.FILTER_DIRECTIVE, filter.toString());
  }
  this.directives = Collections.unmodifiableMap(dirs);
}