Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.portable » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.portable;
   15   
   16   import java.lang.reflect.Constructor;
   17   import java.lang.reflect.Field;
   18   import java.lang.reflect.Member;
   19   import java.lang.reflect.Method;
   20   import java.lang.reflect.Type;
   21   
   22   import javax.enterprise.inject.spi.AnnotatedConstructor;
   23   import javax.enterprise.inject.spi.AnnotatedField;
   24   import javax.enterprise.inject.spi.AnnotatedMember;
   25   import javax.enterprise.inject.spi.AnnotatedMethod;
   26   import javax.enterprise.inject.spi.AnnotatedType;
   27   
   28   import org.apache.webbeans.util.ClassUtil;
   29   
   30   /**
   31    * Implementation of {@link AnnotatedMember} interface.
   32    * 
   33    * @version $Rev: 788970 $ $Date: 2009-06-27 16:26:23 +0300 (Sat, 27 Jun 2009) $
   34    *
   35    * @param <X> declaring class
   36    */
   37   abstract class AbstractAnnotatedMember<X> extends AbstractAnnotated implements AnnotatedMember<X>
   38   {
   39       /**Annotated type that owns this member*/
   40       private AnnotatedType<X> declaringType;
   41       
   42       /**Member type*/
   43       protected Member javaMember;
   44       
   45       /**
   46        * Creates a new instance.
   47        * 
   48        * @param baseType base type
   49        * @param javaMember member
   50        */
   51       AbstractAnnotatedMember(Type baseType, Member javaMember)
   52       {
   53           this(baseType, javaMember, null);
   54       }
   55       
   56       @SuppressWarnings("unchecked")    
   57       AbstractAnnotatedMember(Type baseType, Member javaMember, AnnotatedType<X> declaringType)
   58       {
   59           super(baseType);
   60           
   61           this.javaMember = javaMember;
   62           
   63           if(declaringType == null)
   64           {
   65               this.declaringType = (AnnotatedType<X>)AnnotatedElementFactory.newAnnotatedType(this.javaMember.getDeclaringClass());
   66               
   67               AnnotatedTypeImpl<X> impl = (AnnotatedTypeImpl<X>)this.declaringType;
   68               
   69               if(this.javaMember instanceof Constructor)
   70               {
   71                   impl.addAnnotatedConstructor((AnnotatedConstructor<X>)this);
   72               }
   73               
   74               else if(this.javaMember instanceof Method)
   75               {
   76                   impl.addAnnotatedMethod((AnnotatedMethod<X>)this);
   77               }
   78               
   79               else if(this.javaMember instanceof Field)
   80               {
   81                   impl.addAnnotatedField((AnnotatedField<X>)this);
   82               }                
   83           }
   84           else
   85           {
   86               this.declaringType = declaringType;
   87           }
   88       }
   89      /**
   90        * {@inheritDoc}
   91        */    
   92       @Override
   93       public AnnotatedType<X> getDeclaringType()
   94       {
   95           return this.declaringType;
   96       }
   97   
   98       /**
   99        * {@inheritDoc}
  100        */    
  101       @Override
  102       public Member getJavaMember()
  103       {
  104           return this.javaMember;
  105       }
  106   
  107       /**
  108        * {@inheritDoc}
  109        */    
  110       @Override
  111       public boolean isStatic()
  112       {
  113           return ClassUtil.isStatic(this.javaMember.getModifiers());
  114       }
  115   
  116       public String toString()
  117       {
  118           StringBuilder builder = new StringBuilder(super.toString());
  119           builder.append(",");
  120           builder.append("Java Member Name : " + this.javaMember.getName());
  121           
  122           return builder.toString();
  123       }
  124   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.portable » [javadoc | source]