You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ad...@apache.org on 2006/02/28 17:35:26 UTC
svn commit: r381694 [32/38] - in /incubator/ode/scratch: bpe/ ode/
ode/bpelTests/ ode/bpelTests/probeService/ ode/bpelTests/test1/
ode/bpelTests/test10/ ode/bpelTests/test12/ ode/bpelTests/test13/
ode/bpelTests/test14/ ode/bpelTests/test15/ ode/bpelTes...
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiadapter/SPIAdapterInteraction.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiadapter/SPIAdapterInteraction.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiadapter/SPIAdapterInteraction.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiadapter/SPIAdapterInteraction.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,402 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.interaction.spiadapter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+import org.w3c.dom.Document;
+
+import org.apache.ode.client.DescribedValue;
+import org.apache.ode.client.IDescribedValue;
+import org.apache.ode.client.IFormattableValue;
+import org.apache.ode.client.spi.interaction.ISPIInteraction;
+import org.apache.ode.client.spi.interaction.ISPIQuery;
+import org.apache.ode.context.ICloneable;
+import org.apache.ode.context.base.ContextServiceException;
+import org.apache.ode.interaction.IInteraction;
+import org.apache.ode.interaction.IInvocation;
+import org.apache.ode.interaction.IInvocationTypes;
+import org.apache.ode.interaction.IObjectAccessible;
+import org.apache.ode.interaction.IObjectMutable;
+import org.apache.ode.interaction.InteractionException;
+import org.apache.ode.interaction.query.IQuery;
+import org.apache.ode.interaction.query.JaxenXPathSingleNodeQuery;
+import org.apache.ode.interaction.spiimpl.CannedFormattableValue;
+import org.apache.ode.interaction.spiimpl.MasterInteractionFactory;
+import org.apache.ode.util.ObjectInputStreamContextClassLoader;
+
+
+public class SPIAdapterInteraction implements
+ IInteraction, Serializable, ICloneable, IObjectAccessible, IObjectMutable
+{
+ static final long serialVersionUID = -6159197689519493325L;
+
+ private ISPIInteraction m_spi;
+ public SPIAdapterInteraction()
+ {
+ }
+ public SPIAdapterInteraction ( ISPIInteraction interaction )
+ {
+ m_spi = interaction;
+ }
+
+ public Object invoke(IInvocation iInvocation) throws InteractionException
+ {
+ Object returnValue =
+ invoke( iInvocation, null);
+ return returnValue;
+ }
+
+ public Object invoke(IInvocation iInvocation, Object iInput)
+ throws InteractionException
+ {
+ if ( ! (iInput instanceof IFormattableValue) )
+ {
+ if ( iInput != null )
+ {
+ iInput = new CannedFormattableValue( iInput );
+ }
+ }
+ Object returnValue = internalInvoke( iInvocation,
+ ( IFormattableValue )iInput );
+ return returnValue;
+ }
+
+ public void releaseResources() throws InteractionException
+ {
+ m_spi.releaseHeldResources();
+ }
+
+ protected Object internalInvoke( IInvocation invocation,
+ IFormattableValue input )
+ {
+ IFormattableValue returnValue = null;
+ ISPIQuery query = createSPIQuery(invocation.getQuery());
+ switch( invocation.getType())
+ {
+ case( IInvocationTypes.GET_SIMPLE_VALUE ):
+ {
+ if ( m_spi == null )
+ {
+ returnValue = null;
+ }
+ else
+ {
+ if ( !m_spi.supportsGetSimpleValue( query ) )
+ {
+ normalizeInteraction();
+ }
+ returnValue = m_spi.getSimpleValue( query );
+ }
+
+ break;
+ }
+ case( IInvocationTypes.GET_COMPLEX_VALUE):
+ {
+ if ( m_spi == null )
+ {
+ returnValue = null;
+ }
+ else
+ {
+ if ( !m_spi.supportsGetComplexValue( query ) )
+ {
+ normalizeInteraction();
+ }
+ returnValue = m_spi.getComplexValue(query);
+ }
+ break;
+ }
+ case( IInvocationTypes.GET_OBJECT ):
+ {
+ returnValue = ( IFormattableValue ) getContentObject();
+
+ break;
+ }
+ case( IInvocationTypes.COPY_SUB_ELEMENTS ):
+ {
+ if ( m_spi == null )
+ {
+ createEmptyInteraction();
+ }
+
+ if ( !m_spi.supportsCopySubElements( query, input ) )
+ {
+ normalizeInteraction();
+ }
+ m_spi.copySubElements( query,
+ input);
+
+ break;
+ }
+ case( IInvocationTypes.SET_SIMPLE_VALUE ):
+ {
+ if ( m_spi == null )
+ {
+ createEmptyInteraction();
+ }
+ if ( !m_spi.supportsSetSimpleValue( query, input ) )
+ {
+ normalizeInteraction();
+ }
+ m_spi.setSimpleValue( query, input);
+ break;
+ }
+ case( IInvocationTypes.SET_COMPLEX_VALUE):
+ {
+ if ( m_spi == null )
+ {
+ createEmptyInteraction();
+ }
+ if ( !m_spi.supportsSetComplexValue(query,
+ input) )
+ {
+ normalizeInteraction();
+ }
+
+ m_spi.setComplexValue(query,
+ input);
+ break;
+ }
+ case( IInvocationTypes.REMOVE_VALUE ):
+ {
+ if ( m_spi == null )
+ {
+ returnValue = null;
+ }
+ if( !m_spi.supportsRemoveValue(query))
+ {
+ normalizeInteraction();
+ }
+ m_spi.removeValue(query);
+
+ break;
+ }
+ case( IInvocationTypes.SET_OBJECT ):
+ {
+ setContentObject( input );
+
+ break;
+ }
+
+
+ }
+ if ( returnValue != null )
+ {
+ // All formattable values are decorated
+ // with our internal formattable value
+ // adapter. This adapter may house
+ // translation facilities in the future.
+ returnValue =
+ new FormattableValueAdapter( returnValue );
+ }
+
+ return returnValue;
+
+
+
+ }
+
+ private IFormattableValue getContentObject()
+ {
+ IFormattableValue returnValue;
+ if ( m_spi == null )
+ {
+ returnValue = null;
+ }
+ else
+ {
+ returnValue = m_spi.getValue();
+ }
+ return returnValue;
+ }
+ private void normalizeInteraction()
+ {
+ // TODO:
+ // Convert the interaction to a document interaction.
+ //
+ // We can put an XStream adapter in here at some point
+ // which can convert any described object into xml.
+ // For now, let's just hit the 80% case.
+ //
+ // A runtime exception will occur if the interaction
+ // can not provide a document representation.
+ Document documentValue =
+ ( Document )m_spi.getValue().getValueAs( Document.class );
+ DescribedValue dv = new DescribedValue( documentValue );
+ m_spi = MasterInteractionFactory.newInstance().createInteraction(dv);
+ }
+
+ private void createEmptyInteraction()
+ {
+ m_spi =
+ MasterInteractionFactory.newInstance().createAnyTypeInteraction();
+ }
+ protected ISPIQuery createSPIQuery( IQuery query )
+ {
+
+ JaxenQuery jq = null;
+ if ( query != null )
+ {
+ jq = new JaxenQuery(
+ ( JaxenXPathSingleNodeQuery ) query );
+ }
+ return jq;
+ }
+
+ public Object cloneObject() throws ContextServiceException
+ {
+ ISPIInteraction newspi;
+ if (!m_spi.supportsCloneSPIInteraction())
+ {
+ newspi = cloneSPI();
+ } else
+ {
+ newspi = m_spi.cloneSPIInteraction();
+ }
+ return new SPIAdapterInteraction(newspi);
+ }
+
+ /**
+ * This method is called when the interaction object does not provide a
+ * custom clone implementation.
+ *
+ * @return
+ */
+ private ISPIInteraction cloneSPI()
+ {
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(m_spi);
+ oos.close();
+ byte[] bytes = baos.toByteArray();
+ baos.close();
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStreamContextClassLoader(bais);
+ ISPIInteraction newInteraction = (ISPIInteraction) ois.readObject();
+ ois.close();
+ bais.close();
+ return newInteraction;
+ } catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Object getObject() throws InteractionException
+ {
+ return getContentObject();
+ }
+
+ /*
+ * This method is called by the param object
+ * to harvest parameters in a requested format
+ * before invoking an external action.
+ *
+ * I really want to get rid of this method in favor of
+ * the getFormattableValue() method.
+ *
+ * We'll leave it here for now for the sake of backward
+ * compatibility since there are external actions
+ * which rely on the type specifications contained
+ * in the external action binding information.
+ */
+ public Object getObject(String iPreference) throws InteractionException
+ {
+ Object returnValue = null;
+ if (iPreference == null || iPreference.equals("") ||
+ IInteraction.FORMATTABLE_VALUE_TYPE.equalsIgnoreCase(
+ iPreference.toLowerCase()))
+ {
+ returnValue = getUserValue();
+ }
+ else if ( IInteraction.OBJECT_TYPE.equalsIgnoreCase( iPreference ))
+ {
+ returnValue =
+ getUserValue().getDescribedValue().getData();
+ }
+ else if (IInteraction.BUFFER_TYPE.equalsIgnoreCase(
+ iPreference))
+ {
+ returnValue = m_spi.toString().getBytes();
+ } else if (IInteraction.INTERACTION_TYPE.equalsIgnoreCase(
+ iPreference))
+ {
+ returnValue = this;
+ }
+ else
+ {
+ // If we really don't know what's being
+ // asked for, give them the raw data.
+ returnValue =
+ getUserValue().getDescribedValue().getData();
+ }
+ return returnValue;
+ }
+
+ public String toString()
+ {
+ String returnValue;
+
+ returnValue = m_spi.getValue().toString();
+
+ return returnValue;
+ }
+
+ public ISPIInteraction getSPIInteraction()
+ {
+ return m_spi;
+ }
+
+ public void setSPIInteraction( ISPIInteraction spiinteraction)
+ {
+ m_spi = spiinteraction;
+ }
+
+ public IFormattableValue getUserValue()
+ {
+ return new FormattableValueAdapter( m_spi.getValue() );
+ }
+ public void setObject(Object iObject) throws InteractionException
+ {
+ setContentObject( iObject );
+
+ }
+ private void setContentObject(Object object)
+ {
+ IDescribedValue dv;
+ if (object instanceof IFormattableValue)
+ {
+ dv = ((IFormattableValue) (object)).getDescribedValue();
+ }
+ else if (object instanceof IDescribedValue)
+ {
+ dv = (IDescribedValue) (object);
+ }
+ else
+ {
+ dv = new DescribedValue(object);
+ }
+ m_spi = MasterInteractionFactory.newInstance().createInteraction(dv);
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiadapter/SPIAdapterInteractionFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiadapter/SPIAdapterInteractionFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiadapter/SPIAdapterInteractionFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiadapter/SPIAdapterInteractionFactory.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.interaction.spiadapter;
+
+import java.util.Properties;
+
+import org.w3c.dom.Document;
+
+import org.apache.ode.client.DescribedValue;
+import org.apache.ode.client.formats.INativeFormat;
+import org.apache.ode.client.spi.interaction.ISPIInteraction;
+import org.apache.ode.interaction.IInteraction;
+import org.apache.ode.interaction.InteractionException;
+import org.apache.ode.interaction.InteractionFactory;
+import org.apache.ode.interaction.PropertiesInteractionObject;
+import org.apache.ode.interaction.spiimpl.MasterInteractionFactory;
+
+
+public class SPIAdapterInteractionFactory extends InteractionFactory
+{
+ public IInteraction createXMLInteraction(byte[] iBuffer) throws InteractionException
+ {
+ DescribedValue dv = new DescribedValue( iBuffer, INativeFormat.XML );
+ ISPIInteraction spi = MasterInteractionFactory.newInstance().createInteraction(dv);
+ SPIAdapterInteraction adapter = new SPIAdapterInteraction(spi);
+ return adapter;
+ }
+
+ public IInteraction createPropertiesInteraction(Properties iProperties) throws InteractionException
+ {
+ return new PropertiesInteractionObject(iProperties);
+ }
+
+ public IInteraction createDocumentInteraction(Document iDocument) throws InteractionException
+ {
+ DescribedValue dv = new DescribedValue( iDocument );
+ ISPIInteraction spi = MasterInteractionFactory.newInstance().createInteraction(dv);
+ SPIAdapterInteraction adapter = new SPIAdapterInteraction( spi );
+ return adapter;
+ }
+
+ public IInteraction createDocumentInteraction() throws InteractionException
+ {
+ SPIAdapterInteraction adapter = new SPIAdapterInteraction( );
+ return adapter;
+ }
+
+ public IInteraction createObjectInteraction( Object iObject )
+ {
+ DescribedValue dv = new DescribedValue( iObject );
+ ISPIInteraction spi = MasterInteractionFactory.newInstance().createInteraction(dv);
+ SPIAdapterInteraction adapter = new SPIAdapterInteraction( spi );
+ return adapter;
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/CannedFormattableValue.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/CannedFormattableValue.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/CannedFormattableValue.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/CannedFormattableValue.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.interaction.spiimpl;
+
+import java.io.Serializable;
+
+import org.apache.ode.client.DescribedValue;
+import org.apache.ode.client.IDescribedValue;
+import org.apache.ode.client.IFormat;
+import org.apache.ode.client.IFormattableValue;
+
+
+public class CannedFormattableValue implements IFormattableValue, Serializable
+{
+
+ static final long serialVersionUID = -2315555599530458988L;
+
+ IDescribedValue m_describedValue;
+
+ public CannedFormattableValue( Object rawData )
+ {
+ if ( rawData instanceof IDescribedValue )
+ {
+ m_describedValue = ( IDescribedValue )rawData;
+ }
+ else
+ {
+ m_describedValue = new DescribedValue( rawData );
+ }
+ }
+ public CannedFormattableValue( IDescribedValue describedValue )
+ {
+ m_describedValue = describedValue;
+ }
+ public Object getValueAs(Class clazz, IFormat format)
+ {
+ if ( format != null &&
+ !format.equals(m_describedValue.getFormat()))
+ {
+ throw new UnsupportedOperationException();
+ }
+ return getValueAs( clazz);
+
+ }
+ public Object getValueAs(Class clazz)
+ {
+ Object data = m_describedValue.getData();
+ if ( data == null )
+ {
+ return null;
+ }
+ if ( clazz.isAssignableFrom( data.getClass() ) )
+ {
+ return data;
+ }
+ else
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+ public boolean supportsGetValueAs(Class clazz, IFormat format)
+ {
+ if ( format != null &&
+ !format.equals(m_describedValue.getFormat()))
+ {
+ return false;
+ }
+ return supportsGetValueAs( clazz);
+ }
+ public boolean supportsGetValueAs(Class clazz)
+ {
+ Object data = m_describedValue.getData();
+ if ( data == null )
+ {
+ return true;
+ }
+ if ( clazz.isAssignableFrom( data.getClass() ) )
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ public IDescribedValue getDescribedValue()
+ {
+ return m_describedValue;
+ }
+ public String toString()
+ {
+ Object data = m_describedValue.getData();
+ if ( data != null )
+ {
+ return data.toString();
+ }
+ return "";
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/MasterInteractionFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/MasterInteractionFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/MasterInteractionFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/MasterInteractionFactory.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.interaction.spiimpl;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.ode.client.IDescribedValue;
+import org.apache.ode.client.spi.interaction.ISPIInteraction;
+import org.apache.ode.client.spi.interaction.ISPIInteractionFactory;
+import org.apache.ode.util.BPEProperties;
+
+public class MasterInteractionFactory implements ISPIInteractionFactory
+{
+
+ static final long serialVersionUID = 3229334691771274257L;
+
+ private LinkedList m_factoryList = new LinkedList();
+ private static MasterInteractionFactory MasterInstance = null;
+
+ private MasterInteractionFactory()
+ {
+
+ BPEProperties props;
+ try
+ {
+ props = new BPEProperties( true,
+ new InitialContext());
+
+ } catch (NamingException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ String factoriesString =
+ props.getInteractionFactories();
+ String externalFactoriesString =
+ props.getExternalInteractionFactories();
+
+ // Give the external interaction factories precedence.
+ addInteractionFactories( externalFactoriesString );
+ addInteractionFactories( factoriesString );
+
+ }
+
+ private void addInteractionFactories( String factoriesString )
+ {
+ if ( factoriesString == null || factoriesString.equals("") )
+ {
+ return;
+ }
+ String[] factories = factoriesString.split(",");
+ for ( int i = 0; i< factories.length; i++ )
+ {
+ ISPIInteractionFactory
+ factory;
+ try
+ {
+ factory = (ISPIInteractionFactory)Class.forName( factories[i] ).newInstance();
+ } catch (Exception e)
+ {
+ throw new RuntimeException( e );
+ }
+
+ m_factoryList.add ( factory );
+ }
+ }
+ private static synchronized ISPIInteractionFactory CreateMasterInstance()
+ {
+ if ( MasterInstance == null )
+ {
+ MasterInstance = new MasterInteractionFactory();
+ }
+ return MasterInstance;
+ }
+
+ public ISPIInteraction createAnyTypeInteraction()
+ {
+ Iterator iter = m_factoryList.iterator();
+ while( iter.hasNext() )
+ {
+ ISPIInteractionFactory f =
+ ( ISPIInteractionFactory ) iter.next();
+ if ( f.supportsAnyType() )
+ {
+ return f.createAnyTypeInteraction();
+ }
+ }
+ throw new UnsupportedOperationException();
+ }
+
+
+ public ISPIInteraction createInteraction(IDescribedValue describedValue)
+ {
+ Iterator iter = m_factoryList.iterator();
+ ISPIInteractionFactory f = null;
+ while( iter.hasNext() )
+ {
+ f =
+ ( ISPIInteractionFactory ) iter.next();
+ if ( f.supportsInteraction(describedValue) )
+ {
+ return f.createInteraction(describedValue);
+ }
+ }
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean supportsInteraction(IDescribedValue describedValue)
+ {
+ Iterator iter = m_factoryList.iterator();
+ while( iter.hasNext() )
+ {
+ ISPIInteractionFactory f =
+ ( ISPIInteractionFactory ) iter.next();
+ if ( f.supportsInteraction(describedValue) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean supportsAnyType()
+ {
+ Iterator iter = m_factoryList.iterator();
+ while( iter.hasNext() )
+ {
+ ISPIInteractionFactory f =
+ ( ISPIInteractionFactory ) iter.next();
+ if ( f.supportsAnyType() )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static ISPIInteractionFactory newInstance()
+ {
+ if ( MasterInstance == null )
+ {
+ return CreateMasterInstance();
+ }
+ return MasterInstance;
+
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/AtomicInteraction.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/AtomicInteraction.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/AtomicInteraction.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/AtomicInteraction.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.interaction.spiimpl.atomic;
+
+import org.apache.ode.client.IDescribedValue;
+import org.apache.ode.client.IFormattableValue;
+import org.apache.ode.client.spi.interaction.ISPIInteraction;
+import org.apache.ode.client.spi.interaction.ISPIQuery;
+import org.apache.ode.interaction.spiimpl.CannedFormattableValue;
+
+public class AtomicInteraction implements ISPIInteraction
+{
+ static final long serialVersionUID = -899325809844440914L;
+
+ private IDescribedValue m_describedValue;
+ public AtomicInteraction(IDescribedValue describedValue)
+ {
+ m_describedValue = describedValue;
+ }
+ public IFormattableValue getSimpleValue(ISPIQuery query)
+
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void setSimpleValue(ISPIQuery query, IFormattableValue iValue)
+
+ {
+ throw new UnsupportedOperationException();
+ }
+ public IFormattableValue getComplexValue(ISPIQuery query)
+
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void setComplexValue(ISPIQuery query, IFormattableValue iValue)
+
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void removeValue(ISPIQuery query)
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void copySubElements(ISPIQuery query, IFormattableValue source)
+
+ {
+ throw new UnsupportedOperationException();
+ }
+ public ISPIInteraction cloneSPIInteraction()
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void releaseHeldResources()
+ {
+
+ }
+ public boolean supportsSetSimpleValue(ISPIQuery query, ISPIInteraction iValue)
+ {
+ return false;
+ }
+ public boolean supportsGetComplexValue(ISPIQuery query)
+ {
+ return false;
+ }
+ public boolean supportsSetComplexValue(ISPIQuery query, ISPIInteraction iValue)
+ {
+ return false;
+ }
+ public boolean supportsRemoveValue(ISPIQuery query)
+ {
+ return false;
+ }
+ public boolean supportsCopySubElements(ISPIQuery query, IFormattableValue source)
+ {
+ return false;
+ }
+ public boolean supportsCloneSPIInteraction()
+ {
+ return false;
+ }
+ public boolean supportsSetSimpleValue(ISPIQuery query, IFormattableValue iValue)
+ {
+ return false;
+ }
+ public boolean supportsSetComplexValue(ISPIQuery query, IFormattableValue iValue)
+ {
+ return false;
+ }
+ public IFormattableValue getValue()
+ {
+ return new CannedFormattableValue( m_describedValue );
+ }
+ public boolean supportsGetSimpleValue(ISPIQuery query)
+ {
+ return false;
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/AtomicInteractionFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/AtomicInteractionFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/AtomicInteractionFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/AtomicInteractionFactory.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.interaction.spiimpl.atomic;
+
+import java.util.Properties;
+
+import org.apache.ode.client.IDescribedValue;
+import org.apache.ode.client.IFormat;
+import org.apache.ode.client.formats.INativeFormat;
+import org.apache.ode.client.spi.interaction.ISPIInteraction;
+import org.apache.ode.client.spi.interaction.ISPIInteractionFactory;
+
+
+public class AtomicInteractionFactory
+ implements ISPIInteractionFactory
+{
+
+ static final long serialVersionUID = -2590787466188228009L;
+
+ public ISPIInteraction createAnyTypeInteraction()
+ {
+ return null;
+ }
+
+ public ISPIInteraction createInteraction(IDescribedValue describedValue)
+ {
+ return new AtomicInteraction( describedValue );
+ }
+
+ public boolean supportsInteraction(IDescribedValue value)
+ {
+ IFormat format = value.getFormat();
+// Object data = value.getData();
+ Properties contentType = value.getContentType();
+
+ boolean contentInfoEmpty = ( contentType == null ) ||
+ ( contentType.isEmpty() );
+
+ // This interaction does not support content type validation
+ // so return false.
+ if ( ! contentInfoEmpty )
+ {
+ return false;
+ }
+
+ boolean formatOK = ( format == null ) ||
+ format.equals( INativeFormat.ATOMIC );
+
+ if ( ! formatOK )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean supportsAnyType()
+ {
+ return false;
+ }
+
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/LazyObject.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/LazyObject.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/LazyObject.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/atomic/LazyObject.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.interaction.spiimpl.atomic;
+
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+import com.thoughtworks.xstream.XStream;
+
+// The LazyObject performs lazy XStream serialization
+// and deserialization on an arbitrary java object
+// regardless of whether the java object implements
+// the serializable interface or not. The LazyObject
+// is held in the business process context and enables
+// the serialization of objects which do not
+// implement the Serializable interface.
+public class LazyObject implements Serializable
+{
+ static final long serialVersionUID = -2181661690231270298L;
+
+ private transient Object rawObject;
+ private String xmlString;
+ public LazyObject( Object rawObject )
+ {
+ this.rawObject = rawObject;
+ }
+
+ private void writeObject(ObjectOutputStream s) throws IOException
+ {
+ if ( (xmlString == null) && (rawObject != null) )
+ {
+ XStream xstream = new XStream();
+ xmlString = xstream.toXML(rawObject);
+ }
+ s.defaultWriteObject();
+ }
+
+ public Object getObject()
+ {
+ if ( (rawObject == null) && (xmlString != null) )
+ {
+ XStream xstream = new XStream();
+ ClassLoader contextClassLoader =
+ Thread.currentThread().getContextClassLoader();
+ xstream.setClassLoader(contextClassLoader);
+ rawObject = xstream.fromXML(xmlString);
+ }
+
+ return rawObject;
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentFormattableValue.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentFormattableValue.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentFormattableValue.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentFormattableValue.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.interaction.spiimpl.document;
+
+import java.io.Serializable;
+
+import org.w3c.dom.Document;
+
+import org.apache.ode.client.DescribedValue;
+import org.apache.ode.client.IDescribedValue;
+import org.apache.ode.client.IFormat;
+import org.apache.ode.client.IFormattableValue;
+import org.apache.ode.client.formats.INativeFormat;
+
+
+public class DocumentFormattableValue implements IFormattableValue, Serializable
+{
+ static final long serialVersionUID = -4078647545776489807L;
+
+ private LazyDocument m_lo;
+
+ public DocumentFormattableValue( Document document )
+ {
+ m_lo = new LazyDocument( document );
+ }
+
+ public DocumentFormattableValue( LazyDocument lo )
+ {
+ m_lo = lo;
+ }
+
+ public Object getValueAs(Class clazz, IFormat format)
+ {
+ if ( format.equals(INativeFormat.XML) ||
+ (format == null))
+ {
+ return getValueAs( clazz );
+ }
+ else
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+ public Object getValueAs(Class clazz)
+ {
+ if (clazz.isAssignableFrom(byte[].class))
+ {
+ return m_lo.getXMLBuffer();
+ }
+ else if ( clazz.isAssignableFrom(Document.class))
+ {
+ return m_lo.getDocument();
+ }
+ throw new UnsupportedOperationException();
+ }
+ public boolean supportsGetValueAs(Class clazz, IFormat format)
+ {
+ if ( format.equals(INativeFormat.XML) ||
+ (format == null))
+ {
+ return supportsGetValueAs( clazz );
+ }
+ return false;
+ }
+ public boolean supportsGetValueAs(Class clazz)
+ {
+ if (clazz.isAssignableFrom(byte[].class))
+ {
+ return true;
+ }
+ else if ( clazz.isAssignableFrom(Document.class))
+ {
+ return true;
+ }
+ return false;
+ }
+ public IDescribedValue getDescribedValue()
+ {
+ Object convenientForm = m_lo.getConvenientForm();
+ if (convenientForm instanceof Document)
+ {
+ return new DescribedValue(convenientForm);
+ } else
+ {
+ return new DescribedValue(convenientForm, INativeFormat.XML);
+ }
+ }
+ public String toString()
+ {
+ byte[] xmlbytes = ( byte[] )getValueAs( byte[].class );
+ String string = new String(xmlbytes);
+ return string;
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentInteraction.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentInteraction.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentInteraction.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentInteraction.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.interaction.spiimpl.document;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import org.apache.ode.client.IFormattableValue;
+import org.apache.ode.client.spi.interaction.ISPIInteraction;
+import org.apache.ode.client.spi.interaction.ISPIJaxenXPathQuery;
+import org.apache.ode.client.spi.interaction.ISPIQuery;
+import org.apache.ode.client.spi.interaction.ISPIXPathQuery;
+import org.apache.ode.interaction.operations.CopyChildrenOperation;
+import org.apache.ode.interaction.operations.CopyTreeOperation;
+import org.apache.ode.interaction.operations.GetTextValueOperation;
+import org.apache.ode.interaction.operations.IOperation;
+import org.apache.ode.interaction.operations.PruneOperation;
+import org.apache.ode.interaction.operations.SelectTreeOperation;
+import org.apache.ode.interaction.operations.SetTextValueOperation;
+import org.apache.ode.interaction.query.JaxenXPathSingleNodeQuery;
+import org.apache.ode.interaction.spiimpl.CannedFormattableValue;
+
+
+/**
+ * This class implements a full featured interaction for a DOM
+ * document. Interactions which are not full featured will
+ * be converted by the BPE to this interaction if the BPE requires
+ * features they do not implement.
+ *
+ * Note:
+ * It's interesting to note that XStream or other xml serialization
+ * technology allows any object to be serialized as an xml document
+ * and consequently accessible via xpath.
+ *
+ * In the presence of XStream technology, the DocumentInteraction
+ * becomes a rather painless and complete interoperability solution.
+ *
+ * Of course we still need to consider the type of xml which
+ * XStream generates and the performance implications. XStream
+ * undoubtedly stuffs class names and other things in it's xml
+ * which you wouldn't expect in a pure content representation.
+ */
+class DocumentInteraction implements ISPIInteraction
+{
+
+ static final long serialVersionUID = 6173403782746777645L;
+
+ private LazyDocument m_documentHolder = new LazyDocument();
+
+ DocumentInteraction()
+ {
+ }
+ DocumentInteraction( byte[] xmlbuffer )
+ {
+ m_documentHolder = new LazyDocument( xmlbuffer );
+ }
+ DocumentInteraction( Document document )
+ {
+ m_documentHolder = new LazyDocument( document );
+ }
+
+ public IFormattableValue getSimpleValue(ISPIQuery query)
+
+ {
+ IOperation operation = new GetTextValueOperation();
+ Object returnValue =
+ executeOperation( operation, query, null );
+ return createFormattableValue( returnValue );
+ }
+
+ protected Object executeOperation(IOperation operation, ISPIQuery query,
+ Object argument)
+ {
+ try
+ {
+ JaxenXPathSingleNodeQuery jnq = new JaxenXPathSingleNodeQuery();
+ if (query instanceof ISPIJaxenXPathQuery)
+ {
+ ISPIJaxenXPathQuery jq = (ISPIJaxenXPathQuery) (query);
+ jnq.setLocator(jq.getDOMXPath());
+ jnq.setNamespaceMap(jq.getNamespaceMap());
+ jnq.setXPathExpression(jq.getXPathExpressionAsString());
+ } else if (query instanceof ISPIXPathQuery)
+ {
+ ISPIXPathQuery xq = (ISPIXPathQuery) (query);
+ jnq.setNamespaceMap(xq.getNamespaceMap());
+ jnq.setXPathExpression(xq.getXPathExpressionAsString());
+ }
+ Object operationResult = operation.execute(
+ m_documentHolder, jnq,
+ argument, jnq.getXPathExpression());
+ return operationResult;
+ } catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setSimpleValue(ISPIQuery query, IFormattableValue iValue)
+
+ {
+ IOperation operation = new SetTextValueOperation();
+ String arg = ( String )iValue.getValueAs( String.class );
+ executeOperation( operation, query, arg );
+ m_documentHolder.setDirty(true);
+ }
+ public IFormattableValue getComplexValue(ISPIQuery query)
+
+ {
+ IOperation operation = new SelectTreeOperation();
+ Object returnValue = executeOperation( operation, query, null );
+ IFormattableValue value = createFormattableValue( returnValue );
+ return value;
+ }
+ public void setComplexValue(ISPIQuery query,
+ IFormattableValue iValue)
+
+ {
+ if (iValue.supportsGetValueAs(Node.class))
+ {
+ IOperation operation = new CopyTreeOperation();
+ Node arg = ( Node )iValue.getValueAs( Node.class );
+ executeOperation( operation, query, arg );
+ m_documentHolder.setDirty(true);
+ }
+ else
+ setSimpleValue(query, iValue);
+ }
+ public void removeValue(ISPIQuery query)
+ {
+ IOperation operation = new PruneOperation();
+ executeOperation( operation, query, null );
+ m_documentHolder.setDirty(true);
+ }
+ public void copySubElements(ISPIQuery query, IFormattableValue source)
+
+ {
+ IOperation operation = new CopyChildrenOperation();
+ Node arg = ( Node )source.getValueAs( Node.class );
+ executeOperation( operation, query, arg );
+ m_documentHolder.setDirty(true);
+ }
+ public ISPIInteraction cloneSPIInteraction()
+ {
+ throw new UnsupportedOperationException();
+ }
+ public void releaseHeldResources()
+ {
+ }
+
+ public boolean supportsSetSimpleValue(ISPIQuery query, ISPIInteraction iValue)
+ {
+ return true;
+ }
+ public boolean supportsGetComplexValue(ISPIQuery query)
+ {
+ return true;
+ }
+ public boolean supportsSetComplexValue(ISPIQuery query, ISPIInteraction iValue)
+ {
+ return true;
+ }
+ public boolean supportsRemoveValue(ISPIQuery query)
+ {
+ return true;
+ }
+ public boolean supportsCopySubElements(ISPIQuery query, IFormattableValue source)
+ {
+ return true;
+ }
+ public boolean supportsCloneSPIInteraction()
+ {
+ // Defer clone to the framework
+ return false;
+ }
+
+ protected IFormattableValue createFormattableValue( Object value )
+ {
+ if ( value instanceof Document )
+ {
+ return new DocumentFormattableValue(
+ (Document)value );
+ }
+ else
+ {
+ return new CannedFormattableValue( value );
+ }
+ }
+ public boolean supportsSetSimpleValue(ISPIQuery query,
+ IFormattableValue iValue)
+ {
+ return true;
+ }
+ public boolean supportsSetComplexValue(ISPIQuery query,
+ IFormattableValue iValue)
+ {
+ return true;
+ }
+ public IFormattableValue getValue()
+ {
+ return new DocumentFormattableValue(m_documentHolder);
+ }
+ public boolean supportsGetSimpleValue(ISPIQuery query)
+ {
+ return true;
+ }
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentInteractionFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentInteractionFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentInteractionFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/DocumentInteractionFactory.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.interaction.spiimpl.document;
+
+import java.util.Properties;
+
+import org.w3c.dom.Document;
+
+import org.apache.ode.client.IDescribedValue;
+import org.apache.ode.client.IFormat;
+import org.apache.ode.client.formats.XMLFormat;
+import org.apache.ode.client.spi.interaction.ISPIInteraction;
+import org.apache.ode.client.spi.interaction.ISPIInteractionFactory;
+
+
+public class DocumentInteractionFactory
+ implements ISPIInteractionFactory
+{
+
+ static final long serialVersionUID = -4030617350592369896L;
+
+
+ public ISPIInteraction createAnyTypeInteraction()
+ {
+ return new DocumentInteraction();
+ }
+
+ public ISPIInteraction
+ createInteraction(IDescribedValue describedValue)
+ {
+ Object data = describedValue.getData();
+ if ( data instanceof byte[] )
+ {
+ return new DocumentInteraction( (byte[])(data));
+ }
+ if ( data instanceof String )
+ {
+ return new DocumentInteraction( ((String)(data)).getBytes());
+ }
+ if ( data instanceof Document )
+ {
+ return new DocumentInteraction( (Document)(data));
+ }
+ if ( data == null )
+ {
+ return createAnyTypeInteraction();
+ }
+ throw new UnsupportedOperationException();
+
+ }
+
+ public boolean supportsInteraction(IDescribedValue describedValue)
+ {
+ Object data = describedValue.getData();
+ IFormat format = describedValue.getFormat();
+ boolean formatIsXML = ( format != null )
+ && ( format instanceof XMLFormat);
+ Properties contentType =
+ describedValue.getContentType();
+
+ // This factory doesn't support content
+ // type specifiers, so if the user supplied
+ // content type specifiers, we must
+ // return false.
+ if ( contentType != null &&
+ !( contentType.isEmpty() ) )
+ {
+ return false;
+ }
+
+ if ( data instanceof Document )
+ {
+ return true;
+ }
+
+ // Format must match if it exists.
+ if ( format != null && ( ! ( format instanceof XMLFormat ) ) )
+ {
+ return false;
+ }
+
+ if ( data instanceof byte[] && formatIsXML )
+ {
+ return true;
+ }
+
+ if ( data instanceof String && formatIsXML )
+ {
+ return true;
+ }
+
+ if ( data == null )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean supportsAnyType()
+ {
+ // TODO Auto-generated method stub
+ return true;
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/LazyDocument.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/LazyDocument.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/LazyDocument.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/interaction/spiimpl/document/LazyDocument.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.interaction.spiimpl.document;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+
+import org.apache.xml.serializer.Method;
+import org.apache.xml.serializer.OutputPropertiesFactory;
+import org.apache.xml.serializer.Serializer;
+import org.apache.xml.serializer.SerializerFactory;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+import org.apache.ode.interaction.IDocumentAccessible;
+import org.apache.ode.interaction.InteractionException;
+import org.apache.ode.util.XMLDocBuilderByThread;
+
+
+/**
+ * A class that defers deserialization of its contained
+ * object until it is requested. This facility is useful
+ * for cases where the process context tree is brought in
+ * and out memory but the business process does not need
+ * access to all the parts of its context.
+ */
+public class LazyDocument implements Serializable, IDocumentAccessible
+{
+ static final long serialVersionUID = -279092603880466152L;
+
+ private transient Document m_document;
+ private transient boolean m_dirty;
+ private transient Serializer m_serializer;
+ //private transient SerializerToXML m_serializer;
+ private byte[] m_xmlbuffer= new byte[0];
+
+ public LazyDocument()
+ {
+ }
+
+ public LazyDocument( byte[] xmlbytes )
+ {
+ m_xmlbuffer = xmlbytes;
+ }
+
+ protected void setEmptyDocument()
+ {
+ m_document =
+ getDocBuilder().newDocument();
+ }
+
+ protected DocumentBuilder getDocBuilder()
+ {
+ try
+ {
+ // TODO: Need a better way to obtain a document
+ // builder.
+ return XMLDocBuilderByThread.getDocBuilder();
+ } catch (InteractionException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public LazyDocument( Document iDocument )
+ {
+ m_document = iDocument;
+ }
+
+ public Document getDocument()
+ {
+ if ( m_document == null )
+ {
+ deserializeDocument();
+ }
+ return m_document;
+ }
+
+
+ private void deserializeDocument()
+ {
+ try
+ {
+ if ( m_xmlbuffer.length > 0 )
+ {
+ ByteArrayInputStream bai =
+ new ByteArrayInputStream(m_xmlbuffer);
+ InputSource in = new InputSource(bai);
+ m_document =
+ XMLDocBuilderByThread.getDocBuilder().parse(in);
+ }
+ else
+ {
+ setEmptyDocument();
+ }
+ }
+ catch( Exception e )
+ {
+ throw new RuntimeException( e );
+ }
+
+ }
+
+ private void writeObject(ObjectOutputStream s) throws IOException
+ {
+ serializeDocument();
+ s.defaultWriteObject();
+ }
+
+ public void setDirty( boolean dirty )
+ {
+ m_dirty = dirty;
+ }
+
+ public byte[] getXMLBuffer()
+ {
+ try
+ {
+ serializeDocument();
+ } catch (IOException e)
+ {
+ throw new UnsupportedOperationException( e.toString());
+ }
+ return m_xmlbuffer;
+ }
+
+ private void serializeDocument() throws IOException
+ {
+ if ( (m_xmlbuffer.length == 0) || m_dirty )
+ {
+ // If the document has no child nodes,
+ // we don't want to serialize it because
+ // a sax parse error occurs when
+ // reconstructing an empty document
+ // from the buffer.
+ if (m_document != null && m_document.hasChildNodes())
+ {
+ if (m_serializer == null)
+ {
+ Properties props = OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
+ m_serializer = SerializerFactory.getSerializer(props);
+
+ }
+
+ ByteArrayOutputStream bao =
+ new ByteArrayOutputStream();
+ m_serializer.setOutputStream(bao);
+ m_serializer.asDOMSerializer().serialize(m_document);
+ //m_serializer.setOutputStream(bao);
+ //m_serializer.serialize(m_document);
+ m_xmlbuffer=bao.toByteArray();
+ setDirty(false);
+ }
+ else
+ {
+ // The document either does not exist or is
+ // empty, so clear the buffer.
+ m_xmlbuffer = new byte[0];
+ }
+ }
+ }
+
+ public Object getConvenientForm()
+ {
+ if ( m_dirty == true )
+ {
+ return getDocument();
+ }
+ else
+ {
+ return getXMLBuffer();
+ }
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/lang/ResourceGetter.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/lang/ResourceGetter.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/lang/ResourceGetter.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/lang/ResourceGetter.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.lang;
+
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Gets messages from the ResourceBundle.
+ */
+public final class ResourceGetter
+{
+
+ private static Logger logger =
+ Logger.getLogger(ResourceGetter.class.getName());
+
+ private static final ResourceBundle RESOURCE_BUNDLE =
+ ResourceBundle.getBundle("org/apache/ode/lang/ResourceBundle");
+ private static final MessageFormat BAD_MESSAGE =
+ new MessageFormat("{0} [illegal message format in resource bundle]");
+
+ /**
+ * Returns a string from the ResourceBundles.
+ *
+ * @param s the key for the string to get
+ *
+ * @return the string
+ */
+ public static String getString ( String s )
+ {
+ String s1 = s;
+ try
+ {
+ s1 = RESOURCE_BUNDLE.getString(s);
+ return s1;
+ }
+ catch ( Exception e )
+ {
+
+ }
+ return s1;
+ }
+
+ /**
+ * Get a formatted string from the ResourceBundles.
+ *
+ * @param s the key for the format in the bundle
+ * @param aobj the array of objects to push into the format
+ *
+ * @return the formatted string
+ */
+ public static String getFormatted(String s, Object aobj[])
+ {
+ if(aobj == null)
+ {
+ return getString(s);
+ } else
+ {
+ MessageFormat messageformat = getFormat(s);
+ return messageformat.format(((Object) (aobj)));
+ }
+ }
+
+ /**
+ * Check the format string out and return it as a MessageFormat.
+ *
+ * @param s the format string
+ *
+ * @return the MessageFormat
+ */
+ public static MessageFormat getFormat(String s)
+ {
+ String s1 = getString(s);
+ try
+ {
+// MessageFormat messageformat = new MessageFormat(s1);
+ return new MessageFormat(s1);
+ }
+ catch(IllegalArgumentException illegalargumentexception)
+ {
+ logger.log(Level.SEVERE,
+ "BAD_MESSAGE Format",
+ illegalargumentexception);
+ return new MessageFormat(BAD_MESSAGE.format(s));
+ }
+ }
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/DBLockingService.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/DBLockingService.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/DBLockingService.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/DBLockingService.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,271 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.locking;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.ResultSet;
+
+import org.apache.ode.util.BPEProperties;
+
+/**
+ *
+ * @author cpotter
+ *
+ * This class is used by BPE code that needs an exclusive lock on a shared
+ * resource.
+ *
+ * This class uses the locking capabilities of the RDBMS to acquire an
+ * exclusive lock on a resource identifier.
+ *
+ * is dependent on the table BPEMUTEX <BR>
+ * {<BR>
+ * ID int - an integer value between -999 and 999 inclusive <BR>
+ * MUTEX char[1] - the update column <BR>
+ * }<BR>
+ *
+ */
+public class DBLockingService implements LockingService {
+
+ private static Logger logger =
+ Logger.getLogger(DBLockingService.class.getName());
+
+ /* (non-Javadoc)
+ * @see org.apache.ode.locking.LockingService#lock()
+ */
+ public void lock(String aKey) {
+ int hashCode = aKey.hashCode() % 1000;
+ update(hashCode);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ode.locking.LockingService#init(org.apache.ode.util.BPEProperties)
+ */
+ public void init(BPEProperties props) {
+
+ try {
+ int hashBuckets = Integer.valueOf(props.getLockingServiceHashBuckets()).intValue();
+ InitialContext ictx = new InitialContext();
+ Object obj = ictx.lookup(DB_LOCKING_SERVICE_THE_DB);
+ m_dataSource = (DataSource) obj;
+ if ( ! initialized ) {
+ initDB(hashBuckets);
+ initialized = true;
+ }
+ } catch (NamingException ne) {
+ logger.log(Level.SEVERE, "", ne);
+ }
+
+ }
+
+ private void insertMetaData(Connection aConn, int aHashBucketsSize) {
+ PreparedStatement stmt = null,
+ stmt2 = null;
+// int rowCount = 0;
+
+ try {
+
+ // Delete any existing meta-data
+
+ stmt = aConn.prepareStatement(DB_LOCKING_SERVICE_DELETE);
+ stmt.executeUpdate();
+ stmt.close();
+
+ // Insert the positive half of the hash buckets individually
+
+ stmt = aConn.prepareStatement(DB_LOCKING_SERVICE_INSERT);
+
+ for (int cntr=1; cntr<aHashBucketsSize; cntr++) {
+ stmt.setInt(1, cntr);
+ stmt.setString(2, "I");
+ stmt.executeUpdate();
+ }
+
+ // Mass insert the negative half of the hash buckets
+
+ stmt2 = aConn.prepareStatement(DB_LOCKING_SERVICE_BATCH_INSERT);
+ stmt2.executeUpdate();
+
+ // Insert the hash bucket for the 0 key
+
+ stmt.setInt(1, 0);
+ stmt.setString(2, "I");
+ stmt.executeUpdate();
+ } catch (SQLException se) {
+ logger.log(Level.SEVERE, "", se);
+ } finally {
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException se) {
+
+ // Don't really care if there is a problem closing
+ }
+ stmt = null;
+ }
+
+ if (stmt2 != null) {
+ try {
+ stmt2.close();
+ } catch (SQLException se) {
+
+ // Don't really care if there is a problem closing
+ }
+ stmt2 = null;
+ }
+ }
+ }
+
+ private void createTable(Connection aConn, int aHashBucketsSize) {
+ PreparedStatement stmt = null;
+// int rowCount = 0;
+
+ try {
+ stmt = aConn.prepareStatement(DB_LOCKING_SERVICE_CREATE);
+ stmt.executeUpdate();
+ stmt.close();
+
+ stmt = aConn.prepareStatement(DB_LOCKING_SERVICE_INDEX);
+ stmt.executeUpdate();
+ } catch (SQLException se) {
+ logger.log(Level.SEVERE, "", se);
+ } finally {
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException se) {
+
+ // Don't really care if there is a problem closing
+ }
+ stmt = null;
+ }
+ }
+ }
+
+ private void initDB(int aHashBucketsSize) {
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ int rowCount = 0;
+
+ try {
+ conn = m_dataSource.getConnection();
+ stmt = conn.prepareStatement(DB_LOCKING_SERVICE_SELECT);
+ ResultSet rs = stmt.executeQuery();
+
+ if (rs.next()) {
+ rowCount = rs.getInt(1);
+ }
+
+ rs.close();
+
+ // Number of hash buckets changed
+
+ if (rowCount != (2*(aHashBucketsSize-1))+1) {
+
+ // Re-created hash bucket meta-data
+
+ insertMetaData(conn, aHashBucketsSize);
+ }
+ } catch (SQLException se) {
+
+ // Assume table doesn't exist and create it
+
+ createTable(conn, aHashBucketsSize);
+ insertMetaData(conn, aHashBucketsSize);
+ } finally {
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException se) {
+
+ // Don't really care if there is a problem closing
+ }
+ stmt = null;
+ }
+
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException se) {
+
+ // Don't really care if there is a problem closing
+ }
+ conn = null;
+ }
+ }
+ }
+
+ private void update(int aKey) {
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ int rowCount = 0;
+
+ try {
+ conn = m_dataSource.getConnection();
+ stmt = conn.prepareStatement(DB_LOCKING_SERVICE_UPDATE);
+ stmt.setString(1, "U");
+ stmt.setInt(2, aKey);
+ rowCount = stmt.executeUpdate();
+
+ if (rowCount != 1) {
+ logger.log(Level.SEVERE, "", new LockingServiceException("DB_LOCKING_SERVICE", new Object[] {"update"}));
+ }
+ } catch (SQLException se) {
+ logger.log(Level.SEVERE, "", se);
+ } finally {
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException se) {
+
+ // Don't really care if there is a problem closing
+ }
+ stmt = null;
+ }
+
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException se) {
+
+ // Don't really care if there is a problem closing
+ }
+ conn = null;
+ }
+ }
+ }
+
+ private DataSource m_dataSource = null;
+
+ private static final String DB_LOCKING_SERVICE_THE_DB = "java:comp/env/jdbc/theDB";
+ private static final String DB_LOCKING_SERVICE_UPDATE = "update BPE_MUTEX set touch = ? where id = ?";
+ private static final String DB_LOCKING_SERVICE_SELECT = "select count(*) from BPE_MUTEX";
+ private static final String DB_LOCKING_SERVICE_DELETE = "delete from BPE_MUTEX";
+ private static final String DB_LOCKING_SERVICE_INSERT = "insert into BPE_MUTEX (id, touch) values (?, ?)";
+ private static final String DB_LOCKING_SERVICE_BATCH_INSERT = "insert into BPE_MUTEX select 0-id, touch from BPE_MUTEX";
+ private static final String DB_LOCKING_SERVICE_CREATE = "create table BPE_MUTEX(id integer, touch char(1))";
+ private static final String DB_LOCKING_SERVICE_INDEX = "create unique index pk_BPE_MUTEX on BPE_MUTEX(id)";
+
+ private static boolean initialized = false;
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/IMLockingService.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/IMLockingService.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/IMLockingService.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/IMLockingService.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.ode.locking;
+
+//import java.util.logging.Logger;
+
+import org.apache.ode.util.BPEProperties;
+
+/**
+ *
+ * @author cpotter
+ *
+ * This class is used by BPE code that needs an exclusive lock on a shared
+ * resource. This class is intended for use with the in-memory BPE
+ * configuration.
+ *
+ */
+public class IMLockingService implements LockingService {
+
+// private static Logger logger =
+// Logger.getLogger(IMLockingService.class.getName());
+
+ /* (non-Javadoc)
+ * @see org.apache.ode.locking.LockingService#lock()
+ */
+ public void lock(String aKey) {
+
+ // No implementation for in-memory configuration
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ode.locking.LockingService#init(org.apache.ode.util.BPEProperties)
+ */
+ public void init(BPEProperties props) {
+
+ // No implementation for in-memory configuration
+
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingService.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingService.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingService.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingService.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.locking;
+
+import org.apache.ode.util.BPEProperties;
+
+/**
+ * @author cpotter
+ *
+ * Produces locks for serialized execution.
+ *
+ */
+public interface LockingService {
+ public void lock(String aKey);
+ public void init(BPEProperties props) throws LockingServiceException;
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingServiceException.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingServiceException.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingServiceException.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingServiceException.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.locking;
+
+import org.apache.ode.util.BPException;
+
+/**
+ * @author cpotter
+ *
+ *
+ *
+ */
+public class LockingServiceException extends BPException {
+
+ static final long serialVersionUID = -1788410114530593675L;
+
+
+ /**
+ * @param message_id
+ * @param msgParams
+ */
+ public LockingServiceException(String message_id, Object[] msgParams) {
+ super(message_id, msgParams);
+ }
+
+ /**
+ * @param message_id
+ * @param msgParams
+ * @param cause
+ */
+ public LockingServiceException(
+ String message_id,
+ Object[] msgParams,
+ Throwable cause) {
+ super(message_id, msgParams, cause);
+ }
+
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingServiceFactory.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingServiceFactory.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingServiceFactory.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/locking/LockingServiceFactory.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.locking;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.ode.util.BPEProperties;
+import org.apache.ode.util.BPException;
+
+/**
+ * @author cpotter
+ *
+ * Instantiates an implementation of LockingService
+ *
+ */
+public class LockingServiceFactory {
+
+private static Logger logger =
+ Logger.getLogger(LockingServiceFactory.class.getName());
+
+ public static LockingService createLockingService(BPEProperties props)
+ throws LockingServiceException {
+ LockingService ls = null;
+
+ try {
+ // load the implementation
+ Class lockClass = java.lang.Class.forName(props.getLockingServiceClass());
+ // try to instantiate the subclass
+ ls = (LockingService) lockClass.newInstance();
+ ls.init(props);
+
+ } catch (ClassNotFoundException e) {
+ LockingServiceException lse = new LockingServiceException("CLASS_NOT_FOUND",new Object[] {props.getEventDirectorClass()});
+ lse.log(logger,Level.SEVERE);
+ throw lse;
+ } catch (InstantiationException e) {
+ LockingServiceException lse = new LockingServiceException("NATIVE_EXCEPTION",new Object[] {"InstantiationException"},e);
+ lse.log(logger,Level.SEVERE);
+ throw lse;
+ } catch (IllegalAccessException e) {
+ LockingServiceException lse = new LockingServiceException("NATIVE_EXCEPTION",new Object[] {"IllegalAccessException"},e);
+ lse.log(logger,Level.SEVERE);
+ throw lse;
+ } catch (BPException e) {
+ throw new LockingServiceException("BPE_EXCEPTION",new Object[]{},e);
+ }
+
+ return ls;
+
+ }
+}
Added: incubator/ode/scratch/ode/src/main/java/org/apache/ode/pool/MinMaxObjPool.java
URL: http://svn.apache.org/viewcvs/incubator/ode/scratch/ode/src/main/java/org/apache/ode/pool/MinMaxObjPool.java?rev=381694&view=auto
==============================================================================
--- incubator/ode/scratch/ode/src/main/java/org/apache/ode/pool/MinMaxObjPool.java (added)
+++ incubator/ode/scratch/ode/src/main/java/org/apache/ode/pool/MinMaxObjPool.java Tue Feb 28 08:31:48 2006
@@ -0,0 +1,399 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package org.apache.ode.pool;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An ObjPool abstract class that has an initial size and an
+ * optional max size. The pool will grow as needed by blocks
+ * until the max size is reached.
+ *
+ * if max pool size is set to -1, the pool grows
+ * forever. if max pool and min pool are the same,
+ * the pool does not grow beyond what was initialized
+ * unless specifically told to do so.
+ *
+ * @author Bill Flood
+ * @version 1.1
+ * @see ObjPool
+ * @see SimpleObjPool
+ * @since 1.1
+ */
+public abstract class MinMaxObjPool extends SimpleObjPool {
+ private int maxPoolSize = -1;
+ private int initialPoolSize = 1;
+ private int createWaitTime = 0;
+ private int growBlock = 1;
+ // Passed in by subclass (don't care if it is a Set or List).
+ protected Collection pool;
+
+ private static Logger logger =
+ Logger.getLogger(MinMaxObjPool.class.getName());
+
+ /**
+ * Types of objects for which this pool
+ * has been initialized. If we did not check this
+ * the object type requested might not be found in the
+ * pool and the user would wait forever for one of this
+ * type to be checked in.
+ */
+ Set supportedTypes = Collections.synchronizedSet(new HashSet());
+
+ /**
+ * User Supplied routine to identify which object
+ * in the pool to use. Allows the user to supply
+ * which object in the pool they determine is
+ * "best" suited at this time.
+ *
+ * @param factory factory used to match, if necessary. This is the
+ * same factory passed into checkout (by the user)
+ * that resulted in this method being called.
+ * @param auth Authorization object passed into the checkout
+ * method that resulted in this method being called.
+ * @param objSpec Object specification passed into checkout that
+ * resulted in this object being called.
+ * @return
+ * @exception Exception
+ * @since 1.1
+ */
+ abstract protected ObjPoolObject getUserIdentifiedObject(Object factory, Object auth, Object objSpec) throws PoolException;
+
+ /**
+ * Initialize the object pool. Checked out
+ * objects will be monitored if monitorCheckedOutObjects
+ * is true.
+ *
+ * @param pool The collection to use. It must be empty.
+ * @param monitorCheckedOutObjects
+ * If true, the pool monitors objects (retain a reference)
+ * to objects that have been checked out from the
+ * pool.
+ * @since 1.1
+ */
+ public MinMaxObjPool(Collection pool, boolean monitorCheckedOutObjects) throws PoolException {
+ super(monitorCheckedOutObjects);
+ if (pool.isEmpty() == false) {
+ PoolException pe = new PoolException("POOL_INIT_1",null);
+ pe.log(logger,Level.SEVERE);
+ throw pe;
+ }
+ this.pool = pool;
+ }
+
+ /**
+ * Initialize the object pool. Checked out
+ * objects will be monitored.
+ *
+ * The Collection used to initialize the pool must
+ * be empty.
+ *
+ * @param pool
+ * @since 1.1
+ */
+ public MinMaxObjPool(Collection pool) throws PoolException {
+ super();
+ if (pool.isEmpty() == false) {
+ PoolException pe = new PoolException("POOL_INIT_1",null);
+ pe.log(logger,Level.SEVERE);
+ throw pe;
+ }
+ this.pool = pool;
+ }
+
+ /**
+ * Overridden method to ensure that we don't block on objects that this
+ * pool has not been initialized to contain based on the objectSpec argument.
+ *
+ * @param factory factory used to match, if necessary. This is the
+ * same factory passed into checkout (by the user)
+ * that resulted in this method being called.
+ * @param auth Authorization object passed into the checkout
+ * method that resulted in this method being called.
+ * @param objectSpec
+ * @return
+ * @exception Exception
+ * @since 1.1
+ */
+ public ObjPoolObject checkout(Object factory, Object auth, Object objectSpec) throws PoolException {
+ if (supportedTypes.contains(objectSpec) == false) {
+ PoolException pe = new PoolException("POOL_INIT_2",null);
+ pe.log(logger,Level.SEVERE);
+ throw pe;
+ }
+ return super.checkout(factory, auth, objectSpec);
+ }
+
+ /**
+ * Get the number of objects in the pool that are available.
+ *
+ * @return
+ */
+ public int getObjPoolSize() {
+ return this.pool.size();
+ }
+
+ /**
+ * Get the current size of the pool. Returns (objects available
+ * + objects in use)
+ *
+ * @return
+ */
+ public int getCurrentPoolSize() {
+ int size = 0;
+ synchronized (sync) {
+ size = getObjPoolSize() + getObjectsInUse();
+ }
+ return size;
+ }
+
+ /**
+ * Gets the next object from the pool. If the pool is
+ * empty, it is grown by not more than poolGrowBlock elements
+ * up to maxPoolSize total.
+ *
+ * @param factory
+ * @param auth
+ * @param objSpec
+ * @return
+ * @exception Exception If there is a problem getting the next object from the pool -- could be caused by the createObjPoolObject() throwing an exception.
+ */
+ protected ObjPoolObject getNextPoolObject(Object factory, Object auth, Object objSpec) throws PoolException
+ {
+ // pool's not empty -- just get one from there
+ ObjPoolObject ret = null;
+ synchronized (sync) {
+
+ // Let the implementation tell if it's already in the pool
+ // and the best one to use if it is.
+ ret = getUserIdentifiedObject(factory, auth, objSpec);
+ if (ret != null) {
+ return ret;
+ }
+ // grow the pool by "growBlock" elements.
+ else if (getCurrentPoolSize() < maxPoolSize) {
+ int currentPoolSize = getCurrentPoolSize();
+ for (int i=1; i<growBlock && maxPoolSize >= currentPoolSize; i++) {
+ pool.add(createObjPoolObject(factory, auth, objSpec));
+ doCreateWait();
+ }
+ return createObjPoolObject(factory, auth, objSpec);
+ }
+ // special case -- if pool size == -1, grow forever.
+ else if (maxPoolSize == -1) {
+ for (int i=1; i<growBlock; i++) {
+ pool.add(createObjPoolObject(factory, auth, objSpec));
+ doCreateWait();
+ }
+ return createObjPoolObject(factory, auth, objSpec);
+ }
+ }
+ // null - nothing in pool that matches right now.
+ return ret;
+ }
+
+ /**
+ * Change the maximum size of the object pool.
+ *
+ * @param size
+ * @exception PoolException
+ * If the number of objects in use is
+ * greater than the desired size of the pool, or if the
+ * desired size is smaller than the initial size for
+ * this pool, or if we would need to evict objects
+ * from the pool.
+ */
+ public void setMaxObjPoolSize(int size) throws PoolException
+ {
+ synchronized (sync) {
+ if (size < getObjectsInUse()) {
+ PoolException pe = new PoolException("POOL_ADJ_1",null);
+ pe.log(logger,Level.SEVERE);
+ throw pe;
+ }
+ if (size < initialPoolSize) {
+ PoolException pe = new PoolException("POOL_ADJ_2",null);
+ pe.log(logger,Level.SEVERE);
+ throw pe;
+ }
+ // Would objects get evicted?
+ if (getCurrentPoolSize() - size > 0) {
+ PoolException pe = new PoolException("POOL_ADJ_3",null);
+ pe.log(logger,Level.SEVERE);
+ throw pe;
+ }
+ maxPoolSize = size;
+ }
+ }
+
+ private void doCreateWait() {
+ if (createWaitTime > 0) {
+ try {
+ Thread.sleep(createWaitTime);
+ }
+ catch (InterruptedException x) {
+ ;
+ }
+ }
+ }
+
+ /**
+ * Initialize the pool.
+ * Reads the following from the Properties:
+ *
+ * pool.initialSize(Integer)
+ * The initial pool size (default is 1).
+ *
+ * pool.maxSize (Integer)
+ * The max pool size (default is -1). If the max
+ * pool size is -1, the pool grows infinitely.
+ *
+ * pool.growBlock (Integer)
+ * The grow size (default is 1). When a new
+ * object is needed, this many are created.
+ *
+ * pool.createWaitTime (Integer)
+ * The time (in ms) to sleep between pool object creates
+ * (default is 0).
+ *
+ * @param prop
+ * @param factory
+ * @param auth
+ * @param objSpec
+ * @exception Exception If there is an exception initializing the pool.
+ */
+ public void init(Properties prop, Object factory, Object auth, Object objSpec)
+ throws PoolException
+ {
+ if (pool.isEmpty() == false) {
+ PoolException pe = new PoolException("POOL_INIT_3",null);
+ pe.log(logger,Level.SEVERE);
+ throw pe;
+ }
+
+ String value = prop.getProperty("pool.initialSize");
+ if (value != null) initialPoolSize = Integer.parseInt(value);
+ value = prop.getProperty("pool.maxSize");
+ if (value != null) maxPoolSize = Integer.parseInt(value);
+ value = prop.getProperty("pool.growBlock");
+ if (value != null) growBlock = Integer.parseInt(value);
+ value = prop.getProperty("pool.createWaitTime");
+ if (value != null) createWaitTime = Integer.parseInt(value);
+
+ // load up the pool.
+ for (int i=0; i<initialPoolSize; i++) {
+ pool.add(createObjPoolObject(factory, auth, objSpec));
+ }
+ supportedTypes.add(objSpec);
+ }
+
+ /**
+ * Calls deleteObjPoolObject() on all objects
+ * currently in the pool, and then re-creates the initial
+ * number of them.
+ *
+ * @exception Exception If there is an exception re-initializing the pool.
+ */
+ public void reInitializeObjPool(Object factory, Object auth, Object objSpec)
+ throws Exception
+ {
+ synchronized (sync) {
+ Iterator it = pool.iterator();
+ while (it.hasNext()) {
+ ObjPoolObject obj = (ObjPoolObject)it.next();
+ obj.deleteObjPoolObject();
+ }
+ pool.clear();
+
+ for (int i=0; i<initialPoolSize; i++) {
+ pool.add(createObjPoolObject(factory, auth, objSpec));
+ doCreateWait();
+ }
+ }
+ // Synchronized object.
+ supportedTypes.add(objSpec);
+ }
+
+ /**
+ * @exception Exception If there is an exception re-initializing the pool.
+ */
+ public void growObjPool(int additionalSize, Object factory, Object auth, Object objSpec)
+ throws Exception
+ {
+ synchronized (sync) {
+ setMaxObjPoolSize(getInitialObjPoolSize() + additionalSize);
+ for (int i=0; i<additionalSize; i++) {
+ pool.add(createObjPoolObject(factory, auth, objSpec));
+ doCreateWait();
+ }
+ }
+ // Synchronized object.
+ supportedTypes.add(objSpec);
+ }
+
+
+ /**
+ * @see SimpleObjPool
+ */
+ //protected void checkinPoolObject(ObjPoolObject o) {
+ // pool.add(o);
+ //}
+
+ /**
+ * Get the initial size of the pool.
+ */
+ public int getInitialObjPoolSize() {
+ return this.initialPoolSize;
+ }
+
+ /**
+ * Get the maximum number of objects this pool will hold.
+ */
+ public int getMaxObjPoolSize() {
+ return this.maxPoolSize;
+ }
+
+ /**
+ * Get the number of objects the pool should grow by when
+ * it needs to grow.
+ */
+ public int getObjPoolGrowSize() {
+ return this.growBlock;
+ }
+
+ /**
+ * Get the number of milliseconds to sleep between
+ * creates of new objects for the pool.
+ */
+ public int getCreateWaitTime() {
+ return this.createWaitTime;
+ }
+
+ /**
+ * Add a supported type
+ */
+ public void addSupportedType(Object objectSpec) {
+ supportedTypes.add(objectSpec);
+ }
+
+}