Skip to Content.
Sympa Menu

notify-dpml - r1039 - in trunk/main/metro: model/src/main/net/dpml/metro/info model/src/test/net/dpml/metro/info/test tools/src/main/net/dpml/metro/tools

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1039 - in trunk/main/metro: model/src/main/net/dpml/metro/info model/src/test/net/dpml/metro/info/test tools/src/main/net/dpml/metro/tools
  • Date: Sun, 5 Feb 2006 18:38:38 +0100

Author: mcconnell
Date: 2006-02-05 18:38:29 +0100 (Sun, 05 Feb 2006)
New Revision: 1039

Added:
trunk/main/metro/model/src/main/net/dpml/metro/info/ThreadSafePolicy.java

trunk/main/metro/model/src/main/net/dpml/metro/info/ThreadSafePolicyBeanInfo.java
Modified:
trunk/main/metro/model/src/main/net/dpml/metro/info/InfoDescriptor.java

trunk/main/metro/model/src/main/net/dpml/metro/info/InfoDescriptorBeanInfo.java
trunk/main/metro/model/src/main/net/dpml/metro/info/Type.java

trunk/main/metro/model/src/test/net/dpml/metro/info/test/InfoDescriptorTestCase.java
trunk/main/metro/model/src/test/net/dpml/metro/info/test/TypeTestCase.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/CatalogTask.java
trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
Log:
move thread-safe policy from boolean to TRUE | FALSE | UNKNOWN

Modified:
trunk/main/metro/model/src/main/net/dpml/metro/info/InfoDescriptor.java
===================================================================
--- trunk/main/metro/model/src/main/net/dpml/metro/info/InfoDescriptor.java
2006-02-05 16:59:31 UTC (rev 1038)
+++ trunk/main/metro/model/src/main/net/dpml/metro/info/InfoDescriptor.java
2006-02-05 17:38:29 UTC (rev 1039)
@@ -93,9 +93,9 @@
private final CollectionPolicy m_collection;

/**
- * Flag indicating if the type is threadsafe.
+ * Threadsafe policy.
*/
- private final boolean m_threadsafe;
+ private final ThreadSafePolicy m_threadsafe;


//-------------------------------------------------------------------
@@ -114,7 +114,7 @@
public InfoDescriptor( final String name, final String classname )
throws IllegalArgumentException, NullPointerException
{
- this( name, classname, null, null, CollectionPolicy.SYSTEM, false,
null );
+ this( name, classname, null, null, CollectionPolicy.SYSTEM,
ThreadSafePolicy.UNKNOWN, null );
}

