1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.felix.resolver.reason; 20 21 import java.util.Collection; 22 23 import org.osgi.resource.Requirement; 24 import org.osgi.service.resolver.ResolutionException; 25 26 /** 27 * An exception that holds the reason for a resolution failure. 28 * 29 * @see {@link ResolutionException} 30 */ 31 public class ReasonException extends ResolutionException { 32 33 /** 34 * The reasons for resolution failure. 35 */ 36 public static enum Reason { 37 /** 38 * Represents an unresolved package referenced by {@code Dynamic-ImportPackage}. 39 * <p> 40 * {@link ReasonException#getUnresolvedRequirements()} will return a 41 * collection containing the single {@code osgi.wiring.package;resolution:=dynamic} 42 * requirement which failed to resolve. 43 * <p> 44 * This reason has no a transitive cause. 45 */ 46 DynamicImport, 47 48 /** 49 * Represents the scenario where a fragment matches a host but is not 50 * selected because another fragment with the same {@code Bundle-SymbolicName} 51 * already matched, usually a fragment of a higher version. 52 * <p> 53 * {@link ReasonException#getUnresolvedRequirements()} will return 54 * a collection containing the single {@code osgi.wiring.host} requirement of 55 * the fragment. 56 * <p> 57 * This reason has no a transitive cause. 58 */ 59 FragmentNotSelected, 60 61 /** 62 * Represents the scenario where a requirement could not be resolved. 63 * <p> 64 * {@link ReasonException#getUnresolvedRequirements()} will return 65 * a collection containing a single requirement that didn't resolve. 66 * <p> 67 * This reason may have a transitive cause. 68 */ 69 MissingRequirement, 70 71 /** 72 * Represents a failure in the <em>use constraints</em> of a bundle. 73 * <p> 74 * {@link ReasonException#getUnresolvedRequirements()} will return 75 * a collection containing a single requirement to blame for the use constraint 76 * violation. 77 * <p> 78 * This reason has no a transitive cause. 79 */ 80 UseConstraint 81 } 82 83 private static final long serialVersionUID = -5276675175114379539L; 84 ReasonException(Reason reason, String message, Throwable cause, Collection<Requirement> unresolvedRequirements)85 public ReasonException(Reason reason, String message, Throwable cause, Collection<Requirement> unresolvedRequirements) { 86 super(message, cause, unresolvedRequirements); 87 this.reason = reason; 88 } 89 getReason()90 public Reason getReason() { 91 return reason; 92 } 93 94 private final Reason reason; 95 96 } 97