Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.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.xml;
   15   
   16   import java.util.ArrayList;
   17   import java.util.List;
   18   import java.util.Map;
   19   import java.util.concurrent.ConcurrentHashMap;
   20   
   21   import org.apache.webbeans.WebBeansConstants;
   22   import org.apache.webbeans.config.WebBeansFinder;
   23   
   24   /**
   25    * Defines the web beans name space.
   26    */
   27   public class WebBeansNameSpaceContainer
   28   {
   29       /** Hold namespace string to package name */
   30       private Map<String, List<String>> nameSpaceToPackages = new ConcurrentHashMap<String, List<String>>();
   31       
   32       
   33       public WebBeansNameSpaceContainer()
   34       {
   35           
   36       }
   37   
   38       public static WebBeansNameSpaceContainer getInstance()
   39       {
   40           WebBeansNameSpaceContainer nameSpaceContainer = (WebBeansNameSpaceContainer)WebBeansFinder.getSingletonInstance(WebBeansFinder.SINGLETON_WEBBEANS_NAMESPACE_CONTAINER);
   41           
   42           return nameSpaceContainer;
   43       }
   44   
   45       /**
   46        * Add new name space to package binding.
   47        * 
   48        * @param nameSpace new name space
   49        */
   50       public void addNewPackageNameSpace(String nameSpace)
   51       {
   52           // Check that nameSpace starts with urn:java
   53           if (nameSpace.startsWith("urn:java:") && !nameSpace.equals(WebBeansConstants.WEB_BEANS_NAMESPACE))
   54           {
   55   
   56               String packageName = nameSpace.substring("urn:java:".length(), nameSpace.length()) + ".";
   57               
   58               if(this.nameSpaceToPackages.containsKey(packageName))
   59               {
   60                   this.nameSpaceToPackages.get(nameSpace).add(packageName);
   61               }
   62               else
   63               {
   64                   List<String> packageList = new ArrayList<String>();
   65                   packageList.add(packageName);
   66                   
   67                   this.nameSpaceToPackages.put(nameSpace, packageList);
   68               }
   69               
   70           }
   71           
   72           if(nameSpace.equals(WebBeansConstants.WEB_BEANS_NAMESPACE))
   73           {
   74               if(!this.nameSpaceToPackages.containsKey(nameSpace))
   75               {
   76                   List<String> eePackages = new ArrayList<String>();
   77                   eePackages.add("java.lang.");
   78                   eePackages.add("java.util.");
   79                   eePackages.add("javax.enterprise.context.");
   80                   eePackages.add("javax.enterprise.context.spi.");
   81                   eePackages.add("javax.enterprise.event.");
   82                   eePackages.add("javax.enterprise.inject.");
   83                   eePackages.add("javax.enterprise.inject.deployment.");
   84                   eePackages.add("javax.enterprise.inject.spi.");
   85                   eePackages.add("javax.inject.");
   86                   eePackages.add("javax.context.");
   87                   eePackages.add("javax.interceptor.");
   88                   eePackages.add("javax.decorator.");
   89                   eePackages.add("javax.event.");
   90                   eePackages.add("javax.ejb.");
   91                   eePackages.add("javax.persistence.");
   92                   eePackages.add("javax.xml.ws.");
   93                   eePackages.add("javax.jms.");
   94                   eePackages.add("javax.sql.");
   95                   
   96                   this.nameSpaceToPackages.put(nameSpace, eePackages);
   97               }
   98           }
   99       }
  100   
  101       /**
  102        * Gets package string for name space.
  103        * 
  104        * @param nameSpace name space
  105        * @return package for namespace
  106        */
  107       public List<String> getPackageNameFromNameSpace(String nameSpace)
  108       {
  109           if (nameSpaceToPackages.containsKey(nameSpace))
  110           {
  111               return nameSpaceToPackages.get(nameSpace);
  112           }
  113   
  114           return null;
  115       }
  116   }

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