001: /*
002: *
003: * JMoney - A Personal Finance Manager
004: * Copyright (c) 2004 Nigel Westbury <westbury@users.sourceforge.net>
005: *
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: *
021: */
022:
023: package net.sf.jmoney.model2;
024:
025: public class ExtensionPropertySet<E extends ExtensionObject> extends
026: PropertySet<E> {
027:
028: private ExtendablePropertySet<?> extendablePropertySet;
029:
030: /**
031: * An interface that can be used to construct implementation objects,
032: * or null if this is an abstract property set.
033: */
034: IExtensionObjectConstructors<E> constructors;
035:
036: /**
037: * Constructs an extension property set object.
038: *
039: * @param classOfObject
040: * @param constructors
041: * a required interface containing methods for constructing
042: * implementation objects
043: */
044: protected ExtensionPropertySet(Class<E> classOfObject,
045: ExtendablePropertySet<?> extendablePropertySet,
046: IExtensionObjectConstructors<E> constructors) {
047: this .isExtension = true;
048: this .classOfObject = classOfObject;
049: this .extendablePropertySet = extendablePropertySet;
050: this .constructors = constructors;
051:
052: // TODO: move outside this constructor.
053: if (extendablePropertySet == null) {
054: throw new MalformedPluginException(
055: "A non-null extendable property set must be passed.");
056: }
057: }
058:
059: @Override
060: public void initProperties(String propertySetId) {
061: super .initProperties(propertySetId);
062:
063: // Add to our map that maps ids to ExtensionPropertySet objects.
064: allExtensionPropertySetsMap.put(propertySetId, this );
065:
066: // Add to our map that maps ids to ExtensionPropertySet objects
067: // within a particular extendable object.
068: extendablePropertySet.extensionPropertySets.put(propertySetId,
069: this );
070: /*
071: // Build the list of properties that are passed to
072: // the 'new object' constructor and another list that
073: // are passed to the 're-instantiating' constructor.
074:
075: constructorProperties = new Vector<PropertyAccessor>();
076: defaultConstructorProperties = new Vector<PropertyAccessor>();
077:
078: // This property set is an extension.
079: int parameterIndex = 0;
080: for (PropertyAccessor propertyAccessor: properties) {
081: constructorProperties.add(propertyAccessor);
082: propertyAccessor.setIndexIntoConstructorParameters(parameterIndex++);
083: if (propertyAccessor.isList()) {
084: defaultConstructorProperties.add(propertyAccessor);
085: }
086: }
087: */
088: }
089:
090: public ExtendablePropertySet getExtendablePropertySet() {
091: return extendablePropertySet;
092: }
093:
094: /**
095: * This method should be used only by plug-ins that implement
096: * a datastore.
097: * @param constructorParameters an array of values to be passed to
098: * the constructor. If an extendable object is being constructed
099: * then the first three elements of this array must be the
100: * object key, the extension map, and the parent object key.
101: *
102: * @return A newly constructed object, constructed from the given
103: * parameters. This object may be an ExtendableObject or
104: * may be an ExtensionObject.
105: */
106: public E constructImplementationObject(
107: ExtendableObject extendedObject, IValues values) {
108: E extensionObject = constructors.construct(extendedObject,
109: values);
110: extensionObject.setPropertySet(this );
111: return extensionObject;
112: }
113:
114: /**
115: * This method should be used only by plug-ins that implement
116: * a datastore.
117: *
118: * @return A newly constructed object, constructed from the given
119: * parameters. This object may be an ExtendableObject or
120: * may be an ExtensionObject.
121: */
122: public E constructDefaultImplementationObject(
123: ExtendableObject extendedObject) {
124: E extensionObject = constructors.construct(extendedObject);
125: extensionObject.setPropertySet(this );
126: return extensionObject;
127: }
128:
129: @Override
130: protected E getImplementationObject(
131: ExtendableObject extendableObject) {
132: return extendableObject.getExtension(this , true);
133: }
134: }
|