Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.inject.xml » [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.inject.xml;
   15   
   16   import java.lang.annotation.Annotation;
   17   import java.lang.reflect.Member;
   18   import java.lang.reflect.Type;
   19   import java.util.Arrays;
   20   import java.util.Collections;
   21   import java.util.HashSet;
   22   import java.util.Set;
   23   
   24   import org.apache.webbeans.util.Asserts;
   25   import org.apache.webbeans.util.ClassUtil;
   26   
   27   /**
   28    * Defines the model that is related with injection point decleration. Each
   29    * injection point decleration defined in the XML file defines the injection
   30    * point API type and Binding type annotations.
   31    * <p>
   32    * If injection point is a parametrized type, actual type arguments are defined
   33    * in the XML file. See specification for further details.
   34    * </p>
   35    */
   36   public class XMLInjectionPointModel
   37   {
   38       /** Injection point raw/actual class type */
   39       private Class<?> injectionClassType;
   40   
   41       /** This injection point is parametrized */
   42       private boolean parametrized;
   43   
   44       /** Actual type arguments defined in the XML */
   45       private Type[] actualTypeArguments = new Type[0];
   46   
   47       /** Injection point binding types */
   48       private Set<Annotation> bindingTypes = new HashSet<Annotation>();
   49       
   50       /**All annotations*/
   51       private Set<Annotation> annotations = new HashSet<Annotation>();
   52       
   53       /**Injection type*/
   54       private Type injectionGenericType;
   55       
   56       /**Injection Member*/
   57       private Member injectionMember;
   58       
   59       /**Type of the injection*/
   60       private XMLInjectionModelType type;
   61   
   62       /** This injection model is array */
   63       private boolean array;
   64   
   65       public XMLInjectionPointModel(Class<?> arrayElementType)
   66       {
   67           this.array = true;
   68           this.injectionClassType = arrayElementType;
   69           this.injectionGenericType = arrayElementType;
   70       }
   71   
   72       /**
   73        * Creates new injection point model.
   74        * 
   75        * @param injectionClassType injection point class type
   76        * @param actualTypeArguments injection point actual type arguments
   77        */
   78       public XMLInjectionPointModel(Class<?> injectionClassType, Type[] actualTypeArguments)
   79       {
   80           this.injectionClassType = injectionClassType;
   81           this.injectionGenericType = injectionClassType;
   82   
   83           if (actualTypeArguments != null && actualTypeArguments.length > 0)
   84           {
   85               this.actualTypeArguments = actualTypeArguments;
   86           }
   87   
   88           if (ClassUtil.isDefinitionConstainsTypeVariables(this.injectionClassType))
   89           {
   90               this.parametrized = true;
   91           }
   92       }
   93   
   94       /**
   95        * Add new binding type annotation to the injection point.
   96        * 
   97        * @param bindingType new binding type annotation
   98        */
   99       public void addBindingType(Annotation bindingType)
  100       {
  101           this.bindingTypes.add(bindingType);
  102       }
  103   
  104       /**
  105        * Gets injection point class type.
  106        * 
  107        * @return the injectionClassType
  108        */
  109       public Class<?> getInjectionClassType()
  110       {
  111           return injectionClassType;
  112       }
  113   
  114       /**
  115        * Returns the injection point is parametrized type.
  116        * 
  117        * @return the parametrized
  118        */
  119       public boolean isParametrized()
  120       {
  121           return parametrized;
  122       }
  123   
  124       /**
  125        * Gets actual type arguments.
  126        * 
  127        * @return the actualTypeArguments
  128        */
  129       public Type[] getActualTypeArguments()
  130       {
  131           return actualTypeArguments;
  132       }
  133   
  134       /**
  135        * Gets unmodifiable binding types of the injection point.
  136        * 
  137        * @return the bindingTypes
  138        */
  139       public Set<Annotation> getBindingTypes()
  140       {
  141           return Collections.unmodifiableSet(this.bindingTypes);
  142       }
  143       
  144       
  145       /**
  146        * 
  147        * @return annotations
  148        */
  149       public Set<Annotation> getAnnotations()
  150       {
  151           return Collections.unmodifiableSet(this.annotations);
  152       }
  153   
  154       /**
  155        * @return the array
  156        */
  157       public boolean isArray()
  158       {
  159           return array;
  160       }
  161       
  162       /**
  163        * Add new injection point annotation
  164        * @param annotation member annotation
  165        */
  166       public void addAnnotation(Annotation annotation)
  167       {
  168           Asserts.assertNotNull(annotation, "annotation parameter can not be null");
  169           this.annotations.add(annotation);
  170       }
  171       
  172       /**
  173        * @return the injectionType
  174        */
  175       public Type getInjectionGenericType()
  176       {
  177           return injectionGenericType;
  178       }
  179   
  180       /**
  181        * @return the injectionMember
  182        */
  183       public Member getInjectionMember()
  184       {
  185           return injectionMember;
  186       }
  187   
  188       /**
  189        * @param injectionMember the injectionMember to set
  190        */
  191       public void setInjectionMember(Member injectionMember)
  192       {
  193           this.injectionMember = injectionMember;
  194       }
  195       
  196       /**
  197        * @return the type
  198        */
  199       public XMLInjectionModelType getType()
  200       {
  201           return type;
  202       }
  203   
  204       /**
  205        * @param type the type to set
  206        */
  207       public void setType(XMLInjectionModelType type)
  208       {
  209           this.type = type;
  210       }    
  211   
  212       /*
  213        * (non-Javadoc)
  214        * @see java.lang.Object#hashCode()
  215        */
  216       @Override
  217       public int hashCode()
  218       {
  219           final int prime = 31;
  220           int result = 1;
  221           result = prime * result + Arrays.hashCode(actualTypeArguments);
  222           result = prime * result + ((bindingTypes == null) ? 0 : bindingTypes.hashCode());
  223           result = prime * result + ((injectionClassType == null) ? 0 : injectionClassType.hashCode());
  224           result = prime * result + (parametrized ? 1231 : 1237);
  225           return result;
  226       }
  227   
  228       /*
  229        * (non-Javadoc)
  230        * @see java.lang.Object#equals(java.lang.Object)
  231        */
  232       @Override
  233       public boolean equals(Object obj)
  234       {
  235           if (this == obj)
  236               return true;
  237           if (obj == null)
  238               return false;
  239           if (getClass() != obj.getClass())
  240               return false;
  241           final XMLInjectionPointModel other = (XMLInjectionPointModel) obj;
  242           if (!Arrays.equals(actualTypeArguments, other.actualTypeArguments))
  243               return false;
  244           if (bindingTypes == null)
  245           {
  246               if (other.bindingTypes != null)
  247                   return false;
  248           }
  249           else if (!bindingTypes.equals(other.bindingTypes))
  250               return false;
  251           if (injectionClassType == null)
  252           {
  253               if (other.injectionClassType != null)
  254                   return false;
  255           }
  256           else if (!injectionClassType.equals(other.injectionClassType))
  257               return false;
  258           if (parametrized != other.parametrized)
  259               return false;
  260           return true;
  261       }
  262    }

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