http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Properties.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Properties.java b/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Properties.java deleted file mode 100644 index 920b349..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Properties.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2008 Wen Tao. All Rights Reserved. - * - * 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.qi4j.library.beans.properties; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -class Properties -{ - private Map<String, Object> properties = new HashMap<String, Object>(); - private static final String PREFIX_LIST_NAME = "l:"; - private static final String PREFIX_VALUE_NAME = "v:"; - - public Object get( String propertyName ) - { - String name = encodeValueName( propertyName ); - return properties.get( name ); - } - - public void set( String propertyName, Object value ) - { - String name = encodeValueName( propertyName ); - if( value == null ) - { - properties.remove( name ); - } - else - { - properties.put( name, value ); - } - } - - public void add( String propertyName, Object value ) - { - String name = encodeListName( propertyName ); - ArrayList list = (ArrayList) properties.get( name ); - if( list == null ) - { - list = new ArrayList(); - properties.put( name, list ); - } - list.add( value ); - } - - public void remove( String propertyName, Object value ) - { - String name = encodeListName( propertyName ); - ArrayList list = (ArrayList) properties.get( name ); - if( list != null ) - { - list.remove( value ); - if( list.size() == 0 ) - { - properties.remove( name ); - } - } - } - - public Iterator iterator( String propertyName ) - { - String name = encodeListName( propertyName ); - ArrayList list = (ArrayList) properties.get( name ); - if( list != null ) - { - return list.iterator(); - } - return new Iterator() - { - public boolean hasNext() - { - return false; - } - - public Object next() - { - return null; - } - - public void remove() - { - } - }; - } - - private String encodeValueName( String propertyName ) - { - return PREFIX_VALUE_NAME + propertyName; - } - - private String encodeListName( String propertyName ) - { - return PREFIX_LIST_NAME + propertyName; - } - -} -
http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/properties/PropertiesMixin.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/PropertiesMixin.java b/libraries/beans/src/main/java/org/qi4j/library/beans/properties/PropertiesMixin.java deleted file mode 100644 index 4032870..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/PropertiesMixin.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2007 Rickard Ãberg. All Rights Reserved. - * Copyright 2007 Alin Dreghiciu. All Rights Reserved. - * Copyright 2007 Edward Yakop. All Rights Reserved. - * - * 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.qi4j.library.beans.properties; - -import org.qi4j.api.common.AppliesTo; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -/** - * Generic property mixin. Methods in interface - * can be of the following types: - * setFoo = set property named foo - * getFoo = get property named foo - * addFoo = add object to list named foo - * removeFoo = remove object from list named foo - * fooIterator - return an iterator over the list of Foos - */ -@AppliesTo( { Getters.class, Setters.class, Iterables.class } ) -public class PropertiesMixin implements InvocationHandler -{ - private static final PropertyHandler[] HANDLERS = new PropertyHandler[] - { - new AbstractPropertyHandler( Setters.SET ) - { - protected Object handleProperty( Properties properties, String propertyName, Object[] args ) - { - properties.set( propertyName, args[ 0 ] ); - return null; - } - }, - new GetPropertyHandler( Getters.GET ), - new GetPropertyHandler( Getters.IS ), - new GetPropertyHandler( Getters.HAS ), - new AbstractPropertyHandler( Setters.ADD ) - { - public Object handleProperty( Properties properties, String propertyName, Object[] args ) - { - properties.add( propertyName, args[ 0 ] ); - return null; - } - }, - new AbstractPropertyHandler( Setters.REMOVE ) - { - protected Object handleProperty( Properties properties, String propertyName, Object[] args ) - { - properties.remove( propertyName, args[ 0 ] ); - return null; - } - }, - new AbstractPropertyHandler( new Iterables() ) - { - protected Object handleProperty( Properties properties, String propertyName, Object[] args ) - { - return properties.iterator( propertyName ); - } - } - }; - - // Attributes ---------------------------------------------------- - Properties properties; - - /** - * Construct and empty properties mixins. - * - * @since 0.1.0 - */ - public PropertiesMixin() - { - properties = new Properties(); - } - - // InvocationHandler implementation ------------------------------ - @SuppressWarnings( "unchecked" ) - public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable - { - String methodName = method.getName(); - for( PropertyHandler handler : HANDLERS ) - { - if( handler.shouldHandle( methodName ) ) - { - return handler.handleInvocation( properties, methodName, args ); - } - } - return null; - } - - private interface PropertyHandler - { - boolean shouldHandle( String methodName ); - - Object handleInvocation( Properties properties, String methodName, Object[] args ); - } - - private static abstract class AbstractPropertyHandler implements PropertyHandler - { - private PropertyNameExtractor propertyNameExtractor; - - public AbstractPropertyHandler( PropertyNameExtractor propertyNameExtractor ) - { - this.propertyNameExtractor = propertyNameExtractor; - } - - public Object handleInvocation( Properties properties, String methodName, Object[] args ) - { - String propertyName = propertyNameExtractor.extractPropertyName( methodName ); - return handleProperty( properties, propertyName, args ); - } - - protected abstract Object handleProperty( Properties properties, String propertyName, Object[] args ); - - public boolean shouldHandle( String methodName ) - { - return propertyNameExtractor.extractPropertyName( methodName ) != null; - } - } - - private static final class GetPropertyHandler extends AbstractPropertyHandler - { - public GetPropertyHandler( PropertyNameExtractor propertyNameExtractor ) - { - super( propertyNameExtractor ); - } - - protected Object handleProperty( Properties properties, String propertyName, Object[] args ) - { - return properties.get( propertyName ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/properties/PropertyNameExtractor.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/PropertyNameExtractor.java b/libraries/beans/src/main/java/org/qi4j/library/beans/properties/PropertyNameExtractor.java deleted file mode 100644 index 1ad2d53..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/PropertyNameExtractor.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2008 Wen Tao. All Rights Reserved. - * - * 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.qi4j.library.beans.properties; - -public interface PropertyNameExtractor -{ - String extractPropertyName( String methodName ); -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Setters.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Setters.java b/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Setters.java deleted file mode 100644 index 19d1404..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/properties/Setters.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.qi4j.library.beans.properties; - -import org.qi4j.api.common.AppliesToFilter; - -import java.lang.reflect.Method; - -/** - * Filter for setter methods. Method name must match "set*","add*" or "remove*". - */ -public class Setters implements AppliesToFilter -{ - public static final MethodPrefixFilter SET = new MethodPrefixFilter( "set" ); - public static final MethodPrefixFilter ADD = new MethodPrefixFilter( "add" ); - public static final MethodPrefixFilter REMOVE = new MethodPrefixFilter( "remove" ); - public static final AppliesToFilter SETTERS = new OrAppliesToFilter( SET, ADD, REMOVE ); - - public boolean appliesTo( Method method, Class mixin, Class compositeType, Class modelClass ) - { - return SETTERS.appliesTo( method, mixin, compositeType, modelClass ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/support/DelegatingIterator.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/support/DelegatingIterator.java b/libraries/beans/src/main/java/org/qi4j/library/beans/support/DelegatingIterator.java deleted file mode 100644 index c8bb012..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/support/DelegatingIterator.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. All rights Reserved. - * - * 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.qi4j.library.beans.support; - -import org.qi4j.api.composite.TransientBuilderFactory; - -import java.util.Iterator; -import org.qi4j.api.association.AssociationDescriptor; - -public class DelegatingIterator - implements Iterator -{ - private Iterator source; - private final AssociationDescriptor info; - private final TransientBuilderFactory cbf; - - public DelegatingIterator( Iterator source, AssociationDescriptor info, TransientBuilderFactory cbf ) - { - this.source = source; - this.info = info; - this.cbf = cbf; - } - - public boolean hasNext() - { - return source.hasNext(); - } - - public Object next() - { - return Wrapper.wrap( source.next(), info, cbf ); - } - - public void remove() - { - source.remove(); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/support/DelegatingListIterator.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/support/DelegatingListIterator.java b/libraries/beans/src/main/java/org/qi4j/library/beans/support/DelegatingListIterator.java deleted file mode 100644 index 4dc5fb5..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/support/DelegatingListIterator.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. All rights Reserved. - * - * 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.qi4j.library.beans.support; - -import org.qi4j.api.composite.TransientBuilderFactory; - -import java.util.ListIterator; -import org.qi4j.api.association.AssociationDescriptor; - -public class DelegatingListIterator - implements ListIterator -{ - private ListIterator source; - private final AssociationDescriptor info; - private final TransientBuilderFactory cbf; - - public DelegatingListIterator( ListIterator source, AssociationDescriptor info, TransientBuilderFactory cbf ) - { - this.source = source; - this.info = info; - this.cbf = cbf; - } - - public boolean hasNext() - { - return source.hasNext(); - } - - public Object next() - { - return Wrapper.wrap( source.next(), info, cbf ); - } - - public boolean hasPrevious() - { - return source.hasPrevious(); - } - - public Object previous() - { - return Wrapper.wrap( source.previous(), info, cbf ); - } - - public int nextIndex() - { - return source.nextIndex(); - } - - public int previousIndex() - { - return source.previousIndex(); - } - - public void remove() - { - source.remove(); - } - - public void set( Object o ) - { - throw new UnsupportedOperationException( "Read Only." ); - } - - public void add( Object o ) - { - throw new UnsupportedOperationException( "Read Only." ); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanAssociation.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanAssociation.java b/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanAssociation.java deleted file mode 100644 index a30e495..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanAssociation.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. All rights Reserved. - * - * 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.qi4j.library.beans.support; - -import org.qi4j.api.common.QualifiedName; -import org.qi4j.api.association.Association; -import org.qi4j.api.composite.TransientBuilder; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.lang.reflect.UndeclaredThrowableException; -import org.qi4j.api.association.AssociationDescriptor; - -public class JavabeanAssociation - implements Association -{ - private final JavabeanMixin javabeanMixin; - private final AssociationDescriptor descriptor; - public final Method pojoMethod; - - public JavabeanAssociation( JavabeanMixin javabeanMixin, AssociationDescriptor descriptor, Method pojoMethod ) - { - this.javabeanMixin = javabeanMixin; - this.descriptor = descriptor; - this.pojoMethod = pojoMethod; - } - - public <T> T metaInfo( Class<T> infoType ) - { - return descriptor.metaInfo( infoType ); - } - - public QualifiedName qualifiedName() - { - return descriptor.qualifiedName(); - } - - public Type type() - { - return descriptor.type(); - } - - public boolean isImmutable() - { - return descriptor.isImmutable(); - } - - public boolean isAggregated() - { - return descriptor.isAggregated(); - } - - public Object get() - { - try - { - Object resultObject = pojoMethod.invoke( javabeanMixin.pojo ); - Class type = (Class) type(); - if( type.isInterface() ) - { - TransientBuilder<?> builder = javabeanMixin.cbf.newTransientBuilder( type ); - builder.use( resultObject ); - return builder.newInstance(); - } - return resultObject; - } - catch( IllegalAccessException e ) - { - throw new IllegalArgumentException( "POJO is not compatible with JavaBeans specification. Method must be public: " + pojoMethod ); - } - catch( InvocationTargetException e ) - { - throw new UndeclaredThrowableException( e.getTargetException() ); - } - } - - public void set( Object associated ) throws IllegalArgumentException - { - //TODO: Auto-generated, need attention. - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanManyAssociation.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanManyAssociation.java b/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanManyAssociation.java deleted file mode 100644 index c8a96b8..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanManyAssociation.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. All rights Reserved. - * - * 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.qi4j.library.beans.support; - -import org.qi4j.api.common.QualifiedName; -import org.qi4j.api.association.AssociationDescriptor; -import org.qi4j.api.association.ManyAssociation; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.lang.reflect.UndeclaredThrowableException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; -import java.util.List; - -public class JavabeanManyAssociation - implements ManyAssociation -{ - private final JavabeanMixin javabeanMixin; - private final AssociationDescriptor descriptor; - private final Method pojoMethod; - - public JavabeanManyAssociation( JavabeanMixin javabeanMixin, AssociationDescriptor descriptor, Method pojoMethod ) - { - this.javabeanMixin = javabeanMixin; - this.descriptor = descriptor; - this.pojoMethod = pojoMethod; - } - - public <T> T metaInfo( Class<T> infoType ) - { - return descriptor.metaInfo( infoType ); - } - - public QualifiedName qualifiedName() - { - return descriptor.qualifiedName(); - } - - public Type type() - { - return descriptor.type(); - } - - public boolean isImmutable() - { - return descriptor.isImmutable(); - } - - public boolean isAggregated() - { - return descriptor.isAggregated(); - } - - public int size() - { - return delegate().size(); - } - - public boolean isEmpty() - { - return delegate().isEmpty(); - } - - public int count() - { - return 0; //To change body of implemented methods use File | Settings | File Templates. - } - - public boolean contains( Object object ) - { - return delegate().contains( Wrapper.unwrap( object ) ); - } - - public boolean add( int i, Object entity ) - { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - public Iterator iterator() - { - return new DelegatingIterator( delegate().iterator(), descriptor, javabeanMixin.cbf ); - } - - public Object[] toArray() - { - Object[] objects = delegate().toArray(); - Object[] wrapped = new Object[objects.length]; - for( int i = 0; i < objects.length; i++ ) - { - wrapped[ i ] = Wrapper.wrap( objects[ i ], descriptor, javabeanMixin.cbf ); - } - return wrapped; - } - - public boolean add( Object object ) - { - throw new UnsupportedOperationException( "Read/only." ); - } - - public boolean remove( Object object ) - { - throw new UnsupportedOperationException( "Read/only." ); - } - - public Object get( int i ) - { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - public List toList() - { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - public Set toSet() - { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - public boolean addAll( Collection collection ) - { - throw new UnsupportedOperationException( "Read/only." ); - } - - public void clear() - { - throw new UnsupportedOperationException( "Read/only." ); - } - - public boolean retainAll( Collection collection ) - { - throw new UnsupportedOperationException( "Read/only." ); - } - - public boolean removeAll( Collection collection ) - { - throw new UnsupportedOperationException( "Read/only." ); - } - - public boolean containsAll( Collection collection ) - { - for( Object obj : collection ) - { - if( !contains( Wrapper.unwrap( obj ) ) ) - { - return false; - } - } - return true; - } - - public Object[] toArray( Object[] objects ) - { - Object[] array = delegate().toArray( objects ); - for( int i = 0; i < array.length; i++ ) - { - array[ i ] = Wrapper.wrap( array[ i ], descriptor, javabeanMixin.cbf ); - } - return array; - } - - private Set delegate() - { - try - { - Object resultObject = pojoMethod.invoke( javabeanMixin.pojo ); - return (Set) resultObject; - } - catch( IllegalAccessException e ) - { - throw new IllegalArgumentException( "Javabean is not compatible with JavaBeans specification. Method must be public: " + pojoMethod ); - } - catch( ClassCastException e ) - { - throw new IllegalArgumentException( "Javabean and Qi4j models are not compatible. Expected a java.util.Set in return type of " + pojoMethod ); - } - catch( InvocationTargetException e ) - { - throw new UndeclaredThrowableException( e.getTargetException() ); - } - } - - -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanMixin.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanMixin.java b/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanMixin.java deleted file mode 100644 index b6b6772..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanMixin.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. All rights Reserved. - * - * 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.qi4j.library.beans.support; - -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.util.HashMap; -import org.qi4j.api.Qi4j; -import org.qi4j.api.common.AppliesTo; -import org.qi4j.api.common.AppliesToFilter; -import org.qi4j.api.composite.Composite; -import org.qi4j.api.composite.TransientBuilderFactory; -import org.qi4j.api.association.Association; -import org.qi4j.api.association.AssociationDescriptor; -import org.qi4j.api.association.AssociationStateDescriptor; -import org.qi4j.api.association.ManyAssociation; -import org.qi4j.api.composite.CompositeDescriptor; -import org.qi4j.api.composite.StateDescriptor; -import org.qi4j.api.composite.StatefulCompositeDescriptor; -import org.qi4j.api.injection.scope.Structure; -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.injection.scope.Uses; -import org.qi4j.api.property.Property; -import org.qi4j.api.property.PropertyDescriptor; -import org.qi4j.api.structure.Module; - -@AppliesTo( { JavabeanMixin.JavabeanSupportFilter.class } ) -public class JavabeanMixin - implements JavabeanSupport, InvocationHandler -{ - private HashMap<AccessibleObject, Object> handlers; - - @Structure TransientBuilderFactory cbf; - Object pojo; - - public JavabeanMixin( @Structure Module module, @This Composite thisComposite, @Uses Object pojo ) - { - this.pojo = pojo; - this.handlers = new HashMap<AccessibleObject, Object>(); - CompositeDescriptor thisDescriptor = Qi4j.FUNCTION_DESCRIPTOR_FOR.map( thisComposite ); - if( thisDescriptor instanceof StatefulCompositeDescriptor ) - { - StateDescriptor stateDescriptor = ( (StatefulCompositeDescriptor) thisDescriptor ).state(); - for( PropertyDescriptor propDesc : stateDescriptor.properties() ) - { - Method pojoMethod = findMethod( pojo, propDesc.qualifiedName().name() ); - handlers.put( propDesc.accessor(), new JavabeanProperty( this, propDesc, pojoMethod ) ); - } - if( stateDescriptor instanceof AssociationStateDescriptor ) - { - AssociationStateDescriptor assocStateDesc = (AssociationStateDescriptor) stateDescriptor; - for( AssociationDescriptor assocDesc : assocStateDesc.associations() ) - { - Method pojoMethod = findMethod( pojo, assocDesc.qualifiedName().name() ); - handlers.put( assocDesc.accessor(), new JavabeanAssociation( this, assocDesc, pojoMethod ) ); - } - for( AssociationDescriptor assocDesc : assocStateDesc.manyAssociations() ) - { - Method pojoMethod = findMethod( pojo, assocDesc.qualifiedName().name() ); - handlers.put( assocDesc.accessor(), new JavabeanManyAssociation( this, assocDesc, pojoMethod ) ); - } - } - } - } - - private Method findMethod( Object pojo, String name ) - { - String methodName = "get" + Character.toUpperCase( name.charAt( 0 ) ) + name.substring( 1 ); - Method pojoMethod; - try - { - pojoMethod = pojo.getClass().getMethod( methodName ); - } - catch( NoSuchMethodException e ) - { - methodName = "is" + Character.toUpperCase( name.charAt( 0 ) ) + name.substring( 1 ); - try - { - pojoMethod = pojo.getClass().getMethod( methodName ); - } - catch( NoSuchMethodException e1 ) - { - throw new IllegalArgumentException( methodName + " is not present in " + pojo.getClass() ); - } - } - return pojoMethod; - } - - public Object getJavabean() - { - return pojo; - } - - public void setJavabean( Object data ) - { - pojo = data; - } - - public Object invoke( Object proxy, Method method, Object[] args ) - throws Throwable - { - synchronized( this ) - { - return handlers.get( method ); - } - } - - public static class JavabeanSupportFilter - implements AppliesToFilter - { - public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> modifierClass ) - { - String methodName = method.getName(); - Class<?> retType = method.getReturnType(); - return Property.class.isAssignableFrom( retType ) || - Association.class.isAssignableFrom( retType ) || - ManyAssociation.class.isAssignableFrom( retType ) || - "getJavabean".equals( methodName ) || "setJavabean".equals( methodName ); - } - } - -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanProperty.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanProperty.java b/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanProperty.java deleted file mode 100644 index 6ca01f7..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanProperty.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. All rights Reserved. - * - * 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.qi4j.library.beans.support; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.UndeclaredThrowableException; -import java.util.Arrays; -import java.util.List; -import org.qi4j.api.composite.TransientBuilder; -import org.qi4j.api.composite.TransientBuilderFactory; -import org.qi4j.api.property.Property; -import org.qi4j.api.property.PropertyDescriptor; - -public class JavabeanProperty implements Property -{ - private final JavabeanMixin javabeanMixin; - private final PropertyDescriptor descriptor; - private final Method pojoMethod; - - public JavabeanProperty( JavabeanMixin javabeanMixin, PropertyDescriptor descriptor, Method pojoMethod ) - { - this.javabeanMixin = javabeanMixin; - this.descriptor = descriptor; - this.pojoMethod = pojoMethod; - } - - public Object get() - { - try - { - Object resultObject = pojoMethod.invoke( javabeanMixin.pojo ); - return wrap( javabeanMixin.cbf, resultObject ); - } - catch( IllegalAccessException e ) - { - throw new IllegalArgumentException( "POJO is not compatible with JavaBeans specification. Method must be public: " + pojoMethod ); - } - catch( InvocationTargetException e ) - { - throw new UndeclaredThrowableException( e.getTargetException() ); - } - } - - private Object wrap( TransientBuilderFactory factory, Object resultObject ) - { - if( resultObject == null ) - { - return null; - } - Type type = descriptor.type(); - if( type instanceof Class ) - { - Class clazz = (Class) type; - if( clazz.isInterface() ) - { - if( clazz.equals( List.class ) ) - { - if( resultObject.getClass().isArray() ) - { - resultObject = Arrays.asList( (Object[]) resultObject ); - } - } - if( clazz.isArray() ) - { - if( List.class.isAssignableFrom( resultObject.getClass() ) ) - { - resultObject = ( (List) resultObject ).toArray(); - } - } - TransientBuilder<?> builder = factory.newTransientBuilder( clazz ); - builder.use( resultObject ); - return builder.newInstance(); - } - } - if( type instanceof ParameterizedType ) - { - if( !resultObject.getClass().equals( type ) ) - { - ParameterizedType paramtype = (ParameterizedType) type; - Type rawType = paramtype.getRawType(); - Type actType = paramtype.getActualTypeArguments()[ 0 ]; - if( List.class.isAssignableFrom( (Class<?>) rawType ) ) - { - if( !( actType instanceof Class ) || - ( (Class) actType ).isInstance( resultObject ) ) - { - String message = "The type " + paramtype + " is not compatible with " + resultObject.getClass(); - throw new IllegalArgumentException( message ); - } - if( resultObject.getClass().isArray() ) - { - resultObject = Arrays.asList( (Object[]) resultObject ); - } - } - } - } - return resultObject; - } - - public void set( Object newValue ) - throws IllegalArgumentException, IllegalStateException - { - //TODO: Auto-generated, need attention. - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanSupport.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanSupport.java b/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanSupport.java deleted file mode 100644 index faa9e96..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/support/JavabeanSupport.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. All rights Reserved. - * - * 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.qi4j.library.beans.support; - -import org.qi4j.api.mixin.Mixins; - -/** - * This mixin type is used to have a POJO (Spring's definition) as the backing implementation - * of the mixin state. - */ -@Mixins( JavabeanMixin.class ) -public interface JavabeanSupport<T> -{ - T getJavabean(); - - void setJavabean( T data ); -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/main/java/org/qi4j/library/beans/support/Wrapper.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/main/java/org/qi4j/library/beans/support/Wrapper.java b/libraries/beans/src/main/java/org/qi4j/library/beans/support/Wrapper.java deleted file mode 100644 index d717f75..0000000 --- a/libraries/beans/src/main/java/org/qi4j/library/beans/support/Wrapper.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. All rights Reserved. - * - * 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.qi4j.library.beans.support; - -import org.qi4j.api.composite.TransientBuilderFactory; -import org.qi4j.api.composite.TransientBuilder; -import org.qi4j.api.association.AssociationDescriptor; - -public class Wrapper -{ - static Object wrap( Object resultObject, AssociationDescriptor info, TransientBuilderFactory cbf ) - { - Class type = (Class) info.type(); - if( type.isInterface() ) - { - TransientBuilder<?> builder = cbf.newTransientBuilder( type ); - builder.use( resultObject ); - return builder.newInstance(); - } - return resultObject; - } - - static Object unwrap( Object object ) - { - if( object instanceof JavabeanSupport ) - { - return ( (JavabeanSupport) object ).getJavabean(); - } - return object; - } - -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/test/java/org/qi4j/library/beans/properties/PropertiesMixinTest.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/test/java/org/qi4j/library/beans/properties/PropertiesMixinTest.java b/libraries/beans/src/test/java/org/qi4j/library/beans/properties/PropertiesMixinTest.java deleted file mode 100644 index 8ca4dee..0000000 --- a/libraries/beans/src/test/java/org/qi4j/library/beans/properties/PropertiesMixinTest.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright 2007 Alin Dreghiciu. All Rights Reserved. - * - * 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.qi4j.library.beans.properties; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static org.junit.Assert.*; -import org.junit.Before; -import org.junit.Test; -import org.qi4j.api.composite.TransientBuilder; -import org.qi4j.api.composite.TransientComposite; -import org.qi4j.api.mixin.Mixins; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.test.AbstractQi4jTest; - -import java.util.Iterator; - -public class PropertiesMixinTest extends AbstractQi4jTest -{ - private SampleJavaBean m_proxy; - - public void assemble( ModuleAssembly aModule ) throws AssemblyException - { - aModule.transients( SampleJavaBeanComposite.class ); - } - - @Override - @Before - public void setUp() throws Exception - { - super.setUp(); - TransientBuilder<SampleJavaBeanComposite> builder = module.newTransientBuilder( SampleJavaBeanComposite.class ); - m_proxy = builder.newInstance(); - } - - @Test - public void setAndGetFoo() - { - m_proxy.setFoo( "aValue" ); - assertEquals( "aValue", m_proxy.getFoo() ); - } - - @Test - public void setAndGet() - { - m_proxy.set( "aValue" ); - assertEquals( "aValue", m_proxy.get() ); - } - - @Test - public void getFooWithoutSetFoo() - { - assertEquals( null, m_proxy.getFoo() ); - } - - @Test - public void iterateBarAfterAddBar() - { - m_proxy.addBar( "aValue" ); - Iterator<String> iterator = m_proxy.barIterator(); - assertNotNull( "iterator should not be null", iterator ); - assertEquals( "iterator has a value", true, iterator.hasNext() ); - assertEquals( "iterator content", "aValue", iterator.next() ); - } - - @Test - public void iterateAfterAdd() - { - m_proxy.add( "aValue" ); - Iterator<String> iterator = m_proxy.iterator(); - assertNotNull( "iterator should not be null", iterator ); - assertEquals( "iterator has a value", true, iterator.hasNext() ); - assertEquals( "iterator content", "aValue", iterator.next() ); - } - - @Test - public void iterateBarAfterAddAndRemoveBar() - { - m_proxy.addBar( "aValue" ); - m_proxy.removeBar( "aValue" ); - Iterator<String> iterator = m_proxy.barIterator(); - assertNotNull( iterator ); - assertFalse( iterator.hasNext() ); - } - - @Test - public void iterateAfterAddAndRemove() - { - m_proxy.add( "aValue" ); - m_proxy.remove( "aValue" ); - Iterator<String> iterator = m_proxy.iterator(); - assertNotNull( iterator ); - assertFalse( iterator.hasNext() ); - } - - @Test - public void removeBarWithoutAddBar() - { - m_proxy.removeBar( "aValue" ); - } - - @Test - public void removeWithoutAdd() - { - m_proxy.remove( "aValue" ); - } - - @Test - public void iterateBarWithoutAddBar() - { - Iterator<String> iterator = m_proxy.barIterator(); - assertNotNull( "iterator not supposed to be null", iterator ); - assertFalse( iterator.hasNext() ); - } - - @Test - public void iterateWithoutAdd() - { - Iterator<String> iterator = m_proxy.barIterator(); - assertNotNull( "iterator not supposed to be null", iterator ); - assertFalse( iterator.hasNext() ); - } - - @Test - public void addFooAndGetFoo() - { - m_proxy.addFoo( "aValue" ); - assertNull( "getter supposed to be null", m_proxy.getFoo() ); - } - - @Test - public void addFooAndSetFoo() - { - m_proxy.addFoo( "addValue" ); - m_proxy.setFoo( "setValue" ); - } - - @Test - public void setFooAndAddFoo() - { - m_proxy.setFoo( "setValue" ); - m_proxy.addFoo( "addValue" ); - } - - @Test - public void setFooAndRemoveFoo() - { - m_proxy.setFoo( "aValue" ); - m_proxy.removeFoo( "aValue" ); - assertEquals( "aValue", m_proxy.getFoo() ); - } - - @Test - public void setFooAndIterateFoo() - { - m_proxy.setFoo( "aValue" ); - Iterator<String> iterator = m_proxy.fooIterator(); - assertNotNull( "iterator not supposed to be null", iterator ); - assertFalse( iterator.hasNext() ); - } - - @Test - public void setValidAndIsValid() - { - m_proxy.setValid( true ); - assertTrue( m_proxy.isValid() ); - } - - @Test - public void setTestedAndHasTested() - { - m_proxy.setTested( true ); - assertTrue( m_proxy.hasTested() ); - } - - @Mixins( PropertiesMixin.class ) - public static interface SampleJavaBeanComposite extends SampleJavaBean, TransientComposite - { - } - - public static interface SampleJavaBean - { - public String getFoo(); - - public void setFoo( String value ); - - public String get(); - - public void set( String value ); - - public void addFoo( String value ); - - public void removeFoo( String value ); - - public Iterator<String> fooIterator(); - - public void addBar( String value ); - - public void removeBar( String value ); - - public Iterator<String> barIterator(); - - public void add( String value ); - - public void remove( String value ); - - public Iterator<String> iterator(); - - public boolean isValid(); - - public void setValid( boolean value ); - - public boolean hasTested(); - - public void setTested( boolean value ); - } - -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/beans/src/test/java/org/qi4j/library/beans/support/JavabeanBackedTest.java ---------------------------------------------------------------------- diff --git a/libraries/beans/src/test/java/org/qi4j/library/beans/support/JavabeanBackedTest.java b/libraries/beans/src/test/java/org/qi4j/library/beans/support/JavabeanBackedTest.java deleted file mode 100644 index e1ed9a8..0000000 --- a/libraries/beans/src/test/java/org/qi4j/library/beans/support/JavabeanBackedTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright 2008 Niclas Hedhman. All rights Reserved. - * - * 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.qi4j.library.beans.support; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.junit.Ignore; -import org.qi4j.api.common.Optional; -import org.qi4j.api.composite.TransientComposite; -import org.qi4j.api.composite.TransientBuilder; -import org.qi4j.api.association.Association; -import org.qi4j.api.association.ManyAssociation; -import org.qi4j.api.property.Property; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.test.AbstractQi4jTest; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class JavabeanBackedTest extends AbstractQi4jTest -{ - - public void assemble( ModuleAssembly module ) throws AssemblyException - { - module.transients( PersonComposite.class, CountryComposite.class, CityComposite.class ); - } - - @Test - @Ignore - public void givenPersonPojoWhenDataIsOkThenExpectCorrectResult() - throws Exception - { - CountryPojo malaysia = new CountryPojo( "Malaysia" ); - Set<CityPojo> cities = new HashSet<CityPojo>(); - CityPojo kl = new CityPojo( "Kuala Lumpur", malaysia ); - cities.add( kl ); - CityPojo jb = new CityPojo( "Johor Bahru", malaysia ); - cities.add( jb ); - CityPojo penang = new CityPojo( "Penang", malaysia ); - cities.add( penang ); - CityPojo kk = new CityPojo( "Kota Kinabalu", malaysia ); - cities.add( kk ); - malaysia.setCities( cities ); - - List<PersonPojo> friendsNiclas = new ArrayList<PersonPojo>(); - List<PersonPojo> friendsMakas = new ArrayList<PersonPojo>(); - List<PersonPojo> friendsEdward = new ArrayList<PersonPojo>(); - PersonPojo niclasPojo = new PersonPojo( "Niclas Hedhman", kl, friendsNiclas ); - PersonPojo makasPojo = new PersonPojo( "Makas Lau", kl, friendsMakas ); - PersonPojo edwardPojo = new PersonPojo( "Edward Yakop", kl, friendsEdward ); - friendsEdward.add( makasPojo ); - friendsEdward.add( niclasPojo ); - friendsMakas.add( edwardPojo ); - friendsMakas.add( niclasPojo ); - friendsNiclas.add( makasPojo ); - friendsNiclas.add( edwardPojo ); - - TransientBuilder<Person> builder = module.newTransientBuilder( Person.class ); - builder.use( niclasPojo ); - Person niclas = builder.newInstance(); - Property<String> stringProperty = niclas.name(); - assertEquals( "Name match.", "Niclas Hedhman", stringProperty.get() ); - Property<City> cityProperty = niclas.city(); - City cityValue = cityProperty.get(); - Association<Country> countryAssociation = cityValue.country(); - Country country = countryAssociation.get(); - assertEquals( "Country match.", "Malaysia", country.name().get() ); - ManyAssociation citylist = country.cities(); - for( Object aCitylist : citylist ) - { - City city = (City) aCitylist; - String name = city.name().get(); - assertTrue( name.equals( "Kuala Lumpur" ) || - name.equals( "Johor Bahru" ) || - name.equals( "Kota Kinabalu" ) || - name.equals( "Penang" ) - ); - } - assertEquals( 4, country.cities().count() ); - } - - - public interface PersonComposite extends Person, JavabeanSupport, TransientComposite - { - } - - public interface Person - { - @Optional Property<String> name(); - - @Optional Property<City> city(); - - ManyAssociation<Person> friends(); - } - - public interface CityComposite extends City, JavabeanSupport, TransientComposite - { - } - - public interface CountryComposite extends Country, JavabeanSupport, TransientComposite - { - } - - public interface City - { - @Optional Property<String> name(); - - @Optional Association<Country> country(); - } - - public interface Country - { - @Optional Property<String> name(); - - ManyAssociation<City> cities(); - } - - public class PersonPojo - { - private String name; - private CityPojo city; - private List<PersonPojo> friends; - - public PersonPojo( String name, CityPojo city, List<PersonPojo> friends ) - { - this.name = name; - this.city = city; - this.friends = friends; - } - - public String getName() - { - return name; - } - - public CityPojo getCity() - { - return city; - } - - public List<PersonPojo> getFriends() - { - return friends; - } - } - - public class CountryPojo - { - private String countryName; - private Set<CityPojo> cities; - - public CountryPojo( String countryName ) - { - this.countryName = countryName; - } - - public String getName() - { - return countryName; - } - - public Set<CityPojo> getCities() - { - return cities; - } - - public void setCities( Set<CityPojo> cities ) - { - this.cities = cities; - } - } - - public class CityPojo - { - private final String name; - private final CountryPojo country; - - public CityPojo( String name, CountryPojo country ) - { - this.name = name; - this.country = country; - } - - public String getName() - { - return name; - } - - public CountryPojo getCountry() - { - return country; - } - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/pom.xml ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/pom.xml b/libraries/entityproxy/pom.xml deleted file mode 100644 index e046310..0000000 --- a/libraries/entityproxy/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.qi4j.sandbox</groupId> - <artifactId>qi4j-sandbox-libraries</artifactId> - <version>0-SNAPSHOT</version> - </parent> - <groupId>org.qi4j.sandbox</groupId> - <artifactId>org.qi4j.library.entityproxy</artifactId> - <name>Qi4j Library - Entityproxy</name> - <description>This library provides easy way to wrap your entities with transient composites so that qi4j-agnostic code may handle them without worrying about unit of work.</description> - <dependencies> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.api</artifactId> - </dependency> - <dependency> - <groupId>org.qi4j.library</groupId> - <artifactId>org.qi4j.library.constraints</artifactId> - <version>${version.qi4j}</version> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.testsupport</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.qi4j.core</groupId> - <artifactId>org.qi4j.core.runtime</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/EntityProxy.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/EntityProxy.java b/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/EntityProxy.java deleted file mode 100644 index f212b63..0000000 --- a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/EntityProxy.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy; - -import org.qi4j.api.concern.Concerns; -import org.qi4j.api.injection.scope.Structure; -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.property.Immutable; -import org.qi4j.api.property.Property; -import org.qi4j.api.unitofwork.UnitOfWorkFactory; -import org.qi4j.api.unitofwork.concern.UnitOfWorkConcern; -import org.qi4j.api.unitofwork.concern.UnitOfWorkPropagation; -import org.qi4j.api.unitofwork.concern.UnitOfWorkPropagation.Propagation; - -@Mixins({ - EntityProxy.EntityProxyMixin.class -}) -@Concerns({ - UnitOfWorkConcern.class -}) -public interface EntityProxy -{ - - String getEntityID(); - - Class<?> getCommonClass(); - - <EntityType> EntityType getEntity( Class<EntityType> entityClass ); - - public interface EntityProxyState - { - @Immutable - Property<String> entityID(); - - @Immutable - Property<Class<?>> commonClass(); - } - - public abstract class EntityProxyMixin - implements EntityProxy - { - - @This - private EntityProxyState _state; - - @This - private EntityProxy _meAsProxy; - - @Structure private UnitOfWorkFactory _uowf; - - @Override - public String getEntityID() - { - return this._state.entityID().get(); - } - - @Override - public Class<?> getCommonClass() - { - return this._state.commonClass().get(); - } - - @Override - @UnitOfWorkPropagation(Propagation.REQUIRED) - public <EntityType> EntityType getEntity( Class<EntityType> entityClass ) - { - return this._uowf.currentUnitOfWork().get( entityClass, this._meAsProxy.getEntityID() ); - } - - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/EntityProxyHelper.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/EntityProxyHelper.java b/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/EntityProxyHelper.java deleted file mode 100644 index 5376bee..0000000 --- a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/EntityProxyHelper.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy; - -import org.qi4j.api.concern.Concerns; -import org.qi4j.api.injection.scope.Structure; -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.service.ServiceComposite; -import org.qi4j.api.unitofwork.UnitOfWorkFactory; -import org.qi4j.api.unitofwork.concern.UnitOfWorkConcern; -import org.qi4j.api.unitofwork.concern.UnitOfWorkPropagation; -import org.qi4j.api.unitofwork.concern.UnitOfWorkPropagation.Propagation; - -/** - * - * @author Stanislav Muhametsin - */ -public interface EntityProxyHelper -{ - - public <EType, ReturnType> ReturnType getEntity( Class<ReturnType> entityClass, EType proxyOrEntity ); - - public <PType, ReturnType> ReturnType getProxy( Class<ReturnType> proxyClass, PType proxyOrEntity ); - - @Mixins({EntityProxyHelperMixin.class}) - @Concerns({UnitOfWorkConcern.class}) - public interface EntityProxyHelperService extends EntityProxyHelper, ServiceComposite - { - - } - - public abstract class EntityProxyHelperMixin - implements EntityProxyHelper - { - @Structure private UnitOfWorkFactory _uowf; - - - @Override - @UnitOfWorkPropagation(Propagation.REQUIRED) - public <EType, ReturnType> ReturnType getEntity( Class<ReturnType> entityClass, EType proxyOrEntity ) - { - return proxyOrEntity instanceof EntityProxy ? ((EntityProxy) proxyOrEntity).getEntity( entityClass ) - : entityClass.cast( this._uowf.currentUnitOfWork().get( proxyOrEntity )); - } - - @Override - @UnitOfWorkPropagation(Propagation.REQUIRED) - public <PType, ReturnType> ReturnType getProxy( Class<ReturnType> proxyClass, PType proxyOrEntity ) - { - return proxyOrEntity instanceof ProxyableEntity ? ((ProxyableEntity) this._uowf.currentUnitOfWork().get( proxyOrEntity )).getProxy( proxyClass ) - : proxyClass.cast( proxyOrEntity ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/MutualType.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/MutualType.java b/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/MutualType.java deleted file mode 100644 index d00a7b7..0000000 --- a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/MutualType.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -@Documented -public @interface MutualType -{ -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/NoCommonClassFoundException.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/NoCommonClassFoundException.java b/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/NoCommonClassFoundException.java deleted file mode 100644 index 32bd185..0000000 --- a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/NoCommonClassFoundException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy; - -public class NoCommonClassFoundException extends RuntimeException -{ - public NoCommonClassFoundException(String message) - { - super(message); - } - - public NoCommonClassFoundException(String message, Throwable cause) - { - super(message, cause); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/ProxyableEntity.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/ProxyableEntity.java b/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/ProxyableEntity.java deleted file mode 100644 index 38ce038..0000000 --- a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/ProxyableEntity.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy; - -import org.qi4j.api.composite.TransientBuilder; -import org.qi4j.api.composite.TransientBuilderFactory; -import org.qi4j.api.entity.EntityComposite; -import org.qi4j.api.entity.Lifecycle; -import org.qi4j.api.entity.LifecycleException; -import org.qi4j.api.injection.scope.Service; -import org.qi4j.api.injection.scope.Structure; -import org.qi4j.api.injection.scope.This; -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.unitofwork.UnitOfWorkCallback; -import org.qi4j.api.unitofwork.UnitOfWorkCompletionException; -import org.qi4j.api.unitofwork.UnitOfWorkFactory; -import org.qi4j.library.entityproxy.internal.EntityProxyCache; - -@Mixins({ProxyableEntity.ProxyableEntityMixin.class}) -public interface ProxyableEntity -{ - <ProxyType> ProxyType getProxy(Class<ProxyType> proxyClass); - - public abstract class ProxyableEntityMixin - implements ProxyableEntity, Lifecycle -{ - - @Service - private EntityProxyCache _proxyUtils; - - @Structure - private UnitOfWorkFactory _uowf; - - @This - private EntityComposite _meAsEntityComposite; - - @Structure private TransientBuilderFactory _tbf; - - @Override - public <ProxyType> ProxyType getProxy( Class<ProxyType> proxyClass ) - { - String id = this._meAsEntityComposite.identity().get(); - EntityProxy proxy = this._proxyUtils.getFromCache( id ); - if (proxy == null) - { - proxy = this.createProxy( proxyClass ); - this._proxyUtils.storeToCache( proxy ); - } - ProxyType result = proxyClass.cast( proxy ); - return result; - } - - private <ProxyType> EntityProxy createProxy(Class<ProxyType> proxyClass) - { - TransientBuilder<ProxyType> builder = this._tbf.newTransientBuilder(proxyClass); - EntityProxy.EntityProxyState state = builder.prototypeFor(EntityProxy.EntityProxyState.class); - Class<?> commonClass = this.doGetCommonType(proxyClass); - if (commonClass == null) - { - throw new NoCommonClassFoundException("Did not find common class for entity of type: " + this._meAsEntityComposite.getClass().getName() + " [proxyClass: " + proxyClass.getName() + "]."); - } - state.commonClass().set(commonClass); - state.entityID().set(this._meAsEntityComposite.identity().get()); - - return EntityProxy.class.cast( builder.newInstance() ); - } - - private Class<?> doGetCommonType(Class<?> clazz) - { - Class<?> result = null; - MutualType commonType = clazz.getAnnotation(MutualType.class); - if (commonType == null) - { - for (Class<?> sInterface : clazz.getInterfaces()) - { - result = this.doGetCommonType(sInterface); - if (result != null) - { - break; - } - } - - if (result == null && clazz.getSuperclass() != null) - { - result = this.doGetCommonType(clazz.getSuperclass()); - } - } - else - { - result = clazz; - } - - return result; - } - - @Override - public void create() - throws LifecycleException - { - - } - - @Override - public void remove() - throws LifecycleException - { - - final String id = this._meAsEntityComposite.identity().get(); - this._uowf.currentUnitOfWork().addUnitOfWorkCallback( new UnitOfWorkCallback() - { - - @Override - public void beforeCompletion() - throws UnitOfWorkCompletionException - { - // Nothing. - } - - @Override - public void afterCompletion( UnitOfWorkStatus status ) - { - if( status == UnitOfWorkStatus.COMPLETED ) - { - _proxyUtils.removeFromCache( id ); - } - } - } ); - - } -} -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/assembling/EntityProxyAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/assembling/EntityProxyAssembler.java b/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/assembling/EntityProxyAssembler.java deleted file mode 100644 index 8681ff5..0000000 --- a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/assembling/EntityProxyAssembler.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy.assembling; - -import org.qi4j.api.common.Visibility; -import org.qi4j.bootstrap.Assembler; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.library.entityproxy.EntityProxyHelper.EntityProxyHelperService; -import org.qi4j.library.entityproxy.internal.EntityProxyCacheService; - -/** - * - * @author Stanislav Muhametsin - */ -public class EntityProxyAssembler implements Assembler -{ - - public EntityProxyAssembler() - { - - } - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.addServices( EntityProxyCacheService.class, EntityProxyHelperService.class).visibleIn( Visibility.application ); - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/internal/EntityProxyCache.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/internal/EntityProxyCache.java b/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/internal/EntityProxyCache.java deleted file mode 100644 index c2e84a7..0000000 --- a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/internal/EntityProxyCache.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy.internal; - -import java.util.LinkedHashMap; -import java.util.Map; - -import org.qi4j.api.service.ServiceActivation; -import org.qi4j.library.constraints.annotation.GreaterThan; -import org.qi4j.library.entityproxy.EntityProxy; - -public interface EntityProxyCache extends ServiceActivation -{ - public EntityProxy getFromCache(String entityID); - - public void storeToCache(EntityProxy proxy); - - public void removeFromCache(String entityID); - - public Integer getMaxCacheSize(); - - public Integer getCurrentCacheSize(); - - public void setMaxCacheSize(@GreaterThan(0) Integer newSize); - - public abstract class EntityProxyUtilsMixin implements EntityProxyCache - { - - private static final Integer DEFAULT_MAX_PROXIES = 1000; - - private Map<String, EntityProxy> _entityProxyMapping; - - private Integer _maxProxies; - - @Override - public void activateService() throws Exception - { - this._maxProxies = DEFAULT_MAX_PROXIES; - this._entityProxyMapping = new LinkedHashMap<String, EntityProxy>(this._maxProxies); - } - - @Override - public void passivateService() throws Exception - { - } - - @Override - public Integer getCurrentCacheSize() - { - return this._entityProxyMapping.size(); - } - - @Override - public EntityProxy getFromCache( String entityID ) - { - return this._entityProxyMapping.get( entityID ); - } - @Override - public Integer getMaxCacheSize() - { - return this._maxProxies; - } - - @Override - public void removeFromCache( String entityID ) - { - this._entityProxyMapping.remove( entityID ); - } - - @Override - public void setMaxCacheSize( Integer newSize ) - { - this._maxProxies = newSize; - while (this._entityProxyMapping.size() > this._maxProxies) - { - this.removeEldestProxy(); - } - } - - @Override - public void storeToCache( EntityProxy proxy ) - { - synchronized( this._entityProxyMapping ) - { - if (this._entityProxyMapping.size() == this._maxProxies) - { - this.removeEldestProxy(); - } - this._entityProxyMapping.put( proxy.getEntityID(), proxy ); - } - } - - private void removeEldestProxy() - { - this._entityProxyMapping.remove( this._entityProxyMapping.keySet().iterator().next() ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/internal/EntityProxyCacheService.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/internal/EntityProxyCacheService.java b/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/internal/EntityProxyCacheService.java deleted file mode 100644 index cd2ab00..0000000 --- a/libraries/entityproxy/src/main/java/org/qi4j/library/entityproxy/internal/EntityProxyCacheService.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy.internal; - -import org.qi4j.api.concern.Concerns; -import org.qi4j.api.mixin.Mixins; -import org.qi4j.api.service.ServiceComposite; -import org.qi4j.api.unitofwork.concern.UnitOfWorkConcern; - -@Mixins({ - EntityProxyCache.EntityProxyUtilsMixin.class - }) -@Concerns({ - UnitOfWorkConcern.class - }) -public interface EntityProxyCacheService extends EntityProxyCache, ServiceComposite -{ - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/EntityProxyTest.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/EntityProxyTest.java b/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/EntityProxyTest.java deleted file mode 100644 index 2563be2..0000000 --- a/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/EntityProxyTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy; - -import junit.framework.Assert; - -import org.junit.Test; -import org.qi4j.api.unitofwork.ConcurrentEntityModificationException; -import org.qi4j.api.unitofwork.UnitOfWork; -import org.qi4j.api.unitofwork.UnitOfWorkCompletionException; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.library.entityproxy.EntityWithMutualType.EntityCompositeWithMutualType; -import org.qi4j.library.entityproxy.EntityWithMutualType.EntityProxyWithMutualType; -import org.qi4j.library.entityproxy.MissingMutualTypeEntity.MissingMutualTypeEntityComposite; -import org.qi4j.library.entityproxy.MissingMutualTypeEntity.MissingMutualTypeEntityProxy; -import org.qi4j.library.entityproxy.assembling.EntityProxyAssembler; -import org.qi4j.test.AbstractQi4jTest; -import org.qi4j.test.EntityTestAssembler; - -/** - * - * @author Stanislav Muhametsin - */ -public class EntityProxyTest extends AbstractQi4jTest -{ - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.entities( EntityCompositeWithMutualType.class, MissingMutualTypeEntityComposite.class ); - module.transients( EntityProxyWithMutualType.class, MissingMutualTypeEntityProxy.class ); - - EntityProxyAssembler eAss = new EntityProxyAssembler(); - eAss.assemble( module ); - - new EntityTestAssembler().assemble( module ); - } - - private <EntityType> EntityType createEntity(Class<EntityType> entityClass) throws ConcurrentEntityModificationException, UnitOfWorkCompletionException - { - UnitOfWork uow = module.newUnitOfWork(); - EntityType result = uow.newEntity( entityClass ); - uow.complete(); - return result; - } - - @Test - public void getEntityProxyTest() throws Exception - { - EntityWithMutualType entity = this.createEntity( EntityCompositeWithMutualType.class ); - - UnitOfWork uow = module.newUnitOfWork(); - EntityWithMutualType proxy = ((ProxyableEntity)uow.get( entity )).getProxy( EntityWithMutualType.class ); - uow.complete(); - - Assert.assertNotNull( "The proxy must be non-null.", proxy ); - } - - @Test - public void getProxyableEntity() throws Exception - { - EntityWithMutualType entity = this.createEntity( EntityCompositeWithMutualType.class ); - - UnitOfWork uow = module.newUnitOfWork(); - EntityWithMutualType proxy = ((ProxyableEntity)uow.get( entity )).getProxy( EntityWithMutualType.class ); - uow.complete(); - - entity = ((EntityProxy)proxy).getEntity( EntityWithMutualType.class ); - - uow = module.newUnitOfWork(); - try - { - Assert.assertNotNull( "The proxy must point to existing entity.", uow.get(entity) ); - } finally - { - uow.discard(); - } - } - - @Test(expected = NoCommonClassFoundException.class) - public void testMissingMutualType() throws Exception - { - MissingMutualTypeEntity entity = this.createEntity( MissingMutualTypeEntity.class ); - - UnitOfWork uow = module.newUnitOfWork(); - try - { - MissingMutualTypeEntity proxy = ((ProxyableEntity)uow.get( entity )).getProxy( MissingMutualTypeEntity.class ); - } finally - { - uow.complete(); - } - } - - @Test - public void changesMustPropagateToEntityTest() throws Exception - { - EntityWithMutualType entity = this.createEntity( EntityCompositeWithMutualType.class ); - - UnitOfWork uow = module.newUnitOfWork(); - EntityWithMutualType proxy = ((ProxyableEntity)uow.get( entity )).getProxy( EntityWithMutualType.class ); - uow.complete(); - - proxy.setMyString( "TestString" ); - - uow = module.newUnitOfWork(); - try - { - Assert.assertEquals( "The change must go down to entity.", "TestString", uow.get( entity ).getMyString() ); - } finally - { - uow.discard(); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/EntityWithMutualType.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/EntityWithMutualType.java b/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/EntityWithMutualType.java deleted file mode 100644 index 3d6be5b..0000000 --- a/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/EntityWithMutualType.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy; - -import org.qi4j.api.composite.TransientComposite; -import org.qi4j.api.entity.EntityComposite; -import org.qi4j.api.mixin.Mixins; - -/** - * - * @author Stanislav Muhametsin - */ -@MutualType -public interface EntityWithMutualType extends SomeRole -{ - - public interface EntityCompositeWithMutualType extends EntityWithMutualType, ProxyableEntity, EntityComposite - { - - } - - @Mixins({ SomeRole.SomeRoleProxyMixin.class }) - public interface EntityProxyWithMutualType extends EntityWithMutualType, EntityProxy, TransientComposite - { - - } - -} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/MissingMutualTypeEntity.java ---------------------------------------------------------------------- diff --git a/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/MissingMutualTypeEntity.java b/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/MissingMutualTypeEntity.java deleted file mode 100644 index 3bb3f9a..0000000 --- a/libraries/entityproxy/src/test/java/org/qi4j/library/entityproxy/MissingMutualTypeEntity.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved. - * - * 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.qi4j.library.entityproxy; - -import org.qi4j.api.composite.TransientComposite; -import org.qi4j.api.entity.EntityComposite; -import org.qi4j.api.mixin.Mixins; - -/** - * - * @author Stanislav Muhametsin - */ -public interface MissingMutualTypeEntity extends SomeRole -{ - - public interface MissingMutualTypeEntityComposite extends MissingMutualTypeEntity, ProxyableEntity, EntityComposite - { - - } - - @Mixins({ SomeRole.SomeRoleProxyMixin.class }) - public interface MissingMutualTypeEntityProxy extends MissingMutualTypeEntity, EntityProxy, TransientComposite - { - - } -}
