You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by ha...@apache.org on 2004/07/09 00:21:33 UTC
svn commit: rev 22735 - in excalibur/branches/fortress-experiments: container-api container-api/src/java/org/apache/avalon/fortress container-api/src/java/org/apache/avalon/fortress/attributes container-api/src/java/org/apache/avalon/fortress/attributes/qdox container-api/src/test container-api/src/test/org container-api/src/test/org/apache container-api/src/test/org/apache/avalon container-api/src/test/org/apache/avalon/fortress container-api/src/test/org/apache/avalon/fortress/attributes container-api/src/test/org/apache/avalon/fortress/attributes/qdox container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test/data container-impl container-impl/src/java/org/apache/avalon/fortress/impl container-impl/src/java/org/apache/avalon/fortress/impl/handler container-impl/src/java/org/apache/avalon/fortress/impl/interceptor container-impl/src/java/org/apache/avalon/fortress/impl/role container-test container-test/src/test/org/apache/avalon/fortress/impl/interceptor/test container-test/src/test/org/apache/avalon/fortress/impl/interceptor/test/components container-test/src/test/org/apache/avalon/fortress/test/data
Author: hammett
Date: Thu Jul 8 15:21:31 2004
New Revision: 22735
Added:
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/AttributeLevel.java (contents, props changed)
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/qdox/
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/qdox/QDoxSerializer.java (contents, props changed)
excalibur/branches/fortress-experiments/container-api/src/test/
excalibur/branches/fortress-experiments/container-api/src/test/org/
excalibur/branches/fortress-experiments/container-api/src/test/org/apache/
excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/
excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/
excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/
excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/qdox/
excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test/
excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test/QDoxSerializerTestCase.java (contents, props changed)
excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test/data/
excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test/data/Component.java (contents, props changed)
Removed:
excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/interceptor/test/components/test1.xconf
excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/interceptor/test/components/test1.xlog
Modified:
excalibur/branches/fortress-experiments/container-api/project.properties
excalibur/branches/fortress-experiments/container-api/project.xml
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ExtendedMetaInfo.java
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/AttributeInfo.java
excalibur/branches/fortress-experiments/container-impl/project.properties
excalibur/branches/fortress-experiments/container-impl/project.xml
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/InterceptorEnabledContainer.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/interceptor/DefaultInterceptorManager.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/AbstractMetaInfoManager.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/Role2MetaInfoManager.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/ServiceMetaManager.java
excalibur/branches/fortress-experiments/container-test/project.properties
excalibur/branches/fortress-experiments/container-test/project.xml
excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/interceptor/test/DefaultInterceptorManagerTestCase.java
excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/test/data/test1.xconf
Log:
Builds successfully for the first time, since the first time.
+ Extended Metadata facility
Modified: excalibur/branches/fortress-experiments/container-api/project.properties
==============================================================================
--- excalibur/branches/fortress-experiments/container-api/project.properties (original)
+++ excalibur/branches/fortress-experiments/container-api/project.properties Thu Jul 8 15:21:31 2004
@@ -23,3 +23,5 @@
# gump integration
project.name=excalibur-fortress-container-api
+
+maven.junit.fork=true
Modified: excalibur/branches/fortress-experiments/container-api/project.xml
==============================================================================
--- excalibur/branches/fortress-experiments/container-api/project.xml (original)
+++ excalibur/branches/fortress-experiments/container-api/project.xml Thu Jul 8 15:21:31 2004
@@ -44,6 +44,10 @@
<artifactId>d-haven-managed-pool</artifactId>
<version>1.0</version>
</dependency>
+ <dependency>
+ <id>qdox</id>
+ <version>1.2</version>
+ </dependency>
</dependencies>
</project>
Modified: excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ExtendedMetaInfo.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ExtendedMetaInfo.java (original)
+++ excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ExtendedMetaInfo.java Thu Jul 8 15:21:31 2004
@@ -18,9 +18,13 @@
package org.apache.avalon.fortress;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.avalon.fortress.attributes.AttributeInfo;
+import org.apache.avalon.fortress.attributes.AttributeLevel;
/**
* Pending
@@ -29,13 +33,34 @@
*/
public class ExtendedMetaInfo
{
+ private static final AttributeInfo[] EMPTY = new AttributeInfo[0];
+
private final AttributeInfo[] m_classAttributes;
private final Map m_method2Attributes;
- public ExtendedMetaInfo( AttributeInfo[] classAttributes, final Map method2Attributes )
- {
- m_classAttributes = classAttributes;
- m_method2Attributes = method2Attributes;
+ public ExtendedMetaInfo( AttributeInfo[] attributes )
+ {
+ final List classLevel = new ArrayList();
+ m_method2Attributes = new HashMap();
+
+ for (int i = 0; i < attributes.length; i++)
+ {
+ final AttributeInfo attribute = attributes[i];
+
+ if (attribute.getAttributeLevel() == AttributeLevel.ClassLevel)
+ {
+ classLevel.add( attribute );
+ }
+ else if (attribute.getAttributeLevel() == AttributeLevel.MethodLevel)
+ {
+ if (attribute.getMethod() != null)
+ {
+ associateMethodAttribute( attribute );
+ }
+ }
+ }
+
+ m_classAttributes = (AttributeInfo[]) classLevel.toArray( new AttributeInfo[0] );
}
public AttributeInfo[] getClassAttributes()
@@ -45,6 +70,31 @@
public AttributeInfo[] getAttributesForMethod( final Method method )
{
- return (AttributeInfo[]) m_method2Attributes.get( method );
+ List attributes = obtainAttributeList( method );
+
+ if (attributes == null)
+ {
+ return EMPTY;
+ }
+
+ return (AttributeInfo[]) attributes.toArray( new AttributeInfo[0] );
+ }
+
+ private void associateMethodAttribute( AttributeInfo attribute )
+ {
+ List attrs = obtainAttributeList( attribute.getMethod() );
+
+ if (attrs == null)
+ {
+ attrs = new ArrayList();
+ m_method2Attributes.put( attribute.getMethod(), attrs );
+ }
+
+ attrs.add( attribute );
+ }
+
+ private List obtainAttributeList( final Method method )
+ {
+ return (List) m_method2Attributes.get( method );
}
}
Modified: excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/AttributeInfo.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/AttributeInfo.java (original)
+++ excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/AttributeInfo.java Thu Jul 8 15:21:31 2004
@@ -17,6 +17,7 @@
package org.apache.avalon.fortress.attributes;
+import java.lang.reflect.Method;
import java.util.Map;
/**
@@ -28,11 +29,22 @@
{
private final String m_name;
private final Map m_properties;
-
- public AttributeInfo( final String name, final Map properties )
+ private final AttributeLevel m_level;
+ private final Method m_method;
+
+ public AttributeInfo( final String name, final Map properties,
+ final AttributeLevel level, final Method method )
{
m_name = name;
m_properties = properties;
+ m_level = level;
+ m_method = method;
+ }
+
+ public AttributeInfo( final String name, final Map properties,
+ final AttributeLevel level )
+ {
+ this( name, properties, level, null );
}
public String getName()
@@ -43,5 +55,25 @@
public Map getProperties()
{
return m_properties;
+ }
+
+ /**
+ * Pending
+ *
+ * @return
+ */
+ public AttributeLevel getAttributeLevel()
+ {
+ return m_level;
+ }
+
+ /**
+ * Pending
+ *
+ * @return
+ */
+ public Method getMethod()
+ {
+ return m_method;
}
}
Added: excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/AttributeLevel.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/AttributeLevel.java Thu Jul 8 15:21:31 2004
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004 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.avalon.fortress.attributes;
+
+/**
+ * Pending
+ *
+ * @author <a href="mailto:dev@excalibur.apache.org">Excalibur Development Team</a>
+ */
+public final class AttributeLevel
+{
+ public static final AttributeLevel Undefined = new AttributeLevel(0);
+
+ public static final AttributeLevel MethodLevel = new AttributeLevel(1);
+
+ public static final AttributeLevel ClassLevel = new AttributeLevel(2);
+
+ private final int m_level;
+
+ private AttributeLevel(int level)
+ {
+ m_level = level;
+ }
+
+ public int getLevel()
+ {
+ return m_level;
+ }
+
+ /**
+ * Pending
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj)
+ {
+ if ( obj instanceof AttributeLevel == false )
+ {
+ return false;
+ }
+
+ return obj.hashCode() == obj.hashCode();
+ }
+
+ /**
+ * Pending
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return m_level;
+ }
+}
Added: excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/qdox/QDoxSerializer.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/attributes/qdox/QDoxSerializer.java Thu Jul 8 15:21:31 2004
@@ -0,0 +1,328 @@
+/*
+ * Copyright 2004 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.avalon.fortress.attributes.qdox;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.avalon.fortress.ExtendedMetaInfo;
+import org.apache.avalon.fortress.attributes.AttributeInfo;
+import org.apache.avalon.fortress.attributes.AttributeLevel;
+
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaMethod;
+import com.thoughtworks.qdox.model.JavaParameter;
+
+/**
+ * Implements a serialization and deserialization
+ * mechanism for QDox
+ *
+ * @author <a href="mailto:dev@excalibur.apache.org">Excalibur Development Team</a>
+ */
+public class QDoxSerializer
+{
+ private static final QDoxSerializer m_instance = new QDoxSerializer();
+
+ private QDoxSerializer()
+ {
+ }
+
+ public static QDoxSerializer instance()
+ {
+ return m_instance;
+ }
+
+ public void serialize( final ObjectOutputStream stream, final JavaClass clazz )
+ throws IOException
+ {
+ DocletTag[] tags = clazz.getTags();
+
+ for (int i = 0; i < tags.length; i++)
+ {
+ DocletTag tag = tags[i];
+
+ if (tag.getName().equalsIgnoreCase("author"))
+ {
+ continue;
+ }
+
+ stream.writeInt( 1 );
+ QDoxSerializer.instance().serialize( stream, tag );
+ }
+
+ // TODO: Do we need to inspect super classes?
+ final JavaMethod[] methods = clazz.getMethods();
+
+ for ( int i = 0; i < methods.length; i++ )
+ {
+ JavaMethod method = methods[i];
+ tags = method.getTags();
+
+ if (tags.length == 0)
+ {
+ continue;
+ }
+
+ for (int j = 0; j < tags.length; j++)
+ {
+ DocletTag tag = tags[j];
+ stream.writeInt( 1 );
+ QDoxSerializer.instance().serialize( stream, method, tag );
+ }
+ }
+
+ stream.writeInt( 0 );
+ }
+
+ public ExtendedMetaInfo deserialize( final InputStream stream, final Class target )
+ throws IOException
+ {
+ final MethodInfoHelper methodHelper = new MethodInfoHelper( target );
+
+ final ObjectInputStream inStream = new ObjectInputStream( stream );
+
+ final List attributes = new ArrayList();
+
+ try
+ {
+ while ( inStream.readInt() == 1 )
+ {
+ QDoxSerializer.TagInfo info = QDoxSerializer.instance().deserialize( inStream );
+
+ if (info == null)
+ {
+ continue;
+ }
+
+ AttributeInfo attribute = null;
+
+ if (info.getMethod() != null)
+ {
+ attribute = buildAttributeInfoForMethod( info, methodHelper );
+ }
+ else
+ {
+ attribute = buildAttributeInfoForClass( info );
+ }
+
+ attributes.add( attribute );
+ }
+ }
+ catch(ClassNotFoundException ex)
+ {
+ // is ignoring a good strategy? Don't think so
+ // but let's sticky with it at the moment.
+ }
+ finally
+ {
+ inStream.close();
+ }
+
+ AttributeInfo[] attrs = (AttributeInfo[]) attributes.toArray( new AttributeInfo[0] );
+
+ return new ExtendedMetaInfo( attrs );
+ }
+
+ public void serialize( final ObjectOutputStream stream, final DocletTag tag )
+ throws IOException
+ {
+ serialize( stream, null, tag );
+ }
+
+ public void serialize( final ObjectOutputStream stream, final JavaMethod method, final DocletTag tag )
+ throws IOException
+ {
+ stream.writeObject( new TagInfo( tag, method ) );
+ }
+
+ private TagInfo deserialize( final ObjectInputStream stream )
+ throws IOException, ClassNotFoundException
+ {
+ return (TagInfo) stream.readObject();
+ }
+
+ private static AttributeInfo buildAttributeInfoForMethod( final QDoxSerializer.TagInfo info,
+ final MethodInfoHelper methodHelper )
+ {
+ Method classMethod = methodHelper.obtainRealMethod( info.getMethod() );
+
+ return new AttributeInfo( info.getTag().getName(), buildAttributes( info ),
+ AttributeLevel.MethodLevel, classMethod );
+ }
+
+ private static AttributeInfo buildAttributeInfoForClass( final QDoxSerializer.TagInfo info )
+ {
+ return new AttributeInfo( info.getTag().getName(), buildAttributes( info ),
+ AttributeLevel.ClassLevel );
+ }
+
+ private static Map buildAttributes( final QDoxSerializer.TagInfo info )
+ {
+ Map parameters = Collections.EMPTY_MAP;
+
+ String[] params = info.getTag().getParameters();
+
+ if (params.length != 0)
+ {
+ parameters = new TreeMap( String.CASE_INSENSITIVE_ORDER );
+
+ for (int i = 0; i < params.length; i++)
+ {
+ final String property = params[i];
+ final int equalIndex = property.indexOf( '=' );
+
+ String key = property;
+ String value = "";
+
+ if ( equalIndex != -1 )
+ {
+ key = property.substring( 0, equalIndex );
+ value = property.substring( equalIndex + 1 );
+ }
+
+ parameters.put( key, value );
+ }
+ }
+
+ return parameters;
+ }
+
+ public static class TagInfo implements Serializable
+ {
+ private final DocletTag m_tag;
+ private final JavaMethod m_method;
+
+ public TagInfo( final DocletTag tag, final JavaMethod method )
+ {
+ m_tag = tag;
+ m_method = method;
+ }
+
+ public DocletTag getTag()
+ {
+ return m_tag;
+ }
+
+ public JavaMethod getMethod()
+ {
+ return m_method;
+ }
+ }
+
+ /**
+ * Pending
+ *
+ * @author hammett
+ */
+ public static class MethodInfoHelper
+ {
+ private final Map m_key2Method = new HashMap();
+
+ /**
+ * Pending
+ *
+ * @param class1
+ */
+ public MethodInfoHelper(Class targetClass)
+ {
+ final Method[] methods = targetClass.getMethods();
+
+ for (int i = 0; i < methods.length; i++)
+ {
+ Method method = methods[i];
+ m_key2Method.put( buildKey( method ), method );
+ }
+ }
+
+ /**
+ * Pending
+ *
+ * @param javaMethod
+ * @return
+ */
+ public Method obtainRealMethod( JavaMethod javaMethod )
+ {
+ return (Method) m_key2Method.get( buildKey( javaMethod ) );
+ }
+
+ /**
+ * Pending
+ *
+ * @param method
+ * @return
+ */
+ private String buildKey(final Method method)
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append( method.getReturnType().getName() );
+ sb.append( ' ' );
+ sb.append( method.getDeclaringClass().getName() );
+ sb.append( ' ' );
+ sb.append( method.getName() );
+
+ Class[] parameters = method.getParameterTypes();
+
+ for (int i = 0; i < parameters.length; i++)
+ {
+ Class parameter = parameters[i];
+ sb.append( ' ' );
+ sb.append( parameter.getName() );
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Pending
+ *
+ * @param method
+ * @return
+ */
+ private String buildKey(final JavaMethod method)
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append( method.getReturns().getValue() );
+ sb.append( ' ' );
+ sb.append( method.getParentClass().getFullyQualifiedName() );
+ sb.append( ' ' );
+ sb.append( method.getName() );
+
+ JavaParameter[] parameters = method.getParameters();
+
+ for (int i = 0; i < parameters.length; i++)
+ {
+ JavaParameter parameter = parameters[i];
+ sb.append( ' ' );
+ sb.append( parameter.getType().getValue() );
+ }
+
+ return sb.toString();
+ }
+ }
+}
Added: excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test/QDoxSerializerTestCase.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test/QDoxSerializerTestCase.java Thu Jul 8 15:21:31 2004
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2004 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.avalon.fortress.attributes.qdox.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Method;
+
+import org.apache.avalon.fortress.ExtendedMetaInfo;
+import org.apache.avalon.fortress.attributes.AttributeInfo;
+import org.apache.avalon.fortress.attributes.qdox.QDoxSerializer;
+import org.apache.avalon.fortress.attributes.qdox.test.data.Component;
+
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.JavaClass;
+
+import junit.framework.TestCase;
+
+/**
+ * Pending
+ *
+ * @author <a href="mailto:dev@excalibur.apache.org">Excalibur Development Team</a>
+ */
+public class QDoxSerializerTestCase extends TestCase
+{
+ /**
+ * Constructor for QDoxSerializerTestCase.
+ * @param name
+ */
+ public QDoxSerializerTestCase(String name)
+ {
+ super(name);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public void testInstance()
+ {
+ assertNotNull( QDoxSerializer.instance() );
+ }
+
+ /*
+ * Test for void serialize(ObjectOutputStream, JavaClass)
+ */
+ public void testSerializeDeserialize()
+ throws Exception
+ {
+ JavaClass clazz = createJavaClass();
+ assertNotNull( clazz );
+
+ /// Serialization
+ ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
+ ObjectOutputStream outStream = new ObjectOutputStream( byteOutStream );
+
+ QDoxSerializer.instance().serialize( outStream, clazz );
+ outStream.close();
+ byteOutStream.close();
+
+ assertTrue( byteOutStream.size() != 0 );
+
+ /// Deserialization
+ ByteArrayInputStream byteInStream = new ByteArrayInputStream( byteOutStream.toByteArray() );
+
+ ExtendedMetaInfo extendedInfo = QDoxSerializer.instance().deserialize( byteInStream, Component.class );
+ assertNotNull( extendedInfo );
+
+ /// Assertions
+ assertExtendedInfo(extendedInfo);
+ }
+
+ public void testSerializeDeserializeWithFile()
+ throws Exception
+ {
+ JavaClass clazz = createJavaClass();
+ assertNotNull( clazz );
+
+ /// Serialization
+ File targetFile = new File("./data.attrs");
+ targetFile.deleteOnExit();
+
+ FileOutputStream fsOutStream = new FileOutputStream( targetFile );
+ ObjectOutputStream outStream = new ObjectOutputStream( fsOutStream );
+
+ QDoxSerializer.instance().serialize( outStream, clazz );
+ outStream.close();
+ fsOutStream.close();
+
+ /// Deserialization
+ FileInputStream fsInStream = new FileInputStream( targetFile );
+
+ ExtendedMetaInfo extendedInfo = QDoxSerializer.instance().deserialize( fsInStream, Component.class );
+ assertNotNull( extendedInfo );
+
+ /// Assertions
+ assertExtendedInfo(extendedInfo);
+ }
+
+ private void assertExtendedInfo(ExtendedMetaInfo extendedInfo) throws SecurityException
+ {
+ AttributeInfo[] classAttrs = extendedInfo.getClassAttributes();
+ assertNotNull( classAttrs );
+ assertEquals( 3, classAttrs.length );
+
+ Method[] methods = Component.class.getDeclaredMethods();
+
+ for (int i = 0; i < methods.length; i++)
+ {
+ Method method = methods[i];
+ AttributeInfo[] methodAttrs = extendedInfo.getAttributesForMethod( method );
+ assertNotNull( methodAttrs );
+ assertEquals( 1, methodAttrs.length );
+ }
+ }
+
+ private JavaClass createJavaClass() throws FileNotFoundException
+ {
+ JavaDocBuilder builder = new JavaDocBuilder();
+ builder.addSource(new File("src/test/org/apache/avalon/fortress/attributes/qdox/test/data/Component.java"));
+ JavaClass clazz = builder.getClassByName( Component.class.getName() );
+ return clazz;
+ }
+}
Added: excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test/data/Component.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/container-api/src/test/org/apache/avalon/fortress/attributes/qdox/test/data/Component.java Thu Jul 8 15:21:31 2004
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004 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.avalon.fortress.attributes.qdox.test.data;
+
+/**
+ * @attribute1
+ * @attribute2 type=MailService
+ * @attribute3 type=MailService inheritable=false
+ */
+public class Component
+{
+ /**
+ * @passthrought
+ */
+ public void someMethod( int value )
+ {
+ }
+
+ /**
+ * @security.enabled
+ */
+ public String someOtherMethod( int value, int factor )
+ {
+ return "";
+ }
+}
Modified: excalibur/branches/fortress-experiments/container-impl/project.properties
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/project.properties (original)
+++ excalibur/branches/fortress-experiments/container-impl/project.properties Thu Jul 8 15:21:31 2004
@@ -23,3 +23,5 @@
# gump integration
project.name=excalibur-fortress-container-impl
+
+maven.junit.fork=true
Modified: excalibur/branches/fortress-experiments/container-impl/project.xml
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/project.xml (original)
+++ excalibur/branches/fortress-experiments/container-impl/project.xml Thu Jul 8 15:21:31 2004
@@ -98,6 +98,10 @@
<id>excalibur-sourceresolve</id>
<version>2.0</version>
</dependency>
+ <dependency>
+ <id>qdox</id>
+ <version>1.2</version>
+ </dependency>
<dependency>
<groupId>excalibur-lifecycle</groupId>
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/InterceptorEnabledContainer.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/InterceptorEnabledContainer.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/InterceptorEnabledContainer.java Thu Jul 8 15:21:31 2004
@@ -23,7 +23,9 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.DefaultContext;
/**
* InterceptorEnabledContainer extends the default container behavior
@@ -65,6 +67,19 @@
///
/// DefaultContainer's overrides
///
+
+ /**
+ * Pending
+ *
+ * @see org.apache.avalon.fortress.impl.AbstractContainer#provideComponentContext(org.apache.avalon.framework.context.Context)
+ */
+ protected Context provideComponentContext(Context parent) throws Exception
+ {
+ DefaultContext context = new DefaultContext( parent );
+ context.put( "container", this );
+ context.makeReadOnly();
+ return context;
+ }
/**
* Avoid the registration of interceptorManager configuration node.
@@ -136,10 +151,19 @@
{
InterceptorManager manager = createInterceptorManager();
ContainerUtil.configure( manager, m_managerConfiguration );
+ m_manager = manager;
}
protected InterceptorManager createInterceptorManager() throws ContextException
{
- return new DefaultInterceptorManager( m_context );
+ try
+ {
+ return new DefaultInterceptorManager( provideComponentContext( m_context ) );
+ }
+ catch(Exception ex)
+ {
+ throw new ContextException( "Error creating context for InterceptorManager", ex );
+ }
}
+
}
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java Thu Jul 8 15:21:31 2004
@@ -103,7 +103,7 @@
private ClassInfo m_classinfo;
/** Use the dynamic configuration */
- private final boolean m_useDynamicCreation = true;
+ private final boolean m_useDynamicCreation = false;
/**
* Construct a new component factory for the specified component.
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/interceptor/DefaultInterceptorManager.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/interceptor/DefaultInterceptorManager.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/interceptor/DefaultInterceptorManager.java Thu Jul 8 15:21:31 2004
@@ -232,7 +232,7 @@
{
Interceptor tail = createTailInterceptor( interceptors );
- for (int i = interceptors.length; i >= 0; i--)
+ for (int i = interceptors.length - 1; i >= 0; i--)
{
Interceptor last = interceptors[i];
last.init( tail );
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/AbstractMetaInfoManager.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/AbstractMetaInfoManager.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/AbstractMetaInfoManager.java Thu Jul 8 15:21:31 2004
@@ -24,7 +24,6 @@
import org.apache.avalon.fortress.attributes.AttributeInfo;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -62,7 +61,7 @@
static
{
- EMPTY_EXTENDED_META_INFO = new ExtendedMetaInfo( new AttributeInfo[0], Collections.EMPTY_MAP );
+ EMPTY_EXTENDED_META_INFO = new ExtendedMetaInfo( new AttributeInfo[0] );
}
/**
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/Role2MetaInfoManager.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/Role2MetaInfoManager.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/Role2MetaInfoManager.java Thu Jul 8 15:21:31 2004
@@ -17,6 +17,7 @@
package org.apache.avalon.fortress.impl.role;
+import org.apache.avalon.fortress.ExtendedMetaInfo;
import org.apache.avalon.fortress.MetaInfoEntry;
import org.apache.avalon.fortress.MetaInfoManager;
import org.apache.avalon.fortress.RoleEntry;
@@ -88,5 +89,16 @@
{
return null != m_parent ? m_parent.getMetaInfoForClassname( classname ) : null;
}
+ }
+
+ /**
+ * Pending
+ *
+ * @see org.apache.avalon.fortress.MetaInfoManager#getExtendedMetaInfo(java.lang.String)
+ */
+ public ExtendedMetaInfo getExtendedMetaInfo(String classname)
+ {
+ return null != m_parent ?
+ m_parent.getExtendedMetaInfo( classname ) : AbstractMetaInfoManager.EMPTY_EXTENDED_META_INFO;
}
}
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/ServiceMetaManager.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/ServiceMetaManager.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/role/ServiceMetaManager.java Thu Jul 8 15:21:31 2004
@@ -21,7 +21,7 @@
import org.apache.avalon.fortress.MetaInfoEntry;
import org.apache.avalon.fortress.MetaInfoManager;
import org.apache.avalon.fortress.RoleManager;
-import org.apache.avalon.fortress.attributes.AttributeInfo;
+import org.apache.avalon.fortress.attributes.qdox.QDoxSerializer;
import org.apache.avalon.fortress.util.Service;
import org.apache.avalon.framework.activity.Initializable;
@@ -84,18 +84,8 @@
*/
public final class ServiceMetaManager extends AbstractMetaInfoManager implements Initializable
{
-
- /**
- * Pending
- *
- * @param stream
- * @param entry
- */
- public static void buildExtendedMeta(InputStream stream, MetaInfoEntry entry)
- {
- // TODO Auto-generated method stub
-
- }
+ private final Map m_class2ExtendedInfo = new HashMap();
+
/**
* Create a ServiceMetaManager.
*/
@@ -280,18 +270,26 @@
{
final InputStream stream =
getLoader().getResourceAsStream( getAttributesFile( implementation ) );
+
+ if (stream == null)
+ {
+ // Backward compatibility: do nothing
+ return;
+ }
MetaInfoEntry entry = getMetaInfoForClassname( implementation );
- AttributeDigester.buildExtendedMeta( stream, entry );
+ ExtendedMetaInfo extendedInfo =
+ QDoxSerializer.instance().deserialize( stream, entry.getComponentClass() );
stream.close();
+
+ registerExtendedInfo( implementation, extendedInfo );
}
catch ( IOException ioe )
{
getLogger().error( "Could not load meta information for " +
implementation + ", skipping this class." );
- return;
}
}
@@ -334,6 +332,11 @@
return entry;
}
+ private void registerExtendedInfo( final String classname, final ExtendedMetaInfo extendedInfo )
+ {
+ m_class2ExtendedInfo.put( classname, extendedInfo );
+ }
+
/**
* Read entries in a list file and add them all to the provided Set.
*
@@ -359,113 +362,6 @@
finally
{
reader.close();
- }
- }
-
- public static class AttributeDigester
- {
- /**
- * Pending
- *
- * @param stream
- * @param entry
- */
- public static ExtendedMetaInfo buildExtendedMeta(InputStream stream, MetaInfoEntry entry)
- throws IOException
- {
- ExtendedMetaInfo metaInfo = null;
-
- final BufferedReader reader = new BufferedReader( new InputStreamReader( stream ) );
-
- final List classAttrs = new ArrayList();
- final Map method2Attributes = new HashMap();
-
- String line = null;
- while( ( line = reader.readLine() ) != null )
- {
- if (line.length() == 0)
- {
- continue;
- }
-
- if (line.charAt(0) != '{')
- {
- classAttrs.add( buildClassAttribute( line, entry ) );
- }
- else
- {
- buildMethodAttribute( line, entry );
- }
- }
-
- AttributeInfo[] classAttributes = (AttributeInfo[])
- classAttrs.toArray( new AttributeInfo[0] );
-
- metaInfo = new ExtendedMetaInfo( classAttributes, methodAttributes );
-
- reader.close();
- }
-
- private static AttributeInfo buildMethodAttribute( final String line, final MetaInfoEntry entry )
- {
- final Map mapProperties = new TreeMap( String.CASE_INSENSITIVE_ORDER );
-
- int propInitIndex = line.indexOf( '[' );
- int propEndIndex = line.indexOf( ']' );
-
- final String attName = line.substring(0, propInitIndex - 1);
- final String properties = line.substring(propInitIndex, propEndIndex - 1).trim();
-
- StringTokenizer tokenizer = new StringTokenizer( properties, "," );
- while(tokenizer.hasMoreTokens())
- {
- final String property = tokenizer.nextToken();
- final int equalIndex = property.indexOf( '=' );
-
- String key = property;
- String value = "";
-
- if ( equalIndex != -1 )
- {
- key = property.substring( 0, equalIndex );
- value = property.substring( equalIndex + 1 );
- }
-
- mapProperties.put( key, value );
- }
-
- return new AttributeInfo( attName, mapProperties );
- }
-
- private static AttributeInfo buildClassAttribute( final String line, final MetaInfoEntry entry )
- {
- final Map mapProperties = new TreeMap( String.CASE_INSENSITIVE_ORDER );
-
- int propInitIndex = line.indexOf( '[' );
- int propEndIndex = line.indexOf( ']' );
-
- final String attName = line.substring(0, propInitIndex - 1);
- final String properties = line.substring(propInitIndex, propEndIndex - 1).trim();
-
- StringTokenizer tokenizer = new StringTokenizer( properties, "," );
- while(tokenizer.hasMoreTokens())
- {
- final String property = tokenizer.nextToken();
- final int equalIndex = property.indexOf( '=' );
-
- String key = property;
- String value = "";
-
- if ( equalIndex != -1 )
- {
- key = property.substring( 0, equalIndex );
- value = property.substring( equalIndex + 1 );
- }
-
- mapProperties.put( key, value );
- }
-
- return new AttributeInfo( attName, mapProperties );
}
}
}
Modified: excalibur/branches/fortress-experiments/container-test/project.properties
==============================================================================
--- excalibur/branches/fortress-experiments/container-test/project.properties (original)
+++ excalibur/branches/fortress-experiments/container-test/project.properties Thu Jul 8 15:21:31 2004
@@ -23,3 +23,5 @@
# gump integration
project.name=excalibur-fortress-container-test
+
+maven.junit.fork=true
\ No newline at end of file
Modified: excalibur/branches/fortress-experiments/container-test/project.xml
==============================================================================
--- excalibur/branches/fortress-experiments/container-test/project.xml (original)
+++ excalibur/branches/fortress-experiments/container-test/project.xml Thu Jul 8 15:21:31 2004
@@ -60,6 +60,10 @@
<version>2.1</version>
</dependency>
<dependency>
+ <id>commons-logging</id>
+ <version>1.0.3</version>
+ </dependency>
+ <dependency>
<id>commons-beanutils</id>
<version>1.6.1</version>
</dependency>
Modified: excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/interceptor/test/DefaultInterceptorManagerTestCase.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/interceptor/test/DefaultInterceptorManagerTestCase.java (original)
+++ excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/impl/interceptor/test/DefaultInterceptorManagerTestCase.java Thu Jul 8 15:21:31 2004
@@ -108,7 +108,7 @@
config.setContextDirectory( "./" );
config.setWorkDirectory( "./" );
- final String BASE = "resource://org/apache/avalon/fortress/impl/interceptor/test/components/";
+ final String BASE = "resource://org/apache/avalon/fortress/test/data/";
config.setContainerConfiguration( BASE + "test1.xconf" );
config.setLoggerManagerConfiguration( BASE + "test1.xlog" );
Modified: excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/test/data/test1.xconf
==============================================================================
--- excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/test/data/test1.xconf (original)
+++ excalibur/branches/fortress-experiments/container-test/src/test/org/apache/avalon/fortress/test/data/test1.xconf Thu Jul 8 15:21:31 2004
@@ -28,5 +28,8 @@
<component4 id="component4"
logger="component4"
activation="startup"/>
+ <customerDAO id="customerDAO"
+ logger="customerDAO"
+ activation="lazy"/>
</test>
---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org
Re: Attribute toolkit?
Posted by hammett <ha...@uol.com.br>.
Ok, avoding the NIH anti-pattern I've decided to use the Metaclass project.
However I haven't changed the Meta collector code as it must be backward
compatible. The AttributeInfo and ExtendedAttribute stills there and
intended to be a façade for the underlying API - in this case Metaclass and
QDox.
Cheers,
hammett
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
For additional commands, e-mail: dev-help@excalibur.apache.org
Apache Excalibur Project -- URL: http://excalibur.apache.org/
Re: Attribute toolkit?
Posted by hammett <ha...@uol.com.br>.
----- Original Message -----
From: "Peter Donald" <pe...@realityforge.org>
> It looks like you are writing a runtime attribute toolkit.
> Have you considered using one of the existing ones such as
> metaclass? This is the one we use over at loom.
That could be nice, but I only extended the qdox usage while at the same
time allowed people to
use another meta implementation like commons-attributes or other.
It was based on a very old suggestion from LSD
http://www.jroller.com/comments/lsd?anchor=rethinking_attributes
The good think is that fortress will enable attributes to be used by
component developers.
Cheers,
hammett
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
For additional commands, e-mail: dev-help@excalibur.apache.org
Apache Excalibur Project -- URL: http://excalibur.apache.org/
Attribute toolkit?
Posted by Peter Donald <pe...@realityforge.org>.
Hi Hammet,
It looks like you are writing a runtime attribute toolkit.
Have you considered using one of the existing ones such as
metaclass? This is the one we use over at loom.
http://metaclass.codehaus.org
--
Cheers,
Peter Donald
"I am not young enough to know everything."
- Oscar Wilde (1854-1900)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
For additional commands, e-mail: dev-help@excalibur.apache.org
Apache Excalibur Project -- URL: http://excalibur.apache.org/