Save This Page
Home » openejb-3.1.2-src » org.apache.openejb.spring » [javadoc | source]
    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.openejb.spring;
   19   
   20   import java.io.File;
   21   import java.util.ArrayList;
   22   import java.util.Collection;
   23   import java.util.List;
   24   import java.util.Set;
   25   import java.util.TreeSet;
   26   
   27   import org.apache.openejb.OpenEJBException;
   28   import org.apache.openejb.assembler.classic.AppInfo;
   29   import org.apache.openejb.assembler.classic.ClientInfo;
   30   import org.apache.openejb.assembler.classic.ConnectorInfo;
   31   import org.apache.openejb.assembler.classic.EjbJarInfo;
   32   import org.apache.openejb.assembler.classic.WebAppInfo;
   33   import org.apache.openejb.config.ConfigurationFactory;
   34   import org.apache.openejb.config.DeploymentsResolver;
   35   import org.apache.openejb.loader.SystemInstance;
   36   
   37   @Exported
   38   public class ClassPathApplication extends AbstractApplication {
   39       private final ConfigurationFactory configurationFactory = new ConfigurationFactory();
   40       private boolean classpathAsEar = true;
   41   
   42       public boolean isClasspathAsEar() {
   43           return classpathAsEar;
   44       }
   45   
   46       public void setClasspathAsEar(boolean classpathAsEar) {
   47           this.classpathAsEar = classpathAsEar;
   48       }
   49   
   50       protected List<AppInfo> loadApplications() throws OpenEJBException {
   51           Set<String> declaredApplications = getDeployedApplications();
   52   
   53           List<String> classpathApps = new ArrayList<String>();
   54           ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
   55   
   56           DeploymentsResolver.loadFromClasspath(SystemInstance.get().getBase(), classpathApps, classLoader);
   57   
   58           ArrayList<File> jarFiles = new ArrayList<File>();
   59           for (String path : classpathApps) {
   60               if (declaredApplications.contains(path)) continue;
   61               // todo hack to avoid picking up application.xml in openejb-core module
   62               if (path.indexOf("openejb-core/target/test-classes") > 0) continue;
   63   
   64               jarFiles.add(new File(path));
   65           }
   66   
   67           List<AppInfo> appInfos = new ArrayList<AppInfo>();
   68           if (classpathAsEar) {
   69               AppInfo appInfo = configurationFactory.configureApplication(classLoader, "classpath.ear", jarFiles);
   70               appInfos.add(appInfo);
   71           } else {
   72               for (File jarFile : jarFiles) {
   73                   AppInfo appInfo = configurationFactory.configureApplication(jarFile);
   74                   appInfos.add(appInfo);
   75               }
   76           }
   77           return appInfos;
   78       }
   79   
   80       private Set<String> getDeployedApplications() {
   81           Set<String> declaredApps = new TreeSet<String>();
   82           Collection<AppInfo> applications = getAssembler().getDeployedApplications();
   83           for (AppInfo application : applications) {
   84               declaredApps.add(application.jarPath);
   85               for (EjbJarInfo ejbJar : application.ejbJars) {
   86                   declaredApps.add(ejbJar.jarPath);
   87               }
   88               for (ConnectorInfo connector : application.connectors) {
   89                   declaredApps.add(connector.codebase);
   90               }
   91               for (WebAppInfo webApp : application.webApps) {
   92                   declaredApps.add(webApp.codebase);
   93               }
   94               for (ClientInfo client : application.clients) {
   95                   declaredApps.add(client.codebase);
   96               }
   97           }
   98           return declaredApps;
   99       }
  100   }

Save This Page
Home » openejb-3.1.2-src » org.apache.openejb.spring » [javadoc | source]