/**
@@ -136,7 +136,7 @@
final Version version,
final LifestylePolicy lifestyle,
final CollectionPolicy collection,
- final boolean threadsafe,
+ final ThreadSafePolicy threadsafe,
final Properties attributes )
throws IllegalArgumentException, NullPointerException
{
@@ -167,7 +167,7 @@

if( lifestyle == null )
{
- if( threadsafe )
+ if( threadsafe == ThreadSafePolicy.TRUE )
{
m_lifestyle = LifestylePolicy.SINGLETON;
}
@@ -300,11 +300,11 @@
}

/**
- * Ruturn TRUE is this type is threadsafe.
+ * Ruturn the thread-safe policy value.
*
- * @return the threadsafe status
+ * @return the thread-safe policy value
*/
- public boolean isThreadsafe()
+ public ThreadSafePolicy getThreadSafePolicy()
{
return m_threadsafe;
}
@@ -329,7 +329,7 @@
if( isEqual )
{
InfoDescriptor info = (InfoDescriptor) other;
- isEqual = isEqual && m_threadsafe == info.m_threadsafe;
+ isEqual = isEqual && m_threadsafe.equals( info.m_threadsafe );
isEqual = isEqual && m_classname.equals( info.m_classname );
isEqual = isEqual && m_collection.equals( info.m_collection );
isEqual = isEqual && m_name.equals( info.m_name );
@@ -354,14 +354,7 @@
{
int hash = super.hashCode();
hash ^= m_collection.hashCode();
- if( m_threadsafe )
- {
- hash = hash + 383972391;
- }
- else
- {
- hash = hash - 113741397;
- }
+ hash ^= m_threadsafe.hashCode();
hash ^= m_classname.hashCode();
if ( null != m_name )
{

Modified:
trunk/main/metro/model/src/main/net/dpml/metro/info/InfoDescriptorBeanInfo.java
===================================================================
---
trunk/main/metro/model/src/main/net/dpml/metro/info/InfoDescriptorBeanInfo.java
2006-02-05 16:59:31 UTC (rev 1038)
+++
trunk/main/metro/model/src/main/net/dpml/metro/info/InfoDescriptorBeanInfo.java
2006-02-05 17:38:29 UTC (rev 1039)
@@ -68,7 +68,7 @@
args[2] = info.getVersion();
args[3] = info.getLifestyle();
args[4] = info.getCollectionPolicy();
- args[5] = new Boolean( info.isThreadsafe() );
+ args[5] = info.getThreadSafePolicy();
args[6] = info.getProperties();
return new Expression( old, old.getClass(), "new", args );
}

Added:
trunk/main/metro/model/src/main/net/dpml/metro/info/ThreadSafePolicy.java
===================================================================
--- trunk/main/metro/model/src/main/net/dpml/metro/info/ThreadSafePolicy.java
2006-02-05 16:59:31 UTC (rev 1038)
+++ trunk/main/metro/model/src/main/net/dpml/metro/info/ThreadSafePolicy.java
2006-02-05 17:38:29 UTC (rev 1039)
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ * Copyright 1999-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 net.dpml.metro.info;
+
+import net.dpml.lang.Enum;
+
+/**
+ * Collection policy enummeration.
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class ThreadSafePolicy extends Enum
+{
+ //-------------------------------------------------------------------
+ // static
+ //-------------------------------------------------------------------
+
+ /**
+ * Serial version identifier.
+ */
+ static final long serialVersionUID = 1L;
+
+ /**
+ * Weak collection policy.
+ */
+ public static final ThreadSafePolicy TRUE = new ThreadSafePolicy( "true"
);
+
+ /**
+ * Soft collection policy.
+ */
+ public static final ThreadSafePolicy FALSE = new ThreadSafePolicy(
"false" );
+
+ /**
+ * Hard collection policy.
+ */
+ public static final ThreadSafePolicy UNKNOWN = new ThreadSafePolicy(
"unknown" );
+
+ /**
+ * Array of static thread-safe policy enumeration values.
+ */
+ private static final ThreadSafePolicy[] ENUM_VALUES =
+ new ThreadSafePolicy[]{TRUE, FALSE, UNKNOWN};
+
+ /**
+ * Returns an array of policy enum values.
+ * @return the policies array
+ */
+ public static ThreadSafePolicy[] values()
+ {
+ return ENUM_VALUES;
+ }
+
+ /**
+ * Internal constructor.
+ * @param label the enumeration label.
+ * @param index the enumeration index.
+ * @param map the set of constructed enumerations.
+ */
+ private ThreadSafePolicy( String label )
+ {
+ super( label );
+ }
+
+ /**
+ * Parse the supplied name.
+ * @param value the value to parse
+ * @return the collection policy
+ */
+ public static ThreadSafePolicy parse( String value )
+ {
+ if( value.equalsIgnoreCase( "true" ) )
+ {
+ return TRUE;
+ }
+ else if( value.equalsIgnoreCase( "false" ) )
+ {
+ return FALSE;
+ }
+ else
+ {
+ return UNKNOWN;
+ }
+ }
+}

Added:
trunk/main/metro/model/src/main/net/dpml/metro/info/ThreadSafePolicyBeanInfo.java
===================================================================
---
trunk/main/metro/model/src/main/net/dpml/metro/info/ThreadSafePolicyBeanInfo.java
2006-02-05 16:59:31 UTC (rev 1038)
+++
trunk/main/metro/model/src/main/net/dpml/metro/info/ThreadSafePolicyBeanInfo.java
2006-02-05 17:38:29 UTC (rev 1039)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ * Copyright 1999-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 net.dpml.metro.info;
+
+import java.beans.Expression;
+import java.beans.BeanDescriptor;
+import java.beans.DefaultPersistenceDelegate;
+import java.beans.SimpleBeanInfo;
+import java.beans.Encoder;
+
+/**
+ * BeanInfo that declares a specialized persistence delegate for the
collection policy class.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class ThreadSafePolicyBeanInfo extends SimpleBeanInfo
+{
+ private static final BeanDescriptor BEAN_DESCRIPTOR =
setupBeanDescriptor();
+
+ /**
+ * Return the bean descriptor.
+ * @return the descriptor
+ */
+ public BeanDescriptor getBeanDescriptor()
+ {
+ return BEAN_DESCRIPTOR;
+ }
+
+ private static BeanDescriptor setupBeanDescriptor()
+ {
+ BeanDescriptor descriptor = new BeanDescriptor(
ThreadSafePolicy.class );
+ descriptor.setValue(
+ "persistenceDelegate",
+ new ThreadSafePolicyPersistenceDelegate() );
+ return descriptor;
+ }
+
+ /**
+ * Persistence delegate implementation.
+ */
+ private static class ThreadSafePolicyPersistenceDelegate extends
DefaultPersistenceDelegate
+ {
+ /**
+ * Return the expression value.
+ * @param old the old instance
+ * @param encoder the encoder
+ * @return the expression
+ */
+ public Expression instantiate( Object old, Encoder encoder )
+ {
+ ThreadSafePolicy policy = (ThreadSafePolicy) old;
+ return new Expression( policy, ThreadSafePolicy.class, "parse",
new Object[]{policy.getName()} );
+ }
+ }
+}

