Author: rmannibucau
Date: Mon Sep 24 14:23:20 2012
New Revision: 1389398

URL: http://svn.apache.org/viewvc?rev=1389398&view=rev
Log:
adding ResolverClassLoaderEnricherObserver

Added:
    
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/
    
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/AdditionalLibClassLoaderEnricherObserver.java
    
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/ResolverClassLoaderEnricherObserver.java
Removed:
    
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AdditionalLibClassLoaderEnricherObserver.java

Added: 
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/AdditionalLibClassLoaderEnricherObserver.java
URL: 
http://svn.apache.org/viewvc/openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/AdditionalLibClassLoaderEnricherObserver.java?rev=1389398&view=auto
==============================================================================
--- 
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/AdditionalLibClassLoaderEnricherObserver.java
 (added)
+++ 
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/AdditionalLibClassLoaderEnricherObserver.java
 Mon Sep 24 14:23:20 2012
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.assembler.classic.enricher;
+
+import org.apache.openejb.OpenEJBRuntimeException;
+import org.apache.openejb.component.ClassLoaderEnricher;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.observer.Observes;
+import org.apache.openejb.observer.event.ObserverAdded;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+public class AdditionalLibClassLoaderEnricherObserver {
+    public static final String OPENEJB_ENRICHER_ADDITIONAL_LIB = 
"openejb.enricher.additional-lib";
+
+    private static boolean initDone = false;
+
+    private String path = "additional-lib";
+
+    public void initEnricher(@Observes final ObserverAdded event) {
+        if (initDone || path == null || 
!AdditionalLibClassLoaderEnricherObserver.class.isInstance(event.getObserver()))
 {
+            return;
+        }
+
+        File dir = new File(path);
+        if (!dir.exists()) {
+            final String systProp = 
SystemInstance.get().getProperty(OPENEJB_ENRICHER_ADDITIONAL_LIB, (String) 
null);
+            if (systProp != null) {
+                dir = new File(systProp);
+            }
+        }
+        if (dir.exists()) {
+            final File[] libs = dir.listFiles();
+            if (libs != null) {
+                final ClassLoaderEnricher enricher = 
SystemInstance.get().getComponent(ClassLoaderEnricher.class);
+                for (File lib : libs) {
+                    try {
+                        enricher.addUrl(lib.toURI().toURL());
+                    } catch (MalformedURLException e) {
+                        throw new OpenEJBRuntimeException(e);
+                    }
+                }
+            }
+        }
+
+        initDone = true;
+    }
+
+    public void setPath(final String path) {
+        this.path = path;
+    }
+}

Added: 
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/ResolverClassLoaderEnricherObserver.java
URL: 
http://svn.apache.org/viewvc/openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/ResolverClassLoaderEnricherObserver.java?rev=1389398&view=auto
==============================================================================
--- 
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/ResolverClassLoaderEnricherObserver.java
 (added)
+++ 
openejb/branches/openejb-4.5.0/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/enricher/ResolverClassLoaderEnricherObserver.java
 Mon Sep 24 14:23:20 2012
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.assembler.classic.enricher;
+
+import org.apache.openejb.OpenEJBRuntimeException;
+import org.apache.openejb.component.ClassLoaderEnricher;
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.loader.ProvisioningUtil;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.observer.Observes;
+import org.apache.openejb.observer.event.ObserverAdded;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+
+public class ResolverClassLoaderEnricherObserver {
+    private static boolean initDone = false;
+
+    private String configFile = "additional-lib";
+
+    public void initEnricher(@Observes final ObserverAdded event) {
+        if (initDone || configFile == null || 
!ResolverClassLoaderEnricherObserver.class.isInstance(event.getObserver())) {
+            return;
+        }
+
+        final File file = new File(configFile);
+        if (file.exists()) {
+            final ClassLoaderEnricher enricher = 
SystemInstance.get().getComponent(ClassLoaderEnricher.class);
+
+            BufferedReader reader = null;
+            try {
+                reader = new BufferedReader(new FileReader(file));
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    line = line.trim();
+                    if (line.isEmpty() || line.startsWith("#")) {
+                        continue;
+                    }
+
+                    final File lib = new 
File(ProvisioningUtil.realLocation(line));
+                    if (lib.exists()) {
+                        enricher.addUrl(lib.toURI().toURL());
+                    } else {
+                        throw new OpenEJBRuntimeException("can't find " + 
line);
+                    }
+                }
+            } catch (Exception e) {
+                throw new OpenEJBRuntimeException(e);
+            } finally {
+                IO.close(reader);
+            }
+        }
+
+        initDone = true;
+    }
+
+    public void setConfigFile(final String configFile) {
+        this.configFile = configFile;
+    }
+}


Reply via email to