Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.decorator » [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.decorator;
   15   
   16   import java.util.List;
   17   import java.util.concurrent.CopyOnWriteArrayList;
   18   
   19   import org.apache.webbeans.config.WebBeansFinder;
   20   import org.apache.webbeans.util.Asserts;
   21   
   22   public class DecoratorsManager
   23   {
   24       private List<Class<?>> enabledDecorators = new CopyOnWriteArrayList<Class<?>>();
   25   
   26       public DecoratorsManager()
   27       {
   28   
   29       }
   30   
   31       public static DecoratorsManager getInstance()
   32       {
   33           DecoratorsManager instance = (DecoratorsManager) WebBeansFinder.getSingletonInstance(WebBeansFinder.SINGLETON_DECORATORS_MANAGER);
   34   
   35           return instance;
   36       }
   37   
   38       public void addNewDecorator(Class<?> decoratorClazz)
   39       {
   40           Asserts.assertNotNull(decoratorClazz, "decoratorClazz parameter can not be emtpy");
   41           if (!enabledDecorators.contains(decoratorClazz))
   42           {
   43               enabledDecorators.add(decoratorClazz);
   44           }
   45       }
   46   
   47       public int compare(Class<?> src, Class<?> target)
   48       {
   49           Asserts.assertNotNull(src, "src parameter can not be  null");
   50           Asserts.assertNotNull(target, "target parameter can not be null");
   51   
   52           int srcIndex = enabledDecorators.indexOf(src);
   53           int targetIndex = enabledDecorators.indexOf(target);
   54   
   55           if (srcIndex == -1 || targetIndex == -1)
   56           {
   57               throw new IllegalArgumentException("One of the compare class of the list : [" + src.getName() + "," + target.getName() + "]" + " is not contained in the enabled decorators list!");
   58           }
   59   
   60           if (srcIndex == targetIndex)
   61               return 0;
   62           else if (srcIndex < targetIndex)
   63               return -1;
   64           else
   65               return 1;
   66       }
   67   
   68       public boolean isDecoratorEnabled(Class<?> decoratorClazz)
   69       {
   70           Asserts.nullCheckForClass(decoratorClazz, "decoratorClazz can not be null");
   71   
   72           return enabledDecorators.contains(decoratorClazz);
   73       }
   74   
   75   }

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