Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2015 Red Hat, Inc. Red Hat licenses this file to you under the Apache License, version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package io.fabric8.cdi.bean;
 
 
 
 import java.util.Map;
 
 public class ServiceBean<X> extends ProducerBean<X> {
 
     private static final String SUFFIX = "-service";
     private static final Map<KeyServiceBeanBEANS = new ConcurrentHashMap<>();
     
     private final String serviceName;
     private final String serviceProtocol;
     private final String serviceAlias;
     private final Boolean serviceExternal;
     
     public static <S> ServiceBean<S> getBean(String nameString protocolString aliasBoolean externalClass<S> type) {
         String serviceAlias = alias != null ? alias :
                 (external ? "external-" : "") + name + "-" + type.getName() + "-" + protocol + ;
         Key key = new Key(nameprotocolserviceAliasexternaltypenull);
         if (.containsKey(key)) {
             return .get(key);
         }
         ServiceBean bean = new ServiceBean(nameprotocolserviceAliastypenullexternal);
         .put(keybean);
         return bean;
     }
 
     public static <S> ServiceBean<S> anyBean(String idString protocolBoolean externalClass<S> type) {
         for (Map.Entry<KeyServiceBeanentry : .entrySet()) {
             Key key = entry.getKey();
             if (key.serviceName.equals(id)
                     && key.serviceProtocol.equals(protocol)
                     && key.type.equals(type)) {
                 return entry.getValue();
             }
         }
         return getBean(idprotocolnullexternaltype);
     }
     
     
     public static final Collection<ServiceBeangetBeans() {
         return .values();
     }
 
     public static void doWith(Type typeCallback callback) {
         for (Map.Entry<KeyServiceBeanentry : .entrySet()) {
             Key key = entry.getKey();
             if (type.equals(key.type)) {
                 ServiceBean newBean = callback.apply(.remove(key));
                 Key newKey = new Key(newBean.getId(), newBean.getServiceProtocol(), newBean.getServiceAlias(), newBean.getServiceExternal(), newBean.getBeanClass(), newBean.getProducer());
                 .put(newKeynewBean);
             }
         }
     }
     
     private ServiceBean(String serviceNameString serviceProtocolString serviceAliasClass typeProducer<X> producerBoolean serviceExternal) {
         super(serviceAliastypeproducer, Qualifiers.create(serviceNameserviceProtocolfalseserviceExternal));
         this. = serviceName;
         this. = serviceProtocol;
         this. = serviceAlias;
         this. = serviceExternal;
     }
 
     public ServiceBean withProducer(Producer producer) {
         return new ServiceBean(getBeanClass(), producer);
     }
 
     public String getServiceName() {
         return ;
     }
 
     public String getServiceProtocol() {
         return ;
     }
 
     public String getServiceAlias() {
         return ;
     }
    public Boolean getServiceExternal() {
        return ;
    }
    @Override
    public String toString() {
        return "ServiceBean[" +
                "serviceName='" +  + '\'' +
                ", serviceProtocol='" +  + '\'' +
                ", serviceAlias='" +  + '\'' +
                ", serviceExternal=" +  +
                ']';
    }
    private static final class Key {
        private final String serviceName;
        private final String serviceProtocol;
        private final String serviceAlias;
        private final Boolean serviceExternal;
        private final Class type;
        private final Producer producer;
        private Key(String serviceNameString serviceProtocolString serviceAliasBoolean serviceExternalClass typeProducer producer) {
            this. = serviceName;
            this. = serviceProtocol;
            this. = serviceAlias;
            this. = serviceExternal;
            this. = type;
            this. = producer;
        }
        @Override
        public boolean equals(Object o) {
            if (this == oreturn true;
            if (o == null || getClass() != o.getClass()) return false;
            Key key = (Keyo;
            if ( != null ? !.equals(key.producer) : key.producer != nullreturn false;
            if ( != null ? !.equals(key.serviceName) : key.serviceName != nullreturn false;
            if ( != null ? !.equals(key.serviceProtocol) : key.serviceProtocol != nullreturn false;
            if ( != null ? !.equals(key.serviceAlias) : key.serviceAlias != nullreturn false;
            if ( != null ? !.equals(key.serviceExternal) : key.serviceExternal != nullreturn false;
            if ( != null ? !.equals(key.type) : key.type != nullreturn false;
            return true;
        }
        @Override
        public int hashCode() {
            int result =  != null ? .hashCode() : 0;
            result = 31 * result + ( != null ? .hashCode() : 0);
            result = 31 * result + ( != null ? .hashCode() : 0);
            result = 31 * result + ( != null ? .hashCode() : 0);
            result = 31 * result + ( != null ? .hashCode() : 0);
            result = 31 * result + ( != null ? .hashCode() : 0);
            return result;
        }
    }
    
    public static interface Callback {
        public ServiceBean apply(ServiceBean bean);
        
    }
New to GrepCode? Check out our FAQ X