idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
26,500
private boolean hasAbstractPackagePrivateSuperClassWithImplementation ( Class < ? > clazz , BridgeMethod bridgeMethod ) { Class < ? > superClass = clazz . getSuperclass ( ) ; while ( superClass != null ) { if ( Modifier . isAbstract ( superClass . getModifiers ( ) ) && Reflections . isPackagePrivate ( superClass . getModifiers ( ) ) ) { for ( Method method : superClass . getDeclaredMethods ( ) ) { if ( bridgeMethod . signature . matches ( method ) && method . getGenericReturnType ( ) . equals ( bridgeMethod . returnType ) && ! Reflections . isAbstract ( method ) ) { return true ; } } } superClass = superClass . getSuperclass ( ) ; } return false ; }
Returns true if super class of the parameter exists and is abstract and package private . In such case we want to omit such method .
26,501
protected void addSpecialMethods ( ClassFile proxyClassType , ClassMethod staticConstructor ) { try { for ( Method method : LifecycleMixin . class . getMethods ( ) ) { BeanLogger . LOG . addingMethodToProxy ( method ) ; MethodInformation methodInfo = new RuntimeMethodInformation ( method ) ; createInterceptorBody ( proxyClassType . addMethod ( method ) , methodInfo , false , staticConstructor ) ; } Method getInstanceMethod = TargetInstanceProxy . class . getMethod ( "weld_getTargetInstance" ) ; Method getInstanceClassMethod = TargetInstanceProxy . class . getMethod ( "weld_getTargetClass" ) ; generateGetTargetInstanceBody ( proxyClassType . addMethod ( getInstanceMethod ) ) ; generateGetTargetClassBody ( proxyClassType . addMethod ( getInstanceClassMethod ) ) ; Method setMethodHandlerMethod = ProxyObject . class . getMethod ( "weld_setHandler" , MethodHandler . class ) ; generateSetMethodHandlerBody ( proxyClassType . addMethod ( setMethodHandlerMethod ) ) ; Method getMethodHandlerMethod = ProxyObject . class . getMethod ( "weld_getHandler" ) ; generateGetMethodHandlerBody ( proxyClassType . addMethod ( getMethodHandlerMethod ) ) ; } catch ( Exception e ) { throw new WeldException ( e ) ; } }
Adds methods requiring special implementations rather than just delegation .
26,502
public static void checkDelegateType ( Decorator < ? > decorator ) { Set < Type > types = new HierarchyDiscovery ( decorator . getDelegateType ( ) ) . getTypeClosure ( ) ; for ( Type decoratedType : decorator . getDecoratedTypes ( ) ) { if ( ! types . contains ( decoratedType ) ) { throw BeanLogger . LOG . delegateMustSupportEveryDecoratedType ( decoratedType , decorator ) ; } } }
Check whether the delegate type implements or extends all decorated types .
26,503
public static < T > void checkAbstractMethods ( Set < Type > decoratedTypes , EnhancedAnnotatedType < T > type , BeanManagerImpl beanManager ) { if ( decoratedTypes == null ) { decoratedTypes = new HashSet < Type > ( type . getInterfaceClosure ( ) ) ; decoratedTypes . remove ( Serializable . class ) ; } Set < MethodSignature > signatures = new HashSet < MethodSignature > ( ) ; for ( Type decoratedType : decoratedTypes ) { for ( EnhancedAnnotatedMethod < ? , ? > method : ClassTransformer . instance ( beanManager ) . getEnhancedAnnotatedType ( Reflections . getRawType ( decoratedType ) , beanManager . getId ( ) ) . getEnhancedMethods ( ) ) { signatures . add ( method . getSignature ( ) ) ; } } for ( EnhancedAnnotatedMethod < ? , ? > method : type . getEnhancedMethods ( ) ) { if ( Reflections . isAbstract ( ( ( AnnotatedMethod < ? > ) method ) . getJavaMember ( ) ) ) { MethodSignature methodSignature = method . getSignature ( ) ; if ( ! signatures . contains ( methodSignature ) ) { throw BeanLogger . LOG . abstractMethodMustMatchDecoratedType ( method , Formats . formatAsStackTraceElement ( method . getJavaMember ( ) ) ) ; } } } }
Check all abstract methods are declared by the decorated types .
26,504
public void checkSpecialization ( ) { if ( isSpecializing ( ) ) { boolean isNameDefined = getAnnotated ( ) . isAnnotationPresent ( Named . class ) ; String previousSpecializedBeanName = null ; for ( AbstractBean < ? , ? > specializedBean : getSpecializedBeans ( ) ) { String name = specializedBean . getName ( ) ; if ( previousSpecializedBeanName != null && name != null && ! previousSpecializedBeanName . equals ( specializedBean . getName ( ) ) ) { throw BeanLogger . LOG . beansWithDifferentBeanNamesCannotBeSpecialized ( previousSpecializedBeanName , specializedBean . getName ( ) , this ) ; } previousSpecializedBeanName = name ; if ( isNameDefined && name != null ) { throw BeanLogger . LOG . nameNotAllowedOnSpecialization ( getAnnotated ( ) , specializedBean . getAnnotated ( ) ) ; } boolean rawInsteadOfGeneric = ( this instanceof AbstractClassBean < ? > && specializedBean . getBeanClass ( ) . getTypeParameters ( ) . length > 0 && ! ( ( ( AbstractClassBean < ? > ) this ) . getBeanClass ( ) . getGenericSuperclass ( ) instanceof ParameterizedType ) ) ; for ( Type specializedType : specializedBean . getTypes ( ) ) { if ( rawInsteadOfGeneric && specializedType instanceof ParameterizedType ) { throw BeanLogger . LOG . specializingBeanMissingSpecializedType ( this , specializedType , specializedBean ) ; } boolean contains = getTypes ( ) . contains ( specializedType ) ; if ( ! contains ) { for ( Type specializingType : getTypes ( ) ) { if ( TypeEqualitySpecializationUtils . areTheSame ( specializingType , specializedType ) ) { contains = true ; break ; } } } if ( ! contains ) { throw BeanLogger . LOG . specializingBeanMissingSpecializedType ( this , specializedType , specializedBean ) ; } } } } }
Validates specialization if this bean specializes another bean .
26,505
public void fireEvent ( Type eventType , Object event , Annotation ... qualifiers ) { final EventMetadata metadata = new EventMetadataImpl ( eventType , null , qualifiers ) ; notifier . fireEvent ( eventType , event , metadata , qualifiers ) ; }
Fire an event and notify observers that belong to this module .
26,506
@ SuppressWarnings ( "unchecked" ) public static < T > T getJlsDefaultValue ( Class < T > type ) { if ( ! type . isPrimitive ( ) ) { return null ; } return ( T ) JLS_PRIMITIVE_DEFAULT_VALUES . get ( type ) ; }
See also JLS8 4 . 12 . 5 Initial Values of Variables .
26,507
public void afterDeploymentValidation ( @ Priority ( 1 ) AfterDeploymentValidation event , BeanManager beanManager ) { BeanManagerImpl manager = BeanManagerProxy . unwrap ( beanManager ) ; probe . init ( manager ) ; if ( isJMXSupportEnabled ( manager ) ) { try { MBeanServer mbs = ManagementFactory . getPlatformMBeanServer ( ) ; mbs . registerMBean ( new ProbeDynamicMBean ( jsonDataProvider , JsonDataProvider . class ) , constructProbeJsonDataMBeanName ( manager , probe ) ) ; } catch ( MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e ) { event . addDeploymentProblem ( ProbeLogger . LOG . unableToRegisterMBean ( JsonDataProvider . class , manager . getContextId ( ) , e ) ) ; } } addContainerLifecycleEvent ( event , null , beanManager ) ; exportDataIfNeeded ( manager ) ; }
any possible bean invocations from other ADV observers
26,508
static boolean matchPath ( String [ ] tokenizedPattern , String [ ] strDirs , boolean isCaseSensitive ) { int patIdxStart = 0 ; int patIdxEnd = tokenizedPattern . length - 1 ; int strIdxStart = 0 ; int strIdxEnd = strDirs . length - 1 ; while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd ) { String patDir = tokenizedPattern [ patIdxStart ] ; if ( patDir . equals ( DEEP_TREE_MATCH ) ) { break ; } if ( ! match ( patDir , strDirs [ strIdxStart ] , isCaseSensitive ) ) { return false ; } patIdxStart ++ ; strIdxStart ++ ; } if ( strIdxStart > strIdxEnd ) { for ( int i = patIdxStart ; i <= patIdxEnd ; i ++ ) { if ( ! tokenizedPattern [ i ] . equals ( DEEP_TREE_MATCH ) ) { return false ; } } return true ; } else { if ( patIdxStart > patIdxEnd ) { return false ; } } while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd ) { String patDir = tokenizedPattern [ patIdxEnd ] ; if ( patDir . equals ( DEEP_TREE_MATCH ) ) { break ; } if ( ! match ( patDir , strDirs [ strIdxEnd ] , isCaseSensitive ) ) { return false ; } patIdxEnd -- ; strIdxEnd -- ; } if ( strIdxStart > strIdxEnd ) { for ( int i = patIdxStart ; i <= patIdxEnd ; i ++ ) { if ( ! tokenizedPattern [ i ] . equals ( DEEP_TREE_MATCH ) ) { return false ; } } return true ; } while ( patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd ) { int patIdxTmp = - 1 ; for ( int i = patIdxStart + 1 ; i <= patIdxEnd ; i ++ ) { if ( tokenizedPattern [ i ] . equals ( DEEP_TREE_MATCH ) ) { patIdxTmp = i ; break ; } } if ( patIdxTmp == patIdxStart + 1 ) { patIdxStart ++ ; continue ; } int patLength = ( patIdxTmp - patIdxStart - 1 ) ; int strLength = ( strIdxEnd - strIdxStart + 1 ) ; int foundIdx = - 1 ; strLoop : for ( int i = 0 ; i <= strLength - patLength ; i ++ ) { for ( int j = 0 ; j < patLength ; j ++ ) { String subPat = tokenizedPattern [ patIdxStart + j + 1 ] ; String subStr = strDirs [ strIdxStart + i + j ] ; if ( ! match ( subPat , subStr , isCaseSensitive ) ) { continue strLoop ; } } foundIdx = strIdxStart + i ; break ; } if ( foundIdx == - 1 ) { return false ; } patIdxStart = patIdxTmp ; strIdxStart = foundIdx + patLength ; } for ( int i = patIdxStart ; i <= patIdxEnd ; i ++ ) { if ( ! tokenizedPattern [ i ] . equals ( DEEP_TREE_MATCH ) ) { return false ; } } return true ; }
Core implementation of matchPath . It is isolated so that it can be called from TokenizedPattern .
26,509
static String [ ] tokenize ( String str ) { char sep = '.' ; int start = 0 ; int len = str . length ( ) ; int count = 0 ; for ( int pos = 0 ; pos < len ; pos ++ ) { if ( str . charAt ( pos ) == sep ) { if ( pos != start ) { count ++ ; } start = pos + 1 ; } } if ( len != start ) { count ++ ; } String [ ] l = new String [ count ] ; count = 0 ; start = 0 ; for ( int pos = 0 ; pos < len ; pos ++ ) { if ( str . charAt ( pos ) == sep ) { if ( pos != start ) { String tok = str . substring ( start , pos ) ; l [ count ++ ] = tok ; } start = pos + 1 ; } } if ( len != start ) { String tok = str . substring ( start ) ; l [ count ] = tok ; } return l ; }
Tokenize the the string as a package hierarchy
26,510
void endIfStarted ( CodeAttribute b , ClassMethod method ) { b . aload ( getLocalVariableIndex ( 0 ) ) ; b . dup ( ) ; final BranchEnd ifnotnull = b . ifnull ( ) ; b . checkcast ( Stack . class ) ; b . invokevirtual ( Stack . class . getName ( ) , END_INTERCEPTOR_CONTEXT_METHOD_NAME , EMPTY_PARENTHESES + VOID_CLASS_DESCRIPTOR ) ; BranchEnd ifnull = b . gotoInstruction ( ) ; b . branchEnd ( ifnotnull ) ; b . pop ( ) ; b . branchEnd ( ifnull ) ; }
Ends interception context if it was previously stated . This is indicated by a local variable with index 0 .
26,511
@ SuppressFBWarnings ( value = "UL_UNRELEASED_LOCK" , justification = "False positive from FindBugs" ) public < T > T get ( Contextual < T > contextual , CreationalContext < T > creationalContext ) { if ( ! isActive ( ) ) { throw new ContextNotActiveException ( ) ; } checkContextInitialized ( ) ; final BeanStore beanStore = getBeanStore ( ) ; if ( beanStore == null ) { return null ; } if ( contextual == null ) { throw ContextLogger . LOG . contextualIsNull ( ) ; } BeanIdentifier id = getId ( contextual ) ; ContextualInstance < T > beanInstance = beanStore . get ( id ) ; if ( beanInstance != null ) { return beanInstance . getInstance ( ) ; } else if ( creationalContext != null ) { LockedBean lock = null ; try { if ( multithreaded ) { lock = beanStore . lock ( id ) ; beanInstance = beanStore . get ( id ) ; if ( beanInstance != null ) { return beanInstance . getInstance ( ) ; } } T instance = contextual . create ( creationalContext ) ; if ( instance != null ) { beanInstance = new SerializableContextualInstanceImpl < Contextual < T > , T > ( contextual , instance , creationalContext , serviceRegistry . get ( ContextualStore . class ) ) ; beanStore . put ( id , beanInstance ) ; } return instance ; } finally { if ( lock != null ) { lock . unlock ( ) ; } } } else { return null ; } }
Get the bean if it exists in the contexts .
26,512
protected void destroy ( ) { ContextLogger . LOG . contextCleared ( this ) ; final BeanStore beanStore = getBeanStore ( ) ; if ( beanStore == null ) { throw ContextLogger . LOG . noBeanStoreAvailable ( this ) ; } for ( BeanIdentifier id : beanStore ) { destroyContextualInstance ( beanStore . get ( id ) ) ; } beanStore . clear ( ) ; }
Destroys the context
26,513
public static < T > boolean addAll ( Collection < T > target , Iterable < ? extends T > iterable ) { if ( iterable instanceof Collection ) { return target . addAll ( ( Collection < ? extends T > ) iterable ) ; } return Iterators . addAll ( target , iterable . iterator ( ) ) ; }
Add all elements in the iterable to the collection .
26,514
public < T > Producer < T > createProducer ( final Bean < X > declaringBean , final Bean < T > bean , DisposalMethod < X , T > disposalMethod ) { EnhancedAnnotatedField < T , X > enhancedField = getManager ( ) . getServices ( ) . get ( MemberTransformer . class ) . loadEnhancedMember ( field , getManager ( ) . getId ( ) ) ; return new ProducerFieldProducer < X , T > ( enhancedField , disposalMethod ) { public AnnotatedField < X > getAnnotated ( ) { return field ; } public BeanManagerImpl getBeanManager ( ) { return getManager ( ) ; } public Bean < X > getDeclaringBean ( ) { return declaringBean ; } public Bean < T > getBean ( ) { return bean ; } } ; }
Producers returned from this method are not validated . Internal use only .
26,515
protected WeldBeanDeploymentArchive createAdditionalBeanDeploymentArchive ( ) { WeldBeanDeploymentArchive additionalBda = new WeldBeanDeploymentArchive ( ADDITIONAL_BDA_ID , Collections . synchronizedSet ( new HashSet < String > ( ) ) , null ) ; additionalBda . getServices ( ) . addAll ( getServices ( ) . entrySet ( ) ) ; beanDeploymentArchives . add ( additionalBda ) ; setBeanDeploymentArchivesAccessibility ( ) ; return additionalBda ; }
Additional bean deployment archives are used for extentions synthetic annotated types and beans which do not come from a bean archive .
26,516
protected void setBeanDeploymentArchivesAccessibility ( ) { for ( WeldBeanDeploymentArchive beanDeploymentArchive : beanDeploymentArchives ) { Set < WeldBeanDeploymentArchive > accessibleArchives = new HashSet < > ( ) ; for ( WeldBeanDeploymentArchive candidate : beanDeploymentArchives ) { if ( candidate . equals ( beanDeploymentArchive ) ) { continue ; } accessibleArchives . add ( candidate ) ; } beanDeploymentArchive . setAccessibleBeanDeploymentArchives ( accessibleArchives ) ; } }
By default all bean archives see each other .
26,517
static Type parseType ( String value , ResourceLoader resourceLoader ) { value = value . trim ( ) ; if ( value . equals ( WILDCARD ) ) { return WildcardTypeImpl . defaultInstance ( ) ; } if ( value . startsWith ( WILDCARD_EXTENDS ) ) { Type upperBound = parseType ( value . substring ( WILDCARD_EXTENDS . length ( ) , value . length ( ) ) , resourceLoader ) ; if ( upperBound == null ) { return null ; } return WildcardTypeImpl . withUpperBound ( upperBound ) ; } if ( value . startsWith ( WILDCARD_SUPER ) ) { Type lowerBound = parseType ( value . substring ( WILDCARD_SUPER . length ( ) , value . length ( ) ) , resourceLoader ) ; if ( lowerBound == null ) { return null ; } return WildcardTypeImpl . withLowerBound ( lowerBound ) ; } if ( value . contains ( ARRAY ) ) { Type componentType = parseType ( value . substring ( 0 , value . indexOf ( ARRAY ) ) , resourceLoader ) ; if ( componentType == null ) { return null ; } return new GenericArrayTypeImpl ( componentType ) ; } int chevLeft = value . indexOf ( CHEVRONS_LEFT ) ; String rawValue = chevLeft < 0 ? value : value . substring ( 0 , chevLeft ) ; Class < ? > rawRequiredType = tryLoadClass ( rawValue , resourceLoader ) ; if ( rawRequiredType == null ) { return null ; } if ( rawRequiredType . getTypeParameters ( ) . length == 0 ) { return rawRequiredType ; } int chevRight = value . lastIndexOf ( CHEVRONS_RIGHT ) ; if ( chevRight < 0 ) { return null ; } List < String > parts = split ( value . substring ( chevLeft + 1 , chevRight ) , ',' , CHEVRONS_LEFT . charAt ( 0 ) , CHEVRONS_RIGHT . charAt ( 0 ) ) ; Type [ ] typeParameters = new Type [ parts . size ( ) ] ; for ( int i = 0 ; i < typeParameters . length ; i ++ ) { Type typeParam = parseType ( parts . get ( i ) , resourceLoader ) ; if ( typeParam == null ) { return null ; } typeParameters [ i ] = typeParam ; } return new ParameterizedTypeImpl ( rawRequiredType , typeParameters ) ; }
Type variables are not supported .
26,518
public static boolean isPortletEnvSupported ( ) { if ( enabled == null ) { synchronized ( PortletSupport . class ) { if ( enabled == null ) { try { PortletSupport . class . getClassLoader ( ) . loadClass ( "javax.portlet.PortletContext" ) ; enabled = true ; } catch ( Throwable ignored ) { enabled = false ; } } } } return enabled ; }
Is portlet env supported .
26,519
public static BeanManager getBeanManager ( Object ctx ) { return ( BeanManager ) javax . portlet . PortletContext . class . cast ( ctx ) . getAttribute ( WeldServletLifecycle . BEAN_MANAGER_ATTRIBUTE_NAME ) ; }
Get bean manager from portlet context .
26,520
private < T > List < Class < ? > > filter ( List < Class < ? > > enabledClasses , List < Class < ? > > globallyEnabledClasses , LogMessageCallback logMessageCallback , BeanDeployment deployment ) { for ( Iterator < Class < ? > > iterator = enabledClasses . iterator ( ) ; iterator . hasNext ( ) ; ) { Class < ? > enabledClass = iterator . next ( ) ; if ( globallyEnabledClasses . contains ( enabledClass ) ) { logMessageCallback . log ( enabledClass , deployment . getBeanDeploymentArchive ( ) . getId ( ) ) ; iterator . remove ( ) ; } } return enabledClasses ; }
Filter out interceptors and decorators which are also enabled globally .
26,521
public F resolve ( R resolvable , boolean cache ) { R wrappedResolvable = wrap ( resolvable ) ; if ( cache ) { return resolved . getValue ( wrappedResolvable ) ; } else { return resolverFunction . apply ( wrappedResolvable ) ; } }
Get the possible beans for the given element
26,522
private Set < T > findMatching ( R resolvable ) { Set < T > result = new HashSet < T > ( ) ; for ( T bean : getAllBeans ( resolvable ) ) { if ( matches ( resolvable , bean ) ) { result . add ( bean ) ; } } return result ; }
Gets the matching beans for binding criteria from a list of beans
26,523
public < X > Set < DisposalMethod < X , ? > > resolveDisposalBeans ( Set < Type > types , Set < Annotation > qualifiers , AbstractClassBean < X > declaringBean ) { Set < DisposalMethod < X , ? > > beans = cast ( disposalMethodResolver . resolve ( new ResolvableBuilder ( manager ) . addTypes ( types ) . addQualifiers ( qualifiers ) . setDeclaringBean ( declaringBean ) . create ( ) , true ) ) ; resolvedDisposalBeans . addAll ( beans ) ; return Collections . unmodifiableSet ( beans ) ; }
Resolve the disposal method for the given producer method . Any resolved beans will be marked as such for the purpose of validating that all disposal methods are used . For internal use .
26,524
private static < T > Set < Type > getSessionBeanTypes ( EnhancedAnnotated < T , ? > annotated , EjbDescriptor < T > ejbDescriptor ) { ImmutableSet . Builder < Type > types = ImmutableSet . builder ( ) ; Map < Class < ? > , Type > typeMap = new LinkedHashMap < Class < ? > , Type > ( ) ; HierarchyDiscovery beanClassDiscovery = HierarchyDiscovery . forNormalizedType ( ejbDescriptor . getBeanClass ( ) ) ; for ( BusinessInterfaceDescriptor < ? > businessInterfaceDescriptor : ejbDescriptor . getLocalBusinessInterfaces ( ) ) { Type resolvedLocalInterface = beanClassDiscovery . resolveType ( Types . getCanonicalType ( businessInterfaceDescriptor . getInterface ( ) ) ) ; SessionBeanHierarchyDiscovery interfaceDiscovery = new SessionBeanHierarchyDiscovery ( resolvedLocalInterface ) ; if ( beanClassDiscovery . getTypeMap ( ) . containsKey ( businessInterfaceDescriptor . getInterface ( ) ) ) { for ( Entry < Class < ? > , Type > entry : interfaceDiscovery . getTypeMap ( ) . entrySet ( ) ) { if ( annotated . getTypeClosure ( ) . contains ( entry . getValue ( ) ) ) { typeMap . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } } } else { typeMap . putAll ( interfaceDiscovery . getTypeMap ( ) ) ; } } if ( annotated . isAnnotationPresent ( Typed . class ) ) { types . addAll ( Beans . getTypedTypes ( typeMap , annotated . getJavaClass ( ) , annotated . getAnnotation ( Typed . class ) ) ) ; } else { typeMap . put ( Object . class , Object . class ) ; types . addAll ( typeMap . values ( ) ) ; } return Beans . getLegalBeanTypes ( types . build ( ) , annotated ) ; }
Bean types of a session bean .
26,525
public static < T > SessionBean < T > of ( BeanAttributes < T > attributes , InternalEjbDescriptor < T > ejbDescriptor , BeanManagerImpl beanManager , EnhancedAnnotatedType < T > type ) { return new SessionBeanImpl < T > ( attributes , type , ejbDescriptor , new StringBeanIdentifier ( SessionBeans . createIdentifier ( type , ejbDescriptor ) ) , beanManager ) ; }
Creates a simple annotation defined Enterprise Web Bean using the annotations specified on type
26,526
protected void checkConflictingRoles ( ) { if ( getType ( ) . isAnnotationPresent ( Interceptor . class ) ) { throw BeanLogger . LOG . ejbCannotBeInterceptor ( getType ( ) ) ; } if ( getType ( ) . isAnnotationPresent ( Decorator . class ) ) { throw BeanLogger . LOG . ejbCannotBeDecorator ( getType ( ) ) ; } }
Validates for non - conflicting roles
26,527
protected void checkScopeAllowed ( ) { if ( ejbDescriptor . isStateless ( ) && ! isDependent ( ) ) { throw BeanLogger . LOG . scopeNotAllowedOnStatelessSessionBean ( getScope ( ) , getType ( ) ) ; } if ( ejbDescriptor . isSingleton ( ) && ! ( isDependent ( ) || getScope ( ) . equals ( ApplicationScoped . class ) ) ) { throw BeanLogger . LOG . scopeNotAllowedOnSingletonBean ( getScope ( ) , getType ( ) ) ; } }
Check that the scope type is allowed by the stereotypes on the bean and the bean type
26,528
protected void checkObserverMethods ( ) { Collection < EnhancedAnnotatedMethod < ? , ? super T > > observerMethods = BeanMethods . getObserverMethods ( this . getEnhancedAnnotated ( ) ) ; Collection < EnhancedAnnotatedMethod < ? , ? super T > > asyncObserverMethods = BeanMethods . getAsyncObserverMethods ( this . getEnhancedAnnotated ( ) ) ; checkObserverMethods ( observerMethods ) ; checkObserverMethods ( asyncObserverMethods ) ; }
If there are any observer methods they must be static or business methods .
26,529
public static < T > NewManagedBean < T > of ( BeanAttributes < T > attributes , EnhancedAnnotatedType < T > clazz , BeanManagerImpl beanManager ) { return new NewManagedBean < T > ( attributes , clazz , new StringBeanIdentifier ( BeanIdentifiers . forNewManagedBean ( clazz ) ) , beanManager ) ; }
Creates an instance of a NewSimpleBean from an annotated class
26,530
public Object invoke ( Object self , Method method , Method proceed , Object [ ] args ) throws Throwable { if ( "destroy" . equals ( method . getName ( ) ) && Marker . isMarker ( 0 , method , args ) ) { if ( bean . getEjbDescriptor ( ) . isStateful ( ) ) { if ( ! reference . isRemoved ( ) ) { reference . remove ( ) ; } } return null ; } if ( ! bean . isClientCanCallRemoveMethods ( ) && isRemoveMethod ( method ) ) { throw BeanLogger . LOG . invalidRemoveMethodInvocation ( method ) ; } Class < ? > businessInterface = getBusinessInterface ( method ) ; if ( reference . isRemoved ( ) && isToStringMethod ( method ) ) { return businessInterface . getName ( ) + " [REMOVED]" ; } Object proxiedInstance = reference . getBusinessObject ( businessInterface ) ; if ( ! Modifier . isPublic ( method . getModifiers ( ) ) ) { throw new EJBException ( "Not a business method " + method . toString ( ) + ". Do not call non-public methods on EJB's." ) ; } Object returnValue = Reflections . invokeAndUnwrap ( proxiedInstance , method , args ) ; BeanLogger . LOG . callProxiedMethod ( method , proxiedInstance , args , returnValue ) ; return returnValue ; }
Looks up the EJB in the container and executes the method on it
26,531
private < T > void deferNotification ( T event , final EventMetadata metadata , final ObserverMethod < ? super T > observer , final List < DeferredEventNotification < ? > > notifications ) { TransactionPhase transactionPhase = observer . getTransactionPhase ( ) ; boolean before = transactionPhase . equals ( TransactionPhase . BEFORE_COMPLETION ) ; Status status = Status . valueOf ( transactionPhase ) ; notifications . add ( new DeferredEventNotification < T > ( contextId , event , metadata , observer , currentEventMetadata , status , before ) ) ; }
Defers an event for processing in a later phase of the current transaction .
26,532
public void build ( Set < Bean < ? > > beans ) { if ( isBuilt ( ) ) { throw new IllegalStateException ( "BeanIdentifier index is already built!" ) ; } if ( beans . isEmpty ( ) ) { index = new BeanIdentifier [ 0 ] ; reverseIndex = Collections . emptyMap ( ) ; indexHash = 0 ; indexBuilt . set ( true ) ; return ; } List < BeanIdentifier > tempIndex = new ArrayList < BeanIdentifier > ( beans . size ( ) ) ; for ( Bean < ? > bean : beans ) { if ( bean instanceof CommonBean < ? > ) { tempIndex . add ( ( ( CommonBean < ? > ) bean ) . getIdentifier ( ) ) ; } else if ( bean instanceof PassivationCapable ) { tempIndex . add ( new StringBeanIdentifier ( ( ( PassivationCapable ) bean ) . getId ( ) ) ) ; } } Collections . sort ( tempIndex , new Comparator < BeanIdentifier > ( ) { public int compare ( BeanIdentifier o1 , BeanIdentifier o2 ) { return o1 . asString ( ) . compareTo ( o2 . asString ( ) ) ; } } ) ; index = tempIndex . toArray ( new BeanIdentifier [ tempIndex . size ( ) ] ) ; ImmutableMap . Builder < BeanIdentifier , Integer > builder = ImmutableMap . builder ( ) ; for ( int i = 0 ; i < index . length ; i ++ ) { builder . put ( index [ i ] , i ) ; } reverseIndex = builder . build ( ) ; indexHash = Arrays . hashCode ( index ) ; if ( BootstrapLogger . LOG . isDebugEnabled ( ) ) { BootstrapLogger . LOG . beanIdentifierIndexBuilt ( getDebugInfo ( ) ) ; } indexBuilt . set ( true ) ; }
Note that the index can only be built once .
26,533
public static < T > FastEvent < T > of ( Class < T > type , BeanManagerImpl manager , ObserverNotifier notifier , Annotation ... qualifiers ) { ResolvedObservers < T > resolvedObserverMethods = notifier . < T > resolveObserverMethods ( type , qualifiers ) ; if ( resolvedObserverMethods . isMetadataRequired ( ) ) { EventMetadata metadata = new EventMetadataImpl ( type , null , qualifiers ) ; CurrentEventMetadata metadataService = manager . getServices ( ) . get ( CurrentEventMetadata . class ) ; return new FastEventWithMetadataPropagation < T > ( resolvedObserverMethods , metadata , metadataService ) ; } else { return new FastEvent < T > ( resolvedObserverMethods ) ; } }
Constructs a new FastEvent instance
26,534
public static < T > List < T > copyOf ( T [ ] elements ) { Preconditions . checkNotNull ( elements ) ; return ofInternal ( elements . clone ( ) ) ; }
Creates an immutable list that consists of the elements in the given array . A copy of the given array is used which means that any modifications to the given array will not affect the immutable list .
26,535
public static < T > List < T > copyOf ( Collection < T > source ) { Preconditions . checkNotNull ( source ) ; if ( source instanceof ImmutableList < ? > ) { return ( ImmutableList < T > ) source ; } if ( source . isEmpty ( ) ) { return Collections . emptyList ( ) ; } return ofInternal ( source . toArray ( ) ) ; }
Creates an immutable list that consists of the elements in the given collection . If the given collection is already an immutable list it is returned directly .
26,536
public static Set < Annotation > filterInterceptorBindings ( BeanManagerImpl beanManager , Collection < Annotation > annotations ) { Set < Annotation > interceptorBindings = new InterceptorBindingSet ( beanManager ) ; for ( Annotation annotation : annotations ) { if ( beanManager . isInterceptorBinding ( annotation . annotationType ( ) ) ) { interceptorBindings . add ( annotation ) ; } } return interceptorBindings ; }
Extracts a set of interceptor bindings from a collection of annotations .
26,537
public static Set < Annotation > flattenInterceptorBindings ( EnhancedAnnotatedType < ? > clazz , BeanManagerImpl beanManager , Collection < Annotation > annotations , boolean addTopLevelInterceptorBindings , boolean addInheritedInterceptorBindings ) { Set < Annotation > flattenInterceptorBindings = new InterceptorBindingSet ( beanManager ) ; MetaAnnotationStore metaAnnotationStore = beanManager . getServices ( ) . get ( MetaAnnotationStore . class ) ; if ( addTopLevelInterceptorBindings ) { addInterceptorBindings ( clazz , annotations , flattenInterceptorBindings , metaAnnotationStore ) ; } if ( addInheritedInterceptorBindings ) { for ( Annotation annotation : annotations ) { addInheritedInterceptorBindings ( clazz , annotation . annotationType ( ) , metaAnnotationStore , flattenInterceptorBindings ) ; } } return flattenInterceptorBindings ; }
Extracts a flat set of interception bindings from a given set of interceptor bindings .
26,538
protected void validateRIBean ( CommonBean < ? > bean , BeanManagerImpl beanManager , Collection < CommonBean < ? > > specializedBeans ) { validateGeneralBean ( bean , beanManager ) ; if ( bean instanceof NewBean ) { return ; } if ( bean instanceof DecorableBean ) { validateDecorators ( beanManager , ( DecorableBean < ? > ) bean ) ; } if ( ( bean instanceof AbstractClassBean < ? > ) ) { AbstractClassBean < ? > classBean = ( AbstractClassBean < ? > ) bean ; if ( classBean . hasInterceptors ( ) ) { validateInterceptors ( beanManager , classBean ) ; } } if ( bean instanceof AbstractProducerBean < ? , ? , ? > ) { AbstractProducerBean < ? , ? , ? > producerBean = Reflections . < AbstractProducerBean < ? , ? , ? > > cast ( bean ) ; if ( producerBean . getProducer ( ) instanceof AbstractMemberProducer < ? , ? > ) { AbstractMemberProducer < ? , ? > producer = Reflections . < AbstractMemberProducer < ? , ? > > cast ( producerBean . getProducer ( ) ) ; if ( producer . getDisposalMethod ( ) != null ) { for ( InjectionPoint ip : producer . getDisposalMethod ( ) . getInjectionPoints ( ) ) { validateInjectionPointForDefinitionErrors ( ip , null , beanManager ) ; validateMetadataInjectionPoint ( ip , null , ValidatorLogger . INJECTION_INTO_DISPOSER_METHOD ) ; validateEventMetadataInjectionPoint ( ip ) ; validateInjectionPointForDeploymentProblems ( ip , null , beanManager ) ; } } } } }
Validate an RIBean . This includes validating whether two beans specialize the same bean
26,539
public void validateInjectionPoint ( InjectionPoint ij , BeanManagerImpl beanManager ) { validateInjectionPointForDefinitionErrors ( ij , ij . getBean ( ) , beanManager ) ; validateMetadataInjectionPoint ( ij , ij . getBean ( ) , ValidatorLogger . INJECTION_INTO_NON_BEAN ) ; validateEventMetadataInjectionPoint ( ij ) ; validateInjectionPointForDeploymentProblems ( ij , ij . getBean ( ) , beanManager ) ; }
Validate an injection point
26,540
private static void validatePseudoScopedBean ( Bean < ? > bean , BeanManagerImpl beanManager ) { if ( bean . getInjectionPoints ( ) . isEmpty ( ) ) { return ; } reallyValidatePseudoScopedBean ( bean , beanManager , new LinkedHashSet < Object > ( ) , new HashSet < Bean < ? > > ( ) ) ; }
Checks to make sure that pseudo scoped beans ( i . e .
26,541
private static void reallyValidatePseudoScopedBean ( Bean < ? > bean , BeanManagerImpl beanManager , Set < Object > dependencyPath , Set < Bean < ? > > validatedBeans ) { if ( dependencyPath . contains ( bean ) ) { List < Object > realDependencyPath = new ArrayList < Object > ( dependencyPath ) ; realDependencyPath . add ( bean ) ; throw ValidatorLogger . LOG . pseudoScopedBeanHasCircularReferences ( WeldCollections . toMultiRowString ( realDependencyPath ) ) ; } if ( validatedBeans . contains ( bean ) ) { return ; } dependencyPath . add ( bean ) ; for ( InjectionPoint injectionPoint : bean . getInjectionPoints ( ) ) { if ( ! injectionPoint . isDelegate ( ) ) { dependencyPath . add ( injectionPoint ) ; validatePseudoScopedInjectionPoint ( injectionPoint , beanManager , dependencyPath , validatedBeans ) ; dependencyPath . remove ( injectionPoint ) ; } } if ( bean instanceof DecorableBean < ? > ) { final List < Decorator < ? > > decorators = Reflections . < DecorableBean < ? > > cast ( bean ) . getDecorators ( ) ; if ( ! decorators . isEmpty ( ) ) { for ( final Decorator < ? > decorator : decorators ) { reallyValidatePseudoScopedBean ( decorator , beanManager , dependencyPath , validatedBeans ) ; } } } if ( bean instanceof AbstractProducerBean < ? , ? , ? > && ! ( bean instanceof EEResourceProducerField < ? , ? > ) ) { AbstractProducerBean < ? , ? , ? > producer = ( AbstractProducerBean < ? , ? , ? > ) bean ; if ( ! beanManager . isNormalScope ( producer . getDeclaringBean ( ) . getScope ( ) ) && ! producer . getAnnotated ( ) . isStatic ( ) ) { reallyValidatePseudoScopedBean ( producer . getDeclaringBean ( ) , beanManager , dependencyPath , validatedBeans ) ; } } validatedBeans . add ( bean ) ; dependencyPath . remove ( bean ) ; }
checks if a bean has been seen before in the dependencyPath . If not it resolves the InjectionPoints and adds the resolved beans to the set of beans to be validated
26,542
public static InterceptionContext forConstructorInterception ( InterceptionModel interceptionModel , CreationalContext < ? > ctx , BeanManagerImpl manager , SlimAnnotatedType < ? > type ) { return of ( interceptionModel , ctx , manager , null , type ) ; }
The context returned by this method may be later reused for other interception types .
26,543
private Set < QualifierInstance > getRequiredQualifiers ( EnhancedAnnotatedParameter < ? , ? super X > enhancedDisposedParameter ) { Set < Annotation > disposedParameterQualifiers = enhancedDisposedParameter . getMetaAnnotations ( Qualifier . class ) ; if ( disposedParameterQualifiers . isEmpty ( ) ) { disposedParameterQualifiers = Collections . < Annotation > singleton ( Default . Literal . INSTANCE ) ; } return beanManager . getServices ( ) . get ( MetaAnnotationStore . class ) . getQualifierInstances ( disposedParameterQualifiers ) ; }
A disposer method is bound to a producer if the producer is assignable to the disposed parameter .
26,544
public static Type [ ] getActualTypeArguments ( Class < ? > clazz ) { Type type = Types . getCanonicalType ( clazz ) ; if ( type instanceof ParameterizedType ) { return ( ( ParameterizedType ) type ) . getActualTypeArguments ( ) ; } else { return EMPTY_TYPES ; } }
Gets the actual type arguments of a class
26,545
public static Type [ ] getActualTypeArguments ( Type type ) { Type resolvedType = Types . getCanonicalType ( type ) ; if ( resolvedType instanceof ParameterizedType ) { return ( ( ParameterizedType ) resolvedType ) . getActualTypeArguments ( ) ; } else { return EMPTY_TYPES ; } }
Gets the actual type arguments of a Type
26,546
public static < T > Class < T > loadClass ( String className , ResourceLoader resourceLoader ) { try { return cast ( resourceLoader . classForName ( className ) ) ; } catch ( ResourceLoadingException e ) { return null ; } catch ( SecurityException e ) { return null ; } }
Tries to load a class using the specified ResourceLoader . Returns null if the class is not found .
26,547
public static Method findDeclaredMethodByName ( Class < ? > clazz , String methodName ) { for ( Method method : AccessController . doPrivileged ( new GetDeclaredMethodsAction ( clazz ) ) ) { if ( methodName . equals ( method . getName ( ) ) ) { return method ; } } return null ; }
Searches for a declared method with a given name . If the class declares multiple methods with the given name there is no guarantee as of which methods is returned . Null is returned if the class does not declare a method with the given name .
26,548
public static void main ( String [ ] args ) { try { new StartMain ( args ) . go ( ) ; } catch ( Throwable t ) { WeldSELogger . LOG . error ( "Application exited with an exception" , t ) ; System . exit ( 1 ) ; } }
The main method called from the command line .
26,549
public void release ( Contextual < T > contextual , T instance ) { synchronized ( dependentInstances ) { for ( ContextualInstance < ? > dependentInstance : dependentInstances ) { if ( contextual == null || ! ( dependentInstance . getContextual ( ) . equals ( contextual ) ) ) { destroy ( dependentInstance ) ; } } } if ( resourceReferences != null ) { for ( ResourceReference < ? > reference : resourceReferences ) { reference . release ( ) ; } } }
should not be public
26,550
public boolean destroyDependentInstance ( T instance ) { synchronized ( dependentInstances ) { for ( Iterator < ContextualInstance < ? > > iterator = dependentInstances . iterator ( ) ; iterator . hasNext ( ) ; ) { ContextualInstance < ? > contextualInstance = iterator . next ( ) ; if ( contextualInstance . getInstance ( ) == instance ) { iterator . remove ( ) ; destroy ( contextualInstance ) ; return true ; } } } return false ; }
Destroys dependent instance
26,551
protected T checkReturnValue ( T instance ) { if ( instance == null && ! isDependent ( ) ) { throw BeanLogger . LOG . nullNotAllowedFromProducer ( getProducer ( ) , Formats . formatAsStackTraceElement ( getAnnotated ( ) . getJavaMember ( ) ) ) ; } if ( instance == null ) { InjectionPoint injectionPoint = beanManager . getServices ( ) . get ( CurrentInjectionPoint . class ) . peek ( ) ; if ( injectionPoint != null ) { Class < ? > injectionPointRawType = Reflections . getRawType ( injectionPoint . getType ( ) ) ; if ( injectionPointRawType . isPrimitive ( ) ) { return cast ( Defaults . getJlsDefaultValue ( injectionPointRawType ) ) ; } } } if ( instance != null && ! ( instance instanceof Serializable ) ) { if ( beanManager . isPassivatingScope ( getScope ( ) ) ) { throw BeanLogger . LOG . nonSerializableProductError ( getProducer ( ) , Formats . formatAsStackTraceElement ( getAnnotated ( ) . getJavaMember ( ) ) ) ; } InjectionPoint injectionPoint = beanManager . getServices ( ) . get ( CurrentInjectionPoint . class ) . peek ( ) ; if ( injectionPoint != null && injectionPoint . getBean ( ) != null && Beans . isPassivatingScope ( injectionPoint . getBean ( ) , beanManager ) ) { if ( ! ( injectionPoint . getMember ( ) instanceof Field ) || ! injectionPoint . isTransient ( ) ) { throw BeanLogger . LOG . unserializableProductInjectionError ( this , Formats . formatAsStackTraceElement ( getAnnotated ( ) . getJavaMember ( ) ) , injectionPoint , Formats . formatAsStackTraceElement ( injectionPoint . getMember ( ) ) ) ; } } } return instance ; }
Validates the return value
26,552
public static < K , V > Map < K , V > copyOf ( Map < K , V > map ) { Preconditions . checkNotNull ( map ) ; return ImmutableMap . < K , V > builder ( ) . putAll ( map ) . build ( ) ; }
Creates an immutable map . A copy of the given map is used . As a result it is safe to modify the source map afterwards .
26,553
public static < K , V > Map < K , V > of ( K key , V value ) { return new ImmutableMapEntry < K , V > ( key , value ) ; }
Creates an immutable singleton instance .
26,554
public static String formatAsStackTraceElement ( InjectionPoint ij ) { Member member ; if ( ij . getAnnotated ( ) instanceof AnnotatedField ) { AnnotatedField < ? > annotatedField = ( AnnotatedField < ? > ) ij . getAnnotated ( ) ; member = annotatedField . getJavaMember ( ) ; } else if ( ij . getAnnotated ( ) instanceof AnnotatedParameter < ? > ) { AnnotatedParameter < ? > annotatedParameter = ( AnnotatedParameter < ? > ) ij . getAnnotated ( ) ; member = annotatedParameter . getDeclaringCallable ( ) . getJavaMember ( ) ; } else { return "-" ; } return formatAsStackTraceElement ( member ) ; }
See also WELD - 1454 .
26,555
public static int getLineNumber ( Member member ) { if ( ! ( member instanceof Method || member instanceof Constructor ) ) { return 0 ; } if ( ! Reflections . isClassLoadable ( BCEL_CLASS , WeldClassLoaderResourceLoader . INSTANCE ) ) { return 0 ; } String classFile = member . getDeclaringClass ( ) . getName ( ) . replace ( '.' , '/' ) ; ClassLoaderResourceLoader classFileResourceLoader = new ClassLoaderResourceLoader ( member . getDeclaringClass ( ) . getClassLoader ( ) ) ; InputStream in = null ; try { URL classFileUrl = classFileResourceLoader . getResource ( classFile + ".class" ) ; if ( classFileUrl == null ) { return 0 ; } in = classFileUrl . openStream ( ) ; ClassParser cp = new ClassParser ( in , classFile ) ; JavaClass javaClass = cp . parse ( ) ; org . apache . bcel . classfile . Method [ ] methods = javaClass . getMethods ( ) ; org . apache . bcel . classfile . Method match = null ; String signature ; String name ; if ( member instanceof Method ) { signature = DescriptorUtils . methodDescriptor ( ( Method ) member ) ; name = member . getName ( ) ; } else if ( member instanceof Constructor ) { signature = DescriptorUtils . makeDescriptor ( ( Constructor < ? > ) member ) ; name = INIT_METHOD_NAME ; } else { return 0 ; } for ( org . apache . bcel . classfile . Method method : methods ) { if ( method . getName ( ) . equals ( name ) && member . getModifiers ( ) == method . getModifiers ( ) && method . getSignature ( ) . equals ( signature ) ) { match = method ; } } if ( match != null ) { LineNumberTable lineNumberTable = match . getLineNumberTable ( ) ; if ( lineNumberTable != null ) { int line = lineNumberTable . getSourceLine ( 0 ) ; return line == - 1 ? 0 : line ; } } return 0 ; } catch ( Throwable t ) { return 0 ; } finally { if ( in != null ) { try { in . close ( ) ; } catch ( Exception e ) { return 0 ; } } } }
Try to get the line number associated with the given member .
26,556
private static List < String > parseModifiers ( int modifiers ) { List < String > result = new ArrayList < String > ( ) ; if ( Modifier . isPrivate ( modifiers ) ) { result . add ( "private" ) ; } if ( Modifier . isProtected ( modifiers ) ) { result . add ( "protected" ) ; } if ( Modifier . isPublic ( modifiers ) ) { result . add ( "public" ) ; } if ( Modifier . isAbstract ( modifiers ) ) { result . add ( "abstract" ) ; } if ( Modifier . isFinal ( modifiers ) ) { result . add ( "final" ) ; } if ( Modifier . isNative ( modifiers ) ) { result . add ( "native" ) ; } if ( Modifier . isStatic ( modifiers ) ) { result . add ( "static" ) ; } if ( Modifier . isStrict ( modifiers ) ) { result . add ( "strict" ) ; } if ( Modifier . isSynchronized ( modifiers ) ) { result . add ( "synchronized" ) ; } if ( Modifier . isTransient ( modifiers ) ) { result . add ( "transient" ) ; } if ( Modifier . isVolatile ( modifiers ) ) { result . add ( "volatile" ) ; } if ( Modifier . isInterface ( modifiers ) ) { result . add ( "interface" ) ; } return result ; }
Parses a reflection modifier to a list of string
26,557
private boolean initCheckTypeModifiers ( ) { Class < ? > classInfoclass = Reflections . loadClass ( CLASSINFO_CLASS_NAME , new ClassLoaderResourceLoader ( classFileServices . getClass ( ) . getClassLoader ( ) ) ) ; if ( classInfoclass != null ) { try { Method setFlags = AccessController . doPrivileged ( GetDeclaredMethodAction . of ( classInfoclass , "setFlags" , short . class ) ) ; return setFlags != null ; } catch ( Exception exceptionIgnored ) { BootstrapLogger . LOG . usingOldJandexVersion ( ) ; return false ; } } else { return true ; } }
checking availability of ClassInfo . setFlags method is just workaround for JANDEX - 37
26,558
public static < X , T > ProducerMethod < X , T > of ( BeanAttributes < T > attributes , EnhancedAnnotatedMethod < T , ? super X > method , AbstractClassBean < X > declaringBean , DisposalMethod < X , ? > disposalMethod , BeanManagerImpl beanManager , ServiceRegistry services ) { return new ProducerMethod < X , T > ( createId ( attributes , method , declaringBean ) , attributes , method , declaringBean , disposalMethod , beanManager , services ) ; }
Creates a producer method Web Bean
26,559
public static void addLoadInstruction ( CodeAttribute code , String type , int variable ) { char tp = type . charAt ( 0 ) ; if ( tp != 'L' && tp != '[' ) { switch ( tp ) { case 'J' : code . lload ( variable ) ; break ; case 'D' : code . dload ( variable ) ; break ; case 'F' : code . fload ( variable ) ; break ; default : code . iload ( variable ) ; } } else { code . aload ( variable ) ; } }
Adds the correct load instruction based on the type descriptor
26,560
public static void pushClassType ( CodeAttribute b , String classType ) { if ( classType . length ( ) != 1 ) { if ( classType . startsWith ( "L" ) && classType . endsWith ( ";" ) ) { classType = classType . substring ( 1 , classType . length ( ) - 1 ) ; } b . loadClass ( classType ) ; } else { char type = classType . charAt ( 0 ) ; switch ( type ) { case 'I' : b . getstatic ( Integer . class . getName ( ) , TYPE , LJAVA_LANG_CLASS ) ; break ; case 'J' : b . getstatic ( Long . class . getName ( ) , TYPE , LJAVA_LANG_CLASS ) ; break ; case 'S' : b . getstatic ( Short . class . getName ( ) , TYPE , LJAVA_LANG_CLASS ) ; break ; case 'F' : b . getstatic ( Float . class . getName ( ) , TYPE , LJAVA_LANG_CLASS ) ; break ; case 'D' : b . getstatic ( Double . class . getName ( ) , TYPE , LJAVA_LANG_CLASS ) ; break ; case 'B' : b . getstatic ( Byte . class . getName ( ) , TYPE , LJAVA_LANG_CLASS ) ; break ; case 'C' : b . getstatic ( Character . class . getName ( ) , TYPE , LJAVA_LANG_CLASS ) ; break ; case 'Z' : b . getstatic ( Boolean . class . getName ( ) , TYPE , LJAVA_LANG_CLASS ) ; break ; default : throw new RuntimeException ( "Cannot handle primitive type: " + type ) ; } } }
Pushes a class type onto the stack from the string representation This can also handle primitives
26,561
private void checkBindings ( EnhancedAnnotation < T > annotatedAnnotation ) { Set < Annotation > bindings = annotatedAnnotation . getMetaAnnotations ( Qualifier . class ) ; if ( bindings . size ( ) > 0 ) { for ( Annotation annotation : bindings ) { if ( ! annotation . annotationType ( ) . equals ( Named . class ) ) { throw MetadataLogger . LOG . qualifierOnStereotype ( annotatedAnnotation ) ; } } } }
Validates the binding types
26,562
private void initBeanNameDefaulted ( EnhancedAnnotation < T > annotatedAnnotation ) { if ( annotatedAnnotation . isAnnotationPresent ( Named . class ) ) { if ( ! "" . equals ( annotatedAnnotation . getAnnotation ( Named . class ) . value ( ) ) ) { throw MetadataLogger . LOG . valueOnNamedStereotype ( annotatedAnnotation ) ; } beanNameDefaulted = true ; } }
Initializes the bean name defaulted
26,563
private void initDefaultScopeType ( EnhancedAnnotation < T > annotatedAnnotation ) { Set < Annotation > scopeTypes = new HashSet < Annotation > ( ) ; scopeTypes . addAll ( annotatedAnnotation . getMetaAnnotations ( Scope . class ) ) ; scopeTypes . addAll ( annotatedAnnotation . getMetaAnnotations ( NormalScope . class ) ) ; if ( scopeTypes . size ( ) > 1 ) { throw MetadataLogger . LOG . multipleScopes ( annotatedAnnotation ) ; } else if ( scopeTypes . size ( ) == 1 ) { this . defaultScopeType = scopeTypes . iterator ( ) . next ( ) ; } }
Initializes the default scope type
26,564
public static Type boxedType ( Type type ) { if ( type instanceof Class < ? > ) { return boxedClass ( ( Class < ? > ) type ) ; } else { return type ; } }
Gets the boxed type of a class
26,565
public static Type getCanonicalType ( Class < ? > clazz ) { if ( clazz . isArray ( ) ) { Class < ? > componentType = clazz . getComponentType ( ) ; Type resolvedComponentType = getCanonicalType ( componentType ) ; if ( componentType != resolvedComponentType ) { return new GenericArrayTypeImpl ( resolvedComponentType ) ; } } if ( clazz . getTypeParameters ( ) . length > 0 ) { Type [ ] actualTypeParameters = clazz . getTypeParameters ( ) ; return new ParameterizedTypeImpl ( clazz , actualTypeParameters , clazz . getDeclaringClass ( ) ) ; } return clazz ; }
Returns a canonical type for a given class .
26,566
public static boolean isArray ( Type type ) { return ( type instanceof GenericArrayType ) || ( type instanceof Class < ? > && ( ( Class < ? > ) type ) . isArray ( ) ) ; }
Determines whether the given type is an array type .
26,567
public static Type getArrayComponentType ( Type type ) { if ( type instanceof GenericArrayType ) { return GenericArrayType . class . cast ( type ) . getGenericComponentType ( ) ; } if ( type instanceof Class < ? > ) { Class < ? > clazz = ( Class < ? > ) type ; if ( clazz . isArray ( ) ) { return clazz . getComponentType ( ) ; } } throw new IllegalArgumentException ( "Not an array type " + type ) ; }
Determines the component type for a given array type .
26,568
public static boolean isArrayOfUnboundedTypeVariablesOrObjects ( Type [ ] types ) { for ( Type type : types ) { if ( Object . class . equals ( type ) ) { continue ; } if ( type instanceof TypeVariable < ? > ) { Type [ ] bounds = ( ( TypeVariable < ? > ) type ) . getBounds ( ) ; if ( bounds == null || bounds . length == 0 || ( bounds . length == 1 && Object . class . equals ( bounds [ 0 ] ) ) ) { continue ; } } return false ; } return true ; }
Determines whether the given array only contains unbounded type variables or Object . class .
26,569
public < T > T get ( Contextual < T > contextual , CreationalContext < T > creationalContext ) { if ( ! isActive ( ) ) { throw new ContextNotActiveException ( ) ; } if ( creationalContext != null ) { T instance = contextual . create ( creationalContext ) ; if ( creationalContext instanceof WeldCreationalContext < ? > ) { addDependentInstance ( instance , contextual , ( WeldCreationalContext < T > ) creationalContext ) ; } return instance ; } else { return null ; } }
Overridden method always creating a new instance
26,570
public void createEnablement ( ) { GlobalEnablementBuilder builder = beanManager . getServices ( ) . get ( GlobalEnablementBuilder . class ) ; ModuleEnablement enablement = builder . createModuleEnablement ( this ) ; beanManager . setEnabled ( enablement ) ; if ( BootstrapLogger . LOG . isDebugEnabled ( ) ) { BootstrapLogger . LOG . enabledAlternatives ( this . beanManager , WeldCollections . toMultiRowString ( enablement . getAllAlternatives ( ) ) ) ; BootstrapLogger . LOG . enabledDecorators ( this . beanManager , WeldCollections . toMultiRowString ( enablement . getDecorators ( ) ) ) ; BootstrapLogger . LOG . enabledInterceptors ( this . beanManager , WeldCollections . toMultiRowString ( enablement . getInterceptors ( ) ) ) ; } }
Initializes module enablement .
26,571
public static < T > DecoratorImpl < T > of ( BeanAttributes < T > attributes , EnhancedAnnotatedType < T > clazz , BeanManagerImpl beanManager ) { return new DecoratorImpl < T > ( attributes , clazz , beanManager ) ; }
Creates a decorator bean
26,572
protected void merge ( Set < Annotation > stereotypeAnnotations ) { final MetaAnnotationStore store = manager . getServices ( ) . get ( MetaAnnotationStore . class ) ; for ( Annotation stereotypeAnnotation : stereotypeAnnotations ) { StereotypeModel < ? > stereotype = store . getStereotype ( stereotypeAnnotation . annotationType ( ) ) ; if ( stereotype == null ) { throw MetadataLogger . LOG . stereotypeNotRegistered ( stereotypeAnnotation ) ; } if ( stereotype . isAlternative ( ) ) { alternative = true ; } if ( stereotype . getDefaultScopeType ( ) != null ) { possibleScopeTypes . add ( stereotype . getDefaultScopeType ( ) ) ; } if ( stereotype . isBeanNameDefaulted ( ) ) { beanNameDefaulted = true ; } this . stereotypes . add ( stereotypeAnnotation . annotationType ( ) ) ; merge ( stereotype . getInheritedStereotypes ( ) ) ; } }
Perform the merge
26,573
public void run ( ) { try { threadContext . activate ( ) ; runnable . run ( ) ; } finally { threadContext . invalidate ( ) ; threadContext . deactivate ( ) ; } }
Set up the ThreadContext and delegate .
26,574
protected AbstractBeanDeployer < E > deploySpecialized ( ) { for ( DecoratorImpl < ? > bean : getEnvironment ( ) . getDecorators ( ) ) { bean . initialize ( getEnvironment ( ) ) ; containerLifecycleEvents . fireProcessBean ( getManager ( ) , bean ) ; manager . addDecorator ( bean ) ; BootstrapLogger . LOG . foundDecorator ( bean ) ; } for ( InterceptorImpl < ? > bean : getEnvironment ( ) . getInterceptors ( ) ) { bean . initialize ( getEnvironment ( ) ) ; containerLifecycleEvents . fireProcessBean ( getManager ( ) , bean ) ; manager . addInterceptor ( bean ) ; BootstrapLogger . LOG . foundInterceptor ( bean ) ; } return this ; }
interceptors decorators and observers go first
26,575
public static void validateObserverMethod ( ObserverMethod < ? > observerMethod , BeanManager beanManager , ObserverMethod < ? > originalObserverMethod ) { Set < Annotation > qualifiers = observerMethod . getObservedQualifiers ( ) ; if ( observerMethod . getBeanClass ( ) == null ) { throw EventLogger . LOG . observerMethodsMethodReturnsNull ( "getBeanClass" , observerMethod ) ; } if ( observerMethod . getObservedType ( ) == null ) { throw EventLogger . LOG . observerMethodsMethodReturnsNull ( "getObservedType" , observerMethod ) ; } Bindings . validateQualifiers ( qualifiers , beanManager , observerMethod , "ObserverMethod.getObservedQualifiers" ) ; if ( observerMethod . getReception ( ) == null ) { throw EventLogger . LOG . observerMethodsMethodReturnsNull ( "getReception" , observerMethod ) ; } if ( observerMethod . getTransactionPhase ( ) == null ) { throw EventLogger . LOG . observerMethodsMethodReturnsNull ( "getTransactionPhase" , observerMethod ) ; } if ( originalObserverMethod != null && ( ! observerMethod . getBeanClass ( ) . equals ( originalObserverMethod . getBeanClass ( ) ) ) ) { throw EventLogger . LOG . beanClassMismatch ( originalObserverMethod , observerMethod ) ; } if ( ! ( observerMethod instanceof SyntheticObserverMethod ) && ! hasNotifyOverriden ( observerMethod . getClass ( ) , observerMethod ) ) { throw EventLogger . LOG . notifyMethodNotImplemented ( observerMethod ) ; } }
Validates given external observer method .
26,576
private static boolean isAssignableFrom ( WildcardType type1 , Type type2 ) { if ( ! isAssignableFrom ( type1 . getUpperBounds ( ) [ 0 ] , type2 ) ) { return false ; } if ( type1 . getLowerBounds ( ) . length > 0 && ! isAssignableFrom ( type2 , type1 . getLowerBounds ( ) [ 0 ] ) ) { return false ; } return true ; }
This logic is shared for all actual types i . e . raw types parameterized types and generic array types .
26,577
public static CombinedInterceptorAndDecoratorStackMethodHandler peekIfNotEmpty ( ) { Stack stack = interceptionContexts . get ( ) ; if ( stack == null ) { return null ; } return stack . peek ( ) ; }
Peeks the current top of the stack or returns null if the stack is empty
26,578
public static Stack getStack ( ) { Stack stack = interceptionContexts . get ( ) ; if ( stack == null ) { stack = new Stack ( interceptionContexts ) ; interceptionContexts . set ( stack ) ; } return stack ; }
Gets the current Stack . If the stack is not set a new empty instance is created and set .
26,579
public static boolean isTypesProxyable ( Iterable < ? extends Type > types , ServiceRegistry services ) { return getUnproxyableTypesException ( types , services ) == null ; }
Indicates if a set of types are all proxyable
26,580
public static < T > boolean addAll ( Collection < T > target , Iterator < ? extends T > iterator ) { Preconditions . checkArgumentNotNull ( target , "target" ) ; boolean modified = false ; while ( iterator . hasNext ( ) ) { modified |= target . add ( iterator . next ( ) ) ; } return modified ; }
Add all elements in the iterator to the collection .
26,581
public static < T > Iterator < T > concat ( Iterator < ? extends Iterator < ? extends T > > iterators ) { Preconditions . checkArgumentNotNull ( iterators , "iterators" ) ; return new CombinedIterator < T > ( iterators ) ; }
Combine the iterators into a single one .
26,582
HtmlTag attr ( String name , String value ) { if ( attrs == null ) { attrs = new HashMap < > ( ) ; } attrs . put ( name , value ) ; return this ; }
Attribute name and value are not escaped or modified in any way .
26,583
public void clearAnnotationData ( Class < ? extends Annotation > annotationClass ) { stereotypes . invalidate ( annotationClass ) ; scopes . invalidate ( annotationClass ) ; qualifiers . invalidate ( annotationClass ) ; interceptorBindings . invalidate ( annotationClass ) ; }
removes all data for an annotation class . This should be called after an annotation has been modified through the SPI
26,584
public static < K , V > Map < K , V > immutableMapView ( Map < K , V > map ) { if ( map instanceof ImmutableMap < ? , ? > ) { return map ; } return Collections . unmodifiableMap ( map ) ; }
Returns an immutable view of a given map .
26,585
protected void checkProducerMethod ( EnhancedAnnotatedMethod < T , ? super X > method ) { if ( method . getEnhancedParameters ( Observes . class ) . size ( ) > 0 ) { throw BeanLogger . LOG . inconsistentAnnotationsOnMethod ( PRODUCER_ANNOTATION , "@Observes" , this . method , Formats . formatAsStackTraceElement ( method . getJavaMember ( ) ) ) ; } else if ( method . getEnhancedParameters ( ObservesAsync . class ) . size ( ) > 0 ) { throw BeanLogger . LOG . inconsistentAnnotationsOnMethod ( PRODUCER_ANNOTATION , "@ObservesAsync" , this . method , Formats . formatAsStackTraceElement ( method . getJavaMember ( ) ) ) ; } else if ( method . getEnhancedParameters ( Disposes . class ) . size ( ) > 0 ) { throw BeanLogger . LOG . inconsistentAnnotationsOnMethod ( PRODUCER_ANNOTATION , "@Disposes" , this . method , Formats . formatAsStackTraceElement ( method . getJavaMember ( ) ) ) ; } else if ( getDeclaringBean ( ) instanceof SessionBean < ? > && ! Modifier . isStatic ( method . slim ( ) . getJavaMember ( ) . getModifiers ( ) ) ) { boolean methodDeclaredOnTypes = false ; for ( Type type : getDeclaringBean ( ) . getTypes ( ) ) { Class < ? > clazz = Reflections . getRawType ( type ) ; try { AccessController . doPrivileged ( new GetMethodAction ( clazz , method . getName ( ) , method . getParameterTypesAsArray ( ) ) ) ; methodDeclaredOnTypes = true ; break ; } catch ( PrivilegedActionException ignored ) { } } if ( ! methodDeclaredOnTypes ) { throw BeanLogger . LOG . methodNotBusinessMethod ( "Producer" , this , getDeclaringBean ( ) , Formats . formatAsStackTraceElement ( method . getJavaMember ( ) ) ) ; } } }
Validates the producer method
26,586
ProtectionDomain getProtectionDomainForProxy ( ProtectionDomain domain ) { if ( domain . getCodeSource ( ) == null ) { return create ( domain ) ; } ProtectionDomain proxyProtectionDomain = proxyProtectionDomains . get ( domain . getCodeSource ( ) ) ; if ( proxyProtectionDomain == null ) { proxyProtectionDomain = create ( domain ) ; ProtectionDomain existing = proxyProtectionDomains . putIfAbsent ( domain . getCodeSource ( ) , proxyProtectionDomain ) ; if ( existing != null ) { proxyProtectionDomain = existing ; } } return proxyProtectionDomain ; }
Gets an enhanced protection domain for a proxy based on the given protection domain .
26,587
public static < A extends Annotation > EnhancedAnnotation < A > create ( SlimAnnotatedType < A > annotatedType , ClassTransformer classTransformer ) { Class < A > annotationType = annotatedType . getJavaClass ( ) ; Map < Class < ? extends Annotation > , Annotation > annotationMap = new HashMap < Class < ? extends Annotation > , Annotation > ( ) ; annotationMap . putAll ( buildAnnotationMap ( annotatedType . getAnnotations ( ) ) ) ; annotationMap . putAll ( buildAnnotationMap ( classTransformer . getTypeStore ( ) . get ( annotationType ) ) ) ; return new EnhancedAnnotationImpl < A > ( annotatedType , annotationMap , annotationMap , classTransformer ) ; }
we can t call this method of cause it won t compile on JDK7
26,588
protected void init ( EnhancedAnnotation < T > annotatedAnnotation ) { initType ( annotatedAnnotation ) ; initValid ( annotatedAnnotation ) ; check ( annotatedAnnotation ) ; }
Initializes the type and validates it
26,589
protected void initValid ( EnhancedAnnotation < T > annotatedAnnotation ) { this . valid = false ; for ( Class < ? extends Annotation > annotationType : getMetaAnnotationTypes ( ) ) { if ( annotatedAnnotation . isAnnotationPresent ( annotationType ) ) { this . valid = true ; } } }
Validates the data for correct annotation
26,590
private void installFastProcessAnnotatedTypeResolver ( ServiceRegistry services ) { ClassFileServices classFileServices = services . get ( ClassFileServices . class ) ; if ( classFileServices != null ) { final GlobalObserverNotifierService observers = services . get ( GlobalObserverNotifierService . class ) ; try { final FastProcessAnnotatedTypeResolver resolver = new FastProcessAnnotatedTypeResolver ( observers . getAllObserverMethods ( ) ) ; services . add ( FastProcessAnnotatedTypeResolver . class , resolver ) ; } catch ( UnsupportedObserverMethodException e ) { BootstrapLogger . LOG . notUsingFastResolver ( e . getObserver ( ) ) ; return ; } } }
needs to be resolved once extension beans are deployed
26,591
public String load ( ) { this . paginator = new Paginator ( ) ; this . codes = null ; this . codes = codeFragmentManager . searchCodeFragments ( this . codeFragmentPrototype , this . page , this . paginator ) ; return "history" ; }
Do the search called as a page action
26,592
public < T > InternalEjbDescriptor < T > get ( String beanName ) { return cast ( ejbByName . get ( beanName ) ) ; }
Gets an iterator to the EJB descriptors for an EJB implementation class
26,593
private < T > void add ( EjbDescriptor < T > ejbDescriptor ) { InternalEjbDescriptor < T > internalEjbDescriptor = InternalEjbDescriptor . of ( ejbDescriptor ) ; ejbByName . put ( ejbDescriptor . getEjbName ( ) , internalEjbDescriptor ) ; ejbByClass . put ( ejbDescriptor . getBeanClass ( ) , internalEjbDescriptor . getEjbName ( ) ) ; }
Adds an EJB descriptor to the maps
26,594
private void fireEventForNonWebModules ( Type eventType , Object event , Annotation ... qualifiers ) { try { BeanDeploymentModules modules = deploymentManager . getServices ( ) . get ( BeanDeploymentModules . class ) ; if ( modules != null ) { for ( BeanDeploymentModule module : modules ) { if ( ! module . isWebModule ( ) ) { module . fireEvent ( eventType , event , qualifiers ) ; } } } } catch ( Exception ignored ) { } }
Fires given event for non - web modules . Used for
26,595
public static void initialize ( BeanManagerImpl deploymentManager , ServiceRegistry deploymentServices ) { Container instance = new Container ( RegistrySingletonProvider . STATIC_INSTANCE , deploymentManager , deploymentServices ) ; Container . instance . set ( RegistrySingletonProvider . STATIC_INSTANCE , instance ) ; }
Initialize the container for the current application deployment
26,596
public void cleanup ( ) { managers . clear ( ) ; for ( BeanManagerImpl beanManager : beanDeploymentArchives . values ( ) ) { beanManager . cleanup ( ) ; } beanDeploymentArchives . clear ( ) ; deploymentServices . cleanup ( ) ; deploymentManager . cleanup ( ) ; instance . clear ( contextId ) ; }
Cause the container to be cleaned up including all registered bean managers and all deployment services
26,597
public void putBeanDeployments ( BeanDeploymentArchiveMapping bdaMapping ) { for ( Entry < BeanDeploymentArchive , BeanManagerImpl > entry : bdaMapping . getBdaToBeanManagerMap ( ) . entrySet ( ) ) { beanDeploymentArchives . put ( entry . getKey ( ) , entry . getValue ( ) ) ; addBeanManager ( entry . getValue ( ) ) ; } }
Add sub - deployment units to the container
26,598
private < Y > void checkObserverMethod ( EnhancedAnnotatedMethod < T , Y > annotated ) { List < EnhancedAnnotatedParameter < ? , Y > > eventObjects = annotated . getEnhancedParameters ( Observes . class ) ; eventObjects . addAll ( annotated . getEnhancedParameters ( ObservesAsync . class ) ) ; if ( this . reception . equals ( Reception . IF_EXISTS ) && declaringBean . getScope ( ) . equals ( Dependent . class ) ) { throw EventLogger . LOG . invalidScopedConditionalObserver ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } if ( eventObjects . size ( ) > 1 ) { throw EventLogger . LOG . multipleEventParameters ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } EnhancedAnnotatedParameter < ? , Y > eventParameter = eventObjects . iterator ( ) . next ( ) ; checkRequiredTypeAnnotations ( eventParameter ) ; List < ? > disposeParams = annotated . getEnhancedParameters ( Disposes . class ) ; if ( disposeParams . size ( ) > 0 ) { throw EventLogger . LOG . invalidDisposesParameter ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } if ( this . observerMethod . getAnnotated ( ) . isAnnotationPresent ( Produces . class ) ) { throw EventLogger . LOG . invalidProducer ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } if ( this . observerMethod . getAnnotated ( ) . isAnnotationPresent ( Inject . class ) ) { throw EventLogger . LOG . invalidInitializer ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } boolean containerLifecycleObserverMethod = Observers . isContainerLifecycleObserverMethod ( this ) ; for ( EnhancedAnnotatedParameter < ? , ? > parameter : annotated . getEnhancedParameters ( ) ) { if ( containerLifecycleObserverMethod && ! parameter . isAnnotationPresent ( Observes . class ) && ! parameter . isAnnotationPresent ( ObservesAsync . class ) && ! BeanManager . class . equals ( parameter . getBaseType ( ) ) ) { throw EventLogger . LOG . invalidInjectionPoint ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } } }
Performs validation of the observer method for compliance with the specifications .
26,599
protected void sendEvent ( final T event ) { if ( isStatic ) { sendEvent ( event , null , null ) ; } else { CreationalContext < X > creationalContext = null ; try { Object receiver = getReceiverIfExists ( null ) ; if ( receiver == null && reception != Reception . IF_EXISTS ) { creationalContext = beanManager . createCreationalContext ( declaringBean ) ; receiver = getReceiverIfExists ( creationalContext ) ; } if ( receiver != null ) { sendEvent ( event , receiver , creationalContext ) ; } } finally { if ( creationalContext != null ) { creationalContext . release ( ) ; } } } }
Invokes the observer method immediately passing the event .