db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess AnonymousPersistentFieldHelper.java AnonymousPersistentFieldForInheritance.java AnonymousPersistentField.java
Date Sat, 21 Jun 2003 11:40:51 GMT
arminw      2003/06/21 04:40:51

  Modified:    src/java/org/apache/ojb/broker/metadata/fieldaccess
                        AnonymousPersistentFieldHelper.java
                        AnonymousPersistentFieldForInheritance.java
                        AnonymousPersistentField.java
  Log:
  add licence, version id, do layout
  
  Revision  Changes    Path
  1.2       +165 -101  db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldHelper.java
  
  Index: AnonymousPersistentFieldHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AnonymousPersistentFieldHelper.java	26 Mar 2003 10:37:55 -0000	1.1
  +++ AnonymousPersistentFieldHelper.java	21 Jun 2003 11:40:51 -0000	1.2
  @@ -1,102 +1,166 @@
  -package org.apache.ojb.broker.metadata.fieldaccess;
  -
  -import java.lang.reflect.Field;
  -import java.util.Iterator;
  -import java.util.Map;
  -import java.util.Vector;
  -
  -import org.apache.ojb.broker.metadata.AnonymousFieldDescriptor;
  -import org.apache.ojb.broker.metadata.ClassDescriptor;
  -import org.apache.ojb.broker.metadata.CollectionDescriptor;
  -import org.apache.ojb.broker.metadata.DescriptorRepository;
  -import org.apache.ojb.broker.metadata.FieldDescriptor;
  -import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  -
  -public class AnonymousPersistentFieldHelper {
  -
  -	/**
  -	 * An iterative version of org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldxxx
  -	 * This implementastion is more efficient than recursive version
  -	 * If fieldname not exist null is returned
  -	 *
  -	 * @author Houar TINE
  -	 */
  -	public static Field getFieldIterative(
  -		final Class c,
  -		final String fieldname) {
  -			
  -		Field f = null;
  -		Class clazz = c;
  -		do {
  -			try {
  -				f = clazz.getDeclaredField(fieldname);
  -				break;
  -			}
  -			catch (NoSuchFieldException e) {
  -				// ignore
  -			}
  -			clazz = clazz.getSuperclass();
  -		}
  -		while (clazz != Object.class);
  -		return f;
  -	}
  -
  -	public static Vector getPkFieldNames(final ClassDescriptor cld) {
  -		FieldDescriptor[] pks = cld.getPkFields();
  -		Vector v = new Vector(pks.length);
  -		for (int i = pks.length - 1; i >= 0; i--) {
  -			v.add(pks[i].getPersistentField().getName());
  -		}
  -		return v;
  -	}
  -
  -	public static void computeInheritedPersistentFields(final DescriptorRepository repository)
{
  -		Map descriptorTable = repository.getDescriptorTable();
  -		final String OBJECT = Object.class.getName();
  -		for (Iterator iter = descriptorTable.keySet().iterator();
  -			iter.hasNext();
  -			) {
  -			String key = (String) iter.next();
  -			ClassDescriptor cld = (ClassDescriptor) descriptorTable.get(key);
  -
  -			String baseClass = cld.getBaseClass();
  -			if (null != baseClass) {
  -				Vector v = new Vector();
  -				do {
  -					ClassDescriptor tempCld =
  -						repository.getDescriptorFor(baseClass);
  -					FieldDescriptor[] fields = tempCld.getFieldDescriptions();
  -					Vector pkFields = getPkFieldNames(tempCld);
  -					for (int i = fields.length - 1; i >= 0; i--) {
  -						FieldDescriptor f = fields[i];
  -						if (!(f instanceof AnonymousFieldDescriptor)) {
  -							PersistentField pf = f.getPersistentField();
  -							if (!pkFields.contains(pf.getName())) {
  -								v.add(f.getPersistentField());
  -							}
  -						}
  -					}
  -					Vector ords = tempCld.getObjectReferenceDescriptors();
  -					for (int i = ords.size() - 1; i >= 0; i--) {
  -						ObjectReferenceDescriptor ord =
  -							(ObjectReferenceDescriptor) ords.get(i);
  -						PersistentField pf = ord.getPersistentField();
  -						if (!(pf
  -							instanceof AnonymousPersistentFieldForInheritance)) {
  -							v.add(pf);
  -						}
  -					}
  -					Vector cds = tempCld.getCollectionDescriptors();
  -					for (int i = cds.size() - 1; i >= 0; i--) {
  -						CollectionDescriptor cd =
  -							(CollectionDescriptor) cds.get(i);
  -						v.add(cd.getPersistentField());
  -					}
  -					baseClass = tempCld.getBaseClass();
  -				}
  -				while ((null != baseClass) && (baseClass != OBJECT));
  -				cld.setSuperPersistentFieldDescriptors(v);
  -			}
  -		}
  -	}
  +package org.apache.ojb.broker.metadata.fieldaccess;
  +
  +/* ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
  + *    derived from this software without prior written permission. For
  + *    written permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
  + *    prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +import org.apache.ojb.broker.metadata.AnonymousFieldDescriptor;
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.CollectionDescriptor;
  +import org.apache.ojb.broker.metadata.DescriptorRepository;
  +import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  +
  +import java.lang.reflect.Field;
  +import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Vector;
  +
  +/**
  + * Helper class for anonymous fields.
  + *
  + * @author Houar TINE
  + * @version $Id$
  + */
  +public class AnonymousPersistentFieldHelper
  +{
  +    /**
  +     * An iterative version of org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldxxx
  +     * This implementastion is more efficient than recursive version
  +     * If fieldname not exist null is returned
  +     */
  +    public static Field getFieldIterative(final Class c, final String fieldname)
  +    {
  +        Field f = null;
  +        Class clazz = c;
  +        do
  +        {
  +            try
  +            {
  +                f = clazz.getDeclaredField(fieldname);
  +                break;
  +            }
  +            catch (NoSuchFieldException e)
  +            {
  +                // ignore
  +            }
  +            clazz = clazz.getSuperclass();
  +        }
  +        while (clazz != Object.class);
  +        return f;
  +    }
  +
  +    public static Vector getPkFieldNames(final ClassDescriptor cld)
  +    {
  +        FieldDescriptor[] pks = cld.getPkFields();
  +        Vector v = new Vector(pks.length);
  +        for (int i = pks.length - 1; i >= 0; i--)
  +        {
  +            v.add(pks[i].getPersistentField().getName());
  +        }
  +        return v;
  +    }
  +
  +    public static void computeInheritedPersistentFields(final DescriptorRepository repository)
  +    {
  +        Map descriptorTable = repository.getDescriptorTable();
  +        final String OBJECT = Object.class.getName();
  +        for (Iterator iter = descriptorTable.keySet().iterator(); iter.hasNext();)
  +        {
  +            String key = (String) iter.next();
  +            ClassDescriptor cld = (ClassDescriptor) descriptorTable.get(key);
  +            String baseClass = cld.getBaseClass();
  +            if (null != baseClass)
  +            {
  +                Vector v = new Vector();
  +                do
  +                {
  +                    ClassDescriptor tempCld = repository.getDescriptorFor(baseClass);
  +                    FieldDescriptor[] fields = tempCld.getFieldDescriptions();
  +                    Vector pkFields = getPkFieldNames(tempCld);
  +                    for (int i = fields.length - 1; i >= 0; i--)
  +                    {
  +                        FieldDescriptor f = fields[i];
  +                        if (!(f instanceof AnonymousFieldDescriptor))
  +                        {
  +                            PersistentField pf = f.getPersistentField();
  +                            if (!pkFields.contains(pf.getName()))
  +                            {
  +                                v.add(f.getPersistentField());
  +                            }
  +                        }
  +                    }
  +                    Vector ords = tempCld.getObjectReferenceDescriptors();
  +                    for (int i = ords.size() - 1; i >= 0; i--)
  +                    {
  +                        ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) ords.get(i);
  +                        PersistentField pf = ord.getPersistentField();
  +                        if (!(pf instanceof AnonymousPersistentFieldForInheritance))
  +                        {
  +                            v.add(pf);
  +                        }
  +                    }
  +                    Vector cds = tempCld.getCollectionDescriptors();
  +                    for (int i = cds.size() - 1; i >= 0; i--)
  +                    {
  +                        CollectionDescriptor cd = (CollectionDescriptor) cds.get(i);
  +                        v.add(cd.getPersistentField());
  +                    }
  +                    baseClass = tempCld.getBaseClass();
  +                }
  +                while ((null != baseClass) && (baseClass != OBJECT));
  +                cld.setSuperPersistentFieldDescriptors(v);
  +            }
  +        }
  +    }
   }
  
  
  
  1.2       +129 -63   db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldForInheritance.java
  
  Index: AnonymousPersistentFieldForInheritance.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldForInheritance.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AnonymousPersistentFieldForInheritance.java	26 Mar 2003 10:37:55 -0000	1.1
  +++ AnonymousPersistentFieldForInheritance.java	21 Jun 2003 11:40:51 -0000	1.2
  @@ -1,64 +1,130 @@
  -package org.apache.ojb.broker.metadata.fieldaccess;
  -
  -import java.util.Vector;
  -
  -import org.apache.ojb.broker.metadata.ClassDescriptor;
  -import org.apache.ojb.broker.metadata.MetadataException;
  -
  -public class AnonymousPersistentFieldForInheritance
  -	extends AnonymousPersistentField {
  -	ClassDescriptor cld = null;
  -
  -	public AnonymousPersistentFieldForInheritance(ClassDescriptor cld) {
  -		super(null);
  -		this.cld = cld;
  -	}
  -
  -	private void copyObjectToObject(Object fromObject, Object toObject) {
  -		Vector persistentFields = cld.getSuperPersistentFieldDescriptors();
  -		for (int i = persistentFields.size() - 1; i >= 0; i--) {
  -			PersistentField pf = (PersistentField) persistentFields.get(i);
  -			pf.set(toObject, pf.get(fromObject));
  -		}
  -	}
  -
  -	/** 
  -	 * Field values of 'value' (base object) are copied to 'obj' (derived object)
  -	 * then obj is saved in a map
  -	 * 
  -	 * @param obj - the base object instance
  -	 * @param value - the derived object instance
  -	 * @throws MetadataException
  -	 * @author Houar TINE
  -	 */
  -	public synchronized void set(Object obj, Object value)
  -		throws MetadataException {
  -		copyObjectToObject(value, obj);
  -		fkCache.put(obj, value);
  -	}
  -
  -	/** 
  -	 * Field values of 'obj' (derived object) are copied to 'value' (base object)
  -	 * then value is returned as a referenced object.
  -	 * 
  -	 * @param obj - the base object instance
  -	 * @param value - the derived object instance
  -	 * @throws MetadataException
  -	 * @author Houar TINE
  -	 */
  -	public synchronized Object get(Object obj) throws MetadataException {
  -		Object value = fkCache.get(obj);
  -		if (null == value) {
  -			try {
  -				value = Class.forName(cld.getBaseClass()).newInstance();	
  -			}
  -			catch (Exception e) {
  -				throw new MetadataException(e);
  -			}
  -			fkCache.put(obj, value);
  -		} else {
  -			copyObjectToObject(obj, value);
  -		}		
  -		return value;
  -	}
  +package org.apache.ojb.broker.metadata.fieldaccess;
  +
  +/* ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
  + *    derived from this software without prior written permission. For
  + *    written permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
  + *    prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.MetadataException;
  +
  +import java.util.Vector;
  +
  +/**
  + * @author Houar TINE
  + * @version $Id$
  + */
  +public class AnonymousPersistentFieldForInheritance extends AnonymousPersistentField
  +{
  +    ClassDescriptor cld = null;
  +
  +    public AnonymousPersistentFieldForInheritance(ClassDescriptor cld)
  +    {
  +        super(null);
  +        this.cld = cld;
  +    }
  +
  +    private void copyObjectToObject(Object fromObject, Object toObject)
  +    {
  +        Vector persistentFields = cld.getSuperPersistentFieldDescriptors();
  +        for (int i = persistentFields.size() - 1; i >= 0; i--)
  +        {
  +            PersistentField pf = (PersistentField) persistentFields.get(i);
  +            pf.set(toObject, pf.get(fromObject));
  +        }
  +    }
  +
  +    /**
  +     * Field values of 'value' (base object) are copied to 'obj' (derived object)
  +     * then obj is saved in a map
  +     *
  +     * @param obj - the base object instance
  +     * @param value - the derived object instance
  +     * @throws MetadataException
  +     */
  +    public synchronized void set(Object obj, Object value)
  +            throws MetadataException
  +    {
  +        copyObjectToObject(value, obj);
  +        fkCache.put(obj, value);
  +    }
  +
  +    /**
  +     * Field values of 'obj' (derived object) are copied to 'value' (base object)
  +     * then value is returned as a referenced object.
  +     *
  +     * @param obj - the base object instance
  +     * @param value - the derived object instance
  +     * @throws MetadataException
  +     */
  +    public synchronized Object get(Object obj) throws MetadataException
  +    {
  +        Object value = fkCache.get(obj);
  +        if (null == value)
  +        {
  +            try
  +            {
  +                value = Class.forName(cld.getBaseClass()).newInstance();
  +            }
  +            catch (Exception e)
  +            {
  +                throw new MetadataException(e);
  +            }
  +            fkCache.put(obj, value);
  +        }
  +        else
  +        {
  +            copyObjectToObject(obj, value);
  +        }
  +        return value;
  +    }
   }
  
  
  
  1.3       +122 -55   db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentField.java
  
  Index: AnonymousPersistentField.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentField.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AnonymousPersistentField.java	10 Jun 2003 06:19:24 -0000	1.2
  +++ AnonymousPersistentField.java	21 Jun 2003 11:40:51 -0000	1.3
  @@ -1,56 +1,123 @@
  -package org.apache.ojb.broker.metadata.fieldaccess;
  -
  -import java.util.Map;
  -import java.util.WeakHashMap;
  -import org.apache.ojb.broker.metadata.MetadataException;
  -
  -/**
  - * This class handle an anonymous persistent fiels for 1-1 association, 
  - * and ojbConcreteClass
  - * @author Houar TINE
  - */
  -
  -public class AnonymousPersistentField implements PersistentField {
  -	protected transient Map fkCache = new WeakHashMap();
  -	protected String fieldname;
  -
  -	public AnonymousPersistentField(String fieldname) {
  -		this.fieldname = fieldname;
  -	}
  -
  -	public synchronized void set(Object obj, Object value)
  -		throws MetadataException {
  -		fkCache.put(obj, value);
  -	}
  -
  -	public synchronized Object get(Object anObject) throws MetadataException {
  -		return fkCache.get(anObject);
  -	}
  -	/**
  -	 * @see PersistentField#getDeclaringClass()
  -	 */
  -	public Class getDeclaringClass() {
  -		return null;
  -	}
  -
  -	/**
  -	 * @see PersistentField#getName()
  -	 */
  -	public String getName() {
  -		return fieldname;
  -	}
  -
  -	/**
  -	 * @see PersistentField#getType()
  -	 */
  -	public Class getType() {
  -		return null;
  -	}
  -
  -	/**
  -	 * @see PersistentField#usesAccessorsAndMutators()
  -	 */
  -	public boolean usesAccessorsAndMutators() {
  -		return false;
  -	}
  +package org.apache.ojb.broker.metadata.fieldaccess;
  +
  +/* ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
  + *    derived from this software without prior written permission. For
  + *    written permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
  + *    prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +import org.apache.ojb.broker.metadata.MetadataException;
  +
  +import java.util.Map;
  +import java.util.WeakHashMap;
  +
  +/**
  + * This class handle an anonymous persistent fiels for 1-1 association,
  + * and ojbConcreteClass
  + * @author Houar TINE
  + * @version $Id$
  + */
  +public class AnonymousPersistentField implements PersistentField
  +{
  +    protected transient Map fkCache = new WeakHashMap();
  +    protected String fieldname;
  +
  +    public AnonymousPersistentField(String fieldname)
  +    {
  +        this.fieldname = fieldname;
  +    }
  +
  +    public synchronized void set(Object obj, Object value)
  +            throws MetadataException
  +    {
  +        fkCache.put(obj, value);
  +    }
  +
  +    public synchronized Object get(Object anObject) throws MetadataException
  +    {
  +        return fkCache.get(anObject);
  +    }
  +
  +    /**
  +     * Always returns <tt>null</tt>.
  +     * @see PersistentField#getDeclaringClass()
  +     */
  +    public Class getDeclaringClass()
  +    {
  +        return null;
  +    }
  +
  +    /**
  +     * @see PersistentField#getName()
  +     */
  +    public String getName()
  +    {
  +        return fieldname;
  +    }
  +
  +    /**
  +     * Always returns <tt>null</tt>.
  +     * @see PersistentField#getType()
  +     */
  +    public Class getType()
  +    {
  +        return null;
  +    }
  +
  +    /**
  +     * Returns <tt>false</tt>.
  +     * @see PersistentField#usesAccessorsAndMutators()
  +     */
  +    public boolean usesAccessorsAndMutators()
  +    {
  +        return false;
  +    }
   }
  
  
  

Mime
View raw message