Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2012, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed 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 org.jboss.weld.serialization;
 
 
 
 
 import  edu.umd.cs.findbugs.annotations.SuppressWarnings;

Serializable holder for InjectionPoint.

Author(s):
Jozef Hartinger
 
 
     private static final long serialVersionUID = -6128821485743815308L;
 
     private final InjectionPointIdentifier identifier;
 
     public InjectionPointHolder(String contextIdInjectionPoint ip) {
         super(ip);
         if (ip.getBean() == null) {
             this. = new NoopInjectionPointIdentifier(ip);
         } else if (ip.getAnnotated() instanceof AnnotatedField<?>) {
             AnnotatedField<?> field = Reflections.cast(ip.getAnnotated());
             this. = new FieldInjectionPointIdentifier(contextIdip.getBean(), field);
         } else if (ip.getAnnotated() instanceof AnnotatedParameter<?>) {
             AnnotatedParameter<?> parameter = Reflections.cast(ip.getAnnotated());
             if (parameter.getDeclaringCallable() instanceof AnnotatedConstructor<?>) {
                 AnnotatedConstructor<?> constructor = Reflections.cast(parameter.getDeclaringCallable());
                 this. = new ConstructorParameterInjectionPointIdentifier(contextIdip.getBean(), parameter.getPosition(), constructor);
             } else if (parameter.getDeclaringCallable() instanceof AnnotatedMethod<?>) {
                 AnnotatedMethod<?> method = Reflections.cast(parameter.getDeclaringCallable());
                 this. = new MethodParameterInjectionPointIdentifier(contextIdip.getBean(), parameter.getPosition(), method);
             } else {
                 throw ..invalidAnnotatedCallable(parameter.getDeclaringCallable());
             }
         } else {
             throw ..invalidAnnotatedOfInjectionPoint(ip.getAnnotated(), ip);
         }
     }
 
     @Override
     protected InjectionPoint initialize() {
         return .restoreInjectionPoint();
     }
 
     private interface InjectionPointIdentifier extends Serializable {
     }

    
Noop implementation of InjectionPointIdentifier. An instance is serializable as long as the underlying InjectionPoint is serializable. This identifier should only be used to wrap InjectionPoints that do not belong to a bean.

Author(s):
Jozef Hartinger
 
     private static class NoopInjectionPointIdentifier implements InjectionPointIdentifier {
 
         private static final long serialVersionUID = 6952579330771485841L;
 
         @SuppressWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
         private final transient InjectionPoint ip;
 
         public NoopInjectionPointIdentifier(InjectionPoint ip) {
             this. = ip;
         }
 
         @Override
         public InjectionPoint restoreInjectionPoint() {
             return ;
        }
    }
    private abstract static class AbstractInjectionPointIdentifier implements InjectionPointIdentifier {
        private static final long serialVersionUID = -8167922066673252787L;
        private final BeanHolder<?> bean;
        public AbstractInjectionPointIdentifier(String contextIdBean<?> bean) {
            this. = BeanHolder.of(contextIdbean);
        }
        @Override
        public InjectionPoint restoreInjectionPoint() {
            InjectionPoint injectionPoint = null;
            for (InjectionPoint ip : .get().getInjectionPoints()) {
                if (matches(ip)) {
                    if (injectionPoint != null) {
                        throw ..unableToRestoreInjectionPointMultiple(.get(), injectionPointip);
                    }
                    injectionPoint = ip;
                }
            }
            if (injectionPoint == null) {
                throw ..unableToRestoreInjectionPoint(.get());
            }
            return injectionPoint;
        }
        protected abstract boolean matches(InjectionPoint ip);
    }
    private static class FieldInjectionPointIdentifier extends AbstractInjectionPointIdentifier {
        private static final long serialVersionUID = 4581216810217284043L;
        private final FieldHolder field;
        public FieldInjectionPointIdentifier(String contextIdBean<?> beanAnnotatedField<?> field) {
            super(contextIdbean);
            this. = new FieldHolder(field.getJavaMember());
        }
        @Override
        protected boolean matches(InjectionPoint ip) {
            if (ip.getAnnotated() instanceof AnnotatedField<?>) {
                AnnotatedField<?> annotatedField = Reflections.cast(ip.getAnnotated());
                return (.get().equals(annotatedField.getJavaMember()));
            }
            return false;
        }
    }
    private abstract static class AbstractParameterInjectionPointIdentifier extends AbstractInjectionPointIdentifier {
        private static final long serialVersionUID = -3618042716814281161L;
        private final int position;
        public AbstractParameterInjectionPointIdentifier(String contextIdBean<?> beanint position) {
            super(contextIdbean);
            this. = position;
        }
        @Override
        protected boolean matches(InjectionPoint ip) {
            if (ip.getAnnotated() instanceof AnnotatedParameter<?>) {
                AnnotatedParameter<?> annotatedParameter = Reflections.cast(ip.getAnnotated());
                return  == annotatedParameter.getPosition() && matches(ipannotatedParameter.getDeclaringCallable());
            }
            return false;
        }
        protected abstract boolean matches(InjectionPoint ipAnnotatedCallable<?> annotatedCallable);
    }
        private static final long serialVersionUID = 638702977751948835L;
        private final ConstructorHolder<?> constructor;
        public ConstructorParameterInjectionPointIdentifier(String contextIdBean<?> beanint positionAnnotatedConstructor<?> constructor) {
            super(contextIdbeanposition);
            this. = ConstructorHolder.of(constructor.getJavaMember());
        }
        @Override
        protected boolean matches(InjectionPoint ipAnnotatedCallable<?> annotatedCallable) {
            if (annotatedCallable instanceof AnnotatedConstructor<?>) {
                AnnotatedConstructor<?> annotatedConstructor = Reflections.cast(annotatedCallable);
                return .get().equals(annotatedConstructor.getJavaMember());
            }
            return false;
        }
    }
        private static final long serialVersionUID = -3263543692438746424L;
        private final MethodHolder method;
        public MethodParameterInjectionPointIdentifier(String contextIdBean<?> beanint positionAnnotatedMethod<?> constructor) {
            super(contextIdbeanposition);
            this. = MethodHolder.of(constructor);
        }
        @Override
        protected boolean matches(InjectionPoint ipAnnotatedCallable<?> annotatedCallable) {
            if (annotatedCallable instanceof AnnotatedMethod<?>) {
                AnnotatedMethod<?> annotatedMethod = Reflections.cast(annotatedCallable);
                return .get().equals(annotatedMethod.getJavaMember());
            }
            return false;
        }
    }
New to GrepCode? Check out our FAQ X