Modified: trunk/main/metro/model/src/main/net/dpml/metro/info/Type.java
===================================================================
--- trunk/main/metro/model/src/main/net/dpml/metro/info/Type.java
2006-02-05 16:59:31 UTC (rev 1038)
+++ trunk/main/metro/model/src/main/net/dpml/metro/info/Type.java
2006-02-05 17:38:29 UTC (rev 1039)
@@ -173,23 +173,32 @@
String path = clazz.getName().replace( '.', '/' ) + ".type";
URL url = clazz.getClassLoader().getResource( path );
InputStream input = url.openStream();
- try
+ if( null == input )
{
- return decode( context, input );
+ // no component type defined ..
+ // create a default type definition
+ return createType( clazz );
}
- catch( IOException e )
+ else
{
- throw e;
+ try
+ {
+ return decode( context, input );
+ }
+ catch( IOException e )
+ {
+ throw e;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error occured while attempting to load an
encoded type."
+ + "\nResource path: " + path;
+ IOException ioe = new IOException( error );
+ ioe.initCause( e );
+ throw ioe;
+ }
}
- catch( Throwable e )
- {
- final String error =
- "Unexpected error occured while attempting to load an encoded
type."
- + "\nResource path: " + path;
- IOException ioe = new IOException( error );
- ioe.initCause( e );
- throw ioe;
- }
}

