Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/DelegatingPartialDataObjectMapper.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/DelegatingPartialDataObjectMapper.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/DelegatingPartialDataObjectMapper.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/DelegatingPartialDataObjectMapper.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,138 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import java.util.Collection; +import java.util.Iterator; + +import com.agfa.hap.sdo.DataMapper; +import com.agfa.hap.sdo.PartialDataObject; +import com.agfa.hap.sdo.Property; +import com.agfa.hap.sdo.SnapshotDefinition; +import com.agfa.hap.sdo.Type; + +/** + * @author awvjz + * + * this datamapper wraps another datamapper and delegates to this second mapper in case the object it has to work with are not partialdataobjects + * + */ +public class DelegatingPartialDataObjectMapper<T> implements DataMapper<T> { + private DataMapper<T> delegate; + private PartialDataObjectMapper defaultMapper = new PartialDataObjectMapper(); + + public DelegatingPartialDataObjectMapper(DataMapper<T> delegateDataMapper){ + delegate = delegateDataMapper; + } + + public T create(Type type) { + T instance = delegate.create(type); + if (instance == null){ + return (T) defaultMapper.create(type); + } + return instance; + } + + public Type getCorrespondingType(Class clazz) { + Type type = null; + try { + type = delegate.getCorrespondingType(clazz); + } catch (IllegalArgumentException e){ + //no type was found + } + if (type == null){ + return defaultMapper.getCorrespondingType(clazz); + } + return type; + } + + + public Object getProperty(T object, Property property) { + if (object instanceof PartialDataObject){ + return defaultMapper.getProperty((PartialDataObject) object, property); + } + return delegate.getProperty(object, property); + } + + + public T newProxy(Type type, Object identity) { + T proxy = delegate.newProxy(type, identity); + if (proxy == null){ + return (T) defaultMapper.newProxy(type, identity); + } + return proxy; + } + + + public Iterator<? extends T> getObjects(T object, Property property) { + if (object instanceof PartialDataObject){ + return (Iterator<? extends T>) defaultMapper.getObjects((PartialDataObject) object, property); + } + return delegate.getObjects(object, property); + } + + + public Type getType(T object) { + if (object instanceof PartialDataObject){ + return defaultMapper.getType((PartialDataObject) object); + } + return delegate.getType(object); + } + + + public boolean isProxy(T object) { + if (object instanceof PartialDataObject){ + return defaultMapper.isProxy((PartialDataObject) object); + } + return delegate.isProxy(object); + } + + + public void setProperty(T object, Property property, Object value) { + if (object instanceof PartialDataObject){ + defaultMapper.setProperty((PartialDataObject) object, property, value); + } else { + delegate.setProperty(object, property, value); + } + } + + + public void setUnavailable(T object, Property property) { + if (object instanceof PartialDataObject){ + defaultMapper.setUnavailable((PartialDataObject) object, property); + } else { + delegate.setUnavailable(object, property); + } + } + + public Collection<T> getProperties(Collection<T> object, Property bulkProperty, SnapshotDefinition def) { + return delegate.getProperties(object, bulkProperty, def); + } + + public boolean isBulkProperty(Class clazz, Property property) { + if (PartialDataObject.class.isAssignableFrom(clazz)) { + return false; + } + return delegate.isBulkProperty(clazz, property); + } + + + +}
Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/FalsePropertyAccessor.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/FalsePropertyAccessor.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/FalsePropertyAccessor.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/FalsePropertyAccessor.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,32 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import com.agfa.hap.sdo.DataMapper; +import com.agfa.hap.sdo.Property; + +public class FalsePropertyAccessor extends AbstractPropertyAccessor { + + public Object getValue(Object instance, Property property, + DataMapper dataMapper) { + return Boolean.FALSE; + } + +} Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/FilteringPartialDataObjectMapper.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/FilteringPartialDataObjectMapper.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/FilteringPartialDataObjectMapper.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/FilteringPartialDataObjectMapper.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,49 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import com.agfa.hap.sdo.PartialDataObject; +import com.agfa.hap.sdo.Type; + +/** + * ObjectMapper that always considers certain types to be proxies + * + */ +public class FilteringPartialDataObjectMapper extends PartialDataObjectMapper { + Set<Type> typesToConsiderAsProxies; + + public FilteringPartialDataObjectMapper(Collection<Type> typesToConsiderAsProxies){ + this.typesToConsiderAsProxies = new HashSet<Type>(typesToConsiderAsProxies); + } + + @Override + public boolean isProxy(PartialDataObject partialDataObject) { + if (typesToConsiderAsProxies.contains(partialDataObject.getType())){ + return true; + } + return super.isProxy(partialDataObject); + } + + +} Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/JavaBeanMapper.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/JavaBeanMapper.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/JavaBeanMapper.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/JavaBeanMapper.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,140 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; + +import com.agfa.hap.sdo.DataMapper; +import com.agfa.hap.sdo.Property; +import com.agfa.hap.sdo.SnapshotDefinition; +import com.agfa.hap.sdo.Type; + +/** + * DataMapper that uses Java Bean conventions to access data on java classes. + * This mapper assumes that for each [EMAIL PROTECTED] Property} there are appropriately named + * accessors defined on the corresponding class. + * Each [EMAIL PROTECTED] Type} is mapped to the java class with the same name. It is also possible + * to register a class as corresponding to a type. + * <p/> + * This DataMapper ensures that opposite properties are properly filled in. As such, objects will + * not be added multiple times to a many-valued property if that property has an opposite property. + * @author AMOCZ + */ +public class JavaBeanMapper implements DataMapper<Object> { + + public JavaBeanMapper(TypeMapper typeMapper) { + this.typeMapper = typeMapper; + } + + public Iterator<?> getObjects(Object object, Property property) { + PropertyAccessor propertyAccessor = typeMapper.property(object.getClass(), property); + if (propertyAccessor == null){ + throw new RuntimeException("no property accessor for sdo property " + property); + } + return ((Collection<?>) propertyAccessor.getValue(object, property, this)).iterator(); + } + + public Object getProperty(Object object, Property property) { + PropertyAccessor propertyAccessor = typeMapper.property(object.getClass(), property); + if (propertyAccessor == null){ + throw new RuntimeException("no property accessor for sdo property " + property); + } + return propertyAccessor.getValue(object, property, this); + } + + public void setProperty(Object object, Property property, Object value) { + PropertyAccessor propertyAccessor = typeMapper.property(object.getClass(), property); + if (propertyAccessor == null){ + throw new RuntimeException("no property accessor for sdo property " + property); + } + propertyAccessor.setValue(object, property, value, this); + if (property.getOpposite() != null && value != null) { + setOpposite(object, property, value); + } + } + + protected void setOpposite(Object object, Property property, Object value) { + typeMapper.property(value.getClass(), property.getOpposite()).setValue(value, property.getOpposite(), object, this); + } + + public void setUnavailable(Object object, Property property) { + } + + public Type getType(Object object) { + return typeMapper.getCorrespondingType(object.getClass()); + } + + public Type getCorrespondingType(Class clazz) { + return typeMapper.getCorrespondingType(clazz); + } + + public TypeMapper getTypeMapper() { + return typeMapper; + } + + public Object create(Type type) { + Constructor<?> constructor = typeMapper.getConstructor(type); + if (constructor == null){ + return null; + } + try { + return constructor.newInstance((Object[]) null); + } catch (InstantiationException e) { + throw new IllegalArgumentException("Unable to create new instance of bean class corresponding to " + type.getName(), e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException("Unable to create new instance of bean class corresponding to " + type.getName(), e); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException("Unable to create new instance of bean class corresponding to " + type.getName(), e); + } + } + + public Object newProxy(Type type, Object identity) { + return null; + } + + public boolean isProxy(Object instance) { + return false; + } + + + public Collection<Object> getProperties(Collection<Object> objects, Property bulkProperty, SnapshotDefinition def) { + Iterator<Object> it = objects.iterator(); + if (!it.hasNext()) { + return Collections.emptyList(); + } + return (Collection<Object>) typeMapper.property(it.next().getClass(), bulkProperty).getValues(objects, bulkProperty, def, this); + } + + public boolean isBulkProperty(Class clazz, Property property) { + PropertyAccessor propertyAccessor = typeMapper.property(clazz, property); + if (propertyAccessor == null){ + throw new RuntimeException("no property accessor for sdo property " + property); + } + return propertyAccessor.isBulkAccessor(); + } + + + private final TypeMapper typeMapper; + +} Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/ManyValuedBeanPropertyAccessor.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/ManyValuedBeanPropertyAccessor.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/ManyValuedBeanPropertyAccessor.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/ManyValuedBeanPropertyAccessor.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,44 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import java.util.Collection; + +import com.agfa.hap.sdo.DataMapper; +import com.agfa.hap.sdo.Property; + +public class ManyValuedBeanPropertyAccessor extends BeanPropertyAccessor { + + /** + * Sets the value of this property for the specified Object. + * @throws IllegalArgumentException + */ + public void setValue(Object instance, Property property, Object newValue, DataMapper dataMapper) { + Collection<Object> coll = (Collection<Object>) super.getValue(instance, property, dataMapper); + if (property.getOpposite() == null || !coll.contains(newValue)) { + coll.add(newValue); + } + } + + public void initialize(Object instance, Collection<Object> value) { + super.setValue(instance, null, value, null); + } + +} Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/NullPropertyAccessor.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/NullPropertyAccessor.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/NullPropertyAccessor.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/NullPropertyAccessor.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,36 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import com.agfa.hap.sdo.DataMapper; +import com.agfa.hap.sdo.Property; + +/** + * [EMAIL PROTECTED] PropertyAccessor} that allows returns null. + * @author AMOCZ + */ +public class NullPropertyAccessor extends AbstractPropertyAccessor { + + public Object getValue(Object instance, Property property, + DataMapper dataMapper) { + return null; + } + +} Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PartialDataObjectMapper.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PartialDataObjectMapper.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PartialDataObjectMapper.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PartialDataObjectMapper.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,97 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import com.agfa.hap.sdo.DataMapper; +import com.agfa.hap.sdo.PartialDataFactory; +import com.agfa.hap.sdo.PartialDataObject; +import com.agfa.hap.sdo.Property; +import com.agfa.hap.sdo.SnapshotDefinition; +import com.agfa.hap.sdo.Type; + +/** + * Default implementation that only support object that are instances + * of [EMAIL PROTECTED] PartialDataObject}. + * @author AMOCZ + */ +public class PartialDataObjectMapper implements DataMapper<PartialDataObject> { + + @SuppressWarnings("unchecked") + public Iterator<PartialDataObject> getObjects(PartialDataObject object, Property property) { + return object.getList(property).iterator(); + } + + public Object getProperty(PartialDataObject object, Property property) { + return object.get(property); + } + + public Type getType(PartialDataObject object) { + return object.getType(); + } + + public Type getCorrespondingType(Class clazz) { + throw new IllegalArgumentException("No sdo type for class " + clazz.getName()); + } + + public void setProperty(PartialDataObject object, Property property, Object value) { + if (property.isMany()) { + if (property.getOpposite() != null) { + ((PartialDataObject) value).set(property.getOpposite(), object); + } else { + object.getList(property).add(value); + } + } else { + object.set(property, value); + } + } + + public void setUnavailable(PartialDataObject object, Property property) { + object.setUnavailable(property); + } + + public PartialDataObject create(Type type) { + return PartialDataFactory.INSTANCE.create(type); + } + + public PartialDataObject newProxy(Type type, Object identity) { + return PartialDataFactory.INSTANCE.createProxy(type, identity); + } + + public boolean isProxy(PartialDataObject object) { + return object.isProxy(); + } + + public Collection<PartialDataObject> getProperties(Collection<PartialDataObject> object, Property bulkProperty, SnapshotDefinition def) { + throw new NotImplementedException(); + } + + public boolean isBulkProperty(Class clazz, Property property) { + return false; + } + + + +} Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PropertyAccessor.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PropertyAccessor.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PropertyAccessor.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PropertyAccessor.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,45 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import java.util.Collection; + +import com.agfa.hap.sdo.DataMapper; +import com.agfa.hap.sdo.Property; +import com.agfa.hap.sdo.SnapshotDefinition; + +/** + * Interface that allows property values to be accessed in a generic way from any instance. + * Typically propertyaccessors will be registered in a sdo-propertyaccessors.properties file which is read by ExtendablePropertyAccessorBuilder + * + * To allow for efficient retrieval, some properties are always accessed in bulk. A typical + * example is a property for which a query needs to be made. + * + * @author AMOCZ + * + */ +public interface PropertyAccessor { + + Object getValue(Object instance, Property property, DataMapper dataMapper); + void setValue(Object instance, Property property, Object value, DataMapper dataMapper); + + boolean isBulkAccessor(); + Collection<?> getValues(Collection<?> instances, Property property, SnapshotDefinition def, DataMapper dataMapper); +} Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PropertyAccessorBuilder.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PropertyAccessorBuilder.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PropertyAccessorBuilder.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/PropertyAccessorBuilder.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,72 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import com.agfa.hap.sdo.Property; +import com.agfa.hap.sdo.Type; + +/** + * Factory class to build a map containing all [EMAIL PROTECTED] PropertyAccessor} instances for a given class. + * @author AMOCZ + */ +public abstract class PropertyAccessorBuilder { + + public PropertyAccessorBuilder() { + this(null); + } + + public PropertyAccessorBuilder(PropertyAccessorBuilder next) { + this.next = next; + } + + public PropertyAccessor[] buildMap(Class cls, Type type) { + if (!accepts(cls, type)) { + return next == null ? null : next.buildMap(cls, type); + } + PropertyAccessor[] result = new PropertyAccessor[type.getProperties().size()]; + for (Property prop : type.getProperties()) { + PropertyAccessor property = createPropertyAccessor(cls, prop); + result[prop.getIndex()] = property; + } + return result; + } + + /** + * @return If this propertyAccessorBuilder can create propertyAccessors for this class/type + * combination. + */ + protected abstract boolean accepts(Class cls, Type type); + + protected abstract PropertyAccessor createPropertyAccessor(Class cls, Property property); + + protected PropertyAccessorBuilder next; + + public PropertyAccessor createPropertyAccessorOrDelegate(Class cls, Property property){ + if (this.accepts(cls, property.getContainingType())){ + return this.createPropertyAccessor(cls, property); + } else { + if (next == null){ + return null; + } + return next.createPropertyAccessor(cls, property); + } + } + +} Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/TruePropertyAccessor.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/TruePropertyAccessor.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/TruePropertyAccessor.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/TruePropertyAccessor.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,32 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import com.agfa.hap.sdo.DataMapper; +import com.agfa.hap.sdo.Property; + +public class TruePropertyAccessor extends AbstractPropertyAccessor { + + public Object getValue(Object instance, Property property, + DataMapper dataMapper) { + return true; + } + +} Added: incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/TypeMapper.java URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/TypeMapper.java?rev=581184&view=auto ============================================================================== --- incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/TypeMapper.java (added) +++ incubator/tuscany/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/mapper/TypeMapper.java Tue Oct 2 03:25:29 2007 @@ -0,0 +1,100 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.agfa.hap.sdo.mapper; + +import java.lang.reflect.Constructor; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import com.agfa.hap.sdo.Property; +import com.agfa.hap.sdo.Type; +import com.agfa.hap.sdo.helper.TypeHelper; + +/** + * Maps classes onto sdo Type instances. + * <P/> + * This implementation only on classes that are registered + * ([EMAIL PROTECTED] [EMAIL PROTECTED] #register(Class, String, String)}). + * + * <P /> + * This class is thread safe and can be concurrently accessed by multiple threads. + * @author AMOCZ + */ +public class TypeMapper { + + public TypeMapper() { + this(new BeanPropertyAccessorBuilder()); + } + + public TypeMapper(PropertyAccessorBuilder builder) { + this.propertyAccessorBuilder = builder; + } + + /** + * Locates a property accessor + */ + public PropertyAccessor property(Class cls, Property property) { + PropertyAccessor[] properties = buildMap(cls); + PropertyAccessor propertyAccessor = properties[property.getIndex()]; + if (propertyAccessor == null) { + throw new IllegalArgumentException("Can't access property " + property.getName() + " on " + cls.getName() + "."); + } + return propertyAccessor; + } + + private PropertyAccessor[] buildMap(Class cls) { + String clsName = cls.getName(); + PropertyAccessor[] props = keyedByPropertyNameCache.get(clsName); + if (props == null) { + // we don't care too much if it is computed more than once under some race conditions + props = propertyAccessorBuilder.buildMap(cls, getCorrespondingType(cls)); + keyedByPropertyNameCache.put(clsName, props); + } + return props; + } + + public Type getCorrespondingType(Class clazz) { + String[] exc = exceptions.get(clazz); + if (exc != null) { + return TypeHelper.INSTANCE.getType(exc[0], exc[1]); + } + return null; + } + + public void register(Class<?> clazz, String uri, String typeName) { + exceptions.put(clazz, new String[] { uri, typeName }); + try { + factories.put(typeName, clazz.getConstructor((Class[]) null)); + } catch (SecurityException e) { + } catch (NoSuchMethodException e) { + } + } + + public Constructor<?> getConstructor(Type type) { + return factories.get(type.getName()); + } + + private final Map<String, Constructor<?>> factories = new ConcurrentHashMap<String, Constructor<?>>(); + private final Map<Class<?>, String[]> exceptions = new ConcurrentHashMap<Class<?>, String[]>(); + private final Map<String, PropertyAccessor[]> keyedByPropertyNameCache = + new ConcurrentHashMap<String, PropertyAccessor[]>(); + protected final PropertyAccessorBuilder propertyAccessorBuilder; + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
