You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2008/03/28 16:35:29 UTC
svn commit: r642265 [9/11] - in /felix/trunk/ipojo: ./ annotations/ ant/
ant/src/main/java/org/apache/felix/ipojo/task/ arch/
arch/src/main/java/org/apache/felix/ipojo/arch/ arch/src/main/resources/
composite/ composite/src/ composite/src/main/ composi...
Copied: felix/trunk/ipojo/extender.pattern.handler/pom.xml (from r640936, felix/sandbox/clement/ipojo/extender.pattern.handler/pom.xml)
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/extender.pattern.handler/pom.xml?p2=felix/trunk/ipojo/extender.pattern.handler/pom.xml&p1=felix/sandbox/clement/ipojo/extender.pattern.handler/pom.xml&r1=640936&r2=642265&rev=642265&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/extender.pattern.handler/pom.xml (original)
+++ felix/trunk/ipojo/extender.pattern.handler/pom.xml Fri Mar 28 08:33:36 2008
@@ -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.
+-->
<project>
<parent>
<artifactId>iPOJO</artifactId>
@@ -47,7 +65,9 @@
org.apache.felix.ipojo.handler.extender
</Private-Package>
<Bundle-Name>${pom.name}</Bundle-Name>
- <Bundle-SymbolicName>org.apache.felix.ipojo.handler.extender.pattern</Bundle-SymbolicName>
+ <Bundle-SymbolicName>
+ org.apache.felix.ipojo.handler.extender.pattern
+ </Bundle-SymbolicName>
</instructions>
</configuration>
</plugin>
@@ -68,17 +88,4 @@
</plugin>
</plugins>
</build>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <configuration>
- <configLocation>
- http://people.apache.org/~clement/styles/checkstyle_ipojo.xml
- </configLocation>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
</project>
Copied: felix/trunk/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java (from r640936, felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java)
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java?p2=felix/trunk/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java&p1=felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java&r1=640936&r2=642265&rev=642265&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java (original)
+++ felix/trunk/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderManager.java Fri Mar 28 08:33:36 2008
@@ -30,15 +30,49 @@
import org.osgi.framework.BundleEvent;
import org.osgi.framework.SynchronousBundleListener;
+/**
+ * Track and manage extensions.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
public class ExtenderManager implements SynchronousBundleListener {
+ /**
+ * Looked extension.
+ */
private String m_extension;
+
+ /**
+ * OnArrival method.
+ */
private Callback m_onArrival;
+
+ /**
+ * OnDeparture method.
+ */
private Callback m_onDeparture;
+
+ /**
+ * Attached handler.
+ */
private PrimitiveHandler m_handler;
+
+ /**
+ * Bundle context.
+ */
private BundleContext m_context;
+
+ /**
+ * List of managed bundles.
+ */
private List m_bundles = new ArrayList();
+ /**
+ * Constructor.
+ * @param handler : attached handler.
+ * @param extension : looked extension.
+ * @param bind : onArrival method
+ * @param unbind : onDeparture method.
+ */
public ExtenderManager(ExtenderModelHandler handler, String extension, String bind, String unbind) {
m_handler = handler;
m_onArrival = new Callback(bind, new Class[] {Bundle.class, String.class}, false, m_handler.getInstanceManager());
@@ -47,6 +81,10 @@
m_context = handler.getInstanceManager().getContext();
}
+ /**
+ * Start method.
+ * Look for already presents bundle and register a (synchronous) bundle listener.
+ */
public void start() {
synchronized (this) {
// listen to any changes in bundles.
@@ -60,9 +98,14 @@
}
}
+ /**
+ * Manage a bundle arrival:
+ * Check the extension and manage it if present.
+ * @param bundle : bundle.
+ */
private void onArrival(Bundle bundle) {
Dictionary headers = bundle.getHeaders();
- String header = (String )headers.get(m_extension);
+ String header = (String) headers.get(m_extension);
if (header != null) {
m_bundles.add(bundle);
try {
@@ -80,11 +123,20 @@
}
}
+ /**
+ * Stop method.
+ * Remove the bundle listener.
+ */
public void stop() {
m_context.removeBundleListener(this);
m_bundles.clear();
}
+ /**
+ * Bundle listener.
+ * @param event : event.
+ * @see org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent)
+ */
public void bundleChanged(BundleEvent event) {
switch (event.getType()) {
case BundleEvent.STARTED:
@@ -99,6 +151,11 @@
}
+ /**
+ * Manage a bundle departure.
+ * If the bundle was managed, invoke the OnDeparture callback, and remove the bundle from the list.
+ * @param bundle : bundle.
+ */
private void onDeparture(Bundle bundle) {
if (m_bundles.contains(bundle)) {
try {
Copied: felix/trunk/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java (from r640936, felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java)
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java?p2=felix/trunk/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java&p1=felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java&r1=640936&r2=642265&rev=642265&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java (original)
+++ felix/trunk/ipojo/extender.pattern.handler/src/main/java/org/apache/felix/ipojo/handler/extender/ExtenderModelHandler.java Fri Mar 28 08:33:36 2008
@@ -26,14 +26,33 @@
import org.apache.felix.ipojo.PrimitiveHandler;
import org.apache.felix.ipojo.metadata.Element;
+/**
+ * Handler automating extender pattern. The component using this handler is notified
+ * when an handler with a special manifest extension is detected, the component is notified.
+ * When a managed handler leaves, the component is also notified.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
public class ExtenderModelHandler extends PrimitiveHandler {
- public final static String NAMESPACE = "org.apache.felix.ipojo.extender";
+ /**
+ * Handler namespace.
+ */
+ public static final String NAMESPACE = "org.apache.felix.ipojo.extender";
+ /**
+ * Extension manager list.
+ */
private List m_managers = new ArrayList(1);
+ /**
+ * Configure method.
+ * @param elem : component type element.
+ * @param dict : instance configuration.
+ * @throws ConfigurationException : the configuration is not valid.
+ * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+ */
public void configure(Element elem, Dictionary dict) throws ConfigurationException {
- Element[] elems = elem.getElements("extender",NAMESPACE);
+ Element[] elems = elem.getElements("extender", NAMESPACE);
for (int i = 0; i < elems.length; i++) {
String extension = elems[i].getAttribute("extension");
String onArrival = elems[i].getAttribute("onArrival");
@@ -52,12 +71,20 @@
}
+ /**
+ * Start the handler.
+ * @see org.apache.felix.ipojo.Handler#start()
+ */
public void start() {
for (int i = 0; i < m_managers.size(); i++) {
((ExtenderManager) m_managers.get(i)).start();
}
}
+ /**
+ * Stop the handler.
+ * @see org.apache.felix.ipojo.Handler#stop()
+ */
public void stop() {
for (int i = 0; i < m_managers.size(); i++) {
((ExtenderManager) m_managers.get(i)).stop();
Propchange: felix/trunk/ipojo/jmx.handler/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Mar 28 08:33:36 2008
@@ -1,3 +1,8 @@
*.patch
.externalToolBuilders
maven-eclipse.xml
+target
+.settings
+.project
+.classpath
+.checkstyle
Modified: felix/trunk/ipojo/jmx.handler/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/jmx.handler/pom.xml?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/jmx.handler/pom.xml (original)
+++ felix/trunk/ipojo/jmx.handler/pom.xml Fri Mar 28 08:33:36 2008
@@ -1,49 +1,53 @@
-<!--
- 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.
--->
+<!--
+ 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.
+-->
<project>
+ <parent>
+ <artifactId>iPOJO</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>0.7.6-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
<modelVersion>4.0.0</modelVersion>
<packaging>bundle</packaging>
- <groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.handler.jmx</artifactId>
- <version>0.7.5-SNAPSHOT</version>
- <name>iPOJO JMX Handler</name>
+ <name>Apache Felix iPOJO JMX Handler</name>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.compendium</artifactId>
- <version>1.0.0</version>
+ <version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.metadata</artifactId>
- <version>0.7.5-SNAPSHOT</version>
+ <version>${pom.version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo</artifactId>
- <version>0.7.5-SNAPSHOT</version>
+ <version>${pom.version}</version>
</dependency>
</dependencies>
@@ -52,7 +56,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.0</version>
+ <version>1.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
@@ -60,7 +64,9 @@
org.apache.felix.ipojo.handlers.jmx
</Private-Package>
<Bundle-Name>${pom.name}</Bundle-Name>
- <Bundle-SymbolicName>ipojo.jmx.handler</Bundle-SymbolicName>
+ <Bundle-SymbolicName>
+ ipojo.jmx.handler
+ </Bundle-SymbolicName>
</instructions>
</configuration>
</plugin>
@@ -73,20 +79,20 @@
</configuration>
</plugin>
<plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-ipojo-plugin</artifactId>
- <version>${pom.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>ipojo-bundle</goal>
- </goals>
- <configuration>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <version>${pom.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ <configuration>
<metadata>metadata.xml</metadata>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
Modified: felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java (original)
+++ felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java Fri Mar 28 08:33:36 2008
@@ -43,6 +43,7 @@
import org.apache.felix.ipojo.InstanceManager;
import org.apache.felix.ipojo.parser.MethodMetadata;
import org.apache.felix.ipojo.util.Callback;
+import org.apache.felix.ipojo.util.Logger;
/**
* this class implements iPOJO DynamicMBean.
@@ -55,24 +56,27 @@
* JmxConfigDFieldMap : store the data extracted from metadata.xml.
*/
private JmxConfigFieldMap m_configMap;
+
/**
* InstanceManager: use to store the InstanceManager instance.
*/
private InstanceManager m_instanceManager;
+
/**
* MBeanInfo : class wich store the MBean Informations.
*/
private MBeanInfo m_mBeanInfo;
+
/**
* String : constant which store the name of the class.
*/
private String m_className = this.getClass().getName();
-
+
/**
* sequenceNumber : use to calculate unique id to notification.
*/
private int m_sequenceNumber = 0;
-
+
/**
* DynamicMBeanImpl : constructor.
* @param properties : data extracted from metadat.xml file
@@ -83,7 +87,7 @@
m_instanceManager = instanceManager;
this.buildMBeanInfo();
}
-
+
/**
* getAttribute implements from JMX.
* get the value of the required attribute
@@ -95,13 +99,14 @@
*/
public Object getAttribute(String arg0) throws AttributeNotFoundException, MBeanException, ReflectionException {
PropertyField attribute = m_configMap.getPropertyFromName(arg0);
-
+
if (attribute == null) {
throw new AttributeNotFoundException(arg0 + " not found");
} else {
return attribute.getValue();
}
}
+
/**
* getAttributes : implement from JMX.
* get values of reuqired attributes
@@ -109,21 +114,22 @@
* @return return the list of the attribute
*/
public AttributeList getAttributes(String[] attributeNames) {
-
+
if (attributeNames == null) {
throw new IllegalArgumentException("attributeNames[] cannot be null");
}
-
+
AttributeList resultList = new AttributeList();
for (int i = 0; i < attributeNames.length; i++) {
PropertyField propertyField = (PropertyField) m_configMap.getPropertyFromField((String) attributeNames[i]);
-
+
if (propertyField != null) {
resultList.add(new Attribute(attributeNames[i], propertyField.getValue()));
}
}
return resultList;
}
+
/**
* getMBeanInfo : return the MBean Class builded.
* @return return MBeanInfo class constructed by buildMBeanInfo
@@ -131,6 +137,7 @@
public MBeanInfo getMBeanInfo() {
return m_mBeanInfo;
}
+
/**
* invoke : invoke the required method on the targeted POJO.
* @param operationName : name of the method called
@@ -159,13 +166,15 @@
e.printStackTrace();
}
} else {
- throw new ReflectionException(new NoSuchMethodException(
- operationName), "Cannot find the operation "
- + operationName + " in " + m_className);
+ throw new ReflectionException(new NoSuchMethodException(operationName), "Cannot find the operation "
+ + operationName
+ + " in "
+ + m_className);
}
-
+
return null;
}
+
/**
* setAttribute : change specified attribute value.
* @param attribute : attribute with new value to be changed
@@ -174,71 +183,68 @@
* @throws MBeanException :
* @throws ReflectionException :
*/
- public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
-
+ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException,
+ ReflectionException {
+
// Check attribute is not null to avoid NullPointerException later on
if (attribute == null) {
- throw new RuntimeOperationsException(new IllegalArgumentException(
- "Attribute cannot be null"), "Cannot invoke a setter of "
- + m_className + " with null attribute");
+ throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Cannot invoke a setter of "
+ + m_className
+ + " with null attribute");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
- throw new RuntimeOperationsException(new IllegalArgumentException(
- "Attribute name cannot be null"),
- "Cannot invoke the setter of " + m_className
- + " with null attribute name");
+ throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot invoke the setter of "
+ + m_className
+ + " with null attribute name");
}
// Check for a recognized attribute name and call the corresponding
// setter
//
-
+
PropertyField propertyField = (PropertyField) m_configMap.getPropertyFromName(name);
if (propertyField == null) {
// unrecognized attribute name:
- throw new AttributeNotFoundException("Attribute " + name
- + " not found in " + m_className);
+ throw new AttributeNotFoundException("Attribute " + name + " not found in " + m_className);
}
if (!propertyField.isWritable()) {
- throw new InvalidAttributeValueException(
- "Attribute " + name + " can not be setted");
+ throw new InvalidAttributeValueException("Attribute " + name + " can not be setted");
}
-
+
if (value == null) {
try {
- m_instanceManager.setterCallback(propertyField.getField(), null);
+ m_instanceManager.onSet(null, propertyField.getField(), null);
} catch (Exception e) {
- throw new InvalidAttributeValueException(
- "Cannot set attribute " + name + " to null");
+ throw new InvalidAttributeValueException("Cannot set attribute " + name + " to null");
}
} else { // if non null value, make sure it is assignable to the attribute
if (true /* TODO type.class.isAssignableFrom(value.getClass())*/) {
//propertyField.setValue(value);
// setValue(attributeField.getField(),null);
- m_instanceManager.setterCallback(propertyField.getField(), value);
+ m_instanceManager.onSet(null, propertyField.getField(), value);
} else {
- throw new InvalidAttributeValueException(
- "Cannot set attribute " + name + " to a "
- + value.getClass().getName()
- + " object, String expected");
+ throw new InvalidAttributeValueException("Cannot set attribute "
+ + name
+ + " to a "
+ + value.getClass().getName()
+ + " object, String expected");
}
}
-
}
+
/**
* setAttributes : change all the attributes value.
* @param attributes : list of attribute value to be changed
* @return AttributeList : list of new attribute
*/
public AttributeList setAttributes(AttributeList attributes) {
-
-// Check attributes is not null to avoid NullPointerException later on
+
+ // Check attributes is not null to avoid NullPointerException later on
if (attributes == null) {
- throw new RuntimeOperationsException(new IllegalArgumentException(
- "AttributeList attributes cannot be null"),
+ throw new RuntimeOperationsException(new IllegalArgumentException("AttributeList attributes cannot be null"),
"Cannot invoke a setter of " + m_className);
}
AttributeList resultList = new AttributeList();
@@ -247,7 +253,7 @@
if (attributes.isEmpty()) {
return resultList;
}
-
+
// for each attribute, try to set it and add to the result list if
// successfull
for (Iterator i = attributes.iterator(); i.hasNext();) {
@@ -263,58 +269,45 @@
}
return resultList;
}
+
/**
- * buildMBeanInfo : buil the MBean information on initilisation.
+ * buildMBeanInfo : build the MBean information on initialization.
* this value don't change after
*/
private void buildMBeanInfo() {
String dDescription = m_configMap.getDecription();
-
+
// generate infos for attributes
MBeanAttributeInfo[] dAttributes = null;
-
+
if (m_configMap == null) {
return;
}
-
+
if (m_configMap.getProperties() != null) {
- List <MBeanAttributeInfo> lAttributes = null;
- lAttributes = new ArrayList <MBeanAttributeInfo> ();
+ List<MBeanAttributeInfo> lAttributes = null;
+ lAttributes = new ArrayList<MBeanAttributeInfo>();
- Iterator <PropertyField> iterator = m_configMap.getProperties().iterator();
+ Iterator<PropertyField> iterator = m_configMap.getProperties().iterator();
while (iterator.hasNext()) {
PropertyField propertyField = (PropertyField) iterator.next();
- lAttributes.add(new MBeanAttributeInfo(
- propertyField.getName(),
- propertyField.getType(),
- propertyField.getDescription(),
- propertyField.isReadable(),
- propertyField.isWritable(),
- false));
+ lAttributes.add(new MBeanAttributeInfo(propertyField.getName(), propertyField.getType(), propertyField.getDescription(),
+ propertyField.isReadable(), propertyField.isWritable(), false));
}
- dAttributes = (MBeanAttributeInfo[]) lAttributes.toArray(new MBeanAttributeInfo[ lAttributes.size() ]);
+ dAttributes = (MBeanAttributeInfo[]) lAttributes.toArray(new MBeanAttributeInfo[lAttributes.size()]);
}
-
-
MBeanOperationInfo[] dOperations = null;
if (m_configMap.getMethods() != null) {
-
- List <MBeanOperationInfo> lOperations = new ArrayList <MBeanOperationInfo>();
-
- Iterator <MethodField[]> iterator = m_configMap.getMethods().iterator();
+
+ List<MBeanOperationInfo> lOperations = new ArrayList<MBeanOperationInfo>();
+
+ Iterator<MethodField[]> iterator = m_configMap.getMethods().iterator();
while (iterator.hasNext()) {
MethodField[] method = (MethodField[]) iterator.next();
- for (int i = 0 ; i < method.length ; i++) {
- lOperations.add(
- new MBeanOperationInfo(
- method[i].getName(),
- method[i].getDescription(),
- method[i].getParams(),
- method[i].getReturnType(),
- MBeanOperationInfo.UNKNOWN
- )
- );
+ for (int i = 0; i < method.length; i++) {
+ lOperations.add(new MBeanOperationInfo(method[i].getName(), method[i].getDescription(), method[i].getParams(), method[i]
+ .getReturnType(), MBeanOperationInfo.UNKNOWN));
}
dOperations = (MBeanOperationInfo[]) lOperations.toArray(new MBeanOperationInfo[lOperations.size()]);
}
@@ -322,10 +315,10 @@
MBeanNotificationInfo[] dNotification = new MBeanNotificationInfo[0];
if (m_configMap.getMethods() != null) {
-
- List <MBeanNotificationInfo> lNotifications = new ArrayList <MBeanNotificationInfo>();
-
- Iterator <NotificationField> iterator = m_configMap.getNotifications().iterator();
+
+ List<MBeanNotificationInfo> lNotifications = new ArrayList<MBeanNotificationInfo>();
+
+ Iterator<NotificationField> iterator = m_configMap.getNotifications().iterator();
while (iterator.hasNext()) {
NotificationField notification = (NotificationField) iterator.next();
lNotifications.add(notification.getNotificationInfo());
@@ -333,13 +326,8 @@
dNotification = (MBeanNotificationInfo[]) lNotifications.toArray(new MBeanNotificationInfo[lNotifications.size()]);
}
- m_mBeanInfo = new MBeanInfo(
- this.m_className,
- dDescription,
- dAttributes,
- null, // No constructor
- dOperations,
- dNotification);
+ m_mBeanInfo = new MBeanInfo(this.m_className, dDescription, dAttributes, null, // No constructor
+ dOperations, dNotification);
}
/**
@@ -349,10 +337,10 @@
public MBeanNotificationInfo[] getNotificationInfo() {
MBeanNotificationInfo[] dNotification = new MBeanNotificationInfo[0];
if (m_configMap.getMethods() != null) {
-
- List < MBeanNotificationInfo> lNotifications = new ArrayList < MBeanNotificationInfo>();
-
- Iterator <NotificationField> iterator = m_configMap.getNotifications().iterator();
+
+ List<MBeanNotificationInfo> lNotifications = new ArrayList<MBeanNotificationInfo>();
+
+ Iterator<NotificationField> iterator = m_configMap.getNotifications().iterator();
while (iterator.hasNext()) {
NotificationField notification = (NotificationField) iterator.next();
lNotifications.add(notification.getNotificationInfo());
@@ -361,7 +349,7 @@
}
return dNotification;
}
-
+
/**
* sendNotification : send a notification to a subscriver.
* @param msg : msg to send
@@ -370,20 +358,17 @@
* @param oldValue : oldvalue of the attribute
* @param newValue : new value of the attribute
*/
- public void sendNotification(String msg, String attributeName,
- String attributeType, Object oldValue, Object newValue) {
+ public void sendNotification(String msg, String attributeName, String attributeType, Object oldValue, Object newValue) {
long timeStamp = System.currentTimeMillis();
-
-
+
if (newValue.equals(oldValue)) {
return;
}
m_sequenceNumber++;
- Notification notification = new AttributeChangeNotification(
- this, m_sequenceNumber, timeStamp,
- msg, attributeName, attributeType, oldValue, newValue);
+ Notification notification =
+ new AttributeChangeNotification(this, m_sequenceNumber, timeStamp, msg, attributeName, attributeType, oldValue, newValue);
sendNotification(notification);
- System.out.println("DEBUG: Notification sent");
+ m_instanceManager.getFactory().getLogger().log(Logger.INFO, "Notification sent");
}
}
Modified: felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/JmxConfigFieldMap.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/JmxConfigFieldMap.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/JmxConfigFieldMap.java (original)
+++ felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/JmxConfigFieldMap.java Fri Mar 28 08:33:36 2008
@@ -228,7 +228,6 @@
return false;
} else {
for (int i = 0; i < sig1.length; i++) {
- //System.out.println(sig1[i] +" == "+ sig2[i]);
if (!sig1[i].equals(sig2[i])) {
return false;
}
Modified: felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java (original)
+++ felix/trunk/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java Fri Mar 28 08:33:36 2008
@@ -27,12 +27,13 @@
import org.apache.felix.ipojo.PrimitiveHandler;
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.FieldMetadata;
-import org.apache.felix.ipojo.parser.ManipulationMetadata;
import org.apache.felix.ipojo.parser.MethodMetadata;
+import org.apache.felix.ipojo.parser.PojoMetadata;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
-/** this class implements iPOJO Handler.
+/**
+ * This class implements iPOJO Handler.
* it builds the dynamic MBean from metadata.xml and expose it to the MBean Server.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
@@ -43,7 +44,7 @@
*/
private InstanceManager m_instanceManager;
/**
- * ServiceRegistration : use to register and deregister the Dynamic MBean.
+ * ServiceRegistration : use to register and unregister the Dynamic MBean.
*/
private ServiceRegistration m_serviceRegistration;
/**
@@ -57,16 +58,16 @@
/**
* String : constant which store the name of the class.
*/
- private String m_NAMESPACE = this.getClass().getName();
+ private String m_namespace = this.getClass().getName();
/**
* configure : construct the structure JmxConfigFieldMap.and the Dynamic Mbean.
* @param metadata Element
- * @param dict Dictionnary
+ * @param dict Dictionary
*/
public void configure(Element metadata, Dictionary dict) {
- ManipulationMetadata manipulation = new ManipulationMetadata(metadata);
+ PojoMetadata manipulation = getPojoMetadata();
m_instanceManager = getInstanceManager();
@@ -74,7 +75,7 @@
m_jmxConfigFieldMap = new JmxConfigFieldMap();
// Build the hashmap
- Element[] mbeans = metadata.getElements("config", m_NAMESPACE);
+ Element[] mbeans = metadata.getElements("config", m_namespace);
if (mbeans.length != 1) { return; }
@@ -83,47 +84,48 @@
// set property
Element[] attributes = mbeans[0].getElements("property");
//String[] fields = new String[attributes.length];
- FieldMetadata[] fields = new FieldMetadata[attributes.length];
- for (int i = 0 ; i < attributes.length ; i++) {
- boolean notif = false;
- String rights;
- String name;
- String field = attributes[i].getAttribute("field");
-
- if (attributes[i].containsAttribute("name")) {
- name = attributes[i].getAttribute("name");
- } else {
- name = field;
- }
- if (attributes[i].containsAttribute("rights")) {
- rights = attributes[i].getAttribute("rights");
- } else {
- rights = "w";
- }
-
- PropertyField property = new PropertyField(name, field, rights, getTypeFromAttributeField(field, manipulation));
-
- if (attributes[i].containsAttribute("notification")) {
- notif = Boolean.parseBoolean(attributes[i].getAttribute("notification"));
- }
-
- property.setNotifiable(notif);
-
- if (notif) {
- //add the new notifiable property in structure
- NotificationField notification = new NotificationField(name, this.getClass().getName() + "." + field, null);
- m_jmxConfigFieldMap.addNotificationFromName(name, notification);
- }
- m_jmxConfigFieldMap.addPropertyFromName(name, property);
- fields[i] = manipulation.getField(field);
- System.out.println("DEBUG: property exposed:" + name + " " + field + ":"
+ if (attributes != null) {
+ for (int i = 0 ; attributes != null && i < attributes.length ; i++) {
+ boolean notif = false;
+ String rights;
+ String name;
+ String field = attributes[i].getAttribute("field");
+
+ if (attributes[i].containsAttribute("name")) {
+ name = attributes[i].getAttribute("name");
+ } else {
+ name = field;
+ }
+ if (attributes[i].containsAttribute("rights")) {
+ rights = attributes[i].getAttribute("rights");
+ } else {
+ rights = "w";
+ }
+
+ PropertyField property = new PropertyField(name, field, rights, getTypeFromAttributeField(field, manipulation));
+
+ if (attributes[i].containsAttribute("notification")) {
+ notif = Boolean.parseBoolean(attributes[i].getAttribute("notification"));
+ }
+
+ property.setNotifiable(notif);
+
+ if (notif) {
+ //add the new notifiable property in structure
+ NotificationField notification = new NotificationField(name, this.getClass().getName() + "." + field, null);
+ m_jmxConfigFieldMap.addNotificationFromName(name, notification);
+ }
+ m_jmxConfigFieldMap.addPropertyFromName(name, property);
+ getInstanceManager().register(manipulation.getField(field), this);
+ info("property exposed:" + name + " " + field + ":"
+ getTypeFromAttributeField(field, manipulation) + " " + rights
+ ", Notif=" + notif);
+ }
}
//set methods
Element[] methods = mbeans[0].getElements("method");
- for (int i = 0 ; i < methods.length ; i++) {
+ for (int i = 0 ; methods != null && i < methods.length ; i++) {
String name = methods[i].getAttribute("name");
String description = null;
if (methods[i].containsAttribute("description")) {
@@ -135,19 +137,16 @@
for (int j = 0 ; j < method.length ; j++) {
m_jmxConfigFieldMap.addMethodFromName(name, method[j]);
- System.out.println("DEBUG: method exposed:" + method[j].getReturnType() + " " + name);
+ info("method exposed:" + method[j].getReturnType() + " " + name);
}
}
-
- m_instanceManager.register(this, fields, null);
}
/**
* start : register the Dynamic Mbean.
*/
public void start() {
-
-// create the corresponding MBean
+ // create the corresponding MBean
m_MBean = new DynamicMBeanImpl(m_jmxConfigFieldMap, m_instanceManager);
if (m_serviceRegistration != null) { m_serviceRegistration.unregister(); }
@@ -163,21 +162,20 @@
}
/**
- * stop : deregister the Dynamic Mbean.
+ * stop : unregister the Dynamic Mbean.
*/
public void stop() {
if (m_serviceRegistration != null) { m_serviceRegistration.unregister(); }
-
-
}
/**
* setterCallback : call when a POJO member is modified externally.
+ * @param pojo : the POJO object
* @param fieldName : name of the modified field
* @param value : new value of the field
*/
- public void setterCallback(String fieldName, Object value) {
+ public void onSet(Object pojo, String fieldName, Object value) {
// Check if the field is a configurable property
PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap.getPropertyFromField(fieldName);
@@ -193,20 +191,20 @@
/**
* getterCallback : call when a POJO member is modified by the MBean.
+ * @pojo : pojo object.
* @param fieldName : name of the modified field
* @param value : old value of the field
* @return : new value of the field
*/
- public Object getterCallback(String fieldName, Object value) {
-
+ public Object onGet(Object pojo, String fieldName, Object value) {
// Check if the field is a configurable property
PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap.getPropertyFromField(fieldName);
if (propertyField != null) {
- m_instanceManager.setterCallback(fieldName, propertyField.getValue());
+ m_instanceManager.onSet(pojo, fieldName, propertyField.getValue());
return propertyField.getValue();
}
- m_instanceManager.setterCallback(fieldName, value);
+ m_instanceManager.onSet(pojo, fieldName, value);
return value;
}
@@ -216,13 +214,13 @@
* @param manipulation : metadata extract from metadata.xml file
* @return : type of the field or null if it wasn't found
*/
- private static String getTypeFromAttributeField(String fieldRequire, ManipulationMetadata manipulation) {
+ private static String getTypeFromAttributeField(String fieldRequire, PojoMetadata manipulation) {
FieldMetadata field = manipulation.getField(fieldRequire);
if (field == null) {
return null;
} else {
- return field.getReflectionType();
+ return FieldMetadata.getReflectionType(field.getFieldType());
}
}
@@ -233,7 +231,7 @@
* @param description : description which appears in jmx console
* @return : array of methods with the right name
*/
- private MethodField[] getMethodsFromName(String methodName, ManipulationMetadata manipulation, String description) {
+ private MethodField[] getMethodsFromName(String methodName, PojoMetadata manipulation, String description) {
MethodMetadata[] fields = manipulation.getMethods(methodName);
if (fields.length == 0) {
Modified: felix/trunk/ipojo/manipulator/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/pom.xml?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/pom.xml (original)
+++ felix/trunk/ipojo/manipulator/pom.xml Fri Mar 28 08:33:36 2008
@@ -1,82 +1,79 @@
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix</artifactId>
- <version>1.0.2</version>
- <relativePath>../../pom/pom.xml</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <packaging>bundle</packaging>
- <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
- <version>0.7.5-SNAPSHOT</version>
- <name>Apache Felix iPOJO Manipulator</name>
-
-
- <dependencies>
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>3.0</version>
- </dependency>
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm-commons</artifactId>
- <version>3.0</version>
- <exclusions>
- <exclusion>
- <groupId>asm</groupId>
- <artifactId>asm-tree</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.ipojo.metadata</artifactId>
- <version>0.7.5-SNAPSHOT</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.0</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Name>iPOJO Manipulator</Bundle-Name>
- <Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
- <Bundle-Description> iPOJO Manipulator </Bundle-Description>
- <Export-Package>org.apache.felix.ipojo.manipulator</Export-Package>
- <Private-Package>
- org.apache.felix.ipojo.manipulation,
- org.apache.felix.ipojo.manipulation.annotations,
- org.apache.felix.ipojo.xml.parser,
- org.objectweb.asm,
- org.objectweb.asm.commons
- </Private-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>iPOJO</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <version>0.7.6-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
+ <name>Apache Felix iPOJO Manipulator</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm-all</artifactId>
+ <version>3.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>asm</groupId>
+ <artifactId>asm-tree</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+ <version>0.7.6-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>iPOJO Manipulator</Bundle-Name>
+ <Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
+ <Bundle-Description>
+ iPOJO Manipulator
+ </Bundle-Description>
+ <Export-Package>
+ org.apache.felix.ipojo.manipulator
+ </Export-Package>
+ <Private-Package>
+ org.apache.felix.ipojo.manipulation,
+ org.apache.felix.ipojo.manipulation.annotations,
+ org.apache.felix.ipojo.xml.parser,
+ org.objectweb.asm, org.objectweb.asm.commons
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java Fri Mar 28 08:33:36 2008
@@ -76,12 +76,14 @@
public FieldVisitor visitField(int access, String name, String desc,
String signature, Object value) {
- if (access == ACC_PRIVATE && name.equals("_cm")
+ if (access == ACC_PRIVATE && name.equals(MethodCreator.IM_FIELD)
&& desc.equals("Lorg/apache/felix/ipojo/InstanceManager;")) {
m_isAlreadyManipulated = true;
} else if (name.startsWith("class$")) { // Does not add class$* field generated by 'x.class'
return null;
- }
+ } else if ((access & ACC_STATIC) == ACC_STATIC) {
+ return null;
+ }
Type type = Type.getType(desc);
if (type.getSort() == Type.ARRAY) {
Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java Fri Mar 28 08:33:36 2008
@@ -23,7 +23,6 @@
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
import org.objectweb.asm.commons.GeneratorAdapter;
@@ -48,11 +47,6 @@
* Set of contained fields.
*/
private Set m_fields;
-
- /**
- * Constructor description.
- */
- private String m_desc;
/**
* PropertyCodeAdapter constructor.
@@ -69,7 +63,6 @@
m_owner = owner;
m_superDetected = false;
m_fields = fields;
- m_desc = desc;
}
@@ -89,12 +82,12 @@
if (m_fields.contains(name) && m_owner.equals(owner)) {
if (opcode == GETFIELD) {
String gDesc = "()" + desc;
- visitMethodInsn(INVOKESPECIAL, owner, "_get" + name, gDesc);
+ visitMethodInsn(INVOKESPECIAL, owner, "__get" + name, gDesc);
return;
} else
if (opcode == PUTFIELD) {
String sDesc = "(" + desc + ")V";
- visitMethodInsn(INVOKESPECIAL, owner, "_set" + name, sDesc);
+ visitMethodInsn(INVOKESPECIAL, owner, "__set" + name, sDesc);
return;
}
}
@@ -124,12 +117,8 @@
//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/InstanceManager;)V");
-
- // Add the entry callback call.
- methodEntry();
+ mv.visitMethodInsn(INVOKESPECIAL, m_owner, "_setInstanceManager", "(Lorg/apache/felix/ipojo/InstanceManager;)V");
- // insertion finished
} else {
mv.visitMethodInsn(opcode, owner, name, desc);
}
@@ -197,101 +186,6 @@
public void visitMaxs(int maxStack, int maxLocals) {
mv.visitMaxs(maxStack + 1, maxLocals + 2);
}
-
- /**
- * Visit zero argument instruction.
- * This allow to catch RETURN instruction in order to insert the invocation to exit callback.
- * @param opcode : instruction code
- * @see org.objectweb.asm.MethodAdapter#visitInsn(int)
- */
- public void visitInsn(int opcode) {
- switch(opcode) {
- case RETURN:
- onMethodExit(opcode);
- break;
- default :
- break;
- }
- super.visitInsn(opcode);
- }
-
- /**
- * Method injecting call at the entry of each method.
- */
- private void methodEntry() {
- Type[] args = Type.getArgumentTypes(m_desc);
- String name = "$init";
-
- for (int i = 0; i < args.length; i++) {
- String cn = args[i].getClassName();
- if (cn.endsWith("[]")) {
- cn = cn.replace('[', '$');
- cn = cn.substring(0, cn.length() - 1);
- }
- cn = cn.replace('.', '_');
- name += cn;
- }
-
- String flag = "_M" + name;
-
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, flag, "Z");
- Label l1 = new Label();
- mv.visitJumpInsn(IFEQ, l1);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
- mv.visitLdcInsn(name);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "entryCallback", "(Ljava/lang/String;)V");
- mv.visitLabel(l1);
- }
-
- /**
- * Method injecting call at the exit of each method.
- * @param opcode : returned opcode (ARETURN, IRETURN, ATHROW ...)
- * @see org.objectweb.asm.commons.AdviceAdapter#onMethodExit(int)
- */
- protected void onMethodExit(int opcode) {
- Type[] args = Type.getArgumentTypes(m_desc);
- String name = "$init";
-
- for (int i = 0; i < args.length; i++) {
- String cn = args[i].getClassName();
- if (cn.endsWith("[]")) {
- cn = cn.replace('[', '$');
- cn = cn.substring(0, cn.length() - 1);
- }
- cn = cn.replace('.', '_');
- name += cn;
- }
-
- String flag = "_M" + name;
-
- int local = newLocal(Type.getType(Object.class));
- local++;
- visitInsn(ACONST_NULL);
-
- mv.visitVarInsn(ASTORE, local);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, flag, "Z");
- Label l5 = new Label();
- mv.visitJumpInsn(IFEQ, l5);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
- mv.visitLdcInsn(name);
- mv.visitVarInsn(ALOAD, local);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "exitCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
-
- mv.visitLabel(l5);
- }
-
-
- /**
- * Do nothing.
- * @see org.objectweb.asm.commons.AdviceAdapter#onMethodEnter()
- */
- protected void onMethodEnter() { }
}
Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java Fri Mar 28 08:33:36 2008
@@ -19,11 +19,8 @@
package org.apache.felix.ipojo.manipulation;
import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -60,73 +57,6 @@
private String m_superClass;
/**
- * Manipulate the class.
- *
- * @param name : The name of the class
- * @param outputDirectory : output directory where the class if stored.
- * @return true if the class is correctly manipulated.
- * @throws Exception : occurs if the manipulation failed.
- */
- public boolean manipulate(String name, File outputDirectory) throws Exception {
- // gets an input stream to read the byte code of the class
- String path = outputDirectory + "/" + name.replace('.', '/') + ".class";
- File clazz = new File(path);
-
- if (!clazz.exists()) {
- return false;
- }
-
- URL url = clazz.toURL();
-
- // if (url == null) { throw new ClassNotFoundException(name); }
- ManipulationProperty.getLogger().log(ManipulationProperty.INFO, "Manipulate the class file : " + clazz.getAbsolutePath());
-
- InputStream is1 = url.openStream();
-
- // First check if the class is already manipulated :
- ClassReader ckReader = new ClassReader(is1);
- ClassChecker ck = new ClassChecker();
- ckReader.accept(ck, ClassReader.SKIP_FRAMES);
- is1.close();
-
- m_fields = ck.getFields(); // Get visited fields (contains only POJO fields)
-
- // Get interfaces and super class.
- m_interfaces = ck.getInterfaces();
- m_superClass = ck.getSuperClass();
-
- // Get the methods list
- m_methods = ck.getMethods();
-
- if (!ck.isalreadyManipulated()) {
-
- // Manipulation ->
- // Add the _setComponentManager method
- // Instrument all fields
- InputStream is2 = url.openStream();
- ClassReader cr0 = new ClassReader(is2);
- ClassWriter cw0 = new ClassWriter(ClassWriter.COMPUTE_MAXS);
- PojoAdapter preprocess = new PojoAdapter(cw0, m_fields);
- cr0.accept(preprocess, ClassReader.SKIP_FRAMES);
- is2.close();
-
- try {
- FileOutputStream fos = new FileOutputStream(clazz);
-
- fos.write(cw0.toByteArray());
-
- fos.close();
- ManipulationProperty.getLogger().log(ManipulationProperty.INFO, "Put the file " + clazz.getAbsolutePath() + " in the jar file");
- } catch (Exception e) {
- System.err.println("Problem to write the adapted class on the file system " + " [ " + clazz.getAbsolutePath() + " ] " + e.getMessage());
- e.printStackTrace();
- }
- }
- // The file is in the bundle
- return true;
- }
-
- /**
* Manipulate the given byte array.
* @param origin : original class.
* @return the manipulated class.
@@ -158,7 +88,8 @@
InputStream is2 = new ByteArrayInputStream(origin);
ClassReader cr0 = new ClassReader(is2);
ClassWriter cw0 = new ClassWriter(ClassWriter.COMPUTE_MAXS);
- PojoAdapter preprocess = new PojoAdapter(cw0, m_fields);
+ //CheckClassAdapter ch = new CheckClassAdapter(cw0);
+ MethodCreator preprocess = new MethodCreator(cw0, m_fields);
cr0.accept(preprocess, ClassReader.SKIP_FRAMES);
is2.close();
finalWriter = cw0;
Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java?rev=642265&r1=642264&r2=642265&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java Fri Mar 28 08:33:36 2008
@@ -20,28 +20,21 @@
import java.util.Set;
-import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
-import org.objectweb.asm.commons.AdviceAdapter;
+import org.objectweb.asm.commons.GeneratorAdapter;
/**
* Insert code calling callbacks at the entry and before the exit of a method.
* Moreover it replaces all GETFIELD and SETFIELD by getter and setter invocation.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class MethodCodeAdapter extends AdviceAdapter implements Opcodes {
+public class MethodCodeAdapter extends GeneratorAdapter implements Opcodes {
/**
* The owner class of the field. m_owner : String
*/
private String m_owner;
-
- /**
- * Name of the method.
- */
- private String m_name;
/**
* Contained fields.
@@ -60,7 +53,6 @@
public MethodCodeAdapter(final MethodVisitor mv, final String owner, int access, String name, String desc, Set fields) {
super(mv, access, name, desc);
m_owner = owner;
- m_name = name;
m_fields = fields;
}
@@ -76,106 +68,15 @@
if (owner.equals(m_owner) && m_fields.contains(name)) {
if (opcode == GETFIELD) {
String gDesc = "()" + desc;
- visitMethodInsn(INVOKESPECIAL, owner, "_get" + name, gDesc);
+ visitMethodInsn(INVOKESPECIAL, owner, "__get" + name, gDesc);
return;
} else if (opcode == PUTFIELD) {
String sDesc = "(" + desc + ")V";
- visitMethodInsn(INVOKESPECIAL, owner, "_set" + name, sDesc);
+ visitMethodInsn(INVOKESPECIAL, owner, "__set" + name, sDesc);
return;
}
}
super.visitFieldInsn(opcode, owner, name, desc);
- }
-
- /**
- * Method injecting call at the entry of each method.
- * @see org.objectweb.asm.commons.AdviceAdapter#onMethodEnter()
- */
- protected void onMethodEnter() {
- Type[] args = Type.getArgumentTypes(methodDesc);
- String name = m_name;
-
- for (int i = 0; i < args.length; i++) {
- String cn = args[i].getClassName();
- if (cn.endsWith("[]")) {
- cn = cn.replace('[', '$');
- cn = cn.substring(0, cn.length() - 1);
- }
- cn = cn.replace('.', '_');
- name += cn;
- }
-
- String flag = "_M" + name;
-
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, flag, "Z");
- Label l1 = new Label();
- mv.visitJumpInsn(IFEQ, l1);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
- mv.visitLdcInsn(name);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "entryCallback", "(Ljava/lang/String;)V");
- mv.visitLabel(l1);
- }
-
- /**
- * Method injecting call at the exit of each method.
- * @param opcode : returned opcode (ARETURN, IRETURN, ATHROW ...)
- * @see org.objectweb.asm.commons.AdviceAdapter#onMethodExit(int)
- */
- protected void onMethodExit(int opcode) {
- Type[] args = Type.getArgumentTypes(methodDesc);
- String name = m_name;
-
- for (int i = 0; i < args.length; i++) {
- String cn = args[i].getClassName();
- if (cn.endsWith("[]")) {
- cn = cn.replace('[', '$');
- cn = cn.substring(0, cn.length() - 1);
- }
- cn = cn.replace('.', '_');
- name += cn;
- }
-
- String flag = "_M" + name;
-
- int local = newLocal(Type.getType(Object.class));
- if (opcode == RETURN) {
- visitInsn(ACONST_NULL);
- } else if (opcode != ARETURN && opcode != ATHROW) {
- box(Type.getReturnType(this.methodDesc));
- }
-
- mv.visitVarInsn(ASTORE, local);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, flag, "Z");
- Label l5 = new Label();
- mv.visitJumpInsn(IFEQ, l5);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
- mv.visitLdcInsn(name);
- mv.visitVarInsn(ALOAD, local);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "exitCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
-
- mv.visitLabel(l5);
- if (opcode == ARETURN || opcode == ATHROW) {
- mv.visitVarInsn(ALOAD, local);
- } else if (opcode != RETURN) {
- mv.visitVarInsn(ALOAD, local);
- unbox(Type.getReturnType(this.methodDesc));
- }
- }
-
- /**
- * Compute max local and max stack size.
- * @param maxStack : new stack size.
- * @param maxLocals : max local (do not modified, super will update it automatically).
- * @see org.objectweb.asm.commons.LocalVariablesSorter#visitMaxs(int, int)
- */
- public void visitMaxs(int maxStack, int maxLocals) {
- super.visitMaxs(maxStack + 1, maxLocals);
}
}