Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.jersey.model.internal;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.NameBinding;
import javax.ws.rs.core.Feature;
import javax.annotation.Priority;
import javax.inject.Scope;
import org.glassfish.jersey.Severity;
import org.glassfish.jersey.internal.Errors;
import org.glassfish.jersey.internal.LocalizationMessages;
import org.glassfish.jersey.internal.inject.Providers;
import org.glassfish.jersey.internal.util.Producer;
import org.glassfish.jersey.model.ContractProvider;
import org.glassfish.jersey.process.Inflector;
import org.glassfish.hk2.utilities.Binder;
import jersey.repackaged.com.google.common.base.Predicate;
import jersey.repackaged.com.google.common.base.Predicates;
import jersey.repackaged.com.google.common.collect.Maps;
import jersey.repackaged.com.google.common.collect.Sets;
/**
* An internal Jersey container for custom component classes and instances.
*
* The component bag can automatically compute a {@link ContractProvider contract provider} model
* for the registered component type and stores it with the component registration.
*
* The rules for managing components inside a component bag are derived from the
* rules of JAX-RS {@link javax.ws.rs.core.Configurable} API. In short:
*
*
The iteration order of registered components mirrors the registration order
* of these components.
*
There can be only one registration for any given component type.
*
Existing registrations cannot be overridden (any attempt to override
* an existing registration will be rejected).
*
*
*
* @author Marek Potociar (marek.potociar at oracle.com)
*/
public class ComponentBag {
/**
* A filtering strategy that excludes all pure meta-provider models (i.e. models that only contain
* recognized meta-provider contracts - {@link javax.ws.rs.core.Feature} and/or {@link org.glassfish.hk2.utilities.Binder}).
*
* This filter predicate returns {@code false} for all {@link org.glassfish.jersey.model.ContractProvider contract provider models}
* that represent a model containing only recognized meta-provider contracts.
*
*/
public static final Predicate EXCLUDE_META_PROVIDERS = new Predicate() {
@Override
public boolean apply(ContractProvider model) {
final Set> contracts = model.getContracts();
if (contracts.isEmpty()) {
return true;
}
byte count = 0;
if (contracts.contains(Feature.class)) {
count++;
}
if (contracts.contains(Binder.class)) {
count++;
}
return contracts.size() > count;
}
};
/**
* A filtering strategy that includes only models that contain HK2 Binder provider contract.
*
* This filter predicate returns {@code true} for all {@link org.glassfish.jersey.model.ContractProvider contract provider models}
* that represent a provider registered to provide HK2 {@link org.glassfish.hk2.utilities.Binder} contract.
*
*/
public static final Predicate BINDERS_ONLY = new Predicate() {
@Override
public boolean apply(ContractProvider model) {
return model.getContracts().contains(Binder.class);
}
};
/**
* A filtering strategy that excludes models with no recognized contracts.
*
* This filter predicate returns {@code false} for all {@link org.glassfish.jersey.model.ContractProvider contract provider models}
* that are empty, i.e. do not contain any recognized contracts.
*
*/
public static final Predicate EXCLUDE_EMPTY = new Predicate() {
@Override
public boolean apply(ContractProvider model) {
return !model.getContracts().isEmpty();
}
};
/**
* A filtering strategy that accepts any contract provider model.
*
* This filter predicate returns {@code true} for any contract provider model.
*
*/
public static final Predicate INCLUDE_ALL = Predicates.alwaysTrue();
/**
* Contract provider model enhancer that builds a model as is, without any
* modifications.
*/
public static final Inflector AS_IS =
new Inflector() {
@Override
public ContractProvider apply(ContractProvider.Builder builder) {
return builder.build();
}
};
/**
* Contract provider model registration strategy.
*/
private final Predicate registrationStrategy;
/**
* Registered component classes collection and it's immutable view.
*/
private final Set> classes;
private final Set> classesView;
/**
* Registered component instances collection and it's immutable view.
*/
private final Set