/**
@@ -511,13 +520,21 @@
}
return hash;
}
-
+
private static Type createObjectType()
{
- final InfoDescriptor info = new InfoDescriptor( "object",
Object.class.getName() );
+ return createType( Object.class );
+ }
+
+ private static Type createType( Class clazz )
+ {
+ final InfoDescriptor info = new InfoDescriptor( "object",
clazz.getName() );
final CategoryDescriptor[] loggers = new CategoryDescriptor[0];
final ContextDescriptor context = new ContextDescriptor( new
EntryDescriptor[0] );
- final ServiceDescriptor[] services = new ServiceDescriptor[0];
+ final ServiceDescriptor[] services =
+ new ServiceDescriptor[]{
+ new ServiceDescriptor( clazz.getName() )
+ };
final PartReference[] parts = new PartReference[0];
return new Type( info, loggers, context, services, parts,
State.NULL_STATE );
}

Modified:
trunk/main/metro/model/src/test/net/dpml/metro/info/test/InfoDescriptorTestCase.java
===================================================================
---
trunk/main/metro/model/src/test/net/dpml/metro/info/test/InfoDescriptorTestCase.java
2006-02-05 16:59:31 UTC (rev 1038)
+++
trunk/main/metro/model/src/test/net/dpml/metro/info/test/InfoDescriptorTestCase.java
2006-02-05 17:38:29 UTC (rev 1039)
@@ -22,6 +22,7 @@
import net.dpml.metro.info.InfoDescriptor;
import net.dpml.metro.info.CollectionPolicy;
import net.dpml.metro.info.LifestylePolicy;
+import net.dpml.metro.info.ThreadSafePolicy;

import net.dpml.part.Version;

@@ -38,7 +39,7 @@
private final Version m_version = Version.getVersion( "1.2.3" );
private final LifestylePolicy m_lifestyle = LifestylePolicy.SINGLETON;
private final CollectionPolicy m_collection = CollectionPolicy.WEAK;
- private final boolean m_threadsafe = false;
+ private final ThreadSafePolicy m_threadsafe = ThreadSafePolicy.FALSE;

private InfoDescriptor m_info;

@@ -88,7 +89,7 @@
*/
public void testThreadsafeCapable()
{
- assertEquals( m_threadsafe, m_info.isThreadsafe() );
+ assertEquals( m_threadsafe, m_info.getThreadSafePolicy() );
}

