Applied major patch to iPOJO (FELIX-166).
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@469182 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo.metadata/pom.xml b/ipojo.metadata/pom.xml
index 13ad0fb..8baf64e 100644
--- a/ipojo.metadata/pom.xml
+++ b/ipojo.metadata/pom.xml
@@ -7,6 +7,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>org.apache.felix.ipojo.metadata</artifactId>
<packaging>jar</packaging>
- <version>0.6.0-SNAPSHOT</version>
+ <version>0.7.0-incubator-SNAPSHOT</version>
<name>Apache Felix iPOJO Metadata</name>
</project>
diff --git a/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java b/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java
index 89451a4..88e0540 100644
--- a/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java
+++ b/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Attribute.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.metadata;
diff --git a/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java b/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
index ff4e428..c9779a5 100644
--- a/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
+++ b/ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/Element.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.metadata;
diff --git a/ipojo.plugin/pom.xml b/ipojo.plugin/pom.xml
index 0e476d8..e5809a9 100644
--- a/ipojo.plugin/pom.xml
+++ b/ipojo.plugin/pom.xml
@@ -6,7 +6,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.apache.felix.ipojo.plugin</artifactId>
- <version>0.6.0-SNAPSHOT</version>
+ <version>0.7.0-incubator-SNAPSHOT</version>
<name>Apache Felix iPOJO Maven Plugin</name>
<packaging>maven-plugin</packaging>
<dependencies>
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
index e8880f9..95e1b42 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
@@ -1,3 +1,21 @@
+/*
+ * 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.felix.ipojo.manipulation;
import java.util.HashMap;
@@ -32,7 +50,7 @@
*/
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
- if (access == ACC_PRIVATE && name.equals("_cm") && desc.equals("Lorg/apache/felix/ipojo/ComponentManager;")) {
+ if (access == ACC_PRIVATE && name.equals("_cm") && desc.equals("Lorg/apache/felix/ipojo/ComponentManagerImpl;")) {
isAlreadyManipulated = true;
}
@@ -45,11 +63,9 @@
}
else {
String nameType = type.getClassName().substring(0, type.getClassName().length() - 2);
- m_fields.put(name, nameType);
+ m_fields.put(name, nameType + "[]");
}
- } else {
- m_fields.put(name, type.getClassName());
- }
+ } else { m_fields.put(name, type.getClassName()); }
return null;
}
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
index df33d31..a923c0c 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.manipulation;
@@ -46,7 +48,6 @@
public ConstructorCodeAdapter(final MethodVisitor mv, final String owner) {
super(mv);
m_owner = owner;
- System.out.println("Create a constructor adapter");
m_superDetected = false;
}
@@ -95,7 +96,7 @@
//mv.visitVarInsn(ALOAD, Type.getArgumentTypes(m_constructorDesc).length);
mv.visitVarInsn(ALOAD, 1); // CM is always the first argument
// 3) Initialize the field
- mv.visitMethodInsn(INVOKESPECIAL, m_owner, "_setComponentManager", "(Lorg/apache/felix/ipojo/ComponentManager;)V");
+ mv.visitMethodInsn(INVOKESPECIAL, m_owner, "_setComponentManager", "(Lorg/apache/felix/ipojo/ComponentManagerImpl;)V");
// insertion finished
}
else { mv.visitMethodInsn(opcode, owner, name, desc); }
@@ -117,9 +118,9 @@
public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
if(index == 0) {
mv.visitLocalVariable(name, desc, signature, start, end, index);
- mv.visitLocalVariable("_manager", "Lorg/apache/felix/ipojo/ComponentManager;", null, start, end, 1);
+ mv.visitLocalVariable("_manager", "Lorg/apache/felix/ipojo/ComponentManagerImpl;", null, start, end, 1);
IPojoPluginConfiguration.getLogger().log(Level.INFO, "Local Variable : " + name + " index = " + index + " desc = " + desc);
- IPojoPluginConfiguration.getLogger().log(Level.INFO, "Local Variable : " + "_manager" + " index = " + 1 + " desc = " + "Lorg/apache/felix/ipojo/ComponentManager;");
+ IPojoPluginConfiguration.getLogger().log(Level.INFO, "Local Variable : " + "_manager" + " index = " + 1 + " desc = " + "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
}
mv.visitLocalVariable(name, desc, signature, start, end, index+1);
IPojoPluginConfiguration.getLogger().log(Level.INFO, "Local Variable : " + name + " index = " + index + " desc = " + desc);
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java
index 7ce5bd5..2275eab 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ManipulationProperty.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.manipulation;
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
index 34f55cc..8e0770a 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.manipulation;
@@ -66,14 +68,16 @@
* @param bundle The component's m_bundle
* @param name The name of the class
* @param cm The component manager attached to this manipulation
- * @return A byte array.
* @throws Exception : throwed if the manipulation failed.
*/
- public void preProcess(String name, File outputDirectory) throws Exception {
+ public boolean preProcess(String name, File outputDirectory) throws Exception {
// gets an input stream to read the bytecode of the class
String path = outputDirectory+"/"+name.replace('.', '/') + ".class";
File clazz = new File(path);
+
+ if(!clazz.exists()) { return false; }
+
URL url = clazz.toURI().toURL();
//if (url == null) { throw new ClassNotFoundException(name); }
@@ -118,8 +122,9 @@
fos.close();
IPojoPluginConfiguration.getLogger().log(Level.INFO, "Put the file " + file.getAbsolutePath() + " in the jar file");
} catch (Exception e) { System.err.println("Problem to write the adapted class on the file system " + " [ "+ file.getAbsolutePath() +" ] " + e.getMessage()); }
-
}
+ // The file is in the bundle
+ return true;
}
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java
index bb569e1..982faa9 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessClassAdapter.java
@@ -1,22 +1,23 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.manipulation;
-import java.util.HashMap;
import java.util.logging.Level;
import org.apache.felix.ipojo.plugin.IPojoPluginConfiguration;
@@ -78,7 +79,7 @@
m_owner = name;
// Insert _cm field
- FieldVisitor fv = super.visitField(ACC_PRIVATE, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;", null, null);
+ FieldVisitor fv = super.visitField(ACC_PRIVATE, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;", null, null);
fv.visitEnd();
// Create the _cmSetter(ComponentManager cm) method
@@ -107,7 +108,7 @@
if(name.equals("<init>")) {
// 1) change the constructor descriptor (add a component manager arg as first argument)
String new_desc = desc.substring(1);
- new_desc = "(Lorg/apache/felix/ipojo/ComponentManager;"+new_desc;
+ new_desc = "(Lorg/apache/felix/ipojo/ComponentManagerImpl;"+new_desc;
// Insert the new constructor
MethodVisitor mv = super.visitMethod(ACC_PUBLIC, "<init>", new_desc, null, null);
@@ -128,11 +129,11 @@
* Create the setter method for the _cm field.
*/
private void createComponentManagerSetter() {
- MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_setComponentManager", "(Lorg/apache/felix/ipojo/ComponentManager;)V", null, null);
+ MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_setComponentManager", "(Lorg/apache/felix/ipojo/ComponentManagerImpl;)V", null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
- mv.visitFieldInsn(PUTFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitFieldInsn(PUTFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
mv.visitInsn(RETURN);
@@ -200,10 +201,10 @@
mv.visitFieldInsn(PUTFIELD, m_owner, name, internalType);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
mv.visitInsn(RETURN);
@@ -234,10 +235,10 @@
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 2);
@@ -308,10 +309,10 @@
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 2);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitVarInsn(ASTORE, 3);
mv.visitVarInsn(ALOAD, 3);
@@ -348,10 +349,10 @@
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "getterCallback", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
mv.visitVarInsn(ASTORE, 2);
mv.visitVarInsn(ALOAD, 2);
@@ -429,10 +430,10 @@
Label l2 = new Label();
mv.visitLabel(l2);
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 2);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
Label l3 = new Label();
mv.visitLabel(l3);
@@ -445,10 +446,10 @@
mv.visitFieldInsn(PUTFIELD, m_owner, name, "L" + type.getInternalName() + ";");
mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManager;");
+ mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/ComponentManagerImpl;");
mv.visitLdcInsn(name);
mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManager", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/ComponentManagerImpl", "setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
mv.visitInsn(RETURN);
break;
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java
index bea6444..6a2e235 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/PreprocessCodeAdapter.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.manipulation;
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
index 7158c68..ca83af9 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.parser;
@@ -89,7 +91,6 @@
public void parse(Dictionary dict) throws ParseException {
m_headers = dict;
String componentClassesStr = (String)m_headers.get("iPOJO-Components");
- System.out.println("Parse : " + componentClassesStr);
parseElements(componentClassesStr.trim());
}
@@ -110,7 +111,6 @@
for (int i = 0; i < string.length; i++) {
char c = string[i];
- System.out.println("Analyse : " + c);
switch(c) {
case '$' :
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java
index c59afd8..85758c8 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/ParseException.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.parser;
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java
index 3cc91bd..66ac076 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/parser/XMLMetadataParser.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.parser;
@@ -42,6 +44,16 @@
return m_elements[0].getElements("Component");
}
+ public Element[] getMetadata() throws ParseException {
+ Element[] comp = m_elements[0].getElements("Component");
+ Element[] conf = m_elements[0].getElements("Instance");
+ Element[] metadata = new Element[comp.length + conf.length];
+ int l = 0;
+ for(int i = 0; i < comp.length; i++) { metadata[l] = comp[i]; l++;}
+ for(int i = 0; i < conf.length; i++) { metadata[l] = conf[i]; l++;}
+ return metadata;
+ }
+
/* (non-Javadoc)
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Clazz.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Clazz.java
index 79c6dc8..a034ed1 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Clazz.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Clazz.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.plugin;
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/IPojoPluginConfiguration.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/IPojoPluginConfiguration.java
index b81e5e2..150d036 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/IPojoPluginConfiguration.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/IPojoPluginConfiguration.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.plugin;
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Jar.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Jar.java
index f630b7c..58b09c7 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Jar.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/Jar.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.plugin;
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
index 807a68d..6ccd1e8 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiJarMojo.java
@@ -1,20 +1,21 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.plugin;
import java.io.*;
@@ -505,7 +506,8 @@
* Calculate the bundle class path based on the list of JARs in our bundle.
* This list includes outselves. We also calculate the Bundle-Classpath
* header (a bit clumsy) This is a bit cheap, so maybe this needs to be
- * changed TODO
+ * changed
+
*
* @param mainJar
* @return
@@ -848,7 +850,7 @@
private Element[] parseXMLMetadata(String path) throws MojoExecutionException {
File metadata = new File(outputDirectory+path);
URL url;
- Element[] components = null;
+ Element[] meta = null;
try {
url = metadata.toURI().toURL();
if (url == null) {
@@ -863,7 +865,7 @@
InputSource is = new InputSource(stream);
parser.parse(is);
- components = handler.getComponentsMetadata();
+ meta = handler.getMetadata();
} catch (MalformedURLException e) {
getLog().error("Malformed URL for " + outputDirectory+path+ "("+e.getMessage()+")");
@@ -876,12 +878,12 @@
throw new MojoExecutionException("[iPOJO] Parsing Error when parsing the XML file " + outputDirectory+path);
}
- if(components == null || components.length == 0) {
- getLog().error("No component in " + outputDirectory+path);
+ if(meta == null || meta.length == 0) {
+ getLog().error("No component in " + outputDirectory+path); //TODO : change the message
throw new MojoExecutionException("[iPOJO] No component in " + outputDirectory+path);
}
- return components;
+ return meta;
}
private Element[] parseManifestMetadata(String metadata) throws MojoExecutionException {
@@ -908,18 +910,18 @@
//Try to read the content of a file of the ouptut directory
getLog().info("iPOJO Manipulation ...");
- Element[] components = null;
+ Element[] original_meta = null;
// Get the metadata.xml location
String path = (String) osgiManifest.getEntries().get("iPOJO-Metadata");
if(path != null) {
if(!path.startsWith("/")) { path = "/" + path; }
- components = parseXMLMetadata(path);
+ original_meta = parseXMLMetadata(path);
} else {
String meta_ = (String) osgiManifest.getEntries().get("iPOJO-Components");
if(meta_ != null) {
- components = parseManifestMetadata(meta_);
+ original_meta = parseManifestMetadata(meta_);
} else {
getLog().error("Neither iPOJO-Metadata nor iPOJO-Components are in the manifest, please in the osgi-bundle packaging instead og ipojo-bundle");
throw new MojoExecutionException("[iPOJO] Neither iPOJO-Metadata nor iPOJO-Components are in the manifest");
@@ -927,45 +929,49 @@
}
Manipulator manipulator = new Manipulator();
- String[] metadata = new String[components.length];
+ String[] metadata = new String[original_meta.length];
String meta = "";
- if(namespaces == null) { namespaces = new String[components.length][]; }
- for(int i = 0; i < components.length; i++) {
- getLog().info("Component Class Name : " + components[i].getAttribute("className"));
- namespaces[i] = components[i].getNamespaces();
- try {
- manipulator.preProcess(components[i].getAttribute("className"), outputDirectory);
- } catch (Exception e) {
- getLog().error("Manipulation error in the class : " + components[i].getAttribute("className") + "("+e.getMessage()+")");
- throw new MojoExecutionException("[iPOJO] Manipulation error in the class : " + components[i].getAttribute("className"));
- }
+
+ if(namespaces == null) { namespaces = new String[original_meta.length][]; } //NO
+ for(int i = 0; i < original_meta.length; i++) {
+ if(original_meta[i].getName().equalsIgnoreCase("component")) {
+ getLog().info("Component Class Name : " + original_meta[i].getAttribute("className"));
+ namespaces[i] = original_meta[i].getNamespaces();
+ try {
+ manipulator.preProcess(original_meta[i].getAttribute("className"), outputDirectory);
+ } catch (Exception e) {
+ getLog().error("Manipulation error in the class : " + original_meta[i].getAttribute("className") + "("+e.getMessage()+")");
+ throw new MojoExecutionException("[iPOJO] Manipulation error in the class : " + original_meta[i].getAttribute("className"));
+ }
- getLog().info("Add manipulation metadata for : " + components[i].getAttribute("className"));
- // Insert information to metadata
- Element elem = new Element("Manipulation", "");
- for(int j = 0; j < manipulator.getInterfaces().length; j++) {
- // Create an interface element for each implemented interface
- Element itf = new Element("Interface", "");
- Attribute att =new Attribute("name", manipulator.getInterfaces()[j]);
- itf.addAttribute(att);
- elem.addElement(itf);
- }
+ getLog().info("Add manipulation metadata for : " + original_meta[i].getAttribute("className"));
+ // Insert information to metadata
+ Element elem = new Element("Manipulation", "");
+ for(int j = 0; j < manipulator.getInterfaces().length; j++) {
+ // Create an interface element for each implemented interface
+ Element itf = new Element("Interface", "");
+ Attribute att =new Attribute("name", manipulator.getInterfaces()[j]);
+ itf.addAttribute(att);
+ elem.addElement(itf);
+ }
- for(Iterator it = manipulator.getFields().keySet().iterator(); it.hasNext(); ) {
- Element field = new Element("Field", "");
- String name = (String) it.next();
- String type = (String) manipulator.getFields().get(name);
- Attribute attName =new Attribute("name", name);
- Attribute attType =new Attribute("type", type);
- field.addAttribute(attName);
- field.addAttribute(attType);
- elem.addElement(field);
- }
+ for(Iterator it = manipulator.getFields().keySet().iterator(); it.hasNext(); ) {
+ Element field = new Element("Field", "");
+ String name = (String) it.next();
+ String type = (String) manipulator.getFields().get(name);
+ Attribute attName =new Attribute("name", name);
+ Attribute attType =new Attribute("type", type);
+ field.addAttribute(attName);
+ field.addAttribute(attType);
+ elem.addElement(field);
+ }
- components[i].addElement(elem);
+ original_meta[i].addElement(elem);
+ } else { namespaces[i] = new String[0]; }
+
// Transform the metadate to manifest metadata
- metadata[i] = buildManifestMetadata(components[i], "");
+ metadata[i] = buildManifestMetadata(original_meta[i], "");
meta = meta + metadata[i];
}
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiManifest.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiManifest.java
index 37277fc..68046e1 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiManifest.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/OsgiManifest.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.plugin;
diff --git a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/QuotedTokenizer.java b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/QuotedTokenizer.java
index c532961..5f2b12c 100644
--- a/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/QuotedTokenizer.java
+++ b/ipojo.plugin/src/main/java/org/apache/felix/ipojo/plugin/QuotedTokenizer.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.plugin;
diff --git a/ipojo.plugin/src/main/resources/META-INF/plexus/components.xml b/ipojo.plugin/src/main/resources/META-INF/plexus/components.xml
index 800acd1..d6710f2 100644
--- a/ipojo.plugin/src/main/resources/META-INF/plexus/components.xml
+++ b/ipojo.plugin/src/main/resources/META-INF/plexus/components.xml
@@ -26,13 +26,13 @@
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
- <role-hint>ipojo-bundle</role-hint>
+ <role-hint>ipojo-bundle</role-hint>;
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
+ <extension>jar</extension>
<type>ipojo-bundle</type>
<includesDependencies>true</includesDependencies>
<language>java</language>
- <extension>jar</extension>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
diff --git a/ipojo/pom.xml b/ipojo/pom.xml
index a9119a0..0b47da4 100644
--- a/ipojo/pom.xml
+++ b/ipojo/pom.xml
@@ -8,7 +8,7 @@
<packaging>osgi-bundle</packaging>
<name>Apache Felix iPOJO</name>
<artifactId>org.apache.felix.ipojo</artifactId>
- <version>0.6.0-SNAPSHOT</version>
+ <version>0.7.0-incubator-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
@@ -24,7 +24,7 @@
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>org.apache.felix.ipojo.metadata</artifactId>
- <version>${pom.version}</version>
+ <version>0.7.0-incubator-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
@@ -40,10 +40,15 @@
<bundleVendor>Clement ESCOFFIER</bundleVendor>
<bundleDescription> iPOJO </bundleDescription>
<importPackage>
- org.osgi.framework, org.osgi.service.cm
+ org.osgi.framework; specification-version="1.3",
+ org.osgi.service.cm; specification-version="1.2"
</importPackage>
<exportPackage>
- org.apache.felix.ipojo, org.apache.felix.ipojo.metadata, org.apache.felix.ipojo.architecture, org.apache.felix.ipojo.parser, org.osgi.service.cm
+ org.apache.felix.ipojo,
+ org.apache.felix.ipojo.metadata,
+ org.apache.felix.ipojo.architecture,
+ org.apache.felix.ipojo.parser,
+ org.osgi.service.cm; specification-version="1.2"
</exportPackage>
</osgiManifest>
</configuration>
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java b/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
index 70ba2af..9eed6d1 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Activator.java
@@ -1,23 +1,23 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo;
-
-
import java.io.IOException;
import java.util.Dictionary;
import java.util.logging.Level;
@@ -36,19 +36,16 @@
*/
public class Activator implements BundleActivator {
+ // STATIC
+ /**
+ * The iPOJO static logger. This logger is used by each iPOJO instance.
+ */
+ private static Logger m_logger = Logger.getLogger("org.apache.felix.ipojo");
- // STATIC
- /**
- * The iPOJO static logger. This logger is used by each iPOJO instance.
- */
- private static Logger m_logger = Logger.getLogger("org.apache.felix.ipojo");
-
- /**
+ /**
* @return Returns the static ipojo logger : org.apache.felix.ipojo
*/
- public static Logger getLogger() {
- return Activator.m_logger;
- }
+ public static Logger getLogger() { return Activator.m_logger; }
// END STATIC
// NON STATIC PART
@@ -65,6 +62,12 @@
*/
private ComponentManagerFactory[] m_factories;
+ /**
+ * The configuration to create.
+ * m_configuration : Array of Dictionary
+ */
+ private Dictionary[] m_configurations;
+
// Field accessors :
/**
@@ -79,10 +82,10 @@
* @param cm : the new component metadata.
*/
public void addComponentFactory(Element cm) {
- // Create the factory :
- ComponentManagerFactory factory = new ComponentManagerFactory(m_bundleContext, cm);
+ // Create the factory :
+ ComponentManagerFactory factory = new ComponentManagerFactory(m_bundleContext, cm);
- // If the factory array is not empty add the new factory at the end
+ // If the factory array is not empty add the new factory at the end
if (m_factories.length != 0) {
ComponentManagerFactory[] newFactory = new ComponentManagerFactory[m_factories.length + 1];
System.arraycopy(m_factories, 0, newFactory, 0, m_factories.length);
@@ -110,7 +113,7 @@
if (idx >= 0) {
// If this is the factory, then point to empty list.
if ((m_factories.length - 1) == 0) {
- m_factories = new ComponentManagerFactory[0];
+ m_factories = new ComponentManagerFactory[0];
}
// Otherwise, we need to do some array copying.
else {
@@ -147,33 +150,18 @@
* @throws Exception : when a problem occurs
*/
public void start(final BundleContext bc) throws Exception {
- m_bundleContext = bc;
+ m_bundleContext = bc;
+ Activator.getLogger().setLevel(IPojoConfiguration.LOG_LEVEL);
- // Set the trace level
- String level = System.getProperty("ipojo.loglevel");
- if (level != null) {
- if (level.equals("ALL")) {
- Activator.getLogger().setLevel(Level.ALL);
- }
- if (level.equals("FINEST")) {
- Activator.getLogger().setLevel(Level.FINEST);
- }
- if (level.equals("WARNING")) {
- Activator.getLogger().setLevel(Level.WARNING);
- }
- }
- else { Activator.getLogger().setLevel(IPojoConfiguration.LOG_LEVEL); }
+ try {
+ parse();
+ } catch (Exception e) {
+ Activator.getLogger().log(Level.SEVERE, "Parse error for the bundle " + m_bundleContext.getBundle().getBundleId() + " : " + e.getMessage());
+ return;
+ }
+ Activator.getLogger().log(Level.INFO, "[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Called start after the parsing");
- try {
- parse();
- } catch (Exception e) {
- Activator.getLogger().log(Level.SEVERE, "Parse error for the bundle " + m_bundleContext.getBundle().getBundleId() + " : " + e.getMessage());
- return;
- }
- Activator.getLogger().log(Level.INFO, "[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Called start after the parsing");
-
- // Call the internal start method
- start();
+ start(); // Call the internal start method
}
@@ -185,8 +173,8 @@
*/
public void stop(BundleContext arg0) throws Exception {
for (int i = 0; i < m_factories.length; i++) {
- ComponentManagerFactory factory = m_factories[i];
- factory.stop();
+ ComponentManagerFactory factory = m_factories[i];
+ factory.stop();
}
}
@@ -197,29 +185,36 @@
/**
* Parse the file who is at the Metadata-Location place, manipulate the bytecode of the component implementation class
* and set the manager.
- * @throws IOException
- * @throws ParseException
+ * @throws IOException : the manisfest could not be found
+ * @throws ParseException : the parsing process failed
*/
private void parse() throws IOException, ParseException {
- String componentClasses = (String)m_bundleContext.getBundle().getHeaders().get("iPOJO-Components");
+ String componentClasses = (String) m_bundleContext.getBundle().getHeaders().get("iPOJO-Components");
if (componentClasses != null) {
- parseManifest(m_bundleContext.getBundle().getHeaders());
+ parseManifest(m_bundleContext.getBundle().getHeaders());
} else {
- Activator.getLogger().log(Level.SEVERE, "[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Components-Metadata are not in the manifest");
- throw new ParseException("[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Component-Metadata are not in the manifest");
+ Activator.getLogger().log(Level.SEVERE, "[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Components-Metadata are not in the manifest");
+ throw new ParseException("[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Component-Metadata are not in the manifest");
}
}
+ /**
+ * Parse the manifest.
+ * @param dict : Manifest Entries
+ * @throws ParseException : throwed when the parsing failed
+ */
private void parseManifest(Dictionary dict) throws ParseException {
- ManifestMetadataParser parser = new ManifestMetadataParser();
- parser.parse(dict);
- // Create the components Factory according to the declared component
+ ManifestMetadataParser parser = new ManifestMetadataParser();
+ parser.parse(dict);
+ // Create the components Factory according to the declared component
Element[] componentsMetadata = parser.getComponentsMetadata();
+ m_configurations = parser.getInstances();
for (int i = 0; i < componentsMetadata.length; i++) {
- Activator.getLogger().log(Level.INFO, "[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Create a component factory for " + componentsMetadata[i].getAttribute("classname"));
- addComponentFactory(componentsMetadata[i]);
+ Activator.getLogger().log(Level.INFO, "[Bundle" + m_bundleContext.getBundle().getBundleId() + "] Create a component factory for " + componentsMetadata[i].getAttribute("classname"));
+ addComponentFactory(componentsMetadata[i]);
}
+
}
/**
@@ -228,7 +223,14 @@
private void start() {
for (int i = 0; i < m_factories.length; i++) {
ComponentManagerFactory factory = m_factories[i];
- factory.start(); // Start the management
+ String componentClass = factory.getComponentClassName();
+ for (int j = 0; j < m_configurations.length; j++) {
+ Dictionary conf = m_configurations[j];
+ if (conf.get("component") != null && conf.get("component").equals(componentClass)) {
+ factory.createComponent(m_configurations[j]); // create a component
+ }
+ }
+ factory.start(); // Start the factory exposition
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Callback.java b/ipojo/src/main/java/org/apache/felix/ipojo/Callback.java
index b3a0c1b..d410547 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Callback.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Callback.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo;
@@ -23,33 +25,33 @@
/**
- * A callback allows calling a method on the component.
+ * A callback allows calling a method on the component instances.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public class Callback {
- /**
- * Name of the method to call.
- */
- private String m_method;
+ /**
+ * Name of the method to call.
+ */
+ private String m_method;
- /**
- * Is the method a static method ?
- */
- private boolean m_isStatic;
+ /**
+ * Is the method a static method ?
+ */
+ private boolean m_isStatic;
- /**
- * Reference on the component manager.
- */
- private ComponentManager m_manager;
+ /**
+ * Reference on the component manager.
+ */
+ private ComponentManagerImpl m_manager;
- /**
+ /**
* LifecycleCallback constructor.
* @param method : the name of the method to call
* @param isStatic : is the method a static method
* @param cm : the component manager of the component containing the method
*/
- public Callback(String method, boolean isStatic, ComponentManager cm) {
+ public Callback(String method, boolean isStatic, ComponentManagerImpl cm) {
m_method = method;
m_isStatic = isStatic;
m_manager = cm;
@@ -62,28 +64,42 @@
* @throws IllegalAccessException : The method can not be invoked
*/
public void call() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Call an callback method : " + m_method);
+ Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Call an callback method : " + m_method);
Method method = m_manager.getClazz().getMethod(m_method, new Class[] {});
method.setAccessible(true);
if (m_isStatic) { method.invoke(null, new Object[]{}); }
else {
- // Two cases :
- // - if instances already exists : call on each instances
- // - if no instance exists : create an instance
- if (m_manager.getInstances().length == 0) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Create the first instance " + m_manager.getInstance());
- method.invoke(m_manager.getInstance(), new Object[]{});
- } else {
- for (int i = 0; i < m_manager.getInstances().length; i++) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Call the callback on the instance " + m_manager.getInstances()[i]);
- method.invoke(m_manager.getInstances()[i], new Object[]{});
- }
- }
+ // Two cases :
+ // - if instances already exists : call on each instances
+ // - if no instance exists : create an instance
+ if (m_manager.getInstances().length == 0) {
+ Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Create the first instance " + m_manager.getInstance());
+ method.invoke(m_manager.getInstance(), new Object[]{});
+ } else {
+ for (int i = 0; i < m_manager.getInstances().length; i++) {
+ Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Call the callback on the instance " + m_manager.getInstances()[i]);
+ method.invoke(m_manager.getInstances()[i], new Object[]{});
+ }
+ }
}
}
/**
+ * Call the current callback method on the instance given in parameter.
+ * @param instance : instance on which call the callbakc
+ * @throws NoSuchMethodException : the method was not found
+ * @throws IllegalAccessException : the method cannont be called
+ * @throws InvocationTargetException : an error happens in the method
+ */
+ public void call(Object instance) throws NoSuchMethodException,
+ IllegalAccessException, InvocationTargetException {
+ Method method = m_manager.getClazz().getMethod(m_method, new Class[] {});
+ method.setAccessible(true);
+ method.invoke(instance, new Object[] {});
+ }
+
+ /**
* Call the callback on the method with the argument given in parameter.
* @param arg : the parameters
* @throws NoSuchMethodException : the callback method is not found
@@ -91,29 +107,49 @@
* @throws InvocationTargetException : an error occurs inside the called method
*/
public void call(Object[] arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Call an callback method : " + m_method);
+ Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Call an callback method : " + m_method);
- // Build an array of call for arg :
- Class[] classes = new Class[arg.length];
- for (int i = 0; i < arg.length; i++) {
- classes[i] = arg[i].getClass();
- }
+ // Build an array of call for arg :
+ Class[] classes = new Class[arg.length];
+ for (int i = 0; i < arg.length; i++) {
+ classes[i] = arg[i].getClass();
+ }
Method method = m_manager.getClazz().getMethod(m_method, classes);
method.setAccessible(true);
if (m_isStatic) { method.invoke(null, arg); }
else {
- // Two cases :
- // - if instances already exists : call on each instances
- // - if no instance exists : create an instance
- if (m_manager.getInstances().length == 0) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Create the first instance " + m_manager.getInstance());
- method.invoke(m_manager.getInstance(), new Object[]{});
- } else {
- for (int i = 0; i < m_manager.getInstances().length; i++) {
- method.invoke(m_manager.getInstances()[i], arg);
- }
- }
+ // Two cases :
+ // - if instances already exists : call on each instances
+ // - if no instance exists : create an instance
+ if (m_manager.getInstances().length == 0) {
+ Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Create the first instance " + m_manager.getInstance());
+ method.invoke(m_manager.getInstance(), new Object[]{});
+ } else {
+ for (int i = 0; i < m_manager.getInstances().length; i++) {
+ method.invoke(m_manager.getInstances()[i], arg);
+ }
+ }
}
}
+
+ /**
+ * Call the callback on the method with the argument given in parameter and with the arguments given in parameter too.
+ * @param instance : instance on which call the callback
+ * @param arg : the argument array
+ * @throws NoSuchMethodException : the callback method is not found
+ * @throws IllegalAccessException : the callbback method cannot be called
+ * @throws InvocationTargetException : an error occurs inside the called method
+ */
+ public void call(Object instance, Object[] arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ // Build an array of call for arg :
+ Class[] classes = new Class[arg.length];
+ for (int i = 0; i < arg.length; i++) {
+ classes[i] = arg[i].getClass();
+ }
+
+ Method method = m_manager.getClazz().getMethod(m_method, classes);
+ method.setAccessible(true);
+ method.invoke(instance, arg);
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInfo.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInfo.java
new file mode 100644
index 0000000..7d10e41
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentInfo.java
@@ -0,0 +1,95 @@
+/*
+ * 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.felix.ipojo;
+
+import java.util.ArrayList;
+import java.util.List;
+/**
+ * Component Type information.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class ComponentInfo {
+
+ /**
+ * Provided service by the component type.
+ */
+ private ArrayList m_providedServiceSpecification = new ArrayList();
+
+ /**
+ * Component Type implementation class.
+ */
+ private String m_className;
+
+ /**
+ * Configuration Properties accepted by the component type.
+ */
+ private ArrayList m_properties = new ArrayList();
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ String res = "";
+ res += "Component : " + m_className + "\n";
+ for (int i = 0; i < m_providedServiceSpecification.size(); i++) {
+ res += "\tProvides : " + (String) m_providedServiceSpecification.get(i) + "\n";
+ }
+ for (int i = 0; i < m_properties.size(); i++) {
+ res += "\tProperty : " + (PropertyInfo) m_properties.get(i) + "\n";
+ }
+ return res;
+ }
+
+ /**
+ * @return the component type implementation class name.
+ */
+ public String getClassName() { return m_className; }
+
+ /**
+ * Set the component type implementation class name.
+ * @param name : the name of the implementation class
+ */
+ protected void setClassName(String name) { m_className = name; }
+
+ /**
+ * @return the list of configuration properties accepted by the component type.
+ */
+ public List getProperties() { return m_properties; }
+
+ /**
+ * Add a configuration properties to the component type.
+ * @param pi : the property to add
+ */
+ public void addProperty(PropertyInfo pi) { this.m_properties.add(pi); }
+
+ /**
+ * @return the list of the provided service.
+ */
+ public List getprovidedServiceSpecification() { return m_providedServiceSpecification; }
+
+ /**
+ * add a provided service to the component type.
+ * @param serviceSpecification : the provided service to add (interface name)
+ */
+ public void addProvidedServiceSpecification(String serviceSpecification) { m_providedServiceSpecification.add(serviceSpecification); }
+
+
+
+
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java
index 8a0c4d8..37bfe64 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManager.java
@@ -1,496 +1,70 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.logging.Level;
-
-import org.apache.felix.ipojo.metadata.Element;
-import org.osgi.framework.BundleContext;
-
/**
- * The component manager class manage one "version" of a component.
- * It manages component lifecycle, component instance creation and handlers.
+ * The component manager class manages one instance of a component type.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class ComponentManager {
+public interface ComponentManager {
- // STATIC PART
-
- /**
+ /**
* Component State : INVALID.
* The component is invalid when it start or when a component dependency is unvalid.
*/
- public static final int INVALID = 1;
+ int INVALID = 1;
/**
* Component State : VALID.
* The component is resolved when it is running and all its component dependencies are valid.
*/
- public static final int VALID = 2;
+ int VALID = 2;
- // END STATIC PART
-
- /**
- * Parent factory (ComponentManagerFactory).
- */
- private ComponentManagerFactory m_factory;
-
- /**
- * Attached metadata of the managed component.
- */
- private ComponentMetadata m_metadata;
-
- /**
- * The context of the component.
- */
- private BundleContext m_context;
-
- /**
- * Handler list.
- */
- private Handler[] m_handlers = new Handler[0];
-
- /**
- * Component state (STOPPED at the beginning).
- */
- private int m_state = INVALID;
-
- // Fields use for the manipulation, the loading of the class and for the instance creation
-
- /**
- * Manipulatd clazz.
- */
- private Class m_clazz;
-
- /**
- * Instances of the components.
- */
- private Object[] m_instances = new Object[0];
-
- // Constructor
/**
- * Construct a new Component Manager.
- * @param factory : the factory managing the component manager
+ * Start the component manager.
*/
- public ComponentManager(ComponentManagerFactory factory) {
- m_factory = factory;
- m_context = factory.getBundleContext();
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] Create a component manager from the factory " + m_factory);
- }
+ void start();
- /**
- * Configure the component manager.
- * Stop the existings handler, clear the handler list, change the metadata, recreate the handlers
- * @param cm
- */
- public void configure(Element cm) {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] Configure the component manager " + cm.getAttribute("className"));
+ /**
+ * Stop the component manager.
+ */
+ void stop();
- // Stop all previous registred handler
- if (m_handlers.length != 0) { stop(); }
+ /**
+ * @return the actual state of the component.
+ */
+ int getState();
- // Clear the handler list
- m_handlers = new Handler[0];
+ /**
+ * @return the component type information.
+ */
+ ComponentInfo getComponentInfo();
- // Change the metadata
- m_metadata = new ComponentMetadata(cm);
+ /**
+ * @return the component metadata.
+ */
+ ComponentMetadata getComponentMetatada();
- // Create the standard handlers and add these handlers to the list
- for (int i = 0; i < IPojoConfiguration.INTERNAL_HANDLERS.length; i++) {
- // Create a new instance
- try {
- Handler h = (Handler)IPojoConfiguration.INTERNAL_HANDLERS[i].newInstance();
- h.configure(this, cm);
- } catch (InstantiationException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
- } catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
- }
- }
-
- // Look for namespaces
- for (int i = 0; i < cm.getNamespaces().length; i++) {
- if (!cm.getNamespaces()[i].equals("")) {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Look for class for the namespace : " + cm.getNamespaces()[i]);
- // It is not an internal handler, try to load it
- try {
- Class c = m_context.getBundle().loadClass(cm.getNamespaces()[i]);
- Handler h = (Handler) c.newInstance();
- h.configure(this, cm);
- } catch (ClassNotFoundException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
- } catch (InstantiationException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
- } catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
- }
-
- }
- }
- }
-
- /**
- * @return the component metadata.
- */
- public ComponentMetadata getComponentMetatada() { return m_metadata; }
-
- /**
- * @return the list of the registred handlers.
- */
- public Handler[] getRegistredHandlers() { return m_handlers; }
-
- /**
- * Return a specified handler.
- * @param name : class name of the handler to find
- * @return : the handler, or null if not found
- */
- public Handler getHandler(String name) {
- for (int i = 0; i < m_handlers.length; i++) {
- if (m_handlers[i].getClass().getName().equalsIgnoreCase(name)) { return m_handlers[i]; }
- }
- return null;
- }
-
- // ===================== Lifecycle management =====================
-
- /**
- * Start the component manager.
- */
- public void start() {
- // Start all the handlers
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Start the component manager with " + m_handlers.length + " handlers");
-
- // The new state of the component is UNRESOLVED
- m_state = INVALID;
-
- for (int i = 0; i < m_handlers.length; i++) {
- m_handlers[i].start();
- }
-
- // Defines the state of the component :
- check();
- }
-
- /**
- * Stop the component manager.
- */
- public void stop() {
- setState(INVALID);
- // Stop all the handlers
- for (int i = m_handlers.length - 1; i > -1; i--) {
- m_handlers[i].stop();
- }
- m_instances = new Object[0];
- }
-
- /**
- * Set the state of the component.
- * if the state changed call the stateChanged(int) method on the handlers
- */
- public void setState(int state) {
- if (m_state != state) {
-
- // Log the state change
- if (state == INVALID) { Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component " + m_metadata.getClassName() + " State -> UNRESOLVED"); }
- if (state == VALID) { Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component " + m_metadata.getClassName() + " State -> VALID"); }
-
- // The state changed call the handler stateChange method
- m_state = state;
- for (int i = m_handlers.length - 1; i > -1; i--) {
- m_handlers[i].stateChanged(state);
- }
- }
- }
-
- /**
- * @return the actual state of the component
- */
- public int getState() {
- return m_state;
- }
-
- // ===================== end Lifecycle management =====================
-
- // ================== Class & Instance management ===================
-
- /**
- * @return the factory of the component
- */
- public ComponentManagerFactory getFactory() { return m_factory; }
-
- /**
- * Load the manipulated class.
- */
- private void load() {
- try {
- m_clazz = m_factory.loadClass(m_metadata.getClassName());
- } catch (ClassNotFoundException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Class not found during the loading phase : " + e.getMessage());
- return;
- }
- }
-
- /**
- * @return true if the class is loaded
- */
- private boolean isLoaded() {
- return (m_clazz != null);
- }
-
- private void addInstance(Object o) {
- for (int i = 0; (m_instances != null) && (i < m_instances.length); i++) {
- if (m_instances[i] == o) { return; }
- }
-
- if (m_instances.length > 0) {
- Object[] newInstances = new Object[m_instances.length + 1];
- System.arraycopy(m_instances, 0, newInstances, 0, m_instances.length);
- newInstances[m_instances.length] = o;
- m_instances = newInstances;
- }
- else {
- m_instances = new Object[] {o};
- }
- }
-
- private void removeInstance(Object o) {
- int idx = -1;
- for (int i = 0; i < m_instances.length; i++) {
- if (m_instances[i] == o) { idx = i; break; }
- }
-
- if (idx >= 0) {
- if ((m_instances.length - 1) == 0) { m_instances = new Element[0]; }
- else {
- Object[] newInstances = new Object[m_instances.length - 1];
- System.arraycopy(m_instances, 0, newInstances, 0, idx);
- if (idx < newInstances.length) {
- System.arraycopy(m_instances, idx + 1, newInstances, idx, newInstances.length - idx); }
- m_instances = newInstances;
- }
- }
- }
-
- /**
- * @return the created instance of the component.
- */
- public Object[] getInstances() { return m_instances; }
-
- /**
- * Delete the created instance (remove it from the list, to allow the garbage collector to eat the instance).
- * @param o : the instance to delete
- */
- public void deleteInstance(Object o) { removeInstance(o); }
-
- /**
- * Create an instance of the component.
- * This method need to be called one time only for singleton provided service
- * @return a new instance
- */
- public Object createInstance() {
-
- if (!isLoaded()) { load(); }
- Object instance = null;
- try {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Try to find the constructor");
-
- // Try to find if there is a constructor with a bundle context as parameter :
- try {
- Constructor constructor = m_clazz.getConstructor(new Class[] {ComponentManager.class, BundleContext.class});
- constructor.setAccessible(true);
- instance = constructor.newInstance(new Object[] {this, m_factory.getBundleContext()});
- }
- catch (NoSuchMethodException e) {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> No constructor with a bundle context");
- }
-
- // Create an instance if no instance are already created with <init>()BundleContext
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Try to create the object with an empty constructor");
- if (instance == null) {
- Constructor constructor = m_clazz.getConstructor(new Class[] {ComponentManager.class});
- constructor.setAccessible(true);
- instance = constructor.newInstance(new Object[] {this});
- }
-
- } catch (InstantiationException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance cannot be instancied : " + e.getMessage());
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance is not accessible : " + e.getMessage());
- e.printStackTrace();
- } catch (SecurityException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance is not accessible (security reason) : " + e.getMessage());
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> Cannot invoke the constructor method (illegal target) : " + e.getMessage());
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> Cannot invoke the constructor (method not found) : " + e.getMessage());
- e.printStackTrace();
- }
-
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Return the instance " + instance);
-
- // Register the new instance
- addInstance(instance);
- return instance;
- }
-
- /**
- * @return the instance of the component to use for singleton component
- */
- public Object getInstance() {
- if (m_instances.length == 0) { createInstance(); }
- return m_instances[0];
- }
-
- /**
- * @return the manipulated class
- */
- public Class getClazz() {
- if (!isLoaded()) { load(); }
- return m_clazz;
- }
-
- // ================== end Class & Instance management ================
-
- // ======================== Handlers Management ======================
-
- /**
- * Register the given handler to the current component manager.
- * @param h : the handler to register
- */
- public void register(Handler h) {
- for (int i = 0; (m_handlers != null) && (i < m_handlers.length); i++) {
- if (m_handlers[i] == h) {
- return;
- }
- }
-
- if (m_handlers != null) {
- Handler[] newList = new Handler[m_handlers.length + 1];
- System.arraycopy(m_handlers, 0, newList, 0, m_handlers.length);
- newList[m_handlers.length] = h;
- m_handlers = newList;
- }
- }
-
- /**
- * Unregister the given handler.
- * @param h : the handler to unregiter
- */
- public void unregister(Handler h) {
- int idx = -1;
- for (int i = 0; i < m_handlers.length; i++) {
- if (m_handlers[i] == h) {
- idx = i;
- break;
- }
- }
-
- if (idx >= 0) {
- if ((m_handlers.length - 1) == 0) {
- m_handlers = new Handler[0];
- }
- else {
- Handler[] newList = new Handler[m_handlers.length - 1];
- System.arraycopy(m_handlers, 0, newList, 0, idx);
- if (idx < newList.length) {
- System.arraycopy(
- m_handlers, idx + 1, newList, idx, newList.length - idx);
- }
- m_handlers = newList;
- }
- }
- }
-
- /**
- * This method is called by the manipulated class each time that a GETFIELD instruction is found.
- * The method ask to each handler which value need to be returned.
- * @param fieldName : the field name on which the GETFIELD instruction is called
- * @param initialValue : the value of the field in the code
- * @return the value decided by the last asked handler (throw a warining if two fields decide two different values)
- */
- public Object getterCallback(String fieldName, Object initialValue) {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Call the getterCallbackMethod on " + fieldName + " with " + initialValue);
- Object result = null;
- for (int i = 0; i < m_handlers.length; i++) {
- Object handlerResult = m_handlers[i].getterCallback(fieldName, initialValue);
- if (handlerResult != initialValue) { result = handlerResult; }
- }
-
- if (result != null) {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] getterCallbackMethod return for " + fieldName + " -> " + result);
- return result;
- } else {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] getterCallbackMethod return for " + fieldName + " -> " + initialValue);
- return initialValue;
- }
- }
-
- /**
- * This method is called by the manipulated class each time that a PUTFILED instruction is found.
- * the method send to each handler the new value.
- * @param fieldName : the field name on which the PUTFIELD instruction is called
- * @param objectValue : the value of the field
- */
- public void setterCallback(String fieldName, Object objectValue) {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Call the setterCallbackMethod on " + fieldName + " with " + objectValue);
-
- for (int i = 0; i < m_handlers.length; i++) {
- m_handlers[i].setterCallback(fieldName, objectValue);
- }
- }
-
- /**
- * @return the context of the component.
- */
- public BundleContext getContext() { return m_context; }
-
- /**
- * Check the state of all handlers.
- */
- public void check() {
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Check the component state");
- boolean isValid = true;
- for (int i = 0; i < m_handlers.length; i++) {
- boolean b = m_handlers[i].isValid();
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Validity of the handler : " + m_handlers[i] + " = " + b);
- isValid = isValid && b;
- }
-
- // Update the component state if necessary
- if (!isValid && m_state == VALID) {
- // Need to update the state to UNRESOLVED
- setState(INVALID);
- m_instances = new Object[0];
- return;
- }
- if (isValid && m_state == INVALID) {
- setState(VALID);
- if (m_metadata.isImmediate() && m_instances.length == 0) { createInstance(); }
- }
-
- Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component Manager : " + m_state);
- }
+ /**
+ * @return the factory of the component
+ */
+ ComponentManagerFactory getFactory();
- // ======================= end Handlers Management =====================
-
-}
\ No newline at end of file
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java
index bf8eade..bd833ca 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerFactory.java
@@ -1,270 +1,318 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo;
import java.io.IOException;
import java.net.URL;
import java.security.ProtectionDomain;
+import java.util.Collection;
+import java.util.Dictionary;
import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Properties;
import java.util.logging.Level;
import org.apache.felix.ipojo.metadata.Element;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
/**
* The component manager factory class manages component manager object.
+ * This class could export Factory and ManagedServiceFactory services.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class ComponentManagerFactory {
+public class ComponentManagerFactory implements Factory, ManagedServiceFactory {
- // Fields :
- /**
- * List of the managed component manager.
- */
- private ComponentManager[] m_componentManagers = new ComponentManager[0];
-
- /**
- * The bundle context reference.
- */
- private BundleContext m_bundleContext = null;
-
- /**
- * Component class.
- */
- private byte[] m_clazz = null;
-
- /**
- * Component Class Name.
- */
- private String m_componentClassName = null;
-
- /**
- * Classloader to delegate loading.
- */
- private FactoryClassloader m_classLoader = null;
-
- //End field
-
- /**
- * FactoryClassloader.
- */
- private class FactoryClassloader extends ClassLoader {
-
- /**
- * load the class.
- * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
- * @param name : the name of the class
- * @param resolve : should be the class resolve now ?
- * @return : the loaded class
- * @throws ClassNotFoundException : the class to load is not found
- */
- protected synchronized Class loadClass(final String name,
- final boolean resolve) throws ClassNotFoundException {
- return m_bundleContext.getBundle().loadClass(name);
- }
-
-
- /**
- * Return the URL of the asked ressource.
- * @param arg : the name of the resource to find.
- * @return the URL of the resource.
- * @see java.lang.ClassLoader#getResource(java.lang.String)
- */
- public URL getResource(String arg) {
- return m_bundleContext.getBundle().getResource(arg);
- }
-
- /**
- * .
- * @param arg : resource to find
- * @return : the enumeration found
- * @throws IOException : if the lookup failed.
- * @see java.lang.ClassLoader#getResources(java.lang.String)
- */
- public Enumeration getRessources(String arg) throws IOException {
- return m_bundleContext.getBundle().getResources(arg);
- }
-
- /**
- * The defineClass method.
- * @param name : name of the class
- * @param b : the byte array of the class
- * @param domain : the protection domain
- * @return : the defined class.
- * @throws Exception : if a problem is detected during the loading
- */
- public Class defineClass(String name, byte[] b,
- ProtectionDomain domain) throws Exception {
- return super.defineClass(name, b, 0, b.length, domain);
- }
- }
-
- // Field accessors
-
- /**
- * Add a component manager factory to the component manager list.
- * @param cm : the new component metadata.
+ // Fields :
+ /**
+ * List of the managed component manager.
+ * The key of tis hashmap is the name (pid) of the component created
*/
- private void addComponent(ComponentManager cm) {
+ private HashMap m_componentManagers = new HashMap();
- // If the component manager array is not empty add the new factory at the end
- if (m_componentManagers.length != 0) {
- ComponentManager[] newCM = new ComponentManager[m_componentManagers.length + 1];
- System.arraycopy(m_componentManagers, 0, newCM, 0, m_componentManagers.length);
- newCM[m_componentManagers.length] = cm;
- m_componentManagers = newCM;
+ /**
+ * The bundle context reference.
+ */
+ private BundleContext m_bundleContext = null;
+
+ /**
+ * Component class.
+ */
+ private byte[] m_clazz = null;
+
+ /**
+ * Component Class Name.
+ */
+ private String m_componentClassName = null;
+
+ /**
+ * Classloader to delegate loading.
+ */
+ private FactoryClassloader m_classLoader = null;
+
+ /**
+ * Component Type provided by this factory.
+ */
+ private Element m_componentMetadata;
+
+ /**
+ * Service Registration of this factory (Facotry & ManagedServiceFactory).
+ */
+ private ServiceRegistration m_sr;
+
+ /**
+ * Component-Type info exposed by the factory service.
+ */
+ private ComponentInfo m_componentInfo;
+
+ //End field
+
+ /**
+ * FactoryClassloader.
+ */
+ private class FactoryClassloader extends ClassLoader {
+
+ /**
+ * load the class.
+ * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
+ * @param name : the name of the class
+ * @param resolve : should be the class resolve now ?
+ * @return : the loaded class
+ * @throws ClassNotFoundException : the class to load is not found
+ */
+ protected synchronized Class loadClass(final String name,
+ final boolean resolve) throws ClassNotFoundException {
+ return m_bundleContext.getBundle().loadClass(name);
}
- // Else create an array of size one with the new component manager
- else {
- m_componentManagers = new ComponentManager[] {cm};
+
+
+ /**
+ * Return the URL of the asked ressource.
+ * @param arg : the name of the resource to find.
+ * @return the URL of the resource.
+ * @see java.lang.ClassLoader#getResource(java.lang.String)
+ */
+ public URL getResource(String arg) {
+ return m_bundleContext.getBundle().getResource(arg);
+ }
+
+ /**
+ * .
+ * @param arg : resource to find
+ * @return : the enumeration found
+ * @throws IOException : if the lookup failed.
+ * @see java.lang.ClassLoader#getResources(java.lang.String)
+ */
+ public Enumeration getRessources(String arg) throws IOException {
+ return m_bundleContext.getBundle().getResources(arg);
+ }
+
+ /**
+ * The defineClass method.
+ * @param name : name of the class
+ * @param b : the byte array of the class
+ * @param domain : the protection domain
+ * @return : the defined class.
+ * @throws Exception : if a problem is detected during the loading
+ */
+ public Class defineClass(String name, byte[] b,
+ ProtectionDomain domain) throws Exception {
+ return super.defineClass(name, b, 0, b.length, domain);
}
}
- /**
- * Remove the component manager for m the list.
- * @param cm : the component manager to remove
- */
- public void removeComponent(ComponentManager cm) {
- cm.stop();
- int idx = -1;
-
- for (int i = 0; i < m_componentManagers.length; i++) {
- if (m_componentManagers[i] == cm) { idx = i; }
- }
-
- if (idx >= 0) {
- if ((m_componentManagers.length - 1) == 0) { m_componentManagers = new ComponentManager[0]; }
- else {
- ComponentManager[] newCMList = new ComponentManager[m_componentManagers.length - 1];
- System.arraycopy(m_componentManagers, 0, newCMList, 0, idx);
- if (idx < newCMList.length) {
- System.arraycopy(m_componentManagers, idx + 1, newCMList, idx, newCMList.length - idx); }
- m_componentManagers = newCMList;
- }
- }
- }
/**
* @return the iPOJO activator reference
*/
public BundleContext getBundleContext() { return m_bundleContext; }
- // End field accessors
+ /**
+ * @return the class name of the component-type provided by this factory.
+ */
+ protected String getComponentClassName() { return m_componentClassName; }
- /**
- * Create a component manager factory and create a component manager with the given medatada.
- * @param bc : bundle context
- * @param cm : metadata of the component to create
- */
- public ComponentManagerFactory(BundleContext bc, Element cm) {
- m_bundleContext = bc;
- createComponentManager(cm);
- m_componentClassName = cm.getAttribute("className");
- }
+ /**
+ * Create a component manager factory.
+ * @param bc : bundle context
+ * @param cm : metadata of the component to create
+ */
+ public ComponentManagerFactory(BundleContext bc, Element cm) {
+ m_bundleContext = bc;
+ m_componentClassName = cm.getAttribute("className");
+ m_componentMetadata = cm;
+ }
- /**
- * Create a component manager factory and create a component manager with the given medatada.
- * @param bc : bundle context
- * @param clazz : the component class
- * @param cm : metadata of the component
- */
- public ComponentManagerFactory(BundleContext bc, byte[] clazz, Element cm) {
- m_bundleContext = bc;
- m_clazz = clazz;
- m_componentClassName = cm.getAttribute("className");
- createComponentManager(cm);
- }
+ /**
+ * Create a component manager factory. The class is given in parameter.
+ * @param bc : bundle context
+ * @param clazz : the component class
+ * @param cm : metadata of the component
+ */
+ public ComponentManagerFactory(BundleContext bc, byte[] clazz, Element cm) {
+ m_bundleContext = bc;
+ m_clazz = clazz;
+ m_componentClassName = cm.getAttribute("className");
+ m_componentMetadata = cm;
+ }
- /**
- * Create a component manager factory, no component manager are created.
- * @param bc
- */
- public ComponentManagerFactory(BundleContext bc) {
- m_bundleContext = bc;
- }
+ /**
+ * Create a component manager factory, no component manager are created.
+ * @param bc
+ */
+ public ComponentManagerFactory(BundleContext bc) { m_bundleContext = bc; }
- /**
- * Create a component manager form the component metadata.
- * @param cm : Component Metadata
- * @return a component manager configured with the metadata
- */
- public ComponentManager createComponentManager(Element cm) {
- ComponentManager component = new ComponentManager(this);
- component.configure(cm);
- addComponent(component);
- return component;
- }
- // Factory lifecycle management
+ // Factory lifecycle management
- /**
- * Stop all the component managers.
- */
- public void stop() {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Stop the component factory");
- for (int i = 0; i < m_componentManagers.length; i++) {
- ComponentManager cm = m_componentManagers[i];
- cm.stop();
- }
- }
+ /**
+ * Stop all the component managers.
+ */
+ public void stop() {
+ Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Stop the component factory");
+ Collection col = m_componentManagers.values();
+ Iterator it = col.iterator();
+ while (it.hasNext()) {
+ ComponentManagerImpl cm = (ComponentManagerImpl) it.next();
+ cm.stop();
+ }
+ m_componentManagers.clear();
+ if (m_sr != null) { m_sr.unregister(); }
+ m_sr = null;
+ }
- /**
- * Start all the component managers.
- */
- public void start() {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Start the component factory");
- for (int i = 0; i < m_componentManagers.length; i++) {
- ComponentManager cm = m_componentManagers[i];
- cm.start();
- }
- }
+ /**
+ * Start all the component managers.
+ */
+ public void start() {
+ Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Start the component factory");
- /**
- * Load a class.
- * @param className : name of the class to load
- * @return the resulting Class object
- * @throws ClassNotFoundException : happen when the class is not found
- */
- public Class loadClass(String className) throws ClassNotFoundException {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] In load for : " + className);
- if (m_clazz != null && className.equals(m_componentClassName)) {
- if (m_classLoader == null) {
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Create the FactoryClassLoader for : " + className);
- m_classLoader = new FactoryClassloader();
- }
- try {
- Class c = m_classLoader.defineClass(m_componentClassName, m_clazz, null);
- Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Return " + c + " for " + className);
- return c;
- } catch (Exception e) {
- Activator.getLogger().log(Level.SEVERE, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Cannot define the class : " + className);
- return null;
- }
- }
- return m_bundleContext.getBundle().loadClass(className);
- }
+ // Check if the factory should be exposed
+ if (m_componentMetadata.containsAttribute("factory") && m_componentMetadata.getAttribute("factory").equalsIgnoreCase("no")) { return; }
+ Properties props = new Properties();
+ props.put("component.class", m_componentClassName);
- /**
- * Return the URL of a resource.
- * @param resName : resource name
- * @return the URL of the resource
- */
- public URL getResource(String resName) {
- return m_bundleContext.getBundle().getResource(resName);
- }
+ // create a ghost component
+ ComponentManagerImpl ghost = new ComponentManagerImpl(this);
+ ghost.configure(m_componentMetadata, new Properties());
+ m_componentInfo = ghost.getComponentInfo();
+
+ props.put("component.providedServiceSpecifications", m_componentInfo.getprovidedServiceSpecification());
+ props.put("component.properties", m_componentInfo.getProperties());
+ props.put("component.information", m_componentInfo.toString());
+
+ // Get factory PID :
+ if (m_componentMetadata.containsAttribute("name")) { props.put(Constants.SERVICE_PID, m_componentMetadata.getAttribute("name")); }
+ else { props.put(Constants.SERVICE_PID, m_componentMetadata.getAttribute("className")); }
+
+ // Exposition of the factory service
+ m_sr = m_bundleContext.registerService(new String[] {Factory.class.getName(), ManagedServiceFactory.class.getName()}, this, props);
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.Factory#getComponentInfo()
+ */
+ public ComponentInfo getComponentInfo() { return m_componentInfo; }
+
+ /**
+ * Load a class.
+ * @param className : name of the class to load
+ * @return the resulting Class object
+ * @throws ClassNotFoundException : happen when the class is not found
+ */
+ public Class loadClass(String className) throws ClassNotFoundException {
+ Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] In load for : " + className);
+ if (m_clazz != null && className.equals(m_componentClassName)) {
+ if (m_classLoader == null) {
+ Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Create the FactoryClassLoader for : " + className);
+ m_classLoader = new FactoryClassloader();
+ }
+ try {
+ Class c = m_classLoader.defineClass(m_componentClassName, m_clazz, null);
+ Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Return " + c + " for " + className);
+ return c;
+ } catch (Exception e) {
+ Activator.getLogger().log(Level.SEVERE, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Cannot define the class : " + className);
+ return null;
+ }
+ }
+ return m_bundleContext.getBundle().loadClass(className);
+ }
+
+ /**
+ * Return the URL of a resource.
+ * @param resName : resource name
+ * @return the URL of the resource
+ */
+ public URL getResource(String resName) {
+ return m_bundleContext.getBundle().getResource(resName);
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.Factory#createComponent(java.util.Dictionary)
+ */
+ public ComponentManager createComponent(Dictionary configuration) {
+ Activator.getLogger().log(Level.INFO, "[Bundle " + m_bundleContext.getBundle().getBundleId() + "] Create a component and start it");
+ ComponentManagerImpl component = new ComponentManagerImpl(this);
+ component.configure(m_componentMetadata, configuration);
+
+ String pid = null;
+ if (configuration.get("name") != null) { pid = (String) configuration.get("name"); }
+ else { pid = m_componentMetadata.getAttribute("className"); }
+
+ m_componentManagers.put(pid, component);
+ component.start();
+ return component;
+ }
+
+ /**
+ * @see org.osgi.service.cm.ManagedServiceFactory#deleted(java.lang.String)
+ */
+ public void deleted(String pid) {
+ ComponentManagerImpl cm = (ComponentManagerImpl) m_componentManagers.remove(pid);
+ if (cm == null) { return; } // do nothing, the component does not exist !
+ else { cm.stop(); }
+ }
+
+ /**
+ * @see org.osgi.service.cm.ManagedServiceFactory#getName()
+ */
+ public String getName() {
+ if (m_componentMetadata.containsAttribute("name")) { return m_componentMetadata.getAttribute("name"); }
+ else { return m_componentMetadata.getAttribute("className"); }
+ }
+
+ /**
+ * @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
+ */
+ public void updated(String pid, Dictionary properties) throws ConfigurationException {
+ ComponentManagerImpl cm = (ComponentManagerImpl) m_componentManagers.get(pid);
+ if (cm == null) { createComponent(properties); } // Create the component
+ else {
+ cm.stop(); // Stop the component
+ cm.configure(m_componentMetadata, properties); // re-configure the component
+ cm.start(); // restart it
+ }
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerImpl.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerImpl.java
new file mode 100644
index 0000000..af393e4
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentManagerImpl.java
@@ -0,0 +1,579 @@
+/*
+ * 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.felix.ipojo;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.logging.Level;
+
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The component manager implementation class manages one instance of a component type.
+ * It manages component lifecycle, component instance creation and handlers.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class ComponentManagerImpl implements ComponentManager {
+
+ /**
+ * Parent factory (ComponentManagerFactory).
+ */
+ private ComponentManagerFactory m_factory;
+
+ /**
+ * Attached metadata of the managed component.
+ */
+ private ComponentMetadata m_metadata;
+
+ /**
+ * The context of the component.
+ */
+ private BundleContext m_context;
+
+ /**
+ * Handler list.
+ */
+ private Handler[] m_handlers = new Handler[0];
+
+ /**
+ * Map [field, handler list] storing handlers interested by the field.
+ */
+ private HashMap m_fieldRegistration = new HashMap();
+
+ /**
+ * Component state (STOPPED at the beginning).
+ */
+ private int m_state = INVALID;
+
+ // Fields use for the manipulation, the loading of the class and for the instance creation
+
+ /**
+ * Manipulatd clazz.
+ */
+ private Class m_clazz;
+
+ /**
+ * Instances of the components.
+ */
+ private Object[] m_instances = new Object[0];
+
+ /**
+ * Component type information.
+ */
+ private ComponentInfo m_componentInfo;
+
+ // Constructor
+ /**
+ * Construct a new Component Manager.
+ * @param factory : the factory managing the component manager
+ */
+ public ComponentManagerImpl(ComponentManagerFactory factory) {
+ m_factory = factory;
+ m_context = factory.getBundleContext();
+ Activator.getLogger().log(Level.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] Create a component manager from the factory " + m_factory);
+ }
+
+ /**
+ * Configure the component manager.
+ * Stop the existings handler, clear the handler list, change the metadata, recreate the handlers
+ * @param cm
+ */
+ public void configure(Element cm, Dictionary configuration) {
+ Activator.getLogger().log(Level.INFO, "[Bundle " + m_context.getBundle().getBundleId() + "] Configure the component manager " + cm.getAttribute("className"));
+
+ // Stop all previous registred handler
+ if (m_handlers.length != 0) { stop(); }
+
+ // Clear the handler list
+ m_handlers = new Handler[0];
+
+ // Change the metadata
+ m_metadata = new ComponentMetadata(cm);
+
+ // COmponentInfo initialization
+ m_componentInfo = new ComponentInfo();
+ m_componentInfo.setClassName(m_metadata.getClassName());
+
+ // Create the standard handlers and add these handlers to the list
+ for (int i = 0; i < IPojoConfiguration.INTERNAL_HANDLERS.length; i++) {
+ // Create a new instance
+ try {
+ Handler h = (Handler) IPojoConfiguration.INTERNAL_HANDLERS[i].newInstance();
+ h.configure(this, cm, configuration);
+ } catch (InstantiationException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + IPojoConfiguration.INTERNAL_HANDLERS[i] + " : " + e.getMessage());
+ }
+ }
+
+ // Look for namespaces
+ for (int i = 0; i < cm.getNamespaces().length; i++) {
+ if (!cm.getNamespaces()[i].equals("")) {
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Look for class for the namespace : " + cm.getNamespaces()[i]);
+ // It is not an internal handler, try to load it
+ try {
+ Class c = m_context.getBundle().loadClass(cm.getNamespaces()[i]);
+ Handler h = (Handler) c.newInstance();
+ h.configure(this, cm, configuration);
+ } catch (ClassNotFoundException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ } catch (InstantiationException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Cannot instantiate the handler " + cm.getNamespaces()[i] + " : " + e.getMessage());
+ }
+
+ }
+ }
+
+ }
+
+ /**
+ * @return the component type information.
+ */
+ public ComponentInfo getComponentInfo() { return m_componentInfo; }
+
+ /**
+ * @return the component metadata.
+ */
+ public ComponentMetadata getComponentMetatada() { return m_metadata; }
+
+ /**
+ * @return the list of the registred handlers.
+ */
+ public Handler[] getRegistredHandlers() { return m_handlers; }
+
+ /**
+ * Return a specified handler.
+ * @param name : class name of the handler to find
+ * @return : the handler, or null if not found
+ */
+ public Handler getHandler(String name) {
+ for (int i = 0; i < m_handlers.length; i++) {
+ if (m_handlers[i].getClass().getName().equalsIgnoreCase(name)) { return m_handlers[i]; }
+ }
+ return null;
+ }
+
+ // ===================== Lifecycle management =====================
+
+ /**
+ * Start the component manager.
+ */
+ public void start() {
+ // Start all the handlers
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Start the component manager with " + m_handlers.length + " handlers");
+
+ // The new state of the component is UNRESOLVED
+ m_state = INVALID;
+
+ for (int i = 0; i < m_handlers.length; i++) {
+ m_handlers[i].start();
+ }
+
+ // Defines the state of the component :
+ checkComponentState();
+ }
+
+ /**
+ * Stop the component manager.
+ */
+ public void stop() {
+ setState(INVALID);
+ // Stop all the handlers
+ for (int i = m_handlers.length - 1; i > -1; i--) {
+ m_handlers[i].stop();
+ }
+ m_instances = new Object[0];
+ }
+
+ /**
+ * Set the state of the component.
+ * if the state changed call the stateChanged(int) method on the handlers
+ */
+ public void setState(int state) {
+ if (m_state != state) {
+
+ // Log the state change
+ if (state == INVALID) { Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component " + m_metadata.getClassName() + " State -> UNRESOLVED"); }
+ if (state == VALID) { Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component " + m_metadata.getClassName() + " State -> VALID"); }
+
+ // The state changed call the handler stateChange method
+ m_state = state;
+ for (int i = m_handlers.length - 1; i > -1; i--) {
+ m_handlers[i].stateChanged(state);
+ }
+ }
+ }
+
+ /**
+ * @return the actual state of the component.
+ */
+ public int getState() {
+ return m_state;
+ }
+
+ // ===================== end Lifecycle management =====================
+
+ // ================== Class & Instance management ===================
+
+ /**
+ * @return the factory of the component
+ */
+ public ComponentManagerFactory getFactory() { return m_factory; }
+
+ /**
+ * Load the manipulated class.
+ */
+ private void load() {
+ try {
+ m_clazz = m_factory.loadClass(m_metadata.getClassName());
+ } catch (ClassNotFoundException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] Class not found during the loading phase : " + e.getMessage());
+ return;
+ }
+ }
+
+ /**
+ * @return true if the class is loaded
+ */
+ private boolean isLoaded() {
+ return (m_clazz != null);
+ }
+
+ /**
+ * Add an instance to the created instance list.
+ * @param o : the instance to add
+ */
+ private void addInstance(Object o) {
+ for (int i = 0; (m_instances != null) && (i < m_instances.length); i++) {
+ if (m_instances[i] == o) { return; }
+ }
+
+ if (m_instances.length > 0) {
+ Object[] newInstances = new Object[m_instances.length + 1];
+ System.arraycopy(m_instances, 0, newInstances, 0, m_instances.length);
+ newInstances[m_instances.length] = o;
+ m_instances = newInstances;
+ }
+ else {
+ m_instances = new Object[] {o};
+ }
+ }
+
+ /**
+ * Remove an instance from the created instance list. The instance will be eated by the garbage collector.
+ * @param o : the instance to remove
+ */
+ private void removeInstance(Object o) {
+ int idx = -1;
+ for (int i = 0; i < m_instances.length; i++) {
+ if (m_instances[i] == o) { idx = i; break; }
+ }
+
+ if (idx >= 0) {
+ if ((m_instances.length - 1) == 0) { m_instances = new Element[0]; }
+ else {
+ Object[] newInstances = new Object[m_instances.length - 1];
+ System.arraycopy(m_instances, 0, newInstances, 0, idx);
+ if (idx < newInstances.length) {
+ System.arraycopy(m_instances, idx + 1, newInstances, idx, newInstances.length - idx); }
+ m_instances = newInstances;
+ }
+ }
+ }
+
+ /**
+ * @return the created instance of the component.
+ */
+ public Object[] getInstances() { return m_instances; }
+
+ /**
+ * Delete the created instance (remove it from the list, to allow the garbage collector to eat the instance).
+ * @param o : the instance to delete
+ */
+ public void deleteInstance(Object o) { removeInstance(o); }
+
+ /**
+ * Create an instance of the component.
+ * This method need to be called one time only for singleton provided service
+ * @return a new instance
+ */
+ public Object createInstance() {
+
+ if (!isLoaded()) { load(); }
+ Object instance = null;
+ try {
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Try to find the constructor");
+
+ // Try to find if there is a constructor with a bundle context as parameter :
+ try {
+ Constructor constructor = m_clazz.getConstructor(new Class[] {ComponentManagerImpl.class, BundleContext.class});
+ constructor.setAccessible(true);
+ instance = constructor.newInstance(new Object[] {this, m_factory.getBundleContext()});
+ }
+ catch (NoSuchMethodException e) {
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> No constructor with a bundle context");
+ }
+
+ // Create an instance if no instance are already created with <init>()BundleContext
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Try to create the object with an empty constructor");
+ if (instance == null) {
+ Constructor constructor = m_clazz.getConstructor(new Class[] {ComponentManagerImpl.class});
+ constructor.setAccessible(true);
+ instance = constructor.newInstance(new Object[] {this});
+ }
+
+ } catch (InstantiationException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance cannot be instancied : " + e.getMessage());
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance is not accessible : " + e.getMessage());
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> The Component Instance is not accessible (security reason) : " + e.getMessage());
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> Cannot invoke the constructor method (illegal target) : " + e.getMessage());
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_metadata.getClassName() + "] createInstance -> Cannot invoke the constructor (method not found) : " + e.getMessage());
+ e.printStackTrace();
+ }
+
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] createInstance -> Return the instance " + instance);
+
+ // Register the new instance
+ addInstance(instance);
+ // Call createInstance on Handlers :
+ for (int i = 0; i < m_handlers.length; i++) { m_handlers[i].createInstance(instance); }
+ return instance;
+ }
+
+ /**
+ * @return the instance of the component to use for singleton component
+ */
+ public Object getInstance() {
+ if (m_instances.length == 0) { createInstance(); }
+ return m_instances[0];
+ }
+
+ /**
+ * @return the manipulated class
+ */
+ public Class getClazz() {
+ if (!isLoaded()) { load(); }
+ return m_clazz;
+ }
+
+ // ================== end Class & Instance management ================
+
+ // ======================== Handlers Management ======================
+
+ /**
+ * Register the given handler to the current component manager.
+ * @param h : the handler to register
+ */
+ public void register(Handler h) {
+ for (int i = 0; (m_handlers != null) && (i < m_handlers.length); i++) {
+ if (m_handlers[i] == h) {
+ return;
+ }
+ }
+
+ if (m_handlers != null) {
+ Handler[] newList = new Handler[m_handlers.length + 1];
+ System.arraycopy(m_handlers, 0, newList, 0, m_handlers.length);
+ newList[m_handlers.length] = h;
+ m_handlers = newList;
+ }
+ }
+
+ /**
+ * Register an handler.
+ * The handler will be notified of event on each field given in the list.
+ * @param h : the handler to register
+ * @param fields : the fields list
+ */
+ public void register(Handler h, String[] fields) {
+ register(h);
+ for (int i = 0; i < fields.length; i++) {
+ if (m_fieldRegistration.get(fields[i]) == null) {
+ m_fieldRegistration.put(fields[i], new Handler[] {h});
+ }
+ else {
+ Handler[] list = (Handler[]) m_fieldRegistration.get(fields[i]);
+ for (int j = 0; j < list.length; i++) { if (list[i] == h) { return; } }
+ Handler[] newList = new Handler[list.length + 1];
+ System.arraycopy(list, 0, newList, 0, list.length);
+ newList[list.length] = h;
+ m_fieldRegistration.put(fields[i], newList);
+ }
+ }
+ }
+
+ /**
+ * Unregister an handler for the field list.
+ * The handler will not be notified of field access but is allways register on the component manager.
+ * @param h : the handler to unregister.
+ * @param fields : the fields list
+ */
+ public void unregister(Handler h, String[] fields) {
+ for (int i = 0; i < fields.length; i++) {
+ if (m_fieldRegistration.get(fields[i]) == null) { break; }
+ else {
+ Handler[] list = (Handler[]) m_fieldRegistration.get(fields[i]);
+ int idx = -1;
+ for (int j = 0; j < list.length; j++) {
+ if (list[j] == h) {
+ idx = j;
+ break;
+ }
+ }
+
+ if (idx >= 0) {
+ if ((list.length - 1) == 0) {
+ list = new Handler[0];
+ }
+ else {
+ Handler[] newList = new Handler[list.length - 1];
+ System.arraycopy(list, 0, newList, 0, idx);
+ if (idx < newList.length) {
+ System.arraycopy(
+ list, idx + 1, newList, idx, newList.length - idx);
+ }
+ list = newList;
+ }
+ m_fieldRegistration.put(fields[i], list);
+ }
+ }
+ }
+ }
+
+ /**
+ * Unregister the given handler.
+ * @param h : the handler to unregiter
+ */
+ public void unregister(Handler h) {
+ int idx = -1;
+ for (int i = 0; i < m_handlers.length; i++) {
+ if (m_handlers[i] == h) {
+ idx = i;
+ break;
+ }
+ }
+
+ if (idx >= 0) {
+ if ((m_handlers.length - 1) == 0) {
+ m_handlers = new Handler[0];
+ }
+ else {
+ Handler[] newList = new Handler[m_handlers.length - 1];
+ System.arraycopy(m_handlers, 0, newList, 0, idx);
+ if (idx < newList.length) {
+ System.arraycopy(
+ m_handlers, idx + 1, newList, idx, newList.length - idx);
+ }
+ m_handlers = newList;
+ }
+ }
+ }
+
+ /**
+ * This method is called by the manipulated class each time that a GETFIELD instruction is found.
+ * The method ask to each handler which value need to be returned.
+ * @param fieldName : the field name on which the GETFIELD instruction is called
+ * @param initialValue : the value of the field in the code
+ * @return the value decided by the last asked handler (throw a warining if two fields decide two different values)
+ */
+ public Object getterCallback(String fieldName, Object initialValue) {
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Call the getterCallbackMethod on " + fieldName + " with " + initialValue);
+ Object result = null;
+ // Get the list of registered handlers
+ Handler[] list = (Handler[]) m_fieldRegistration.get(fieldName);
+ for (int i = 0; list != null && i < list.length; i++) {
+ Object handlerResult = list[i].getterCallback(fieldName, initialValue);
+ if (handlerResult != initialValue) { result = handlerResult; }
+ }
+
+ if (result != null) {
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] getterCallbackMethod return for " + fieldName + " -> " + result);
+ return result;
+ } else {
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] getterCallbackMethod return for " + fieldName + " -> " + initialValue);
+ return initialValue;
+ }
+ }
+
+ /**
+ * This method is called by the manipulated class each time that a PUTFILED instruction is found.
+ * the method send to each handler the new value.
+ * @param fieldName : the field name on which the PUTFIELD instruction is called
+ * @param objectValue : the value of the field
+ */
+ public void setterCallback(String fieldName, Object objectValue) {
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Call the setterCallbackMethod on " + fieldName + " with " + objectValue);
+ // Get the list of registered handlers
+ Handler[] list = (Handler[]) m_fieldRegistration.get(fieldName);
+
+ for (int i = 0; list != null && i < list.length; i++) {
+ m_handlers[i].setterCallback(fieldName, objectValue);
+ }
+ }
+
+ /**
+ * @return the context of the component.
+ */
+ public BundleContext getContext() { return m_context; }
+
+ /**
+ * Check the state of all handlers.
+ */
+ public void checkComponentState() {
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Check the component state");
+ boolean isValid = true;
+ for (int i = 0; i < m_handlers.length; i++) {
+ boolean b = m_handlers[i].isValid();
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Validity of the handler : " + m_handlers[i] + " = " + b);
+ isValid = isValid && b;
+ }
+
+ // Update the component state if necessary
+ if (!isValid && m_state == VALID) {
+ // Need to update the state to UNRESOLVED
+ setState(INVALID);
+ m_instances = new Object[0];
+ return;
+ }
+ if (isValid && m_state == INVALID) {
+ setState(VALID);
+ if (m_metadata.isImmediate() && m_instances.length == 0) { createInstance(); }
+ }
+
+ Activator.getLogger().log(Level.INFO, "[" + m_metadata.getClassName() + "] Component Manager : " + m_state);
+ }
+
+
+ // ======================= end Handlers Management =====================
+
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java
index 059531e..dc0c43f 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/ComponentMetadata.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo;
@@ -26,48 +28,48 @@
*/
public class ComponentMetadata {
- /**
- * Class name of the component.
- */
- private String m_className;
-
- /**
- * Is the component an immediate component ?
- */
- private boolean m_isImmediate = false;
+ /**
+ * Class name of the component.
+ */
+ private String m_className;
/**
- * Metadata of the component.
- */
- private Element m_metadata;
+ * Is the component an immediate component ?
+ */
+ private boolean m_isImmediate = false;
- /**
+ /**
+ * Metadata of the component.
+ */
+ private Element m_metadata;
+
+ /**
* Constructor.
- * @param metadata : metadata of the component
- */
- public ComponentMetadata(Element metadata) {
- m_metadata = metadata;
- m_className = metadata.getAttribute("className");
- if (m_className == null) {
- Activator.getLogger().log(Level.SEVERE, "The class name of ths component cannot be setted, it does not exist in the metadata");
- }
- if (metadata.containsAttribute("immediate") && metadata.getAttribute("immediate").equals("true")) { m_isImmediate = true; }
- }
+ * @param metadata : metadata of the component
+ */
+ public ComponentMetadata(Element metadata) {
+ m_metadata = metadata;
+ m_className = metadata.getAttribute("className");
+ if (m_className == null) {
+ Activator.getLogger().log(Level.SEVERE, "The class name of ths component cannot be setted, it does not exist in the metadata");
+ }
+ if (metadata.containsAttribute("immediate") && metadata.getAttribute("immediate").equals("true")) { m_isImmediate = true; }
+ }
- // Getter
- /**
- * @return the class name
- */
- public String getClassName() { return m_className; }
+ // Getter
+ /**
+ * @return the class name
+ */
+ public String getClassName() { return m_className; }
- /**
- * @return the component metadata
- */
- public Element getMetadata() { return m_metadata; }
+ /**
+ * @return the component metadata
+ */
+ public Element getMetadata() { return m_metadata; }
- /**
- * @return true if its an immediate component
- */
- public boolean isImmediate() { return m_isImmediate; }
+ /**
+ * @return true if its an immediate component.
+ */
+ public boolean isImmediate() { return m_isImmediate; }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/DummyActivator.java b/ipojo/src/main/java/org/apache/felix/ipojo/DummyActivator.java
deleted file mode 100644
index e69de29..0000000
--- a/ipojo/src/main/java/org/apache/felix/ipojo/DummyActivator.java
+++ /dev/null
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java b/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java
new file mode 100644
index 0000000..2a99e29
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Factory.java
@@ -0,0 +1,43 @@
+/*
+ * 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.felix.ipojo;
+
+import java.util.Dictionary;
+
+/**
+ * Component Type Factory Service.
+ * This service is exposed by a component manager factory, and allows the dynamic creation of component instance.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public interface Factory {
+
+ /**
+ * Create a component manager (i.e. component type instance).
+ * @param configuration : the configuration property for this component.
+ * @return the created component manager.
+ */
+ ComponentManager createComponent(Dictionary configuration);
+
+ /**
+ * Get the component type information containing provided service, configuration properties ...
+ * @return the compionent type information.
+ */
+ ComponentInfo getComponentInfo();
+
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java b/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
index b241f03..d52b488 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Handler.java
@@ -1,72 +1,81 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo;
+import java.util.Dictionary;
+
import org.apache.felix.ipojo.metadata.Element;
/**
- * Handler Interface.
+ * Handler Abstract Class.
* An handler need implements tese method to be notifed of lifecycle change, getfield operation and putfield operation
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public interface Handler {
+public abstract class Handler {
- /**
- * Configure the handler.
- * @param cm : the component manager
- * @param metadata : the metadata of the component
- */
- void configure(ComponentManager cm, Element metadata);
+ /**
+ * Configure the handler.
+ * @param cm : the component manager
+ * @param metadata : the metadata of the component
+ */
+ public abstract void configure(ComponentManagerImpl cm, Element metadata, Dictionary configuration);
- /**
- * Stop the handler : stop the management.
- */
- void stop();
+ /**
+ * Stop the handler : stop the management.
+ */
+ public abstract void stop();
- /**
- * Start the handler : start the management.
- */
- void start();
+ /**
+ * Start the handler : start the management.
+ */
+ public abstract void start();
- /**
- * This method is called when a PUTFIELD operation is detected.
- * @param fieldName : the field name
- * @param value : the value passed to the field
- */
- void setterCallback(String fieldName, Object value);
+ /**
+ * This method is called when a PUTFIELD operation is detected.
+ * @param fieldName : the field name
+ * @param value : the value passed to the field
+ */
+ public void setterCallback(String fieldName, Object value) { }
- /**
- * This method is called when a GETFIELD operation is detected.
- * @param fieldName : the field name
- * @param value : the value passed to the field (by the previous handler)
- * @return : the managed value of the field
- */
- Object getterCallback(String fieldName, Object value);
+ /**
+ * This method is called when a GETFIELD operation is detected.
+ * @param fieldName : the field name
+ * @param value : the value passed to the field (by the previous handler)
+ * @return : the managed value of the field
+ */
+ public Object getterCallback(String fieldName, Object value) { return value; }
- /**
- * Is the actual state valid for this handler ?
- * @return true is the state seems valid for the handler
- */
- boolean isValid();
+ /**
+ * Is the actual state valid for this handler ?
+ * @return true is the state seems valid for the handler
+ */
+ public boolean isValid() { return true; }
- /**
- * This method is called when the component state changed.
- * @param state : the new state
- */
- void stateChanged(int state);
+ /**
+ * This method is called when the component state changed.
+ * @param state : the new state
+ */
+ public void stateChanged(int state) { }
+ /**
+ * This method is called when an instance of the component is created, but before someone can use it.
+ * @param instance : the created instance
+ */
+ public void createInstance(Object instance) { }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java b/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
index fbf350d..9aca014 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/IPojoConfiguration.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo;
@@ -32,20 +34,20 @@
*/
public class IPojoConfiguration {
- /**
- * iPOJO logger log level.
- */
- public static final Level LOG_LEVEL = Level.WARNING;
+ /**
+ * iPOJO logger log level.
+ */
+ public static final Level LOG_LEVEL = Level.WARNING;
- /**
- * Available handlers in the iPOJO bundle.
- */
- public static final Class[] INTERNAL_HANDLERS = new Class[] {
- DependencyHandler.class,
- ProvidedServiceHandler.class,
- ConfigurationHandler.class,
- LifecycleCallbackHandler.class,
- ArchitectureHandler.class
- };
+ /**
+ * Available handlers in the iPOJO bundle.
+ */
+ public static final Class[] INTERNAL_HANDLERS = new Class[] {
+ DependencyHandler.class,
+ ProvidedServiceHandler.class,
+ ConfigurationHandler.class,
+ LifecycleCallbackHandler.class,
+ ArchitectureHandler.class
+ };
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java b/ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java
index bdb74dc..1026d3f 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/Nullable.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo;
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/PropertyInfo.java b/ipojo/src/main/java/org/apache/felix/ipojo/PropertyInfo.java
new file mode 100644
index 0000000..ab16b0f
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/PropertyInfo.java
@@ -0,0 +1,77 @@
+/*
+ * 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.felix.ipojo;
+
+/**
+ * Property Information.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class PropertyInfo {
+
+ /**
+ * Name of the property.
+ */
+ private String m_name;
+
+ /**
+ * Type of the property.
+ */
+ private String m_type;
+
+ /**
+ * Default value of the property.
+ */
+ private String m_value = null;
+
+ /**
+ * Constructor.
+ * @param name : name of the property
+ * @param type : type of the property
+ * @param value : default value of the property
+ */
+ public PropertyInfo(String name, String type, String value) {
+ m_name = name;
+ m_type = type;
+ m_value = value;
+ }
+
+ /**
+ * @return the property name.
+ */
+ public String getName() { return m_name; }
+
+ /**
+ * @return the property type.
+ */
+ public String getType() { return m_type; }
+
+ /**
+ * @return the default value for the property.
+ */
+ public String getValue() { return m_value; }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ if (m_value != null) { return getName() + " - " + getType() + " - " + getValue(); }
+ else { return getName() + " - " + getType() + " - CONFIGURABLE"; }
+ }
+
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java
index 478572e..6ef826d 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/Architecture.java
@@ -1,24 +1,26 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.architecture;
/**
* Architecture service.
- * Allows to have information of the service delivery about GenSD component.
+ * Allows to have information on the component.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
public interface Architecture {
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
index 9fb29b4..55f0c62 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
@@ -1,24 +1,23 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.architecture;
-import java.util.HashMap;
-
-
/**
* Component Description.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
@@ -32,19 +31,14 @@
private String m_className;
/**
- * List of provided service.
+ * The name of the component (instance).
*/
- private ProvidedServiceDescription[] m_provideServices = new ProvidedServiceDescription[0];
+ private String m_name;
/**
- * List of dependencies.
+ * Handlers of the component instance.
*/
- private DependencyDescription[] m_dependencies = new DependencyDescription[0];
-
- /**
- * Hashmap [Instance reference, service reference] of the used service.
- */
- private HashMap m_usedServices = new HashMap();
+ private HandlerDescription[] m_handlers = new HandlerDescription[0];
/**
* Created Instances of the components.
@@ -57,18 +51,30 @@
private int m_state;
/**
+ * BundleId of the component.
+ */
+ private long m_bundleId;
+
+ /**
* Constructor.
* @param name : the name of the component (the class name).
* @param state : the state of the component.
*/
- public ComponentDescription(String name, int state) {
- m_className = name;
+ public ComponentDescription(String name, String className, int state, long bundleId) {
+ m_name = name;
+ m_className = className;
m_state = state;
- m_usedServices.clear();
m_instances = new String[0];
+ m_handlers = new HandlerDescription[0];
+ m_bundleId = bundleId;
}
/**
+ * @return the name of the component.
+ */
+ public String getName() { return m_name; }
+
+ /**
* @return the created instances
*/
public String[] getInstances() { return m_instances; }
@@ -84,67 +90,43 @@
public String getClassName() { return m_className; }
/**
- * @return the live dependency list
+ * @return the live handler list
*/
- public DependencyDescription[] getDependencies() { return m_dependencies; }
+ public HandlerDescription[] getHandlers() { return m_handlers; }
/**
- * @return the live provided service list
+ * Add an handler description to the list.
+ * @param hd : the handler description to add
*/
- public ProvidedServiceDescription[] getProvideServices() { return m_provideServices; }
-
- /**
- * Add a dependency.
- * @param dep : the dependency to add
- */
- public void addDependency(DependencyDescription dep) {
+ public void addHandler(HandlerDescription hd) {
// Verify that the dependency description is not already in the array.
- for (int i = 0; (i < m_dependencies.length); i++) {
- if (m_dependencies[i] == dep) {
+ for (int i = 0; (i < m_handlers.length); i++) {
+ if (m_handlers[i] == hd) {
return; //NOTHING TO DO, the description is already in the array
}
}
// The component Description is not in the array, add it
- DependencyDescription[] newDep = new DependencyDescription[m_dependencies.length + 1];
- System.arraycopy(m_dependencies, 0, newDep, 0, m_dependencies.length);
- newDep[m_dependencies.length] = dep;
- m_dependencies = newDep;
- }
-
- /**
- * Add a provided service.
- * @param pds : the provided service to add
- */
- public void addProvidedService(ProvidedServiceDescription pds) {
- //Verify that the provided service description is not already in the array.
- for (int i = 0; (i < m_provideServices.length); i++) {
- if (m_provideServices[i] == pds) {
- return; //NOTHING DO DO, the description is already in the array
- }
- }
-
- // The component Description is not in the array, add it
- ProvidedServiceDescription[] newPSD = new ProvidedServiceDescription[m_provideServices.length + 1];
- System.arraycopy(m_provideServices, 0, newPSD, 0, m_provideServices.length);
- newPSD[m_provideServices.length] = pds;
- m_provideServices = newPSD;
-
+ HandlerDescription[] newHd = new HandlerDescription[m_handlers.length + 1];
+ System.arraycopy(m_handlers, 0, newHd, 0, m_handlers.length);
+ newHd[m_handlers.length] = hd;
+ m_handlers = newHd;
}
/**
* Set the state of the component.
* @param i : the state
*/
- public void setState(int i) {
- m_state = i;
- }
+ public void setState(int i) { m_state = i; }
/**
* @return the state of the component.
*/
- public int getState() {
- return m_state;
- }
+ public int getState() { return m_state; }
+
+ /**
+ * @return the bundle id owning the component implementation class.
+ */
+ public long getBundleId() { return m_bundleId; }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java
index 74a9f6a..e7652e9 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyDescription.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.architecture;
@@ -50,57 +52,41 @@
* Filter.
*/
private String m_filter;
+
/**
* Hashmap [Instance reference, service reference] of the used service.
*/
private HashMap m_usedServices = new HashMap();
-
/**
* The list of service reference.
*/
private ServiceReference[] m_serviceReferences;
/**
- * Parent of the dependency either de ProvidedServiceDescription or a ComponentDescription.
- */
- private Object m_parent;
-
-
- /**
* @return true if the dependency is a multiple dependency.
*/
- public boolean isMultiple() {
- return m_multiple;
- }
+ public boolean isMultiple() { return m_multiple; }
/**
* @return true if the dependency is an optional dependency.
*/
- public boolean isOptional() {
- return m_optional;
- }
+ public boolean isOptional() { return m_optional; }
/**
* @return the filter.
*/
- public String getFilter() {
- return m_filter;
- }
+ public String getFilter() { return m_filter; }
/**
* @return the needed interface.
*/
- public String getInterface() {
- return m_interface;
- }
+ public String getInterface() { return m_interface; }
/**
* @return the state of the dependency.
*/
- public int getState() {
- return m_state;
- }
+ public int getState() { return m_state; }
/**
* Constructor.
@@ -119,37 +105,23 @@
m_filter = filter;
m_state = state;
m_serviceReferences = new ServiceReference[0];
- m_parent = parent;
}
/**
* @return the array of service reference (only if the cardinality could be n).
*/
- public ServiceReference[] getServiceReferences() {
- return m_serviceReferences;
- }
+ public ServiceReference[] getServiceReferences() { return m_serviceReferences; }
/**
* @return the ServiceReference (only if the cardinality could be 1).
*/
- public ServiceReference getServiceReference() {
- return m_serviceReferences[0];
- }
+ public ServiceReference getServiceReference() { return m_serviceReferences[0]; }
/**
* Set the service reference array.
* @param sr : the array of service reference
*/
- public void setServiceReferences(ServiceReference[] sr) {
- m_serviceReferences = sr;
- }
-
- /**
- * @return the parent of the dependency
- */
- public Object getParent() {
- return m_parent;
- }
+ public void setServiceReferences(ServiceReference[] sr) { m_serviceReferences = sr; }
/**
* @return the hashmap [object reference, service reference] containing the used services
@@ -161,7 +133,7 @@
* @param hm : the new usedService
*/
public void setUsedServices(HashMap hm) {
- m_usedServices = hm;
+ m_usedServices = hm;
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyHandlerDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyHandlerDescription.java
new file mode 100644
index 0000000..ee145f6
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/DependencyHandlerDescription.java
@@ -0,0 +1,84 @@
+/*
+ * 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.felix.ipojo.architecture;
+
+import java.util.Iterator;
+import org.apache.felix.ipojo.handlers.dependency.DependencyHandler;
+
+/**
+ * Dependency Handler Description.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class DependencyHandlerDescription extends HandlerDescription {
+
+
+ /**
+ * Dependencies managed by the dependency handler.
+ */
+ private DependencyDescription[] m_dependencies = new DependencyDescription[0];
+
+ /**
+ * Constructor.
+ * @param isValid : the validity of the dependency handler.
+ */
+ public DependencyHandlerDescription(boolean isValid) {
+ super(DependencyHandler.class.getName(), isValid);
+ }
+
+ /**
+ * @return the dependencies list.
+ */
+ public DependencyDescription[] getDependencies() { return m_dependencies; }
+
+ /**
+ * Add a dependency.
+ * @param dep : the dependency to add
+ */
+ public void addDependency(DependencyDescription dep) {
+ // Verify that the dependency description is not already in the array.
+ for (int i = 0; (i < m_dependencies.length); i++) {
+ if (m_dependencies[i] == dep) {
+ return; //NOTHING TO DO, the description is already in the array
+ }
+ }
+ // The component Description is not in the array, add it
+ DependencyDescription[] newDep = new DependencyDescription[m_dependencies.length + 1];
+ System.arraycopy(m_dependencies, 0, newDep, 0, m_dependencies.length);
+ newDep[m_dependencies.length] = dep;
+ m_dependencies = newDep;
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
+ */
+ public String getHandlerInfo() {
+ String info = "";
+ for (int i = 0; i < m_dependencies.length; i++) {
+ String state = "resolved";
+ if (m_dependencies[i].getState() == 2) { state = "unresolved"; }
+ info += "\t Dependency on " + m_dependencies[i].getInterface() + "[" + m_dependencies[i].getFilter() + "] is " + state;
+ Iterator it = m_dependencies[i].getUsedServices().keySet().iterator();
+ while (it.hasNext()) {
+ info += "\n \t\t Uses : " + it.next();
+ }
+ }
+ return info;
+ }
+
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java
new file mode 100644
index 0000000..6997099
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/HandlerDescription.java
@@ -0,0 +1,65 @@
+/*
+ * 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.felix.ipojo.architecture;
+
+
+/**
+ * Handler Description.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class HandlerDescription {
+
+
+ /**
+ * Handler Class Name (i.e namespace).
+ */
+ private String m_handlerName;
+
+ /**
+ * Is the handler valid.
+ */
+ private boolean m_isValid;
+
+
+ /**
+ * Constructor.
+ * @param name : handler name
+ * @param isValid : is the handler valid
+ */
+ public HandlerDescription(String name, boolean isValid) {
+ m_handlerName = name;
+ m_isValid = isValid;
+ }
+
+ /**
+ * @return true if the handler is valid.
+ */
+ public boolean isValid() { return m_isValid; }
+
+ /**
+ * @return the handler name (i.e. namespace).
+ */
+ public String getHandlerName() { return m_handlerName; }
+
+ /**
+ * @return the handler information.
+ */
+ public String getHandlerInfo() { return ""; };
+
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java
index b663a1c..579147f 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceDescription.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.architecture;
@@ -36,7 +38,6 @@
*/
private DependencyDescription[] m_dependencies = new DependencyDescription[0];
-
/**
* State.
*/
@@ -47,7 +48,6 @@
*/
private ServiceReference m_serviceReference;
-
/**
* Handler on the component description who contains this description.
*/
@@ -91,11 +91,11 @@
return; //NOTHING DO DO, the description is already in the array
}
}
- // The component Description is not in the array, add it
- DependencyDescription[] newDep = new DependencyDescription[m_dependencies.length + 1];
- System.arraycopy(m_dependencies, 0, newDep, 0, m_dependencies.length);
- newDep[m_dependencies.length] = dep;
- m_dependencies = newDep;
+ // The component Description is not in the array, add it
+ DependencyDescription[] newDep = new DependencyDescription[m_dependencies.length + 1];
+ System.arraycopy(m_dependencies, 0, newDep, 0, m_dependencies.length);
+ newDep[m_dependencies.length] = dep;
+ m_dependencies = newDep;
}
/**
@@ -112,7 +112,7 @@
* @param props : the properties
*/
public void setProperty(Properties props) {
- m_properties = (Properties)props.clone();
+ m_properties = (Properties) props.clone();
}
/**
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceHandlerDescription.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceHandlerDescription.java
new file mode 100644
index 0000000..a838d86
--- /dev/null
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/ProvidedServiceHandlerDescription.java
@@ -0,0 +1,93 @@
+/*
+ * 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.felix.ipojo.architecture;
+
+import java.util.Iterator;
+
+import org.apache.felix.ipojo.handlers.providedservice.ProvidedService;
+import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler;
+
+/**
+ * Provided Service Handler Description.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class ProvidedServiceHandlerDescription extends HandlerDescription {
+
+ /**
+ * Provided Service Description list.
+ */
+ private ProvidedServiceDescription[] m_providedServices = new ProvidedServiceDescription[0];
+
+
+ /**
+ * Constructor.
+ * @param isValid : the validity of the provided service handler.
+ */
+ public ProvidedServiceHandlerDescription(boolean isValid) {
+ super(ProvidedServiceHandler.class.getName(), isValid);
+ }
+
+ /**
+ * @return the provided service description list.
+ */
+ public ProvidedServiceDescription[] getProvidedServices() { return m_providedServices; }
+
+ /**
+ * Add a provided service.
+ * @param pds : the provided service to add
+ */
+ public void addProvidedService(ProvidedServiceDescription pds) {
+ //Verify that the provided service description is not already in the array.
+ for (int i = 0; (i < m_providedServices.length); i++) {
+ if (m_providedServices[i] == pds) {
+ return; //NOTHING DO DO, the description is already in the array
+ }
+ }
+ // The component Description is not in the array, add it
+ ProvidedServiceDescription[] newPSD = new ProvidedServiceDescription[m_providedServices.length + 1];
+ System.arraycopy(m_providedServices, 0, newPSD, 0, m_providedServices.length);
+ newPSD[m_providedServices.length] = pds;
+ m_providedServices = newPSD;
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
+ */
+ public String getHandlerInfo() {
+ String info = "";
+ for (int i = 0; i < m_providedServices.length; i++) {
+ String state = "unregistered";
+ if (m_providedServices[i].getState() == ProvidedService.REGISTERED) { state = "registered"; }
+ String spec = "";
+ for (int j = 0; j < m_providedServices[i].getServiceSpecification().length; j++) {
+ spec += m_providedServices[i].getServiceSpecification()[j] + " ";
+ }
+ info += "\t Provided Service [" + spec + "] is " + state;
+ Iterator it = m_providedServices[i].getProperties().keySet().iterator();
+ while (it.hasNext()) {
+ String k = (String) it.next();
+ info += "\n\t\t Service Property : " + k + " = " + m_providedServices[i].getProperties().getProperty(k);
+ }
+ }
+ return info;
+ }
+
+
+
+}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/State.java b/ipojo/src/main/java/org/apache/felix/ipojo/architecture/State.java
deleted file mode 100644
index 9b5844c..0000000
--- a/ipojo/src/main/java/org/apache/felix/ipojo/architecture/State.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2006 The Apache Software Foundation
- *
- * Licensed 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.felix.ipojo.architecture;
-
-/**
- * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
- */
-public class State {
-
- /**
- * Return the String corresponding to a component state.
- * @param state : the state in int
- * @return : the string of the state (Stopped, Unresolved, Resolved) or "Unknow" if state is not revelant
- */
- public static String printComponentState(int state) {
- switch(state) {
- case(0) :
- return "STOPPED";
- case(1) :
- return "INVALID";
- case(2) :
- return "VALID";
- default :
- return "UNKNOW";
- }
- }
-
- /**
- * Return the String corresponding to a dependency state.
- * @param state : the state in int
- * @return : the string of the state (Stopped, Valid, Invalid) or "Unknow" if state is not revelant
- */
- public static String printDependencyState(int state) {
- switch(state) {
- case(0) :
- return "STOPPED";
- case(1) :
- return "RESOLVED";
- case(2) :
- return "UNRESOLVED";
- default :
- return "UNKNOW";
- }
- }
-
- /**
- * Return the String corresponding to a provided service state.
- * @param state : the state in int
- * @return : the string of the state (Unregistred, Registredu) or "Unknow" if state is not revelant
- */
- public static String printProvidedServiceState(int state) {
- switch(state) {
- case(0) :
- return "UNREGISTRED";
- case(1) :
- return "REGISTRED";
- default :
- return "UNKNOW";
- }
- }
-
-}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
index 281ee73..971a498 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
@@ -1,30 +1,35 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.architecture;
import java.util.Dictionary;
import java.util.Properties;
-import org.apache.felix.ipojo.ComponentManager;
+import org.apache.felix.ipojo.ComponentManagerImpl;
import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.architecture.ComponentDescription;
import org.apache.felix.ipojo.architecture.DependencyDescription;
+import org.apache.felix.ipojo.architecture.DependencyHandlerDescription;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
import org.apache.felix.ipojo.architecture.ProvidedServiceDescription;
+import org.apache.felix.ipojo.architecture.ProvidedServiceHandlerDescription;
import org.apache.felix.ipojo.handlers.dependency.Dependency;
import org.apache.felix.ipojo.handlers.dependency.DependencyHandler;
import org.apache.felix.ipojo.handlers.dependency.DependencyMetadata;
@@ -42,12 +47,12 @@
* Achtiecture Handler : do reflection on your component.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class ArchitectureHandler implements Handler, Architecture {
+public class ArchitectureHandler extends Handler implements Architecture {
- /**
- * Component Manager.
- */
- private ComponentManager m_manager;
+ /**
+ * Component Manager.
+ */
+ private ComponentManagerImpl m_manager;
/**
* Service Registration of the Architecture service provided by this handler.
@@ -55,123 +60,113 @@
private ServiceRegistration m_sr;
/**
- * Unique name of the component : either the name of the component, either the classname if the name if not setted.
+ * Name of the component.
*/
private String m_name;
- /**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManager, org.apache.felix.ipojo.metadata.Element)
- */
- public void configure(ComponentManager cm, Element metadata) {
- if (metadata.containsAttribute("architecture")) {
- String isArchitectureEnabled = (metadata.getAttribute("architecture")).toLowerCase();
- if (isArchitectureEnabled.equals("true")) { cm.register(this); }
- }
+ /**
+ * Component Type.
+ */
+ private String m_className;
- if (metadata.containsAttribute("name")) { m_name = metadata.getAttribute("name"); }
- else { m_name = metadata.getAttribute("className"); }
+ /**
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ */
+ public void configure(ComponentManagerImpl cm, Element metadata, Dictionary configuration) {
+ if (metadata.containsAttribute("architecture")) {
+ String isArchitectureEnabled = (metadata.getAttribute("architecture")).toLowerCase();
+ if (isArchitectureEnabled.equals("true")) { cm.register(this); }
+ }
- m_manager = cm;
- }
+ m_className = metadata.getAttribute("className");
- /**
- * @see org.apache.felix.ipojo.Handler#stop()
- */
- public void stop() {
+ m_name = (String) configuration.get("name");
+
+ m_manager = cm;
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.Handler#stop()
+ */
+ public void stop() {
try {
if (m_sr != null) { m_sr.unregister(); }
} catch (Exception e) { return; }
- }
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#start()
- */
- public void start() {
- // Unregister the service if already registred
- if (m_sr != null) { m_sr.unregister(); }
+ /**
+ * @see org.apache.felix.ipojo.Handler#start()
+ */
+ public void start() {
+ // Unregister the service if already registred
+ if (m_sr != null) { m_sr.unregister(); }
- // Register the ManagedService
- BundleContext bc = m_manager.getContext();
- Dictionary properties = new Properties();
- properties.put("Component Implementation Class", m_manager.getComponentMetatada().getClassName());
- properties.put(Constants.SERVICE_PID, m_name);
+ // Register the ManagedService
+ BundleContext bc = m_manager.getContext();
+ Dictionary properties = new Properties();
+ properties.put("Component Implementation Class", m_manager.getComponentMetatada().getClassName());
+ properties.put(Constants.SERVICE_PID, m_name);
- m_sr = bc.registerService(Architecture.class.getName(), this, properties);
+ m_sr = bc.registerService(Architecture.class.getName(), this, properties);
- }
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
- */
- public void setterCallback(String fieldName, Object value) { // Nothing to do
- }
+ /**
+ * @see org.apache.felix.ipojo.architecture.Architecture#getComponentDescription()
+ */
+ public ComponentDescription getComponentDescription() {
+ int componentState = m_manager.getState();
+ ComponentDescription componentDescription = new ComponentDescription(m_className, m_name, componentState, m_manager.getContext().getBundle().getBundleId());
- /**
- * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
- */
- public Object getterCallback(String fieldName, Object value) { return value; }
+ String[] instances = new String[m_manager.getInstances().length];
+ for (int i = 0; i < m_manager.getInstances().length; i++) {
+ instances[i] = m_manager.getInstances()[i].toString();
+ }
+ componentDescription.setInstances(instances);
- /**
- * @see org.apache.felix.ipojo.Handler#isValid()
- */
- public boolean isValid() { return true; }
+ Handler[] handlers = m_manager.getRegistredHandlers();
+ for (int i = 0; i < handlers.length; i++) {
+ if (handlers[i] instanceof DependencyHandler) {
+ DependencyHandler dh = (DependencyHandler) handlers[i];
+ DependencyHandlerDescription dhd = new DependencyHandlerDescription(dh.isValid());
- /**
- * @see org.apache.felix.ipojo.Handler#stateChanged(int)
- */
- public void stateChanged(int state) {
- // Nothing to do
- }
+ for (int j = 0; j < dh.getDependencies().length; j++) {
+ Dependency dep = dh.getDependencies()[j];
+ DependencyMetadata dm = dep.getMetadata();
+ // Create & add the dependency description
+ DependencyDescription dd = new DependencyDescription(dm.getServiceSpecification(), dm.isMultiple(), dm.isOptional(), dm.getFilter(), dep.getState(), componentDescription);
+ dd.setUsedServices(dep.getUsedServices());
+ dhd.addDependency(dd);
+ }
+ componentDescription.addHandler(dhd);
+ break;
+ }
- /**
- * @see org.apache.felix.ipojo.architecture.Architecture#getComponentDescription()
- */
- public ComponentDescription getComponentDescription() {
- int componentState = m_manager.getState();
- ComponentDescription componentDescription = new ComponentDescription(m_name, componentState);
+ if (handlers[i] instanceof ProvidedServiceHandler) {
+ ProvidedServiceHandler psh = (ProvidedServiceHandler) handlers[i];
+ ProvidedServiceHandlerDescription pshd = new ProvidedServiceHandlerDescription(psh.isValid());
- String[] instances = new String[m_manager.getInstances().length];
- for (int i = 0; i < m_manager.getInstances().length; i++) {
- instances[i] = m_manager.getInstances()[i].toString();
- }
- componentDescription.setInstances(instances);
+ for (int j = 0; j < psh.getProvidedService().length; j++) {
+ ProvidedService ps = psh.getProvidedService()[j];
+ ProvidedServiceMetadata psm = ps.getMetadata();
+ ProvidedServiceDescription psd = new ProvidedServiceDescription(psm.getServiceSpecification(), ps.getState(), ps.getServiceReference(), componentDescription);
- Handler[] handlers = m_manager.getRegistredHandlers();
- for (int i = 0; i < handlers.length; i++) {
- if (handlers[i] instanceof DependencyHandler) {
- DependencyHandler dh = (DependencyHandler)handlers[i];
- for (int j = 0; j < dh.getDependencies().length; j++) {
- Dependency dep = dh.getDependencies()[j];
- DependencyMetadata dm = dep.getMetadata();
-
- // Create & add the dependency description
- DependencyDescription dd = new DependencyDescription(dm.getServiceSpecification(), dm.isMultiple(), dm.isOptional(), dm.getFilter(), dep.getState(), componentDescription);
- dd.setUsedServices(dep.getUsedServices());
- componentDescription.addDependency(dd);
- }
- }
- if (handlers[i] instanceof ProvidedServiceHandler) {
- ProvidedServiceHandler psh = (ProvidedServiceHandler)handlers[i];
- for (int j = 0; j < psh.getProvidedService().length; j++) {
- ProvidedService ps = psh.getProvidedService()[j];
- ProvidedServiceMetadata psm = ps.getMetadata();
- ProvidedServiceDescription psd = new ProvidedServiceDescription(psm.getServiceSpecification(), ps.getState(), ps.getServiceReference(), componentDescription);
-
- Properties props = new Properties();
- for (int k = 0; k < ps.getProperties().length; k++) {
- Property prop = ps.getProperties()[k];
- PropertyMetadata pm = prop.getMetadata();
- if (prop.getValue() != null) {
- props.put(pm.getName(), prop.getValue().toString());
- }
- }
- psd.setProperty(props);
- componentDescription.addProvidedService(psd);
- }
- }
-
- }
- return componentDescription;
- }
+ Properties props = new Properties();
+ for (int k = 0; k < ps.getProperties().length; k++) {
+ Property prop = ps.getProperties()[k];
+ PropertyMetadata pm = prop.getMetadata();
+ if (prop.getValue() != null) { props.put(pm.getName(), prop.getValue().toString()); }
+ }
+ psd.setProperty(props);
+ pshd.addProvidedService(psd);
+ }
+ componentDescription.addHandler(pshd);
+ break;
+ }
+ // Else add a generic handler to the description
+ componentDescription.addHandler(new HandlerDescription(handlers[i].getClass().getName(), handlers[i].isValid()));
+ }
+ return componentDescription;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
index e179ec7..56fcb73 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.configuration;
@@ -30,63 +32,80 @@
*/
public class ConfigurableProperty {
- /**
- * Name of the property (filed name if not set).
- */
- private String m_name;
+ /**
+ * Name of the property (filed name if not set).
+ */
+ private String m_name;
- /**
- * Field of the property.
- */
- private String m_field;
+ /**
+ * Field of the property.
+ */
+ private String m_field;
- /**
- * Value of the property.
- */
- private Object m_value;
+ /**
+ * Value of the property.
+ */
+ private Object m_value;
- /**
- * Configuration Handler managing this property.
- */
- private ConfigurationHandler m_handler;
+ /**
+ * Configuration Handler managing this property.
+ */
+ private ConfigurationHandler m_handler;
- /**
- * Configurable Property Constructor.
- * @param name : name of the property (optional)
- * @param field : name of the field (mandatory)
- * @param value : initial value of the property (optional)
- * @param ch : configuration handler managing this configurable property
- */
- public ConfigurableProperty(String name, String field, String value, ConfigurationHandler ch) {
- m_handler = ch;
- if (name != null) { m_name = name; }
- else { m_name = field; }
- m_field = field;
+ /**
+ * Configurable Property Constructor.
+ * @param name : name of the property (optional)
+ * @param field : name of the field (mandatory)
+ * @param value : initial value of the property (optional)
+ * @param ch : configuration handler managing this configurable property
+ */
+ public ConfigurableProperty(String name, String field, String value, ConfigurationHandler ch) {
+ m_handler = ch;
+ if (name != null) { m_name = name; }
+ else { m_name = field; }
+ m_field = field;
- if (value != null) { setValue(m_field, value); }
+ if (value != null) { setValue(m_field, value); }
- }
+ }
- /**
+ /**
+ * @return the type of a configurable property.
+ */
+ public String getType() {
+ Element manipulation = m_handler.getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
+ String type = null;
+ for (int i = 0; i < manipulation.getElements("Field").length; i++) {
+ if (m_field.equals(manipulation.getElements("Field")[i].getAttribute("name"))) {
+ return manipulation.getElements("Field")[i].getAttribute("type");
+ }
+ }
+
+ if (type == null) { Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] The field " + m_field + " does not exist in the implementation"); }
+ return null;
+
+ }
+
+ /**
* Set the value of the property.
* @param strValue : value of the property (String)
*/
private void setValue(String field, String strValue) {
- // Look for the type of the field
- Element manipulation = m_handler.getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
- String type = null;
- for (int i = 0; i < manipulation.getElements("Field").length; i++) {
- if (field.equals(manipulation.getElements("Field")[i].getAttribute("name"))) {
- type = manipulation.getElements("Field")[i].getAttribute("type");
- break;
- }
- }
+ // Look for the type of the field
+ Element manipulation = m_handler.getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
+ String type = null;
+ for (int i = 0; i < manipulation.getElements("Field").length; i++) {
+ if (field.equals(manipulation.getElements("Field")[i].getAttribute("name"))) {
+ type = manipulation.getElements("Field")[i].getAttribute("type");
+ break;
+ }
+ }
- if (type == null) { Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] The field " + field + " does not exist in the implementation"); return; }
+ if (type == null) { Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] The field " + field + " does not exist in the implementation"); return; }
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Set the value of the configurable property " + field + " [" + type + "] " + " with the value : " + strValue);
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Set the value of the configurable property " + field + " [" + type + "] " + " with the value : " + strValue);
- Object value = null;
+ Object value = null;
if (type.equals("string") || type.equals("String")) { value = new String(strValue); }
if (type.equals("boolean")) { value = new Boolean(strValue); }
@@ -96,95 +115,100 @@
if (type.equals("long")) { value = new Long(strValue); }
if (type.equals("float")) { value = new Float(strValue); }
if (type.equals("double")) { value = new Double(strValue); }
- // Array :
- if (type.endsWith("[]")) {
- String internalType = type.substring(0, type.length() - 2);
- strValue = strValue.substring(1, strValue.length() - 1);
- String[] values = strValue.split(",");
- setArrayValue(internalType, values);
- return;
- }
+ // Array :
+ if (type.endsWith("[]")) {
+ String internalType = type.substring(0, type.length() - 2);
+ strValue = strValue.substring(1, strValue.length() - 1);
+ String[] values = strValue.split(",");
+ setArrayValue(internalType, values);
+ return;
+ }
if (value == null) {
- // Else it is a neither a primitive type neither a String -> create the object by calling a constructor with a string in argument.
- try {
- Class c = m_handler.getComponentManager().getContext().getBundle().loadClass(type);
- Constructor cst = c.getConstructor(new Class[] {String.class});
- value = cst.newInstance(new Object[] {strValue});
- } catch (ClassNotFoundException e) {
- System.err.println("Class not found exception in setValue on " + type);
- e.printStackTrace();
- return;
- } catch (SecurityException e) {
- e.printStackTrace();
- return;
- } catch (NoSuchMethodException e) {
- System.err.println("Constructor not found exeption in setValue on " + type);
- e.printStackTrace();
- return;
- } catch (IllegalArgumentException e) {
- System.err.println("Argument problem to call the constructor of the type " + type);
- e.printStackTrace();
- return;
- } catch (InstantiationException e) {
- System.err.println("Instantiation problem " + type);
- e.printStackTrace();
- return;
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- System.err.println("Invocation problem " + type);
- e.printStackTrace();
- return;
- }
+ // Else it is a neither a primitive type neither a String -> create the object by calling a constructor with a string in argument.
+ try {
+ Class c = m_handler.getComponentManager().getContext().getBundle().loadClass(type);
+ Constructor cst = c.getConstructor(new Class[] {String.class});
+ value = cst.newInstance(new Object[] {strValue});
+ } catch (ClassNotFoundException e) {
+ System.err.println("Class not found exception in setValue on " + type);
+ e.printStackTrace();
+ return;
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ return;
+ } catch (NoSuchMethodException e) {
+ System.err.println("Constructor not found exeption in setValue on " + type);
+ e.printStackTrace();
+ return;
+ } catch (IllegalArgumentException e) {
+ System.err.println("Argument problem to call the constructor of the type " + type);
+ e.printStackTrace();
+ return;
+ } catch (InstantiationException e) {
+ System.err.println("Instantiation problem " + type);
+ e.printStackTrace();
+ return;
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ System.err.println("Invocation problem " + type);
+ e.printStackTrace();
+ return;
+ }
}
m_value = value;
}
+ /**
+ * Set array value to the current property.
+ * @param internalType : type of the property
+ * @param values : new property value
+ */
private void setArrayValue(String internalType, String[] values) {
- if (internalType.equals("string") || internalType.equals("String")) { m_value = values; return; }
+ if (internalType.equals("string") || internalType.equals("String")) { m_value = values; return; }
if (internalType.equals("boolean")) {
- boolean[] bool = new boolean[values.length];
- for (int i = 0; i < values.length; i++) { bool[i] = new Boolean(values[i]).booleanValue(); }
- m_value = bool;
- return;
- }
- if (internalType.equals("byte")) {
- byte[] byt = new byte[values.length];
- for (int i = 0; i < values.length; i++) { byt[i] = new Byte(values[i]).byteValue(); }
- m_value = byt;
- return;
- }
+ boolean[] bool = new boolean[values.length];
+ for (int i = 0; i < values.length; i++) { bool[i] = new Boolean(values[i]).booleanValue(); }
+ m_value = bool;
+ return;
+ }
+ if (internalType.equals("byte")) {
+ byte[] byt = new byte[values.length];
+ for (int i = 0; i < values.length; i++) { byt[i] = new Byte(values[i]).byteValue(); }
+ m_value = byt;
+ return;
+ }
if (internalType.equals("short")) {
- short[] shor = new short[values.length];
- for (int i = 0; i < values.length; i++) { shor[i] = new Short(values[i]).shortValue(); }
- m_value = shor;
- return;
- }
+ short[] shor = new short[values.length];
+ for (int i = 0; i < values.length; i++) { shor[i] = new Short(values[i]).shortValue(); }
+ m_value = shor;
+ return;
+ }
if (internalType.equals("int")) {
- int[] in = new int[values.length];
- for (int i = 0; i < values.length; i++) { in[i] = new Integer(values[i]).intValue(); }
- m_value = in;
- return;
- }
+ int[] in = new int[values.length];
+ for (int i = 0; i < values.length; i++) { in[i] = new Integer(values[i]).intValue(); }
+ m_value = in;
+ return;
+ }
if (internalType.equals("long")) {
- long[] ll = new long[values.length];
- for (int i = 0; i < values.length; i++) { ll[i] = new Long(values[i]).longValue(); }
- m_value = ll;
- return;
- }
+ long[] ll = new long[values.length];
+ for (int i = 0; i < values.length; i++) { ll[i] = new Long(values[i]).longValue(); }
+ m_value = ll;
+ return;
+ }
if (internalType.equals("float")) {
- float[] fl = new float[values.length];
- for (int i = 0; i < values.length; i++) { fl[i] = new Float(values[i]).floatValue(); }
- m_value = fl;
- return; }
+ float[] fl = new float[values.length];
+ for (int i = 0; i < values.length; i++) { fl[i] = new Float(values[i]).floatValue(); }
+ m_value = fl;
+ return; }
if (internalType.equals("double")) {
- double[] dl = new double[values.length];
- for (int i = 0; i < values.length; i++) { dl[i] = new Double(values[i]).doubleValue(); }
- m_value = dl;
- return; }
+ double[] dl = new double[values.length];
+ for (int i = 0; i < values.length; i++) { dl[i] = new Double(values[i]).doubleValue(); }
+ m_value = dl;
+ return; }
// Else it is a neither a primitive type neither a String -> create the object by calling a constructor with a string in argument.
try {
@@ -192,7 +216,7 @@
Constructor cst = c.getConstructor(new Class[] {String.class});
Object[] ob = (Object[]) Array.newInstance(c, values.length);
for (int i = 0; i < values.length; i++) {
- ob[i] = cst.newInstance(new Object[] {values[i]});
+ ob[i] = cst.newInstance(new Object[] {values[i]});
}
m_value = ob;
return;
@@ -216,7 +240,7 @@
System.err.println("Invocation problem " + internalType);
e.printStackTrace();
}
- }
+ }
/**
* @return the name of the property.
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
index 62b6cff..7367cb2 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.configuration;
@@ -21,11 +23,11 @@
import java.util.Properties;
import java.util.logging.Level;
-import org.apache.felix.ipojo.ComponentManager;
-import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.Activator;
-import org.apache.felix.ipojo.handlers.providedservice.Property;
-import org.apache.felix.ipojo.handlers.providedservice.ProvidedService;
+import org.apache.felix.ipojo.ComponentInfo;
+import org.apache.felix.ipojo.ComponentManagerImpl;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.PropertyInfo;
import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler;
import org.apache.felix.ipojo.metadata.Element;
import org.osgi.framework.BundleContext;
@@ -38,229 +40,261 @@
* Handler managing the Configuration Admin.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class ConfigurationHandler implements Handler, ManagedService {
+public class ConfigurationHandler extends Handler implements ManagedService {
- /**
- * Reference on the component manager.
- */
- private ComponentManager m_manager;
+ /**
+ * Reference on the component manager.
+ */
+ private ComponentManagerImpl m_manager;
- /**
- * List of the configurable fields.
- */
- private ConfigurableProperty[] m_configurableProperties = new ConfigurableProperty[0];
+ /**
+ * List of the configurable fields.
+ */
+ private ConfigurableProperty[] m_configurableProperties = new ConfigurableProperty[0];
- /**
- * ProvidedServiceHandler of the component.
- * It is useful to priopagate properties to service registrations.
- */
- private ProvidedServiceHandler m_providedServiceHandler;
+ /**
+ * ProvidedServiceHandler of the component.
+ * It is useful to priopagate properties to service registrations.
+ */
+ private ProvidedServiceHandler m_providedServiceHandler;
- /**
- * Properties porpagated at the last "updated".
- */
- private Dictionary m_propagated = new Properties();
+ /**
+ * Properties porpagated at the last "updated".
+ */
+ private Dictionary m_propagated = new Properties();
- /**
- * PID of the component.
- */
- private String m_pid;
+ /**
+ * PID of the component.
+ */
+ private String m_pid;
- /**
- * Service registration of the ManagedService provided by this handler.
- */
- private ServiceRegistration m_sr;
+ /**
+ * should the component provided ManagedService ?
+ */
+ private boolean m_isConfigurable;
- /**
- * @return component manager of this handler.
- */
- protected ComponentManager getComponentManager() { return m_manager; }
+ /**
+ * Service registration of the ManagedService provided by this handler.
+ */
+ private ServiceRegistration m_sr;
- /**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManager, org.apache.felix.ipojo.metadata.Element)
- */
- public void configure(ComponentManager cm, Element metadata) {
- // Store the component manager
- m_manager = cm;
- m_configurableProperties = new ConfigurableProperty[0];
+ /**
+ * @return component manager of this handler.
+ */
+ protected ComponentManagerImpl getComponentManager() { return m_manager; }
- // Build the hashmap
- Element[] configurables = metadata.getElements("ConfigurableProperty");
+ /**
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ */
+ public void configure(ComponentManagerImpl cm, Element metadata, Dictionary configuration) {
+ // Store the component manager
+ m_manager = cm;
+ ComponentInfo ci = cm.getComponentInfo();
+ m_configurableProperties = new ConfigurableProperty[0];
- if (configurables.length > 0) { m_manager.register(this); }
- else { return; }
+ // Build the hashmap
+ Element[] confs = metadata.getElements("Properties", "");
+ if (confs.length == 0) { return; }
- for (int i = 0; i < configurables.length; i++) {
- String fieldName = configurables[i].getAttribute("field");
- String name = null;
- if (configurables[i].containsAttribute("name")) { name = configurables[i].getAttribute("name"); }
- else { name = fieldName; }
- String value = null;
- if (configurables[i].containsAttribute("value")) {
- value = configurables[i].getAttribute("value");
- }
- ConfigurableProperty cp = new ConfigurableProperty(name, fieldName, value, this);
- addProperty(cp);
- }
+ // Check if the component is dynamically configurable
+ m_isConfigurable = false;
+ if (confs[0].containsAttribute("configurable") && confs[0].getAttribute("configurable").equalsIgnoreCase("true")) { m_isConfigurable = true; }
- // Get the PID :
- if (metadata.containsAttribute("name")) { m_pid = metadata.getAttribute("name"); }
- else { m_pid = metadata.getAttribute("className"); }
- m_providedServiceHandler = (ProvidedServiceHandler) m_manager.getHandler(ProvidedServiceHandler.class.getName());
- }
+ Element[] configurables = confs[0].getElements("Property");
- /**
- * @see org.apache.felix.ipojo.Handler#stop()
- */
- public void stop() {
- // Unregister the service
- if (m_sr != null) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Unregister Managed Service");
- m_sr.unregister();
- m_sr = null;
- }
+ for (int i = 0; i < configurables.length; i++) {
+ String fieldName = configurables[i].getAttribute("field");
+ String name = null;
+ if (configurables[i].containsAttribute("name")) { name = configurables[i].getAttribute("name"); }
+ else { name = fieldName; }
+ String value = null;
+ if (configurables[i].containsAttribute("value")) { value = configurables[i].getAttribute("value"); }
- }
+ if (name != null && configuration.get(name) != null && configuration.get(name) instanceof String) { value = (String) configuration.get(name); }
+ else { if (fieldName != null && configuration.get(fieldName) != null && configuration.get(fieldName) instanceof String) { value = (String) configuration.get(fieldName); } }
- /**
- * @see org.apache.felix.ipojo.Handler#start()
- */
- public void start() {
- // Unregister the service if already registred (it should not happen )
- if (m_sr != null) { m_sr.unregister(); }
+ ConfigurableProperty cp = new ConfigurableProperty(name, fieldName, value, this);
- // Register the ManagedService
- BundleContext bc = m_manager.getContext();
- Dictionary properties = new Properties();
- properties.put(Constants.SERVICE_PID, m_pid);
+ if (cp.getValue() != null) { ci.addProperty(new PropertyInfo(name, cp.getType(), cp.getValue().toString())); }
+ else { ci.addProperty(new PropertyInfo(name, cp.getType(), "")); }
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Register Managed Service");
- m_sr = bc.registerService(ManagedService.class.getName(), this, properties);
- }
+ addProperty(cp);
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
- */
- public void setterCallback(String fieldName, Object value) {
- // Verify that the field name correspond to a configurable property
- for (int i = 0; i < m_configurableProperties.length; i++) {
- ConfigurableProperty cp = m_configurableProperties[i];
- if (cp.getName().equals(fieldName)) {
- // Check if the value has change
- if (cp.getValue() == null || !cp.getValue().equals(value)) {
- cp.setValue(value); // Change the value
- }
- }
- }
- //Else do nothing
- }
+ // Get the PID in the configuration name :
+ if (configuration.get("name") != null) { m_pid = (String) configuration.get("name"); }
+ else { m_pid = metadata.getAttribute("className"); }
- /**
- * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
- */
- public Object getterCallback(String fieldName, Object value) {
- // Check if the field is a configurable property
- for (int i = 0; i < m_configurableProperties.length; i++) {
- if (m_configurableProperties[i].getField().equals(fieldName)) {
- return m_configurableProperties[i].getValue();
- }
- }
- return value;
- }
+ // Get the provided service handler :
+ m_providedServiceHandler = (ProvidedServiceHandler) m_manager.getHandler(ProvidedServiceHandler.class.getName());
- /**
- * @see org.apache.felix.ipojo.Handler#isValid()
- */
- public boolean isValid() {
- return true;
- }
+ if (configurables.length > 0) {
+ String[] fields = new String[m_configurableProperties.length];
+ for (int k = 0; k < m_configurableProperties.length; k++) {
+ fields[k] = m_configurableProperties[k].getField();
- /**
- * @see org.apache.felix.ipojo.Handler#stateChanged(int)
- */
- public void stateChanged(int state) {
- if (state == ComponentManager.VALID) {
- if (m_sr == null) { start(); }
- return;
- }
- if (state == ComponentManager.INVALID) {
- if (m_sr != null) { stop(); }
- return;
- }
- }
+ // Check if the instance configuration contains value for the current property :
+ String name = m_configurableProperties[k].getName();
+ String fieldName = m_configurableProperties[k].getField();
+ if (name != null && configuration.get(name) != null && !(configuration.get(name) instanceof String)) { m_configurableProperties[k].setValue(configuration.get(name)); }
+ else { if (fieldName != null && configuration.get(fieldName) != null && !(configuration.get(fieldName) instanceof String)) { m_configurableProperties[k].setValue(configuration.get(fieldName)); } }
+ }
+ m_manager.register(this, fields);
- /**
- * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
- */
- public void updated(Dictionary np) throws ConfigurationException {
- Properties toPropagate = new Properties();
- if (np != null) {
- Enumeration keysEnumeration = np.keys();
- while (keysEnumeration.hasMoreElements()) {
- String name = (String)keysEnumeration.nextElement();
- Object value = np.get(name);
- boolean find = false;
- // Check if the field is a configurable property
- for (int i = 0; !find && i < m_configurableProperties.length; i++) {
- if (m_configurableProperties[i].getName().equals(name)) {
- // Check if the value has change
- if (m_configurableProperties[i].getValue() == null || !m_configurableProperties[i].getValue().equals(value)) {
- //m_configurableProperties[i].setValue(value); // Useless, the setterCallback will call the setValue
- m_manager.setterCallback(m_configurableProperties[i].getField(), value); // says that the value has change
- }
- find = true;
- // Else do nothing
- }
- }
- if (!find) {
- //The property is not a configurable property
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] The property " + name + " will be propagated to service registrations");
- toPropagate.put(name, value);
- }
- }
- }
- else { Activator.getLogger().log(Level.WARNING, "[" + m_manager.getComponentMetatada().getClassName() + "] The pushed configuration is null for " + m_pid); }
- // Propagation of the properties to service registrations :
- if (m_providedServiceHandler != null && !toPropagate.isEmpty()) {
- Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Properties will be propagated");
- m_providedServiceHandler.removeProperties(m_propagated);
- m_providedServiceHandler.addProperties(toPropagate);
- m_propagated = toPropagate;
- }
- }
- /**
+ }
+ else { return; }
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.Handler#stop()
+ */
+ public void stop() {
+ // Unregister the service
+ if (m_isConfigurable && m_sr != null) {
+ Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Unregister Managed Service");
+ m_sr.unregister();
+ m_sr = null;
+ }
+
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.Handler#start()
+ */
+ public void start() {
+ // Unregister the service if already registred (it should not happen )
+ if (m_isConfigurable && m_sr != null) { m_sr.unregister(); }
+
+ // Register the ManagedService
+ if (m_isConfigurable) {
+ BundleContext bc = m_manager.getContext();
+ Dictionary properties = new Properties();
+ properties.put(Constants.SERVICE_PID, m_pid);
+
+ Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Register Managed Service");
+ m_sr = bc.registerService(ManagedService.class.getName(), this, properties);
+ }
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
+ */
+ public void setterCallback(String fieldName, Object value) {
+ // Verify that the field name correspond to a configurable property
+ for (int i = 0; i < m_configurableProperties.length; i++) {
+ ConfigurableProperty cp = m_configurableProperties[i];
+ if (cp.getName().equals(fieldName)) {
+ // Check if the value has change
+ if (cp.getValue() == null || !cp.getValue().equals(value)) {
+ cp.setValue(value); // Change the value
+ }
+ }
+ }
+ //Else do nothing
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
+ */
+ public Object getterCallback(String fieldName, Object value) {
+ // Check if the field is a configurable property
+ for (int i = 0; i < m_configurableProperties.length; i++) {
+ if (m_configurableProperties[i].getField().equals(fieldName)) {
+ return m_configurableProperties[i].getValue();
+ }
+ }
+ return value;
+ }
+
+ /**
+ * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+ */
+ public void stateChanged(int state) {
+ if (state == ComponentManagerImpl.VALID) {
+ if (m_sr == null) { start(); }
+ return;
+ }
+ if (state == ComponentManagerImpl.INVALID) {
+ if (m_sr != null) { stop(); }
+ return;
+ }
+ }
+
+ /**
+ * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
+ */
+ public void updated(Dictionary np) throws ConfigurationException {
+ Properties toPropagate = new Properties();
+ if (np != null) {
+ Enumeration keysEnumeration = np.keys();
+ while (keysEnumeration.hasMoreElements()) {
+ String name = (String) keysEnumeration.nextElement();
+ Object value = np.get(name);
+ boolean find = false;
+ // Check if the field is a configurable property
+ for (int i = 0; !find && i < m_configurableProperties.length; i++) {
+ if (m_configurableProperties[i].getName().equals(name)) {
+ // Check if the value has change
+ if (m_configurableProperties[i].getValue() == null || !m_configurableProperties[i].getValue().equals(value)) {
+ //m_configurableProperties[i].setValue(value); // Useless, the setterCallback will call the setValue
+ m_manager.setterCallback(m_configurableProperties[i].getField(), value); // says that the value has change
+ }
+ find = true;
+ // Else do nothing
+ }
+ }
+ if (!find) {
+ //The property is not a configurable property
+ Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] The property " + name + " will be propagated to service registrations");
+ toPropagate.put(name, value);
+ }
+ }
+ }
+ else { Activator.getLogger().log(Level.WARNING, "[" + m_manager.getComponentMetatada().getClassName() + "] The pushed configuration is null for " + m_pid); }
+
+ // Propagation of the properties to service registrations :
+ if (m_providedServiceHandler != null && !toPropagate.isEmpty()) {
+ Activator.getLogger().log(Level.INFO, "[" + m_manager.getComponentMetatada().getClassName() + "] Properties will be propagated");
+ m_providedServiceHandler.removeProperties(m_propagated);
+ m_providedServiceHandler.addProperties(toPropagate);
+ m_propagated = toPropagate;
+ }
+
+ }
+
+ /**
* Add the given property metadata to the property metadata list.
- * @param p : property metdata to add
- */
- protected void addProperty(ConfigurableProperty p) {
+ * @param p : property metdata to add
+ */
+ protected void addProperty(ConfigurableProperty p) {
for (int i = 0; (m_configurableProperties != null) && (i < m_configurableProperties.length); i++) {
if (m_configurableProperties[i] == p) { return; }
}
if (m_configurableProperties.length > 0) {
- ConfigurableProperty[] newProp = new ConfigurableProperty[m_configurableProperties.length + 1];
+ ConfigurableProperty[] newProp = new ConfigurableProperty[m_configurableProperties.length + 1];
System.arraycopy(m_configurableProperties, 0, newProp, 0, m_configurableProperties.length);
newProp[m_configurableProperties.length] = p;
m_configurableProperties = newProp;
}
else {
- m_configurableProperties = new ConfigurableProperty[] {p};
+ m_configurableProperties = new ConfigurableProperty[] {p};
}
- }
+ }
- /**
- * Check if the liste contains the property.
- * @param name : name of the property
- * @return true if the property exist in the list
- */
- protected boolean containsProperty(String name) {
- for (int i = 0; (m_configurableProperties != null) && (i < m_configurableProperties.length); i++) {
+ /**
+ * Check if the liste contains the property.
+ * @param name : name of the property
+ * @return true if the property exist in the list
+ */
+ protected boolean containsProperty(String name) {
+ for (int i = 0; (m_configurableProperties != null) && (i < m_configurableProperties.length); i++) {
if (m_configurableProperties[i].getName() == name) { return true; }
}
- return false;
- }
+ return false;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
index 75e7d6b..6836743 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.dependency;
@@ -22,7 +24,8 @@
import java.util.logging.Level;
import org.apache.felix.ipojo.Activator;
-import org.apache.felix.ipojo.ComponentManager;
+import org.apache.felix.ipojo.ComponentManagerImpl;
+import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
@@ -90,6 +93,11 @@
*/
private Class m_clazz;
+ /**
+ * LDAP Filter of the dependency.
+ */
+ private Filter m_filter;
+
/**
* Dependency contructor. After the creation the dependency is not started.
@@ -97,7 +105,7 @@
* @param dm : the depednency metadata
*/
public Dependency(DependencyHandler dh, DependencyMetadata dm) {
- m_handler = dh;
+ m_handler = dh;
m_metadata = dm;
}
@@ -115,15 +123,15 @@
* @return the used service.
*/
public HashMap getUsedServices() {
- HashMap hm = new HashMap();
- if (m_metadata.isMultiple()) {
- for (int i = 0; i < m_ref.length; i++) {
- if (i < m_services.length) { hm.put(((Object)m_services[i]).toString(), m_ref[i]); }
- }
- } else {
- if (m_ref.length != 0 && m_services.length != 0) { hm.put(((Object)m_services[0]).toString(), m_ref[0]); }
- }
- return hm;
+ HashMap hm = new HashMap();
+ if (m_metadata.isMultiple()) {
+ for (int i = 0; i < m_ref.length; i++) {
+ if (i < m_services.length) { hm.put(((Object) m_services[i]).toString(), m_ref[i]); }
+ }
+ } else {
+ if (m_ref.length != 0 && m_services.length != 0) { hm.put(((Object) m_services[0]).toString(), m_ref[0]); }
+ }
+ return hm;
}
/**
@@ -141,7 +149,7 @@
*/
protected Object get() {
Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Call get for a dependency on : " + m_metadata.getServiceSpecification()
- + " Multiple : " + m_metadata.isMultiple() + " Optional : " + m_metadata.isOptional());
+ + " Multiple : " + m_metadata.isMultiple() + " Optional : " + m_metadata.isOptional());
try {
// 1 : Test if there is any change in the reference list :
@@ -149,15 +157,15 @@
if (!m_metadata.isMultiple()) {
if (m_services.length > 0) {
return m_services[0]; }
- }
+ }
else {
return m_services;
- }
+ }
}
// 2 : Else there is a change in the list -> recompute the m_services array
Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Create a service array of " + m_clazz.getName());
- m_services = (Object[])Array.newInstance(m_clazz, m_ref.length);
+ m_services = (Object[]) Array.newInstance(m_clazz, m_ref.length);
for (int i = 0; i < m_ref.length; i++) {
m_services[i] = m_handler.getComponentManager().getContext().getService(m_ref[i]);
@@ -173,33 +181,33 @@
if (m_services.length > 0) {
return m_services[0];
} else {
- // Load the nullable class
- String[] segment = m_metadata.getServiceSpecification().split("[.]");
- String className = "org.apache.felix.ipojo." + segment[segment.length - 1] + "Nullable";
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Try to load the nullable class for " + getMetadata().getServiceSpecification() + " -> " + className);
- Class nullableClazz = m_handler.getNullableClass(className);
+ // Load the nullable class
+ String[] segment = m_metadata.getServiceSpecification().split("[.]");
+ String className = "org.apache.felix.ipojo." + segment[segment.length - 1] + "Nullable";
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Try to load the nullable class for " + getMetadata().getServiceSpecification() + " -> " + className);
+ Class nullableClazz = m_handler.getNullableClass(className);
- if (nullableClazz == null) {
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Cannot load the nullable class to return a dependency object for " + m_metadata.getField() + " -> " + m_metadata.getServiceSpecification());
- return null;
- }
+ if (nullableClazz == null) {
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Cannot load the nullable class to return a dependency object for " + m_metadata.getField() + " -> " + m_metadata.getServiceSpecification());
+ return null;
+ }
- // The nullable class is loaded, create the object and return it
- Object instance = nullableClazz.newInstance();
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Nullable object created for " + getMetadata().getServiceSpecification() + " -> " + instance);
- return instance;
- }
+ // The nullable class is loaded, create the object and return it
+ Object instance = nullableClazz.newInstance();
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Nullable object created for " + getMetadata().getServiceSpecification() + " -> " + instance);
+ return instance;
+ }
}
else { // Multiple dependency
- return m_services;
+ return m_services;
}
} catch (Exception e) {
// There is a problem in the dependency resolving (like in stopping method)
if (!m_metadata.isMultiple()) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Return null, an exception was throwed in the get method -> " + e.getMessage());
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Return null, an exception was throwed in the get method -> " + e.getMessage());
return null; }
else {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Return an empty array, an exception was throwed in the get method" + e.getMessage());
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Return an empty array, an exception was throwed in the get method" + e.getMessage());
return Array.newInstance(m_clazz, 0); }
}
}
@@ -215,133 +223,272 @@
// If a service goes way.
if (event.getType() == ServiceEvent.UNREGISTERING) {
Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] A service is gone -> " + event.getServiceReference().getBundle());
- if (containsSR(event.getServiceReference())) {
- // Call unbind method
- callUnbindMethod(event.getServiceReference());
- // Unget the service reference
- m_handler.getComponentManager().getContext().ungetService(event.getServiceReference());
- int index = removeReference(event.getServiceReference());
-
- // Is the state valid or invalid
- if (m_ref.length == 0 && !m_metadata.isOptional()) {
- m_state = UNRESOLVED;
- }
- if (m_ref.length == 0 && m_metadata.isOptional()) {
- m_state = RESOLVED;
- }
- // Is there any change ?
- if (!m_metadata.isMultiple() && index == 0) { m_change = true; }
- if (!m_metadata.isMultiple() && index != 0) { m_change = false; }
- if (m_metadata.isMultiple()) { m_change = true; }
- }
- m_handler.checkContext();
- return;
+ if (containsSR(event.getServiceReference())) { departureManagement(event.getServiceReference()); }
+ return;
}
// If a service arrives
if (event.getType() == ServiceEvent.REGISTERED) {
- // Add the new service inside the ref list
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Add a service for a dependency");
- addReference(event.getServiceReference());
- if (isSatisfied()) {
- m_state = RESOLVED;
- if (m_metadata.isMultiple() || m_ref.length == 1) { m_change = true; }
- callBindMethod(event.getServiceReference());
+ if (m_filter.match(event.getServiceReference())) { arrivalManagement(event.getServiceReference()); return; }
+ else { return; }
+ }
+
+ // If a service is modified
+ if (event.getType() == ServiceEvent.MODIFIED) {
+ if (m_filter.match(event.getServiceReference())) {
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] A service with a filter matching is arrived -> " + event.getServiceReference().getBundle());
+ if (!containsSR(event.getServiceReference())) { arrivalManagement(event.getServiceReference()); }
}
- m_handler.checkContext();
+ else {
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] A service with a filter matching has gone -> " + event.getServiceReference().getBundle());
+ if (containsSR(event.getServiceReference())) { departureManagement(event.getServiceReference()); }
+ }
+ return;
}
}
}
- private void callUnbindMethod(ServiceReference ref) {
- if (m_handler.getComponentManager().getState() == ComponentManager.VALID && m_metadata.isMultiple()) {
- for (int i = 0; i < m_metadata.getCallbacks().length; i++) {
- if (m_metadata.getCallbacks()[i].getMethodType() == DependencyCallback.UNBIND) {
- // Try to call the bind method with a service reference inside
- try {
- m_metadata.getCallbacks()[i].call(new Object[] {ref});
- } catch (NoSuchMethodException e) {
- // The method was not found : try without service reference
- try {
- m_metadata.getCallbacks()[i].call();
- } catch (NoSuchMethodException e1) {
- // The method was not found : try with the service object
- try {
- m_metadata.getCallbacks()[i].call(new Object[] {m_handler.getComponentManager().getContext().getService(ref)});
- } catch (NoSuchMethodException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Unbind method not found : " + e1.getMessage());
- return;
- } catch (IllegalAccessException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on unbind method : " + e2.getMessage());
- return;
- } catch (InvocationTargetException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method " + e2.getMessage());
- return;
- }
- } catch (IllegalAccessException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on unbind method : " + e1.getMessage());
- return;
- } catch (InvocationTargetException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method " + e1.getMessage());
- return;
- }
+ /**
+ * Method called when a service arrives.
+ * @param ref : the arriving service reference
+ */
+ private void arrivalManagement(ServiceReference ref) {
+ // Add the new service inside the ref list
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Add a service for a dependency");
+ addReference(ref);
+ if (isSatisfied()) {
+ m_state = RESOLVED;
+ if (m_metadata.isMultiple() || m_ref.length == 1) { m_change = true; callBindMethod(ref); }
+ }
+ m_handler.checkContext();
+ }
- } catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
- return;
- } catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
- return;
- }
- }
- }
+ /**
+ * Method called when a service goes away.
+ * @param ref : the leaving service reference
+ */
+ private void departureManagement(ServiceReference ref) {
+ // Call unbind method
+ if (!m_metadata.isMultiple() && ref == m_ref[0]) { callUnbindMethod(ref); }
+ if (m_metadata.isMultiple()) { callUnbindMethod(ref); }
+
+ // Unget the service reference
+ m_handler.getComponentManager().getContext().ungetService(ref);
+ int index = removeReference(ref);
+
+ // Is the state valid or invalid
+ if (m_ref.length == 0 && !m_metadata.isOptional()) {
+ m_state = UNRESOLVED;
+ }
+ if (m_ref.length == 0 && m_metadata.isOptional()) {
+ m_state = RESOLVED;
+ }
+ // Is there any change ?
+ if (!m_metadata.isMultiple() && index == 0) {
+ m_change = true;
+ if (m_ref.length != 0) { callBindMethod(m_ref[0]); }
+ }
+ if (!m_metadata.isMultiple() && index != 0) { m_change = false; }
+ if (m_metadata.isMultiple()) { m_change = true; }
+
+ m_handler.checkContext();
+ return;
+ }
+
+ /**
+ * Call unbind callback method.
+ * @param ref : reference to send (if accepted) to the method
+ */
+ private void callUnbindMethod(ServiceReference ref) {
+ if (m_handler.getComponentManager().getState() == ComponentManagerImpl.VALID) {
+ for (int i = 0; i < m_metadata.getCallbacks().length; i++) {
+ if (m_metadata.getCallbacks()[i].getMethodType() == DependencyCallback.UNBIND) {
+ // Try to call the bind method with a service reference inside
+ try {
+ m_metadata.getCallbacks()[i].call(new Object[] {ref});
+ } catch (NoSuchMethodException e) {
+ // The method was not found : try without service reference
+ try {
+ m_metadata.getCallbacks()[i].call();
+ } catch (NoSuchMethodException e1) {
+ // The method was not found : try with the service object
+ try {
+ m_metadata.getCallbacks()[i].call(new Object[] {m_handler.getComponentManager().getContext().getService(ref)});
+ } catch (NoSuchMethodException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Unbind method not found : " + e1.getMessage());
+ return;
+ } catch (IllegalAccessException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on unbind method : " + e2.getMessage());
+ return;
+ } catch (InvocationTargetException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method " + e2.getMessage());
+ return;
+ }
+ } catch (IllegalAccessException e1) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on unbind method : " + e1.getMessage());
+ return;
+ } catch (InvocationTargetException e1) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the unbind method " + e1.getMessage());
+ return;
+ }
+
+ } catch (IllegalAccessException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
+ return;
+ } catch (InvocationTargetException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
+ return;
+ }
+ }
+ }
}
}
- private void callBindMethod(ServiceReference ref) {
- // call bind method :
- if (m_handler.getComponentManager().getState() == ComponentManager.VALID && m_metadata.isMultiple()) {
- for (int i = 0; i < m_metadata.getCallbacks().length; i++) {
- if (m_metadata.getCallbacks()[i].getMethodType() == DependencyCallback.BIND) {
- // Try to call the bind method with a service reference inside
- try {
- m_metadata.getCallbacks()[i].call(new Object[] {ref});
- } catch (NoSuchMethodException e) {
- // The method was not found : try without service reference
- try {
- m_metadata.getCallbacks()[i].call();
- } catch (NoSuchMethodException e1) {
- // The method was not found : try with the service object
- try {
- m_metadata.getCallbacks()[i].call(new Object[] {m_handler.getComponentManager().getContext().getService(ref)});
- } catch (NoSuchMethodException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Bind method not found : " + e1.getMessage());
- return;
- } catch (IllegalAccessException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e2.getMessage());
- return;
- } catch (InvocationTargetException e2) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e2.getMessage());
- return;
- }
- } catch (IllegalAccessException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e1.getMessage());
- return;
- } catch (InvocationTargetException e1) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e1.getMessage());
- return;
- }
+ /**
+ * Call the bind method.
+ * @param instance : instance on which calling the bind method.
+ */
+ protected void callBindMethod(Object instance) {
+ // Check optional case : nullable object case : do not call bind on nullable object
+ if (m_metadata.isOptional() && m_ref.length == 0) { return; }
- } catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
- return;
- } catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
- return;
- }
- }
- }
+
+ if (m_metadata.isMultiple()) {
+ for (int i = 0; i < m_ref.length; i++) {
+ for (int j = 0; j < m_metadata.getCallbacks().length; j++) {
+ if (m_metadata.getCallbacks()[j].getMethodType() == DependencyCallback.BIND) {
+ // Try to call the bind method with a service reference inside
+ try {
+ m_metadata.getCallbacks()[j].call(instance, new Object[] {m_ref[i]});
+ } catch (NoSuchMethodException e) {
+ // The method was not found : try without service reference
+ try {
+ m_metadata.getCallbacks()[j].call(instance);
+ } catch (NoSuchMethodException e1) {
+ // The method was not found : try with the service object
+ try {
+ m_metadata.getCallbacks()[j].call(instance, new Object[] {m_handler.getComponentManager().getContext().getService(m_ref[i])});
+ } catch (NoSuchMethodException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Bind method not found : " + e1.getMessage());
+ return;
+ } catch (IllegalAccessException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e2.getMessage());
+ return;
+ } catch (InvocationTargetException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e2.getMessage());
+ return;
+ }
+ } catch (IllegalAccessException e1) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e1.getMessage());
+ return;
+ } catch (InvocationTargetException e1) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e1.getMessage());
+ return;
+ }
+ } catch (IllegalAccessException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
+ return;
+ } catch (InvocationTargetException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
+ return;
+ }
+ }
+ }
+ }
+ } else {
+ for (int j = 0; j < m_metadata.getCallbacks().length; j++) {
+ if (m_metadata.getCallbacks()[j].getMethodType() == DependencyCallback.BIND) {
+ // Try to call the bind method with a service reference inside
+ try {
+ m_metadata.getCallbacks()[j].call(instance, new Object[] {m_ref[0]});
+ } catch (NoSuchMethodException e) {
+ // The method was not found : try without service reference
+ try {
+ Activator.getLogger().log(Level.WARNING, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Call the Bind method");
+ m_metadata.getCallbacks()[j].call(instance);
+ } catch (NoSuchMethodException e1) {
+ // The method was not found : try with the service object
+ try {
+ m_metadata.getCallbacks()[j].call(new Object[] {m_handler.getComponentManager().getContext().getService(m_ref[0])});
+ } catch (NoSuchMethodException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Bind method not found : " + e1.getMessage());
+ return;
+ } catch (IllegalAccessException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e2.getMessage());
+ return;
+ } catch (InvocationTargetException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e2.getMessage());
+ return;
+ }
+ } catch (IllegalAccessException e1) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e1.getMessage());
+ return;
+ } catch (InvocationTargetException e1) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e1.getMessage());
+ return;
+ }
+
+ } catch (IllegalAccessException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
+ return;
+ } catch (InvocationTargetException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Call bind method with the service reference in parameter (if accepted).
+ * @param ref : the service reference of the new service
+ */
+ private void callBindMethod(ServiceReference ref) {
+ // call bind method :
+ if (m_handler.getComponentManager().getState() == ComponentManagerImpl.VALID) {
+ for (int i = 0; i < m_metadata.getCallbacks().length; i++) {
+ if (m_metadata.getCallbacks()[i].getMethodType() == DependencyCallback.BIND) {
+ // Try to call the bind method with a service reference inside
+ try {
+ m_metadata.getCallbacks()[i].call(new Object[] {ref});
+ } catch (NoSuchMethodException e) {
+ // The method was not found : try without service reference
+ try {
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Call the Bind method");
+ m_metadata.getCallbacks()[i].call();
+ } catch (NoSuchMethodException e1) {
+ // The method was not found : try with the service object
+ try {
+ m_metadata.getCallbacks()[i].call(new Object[] {m_handler.getComponentManager().getContext().getService(ref)});
+ } catch (NoSuchMethodException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Bind method not found : " + e1.getMessage());
+ return;
+ } catch (IllegalAccessException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e2.getMessage());
+ return;
+ } catch (InvocationTargetException e2) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e2.getMessage());
+ return;
+ }
+ } catch (IllegalAccessException e1) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e1.getMessage());
+ return;
+ } catch (InvocationTargetException e1) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e1.getMessage());
+ return;
+ }
+
+ } catch (IllegalAccessException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Illegal access on bind method : " + e.getMessage());
+ return;
+ } catch (InvocationTargetException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Dependency Callback Error : Invocation Target Exception in the bind method " + e.getMessage());
+ return;
+ }
+ }
+ }
}
}
@@ -372,13 +519,16 @@
try {
// Look if the service is already present :
ServiceReference[] sr = m_handler.getComponentManager().getContext().getServiceReferences(
- m_metadata.getServiceSpecification(), filter);
+ m_metadata.getServiceSpecification(), filter);
if (sr != null) {
for (int i = 0; i < sr.length; i++) { addReference(sr[i]); }
m_state = RESOLVED;
- }
+ }
// Register a listener :
- m_handler.getComponentManager().getContext().addServiceListener(this, filter);
+ //m_handler.getComponentManager().getContext().addServiceListener(this, filter); // Try without filter
+ m_handler.getComponentManager().getContext().addServiceListener(this);
+ m_filter = m_handler.getComponentManager().getContext().createFilter(filter); // Store the filter
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Create a filter from : " + filter);
m_change = true;
}
catch (InvalidSyntaxException e1) {
@@ -396,7 +546,7 @@
// Unget all services references
for (int i = 0; i < m_ref.length; i++) {
- m_handler.getComponentManager().getContext().ungetService(m_ref[i]);
+ m_handler.getComponentManager().getContext().ungetService(m_ref[i]);
}
m_ref = new ServiceReference[0];
@@ -410,7 +560,8 @@
* @return the state of the dependency (1 : valid, 2 : invalid)
*/
public int getState() {
- return m_state;
+ if (m_metadata.isOptional()) { return 1; }
+ else { return m_state; }
}
/**
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
index 604d20f..ebd35f4 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.dependency;
@@ -27,20 +29,20 @@
*/
public class DependencyCallback {
- /**
- * Bind method (called when a service arrives).
- */
- public static final int BIND = 0;
+ /**
+ * Bind method (called when a service arrives).
+ */
+ public static final int BIND = 0;
- /**
- * Unbind method (called when a service disappears).
- */
- public static final int UNBIND = 1;
+ /**
+ * Unbind method (called when a service disappears).
+ */
+ public static final int UNBIND = 1;
- /**
- * Is the method a bind method or an unbind method ?
- */
- private int m_methodType;
+ /**
+ * Is the method a bind method or an unbind method ?
+ */
+ private int m_methodType;
/**
* Callback object.
@@ -56,7 +58,7 @@
* @param isStatic : is the method to call static ?
*/
public DependencyCallback(Dependency dep, String method, int methodType, boolean isStatic) {
- m_methodType = methodType;
+ m_methodType = methodType;
m_callback = new Callback(method, isStatic, dep.getDependencyHandler().getComponentManager());
}
@@ -72,7 +74,7 @@
* @throws IllegalAccessException : The method can not be invoked
*/
protected void call() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- m_callback.call();
+ m_callback.call();
}
/**
@@ -82,6 +84,28 @@
* @throws IllegalAccessException : The method can not be invoked
*/
protected void call(Object[] arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- m_callback.call(arg);
+ m_callback.call(arg);
+ }
+
+ /**
+ * Call the callback on the given instance.
+ * @param instance : the instance on which call the callback
+ * @throws NoSuchMethodException : the method is not found
+ * @throws IllegalAccessException : the method could not be called
+ * @throws InvocationTargetException : an error happens in the called method
+ */
+ protected void call(Object instance) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { m_callback.call(instance); }
+
+ /**
+ * Call the callback on the given instance with the given argument.
+ * @param instance : the instance on which call the callback
+ * @param arg : the argument of the callback
+ * @throws NoSuchMethodException : the method is not found
+ * @throws IllegalAccessException : the method could not be called
+ * @throws InvocationTargetException : an error happens in the called method
+ * @throws InvocationTargetException
+ */
+ protected void call(Object instance, Object[] arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ m_callback.call(instance, arg);
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
index ee39ead..3bedc45 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
@@ -1,28 +1,31 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.dependency;
import java.io.IOException;
import java.net.URL;
+import java.util.Dictionary;
import java.util.logging.Level;
-import org.apache.felix.ipojo.ComponentManager;
-import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.Activator;
+import org.apache.felix.ipojo.ComponentManagerImpl;
+import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.handlers.dependency.nullable.NullableObjectWriter;
import org.apache.felix.ipojo.metadata.Element;
@@ -30,36 +33,40 @@
* The dependency handler manages a list of dependencies.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class DependencyHandler implements Handler {
+public class DependencyHandler extends Handler {
- /**
- * The component manager using this handler.
- */
- private ComponentManager m_componentManager;
+ /**
+ * The component manager using this handler.
+ */
+ private ComponentManagerImpl m_componentManager;
- /**
- * List of depednencies of the component.
- */
- private Dependency[] m_dependencies = new Dependency[0];
+ /**
+ * List of depednencies of the component.
+ */
+ private Dependency[] m_dependencies = new Dependency[0];
- /**
- * List of nullable class for optional dependencies.
- */
- private Class[] m_nullableClasses = new Class[0];
+ /**
+ * List of nullable class for optional dependencies.
+ */
+ private Class[] m_nullableClasses = new Class[0];
- /**
- * Classloader to use to load nullable classes.
- */
- private NullableClassloader m_classloader;
+ /**
+ * Classloader to use to load nullable classes.
+ */
+ private NullableClassloader m_classloader;
- /**
- * State of the handler.
- */
- private int m_state;
+ /**
+ * State of the handler.
+ */
+ private int m_state;
-// ===================== Fields getters & setters =====================
+// ===================== Fields getters & setters =====================
- private void addDependency(Dependency dep) {
+ /**
+ * Add a dependency.
+ * @param dep : the dependency to add
+ */
+ private void addDependency(Dependency dep) {
for (int i = 0; (m_dependencies != null) && (i < m_dependencies.length); i++) {
if (m_dependencies[i] == dep) {
return;
@@ -72,12 +79,16 @@
m_dependencies = newDep;
}
else {
- m_dependencies = new Dependency[] {dep};
+ m_dependencies = new Dependency[] {dep};
}
- }
+ }
- private void addNullableClass(Class clazz) {
- for (int i = 0; (m_nullableClasses != null) && (i < m_nullableClasses.length); i++) {
+ /**
+ * Add a nullable class.
+ * @param clazz : the class to add
+ */
+ private void addNullableClass(Class clazz) {
+ for (int i = 0; (m_nullableClasses != null) && (i < m_nullableClasses.length); i++) {
if (m_nullableClasses[i] == clazz) {
return;
}
@@ -89,263 +100,275 @@
m_nullableClasses = newClass;
}
else {
- m_nullableClasses = new Class[] {clazz};
+ m_nullableClasses = new Class[] {clazz};
}
- }
+ }
- /**
- * @return the dependency list
- */
- public Dependency[] getDependencies() { return m_dependencies; }
+ /**
+ * @return the dependency list
+ */
+ public Dependency[] getDependencies() { return m_dependencies; }
- /**
- * @return the component manager
- */
- protected ComponentManager getComponentManager() { return m_componentManager; }
+ /**
+ * @return the component manager
+ */
+ protected ComponentManagerImpl getComponentManager() { return m_componentManager; }
-// ===================== Handler implementation =====================
+// ===================== Handler implementation =====================
- /**
- * Check the validity of the dependencies.
- */
- protected void checkContext() {
+ /**
+ * Check the validity of the dependencies.
+ */
+ protected void checkContext() {
- synchronized (this) {
+ synchronized (this) {
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Check Context ...");
+ Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Check Context ...");
- // Store the initial state
- int initialState = m_state;
+ // Store the initial state
+ int initialState = m_state;
- // Check the component dependencies
- if (!validateComponentDependencies()) {
- // The dependencies are not valid
- if (initialState == ComponentManager.VALID) {
- //There is a state change
- m_state = ComponentManager.INVALID;
- m_componentManager.check();
- }
- // Else do nothing, the component state stay UNRESOLVED
- }
- else {
- // The dependencies are valid
- if (initialState == ComponentManager.INVALID) {
- //There is a state change
- m_state = ComponentManager.VALID;
- m_componentManager.check();
- }
- // Else do nothing, the component state stay VALID
- }
-
- }
- }
-
- private boolean checkDependency(Dependency dep) {
- // Check the internal type of dependency
- String field = dep.getMetadata().getField();
-
- Element manipulation = m_componentManager.getComponentMetatada().getMetadata().getElements("Manipulation")[0];
- String type = null;
- for (int i = 0; i < manipulation.getElements("Field").length; i++) {
- if (field.equals(manipulation.getElements("Field")[i].getAttribute("name"))) {
- type = manipulation.getElements("Field")[i].getAttribute("type");
- break;
- }
- }
-
- if (type == null) {
- Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] A declared dependency was not found in the class : " + dep.getMetadata().getField());
- return false;
- }
-
- if (type != null) {
- if (type.endsWith("[]")) {
- // Set the dependency to multiple
- dep.getMetadata().setMultiple();
- type = type.substring(0, type.length() - 2);
- }
-
- if (dep.getMetadata().getServiceSpecification() == null) { dep.getMetadata().setServiceSpecification(type); }
-
- if (!dep.getMetadata().getServiceSpecification().equals(type)) {
- Activator.getLogger().log(Level.WARNING, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] The field type [" + type + "] and the needed service interface [" + dep.getMetadata().getServiceSpecification() + "] are not the same");
- dep.getMetadata().setServiceSpecification(type);
+ // Check the component dependencies
+ if (!validateComponentDependencies()) {
+ // The dependencies are not valid
+ if (initialState == ComponentManagerImpl.VALID) {
+ //There is a state change
+ m_state = ComponentManagerImpl.INVALID;
+ m_componentManager.checkComponentState();
}
+ // Else do nothing, the component state stay UNRESOLVED
}
else {
- Activator.getLogger().log(Level.WARNING, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] The declared dependency " + dep.getMetadata().getField() + " does not exist in the code");
+ // The dependencies are valid
+ if (initialState == ComponentManagerImpl.INVALID) {
+ //There is a state change
+ m_state = ComponentManagerImpl.VALID;
+ m_componentManager.checkComponentState();
+ }
+ // Else do nothing, the component state stay VALID
}
- return true;
- }
+
+ }
+ }
+
+ /**
+ * Check if the dependency given is valid in the sense that metadata are consistent.
+ * @param dep : the dependency to check
+ * @return true if the dependency is valid
+ */
+ private boolean checkDependency(Dependency dep) {
+ // Check the internal type of dependency
+ String field = dep.getMetadata().getField();
+
+ Element manipulation = m_componentManager.getComponentMetatada().getMetadata().getElements("Manipulation")[0];
+ String type = null;
+ for (int i = 0; i < manipulation.getElements("Field").length; i++) {
+ if (field.equals(manipulation.getElements("Field")[i].getAttribute("name"))) {
+ type = manipulation.getElements("Field")[i].getAttribute("type");
+ break;
+ }
+ }
+
+ if (type == null) {
+ Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] A declared dependency was not found in the class : " + dep.getMetadata().getField());
+ return false;
+ }
+
+ if (type != null) {
+ if (type.endsWith("[]")) {
+ // Set the dependency to multiple
+ dep.getMetadata().setMultiple();
+ type = type.substring(0, type.length() - 2);
+ }
+
+ if (dep.getMetadata().getServiceSpecification() == null) { dep.getMetadata().setServiceSpecification(type); }
+
+ if (!dep.getMetadata().getServiceSpecification().equals(type)) {
+ Activator.getLogger().log(Level.WARNING, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] The field type [" + type + "] and the needed service interface [" + dep.getMetadata().getServiceSpecification() + "] are not the same");
+ dep.getMetadata().setServiceSpecification(type);
+ }
+ }
+ else {
+ Activator.getLogger().log(Level.WARNING, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] The declared dependency " + dep.getMetadata().getField() + " does not exist in the code");
+ }
+ return true;
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManager, org.apache.felix.ipojo.metadata.Element)
- */
- public void configure(ComponentManager cm, Element componentMetadata) {
- // Fix the component manager
- m_componentManager = cm;
- m_dependencies = new Dependency[0];
- m_nullableClasses = new Class[0];
+ /**
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ */
+ public void configure(ComponentManagerImpl cm, Element componentMetadata, Dictionary configuration) {
+ // Fix the component manager
+ m_componentManager = cm;
+ m_dependencies = new Dependency[0];
+ m_nullableClasses = new Class[0];
- // Create the dependency according to the component metadata
- Element[] deps = componentMetadata.getElements("Dependency");
- for (int i = 0; i < deps.length; i++) {
- // Create the dependency metadata
- String field = deps[i].getAttribute("field");
- String serviceSpecification = null;
- if (deps[i].containsAttribute("interface")) { serviceSpecification = deps[i].getAttribute("interface"); }
- String filter = "";
- if (deps[i].containsAttribute("filter")) { filter = deps[i].getAttribute("filter"); }
- boolean optional = false;
- if (deps[i].containsAttribute("optional") && deps[i].getAttribute("optional").equals("true")) { optional = true; }
- DependencyMetadata dm = new DependencyMetadata(field, serviceSpecification, filter, optional);
+ // Create the dependency according to the component metadata
+ Element[] deps = componentMetadata.getElements("Dependency");
+ for (int i = 0; i < deps.length; i++) {
+ // Create the dependency metadata
+ String field = deps[i].getAttribute("field");
+ String serviceSpecification = null;
+ if (deps[i].containsAttribute("interface")) { serviceSpecification = deps[i].getAttribute("interface"); }
+ String filter = "";
+ if (deps[i].containsAttribute("filter")) { filter = deps[i].getAttribute("filter"); }
+ boolean optional = false;
+ if (deps[i].containsAttribute("optional") && deps[i].getAttribute("optional").equals("true")) { optional = true; }
+ DependencyMetadata dm = new DependencyMetadata(field, serviceSpecification, filter, optional);
- Dependency dep = new Dependency(this, dm);
- // Check the dependency :
- if (checkDependency(dep)) { addDependency(dep); }
- else { Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] The dependency on " + dep.getMetadata().getField() + " is not valid"); }
+ Dependency dep = new Dependency(this, dm);
+ // Check the dependency :
+ if (checkDependency(dep)) { addDependency(dep); }
+ else { Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] The dependency on " + dep.getMetadata().getField() + " is not valid"); }
- // Look for dependency callback :
- for (int j = 0; j < (deps[i].getElements("Callback", "")).length; j++) {
- String method = deps[i].getElements("Callback", "")[j].getAttribute("method");
- String type = deps[i].getElements("Callback", "")[j].getAttribute("type");
- int methodType = 0;
- if (type.equals("bind")) { methodType = DependencyCallback.BIND; }
- else { methodType = DependencyCallback.UNBIND; }
- boolean isStatic = false;
- if (deps[i].getElements("Callback", "")[j].containsAttribute("isStatic") && deps[i].getElements("Callback", "")[j].getAttribute("isStatic").equals("true")) { isStatic = true; }
- DependencyCallback dc = new DependencyCallback(dep, method, methodType, isStatic);
- dep.getMetadata().addDependencyCallback(dc);
- }
- }
+ // Look for dependency callback :
+ for (int j = 0; j < (deps[i].getElements("Callback", "")).length; j++) {
+ String method = deps[i].getElements("Callback", "")[j].getAttribute("method");
+ String type = deps[i].getElements("Callback", "")[j].getAttribute("type");
+ int methodType = 0;
+ if (type.equals("bind")) { methodType = DependencyCallback.BIND; }
+ else { methodType = DependencyCallback.UNBIND; }
+ boolean isStatic = false;
+ if (deps[i].getElements("Callback", "")[j].containsAttribute("isStatic") && deps[i].getElements("Callback", "")[j].getAttribute("isStatic").equals("true")) { isStatic = true; }
+ DependencyCallback dc = new DependencyCallback(dep, method, methodType, isStatic);
+ dep.getMetadata().addDependencyCallback(dc);
+ }
+ }
- if (deps.length > 0) {
- m_componentManager.register(this);
+ if (deps.length > 0) {
+ String[] fields = new String[m_dependencies.length];
+ for (int k = 0; k < m_dependencies.length; k++) {
+ fields[k] = m_dependencies[k].getMetadata().getField();
+ }
+ m_componentManager.register(this, fields);
- // Create the nullable classloader
- m_classloader = new NullableClassloader(m_componentManager.getContext().getBundle());
+ // Create the nullable classloader
+ m_classloader = new NullableClassloader(m_componentManager.getContext().getBundle());
- }
- }
+ }
+ }
- private void createNullableClass(Dependency dep) {
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Try to load the nullable class for " + dep.getMetadata().getServiceSpecification());
- // Try to load the nullable object :
+ /**
+ * Create a nullable class for the given dependency.
+ * @param dep : the dependency
+ */
+ private void createNullableClass(Dependency dep) {
+ Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Try to load the nullable class for " + dep.getMetadata().getServiceSpecification());
+ // Try to load the nullable object :
String[] segment = dep.getMetadata().getServiceSpecification().split("[.]");
String className = "org/apache/felix/ipojo/" + segment[segment.length - 1] + "Nullable";
String resource = dep.getMetadata().getServiceSpecification().replace('.', '/') + ".class";
URL url = m_componentManager.getContext().getBundle().getResource(resource);
- try {
- byte[] b = NullableObjectWriter.dump(url, dep.getMetadata().getServiceSpecification());
+ try {
+ byte[] b = NullableObjectWriter.dump(url, dep.getMetadata().getServiceSpecification());
-// // DEBUG :
-// try {
-// File file = new File("P:\\workspace\\iPOJO\\adapted\\" + className.replace('/', '.') + ".class");
-// file.createNewFile();
-// FileOutputStream fos = new FileOutputStream(file);
-// fos.write(b);
-// fos.close();
-// } catch (Exception e3) {
-// System.err.println("Problem to write the adapted class on the file system : " + e3.getMessage());
-//
-// }
+// // DEBUG :
+// try {
+// File file = new File("P:\\workspace\\iPOJO\\adapted\\" + className.replace('/', '.') + ".class");
+// file.createNewFile();
+// FileOutputStream fos = new FileOutputStream(file);
+// fos.write(b);
+// fos.close();
+// } catch (Exception e3) {
+// System.err.println("Problem to write the adapted class on the file system : " + e3.getMessage());
- addNullableClass(m_classloader.defineClass(className.replace('/', '.'), b, null));
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Nullable class created for " + dep.getMetadata().getServiceSpecification());
+// }
- } catch (IOException e1) {
- Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Cannot open a stream of an interface to generate the nullable class for " + dep.getMetadata().getServiceSpecification() + " -> " + e1.getMessage());
- } catch (Exception e2) {
- Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Cannot load the nullable class for " + dep.getMetadata().getServiceSpecification() + " -> " + e2.getMessage());
- }
- }
+ addNullableClass(m_classloader.defineClass(className.replace('/', '.'), b, null));
+ Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Nullable class created for " + dep.getMetadata().getServiceSpecification());
- /**
+ } catch (IOException e1) {
+ Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Cannot open a stream of an interface to generate the nullable class for " + dep.getMetadata().getServiceSpecification() + " -> " + e1.getMessage());
+ } catch (Exception e2) {
+ Activator.getLogger().log(Level.SEVERE, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Cannot load the nullable class for " + dep.getMetadata().getServiceSpecification() + " -> " + e2.getMessage());
+ }
+ }
+
+ /**
* Return the nullable class corresponding to the given name.
- * @param name the needed type
- * @return the class correspondig to the name, or null if the class does not exist.
- */
- protected Class getNullableClass(String name) {
- for (int i = 0; i < m_nullableClasses.length; i++) {
- Class c = m_nullableClasses[i];
- if (c.getName().equals(name)) {
- return c;
- }
- }
- return null;
- }
+ * @param name the needed type
+ * @return the class correspondig to the name, or null if the class does not exist.
+ */
+ protected Class getNullableClass(String name) {
+ for (int i = 0; i < m_nullableClasses.length; i++) {
+ Class c = m_nullableClasses[i];
+ if (c.getName().equals(name)) {
+ return c;
+ }
+ }
+ return null;
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
- */
- public Object getterCallback(String fieldName, Object value) {
- for (int i = 0; i < m_dependencies.length; i++) {
- Dependency dep = m_dependencies[i];
- if (dep.getMetadata().getField().equals(fieldName)) {
- // The field name is a dependency, return the get
- return dep.get();
- }
- }
- // Else return the value
- return value;
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
+ */
+ public Object getterCallback(String fieldName, Object value) {
+ //TODO : non performant
+ for (int i = 0; i < m_dependencies.length; i++) {
+ Dependency dep = m_dependencies[i];
+ if (dep.getMetadata().getField().equals(fieldName)) {
+ // The field name is a dependency, return the get
+ return dep.get();
+ }
+ }
+ // Else return the value
+ return value;
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#isValid()
- */
- public boolean isValid() {
- return (m_state == ComponentManager.VALID);
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#isValid()
+ */
+ public boolean isValid() {
+ return (m_state == ComponentManagerImpl.VALID);
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
- */
- public void setterCallback(String fieldName, Object value) {
- // Do nothing
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#start()
+ */
+ public void start() {
+ Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Start the dependency handler");
- /**
- * @see org.apache.felix.ipojo.Handler#start()
- */
- public void start() {
- Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Start the dependency handler");
+ // Start the dependencies, for optional dependencies create Nullable class
+ for (int i = 0; i < m_dependencies.length; i++) {
+ Dependency dep = m_dependencies[i];
+ if (dep.getMetadata().isOptional() && !dep.getMetadata().isMultiple()) { createNullableClass(dep); }
+ dep.start();
+ }
+ // Check the state
+ m_state = m_componentManager.getState();
+ checkContext();
+ }
- // Start the dependencies, for optional dependencies create Nullable class
- for (int i = 0; i < m_dependencies.length; i++) {
- Dependency dep = m_dependencies[i];
- if (dep.getMetadata().isOptional() && !dep.getMetadata().isMultiple()) { createNullableClass(dep); }
- dep.start();
- }
- // Check the state
- m_state = m_componentManager.getState();
- checkContext();
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+ */
+ public void stateChanged(int state) { m_state = state; }
- /**
- * @see org.apache.felix.ipojo.Handler#stateChanged(int)
- */
- public void stateChanged(int state) {
- // Another handler or the component manager itself change the state
- if (m_state == ComponentManager.VALID && state == ComponentManager.INVALID) {
- // The component is stopped => Stop the dependency tracking
- stop();
- }
- m_state = state;
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#stop()
+ */
+ public void stop() {
+ for (int i = 0; i < m_dependencies.length; i++) { m_dependencies[i].stop(); }
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#stop()
- */
- public void stop() {
- for (int i = 0; i < m_dependencies.length; i++) { m_dependencies[i].stop(); }
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#createInstance(java.lang.Object)
+ */
+ public void createInstance(Object instance) {
+ for (int i = 0; i < m_dependencies.length; i++) {
+ m_dependencies[i].callBindMethod(instance);
+ }
+ }
- private boolean validateComponentDependencies() {
- boolean valide = true;
+ /**
+ * @return true if all dependencies are resolved.
+ */
+ private boolean validateComponentDependencies() {
+ boolean valide = true;
for (int i = 0; i < m_dependencies.length; i++) {
Dependency dep = m_dependencies[i];
valide = valide & dep.isSatisfied();
@@ -356,6 +379,6 @@
}
Activator.getLogger().log(Level.INFO, "[DependencyHandler on " + m_componentManager.getComponentMetatada().getClassName() + "] Component Dependencies are valid");
return valide;
- }
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyMetadata.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyMetadata.java
index e4ca5eb..1626ad7 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyMetadata.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyMetadata.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.dependency;
@@ -22,127 +24,127 @@
*/
public class DependencyMetadata {
- /**
- * Service Specification <=> Service contract (or interface in OSGi).
- */
- private String m_serviceSpecification;
+ /**
+ * Service Specification <=> Service contract (or interface in OSGi).
+ */
+ private String m_serviceSpecification;
- /**
- * LDAP filter.
- */
- private String m_filter;
+ /**
+ * LDAP filter.
+ */
+ private String m_filter;
- /**
- * is the dependency optional ?
- */
- private boolean m_isOptional;
+ /**
+ * is the dependency optional ?
+ */
+ private boolean m_isOptional;
- /**
- * is the dependency multiple ?
- */
- private boolean m_isMultiple = false;
+ /**
+ * is the dependency multiple ?
+ */
+ private boolean m_isMultiple = false;
- /**
- * List of dependency callbacks attached to this dependency.
- */
- private DependencyCallback[] m_callbacks = new DependencyCallback[0];
+ /**
+ * List of dependency callbacks attached to this dependency.
+ */
+ private DependencyCallback[] m_callbacks = new DependencyCallback[0];
- /**
- * The field linking the metadata and the component implementation.
- */
- private String m_field;
+ /**
+ * The field linking the metadata and the component implementation.
+ */
+ private String m_field;
- // Constructor
+ // Constructor
- /**
+ /**
* Constructor.
- * @param field : the field name
- * @param service : the interface name.
- * @param filter : the filter of the dependency
- * @param isOptional : is the dependency optional
- */
- public DependencyMetadata(String field, String service, String filter, boolean isOptional) {
- m_field = field;
- m_serviceSpecification = service;
- m_isOptional = isOptional;
- m_filter = filter;
- }
+ * @param field : the field name
+ * @param service : the interface name.
+ * @param filter : the filter of the dependency
+ * @param isOptional : is the dependency optional
+ */
+ public DependencyMetadata(String field, String service, String filter, boolean isOptional) {
+ m_field = field;
+ m_serviceSpecification = service;
+ m_isOptional = isOptional;
+ m_filter = filter;
+ }
- /**
- * Add a callback to the dependency.
- * @param cb : callback to add
- */
- public void addDependencyCallback(DependencyCallback cb) {
- for (int i = 0; (m_callbacks != null) && (i < m_callbacks.length); i++) {
- if (m_callbacks[i] == cb) { return; }
- }
+ /**
+ * Add a callback to the dependency.
+ * @param cb : callback to add
+ */
+ public void addDependencyCallback(DependencyCallback cb) {
+ for (int i = 0; (m_callbacks != null) && (i < m_callbacks.length); i++) {
+ if (m_callbacks[i] == cb) { return; }
+ }
- if (m_callbacks.length > 0) {
- DependencyCallback[] newCallbacks = new DependencyCallback[m_callbacks.length + 1];
- System.arraycopy(m_callbacks, 0, newCallbacks, 0, m_callbacks.length);
- newCallbacks[m_callbacks.length] = cb;
- m_callbacks = newCallbacks;
- }
- else {
- m_callbacks = new DependencyCallback[] {cb};
- }
- }
+ if (m_callbacks.length > 0) {
+ DependencyCallback[] newCallbacks = new DependencyCallback[m_callbacks.length + 1];
+ System.arraycopy(m_callbacks, 0, newCallbacks, 0, m_callbacks.length);
+ newCallbacks[m_callbacks.length] = cb;
+ m_callbacks = newCallbacks;
+ }
+ else {
+ m_callbacks = new DependencyCallback[] {cb};
+ }
+ }
- // Getter
+ // Getter
- /**
- * @return Returns the m_field.
- */
- public String getField() {
- return m_field;
- }
+ /**
+ * @return Returns the m_field.
+ */
+ public String getField() {
+ return m_field;
+ }
- /**
- * @return Returns the m_filter.
- */
- public String getFilter() {
- return m_filter;
- }
+ /**
+ * @return Returns the m_filter.
+ */
+ public String getFilter() {
+ return m_filter;
+ }
- /**
- * @return Returns the m_isMultiple.
- */
- public boolean isMultiple() {
- return m_isMultiple;
- }
+ /**
+ * @return Returns the m_isMultiple.
+ */
+ public boolean isMultiple() {
+ return m_isMultiple;
+ }
- /**
- * @return Returns the m_isOptional.
- */
- public boolean isOptional() {
- return m_isOptional;
- }
+ /**
+ * @return Returns the m_isOptional.
+ */
+ public boolean isOptional() {
+ return m_isOptional;
+ }
- /**
- * @return Returns the m_serviceSpecification.
- */
- public String getServiceSpecification() {
- return m_serviceSpecification;
- }
+ /**
+ * @return Returns the m_serviceSpecification.
+ */
+ public String getServiceSpecification() {
+ return m_serviceSpecification;
+ }
- /**
- * return true if the dependency is multiple.
- */
- public void setMultiple() {
- m_isMultiple = true;
- }
+ /**
+ * return true if the dependency is multiple.
+ */
+ public void setMultiple() {
+ m_isMultiple = true;
+ }
- /**
+ /**
* Set the service specification.
- * @param serviceSpecification : the dependency service specification
- */
- public void setServiceSpecification(String serviceSpecification) {
- m_serviceSpecification = serviceSpecification;
- }
+ * @param serviceSpecification : the dependency service specification
+ */
+ public void setServiceSpecification(String serviceSpecification) {
+ m_serviceSpecification = serviceSpecification;
+ }
- /**
- * @return the list of the callbacks
- */
- public DependencyCallback[] getCallbacks() { return m_callbacks; }
+ /**
+ * @return the list of the callbacks
+ */
+ public DependencyCallback[] getCallbacks() { return m_callbacks; }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/NullableClassloader.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/NullableClassloader.java
index 49940de..104c26d 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/NullableClassloader.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/NullableClassloader.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.dependency;
@@ -30,7 +32,7 @@
*/
public class NullableClassloader extends ClassLoader {
- /**
+ /**
* The owner bundle.
* m_bundle : Bundle
*/
@@ -95,8 +97,8 @@
*/
public Class defineClass(String name, byte[] b,
ProtectionDomain domain) throws Exception {
- Class clazz = super.defineClass(name, b, 0, b.length, domain);
- return clazz;
+ Class clazz = super.defineClass(name, b, 0, b.length, domain);
+ return clazz;
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java
index e20ea49..93d1530 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignature.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.dependency.nullable;
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java
index 7c0cb47..ea17c7b 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/MethodSignatureVisitor.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.dependency.nullable;
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java
index 7a035ea..9665692 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/dependency/nullable/NullableObjectWriter.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.dependency.nullable;
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
index c6b18e9..d023558 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.lifecycle.callback;
@@ -60,7 +62,7 @@
* @throws IllegalAccessException : The method can not be invoked
*/
protected void call() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- m_callback.call();
+ m_callback.call();
}
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
index 4b99cf8..f04c2b2 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
@@ -1,51 +1,54 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.lifecycle.callback;
import java.lang.reflect.InvocationTargetException;
+import java.util.Dictionary;
import java.util.logging.Level;
-import org.apache.felix.ipojo.ComponentManager;
-import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.Activator;
+import org.apache.felix.ipojo.ComponentManagerImpl;
+import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.metadata.Element;
/**
* Lifecycle callback handler.
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class LifecycleCallbackHandler implements Handler {
+public class LifecycleCallbackHandler extends Handler {
- /**
- * The list of the callback of the component.
- */
- private LifecycleCallback[] m_callbacks = new LifecycleCallback[0];
+ /**
+ * The list of the callback of the component.
+ */
+ private LifecycleCallback[] m_callbacks = new LifecycleCallback[0];
- /**
- * State of the component manager (unresolved at the beginning).
- */
- private int m_state = ComponentManager.INVALID;
+ /**
+ * State of the component manager (unresolved at the beginning).
+ */
+ private int m_state = ComponentManagerImpl.INVALID;
- /**
- * The component manager.
- */
- private ComponentManager m_componentManager;
+ /**
+ * The component manager.
+ */
+ private ComponentManagerImpl m_componentManager;
- /**
+ /**
* Add the given Hook to the hook list.
* @param hk : the element to add
*/
@@ -61,100 +64,74 @@
m_callbacks = newHk;
}
else {
- m_callbacks = new LifecycleCallback[] {hk};
+ m_callbacks = new LifecycleCallback[] {hk};
}
}
- /**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManager, org.apache.felix.ipojo.metadata.Element)
- */
- public void configure(ComponentManager cm, Element metadata) {
- m_componentManager = cm;
- m_callbacks = new LifecycleCallback[0];
+ /**
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ */
+ public void configure(ComponentManagerImpl cm, Element metadata, Dictionary configuration) {
+ m_componentManager = cm;
+ m_callbacks = new LifecycleCallback[0];
- Element[] hooksMetadata = metadata.getElements("callback");
- for (int i = 0; i < hooksMetadata.length; i++) {
- // Create an HookMetadata object
- String initialState = hooksMetadata[i].getAttribute("initial");
- String finalState = hooksMetadata[i].getAttribute("final");
- String method = hooksMetadata[i].getAttribute("method");
- boolean isStatic = false;
- if (hooksMetadata[i].containsAttribute("isStatic") && hooksMetadata[i].getAttribute("isStatic").equals("true")) { isStatic = true; }
+ Element[] hooksMetadata = metadata.getElements("callback");
+ for (int i = 0; i < hooksMetadata.length; i++) {
+ // Create an HookMetadata object
+ String initialState = hooksMetadata[i].getAttribute("initial");
+ String finalState = hooksMetadata[i].getAttribute("final");
+ String method = hooksMetadata[i].getAttribute("method");
+ boolean isStatic = false;
+ if (hooksMetadata[i].containsAttribute("isStatic") && hooksMetadata[i].getAttribute("isStatic").equals("true")) { isStatic = true; }
- LifecycleCallbackMetadata hm = new LifecycleCallbackMetadata(initialState, finalState, method, isStatic);
+ LifecycleCallbackMetadata hm = new LifecycleCallbackMetadata(initialState, finalState, method, isStatic);
- LifecycleCallback hk = new LifecycleCallback(this, hm);
- addCallback(hk);
- }
- if (m_callbacks.length > 0) { m_componentManager.register(this); }
- }
+ LifecycleCallback hk = new LifecycleCallback(this, hm);
+ addCallback(hk);
+ }
+ if (m_callbacks.length > 0) { m_componentManager.register(this); }
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#stop()
- */
- public void stop() {
- m_state = ComponentManager.INVALID;
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#start()
+ */
+ public void start() { } //Do nothing during the start
- /**
- * @see org.apache.felix.ipojo.Handler#start()
- */
- public void start() {
- Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] Start the life cycle callback handler");
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#stop()
+ */
+ public void stop() {
+ m_state = ComponentManagerImpl.INVALID;
+ }
- /**
- * Do nothing.
- * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
- */
- public void setterCallback(String fieldName, Object value) {
- // Do nothing
- }
+ /**
+ * @return the component manager
+ */
+ protected ComponentManagerImpl getComponentManager() { return m_componentManager; }
- /**
- * Do nothing, return the initial value.
- * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
- */
- public Object getterCallback(String fieldName, Object value) {
- return value;
- }
-
- /**
- * Return true.
- * @see org.apache.felix.ipojo.Handler#isValid()
- */
- public boolean isValid() {
- return true;
- }
-
- /**
- * @return the component manager
- */
- protected ComponentManager getComponentManager() { return m_componentManager; }
-
- /**
- * When the state change call the associated hooks.
- * @see org.apache.felix.ipojo.Handler#stateChanged(int)
- */
- public void stateChanged(int state) {
- Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] State changed in callback handler, check " + m_callbacks.length + " callbacks. Transition : " + m_state + " -> " + state);
- for (int i = 0; i < m_callbacks.length; i++) {
- if (m_callbacks[i].getMetadata().getInitialState() == m_state && m_callbacks[i].getMetadata().getFinalState() == state) {
- try {
- Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] Call the callback : " + m_callbacks[i].getMetadata().getMethod());
- m_callbacks[i].call();
- } catch (NoSuchMethodException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The callback method " + m_callbacks[i].getMetadata().getMethod() + " is not found : " + e.getMessage());
- } catch (IllegalAccessException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The callback method " + m_callbacks[i].getMetadata().getMethod() + " is not accessible : " + e.getMessage());
- } catch (InvocationTargetException e) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The callback method " + m_callbacks[i].getMetadata().getMethod() + " has throws an exception : " + e.getMessage() + " -> " + e.getCause());
- }
- }
- }
- // Update to internal state
- m_state = state;
- }
+ /**
+ * When the state change call the associated hooks.
+ * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+ */
+ public void stateChanged(int state) {
+ Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] State changed in callback handler, check " + m_callbacks.length + " callbacks. Transition : " + m_state + " -> " + state);
+ for (int i = 0; i < m_callbacks.length; i++) {
+ if (m_callbacks[i].getMetadata().getInitialState() == m_state && m_callbacks[i].getMetadata().getFinalState() == state) {
+ try {
+ Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] Call the callback : " + m_callbacks[i].getMetadata().getMethod());
+ m_callbacks[i].call();
+ } catch (NoSuchMethodException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The callback method " + m_callbacks[i].getMetadata().getMethod() + " is not found : " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The callback method " + m_callbacks[i].getMetadata().getMethod() + " is not accessible : " + e.getMessage());
+ } catch (InvocationTargetException e) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The callback method " + m_callbacks[i].getMetadata().getMethod() + " has throws an exception : " + e.getMessage() + " -> " + e.getCause());
+ }
+ }
+ }
+ // Update to internal state
+ m_state = state;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackMetadata.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackMetadata.java
index 88db994..63c333f 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackMetadata.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackMetadata.java
@@ -1,22 +1,24 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.lifecycle.callback;
-import org.apache.felix.ipojo.ComponentManager;
+import org.apache.felix.ipojo.ComponentManagerImpl;
/**
* Lifecycle callback metadata.
@@ -24,73 +26,73 @@
*/
public class LifecycleCallbackMetadata {
- /**
- * Initial state of the transition.
- */
- private int m_initialState;
+ /**
+ * Initial state of the transition.
+ */
+ private int m_initialState;
- /**
- * Final state of the transition.
- */
- private int m_finalState;
+ /**
+ * Final state of the transition.
+ */
+ private int m_finalState;
- /**
- * Method to call.
- */
- private String m_method;
+ /**
+ * Method to call.
+ */
+ private String m_method;
- /**
- * is the method a static method ?
- */
- private boolean m_isStatic;
+ /**
+ * is the method a static method ?
+ */
+ private boolean m_isStatic;
- // Constructor
+ // Constructor
- /**
+ /**
* Constructor.
- * @param initialState : initial state
- * @param finalState : final state
- * @param method : method name
- * @param isStatic : is the method a static method ?
- */
- public LifecycleCallbackMetadata(String initialState, String finalState, String method, boolean isStatic) {
- if (initialState.equals("VALID")) { m_initialState = ComponentManager.VALID; }
- if (initialState.equals("INVALID")) { m_initialState = ComponentManager.INVALID; }
- if (finalState.equals("VALID")) { m_finalState = ComponentManager.VALID; }
- if (finalState.equals("INVALID")) { m_finalState = ComponentManager.INVALID; }
+ * @param initialState : initial state
+ * @param finalState : final state
+ * @param method : method name
+ * @param isStatic : is the method a static method ?
+ */
+ public LifecycleCallbackMetadata(String initialState, String finalState, String method, boolean isStatic) {
+ if (initialState.equals("VALID")) { m_initialState = ComponentManagerImpl.VALID; }
+ if (initialState.equals("INVALID")) { m_initialState = ComponentManagerImpl.INVALID; }
+ if (finalState.equals("VALID")) { m_finalState = ComponentManagerImpl.VALID; }
+ if (finalState.equals("INVALID")) { m_finalState = ComponentManagerImpl.INVALID; }
- m_method = method;
- m_isStatic = isStatic;
- }
+ m_method = method;
+ m_isStatic = isStatic;
+ }
- // Getters
+ // Getters
- /**
- * @return Returns the m_finalState.
- */
- public int getFinalState() {
- return m_finalState;
- }
+ /**
+ * @return Returns the m_finalState.
+ */
+ public int getFinalState() {
+ return m_finalState;
+ }
- /**
- * @return Returns the m_initialState.
- */
- public int getInitialState() {
- return m_initialState;
- }
+ /**
+ * @return Returns the m_initialState.
+ */
+ public int getInitialState() {
+ return m_initialState;
+ }
- /**
- * @return Returns the m_isStatic.
- */
- public boolean isStatic() {
- return m_isStatic;
- }
+ /**
+ * @return Returns the m_isStatic.
+ */
+ public boolean isStatic() {
+ return m_isStatic;
+ }
- /**
- * @return Returns the m_method.
- */
- public String getMethod() {
- return m_method;
- }
+ /**
+ * @return Returns the m_method.
+ */
+ public String getMethod() {
+ return m_method;
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
index da99dff..1b7451e 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.providedservice;
@@ -56,25 +58,25 @@
* @param pm : metadata of the property
*/
public Property(ProvidedService ps, PropertyMetadata pm) {
- m_providedService = ps;
- m_metadata = pm;
+ m_providedService = ps;
+ m_metadata = pm;
- // Fix the type of the property if null
- if (pm.getType() == null) {
- // If the type is not found, it is a dynamic property
- Element manipulation = m_providedService.getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
- String type = null;
- String field = m_metadata.getField();
- for (int i = 0; i < manipulation.getElements("Field").length; i++) {
- if (field.equals(manipulation.getElements("Field")[i].getAttribute("name"))) {
- type = manipulation.getElements("Field")[i].getAttribute("type");
- break;
- }
- }
- pm.setType(type);
- }
+ // Fix the type of the property if null
+ if (pm.getType() == null) {
+ // If the type is not found, it is a dynamic property
+ Element manipulation = m_providedService.getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
+ String type = null;
+ String field = m_metadata.getField();
+ for (int i = 0; i < manipulation.getElements("Field").length; i++) {
+ if (field.equals(manipulation.getElements("Field")[i].getAttribute("name"))) {
+ type = manipulation.getElements("Field")[i].getAttribute("type");
+ break;
+ }
+ }
+ pm.setType(type);
+ }
- if (pm.getValue() != null) { setValue(pm.getValue()); }
+ if (pm.getValue() != null) { setValue(pm.getValue()); }
}
/**
@@ -85,9 +87,9 @@
* @param value : the value of the property
*/
public Property(ProvidedService ps, String name, Object value) {
- m_providedService = ps;
- m_metadata = new PropertyMetadata(name, null, value.getClass().getName(), null);
- m_value = value;
+ m_providedService = ps;
+ m_metadata = new PropertyMetadata(name, null, value.getClass().getName(), null);
+ m_value = value;
}
/**
@@ -105,7 +107,7 @@
* @return the property metadata.
*/
public PropertyMetadata getMetadata() {
- return m_metadata;
+ return m_metadata;
}
/**
@@ -141,19 +143,20 @@
* @param value : value of the property (String)
*/
private void setValue(String value) {
- String type = m_metadata.getType();
+ String type = m_metadata.getType();
- // Array :
- if (type.endsWith("[]")) {
- String internalType = type.substring(0, type.length() - 2);
- value = value.substring(1, value.length() - 1);
- String[] values = value.split(",");
- setArrayValue(internalType, values);
- return;
- }
+ Activator.getLogger().log(Level.INFO, "[" + m_providedService.getComponentManager().getComponentMetatada().getClassName() + "] Set the value of the property " + m_metadata.getName() + " [" + m_metadata.getType() + "] " + " with the value : " + value);
- // Simple :
- Activator.getLogger().log(Level.INFO, "[" + m_providedService.getComponentManager().getComponentMetatada().getClassName() + "] Set the value of the property " + m_metadata.getName() + " [" + m_metadata.getType() + "] " + " with the value : " + value);
+ // Array :
+ if (type.endsWith("[]")) {
+ String internalType = type.substring(0, type.length() - 2);
+ value = value.substring(1, value.length() - 1);
+ String[] values = value.split(",");
+ setArrayValue(internalType, values);
+ return;
+ }
+
+ // Simple :
if (type.equals("string") || type.equals("String")) { m_value = new String(value); return; }
if (type.equals("boolean")) { m_value = new Boolean(value); return; }
@@ -192,82 +195,87 @@
}
}
+ /**
+ * Set a array value to the current property.
+ * @param internalType : internal array type
+ * @param values : the new value
+ */
private void setArrayValue(String internalType, String[] values) {
- if (internalType.equals("string") || internalType.equals("String")) { m_value = values; return; }
- if (internalType.equals("boolean")) {
- boolean[] bool = new boolean[values.length];
- for (int i = 0; i < values.length; i++) { bool[i] = new Boolean(values[i]).booleanValue(); }
- m_value = bool;
- return;
+ if (internalType.equals("string") || internalType.equals("String")) { m_value = values; return; }
+ if (internalType.equals("boolean")) {
+ boolean[] bool = new boolean[values.length];
+ for (int i = 0; i < values.length; i++) { bool[i] = new Boolean(values[i].trim()).booleanValue(); }
+ m_value = bool;
+ return;
}
if (internalType.equals("byte")) {
- byte[] byt = new byte[values.length];
- for (int i = 0; i < values.length; i++) { byt[i] = new Byte(values[i]).byteValue(); }
- m_value = byt;
- return;
+ byte[] byt = new byte[values.length];
+ for (int i = 0; i < values.length; i++) { byt[i] = new Byte(values[i].trim()).byteValue(); }
+ m_value = byt;
+ return;
}
- if (internalType.equals("short")) {
- short[] shor = new short[values.length];
- for (int i = 0; i < values.length; i++) { shor[i] = new Short(values[i]).shortValue(); }
- m_value = shor;
- return;
+ if (internalType.equals("short")) {
+ short[] shor = new short[values.length];
+ for (int i = 0; i < values.length; i++) { shor[i] = new Short(values[i].trim()).shortValue(); }
+ m_value = shor;
+ return;
}
- if (internalType.equals("int")) {
- int[] in = new int[values.length];
- for (int i = 0; i < values.length; i++) { in[i] = new Integer(values[i]).intValue(); }
- m_value = in;
- return;
+ if (internalType.equals("int")) {
+ int[] in = new int[values.length];
+ for (int i = 0; i < values.length; i++) { in[i] = new Integer(values[i].trim()).intValue(); }
+ m_value = in;
+ return;
}
- if (internalType.equals("long")) {
- long[] ll = new long[values.length];
- for (int i = 0; i < values.length; i++) { ll[i] = new Long(values[i]).longValue(); }
- m_value = ll;
- return;
+ if (internalType.equals("long")) {
+ long[] ll = new long[values.length];
+ for (int i = 0; i < values.length; i++) { ll[i] = new Long(values[i].trim()).longValue(); }
+ m_value = ll;
+ return;
}
- if (internalType.equals("float")) {
- float[] fl = new float[values.length];
- for (int i = 0; i < values.length; i++) { fl[i] = new Float(values[i]).floatValue(); }
- m_value = fl;
- return; }
- if (internalType.equals("double")) {
- double[] dl = new double[values.length];
- for (int i = 0; i < values.length; i++) { dl[i] = new Double(values[i]).doubleValue(); }
- m_value = dl;
- return; }
+ if (internalType.equals("float")) {
+ float[] fl = new float[values.length];
+ for (int i = 0; i < values.length; i++) { fl[i] = new Float(values[i].trim()).floatValue(); }
+ m_value = fl;
+ return; }
+ if (internalType.equals("double")) {
+ double[] dl = new double[values.length];
+ for (int i = 0; i < values.length; i++) { dl[i] = new Double(values[i].trim()).doubleValue(); }
+ m_value = dl;
+ return; }
- // Else it is a neither a primitive type neither a String -> create the object by calling a constructor with a string in argument.
- try {
- Class c = m_providedService.getComponentManager().getContext().getBundle().loadClass(internalType);
- Constructor cst = c.getConstructor(new Class[] {String.class});
- Object[] ob = (Object[]) Array.newInstance(c, values.length);
- for (int i = 0; i < values.length; i++) {
- ob[i] = cst.newInstance(new Object[] {values[i]});
- }
- m_value = ob;
- return;
- } catch (ClassNotFoundException e) {
- System.err.println("Class not found exception in setValue on " + internalType);
- e.printStackTrace();
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- System.err.println("Constructor not found exeption in setValue on " + internalType);
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- System.err.println("Argument problem to call the constructor of the type " + internalType);
- e.printStackTrace();
- } catch (InstantiationException e) {
- System.err.println("Instantiation problem " + internalType);
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- System.err.println("Invocation problem " + internalType);
- e.printStackTrace();
- }
- }
+ // Else it is a neither a primitive type neither a String -> create the object by calling a constructor with a string in argument.
+ try {
+ Class c = m_providedService.getComponentManager().getContext().getBundle().loadClass(internalType);
+ Constructor cst = c.getConstructor(new Class[] {String.class});
+ Object[] ob = (Object[]) Array.newInstance(c, values.length);
+ for (int i = 0; i < values.length; i++) {
+ ob[i] = cst.newInstance(new Object[] {values[i].trim()});
+ }
+ m_value = ob;
+ return;
+ } catch (ClassNotFoundException e) {
+ System.err.println("Class not found exception in setValue on " + internalType);
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ System.err.println("Constructor not found exeption in setValue on " + internalType);
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ System.err.println("Argument problem to call the constructor of the type " + internalType);
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ System.err.println("Instantiation problem " + internalType);
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ System.err.println("Invocation problem " + internalType);
+ e.printStackTrace();
+ }
+ }
- /**
+ /**
* @return the value of the property.
*/
public Object getValue() { return m_value; }
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/PropertyMetadata.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/PropertyMetadata.java
index 90926d6..3b3b42f 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/PropertyMetadata.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/PropertyMetadata.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.providedservice;
@@ -22,72 +24,72 @@
*/
public class PropertyMetadata {
- /**
- * Field of the property.
- */
- private String m_field;
+ /**
+ * Field of the property.
+ */
+ private String m_field;
- /**
- * Name of the property.
- */
- private String m_name;
+ /**
+ * Name of the property.
+ */
+ private String m_name;
- /**
- * Type of the property.
- */
- private String m_type;
+ /**
+ * Type of the property.
+ */
+ private String m_type;
- /**
- * String value of the property (initial value).
- */
- private String m_value;
+ /**
+ * String value of the property (initial value).
+ */
+ private String m_value;
- //Constructor
+ //Constructor
- /**
+ /**
* Constructor.
- * @param name : name of the property
- * @param field : field of the property
- * @param type : type of the property
- * @param value : initial value of the property
- */
- public PropertyMetadata(String name, String field, String type, String value) {
- m_name = name;
- m_field = field;
- m_type = type;
- m_value = value;
+ * @param name : name of the property
+ * @param field : field of the property
+ * @param type : type of the property
+ * @param value : initial value of the property
+ */
+ public PropertyMetadata(String name, String field, String type, String value) {
+ m_name = name;
+ m_field = field;
+ m_type = type;
+ m_value = value;
- // Dynamic property case :
- if (m_field != null) {
- if (m_name == null) { m_name = m_field; }
- }
- }
+ // Dynamic property case :
+ if (m_field != null) {
+ if (m_name == null) { m_name = m_field; }
+ }
+ }
- /**
- * @return the field name.
- */
- public String getField() { return m_field; };
+ /**
+ * @return the field name.
+ */
+ public String getField() { return m_field; };
- /**
- * @return the property name.
- */
- public String getName() { return m_name; };
+ /**
+ * @return the property name.
+ */
+ public String getName() { return m_name; };
- /**
- * @return the type of the property.
- */
- public String getType() { return m_type; };
+ /**
+ * @return the type of the property.
+ */
+ public String getType() { return m_type; };
- /**
- * @return the initial value.
- */
- public String getValue() { return m_value; }
+ /**
+ * @return the initial value.
+ */
+ public String getValue() { return m_value; }
- /**
+ /**
* Set the type of the property (dynamic property only).
- * @param type : the type of the property.
- */
- public void setType(String type) { m_type = type; }
+ * @param type : the type of the property.
+ */
+ public void setType(String type) { m_type = type; }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
index 82ce8fb..b760c29 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.providedservice;
@@ -21,7 +23,7 @@
import java.util.Properties;
import java.util.logging.Level;
-import org.apache.felix.ipojo.ComponentManager;
+import org.apache.felix.ipojo.ComponentManagerImpl;
import org.apache.felix.ipojo.Activator;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
@@ -56,12 +58,6 @@
public static final int SERVICE_FACTORY = 1;
/**
- * Factory policy : COMPONENT_FACTORY.
- * TODO : Component_factory behavior
- */
- public static final int COMPONENT_FACTORY = 2;
-
- /**
* The service registration.
* is null when the service is not registred.
* m_serviceRegistration : ServiceRegistration
@@ -99,8 +95,8 @@
m_handler = handler;
m_metadata = psm;
for (int i = 0; i < psm.getProperties().length; i++) {
- Property prop = new Property(this, ((PropertyMetadata)psm.getProperties()[i]));
- addProperty(prop);
+ Property prop = new Property(this, ((PropertyMetadata) psm.getProperties()[i]));
+ addProperty(prop);
}
}
@@ -122,30 +118,34 @@
else { m_properties = new Property[] {p}; }
}
+ /**
+ * Remove a property.
+ * @param name : the property to remove
+ */
private synchronized void removeProperty(String name) {
- int idx = -1;
- for (int i = 0; i < m_properties.length; i++) {
- if (m_properties[i].getMetadata().getName() == name) { idx = i; break; }
- }
+ int idx = -1;
+ for (int i = 0; i < m_properties.length; i++) {
+ if (m_properties[i].getMetadata().getName() == name) { idx = i; break; }
+ }
- if (idx >= 0) {
- if ((m_properties.length - 1) == 0) { m_properties = new Property[0]; }
- else {
- Property[] newPropertiesList = new Property[m_properties.length - 1];
- System.arraycopy(m_properties, 0, newPropertiesList, 0, idx);
- if (idx < newPropertiesList.length) {
- System.arraycopy(m_properties, idx + 1, newPropertiesList, idx, newPropertiesList.length - idx); }
- m_properties = newPropertiesList;
- }
- }
+ if (idx >= 0) {
+ if ((m_properties.length - 1) == 0) { m_properties = new Property[0]; }
+ else {
+ Property[] newPropertiesList = new Property[m_properties.length - 1];
+ System.arraycopy(m_properties, 0, newPropertiesList, 0, idx);
+ if (idx < newPropertiesList.length) {
+ System.arraycopy(m_properties, idx + 1, newPropertiesList, idx, newPropertiesList.length - idx); }
+ m_properties = newPropertiesList;
+ }
+ }
}
/**
* @return the service reference of the provided service (null if the service is not published).
*/
public ServiceReference getServiceReference() {
- if (m_serviceRegistration != null) { return m_serviceRegistration.getReference(); }
- else { return null; }
+ if (m_serviceRegistration != null) { return m_serviceRegistration.getReference(); }
+ else { return null; }
}
/**
@@ -157,22 +157,18 @@
*/
public Object getService(Bundle bundle, ServiceRegistration registration) {
- switch(m_metadata.getFactoryPolicy()) {
+ switch(m_metadata.getFactoryPolicy()) {
- case SINGLETON_FACTORY :
- return m_handler.getComponentManager().getInstance();
+ case SINGLETON_FACTORY :
+ return m_handler.getComponentManager().getInstance();
- case SERVICE_FACTORY :
- return m_handler.getComponentManager().createInstance();
+ case SERVICE_FACTORY :
+ return m_handler.getComponentManager().createInstance();
- case COMPONENT_FACTORY :
- //TODO Component Factory Behavior
- return null;
-
- default :
- Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Unknown factory policy for " + m_metadata.getServiceSpecification() + " : " + m_metadata.getFactoryPolicy());
- return null;
- }
+ default :
+ Activator.getLogger().log(Level.SEVERE, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Unknown factory policy for " + m_metadata.getServiceSpecification() + " : " + m_metadata.getFactoryPolicy());
+ return null;
+ }
}
@@ -187,23 +183,23 @@
//Nothing to do
}
-// /**
-// * Validate the service dependencies of the current provided service.
-// * @return true if the service dependencies are valid
-// */
-// public boolean validate() {
-// boolean valide = true;
-// for (int i = 0; i < m_dependencies.length; i++) {
-// Dependency dep = m_dependencies[i];
-// valide = valide & dep.isSatisfied();
-// if (!valide) {
-// ComponentManager.getLogger().log(Level.INFO, "Service Dependency for " + m_interface + " not valid : " + dep.getInterface());
-// return false;
-// }
-// }
-// ComponentManager.getLogger().log(Level.INFO, "Service dependencies for " + m_interface + " are valid");
-// return valide;
-// }
+// /**
+// * Validate the service dependencies of the current provided service.
+// * @return true if the service dependencies are valid
+// */
+// public boolean validate() {
+// boolean valide = true;
+// for (int i = 0; i < m_dependencies.length; i++) {
+// Dependency dep = m_dependencies[i];
+// valide = valide & dep.isSatisfied();
+// if (!valide) {
+// ComponentManager.getLogger().log(Level.INFO, "Service Dependency for " + m_interface + " not valid : " + dep.getInterface());
+// return false;
+// }
+// }
+// ComponentManager.getLogger().log(Level.INFO, "Service dependencies for " + m_interface + " are valid");
+// return valide;
+// }
/**
* Register the service.
@@ -211,35 +207,35 @@
* To avoid cycle in Check Context, the registred service is set to registred before the real registration.
*/
protected void registerService() {
- if (m_state != REGISTERED) {
+ if (m_state != REGISTERED) {
String spec = "";
for (int i = 0; i < m_metadata.getServiceSpecification().length; i++) {
spec = spec + m_metadata.getServiceSpecification()[i] + ", ";
}
- Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Register the service : " + spec);
- // Contruct the service properties list
- Properties serviceProperties = getServiceProperties();
+ Activator.getLogger().log(Level.INFO, "[" + m_handler.getComponentManager().getComponentMetatada().getClassName() + "] Register the service : " + spec);
+ // Contruct the service properties list
+ Properties serviceProperties = getServiceProperties();
- m_state = REGISTERED;
- synchronized (this) {
- m_serviceRegistration =
- m_handler.getComponentManager().getContext().registerService(
+ m_state = REGISTERED;
+ synchronized (this) {
+ m_serviceRegistration =
+ m_handler.getComponentManager().getContext().registerService(
m_metadata.getServiceSpecification(), this, serviceProperties);
- }
- }
+ }
+ }
}
/**
* Unregister the service.
*/
protected void unregisterService() {
- if (m_state == REGISTERED) {
- try {
- m_serviceRegistration.unregister();
- m_serviceRegistration = null;
- } catch (Exception e) { return; }
- m_state = UNREGISTERED;
- }
+ if (m_state == REGISTERED) {
+ try {
+ m_serviceRegistration.unregister();
+ m_serviceRegistration = null;
+ } catch (Exception e) { return; }
+ m_state = UNREGISTERED;
+ }
}
/**
@@ -252,8 +248,8 @@
/**
* @return the component manager.
*/
- protected ComponentManager getComponentManager() {
- return m_handler.getComponentManager();
+ protected ComponentManagerImpl getComponentManager() {
+ return m_handler.getComponentManager();
}
/**
@@ -280,11 +276,10 @@
}
/**
- * Update refresh the service properties.
+ * Update the service properties.
* The new list of properties is sended to the service registry.
*/
public void update() {
- // Update the service properties
// Contruct the service properties list
Properties serviceProperties = getServiceProperties();
@@ -297,39 +292,39 @@
}
}
- /**
- * @return the propvided service metadata.
- */
- public ProvidedServiceMetadata getMetadata() {
- return m_metadata;
- }
+ /**
+ * @return the propvided service metadata.
+ */
+ public ProvidedServiceMetadata getMetadata() {
+ return m_metadata;
+ }
- /**
- * Add properties to the list.
- * @param props : properties to add
- */
- protected void addProperties(Dictionary props) {
- Enumeration keys = props.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- Object value = props.get(key);
- Property prop = new Property(this, key, value);
- addProperty(prop);
- }
- update();
- }
+ /**
+ * Add properties to the list.
+ * @param props : properties to add
+ */
+ protected void addProperties(Dictionary props) {
+ Enumeration keys = props.keys();
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ Object value = props.get(key);
+ Property prop = new Property(this, key, value);
+ addProperty(prop);
+ }
+ update();
+ }
- /**
- * Remove properties from the list.
- * @param props : properties to remove
- */
- protected void deleteProperties(Dictionary props) {
- Enumeration keys = props.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- removeProperty(key);
- }
- update();
- }
+ /**
+ * Remove properties from the list.
+ * @param props : properties to remove
+ */
+ protected void deleteProperties(Dictionary props) {
+ Enumeration keys = props.keys();
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ removeProperty(key);
+ }
+ update();
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
index 6361bd7..3deda1c 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
@@ -1,81 +1,92 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.providedservice;
import java.util.Dictionary;
import java.util.logging.Level;
-import org.apache.felix.ipojo.ComponentManager;
-import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.Activator;
+import org.apache.felix.ipojo.ComponentInfo;
+import org.apache.felix.ipojo.ComponentManagerImpl;
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.PropertyInfo;
import org.apache.felix.ipojo.metadata.Element;
/**
* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
*/
-public class ProvidedServiceHandler implements Handler {
+public class ProvidedServiceHandler extends Handler {
- /**
- * The list of the provided service.
- */
- private ProvidedService[] m_providedServices = new ProvidedService[0];
+ /**
+ * The list of the provided service.
+ */
+ private ProvidedService[] m_providedServices = new ProvidedService[0];
- /**
- * The component manager.
- */
- private ComponentManager m_componentManager;
+ /**
+ * The component manager.
+ */
+ private ComponentManagerImpl m_componentManager;
- private void addProvidedService(ProvidedService ps) {
- // Verify that the provided service is not already in the array.
- for (int i = 0; (m_providedServices != null) && (i < m_providedServices.length); i++) {
- if (m_providedServices[i] == ps) { return; }
- }
+ /**
+ * Add a provided service to the list .
+ * @param ps : the provided service to add
+ */
+ private void addProvidedService(ProvidedService ps) {
+ // Verify that the provided service is not already in the array.
+ for (int i = 0; (m_providedServices != null) && (i < m_providedServices.length); i++) {
+ if (m_providedServices[i] == ps) { return; }
+ }
- if (m_providedServices.length > 0) {
- ProvidedService[] newPS = new ProvidedService[m_providedServices.length + 1];
- System.arraycopy(m_providedServices, 0, newPS, 0, m_providedServices.length);
- newPS[m_providedServices.length] = ps;
- m_providedServices = newPS;
- }
- else { m_providedServices = new ProvidedService[] {ps}; }
- }
+ if (m_providedServices.length > 0) {
+ ProvidedService[] newPS = new ProvidedService[m_providedServices.length + 1];
+ System.arraycopy(m_providedServices, 0, newPS, 0, m_providedServices.length);
+ newPS[m_providedServices.length] = ps;
+ m_providedServices = newPS;
+ }
+ else { m_providedServices = new ProvidedService[] {ps}; }
+ }
- /**
- * @return the component manager.
- */
- public ComponentManager getComponentManager() { return m_componentManager; }
+ /**
+ * @return the component manager.
+ */
+ public ComponentManagerImpl getComponentManager() { return m_componentManager; }
- /**
- * @return the list of the provided service.
- */
- public ProvidedService[] getProvidedService() { return m_providedServices; }
+ /**
+ * @return the list of the provided service.
+ */
+ public ProvidedService[] getProvidedService() { return m_providedServices; }
- /**
- * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManager, org.apache.felix.ipojo.metadata.Element)
- */
- public void configure(ComponentManager cm, Element componentMetadata) {
- // Fix the component managert & clean the provided service list
- m_componentManager = cm;
- m_providedServices = new ProvidedService[0];
- // Create the dependency according to the component metadata
- Element[] providedServices = componentMetadata.getElements("Provides");
- for (int i = 0; i < providedServices.length; i++) {
- // Create a ProvidedServiceMetadata object
+ /**
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.ComponentManagerImpl, org.apache.felix.ipojo.metadata.Element)
+ */
+ public void configure(ComponentManagerImpl cm, Element componentMetadata, Dictionary configuration) {
+ // Fix the component manager & clean the provided service list
+ m_componentManager = cm;
+
+ ComponentInfo ci = cm.getComponentInfo();
+
+ m_providedServices = new ProvidedService[0];
+ // Create the dependency according to the component metadata
+ Element[] providedServices = componentMetadata.getElements("Provides");
+ for (int i = 0; i < providedServices.length; i++) {
+ // Create a ProvidedServiceMetadata object
// First : create the serviceSpecification array
String[] serviceSpecification = new String[0];
@@ -86,84 +97,101 @@
serviceSpecification = new String[spec.length];
for (int j = 0; j < spec.length; j++) { serviceSpecification[j] = spec[j].trim(); }
} else {
- Element manipulation = m_componentManager.getComponentMetatada().getMetadata().getElements("Manipulation")[0];
- serviceSpecification = new String[manipulation.getElements("Interface").length];
- for (int j = 0; j < manipulation.getElements("Interface").length; j++) {
- serviceSpecification[j] = manipulation.getElements("Interface")[j].getAttribute("name");
- }
+ Element manipulation = m_componentManager.getComponentMetatada().getMetadata().getElements("Manipulation")[0];
+ serviceSpecification = new String[manipulation.getElements("Interface").length];
+ for (int j = 0; j < manipulation.getElements("Interface").length; j++) {
+ serviceSpecification[j] = manipulation.getElements("Interface")[j].getAttribute("name");
+ }
}
// Get the factory policy
- int factory = ProvidedServiceMetadata.SINGLETON_FACTORY;
- if (providedServices[i].containsAttribute("factory") && providedServices[i].getAttribute("factory").equals("service")) { factory = ProvidedService.SERVICE_FACTORY; }
+ int factory = ProvidedServiceMetadata.SINGLETON_FACTORY;
+ if (providedServices[i].containsAttribute("factory") && providedServices[i].getAttribute("factory").equals("service")) { factory = ProvidedService.SERVICE_FACTORY; }
- // Then create the provided service metadata
- ProvidedServiceMetadata psm = new ProvidedServiceMetadata(serviceSpecification, factory);
+ // Then create the provided service metadata
+ ProvidedServiceMetadata psm = new ProvidedServiceMetadata(serviceSpecification, factory);
- // Create properties
- Element[] dynamicProps = providedServices[i].getElements("DynamicProperty");
- Element[] staticProps = providedServices[i].getElements("StaticProperty");
- Element[] props = providedServices[i].getElements("Property");
- for (int j = 0; j < dynamicProps.length; j++) {
- Activator.getLogger().log(Level.WARNING, "[" + m_componentManager.getComponentMetatada().getClassName() + "] Please use property instead of dynamic property");
- String name = null;
- if (dynamicProps[j].containsAttribute("name")) { name = dynamicProps[j].getAttribute("name"); }
- String field = dynamicProps[j].getAttribute("field");
- String value = null;
- if (dynamicProps[j].containsAttribute("value")) { value = dynamicProps[j].getAttribute("value"); }
- String type = null;
- if (dynamicProps[j].containsAttribute("type")) { type = dynamicProps[j].getAttribute("type"); }
- PropertyMetadata pm = new PropertyMetadata(name, field, type, value);
- psm.addProperty(pm);
- }
- for (int j = 0; j < staticProps.length; j++) {
- Activator.getLogger().log(Level.WARNING, "[" + m_componentManager.getComponentMetatada().getClassName() + "] Please use property instead of static property");
- String name = staticProps[j].getAttribute("name");
- String value = staticProps[j].getAttribute("value");
- String type = staticProps[j].getAttribute("type");
- PropertyMetadata pm = new PropertyMetadata(name, null, type, value);
- psm.addProperty(pm);
- }
- for (int j = 0; j < props.length; j++) {
- String name = null;
- if (props[j].containsAttribute("name")) { name = props[j].getAttribute("name"); }
- String value = null;
- if (props[j].containsAttribute("value")) { value = props[j].getAttribute("value"); }
- String type = null;
- if (props[j].containsAttribute("type")) { type = props[j].getAttribute("type"); }
- String field = null;
- if (props[j].containsAttribute("field")) { field = props[j].getAttribute("field"); }
- PropertyMetadata pm = new PropertyMetadata(name, field, type, value);
- psm.addProperty(pm);
- }
+ Element[] props = providedServices[i].getElements("Property");
+ for (int j = 0; j < props.length; j++) {
+ String name = null;
+ if (props[j].containsAttribute("name")) { name = props[j].getAttribute("name"); }
+ String value = null;
+ if (props[j].containsAttribute("value")) { value = props[j].getAttribute("value"); }
+ String type = null;
+ if (props[j].containsAttribute("type")) { type = props[j].getAttribute("type"); }
+ String field = null;
+ if (props[j].containsAttribute("field")) { field = props[j].getAttribute("field"); }
- // Create the provided service object
- ProvidedService ps = new ProvidedService(this, psm);
- if (checkProvidedService(ps)) { addProvidedService(ps); }
- else {
+ if (name != null && configuration.get(name) != null && configuration.get(name) instanceof String) { value = (String) configuration.get(name); }
+ else { if (field != null && configuration.get(field) != null && configuration.get(field) instanceof String) { value = (String) configuration.get(field); } }
+
+ PropertyMetadata pm = new PropertyMetadata(name, field, type, value);
+ psm.addProperty(pm);
+ }
+
+ // Create the provided service object
+ ProvidedService ps = new ProvidedService(this, psm);
+ if (checkProvidedService(ps)) {
+ addProvidedService(ps);
+ // Change ComponentInfo
+ for (int k = 0; k < ps.getMetadata().getServiceSpecification().length; k++) { ci.addProvidedServiceSpecification(ps.getMetadata().getServiceSpecification()[k]); }
+ for (int k = 0; k < ps.getMetadata().getProperties().length; k++) { ci.addProperty(new PropertyInfo(ps.getMetadata().getProperties()[k].getName(), ps.getMetadata().getProperties()[k].getType(), ps.getMetadata().getProperties()[k].getValue())); }
+ }
+ else {
String itfs = "";
for (int j = 0; j < serviceSpecification.length; j++) {
itfs = itfs + " " + serviceSpecification[j];
}
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The provided service" + itfs + " is not valid, it will be removed");
- ps = null;
- }
- }
+ Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The provided service" + itfs + " is not valid, it will be removed");
+ ps = null;
+ }
- if (providedServices.length > 0) { m_componentManager.register(this); }
- }
+ }
- private boolean containsInterface(String s) {
- Element manipulation = m_componentManager.getComponentMetatada().getMetadata().getElements("Manipulation")[0];
- for (int i = 0; i < manipulation.getElements("Interface").length; i++) {
- if (manipulation.getElements("Interface")[i].getAttribute("name").equals(s)) {
- return true;
- }
- }
- return false;
- }
+ if (providedServices.length > 0) {
+ String[] fields = new String[0];
+ for (int i = 0; i < m_providedServices.length; i++) {
+ ProvidedService ps = m_providedServices[i];
+ for (int j = 0; j < ps.getProperties().length; j++) {
+ Property prop = ps.getProperties()[j];
- private boolean checkProvidedService(ProvidedService ps) {
+ // Check if the instance configuration has a value for this property
+ if (prop.getMetadata().getName() != null && configuration.get(prop.getMetadata().getName()) != null && !(configuration.get(prop.getMetadata().getName()) instanceof String)) { prop.set(configuration.get(prop.getMetadata().getName())); }
+ else { if (prop.getMetadata().getField() != null && configuration.get(prop.getMetadata().getField()) != null && !(configuration.get(prop.getMetadata().getField()) instanceof String)) { prop.set(configuration.get(prop.getMetadata().getField())); } }
+
+ if (prop.getMetadata().getField() != null) {
+ String[] newFields = new String[fields.length + 1];
+ System.arraycopy(fields, 0, newFields, 0, fields.length);
+ newFields[fields.length] = prop.getMetadata().getField();
+ fields = newFields;
+ }
+ }
+ }
+
+ m_componentManager.register(this, fields); }
+ }
+
+ /**
+ * Is the specicifaction s in the list ?
+ * @param s : the specitication to search
+ * @return true if s is in the list
+ */
+ private boolean containsInterface(String s) {
+ Element manipulation = m_componentManager.getComponentMetatada().getMetadata().getElements("Manipulation")[0];
+ for (int i = 0; i < manipulation.getElements("Interface").length; i++) {
+ if (manipulation.getElements("Interface")[i].getAttribute("name").equals(s)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check the provided service given in argument in the sense that the metadata are consistent.
+ * @param ps : the provided service to check
+ * @return true if the provided service is correct
+ */
+ private boolean checkProvidedService(ProvidedService ps) {
for (int i = 0; i < ps.getMetadata().getServiceSpecification().length; i++) {
if (!containsInterface(ps.getMetadata().getServiceSpecification()[i])) {
@@ -172,154 +200,145 @@
}
}
- // Fix internal property type
- for (int i = 0; i < ps.getProperties().length; i++) {
- Property prop = ps.getProperties()[i];
- String field = prop.getMetadata().getField();
+ // Fix internal property type
+ for (int i = 0; i < ps.getProperties().length; i++) {
+ Property prop = ps.getProperties()[i];
+ String field = prop.getMetadata().getField();
- if (field == null) {
- // Static dependency -> Nothing to check
- return true;
- } else {
- Element manipulation = getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
- String type = null;
- for (int j = 0; j < manipulation.getElements("Field").length; j++) {
- if (field.equals(manipulation.getElements("Field")[j].getAttribute("name"))) {
- type = manipulation.getElements("Field")[j].getAttribute("type");
- break;
- }
- }
- if (type == null) {
- Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] A declared property was not found in the class : " + prop.getMetadata().getField());
- return false;
- }
+ if (field == null) {
+ // Static dependency -> Nothing to check
+ return true;
+ } else {
+ Element manipulation = getComponentManager().getComponentMetatada().getMetadata().getElements("Manipulation")[0];
+ String type = null;
+ for (int j = 0; j < manipulation.getElements("Field").length; j++) {
+ if (field.equals(manipulation.getElements("Field")[j].getAttribute("name"))) {
+ type = manipulation.getElements("Field")[j].getAttribute("type");
+ break;
+ }
+ }
+ if (type == null) {
+ Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] A declared property was not found in the class : " + prop.getMetadata().getField());
+ return false;
+ }
- if (type != null) {
-// if (type.endsWith("[]")) {
-// Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] An array property was found in the class [Not implemented yet] : " + prop.getMetadata().getField());
-// return false;
-// }
+ if (type != null) {
+// if (type.endsWith("[]")) {
+// Activator.getLogger().log(Level.SEVERE, "[" + m_componentManager.getComponentMetatada().getClassName() + "] An array property was found in the class [Not implemented yet] : " + prop.getMetadata().getField());
+// return false;
+// }
- if (prop.getMetadata().getType() == null) { prop.getMetadata().setType(type); }
+ if (prop.getMetadata().getType() == null) { prop.getMetadata().setType(type); }
- if (!prop.getMetadata().getType().equals(type)) {
- Activator.getLogger().log(Level.WARNING, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The field type [" + type + "] and the declared type [" + prop.getMetadata().getType() + "] are not the same for " + prop.getMetadata().getField());
- prop.getMetadata().setType(type);
- }
- }
- else {
- Activator.getLogger().log(Level.WARNING, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The declared property " + prop.getMetadata().getField() + " does not exist in the code");
- }
- }
- }
- return true;
- }
+ if (!prop.getMetadata().getType().equals(type)) {
+ Activator.getLogger().log(Level.WARNING, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The field type [" + type + "] and the declared type [" + prop.getMetadata().getType() + "] are not the same for " + prop.getMetadata().getField());
+ prop.getMetadata().setType(type);
+ }
+ }
+ else {
+ Activator.getLogger().log(Level.WARNING, "[" + m_componentManager.getComponentMetatada().getClassName() + "] The declared property " + prop.getMetadata().getField() + " does not exist in the code");
+ }
+ }
+ }
+ return true;
+ }
- /**
- * Stop the provided service handler : unregister all provided services.
- * @see org.apache.felix.ipojo.Handler#stop()
- */
- public void stop() {
- for (int i = 0; i < m_providedServices.length; i++) {
- m_providedServices[i].unregisterService();
- }
- }
+ /**
+ * Stop the provided service handler : unregister all provided services.
+ * @see org.apache.felix.ipojo.Handler#stop()
+ */
+ public void stop() {
+ for (int i = 0; i < m_providedServices.length; i++) {
+ m_providedServices[i].unregisterService();
+ }
+ }
- /**
- * Start the provided service handler : register the service if the component is resolved.
- * Else do nothing and whait for a component state change event
- * @see org.apache.felix.ipojo.Handler#start()
- */
- public void start() {
- Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] Start the provided service handler");
- for (int i = 0; (m_componentManager.getState() == ComponentManager.VALID) && i < m_providedServices.length; i++) {
- m_providedServices[i].registerService();
- }
- }
+ /**
+ * Start the provided service handler : register the service if the component is resolved.
+ * Else do nothing and whait for a component state change event
+ * @see org.apache.felix.ipojo.Handler#start()
+ */
+ public void start() {
+ Activator.getLogger().log(Level.INFO, "[" + m_componentManager.getComponentMetatada().getClassName() + "] Start the provided service handler");
+ for (int i = 0; (m_componentManager.getState() == ComponentManagerImpl.VALID) && i < m_providedServices.length; i++) {
+ m_providedServices[i].registerService();
+ }
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
- */
- public void setterCallback(String fieldName, Object value) {
- // Verify that the field name coreespond to a dependency
- for (int i = 0; i < m_providedServices.length; i++) {
- ProvidedService ps = m_providedServices[i];
- for (int j = 0; j < ps.getProperties().length; j++) {
- Property prop = ps.getProperties()[j];
- if (fieldName.equals(prop.getMetadata().getField())) {
- // it is the associated property
- prop.set(value);
- }
- }
- }
- //Else do nothing
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String, java.lang.Object)
+ */
+ public void setterCallback(String fieldName, Object value) {
+ // Verify that the field name coreespond to a dependency
+ for (int i = 0; i < m_providedServices.length; i++) {
+ ProvidedService ps = m_providedServices[i];
+ for (int j = 0; j < ps.getProperties().length; j++) {
+ Property prop = ps.getProperties()[j];
+ if (fieldName.equals(prop.getMetadata().getField())) {
+ // it is the associated property
+ prop.set(value);
+ }
+ }
+ }
+ //Else do nothing
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
- */
- public Object getterCallback(String fieldName, Object value) {
- for (int i = 0; i < m_providedServices.length; i++) {
- ProvidedService ps = m_providedServices[i];
- for (int j = 0; j < ps.getProperties().length; j++) {
- Property prop = ps.getProperties()[j];
- if (fieldName.equals(prop.getMetadata().getField())) {
- // it is the associated property
- return prop.get();
- }
- }
- }
- // Else it is not a property
- return value;
- }
+ /**
+ * @see org.apache.felix.ipojo.Handler#getterCallback(java.lang.String, java.lang.Object)
+ */
+ public Object getterCallback(String fieldName, Object value) {
+ for (int i = 0; i < m_providedServices.length; i++) {
+ ProvidedService ps = m_providedServices[i];
+ for (int j = 0; j < ps.getProperties().length; j++) {
+ Property prop = ps.getProperties()[j];
+ if (fieldName.equals(prop.getMetadata().getField())) {
+ // it is the associated property
+ return prop.get();
+ }
+ }
+ }
+ // Else it is not a property
+ return value;
+ }
- /**
- * @see org.apache.felix.ipojo.Handler#isValid()
- */
- public boolean isValid() {
- // The provided service handler does not need to manipulate the field
- // Return always true
- return true;
- }
+ /**
+ * Register the services if the new state is VALID.
+ * Unregister the services if the new state is UNRESOLVED.
+ * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+ */
+ public void stateChanged(int state) {
+ // If the new state is UNRESOLVED => unregister all the services
+ if (state == ComponentManagerImpl.INVALID) {
+ stop();
+ return;
+ }
- /**
- * Register the services if the new state is VALID.
- * Unregister the services if the new state is UNRESOLVED.
- * @see org.apache.felix.ipojo.Handler#stateChanged(int)
- */
- public void stateChanged(int state) {
- // If the new state is UNRESOLVED => unregister all the services
- if (state == ComponentManager.INVALID) {
- stop();
- return;
- }
+ // If the new state is VALID => regiter all the services
+ if (state == ComponentManagerImpl.VALID) {
+ start();
+ return;
+ }
- // If the new state is VALID => regiter all the services
- if (state == ComponentManager.VALID) {
- start();
- return;
- }
+ }
- }
+ /**
+ * Add properties to all provided services.
+ * @param dict : dictionary fo properties to add
+ */
+ public void addProperties(Dictionary dict) {
+ for (int i = 0; i < m_providedServices.length; i++) {
+ m_providedServices[i].addProperties(dict);
+ }
+ }
- /**
- * Add properties to all provided services.
- * @param dict : dictionary fo properties to add
- */
- public void addProperties(Dictionary dict) {
- for (int i = 0; i < m_providedServices.length; i++) {
- m_providedServices[i].addProperties(dict);
- }
- }
-
- /**
- * Remove properties form all provided services.
- * @param dict : dictionary of properties to delete.
- */
- public void removeProperties(Dictionary dict) {
- for (int i = 0; i < m_providedServices.length; i++) {
- m_providedServices[i].deleteProperties(dict);
- }
- }
+ /**
+ * Remove properties form all provided services.
+ * @param dict : dictionary of properties to delete.
+ */
+ public void removeProperties(Dictionary dict) {
+ for (int i = 0; i < m_providedServices.length; i++) {
+ m_providedServices[i].deleteProperties(dict);
+ }
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceMetadata.java b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceMetadata.java
index 0e58391..b16f299 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceMetadata.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceMetadata.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.handlers.providedservice;
@@ -23,7 +25,7 @@
*/
public class ProvidedServiceMetadata {
- /**
+ /**
* Factory Policy : SINGLETON_FACTORY.
*/
public static final int SINGLETON_FACTORY = 0;
@@ -34,63 +36,57 @@
public static final int SERVICE_FACTORY = 1;
/**
- * Factory policy : COMPONENT_FACTORY.
- * TODO : Component_factory behavior
+ * At this time, it is only the java interface full name.
*/
- public static final int COMPONENT_FACTORY = 2;
+ private String[] m_serviceSpecification = new String[0];
- /**
- * At this time, it is only the java interface full name.
- */
- private String[] m_serviceSpecification = new String[0];
+ /**
+ * List of proeprty metadata.
+ */
+ private PropertyMetadata[] m_properties = new PropertyMetadata[0];
- /**
- * List of proeprty metadata.
- */
- private PropertyMetadata[] m_properties = new PropertyMetadata[0];
+ /**
+ * Foactory policy.
+ */
+ private int m_factoryPolicy = SINGLETON_FACTORY;
- /**
- * Foactory policy.
- */
- private int m_factoryPolicy = SINGLETON_FACTORY;
+ //CONSTRUCTOR :
- //CONSTRUCTOR :
-
- /**
+ /**
* Constructor.
- * @param specification : service specification (i.e. the interface)
- * @param factoryPolicy : the facotry policy.
- */
- public ProvidedServiceMetadata(String[] specification, int factoryPolicy) {
- m_serviceSpecification = specification;
- m_factoryPolicy = factoryPolicy;
- }
+ * @param specification : service specification (i.e. the interface)
+ * @param factoryPolicy : the facotry policy.
+ */
+ public ProvidedServiceMetadata(String[] specification, int factoryPolicy) {
+ m_serviceSpecification = specification;
+ m_factoryPolicy = factoryPolicy;
+ }
- // GETTERS :
+ // GETTERS :
- /**
- * @return the service specification (i.e. the interface)
- */
- public String[] getServiceSpecification() { return m_serviceSpecification; }
+ /**
+ * @return the service specification (i.e. the interface)
+ */
+ public String[] getServiceSpecification() { return m_serviceSpecification; }
- /**
- * @return the property metadata list.
- */
- public PropertyMetadata[] getProperties() { return m_properties; }
+ /**
+ * @return the property metadata list.
+ */
+ public PropertyMetadata[] getProperties() { return m_properties; }
- /**
- * @return the factory policy.
- */
- public int getFactoryPolicy() { return m_factoryPolicy; }
+ /**
+ * @return the factory policy.
+ */
+ public int getFactoryPolicy() { return m_factoryPolicy; }
- // SETTERS :
+ // SETTERS :
- /**
+ /**
* Add the given property metadata to the property metadata list.
- * @param p : property metdata to add
- */
- protected void addProperty(PropertyMetadata p) {
+ * @param p : property metdata to add
+ */
+ protected void addProperty(PropertyMetadata p) {
for (int i = 0; (m_properties != null) && (i < m_properties.length); i++) {
if (m_properties[i] == p) { return; }
}
@@ -101,8 +97,6 @@
newProp[m_properties.length] = p;
m_properties = newProp;
}
- else {
- m_properties = new PropertyMetadata[] {p};
- }
- }
+ else { m_properties = new PropertyMetadata[] {p}; }
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java b/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
index 04a271e..e484be6 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
@@ -1,22 +1,25 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.parser;
import java.util.Dictionary;
+import java.util.Properties;
import org.apache.felix.ipojo.metadata.Attribute;
import org.apache.felix.ipojo.metadata.Element;
@@ -28,26 +31,52 @@
*/
public class ManifestMetadataParser {
- /**
- * Manifest Headers.
- */
- private Dictionary m_headers;
+ /**
+ * Manifest Headers.
+ */
+ private Dictionary m_headers;
- /**
- * Element list.
- */
- private Element[] m_elements = new Element[0];
+ /**
+ * Element list.
+ */
+ private Element[] m_elements = new Element[0];
/**
* @return the component metadata.
* @throws ParseException when a parsing error occurs
*/
public Element[] getComponentsMetadata() throws ParseException {
- return m_elements[0].getElements("Component");
+ return m_elements[0].getElements("Component");
}
+ /**
+ * @return the instances list.
+ * @throws ParseException : if the metadata cannot be parsed successfully
+ */
+ public Dictionary[] getInstances() throws ParseException {
+ Element[] configs = m_elements[0].getElements("Instance");
+ Dictionary[] dicts = new Dictionary[configs.length];
+ for (int i = 0; i < configs.length; i++) {
+ String comp = configs[i].getAttribute("component"); // get the component targeted by the configuration
+ Dictionary d = new Properties();
+ d.put("component", comp);
+ if (configs[i].getAttribute("name") != null) { d.put("name", configs[i].getAttribute("name")); }
+ for (int j = 0; j < configs[i].getElements("property", "").length; j++) {
+ String propsName = configs[i].getElements("property", "")[j].getAttribute("name", "");
+ String propsValue = configs[i].getElements("property", "")[j].getAttribute("value", "");
+ d.put(propsName, propsValue);
+ }
+ dicts[i] = d;
+ }
+ return dicts;
+ }
+
+ /**
+ * Add an element to the list.
+ * @param elem : the element to add
+ */
private void addElement(Element elem) {
- for (int i = 0; (m_elements != null) && (i < m_elements.length); i++) {
+ for (int i = 0; (m_elements != null) && (i < m_elements.length); i++) {
if (m_elements[i] == elem) { return; }
}
@@ -58,127 +87,135 @@
m_elements = newElementsList;
}
else { m_elements = new Element[] {elem}; }
- }
+ }
+ /**
+ * Remove an element to the list.
+ * @return an element to remove
+ */
private Element removeLastElement() {
- int idx = -1;
- idx = m_elements.length - 1;
- Element last = m_elements[idx];
+ int idx = -1;
+ idx = m_elements.length - 1;
+ Element last = m_elements[idx];
if (idx >= 0) {
if ((m_elements.length - 1) == 0) {
- // It is the last element of the list;
- m_elements = new Element[0];
- }
+ // It is the last element of the list;
+ m_elements = new Element[0];
+ }
else {
- // Remove the last element of the list :
+ // Remove the last element of the list :
Element[] newElementsList = new Element[m_elements.length - 1];
System.arraycopy(m_elements, 0, newElementsList, 0, idx);
m_elements = newElementsList;
}
}
return last;
- }
+ }
- /**
- * Parse the given dictionnary and create the components manager.
- * @param dict : the given headers of the manifest file
- * @throws ParseException : if any error occurs
- */
- public void parse(Dictionary dict) throws ParseException {
- m_headers = dict;
- String componentClassesStr = (String)m_headers.get("iPOJO-Components");
- //Add the ipojo element inside the element list
- addElement(new Element("iPOJO", ""));
- parseElements(componentClassesStr.trim());
+ /**
+ * Parse the given dictionnary and create the components manager.
+ * @param dict : the given headers of the manifest file
+ * @throws ParseException : if any error occurs
+ */
+ public void parse(Dictionary dict) throws ParseException {
+ m_headers = dict;
+ String componentClassesStr = (String) m_headers.get("iPOJO-Components");
+ //Add the ipojo element inside the element list
+ addElement(new Element("iPOJO", ""));
+ parseElements(componentClassesStr.trim());
- }
+ }
- /**
- * Parse the metadata from the string given in argument.
- * @param metadata : the metadata to parse
- * @return Element : the root element resulting of the parsing
- * @throws ParseException : if any error occurs
- */
- public static Element parse(String metadata) throws ParseException {
- ManifestMetadataParser parser = new ManifestMetadataParser();
- parser.parseElements(metadata);
- if (parser.m_elements.length != 1) { throw new ParseException("Error in parsing, root element not found : " + metadata); }
- return parser.m_elements[0];
- }
+ /**
+ * Parse the metadata from the string given in argument.
+ * @param metadata : the metadata to parse
+ * @return Element : the root element resulting of the parsing
+ * @throws ParseException : if any error occurs
+ */
+ public static Element parse(String metadata) throws ParseException {
+ ManifestMetadataParser parser = new ManifestMetadataParser();
+ parser.parseElements(metadata);
+ if (parser.m_elements.length != 1) { throw new ParseException("Error in parsing, root element not found : " + metadata); }
+ return parser.m_elements[0];
+ }
- private void parseElements(String s) {
- char[] string = s.toCharArray();
+ /**
+ * Paser the given string.
+ * @param s : the string to parse
+ */
+ private void parseElements(String s) {
+ char[] string = s.toCharArray();
- for (int i = 0; i < string.length; i++) {
- char c = string[i];
+ for (int i = 0; i < string.length; i++) {
+ char c = string[i];
- switch(c) {
+ switch(c) {
- case '$' :
- String attName = "";
- String attValue = "";
- String attNs = "";
- i++;
- c = string[i];
- while (c != '=') {
- if (c == ':') {
- attNs = attName;
- attName = "";
- } else { attName = attName + c; }
- i = i + 1;
- c = string[i];
- }
- i++; // skip =
- i++; // skip "
- c = string[i];
- while (c != '"') {
- attValue = attValue + c;
- i++;
- c = string[i];
- }
- i++; // skip "
- c = string[i];
+ case '$' :
+ String attName = "";
+ String attValue = "";
+ String attNs = "";
+ i++;
+ c = string[i];
+ while (c != '=') {
+ if (c == ':') {
+ attNs = attName;
+ attName = "";
+ } else { attName = attName + c; }
+ i = i + 1;
+ c = string[i];
+ }
+ i++; // skip =
+ i++; // skip "
+ c = string[i];
+ while (c != '"') {
+ attValue = attValue + c;
+ i++;
+ c = string[i];
+ }
+ i++; // skip "
+ c = string[i];
- Attribute att = new Attribute(attName, attNs , attValue);
- m_elements[m_elements.length - 1].addAttribute(att);
- break;
+ Attribute att = new Attribute(attName, attNs , attValue);
+ m_elements[m_elements.length - 1].addAttribute(att);
+ break;
- case '}' :
- Element lastElement = removeLastElement();
- if (m_elements.length != 0) {
- Element newQueue = m_elements[m_elements.length - 1];
- newQueue.addElement(lastElement);
- }
- else {
- addElement(lastElement);
- }
- break;
- case ' ' : break; // do nothing;
- default :
- String name = "";
- String ns = "";
- c = string[i];
- while (c != ' ') {
- if (c == ':') {
- ns = name;
- name = "";
- i++;
- c = string[i];
- }
- else {
- name = name + c;
- i++;
- c = string[i];
- }
- }
- // Skip spaces
- while (string[i] == ' ') { i = i + 1; }
- i = i + 1; // skip {
- Element elem = new Element(name, ns);
- addElement(elem);
- break;
- }
- }
- }
+ case '}' :
+ Element lastElement = removeLastElement();
+ if (m_elements.length != 0) {
+ Element newQueue = m_elements[m_elements.length - 1];
+ newQueue.addElement(lastElement);
+ }
+ else {
+ addElement(lastElement);
+ }
+ break;
+ case ' ' : break; // do nothing;
+ default :
+ String name = "";
+ String ns = "";
+ c = string[i];
+ while (c != ' ') {
+ if (c == ':') {
+ ns = name;
+ name = "";
+ i++;
+ c = string[i];
+ }
+ else {
+ name = name + c;
+ i++;
+ c = string[i];
+ }
+ }
+ // Skip spaces
+ while (string[i] == ' ') { i = i + 1; }
+ i = i + 1; // skip {
+ Element elem = new Element(name, ns);
+ addElement(elem);
+ break;
+ }
+ }
+ }
}
diff --git a/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseException.java b/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseException.java
index c59afd8..85758c8 100644
--- a/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseException.java
+++ b/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseException.java
@@ -1,18 +1,20 @@
-/*
- * Copyright 2006 The Apache Software Foundation
+/*
+ * 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
*
- * Licensed 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
*
- * 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.
- *
+ * 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.felix.ipojo.parser;