felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r555072 - in /felix/trunk/ipojo: core/src/main/java/org/apache/felix/ipojo/ core/src/main/java/org/apache/felix/ipojo/composite/ core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/ core/src/main/java/org/apache/felix/ipoj...
Date Tue, 10 Jul 2007 20:31:26 GMT
Author: clement
Date: Tue Jul 10 13:31:25 2007
New Revision: 555072

URL: http://svn.apache.org/viewvc?view=rev&rev=555072
Log:
Remove dependency on Java 1.4 inside the iPOJO Runtime.
Improve factory import inside composite to point directly on the global context.

Modified:
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoContext.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/FieldAdapter.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoContext.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoContext.java?view=diff&rev=555072&r1=555071&r2=555072
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoContext.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoContext.java Tue Jul
10 13:31:25 2007
@@ -301,5 +301,13 @@
     public boolean ungetService(ServiceReference reference) {
         return m_serviceContext.ungetService(reference);
     }
+    
+    /**
+     * Get the global context, i.e. the bundle context of the factory.
+     * @return the global bundle context.
+     */
+    public BundleContext getGlobalContext() {
+        return m_bundleContext;
+    }
 
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java?view=diff&rev=555072&r1=555071&r2=555072
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
(original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/CompositeServiceContext.java
Tue Jul 10 13:31:25 2007
@@ -25,6 +25,7 @@
 
 import org.apache.felix.ipojo.ComponentInstance;
 import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.IPojoContext;
 import org.apache.felix.ipojo.ServiceContext;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -79,6 +80,11 @@
      * Component Instance who creates this registry.
      */
     private ComponentInstance m_instance;
+    
+    /**
+     * Global service context.
+     */
+    private BundleContext m_global;
 
     /**
      * Constructor. This constructor instantiate a service registry with the
@@ -89,6 +95,11 @@
     public CompositeServiceContext(BundleContext bc) {
         m_registry = new ServiceRegistry(bc);
         m_parent = bc;
+        if (m_parent instanceof IPojoContext) {
+            m_global = ((IPojoContext) m_parent).getGlobalContext();
+        } else {
+            m_global = m_parent; // the parent context is the global context
+        }
     }
 
     /**
@@ -99,7 +110,6 @@
      */
     public CompositeServiceContext(BundleContext bc, ComponentInstance ci) {
         this(bc);
-        m_parent = bc;
         m_instance = ci;
     }
 
@@ -219,7 +229,7 @@
      */
     private void importFactories() {
         try {
-            ServiceReference[] refs = m_parent.getServiceReferences(Factory.class.getName(),
null);
+            ServiceReference[] refs = m_global.getServiceReferences(Factory.class.getName(),
null);
             if (refs != null) {
                 for (int i = 0; i < refs.length; i++) {
                     importFactory(refs[i]);
@@ -242,7 +252,7 @@
         for (int j = 0; j < ref.getPropertyKeys().length; j++) {
             dict.put(ref.getPropertyKeys()[j], ref.getProperty(ref.getPropertyKeys()[j]));
         }
-        rec.m_fact = new FactoryProxy((Factory) m_parent.getService(ref), this);
+        rec.m_fact = new FactoryProxy((Factory) m_global.getService(ref), this);
         rec.m_reg = registerService(Factory.class.getName(), rec.m_fact, dict);
         rec.m_ref = ref;
     }
@@ -258,7 +268,7 @@
             if (rec.m_ref == ref) {
                 rec.m_reg.unregister();
                 rec.m_fact = null;
-                m_parent.ungetService(rec.m_ref);
+                m_global.ungetService(rec.m_ref);
                 m_factories.remove(rec);
                 return;
             }
@@ -268,13 +278,12 @@
     /**
      * Start the registry management.
      */
-    public void start() {
+    public synchronized void start() {
         importFactories();
         try {
-            m_parent.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + Factory.class.getName()
+ ")");
+            m_global.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + Factory.class.getName()
+ ")");
         } catch (InvalidSyntaxException e) {
-            // Should not happen
-            e.printStackTrace();
+            e.printStackTrace(); // Should not happen
         }
     }
 
@@ -282,7 +291,7 @@
      * Stop the registry management.
      */
     public synchronized void stop() {
-        m_parent.removeServiceListener(this);
+        m_global.removeServiceListener(this);
         m_registry.reset();
         for (int i = 0; i < m_factories.size(); i++) {
             Record rec = (Record) m_factories.get(i);

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java?view=diff&rev=555072&r1=555071&r2=555072
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
(original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
Tue Jul 10 13:31:25 2007
@@ -200,7 +200,7 @@
                     m_manager.getFactory().getLogger().log(
                             Logger.ERROR,
                             "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod()
+ " has throws an exception : "
-                                    + e.getMessage() + " -> " + e.getCause());
+                                    + e.getMessage());
                 }
             }
         }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java?view=diff&rev=555072&r1=555071&r2=555072
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java Tue
Jul 10 13:31:25 2007
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.ipojo.parser;
 
+import java.util.StringTokenizer;
+
 /**
  * Parse Utils Methods.
  * 
@@ -40,7 +42,7 @@
             if (m.length() == 0) {
                 return new String[0];
             }
-            String[] values = m.split(",");
+            String[] values = split(m, ",");
             for (int i = 0; i < values.length; i++) {
                 values[i] = values[i].trim();
             }
@@ -48,6 +50,24 @@
         } else {
             return new String[] { str };
         }
+    }
+    
+    /**
+     * Split method. 
+     * This method is equivalent of the String.split in java 1.4
+     * @param toSplit : String to split
+     * @param separator : separator
+     * @return the token array 
+     */
+    public static String[] split(String toSplit, String separator) {
+        StringTokenizer st = new StringTokenizer(toSplit, separator);
+        String[] result = new String[st.countTokens()];
+        int i = 0;
+        while (st.hasMoreElements()) {
+            result[i] = st.nextToken();
+            i++;
+        }
+        return result;
     }
 
 }

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/FieldAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/FieldAdapter.java?view=diff&rev=555072&r1=555071&r2=555072
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/FieldAdapter.java
(original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/FieldAdapter.java
Tue Jul 10 13:31:25 2007
@@ -18,8 +18,6 @@
  */
 package org.apache.felix.ipojo.manipulation;
 
-import java.util.logging.Level;
-
 import org.objectweb.asm.ClassAdapter;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.FieldVisitor;
@@ -524,7 +522,7 @@
                 break;
 
             default:
-                ManipulationProperty.getLogger().log(Level.SEVERE, "Manipulation problem
in " + m_owner + " : a type is not implemented : " + type);
+                ManipulationProperty.getLogger().log(ManipulationProperty.SEVERE, "Manipulation
problem in " + m_owner + " : a type is not implemented : " + type);
                 break;
         }
 
@@ -646,7 +644,7 @@
                 mv.visitInsn(RETURN);
                 break;
             default:
-                ManipulationProperty.getLogger().log(Level.SEVERE, "Manipulation Error :
Cannot create the setter method for the field : " + name + " (" + type + ")");
+                ManipulationProperty.getLogger().log(ManipulationProperty.SEVERE, "Manipulation
Error : Cannot create the setter method for the field : " + name + " (" + type + ")");
                 break;
         }
 

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java?view=diff&rev=555072&r1=555071&r2=555072
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java
(original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java
Tue Jul 10 13:31:25 2007
@@ -18,10 +18,6 @@
  */
 package org.apache.felix.ipojo.manipulation;
 
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-
 /**
  * Store properties for the manipulation process.
  * 
@@ -29,6 +25,47 @@
  * 
  */
 public class ManipulationProperty {
+    
+    /**
+     * Logger info level.
+     */
+    public static final int INFO = 0;
+    
+    /**
+     * Logger warning level. 
+     */
+    public static final int WARNING = 1;
+    
+    /**
+     * Logger severe level. 
+     */
+    public static final int SEVERE = 2;
+    
+    /**
+     * Internal logger implementation.
+     */
+    protected static class Logger {
+        /**
+         * Log method.
+         * @param level : level
+         * @param message : message to log
+         */
+        public void log(int level, String message) {
+            if (level >= m_logLevel) {
+                switch (level) {
+                    case INFO:
+                        System.err.println("[INFO] " + message);
+                        break;
+                    case WARNING:
+                        System.err.println("[WARNING] " + message);
+                        break;
+                    case SEVERE:
+                        System.err.println("[SEVERE] " + message);
+                        break;
+                }
+            }
+        }
+    }
 
     /**
      * Manipulator logger.
@@ -38,7 +75,7 @@
     /**
      * Default logger level.
      */
-    private static Level m_logLevel = Level.WARNING;
+    private static int m_logLevel = WARNING;
 
     /**
      * Get the manipulator logger.
@@ -46,9 +83,7 @@
      */
     public static Logger getLogger() {
         if (m_logger == null) {
-            String name = "org.apache.felix.ipojo.manipulator";
-            m_logger = Logger.getLogger(name);
-            m_logger.setLevel(m_logLevel);
+            m_logger = new Logger();
         }
         return m_logger;
     }

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java?view=diff&rev=555072&r1=555071&r2=555072
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
(original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
Tue Jul 10 13:31:25 2007
@@ -28,7 +28,6 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.logging.Level;
 
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
@@ -79,10 +78,10 @@
             return false;
         }
 
-        URL url = clazz.toURI().toURL();
+        URL url = clazz.toURL();
 
         // if (url == null) { throw new ClassNotFoundException(name); }
-        ManipulationProperty.getLogger().log(Level.INFO, "Manipulate the class file : " +
clazz.getAbsolutePath());
+        ManipulationProperty.getLogger().log(ManipulationProperty.INFO, "Manipulate the class
file : " + clazz.getAbsolutePath());
 
         InputStream is1 = url.openStream();
 
@@ -138,7 +137,7 @@
                 fos.write(cw0.toByteArray());
 
                 fos.close();
-                ManipulationProperty.getLogger().log(Level.INFO, "Put the file " + clazz.getAbsolutePath()
+ " in the jar file");
+                ManipulationProperty.getLogger().log(ManipulationProperty.INFO, "Put the
file " + clazz.getAbsolutePath() + " in the jar file");
             } catch (Exception e) {
                 System.err.println("Problem to write the adapted class on the file system
" + " [ " + clazz.getAbsolutePath() + " ] " + e.getMessage());
             }

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java?view=diff&rev=555072&r1=555071&r2=555072
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java
(original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java
Tue Jul 10 13:31:25 2007
@@ -18,8 +18,6 @@
  */
 package org.apache.felix.ipojo.manipulation;
 
-import java.util.logging.Level;
-
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
@@ -68,12 +66,10 @@
     public void visitFieldInsn(final int opcode, final String owner, final String name, final
String desc) {
         if (owner.equals(m_owner)) {
             if (opcode == GETFIELD) {
-                ManipulationProperty.getLogger().log(Level.INFO, "Manipulate a GETFIELD on
: " + name);
                 String gDesc = "()" + desc;
                 visitMethodInsn(INVOKEVIRTUAL, owner, "_get" + name, gDesc);
                 return;
             } else if (opcode == PUTFIELD) {
-                ManipulationProperty.getLogger().log(Level.INFO, "Manipulate a PUTFIELD on
: " + name);
                 String sDesc = "(" + desc + ")V";
                 visitMethodInsn(INVOKESPECIAL, owner, "_set" + name, sDesc);
                 return;

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java?view=diff&rev=555072&r1=555071&r2=555072
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
(original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
Tue Jul 10 13:31:25 2007
@@ -29,7 +29,6 @@
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
@@ -211,7 +210,7 @@
                 }
             }
         } catch (IOException e) {
-            error("Cannot manipulate the Jar file : " + e.getMessage() + " - Cause : " +
e.getCause());
+            error("Cannot manipulate the Jar file : " + e.getMessage());
             return;
         }
 
@@ -222,7 +221,7 @@
             jos = null;
             fos = null;
         } catch (IOException e) {
-            error("Cannot close the new Jar file : " + e.getMessage() + " - Cause : " + e.getCause());
+            error("Cannot close the new Jar file : " + e.getMessage());
             return;
         }
     }
@@ -443,7 +442,7 @@
             return new HashMap();
         }
 
-        Map result = new LinkedHashMap();
+        Map result = new HashMap();
         QuotedTokenizer qt = new QuotedTokenizer(value, ";=,");
         char del;
         do {
@@ -525,7 +524,7 @@
         URL url;
         Element[] meta = null;
         try {
-            url = metadata.toURI().toURL();
+            url = metadata.toURL();
             if (url == null) {
                 error("Cannot find the metdata file : " + path);
                 return null;



Mime
View raw message