/**
@@ -131,7 +132,7 @@
assertEquals( m_classname, info.getClassname() );
assertEquals( m_version, info.getVersion() );
assertEquals( m_lifestyle, info.getLifestyle() );
- assertEquals( m_threadsafe, info.isThreadsafe() );
+ assertEquals( m_threadsafe, info.getThreadSafePolicy() );
assertEquals( m_collection, info.getCollectionPolicy() );
}


Modified:
trunk/main/metro/model/src/test/net/dpml/metro/info/test/TypeTestCase.java
===================================================================
---
trunk/main/metro/model/src/test/net/dpml/metro/info/test/TypeTestCase.java
2006-02-05 16:59:31 UTC (rev 1038)
+++
trunk/main/metro/model/src/test/net/dpml/metro/info/test/TypeTestCase.java
2006-02-05 17:38:29 UTC (rev 1039)
@@ -32,6 +32,7 @@
import net.dpml.metro.info.EntryDescriptor;
import net.dpml.metro.info.InfoDescriptor;
import net.dpml.metro.info.CollectionPolicy;
+import net.dpml.metro.info.ThreadSafePolicy;
import net.dpml.metro.info.Type;
import net.dpml.metro.info.PartReference;
import net.dpml.metro.info.ServiceDescriptor;
@@ -135,7 +136,7 @@

private static InfoDescriptor createSimpleInfo( String classname )
{
- return new InfoDescriptor( null, classname, null, null,
CollectionPolicy.WEAK, false, null );
+ return new InfoDescriptor( null, classname, null, null,
CollectionPolicy.WEAK, ThreadSafePolicy.FALSE, null );
}

/**

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/CatalogTask.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/CatalogTask.java
2006-02-05 16:59:31 UTC (rev 1038)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/CatalogTask.java
2006-02-05 17:38:29 UTC (rev 1039)
@@ -526,7 +526,8 @@

writer.write( "\n <table class=\"menubar\">" );
writer.write( "\n <tr>" );
- writer.write( "<td class=\"package\"><a class=\"package\"
href=\"" + offset + "/packages-overview.html\">" );
+ writer.write( "<td class=\"package\"><a class=\"package\"
href=\""
+ + offset + "/packages-overview.html\">" );
writer.write( "overview" );
writer.write( "</a></td>" );
writer.write( "<td class=\"package\"><a class=\"package\"
href=\"overview.html\">" );
@@ -549,10 +550,14 @@
//

writer.write( "\n <table>" );
- writer.write( "\n <tr><td
class=\"feature\">Version:</td><td>" + type.getInfo().getVersion() +
"</td></tr>" );
- writer.write( "\n <tr><td class=\"feature\">Name:</td><td>"
+ type.getInfo().getName() + "</td></tr>" );
- writer.write( "\n <tr><td
class=\"feature\">Lifestyle:</td><td>" +
type.getInfo().getLifestyle().getName() + "</td></tr>" );
- writer.write( "\n <tr><td
class=\"feature\">Thread-Safe:</td><td>" + type.getInfo().isThreadsafe() +
"</td></tr>" );
+ writer.write( "\n <tr><td
class=\"feature\">Version:</td><td>"
+ + type.getInfo().getVersion() + "</td></tr>" );
+ writer.write( "\n <tr><td class=\"feature\">Name:</td><td>"
+ + type.getInfo().getName() + "</td></tr>" );
+ writer.write( "\n <tr><td
class=\"feature\">Lifestyle:</td><td>"
+ + type.getInfo().getLifestyle().getName() + "</td></tr>" );
+ writer.write( "\n <tr><td
class=\"feature\">Thread-Safe:</td><td>"
+ + type.getInfo().getThreadSafePolicy() + "</td></tr>" );
writer.write( "\n <tr><td
class=\"feature\">Collection:</td><td>"
+ type.getInfo().getCollectionPolicy().getName() +
"</td></tr>" );
writer.write( "\n </table>" );

Modified:
trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
===================================================================
--- trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
2006-02-05 16:59:31 UTC (rev 1038)
+++ trunk/main/metro/tools/src/main/net/dpml/metro/tools/TypeBuilderTask.java
2006-02-05 17:38:29 UTC (rev 1039)
@@ -43,6 +43,7 @@
import net.dpml.metro.info.PartReference;
import net.dpml.metro.info.EntryDescriptor;
import net.dpml.metro.info.ServiceDescriptor;
+import net.dpml.metro.info.ThreadSafePolicy;

import net.dpml.state.State;
import net.dpml.state.impl.DefaultState;
@@ -74,7 +75,7 @@
private Class m_class;
private LifestylePolicy m_lifestyle;
private CollectionPolicy m_collection;
- private boolean m_threadsafe = false;
+ private ThreadSafePolicy m_threadsafe = ThreadSafePolicy.UNKNOWN;
private PartsDataType m_parts;
private StateDataType m_state;
private ServicesDataType m_services;
@@ -105,9 +106,16 @@
* Set the threadsafe flag.
* @param value true if the component type is threadsafe
*/
- public void setThreadsafe( boolean value )
+ public void setThreadsafe( boolean flag )
{
- m_threadsafe = value;
+ if( flag )
+ {
+ m_threadsafe = ThreadSafePolicy.TRUE;
+ }
+ else
+ {
+ m_threadsafe = ThreadSafePolicy.FALSE;
+ }
}

/**
@@ -364,13 +372,13 @@
{
String name = getName();
String classname = subject.getName();
- boolean threadsafe = getThreadSafeCapability( subject );
+ ThreadSafePolicy threadsafe = getThreadSafeCapability( subject );
Properties properties = getTypeProperties( subject );
return new InfoDescriptor(
name, classname, null, m_lifestyle, m_collection, threadsafe,
properties );
}

- private boolean getThreadSafeCapability( Class subject )
+ private ThreadSafePolicy getThreadSafeCapability( Class subject )
throws IntrospectionException
{
return m_threadsafe;




  • r1039 - in trunk/main/metro: model/src/main/net/dpml/metro/info model/src/test/net/dpml/metro/info/test tools/src/main/net/dpml/metro/tools, mcconnell at BerliOS, 02/05/2006

Archive powered by MHonArc 2.6.24.

Top of Page