KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > repository > DjObject


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  * Redistribution and use in source and binary forms, with or without
4  * modification, is permitted provided that the following conditions are met: -
5  * Redistributions of source code must retain the above copyright notice, this
6  * list of conditions and the following disclaimer. - Redistributions in binary
7  * form must reproduce the above copyright notice, this list of conditions and
8  * the following disclaimer in the documentation and/or other materials
9  * provided with the distribution. - All advertising materials mentioning
10  * features or use of this software must display the following acknowledgment:
11  * "This product includes Djeneric." - Products derived from this software may
12  * not be called "Djeneric" nor may "Djeneric" appear in their names without
13  * prior written permission of Genimen BV. - Redistributions of any form
14  * whatsoever must retain the following acknowledgment: "This product includes
15  * Djeneric." THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND
16  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
17  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV,
19  * DJENERIC.ORG, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */

27 package com.genimen.djeneric.repository;
28
29 import java.io.UnsupportedEncodingException JavaDoc;
30 import java.math.BigDecimal JavaDoc;
31 import java.text.ParseException JavaDoc;
32 import java.text.SimpleDateFormat JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Arrays JavaDoc;
35 import java.util.Date JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.StringTokenizer JavaDoc;
39
40 import com.genimen.djeneric.language.Messages;
41 import com.genimen.djeneric.repository.exceptions.CanNotDeleteException;
42 import com.genimen.djeneric.repository.exceptions.DjenericException;
43 import com.genimen.djeneric.repository.exceptions.DomainViolationException;
44 import com.genimen.djeneric.repository.exceptions.ObjectDeletedException;
45 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException;
46 import com.genimen.djeneric.repository.exceptions.PropertyFormatException;
47 import com.genimen.djeneric.repository.exceptions.PropertyRequiredException;
48 import com.genimen.djeneric.repository.exceptions.RestrictionFailedException;
49 import com.genimen.djeneric.util.DjLogger;
50
51 /**
52  * Description of the Class
53  *
54  * @author Wido Riezebos
55  * @created November 5, 2001
56  */

57 public abstract class DjObject implements DjValueObject
58 {
59   /////////////////////////////////////////////////////////////////////
60
/**
61    * Performs the actual update in the persistent store
62    *
63    * @exception DjenericException
64    * Description of the Exception
65    */

66   protected abstract void update() throws DjenericException;
67
68   /**
69    * Performs the actual insert in the persistent store
70    *
71    * @exception DjenericException
72    * Description of the Exception
73    */

74   protected abstract void insert() throws DjenericException;
75
76   /**
77    * Performs the actual delete in the persistent store
78    *
79    * @exception DjenericException
80    * Description of the Exception
81    */

82   protected abstract void delete() throws DjenericException;
83
84   /**
85    * Performs the actual reload (requery) from the persistent store
86    *
87    * @exception DjenericException
88    * Description of the Exception
89    */

90   public abstract void reload() throws DjenericException;
91
92   /////////////////////////////////////////////////////////////////////
93

94   /**
95    * Property of type String
96    */

97   public final static int STRING_TYPE = DjDomain.STRING_TYPE;
98   /**
99    * Property of type String Integer
100    */

101   public final static int INT_TYPE = DjDomain.INT_TYPE;
102   /**
103    * Property of type Long
104    */

105   public final static int LONG_TYPE = DjDomain.LONG_TYPE;
106   /**
107    * Property of type Date
108    */

109   public final static int DATE_TYPE = DjDomain.DATE_TYPE;
110   /**
111    * Property of type BigDecimal
112    */

113   public final static int BIGDECIMAL_TYPE = DjDomain.BIGDECIMAL_TYPE;
114
115   private DjExtent _extent;
116   private boolean _isTemporary = false;
117   private boolean _isPersisted = false;
118   private boolean _isBeingLoaded = false;
119   private boolean _isMarkedForDelete = false;
120   private boolean _isModified = false;
121   private boolean _ignoreModifications = false;
122   private String JavaDoc _descriptorExpression = null;
123   private boolean _transient = false;
124   private boolean _alreadyHitDuringCurrentTransaction = false;
125   static SimpleDateFormat JavaDoc sf = new SimpleDateFormat JavaDoc(Messages
126                                                                   .getString("global.DateFormatMask"));
127   private boolean _isDetail = false;
128   private boolean _isDetailOfNewMaster;
129
130   private DjAssociation[] _detailAssociations = null;
131   private DjAssociation[] _masterAssociations = null;
132   private Object JavaDoc[] _propertyValues;
133   private Object JavaDoc[] _originalPropertyValues;
134
135   private DjSession _session;
136
137   /**
138    * Constructor for the DjObject object
139    *
140    * @param session
141    * Description of the Parameter
142    * @param extent
143    * Description of the Parameter
144    * @exception DjenericException
145    * Description of the Exception
146    */

147   protected DjObject(DjSession session, DjExtent extent) throws DjenericException
148   {
149     _propertyValues = new Object JavaDoc[extent.getPropertyCount()];
150     _originalPropertyValues = new Object JavaDoc[extent.getPropertyCount()];
151
152     _extent = extent;
153     _session = session;
154     setDescriptorExpression(extent.getDescriptorExpression());
155     initializeDefaultValues();
156   }
157
158   /**
159    * Returns a shallow copy of the object
160    *
161    * @return the copy
162    * @throws DjenericException
163    */

164   public DjObject shallowCopy() throws DjenericException
165   {
166     DjObject obj = getSession().createObject(getExtent());
167
168     DjProperty id = getExtent().getIdProperty();
169     for (int i = 0; i < getPropertyCount(); i++)
170     {
171       if (getProperty(i) == id) continue;
172       obj.set(i, get(i));
173     }
174
175     return obj;
176   }
177
178   protected void initializeDefaultValues() throws PropertyFormatException, DjenericException
179   {
180     try
181     {
182       setIgnoreModifications(true);
183       DjProperty[] properties = getExtent().getProperties();
184       for (int i = 0; i < properties.length; i++)
185       {
186         if (properties[i].getDefaultValue() != null)
187         {
188           setString(i, properties[i].getDefaultValue());
189         }
190       }
191     }
192     finally
193     { // The following is vital; the modified flag is not reset the object
194
// will never enter the sessions modified list
195
_isModified = false;
196       setIgnoreModifications(false);
197     }
198   }
199
200   /**
201    * Constructor for the DjObject object
202    *
203    * @param session
204    * Description of the Parameter
205    * @param objectType
206    * Description of the Parameter
207    * @exception DjenericException
208    * Description of the Exception
209    */

210   protected DjObject(DjSession session, String JavaDoc objectType) throws DjenericException
211   {
212     this(session, session.getPersistenceManager().getExtentByObjectType(objectType));
213   }
214
215   /**
216    * Sets the persisted attribute of the DjObject object
217    *
218    * @param b
219    * The new persisted value
220    */

221   protected void setPersisted(boolean b)
222   {
223     _isPersisted = b;
224   }
225
226   /**
227    * Sets the hitDuringCurrentTransaction of the DjObject object
228    *
229    * @param b
230    * The new hitDuringCurrentTransaction value
231    */

232   void setHitDuringCurrentTransaction(boolean b)
233   {
234     _alreadyHitDuringCurrentTransaction = b;
235   }
236
237   /**
238    * Returns the hitDuringCurrentTransaction of the DjObject object
239    *
240    * @return The hitDuringCurrentTransaction value
241    */

242   boolean isHitDuringCurrentTransaction()
243   {
244     return _alreadyHitDuringCurrentTransaction;
245   }
246
247   /**
248    * Description of the Method
249    *
250    * @param msg
251    * Description of the Parameter
252    */

253   protected void trace(String JavaDoc msg)
254   {
255     _session.trace(msg);
256   }
257
258   /**
259    * Description of the Method
260    *
261    * @param level
262    * Description of the Parameter
263    * @return Description of the Return Value
264    */

265   public boolean shouldTrace(int level)
266   {
267     return _session.shouldTrace(level);
268   }
269
270   /**
271    * Sets the beingLoaded of the DjObject object
272    *
273    * @param b
274    * The new beingLoaded value
275    */

276   protected void setBeingLoaded(boolean b)
277   {
278     _isBeingLoaded = b;
279   }
280
281   /**
282    * Sets the modified attribute of the DjObject object
283    *
284    * @param b
285    * The new modified value
286    */

287   protected void setModified(boolean b) throws DjenericException
288   {
289     if (b != _isModified)
290     {
291       _isModified = b;
292
293       // Notify the session's caching and modification list
294
if (!isTransient() && !_ignoreModifications && !_isBeingLoaded) getSession().notifyModified(this, _isModified);
295     }
296   }
297
298   public void setTransient(boolean b) throws DjenericException
299   {
300     boolean wastransient = _transient;
301
302     // It is important to set transient to the actual value before we try to
303
// cache the object
304
_transient = b;
305
306     // Switch from transient to persistent again?
307
if (wastransient && !b)
308     {
309       getSession().notifyModified(this, isModified());
310       // And reset the object ID if it was previously set to
311
// TRANSIENT_OBJECT_ID
312
if (getLong(getIdPropertyName()) < 0) setNull(getIdPropertyName());
313     }
314     else if (!_isTemporary && b) getSession().cacheObject(this);
315   }
316
317   /**
318    * Returns the transient of the DjObject object
319    *
320    * @return The transient value
321    */

322   public boolean isTransient()
323   {
324     return _transient;
325   }
326
327   // When set to true the session will not be notified when setModified() is
328
// called.
329
/**
330    * Sets the ignoreModifications of the DjObject object
331    *
332    * @param b
333    * The new ignoreModifications value
334    */

335   protected void setIgnoreModifications(boolean b)
336   {
337     _ignoreModifications = b;
338   }
339
340   /**
341    * Returns the markedForDelete of the DjObject object
342    *
343    * @return The markedForDelete value
344    */

345   public boolean isMarkedForDelete()
346   {
347     return _isMarkedForDelete;
348   }
349
350   /**
351    * Returns the instanceOf of the DjObject object
352    *
353    * @param typeName
354    * Description of the Parameter
355    * @return The instanceOf value
356    * @exception ObjectNotDefinedException
357    * Description of the Exception
358    */

359   public boolean isInstanceOf(String JavaDoc typeName) throws ObjectNotDefinedException
360   {
361     return isInstanceOf(getSession().getPersistenceManager().getExtentByObjectType(typeName));
362   }
363
364   /**
365    * Returns the instanceOf of the DjObject object
366    *
367    * @param ext
368    * Description of the Parameter
369    * @return The instanceOf value
370    */

371   public boolean isInstanceOf(DjExtent ext)
372   {
373     DjExtent sup = getExtent();
374     while (sup != null)
375     {
376       if (sup == ext) return true;
377       sup = sup.getSuper();
378     }
379     return false;
380   }
381
382   public boolean equals(Object JavaDoc o)
383   {
384     if (o == null) return false;
385     if (!(o instanceof DjObject)) return false;
386
387     DjObject obj = (DjObject) o;
388     if (obj.getExtent() != getExtent()) return false;
389
390     for (int i = 0; i < _propertyValues.length; i++)
391     {
392       if (obj._propertyValues[i] == null && _propertyValues[i] != null) return false;
393       if (obj._propertyValues[i] != null && _propertyValues[i] == null) return false;
394       if (obj._propertyValues[i] != null && _propertyValues[i] != null
395           && !obj._propertyValues[i].equals(_propertyValues[i])) return false;
396     }
397     return true;
398   }
399
400   public int hashCode()
401   {
402     int result = 0;
403
404     String JavaDoc[] names = getPropertyNames();
405     for (int i = 0; i < names.length; i++)
406     {
407       Object JavaDoc o = _propertyValues[i];
408       if (o != null) result += o.hashCode();
409     }
410     return result;
411   }
412
413   /**
414    * Gets the extent attribute of the DjObject object
415    *
416    * @return The extent value
417    */

418   public DjExtent getExtent()
419   {
420     return _extent;
421   }
422
423   /**
424    * Gets the originalPropertyValues attribute of the DjObject object
425    *
426    * @return The originalPropertyValues value
427    */

428   protected Object JavaDoc[] getOriginalPropertyValues()
429   {
430     return _originalPropertyValues;
431   }
432
433   /**
434    * Gets the propertyValues attribute of the DjObject object
435    *
436    * @return The propertyValues value
437    */

438   protected Object JavaDoc[] getPropertyValues()
439   {
440     return _propertyValues;
441   }
442
443   /**
444    * Gets the session attribute of the DjObject object
445    *
446    * @return The session value
447    */

448   public DjSession getSession()
449   {
450     return _session;
451   }
452
453   /**
454    * Description of the Method
455    */

456   protected void updateOriginalPropertyValues()
457   {
458     _originalPropertyValues = (Object JavaDoc[]) _propertyValues.clone();
459     // a shallow copy is sufficient here since peoprties are replaced and not
460
// manipulated
461
}
462
463   /**
464    * Sets the isDetail attribute of the DjObject object
465    *
466    * @param b
467    * The new isDetail value
468    */

469   protected void setIsDetail(boolean b)
470   {
471     _isDetail = b;
472   }
473
474   /**
475    * Gets the detail attribute of the DjObject object
476    *
477    * @return The detail value
478    */

479   protected boolean isDetail()
480   {
481     return _isDetail;
482   }
483
484   String JavaDoc _idCol = null;
485
486   public boolean isPropertyChanged(String JavaDoc propertyName) throws ObjectNotDefinedException
487   {
488     return isPropertyChanged(getPropertyIndex(propertyName));
489   }
490
491   public boolean isPropertyChanged(int i)
492   {
493     if (_propertyValues[i] == null && _originalPropertyValues[i] != null) return true;
494     if (_propertyValues[i] != null && _originalPropertyValues[i] == null) return true;
495     return !_propertyValues[i].equals(_originalPropertyValues[i]);
496   }
497
498   /**
499    * Gets the idPropertyName attribute of the DjObject object
500    *
501    * @return The idPropertyName value
502    * @exception ObjectNotDefinedException
503    * Description of the Exception
504    */

505   public String JavaDoc getIdPropertyName() throws ObjectNotDefinedException
506   {
507     if (_idCol == null)
508     {
509       _idCol = _extent.getIdProperty().getName();
510     }
511     return _idCol;
512   }
513
514   /**
515    * Gets the objectId attribute of the DjObject object
516    *
517    * @return The objectId value
518    * @exception DjenericException
519    * Description of the Exception
520    */

521   public long getObjectId() throws DjenericException
522   {
523     determineObjectIdIfNeeded();
524     return getLong(getIdPropertyName());
525   }
526
527   /**
528    * Gets the descriptorExpression attribute of the DjObject object
529    *
530    * @return The descriptorExpression value
531    */

532   public String JavaDoc getDescriptorExpression()
533   {
534     return _descriptorExpression;
535   }
536
537   /**
538    * Sets the descriptorExpression attribute of the DjObject object
539    *
540    * @param descriptorExpression
541    * The new descriptorExpression value
542    */

543   public void setDescriptorExpression(String JavaDoc descriptorExpression)
544   {
545     _descriptorExpression = descriptorExpression;
546   }
547
548   /**
549    * Gets the descriptor attribute of the DjObject object
550    *
551    * @return The descriptor value
552    */

553   public String JavaDoc getDescriptor()
554   {
555     String JavaDoc result = evaluateDescriptorExpression(_descriptorExpression);
556     if (result == null) return "";
557     return result;
558   }
559
560   /**
561    * Gets the descriptor attribute of the DjObject object
562    *
563    * @param origin
564    * Description of the Parameter
565    * @return The descriptor value
566    */

567   private String JavaDoc getDescriptorAvoidingRecursion(DjObject origin)
568   {
569     if (origin == this) return "Recursion Detected";
570     return getDescriptor();
571   }
572
573   /**
574    * Returns the descriptor of the DjObject object
575    *
576    * @param expr
577    * Description of the Parameter
578    * @return The descriptor value
579    */

580   public String JavaDoc getDescriptor(String JavaDoc expr)
581   {
582     if (expr == null || expr.trim().length() == 0) expr = _descriptorExpression;
583
584     String JavaDoc result = evaluateDescriptorExpression(expr);
585     if (result == null) return "";
586     return result;
587   }
588
589   private String JavaDoc evaluateDescriptorExpression(String JavaDoc expr)
590   {
591     String JavaDoc orgExpr = expr;
592     try
593     {
594       if (expr == null || expr.trim().length() == 0)
595       {
596         return getObjectNameSingular() + " " + getObjectId();
597       }
598
599       StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(expr, "+");
600       StringBuffer JavaDoc result = new StringBuffer JavaDoc();
601
602       while (tok.hasMoreElements())
603       {
604         String JavaDoc subExpr = tok.nextToken();
605         String JavaDoc single = evaluateSingleDescriptorField(subExpr);
606         if (single != null)
607         {
608           result.append(single);
609         }
610       }
611
612       if (result.length() == 0) result.append(Messages.getString("DjObject.NewObjectDescriptor", getExtent()
613           .getNameSingular()));
614       return result.toString();
615     }
616     catch (ObjectDeletedException ode)
617     {
618       return Messages.getString("global.Deleted");
619     }
620     catch (Exception JavaDoc x)
621     {
622       DjLogger.log(x);
623       return Messages.getString("DjObject.DescrEvalError", orgExpr);
624     }
625   }
626
627   private String JavaDoc evaluateSingleDescriptorField(String JavaDoc expr) throws DjenericException
628   {
629     expr = expr.trim();
630
631     // First check for string constants:
632
if (expr.length() == 0) return "";
633     if (expr.charAt(0) == '"')
634     {
635       if (expr.endsWith("\"")) return expr.substring(1, expr.length() - 1);
636       return expr.substring(1);
637     }
638
639     DjProperty prop = getProperty(expr);
640     DjPropertyType type = prop.getType();
641
642     if (type instanceof DjDomain)
643     {
644       DjDomain dom = (DjDomain) type;
645       if (dom.hasValidValues())
646       {
647         return dom.translateCode(getString(expr));
648       }
649     }
650     if (type instanceof DjExtent)
651     {
652       DjObject getFrom = (DjObject) get(expr);
653       if (getFrom == null) return null;
654       else return getFrom.getDescriptorAvoidingRecursion(this);
655     }
656     return getString(expr);
657   }
658
659   public String JavaDoc evaluateStringExpression(String JavaDoc expr)
660   {
661     String JavaDoc orgExpr = expr;
662     try
663     {
664       if (expr == null || expr.trim().length() == 0)
665       {
666         return null;
667       }
668
669       StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(expr, "+");
670       StringBuffer JavaDoc result = new StringBuffer JavaDoc();
671
672       while (tok.hasMoreElements())
673       {
674         String JavaDoc subExpr = tok.nextToken();
675         String JavaDoc single = evaluateSingleDescriptorField(subExpr);
676         if (single == null)
677         {
678           return null;
679         }
680         result.append(single);
681       }
682       if (result.length() == 0) return null;
683
684       return result.toString();
685     }
686     catch (Exception JavaDoc x)
687     {
688       DjLogger.log(x);
689       return Messages.getString("DjObject.DescrEvalError", orgExpr);
690     }
691   }
692
693   public Object JavaDoc evaluateObjectExpression(String JavaDoc expr) throws DjenericException
694   {
695     if (expr == null || expr.trim().length() == 0)
696     {
697       return null;
698     }
699
700     String JavaDoc orgExpr = expr;
701     DjObject getFrom = this;
702
703     expr = expr.trim();
704
705     if (expr.length() == 0) return null;
706
707     int idx = expr.indexOf(".");
708     while (idx != -1)
709     {
710       String JavaDoc sub = expr.substring(0, idx);
711       Object JavaDoc o = get(sub);
712       if (o == null) return null;
713       // null value of property
714
if (!(o instanceof DjObject))
715       {
716         System.err.println(Messages.getString("DjObject.DescrEvalErrorFor", orgExpr, getExtent().getName()));
717         System.err.println(Messages.getString("DjObject.CannotTraverse", sub));
718         throw new DjenericException(Messages.getString("DjObject.NotDjObject", sub));
719       }
720       getFrom = (DjObject) o;
721       expr = expr.substring(idx + 1);
722       idx = expr.indexOf(".");
723     }
724     return getFrom;
725   }
726
727   /**
728    * Gets the objectType complete with package prefix
729    *
730    * @return Returns the name of the extent
731    */

732   public String JavaDoc getQualifiedObjectType()
733   {
734     return _extent.getQualifiedObjectType();
735   }
736
737   /**
738    * Gets the objectNameSingular attribute of the DjObject object
739    *
740    * @return The objectNameSingular value
741    */

742   public String JavaDoc getObjectNameSingular()
743   {
744     return _extent.getNameSingular();
745   }
746
747   /**
748    * Gets the objectNamePlural attribute of the DjObject object
749    *
750    * @return The objectNamePlural value
751    */

752   public String JavaDoc getObjectNamePlural()
753   {
754     return _extent.getNamePlural();
755   }
756
757   /**
758    * Gets the detailAssociations attribute of the DjObject object
759    *
760    * @return The detailAssociations value
761    */

762   public DjAssociation[] getDetailAssociations()
763   {
764     if (_detailAssociations == null)
765     {
766       ArrayList JavaDoc directAssocs = new ArrayList JavaDoc();
767
768       ArrayList JavaDoc result = new ArrayList JavaDoc();
769
770       DjRelation[] rels = _extent.getDetailRelations();
771       for (int i = 0; i < rels.length; i++)
772       {
773         DjExtent detailExtent = rels[i].getDetailExtent();
774         ArrayList JavaDoc allDetails = new ArrayList JavaDoc();
775         allDetails.add(detailExtent);
776         directAssocs.add(detailExtent);
777
778         DjExtent[] allSpecs = detailExtent.getAllSpecializations();
779         for (int d = 0; d < allSpecs.length; d++)
780           allDetails.add(allSpecs[d]);
781
782         Iterator JavaDoc it = allDetails.iterator();
783         while (it.hasNext())
784         {
785           DjExtent currentDetail = (DjExtent) it.next();
786           DjAssociation a = _session.getPersistenceManager().createAssociation(_session, this, rels[i], currentDetail);
787           if (!directAssocs.contains(currentDetail)) a.setSpecializationOfActualDetailExtent(true);
788           result.add(a);
789         }
790       }
791       _detailAssociations = (DjAssociation[]) result.toArray(new DjAssociation[0]);
792     }
793
794     return _detailAssociations;
795   }
796
797   /**
798    * Gets the detailAssociationByName attribute of the DjObject object
799    *
800    * @param assocName
801    * Description of the Parameter
802    * @return The detailAssociationByName value
803    * @exception ObjectNotDefinedException
804    * Description of the Exception
805    */

806   public DjAssociation getDetailAssociationByName(String JavaDoc assocName, DjExtent specializedDetailExtent)
807       throws ObjectNotDefinedException
808   {
809     if (_detailAssociations == null)
810     {
811       getDetailAssociations();
812     }
813     for (int i = 0; i < _detailAssociations.length; i++)
814     {
815       if (_detailAssociations[i].getName().equals(assocName)
816           && _detailAssociations[i].getDetailExtent() == specializedDetailExtent)
817       {
818         return _detailAssociations[i];
819       }
820     }
821     throw new ObjectNotDefinedException(Messages.getString("DjObject.AssociationNotDefined", assocName));
822   }
823
824   /**
825    * Returns the named detail association (ignoring associations to specializations of the detail)
826    *
827    * @param assocName
828    * Description of the Parameter
829    * @return The detailAssociationByName value
830    * @exception ObjectNotDefinedException
831    * Description of the Exception
832    */

833   public DjAssociation getDetailAssociationByName(String JavaDoc assocName) throws ObjectNotDefinedException
834   {
835     if (_detailAssociations == null)
836     {
837       getDetailAssociations();
838     }
839     for (int i = 0; i < _detailAssociations.length; i++)
840     {
841       if (_detailAssociations[i].getName().equals(assocName)
842           && !_detailAssociations[i].isSpecializationOfActualDetailExtent())
843       {
844         return _detailAssociations[i];
845       }
846     }
847     throw new ObjectNotDefinedException(Messages.getString("DjObject.AssociationNotDefined", assocName));
848   }
849
850   /**
851    * Gets the masterAssociations attribute of the DjObject object
852    *
853    * @return The masterAssociations value
854    */

855   public DjAssociation[] getMasterAssociations()
856   {
857     if (_masterAssociations == null)
858     {
859       DjRelation[] rels = _extent.getMasterRelations();
860       _masterAssociations = new DjAssociation[rels.length];
861       for (int i = 0; i < rels.length; i++)
862       {
863         DjAssociation ass = _session.getPersistenceManager().createAssociation(_session, this, rels[i],
864                                                                                rels[i].getDetailExtent());
865         _masterAssociations[i] = ass;
866       }
867     }
868     return _masterAssociations;
869   }
870
871   /**
872    * Gets the masterAssociationByName attribute of the DjObject object
873    *
874    * @param assocName
875    * Description of the Parameter
876    * @return The masterAssociationByName value
877    * @exception ObjectNotDefinedException
878    * Description of the Exception
879    */

880   public DjAssociation getMasterAssociationByName(String JavaDoc assocName) throws ObjectNotDefinedException
881   {
882     if (_masterAssociations == null)
883     {
884       getMasterAssociations();
885     }
886     for (int i = 0; i < _masterAssociations.length; i++)
887     {
888       if (_masterAssociations[i].getName().equals(assocName))
889       {
890         return _masterAssociations[i];
891       }
892     }
893     throw new ObjectNotDefinedException(Messages.getString("DjObject.AssociationNotDefined", assocName));
894   }
895
896   /**
897    * Makes sure that there are no objects stored in an association that do not belong there (anymore). This occurs if
898    * properties that are part of a relation are updated. The synch causes the object to be moved from one list to the
899    * other
900    */

901   protected void synchronizeAssociations() throws DjenericException
902   {
903     if (!isTransient() && !isMarkedForDelete())
904     {
905       DjAssociation ass[] = getDetailAssociations();
906       for (int a = 0; a < ass.length; a++)
907       {
908         ass[a].synchronizeWithSession();
909       }
910     }
911   }
912
913   /**
914    * Gets the masterAssociationByPropertyName attribute of the DjObject object
915    *
916    * @param propIdx
917    * Description of the Parameter
918    * @return The masterAssociationByPropertyName value
919    */

920   public DjAssociation getMasterAssociationByPropertyName(int propIdx)
921   {
922     return getMasterAssociationByPropertyName(getPropertyName(propIdx));
923   }
924
925   /**
926    * Gets the masterAssociationByPropertyName attribute of the DjObject object
927    *
928    * @param propertyName
929    * Description of the Parameter
930    * @return The masterAssociationByPropertyName value
931    */

932   public DjAssociation getMasterAssociationByPropertyName(String JavaDoc propertyName)
933   {
934     DjAssociation[] assocs = getMasterAssociations();
935     for (int i = 0; i < assocs.length; i++)
936     {
937       if (assocs[i].getRelation().getDetailProperty().getName().equals(propertyName))
938       {
939         return assocs[i];
940       }
941     }
942     return null;
943   }
944
945   /**
946    * Description of the Method
947    *
948    * @exception PropertyRequiredException
949    * Description of the Exception
950    * @exception ObjectNotDefinedException
951    * Description of the Exception
952    */

953   public void checkRequiredProperties() throws PropertyRequiredException
954   {
955     ArrayList JavaDoc missingProperties = null;
956
957     for (int i = 0; i < getPropertyCount(); i++)
958     {
959       if (_extent.getProperty(i).isRequired() && isNull(i))
960       {
961         if (missingProperties == null)
962         {
963           missingProperties = new ArrayList JavaDoc();
964         }
965         missingProperties.add(getProperty(i).getName());
966       }
967     }
968     if (missingProperties != null)
969     {
970       throw new PropertyRequiredException(Messages.getString("global.RequiredPropNull"), this, missingProperties);
971     }
972   }
973
974   ///////////////////////////////////////////////////////////////////////////////////////////
975
//////////////////////// METADATA
976

977   public boolean hasProperty(String JavaDoc propertyName)
978   {
979     return _extent.hasProperty(propertyName);
980   }
981
982   private DjObject resolveInstance(String JavaDoc instPath, boolean implicitCreate) throws DjenericException
983   {
984     if (instPath == null) return this;
985
986     int idx = instPath.indexOf(".");
987
988     String JavaDoc basePropName = instPath;
989     String JavaDoc restPath = null;
990     if (idx != -1)
991     {
992       basePropName = instPath.substring(0, idx);
993       restPath = instPath.substring(idx + 1);
994     }
995
996     if (_extent.hasProperty(basePropName))
997     {
998       DjProperty prop = _extent.getProperty(basePropName);
999       if (!(prop.getType() instanceof DjExtent)) throw new ObjectNotDefinedException(Messages
1000          .getString("DjObject.PropertyInPathNotObject", basePropName));
1001
1002      DjObject next = (DjObject) get(basePropName);
1003      if (next == null)
1004      {
1005        if (implicitCreate)
1006        {
1007          next = getSession().createObject((DjExtent) prop.getType());
1008          set(basePropName, next);
1009        }
1010        else return null;
1011      }
1012      return next.resolveInstance(restPath, implicitCreate);
1013    }
1014
1015    DjAssociation rel = getDetailAssociationByName(basePropName);
1016    if (!rel.isOneToOne()) throw new ObjectNotDefinedException(Messages.getString("DjObject.RelationNot11", rel
1017        .getName(), instPath));
1018
1019    if (rel.getObjects().size() == 0)
1020    {
1021      if (implicitCreate) return rel.createNew().resolveInstance(restPath, implicitCreate);
1022      else return null;
1023    }
1024
1025    return rel.getObjects().getDjenericObjectAt(0).resolveInstance(restPath, implicitCreate);
1026  }
1027
1028  /**
1029   * Gets the maxLength attribute of the DjObject object
1030   *
1031   * @param propertyName
1032   * Description of the Parameter
1033   * @return The maxLength value
1034   * @exception DjenericException
1035   * Description of the Exception
1036   */

1037  public int getMaxLength(String JavaDoc propertyName) throws DjenericException
1038  {
1039    int idx = propertyName.lastIndexOf(".");
1040    if (idx != -1)
1041    {
1042      String JavaDoc propName = propertyName.substring(idx + 1);
1043      String JavaDoc instPath = propertyName.substring(0, idx);
1044
1045      DjObject dest = resolveInstance(instPath, false);
1046      if (dest == null) throw new DjenericException(Messages.getString("ObjectPath.IdentifierNull", propertyName));
1047      return dest.getMaxLength(propName);
1048    }
1049    else return getMaxLength(_extent.getPropertyIndex(propertyName));
1050  }
1051
1052  /**
1053   * Gets the maxLength attribute of the DjObject object
1054   *
1055   * @param propIdx
1056   * Description of the Parameter
1057   * @return The maxLength value
1058   */

1059  public int getMaxLength(int propIdx)
1060  {
1061    return _extent.getProperty(propIdx).getLength();
1062  }
1063
1064  /**
1065   * Gets the decimals attribute of the DjObject object
1066   *
1067   * @param propertyName
1068   * Description of the Parameter
1069   * @return The decimals value
1070   * @exception DjenericException
1071   * Description of the Exception
1072   */

1073  public int getDecimals(String JavaDoc propertyName) throws DjenericException
1074  {
1075    int idx = propertyName.lastIndexOf(".");
1076    if (idx != -1)
1077    {
1078      String JavaDoc propName = propertyName.substring(idx + 1);
1079      String JavaDoc instPath = propertyName.substring(0, idx);
1080      DjObject dest = resolveInstance(instPath, false);
1081      if (dest == null) throw new DjenericException(Messages.getString("ObjectPath.IdentifierNull", propertyName));
1082      return dest.getMaxLength(propName);
1083    }
1084    else return getDecimals(_extent.getPropertyIndex(propertyName));
1085  }
1086
1087  /**
1088   * Gets the decimals attribute of the DjObject object
1089   *
1090   * @param propIdx
1091   * Description of the Parameter
1092   * @return The decimals value
1093   */

1094  public int getDecimals(int propIdx)
1095  {
1096    return _extent.getProperty(propIdx).getDecimals();
1097  }
1098
1099  /**
1100   * Gets the type attribute of the DjObject object
1101   *
1102   * @param propertyName
1103   * Description of the Parameter
1104   * @return The type value
1105   * @exception DjenericException
1106   * Description of the Exception
1107   */

1108  public int getTypeCode(String JavaDoc propertyName) throws DjenericException
1109  {
1110    return _extent.getProperty(propertyName).getTypeCode();
1111  }
1112
1113  /**
1114   * Gets the type attribute of the DjObject object
1115   *
1116   * @param propIdx
1117   * Description of the Parameter
1118   * @return The type value
1119   */

1120  public int getTypeCode(int propIdx)
1121  {
1122    return _extent.getProperty(propIdx).getTypeCode();
1123  }
1124
1125  /**
1126   * Returns the type of the DjObject object
1127   *
1128   * @param propertyName
1129   * Description of the Parameter
1130   * @return The type value
1131   * @exception DjenericException
1132   * Description of the Exception
1133   */

1134  public DjPropertyType getType(String JavaDoc propertyName) throws DjenericException
1135  {
1136    return _extent.getProperty(propertyName).getType();
1137  }
1138
1139  /**
1140   * Returns the type of the DjObject object
1141   *
1142   * @param propIdx
1143   * Description of the Parameter
1144   * @return The type value
1145   * @exception DjenericException
1146   * Description of the Exception
1147   */

1148  public DjPropertyType getType(int propIdx)
1149  {
1150    return _extent.getProperty(propIdx).getType();
1151  }
1152
1153  /**
1154   * Gets the typeName attribute of the DjObject object
1155   *
1156   * @param propertyName
1157   * Description of the Parameter
1158   * @return The typeName value
1159   * @exception DjenericException
1160   * Description of the Exception
1161   */

1162  public String JavaDoc getTypeName(String JavaDoc propertyName) throws DjenericException
1163  {
1164    return _extent.getProperty(propertyName).getTypeName();
1165  }
1166
1167  /**
1168   * Gets the typeName attribute of the DjObject object
1169   *
1170   * @param propIdx
1171   * Description of the Parameter
1172   * @return The typeName value
1173   * @exception DjenericException
1174   * Description of the Exception
1175   */

1176  public String JavaDoc getTypeName(int propIdx)
1177  {
1178    return _extent.getProperty(propIdx).getTypeName();
1179  }
1180
1181  /**
1182   * Gets the required attribute of the DjObject object
1183   *
1184   * @param propertyName
1185   * Description of the Parameter
1186   * @return The required value
1187   * @exception DjenericException
1188   * Description of the Exception
1189   */

1190  public boolean isRequired(String JavaDoc propertyName) throws DjenericException
1191  {
1192    int idx = propertyName.lastIndexOf(".");
1193    if (idx != -1)
1194    {
1195      String JavaDoc propName = propertyName.substring(idx + 1);
1196      String JavaDoc instPath = propertyName.substring(0, idx);
1197      DjObject dest = resolveInstance(instPath, false);
1198      if (dest == null) throw new DjenericException(Messages.getString("ObjectPath.IdentifierNull", propertyName));
1199      return dest.isRequired(propName);
1200    }
1201    else return isRequired(_extent.getPropertyIndex(propertyName));
1202  }
1203
1204  /**
1205   * Gets the required attribute of the DjObject object
1206   *
1207   * @param propIdx
1208   * Description of the Parameter
1209   * @return The required value
1210   * @exception DjenericException
1211   * Description of the Exception
1212   */

1213  public boolean isRequired(int propIdx)
1214  {
1215    return _extent.getProperty(propIdx).isRequired();
1216  }
1217
1218  /**
1219   * Gets the propertyCount attribute of the DjObject object
1220   *
1221   * @return The propertyCount value
1222   */

1223  public int getPropertyCount()
1224  {
1225    return _extent.getPropertyCount();
1226  }
1227
1228  /**
1229   * Gets the propertyNames attribute of the DjObject object
1230   *
1231   * @return The propertyNames value
1232   */

1233  public String JavaDoc[] getPropertyNames()
1234  {
1235    return _extent.getPropertyNames();
1236  }
1237
1238  /**
1239   * Gets the propertyName attribute of the DjObject object
1240   *
1241   * @param idx
1242   * Description of the Parameter
1243   * @return The propertyName value
1244   */

1245  public String JavaDoc getPropertyName(int idx)
1246  {
1247    return _extent.getPropertyName(idx);
1248  }
1249
1250  /**
1251   * Returns the property of the DjObject object
1252   *
1253   * @param idx
1254   * Description of the Parameter
1255   * @return The property value
1256   */

1257  public DjProperty getProperty(int idx)
1258  {
1259    return _extent.getProperty(idx);
1260  }
1261
1262  /**
1263   * Returns the propertyByName of the DjObject object
1264   *
1265   * @param propertyName
1266   * Description of the Parameter
1267   * @return The propertyByName value
1268   * @exception ObjectNotDefinedException
1269   * Description of the Exception
1270   */

1271  public DjProperty getProperty(String JavaDoc propertyName) throws ObjectNotDefinedException
1272  {
1273    return _extent.getProperty(propertyName);
1274  }
1275
1276  /**
1277   * Gets the propertyIndex attribute of the DjObject object
1278   *
1279   * @param propertyName
1280   * Description of the Parameter
1281   * @return The propertyIndex value
1282   * @exception ObjectNotDefinedException
1283   * Description of the Exception
1284   */

1285  public int getPropertyIndex(String JavaDoc propertyName) throws ObjectNotDefinedException
1286  {
1287    return _extent.getPropertyIndex(propertyName);
1288  }
1289
1290  /**
1291   * Gets the validValues attribute of the DjObject object
1292   *
1293   * @param propertyName
1294   * Description of the Parameter
1295   * @return The validValues value
1296   * @exception DjenericException
1297   * Description of the Exception
1298   */

1299  public DjDomainValue[] getValidValues(String JavaDoc propertyName) throws DjenericException
1300  {
1301    int idx = propertyName.lastIndexOf(".");
1302    if (idx != -1)
1303    {
1304      String JavaDoc propName = propertyName.substring(idx + 1);
1305      String JavaDoc instPath = propertyName.substring(0, idx);
1306      DjObject dest = resolveInstance(instPath, false);
1307      if (dest == null) throw new DjenericException(Messages.getString("ObjectPath.IdentifierNull", propertyName));
1308      return dest.getValidValues(propName);
1309    }
1310    else return getValidValues(_extent.getPropertyIndex(propertyName));
1311  }
1312
1313  /**
1314   * Gets the validValues attribute of the DjObject object
1315   *
1316   * @param propIdx
1317   * Description of the Parameter
1318   * @return The validValues value
1319   * @exception DjenericException
1320   * Description of the Exception
1321   */

1322  public DjDomainValue[] getValidValues(int propIdx) throws DjenericException
1323  {
1324    DjAssociation assoc = getMasterAssociationByPropertyName(propIdx);
1325    if (assoc == null)
1326    {
1327      // No association based on this property? Then return any domain's values
1328
DjProperty prop = getProperty(propIdx);
1329
1330      return prop.getValidValues(getSession());
1331    }
1332
1333    DjExtent masterExtent = assoc.getRelation().getMasterExtent();
1334    // We are the detail!
1335

1336    DjRestriction restriction = assoc.getRestriction();
1337    String JavaDoc listKey = masterExtent.getName();
1338
1339    if (restriction != null)
1340    {
1341      long id = 0;
1342
1343      try
1344      {
1345        id = restriction.evaluate(this);
1346      }
1347      catch (RestrictionFailedException rfe)
1348      {
1349      }
1350
1351      listKey += getObjectId() + assoc.getName() + id;
1352    }
1353
1354    DjDomainValue[] valids = _session.getValidValues(listKey);
1355    if (valids == null)
1356    {
1357      valids = DjDomain.convertToValueList(_session.getValidMasterObjects(this, masterExtent, restriction, false));
1358      _session.registerValidValues(listKey, valids);
1359    }
1360    return valids;
1361  }
1362
1363  /**
1364   * Description of the Method
1365   *
1366   * @exception DjenericException
1367   * Description of the Exception
1368   */

1369  public void validate() throws DjenericException
1370  {
1371    boolean checkIntegrity = getSession().getPersistenceManager().isCheckReferentialIntegrity();
1372    for (int i = 0; i < getPropertyCount(); i++)
1373    {
1374      DjPropertyType type = getProperty(i).getType();
1375
1376      // Should we check the value?
1377
boolean shouldCheck = (type instanceof DjDomain) || (checkIntegrity && type instanceof DjExtent);
1378
1379      if (shouldCheck) checkDomainValue(i, get(i));
1380    }
1381    // validate any other object constraints here.
1382
// to be implemented in subclass
1383
}
1384
1385  ///////////////////////////////////////////////////////////////////////////////////////////
1386
/////////////////////////// SETTERS AND GETTERS
1387

1388  /**
1389   * Sets the null attribute of the DjObject object
1390   *
1391   * @param propertyName
1392   * The new null value
1393   * @exception ObjectNotDefinedException
1394   * Description of the Exception
1395   */

1396  public void setNull(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
1397  {
1398    int idx = propertyName.lastIndexOf(".");
1399    if (idx != -1)
1400    {
1401      String JavaDoc propName = propertyName.substring(idx + 1);
1402      String JavaDoc instPath = propertyName.substring(0, idx);
1403      resolveInstance(instPath, true).setNull(propName);
1404    }
1405    else setNull(_extent.getPropertyIndex(propertyName));
1406  }
1407
1408  /**
1409   * Sets the null attribute of the DjObject object
1410   *
1411   * @param propIdx
1412   * The new null value
1413   */

1414  public void setNull(int propIdx) throws DjenericException
1415  {
1416    if (_propertyValues[propIdx] != null)
1417    {
1418      // Automatically sychronize associations when updates take place.
1419
// BUT: be sure to NOT DO THIS when initial loading from the
1420
// persistent store
1421
// takes place, and ignore transient objects (QBE's and the like)
1422
if (!_isBeingLoaded && !isTransient() && getProperty(propIdx).getType() instanceof DjExtent)
1423      {
1424        Long JavaDoc oldValue = (Long JavaDoc) _propertyValues[propIdx];
1425
1426        DjObject obj = getSession().getFromSession(oldValue.longValue());
1427        if (obj != null) obj.synchronizeAssociations();
1428      }
1429      _propertyValues[propIdx] = null;
1430      setModified(true);
1431    }
1432  }
1433
1434  /**
1435   * Gets the null attribute of the DjObject object
1436   *
1437   * @param propertyName
1438   * Description of the Parameter
1439   * @return The null value
1440   * @exception ObjectNotDefinedException
1441   * Description of the Exception
1442   */

1443  public boolean isNull(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
1444  {
1445    int idx = propertyName.lastIndexOf(".");
1446    if (idx != -1)
1447    {
1448      String JavaDoc propName = propertyName.substring(idx + 1);
1449      String JavaDoc instPath = propertyName.substring(0, idx);
1450      DjObject dest = resolveInstance(instPath, false);
1451      if (dest == null) return true;
1452      return dest.isNull(propName);
1453    }
1454    else return isNull(_extent.getPropertyIndex(propertyName));
1455  }
1456
1457  /**
1458   * Gets the null attribute of the DjObject object
1459   *
1460   * @param propIdx
1461   * Description of the Parameter
1462   * @return The null value
1463   */

1464  public boolean isNull(int propIdx)
1465  {
1466    return _propertyValues[propIdx] == null;
1467  }
1468
1469  /**
1470   * Get returns the value of the specified property OR detail association The result of an association is a DjList for
1471   * 1:n unicity or a DjObject when unicity is 1:1. Furthermore if the unicity is 1:1 and no detail exists, null is
1472   * returned
1473   *
1474   * @param propertyName
1475   * Description of the Parameter
1476   * @return Description of the Return Value
1477   * @exception ObjectNotDefinedException
1478   * Description of the Exception
1479   * @exception DjenericException
1480   * Description of the Exception
1481   */

1482  public Object JavaDoc get(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
1483  {
1484    int idx = propertyName.lastIndexOf(".");
1485    if (idx != -1)
1486    {
1487      String JavaDoc propName = propertyName.substring(idx + 1);
1488      String JavaDoc instPath = propertyName.substring(0, idx);
1489      DjObject dest = resolveInstance(instPath, false);
1490      if (dest == null) return null;
1491      return dest.get(propName);
1492    }
1493    else try
1494    {
1495      return get(_extent.getPropertyIndex(propertyName));
1496    }
1497    catch (ObjectNotDefinedException onde)
1498    {
1499      String JavaDoc assocName = propertyName;
1500      boolean isIndexed = false;
1501      int indexValue = 0;
1502      if (assocName.indexOf('[') != -1)
1503      {
1504        isIndexed = true;
1505        int brackIdx = assocName.indexOf('[');
1506        int brackEndIdx = assocName.indexOf(']');
1507        indexValue = Integer.parseInt(assocName.substring(brackIdx + 1, brackEndIdx));
1508        assocName = assocName.substring(0, brackIdx);
1509      }
1510
1511      DjAssociation detail = getDetailAssociationByName(assocName);
1512      DjList result = detail.getObjects();
1513      if (isIndexed) return result.getDjenericObjectAt(indexValue);
1514
1515      if (detail.isOneToMany()) return result;
1516      if (result.size() == 0) return null;
1517      // It is a 1:1 relation so return the first in the list
1518
return result.getDjenericObjectAt(0);
1519    }
1520  }
1521
1522  /**
1523   * Description of the Method
1524   *
1525   * @param propIdx
1526   * Description of the Parameter
1527   * @return Description of the Return Value
1528   * @exception DjenericException
1529   * Description of the Exception
1530   */

1531  public Object JavaDoc get(int propIdx) throws DjenericException
1532  {
1533    if (isNull(propIdx))
1534    {
1535      return null;
1536    }
1537
1538    DjPropertyType tp = _extent.getProperty(propIdx).getType();
1539    if (tp instanceof DjExtent)
1540    {
1541      return _session.getObject((DjExtent) tp, getLong(propIdx));
1542    }
1543    else
1544    {
1545      return _propertyValues[propIdx];
1546    }
1547  }
1548
1549  /**
1550   * Description of the Method
1551   *
1552   * @param propertyName
1553   * Description of the Parameter
1554   * @param value
1555   * Description of the Parameter
1556   * @exception ObjectNotDefinedException
1557   * Description of the Exception
1558   * @exception PropertyFormatException
1559   * Description of the Exception
1560   * @exception DjenericException
1561   * Description of the Exception
1562   */

1563  public void set(String JavaDoc propertyName, Object JavaDoc value) throws ObjectNotDefinedException, PropertyFormatException,
1564      DjenericException
1565  {
1566    int idx = propertyName.lastIndexOf(".");
1567    if (idx != -1)
1568    {
1569      String JavaDoc propName = propertyName.substring(idx + 1);
1570      String JavaDoc instPath = propertyName.substring(0, idx);
1571      resolveInstance(instPath, true).set(propName, value);
1572    }
1573    else
1574    {
1575      try
1576      {
1577        set(_extent.getPropertyIndex(propertyName), value);
1578      }
1579      catch (ObjectNotDefinedException onde)
1580      {
1581        if (!(value instanceof DjObject) && !(value instanceof DjList)) throw onde;
1582
1583        String JavaDoc assocName = propertyName;
1584        boolean isIndexed = false;
1585        int indexValue = 0;
1586        if (assocName.indexOf('[') != -1)
1587        {
1588          isIndexed = true;
1589          int brackIdx = assocName.indexOf('[');
1590          int brackEndIdx = assocName.indexOf(']');
1591          indexValue = Integer.parseInt(assocName.substring(brackIdx + 1, brackEndIdx));
1592          assocName = assocName.substring(0, brackIdx);
1593        }
1594
1595        DjAssociation detail = getDetailAssociationByName(assocName);
1596
1597        if (isIndexed)
1598        {
1599          if (value instanceof DjList) throw new DjenericException(Messages.getString("DjObject.CannotAssignList",
1600                                                                                      propertyName));
1601          detail.replaceDetail(indexValue, (DjObject) value);
1602        }
1603        else
1604        {
1605          DjList theValues;
1606          if (value instanceof DjObject)
1607          {
1608            theValues = new DjList();
1609            theValues.add(value);
1610          }
1611          else
1612          {
1613            theValues = (DjList) value;
1614            if ((theValues.size() > 1) && detail.isOneToOne())
1615            {
1616              throw new DjenericException(Messages.getString("DjObject.RelationNot11", propertyName, propertyName));
1617            }
1618          }
1619
1620          detail.markAllDeletedExcluding(theValues);
1621          detail.addAll(theValues);
1622        }
1623      }
1624    }
1625  }
1626
1627  /**
1628   * Description of the Method
1629   *
1630   * @param propIdx
1631   * Description of the Parameter
1632   * @param value
1633   * Description of the Parameter
1634   * @exception ObjectNotDefinedException
1635   * Description of the Exception
1636   * @exception PropertyFormatException
1637   * Description of the Exception
1638   * @exception DjenericException
1639   * Description of the Exception
1640   */

1641  public void set(int propIdx, Object JavaDoc value) throws PropertyFormatException, ObjectNotDefinedException,
1642      DjenericException
1643  {
1644    if (value == null)
1645    {
1646      setNull(propIdx);
1647      return;
1648    }
1649    DjProperty prop = _extent.getProperty(propIdx);
1650
1651    if (prop.getType() instanceof DjExtent)
1652    {
1653      if (!(value instanceof DjObject))
1654      {
1655        throw new PropertyFormatException(Messages.getString("DjObject.InvalidObjectType", value.getClass().getName()),
1656            this, _extent.getPropertyName(propIdx));
1657      }
1658
1659      DjObject po = (DjObject) value;
1660      po.determineObjectIdIfNeeded();
1661
1662      setLong(propIdx, po.getObjectId());
1663
1664    }
1665    else
1666    {
1667      if (value instanceof byte[] && prop.getTypeCode() == DjDomain.BYTE_TYPE) setBytes(propIdx, (byte[]) value);
1668      else if (value instanceof byte[] && prop.getTypeCode() == DjDomain.STRING_TYPE) setString(propIdx, new String JavaDoc(
1669          (byte[]) value));
1670      else
1671      // We can always set string properties (using toString())
1672
// but we must fail if we encounter an unsupported conversion
1673
// String, Long, Integer, Date and BigDecimal are supported.
1674
// Of the object is of any other type the property must be of
1675
// type string. So:
1676
if (!(value instanceof String JavaDoc || value instanceof Long JavaDoc || value instanceof Integer JavaDoc
1677            || value instanceof java.util.Date JavaDoc || value instanceof BigDecimal JavaDoc)
1678          && (prop.getTypeCode() != DjDomain.STRING_TYPE))
1679      {
1680        throw new PropertyFormatException(Messages.getString("DjObject.InvalidObjectType", value.getClass().getName()),
1681            this, _extent.getPropertyName(propIdx));
1682      }
1683      else setString(propIdx, value.toString());
1684    }
1685  }
1686
1687  /**
1688   * Sets the string attribute of the DjObject object
1689   *
1690   * @param propertyName
1691   * The new string value
1692   * @param value
1693   * The new string value
1694   * @exception ObjectNotDefinedException
1695   * Description of the Exception
1696   * @exception PropertyFormatException
1697   * Description of the Exception
1698   */

1699  public void setString(String JavaDoc propertyName, String JavaDoc value) throws PropertyFormatException, ObjectNotDefinedException,
1700      DjenericException
1701  {
1702    int idx = propertyName.lastIndexOf(".");
1703    if (idx != -1)
1704    {
1705      String JavaDoc propName = propertyName.substring(idx + 1);
1706      String JavaDoc instPath = propertyName.substring(0, idx);
1707      resolveInstance(instPath, true).setString(propName, value);
1708    }
1709    else setString(_extent.getPropertyIndex(propertyName), value);
1710  }
1711
1712  /**
1713   * Sets the string attribute of the DjObject object
1714   *
1715   * @param propIdx
1716   * The new string value
1717   * @param value
1718   * The new string value
1719   * @exception PropertyFormatException
1720   * Description of the Exception
1721   */

1722  public void setString(int propIdx, String JavaDoc value) throws PropertyFormatException, DjenericException
1723  {
1724    if (value == null)
1725    {
1726      setNull(propIdx);
1727      return;
1728    }
1729    int propType = getTypeCode(propIdx);
1730
1731    if (propType == DjDomain.STRING_TYPE)
1732    {
1733      if (isNull(propIdx) || !_propertyValues[propIdx].equals(value))
1734      {
1735        DjPropertyType tp = getType(propIdx);
1736        if (tp instanceof DjDomain)
1737        {
1738          DjDomain dom = (DjDomain) tp;
1739          if (dom.getCaseConversion().equals(DjDomain.CASE_UPPER)) value = value.toUpperCase();
1740          else if (dom.getCaseConversion().equals(DjDomain.CASE_LOWER)) value = value.toLowerCase();
1741        }
1742        checkDomainValue(propIdx, value);
1743        _propertyValues[propIdx] = value;
1744        setModified(true);
1745      }
1746      return;
1747    }
1748
1749    // An empty string will be interpreted as null from now on:
1750
if (value.trim().length() == 0)
1751    {
1752      setNull(propIdx);
1753    }
1754    else if (propType == DjDomain.BYTE_TYPE)
1755    {
1756      try
1757      {
1758        setBytes(propIdx, value.getBytes(DjPersistenceManager.ENCODING_METHOD));
1759      }
1760      catch (java.io.UnsupportedEncodingException JavaDoc uce)
1761      {
1762        throw new PropertyFormatException(uce.getMessage(), this, getPropertyName(propIdx));
1763      }
1764    }
1765    else if (propType == DjDomain.BIGDECIMAL_TYPE)
1766    {
1767      setBigDecimal(propIdx, new BigDecimal JavaDoc(value));
1768    }
1769    else if (propType == DjDomain.DATE_TYPE)
1770    {
1771      String JavaDoc mask = getFormatMask(propIdx);
1772      try
1773      {
1774        setDate(propIdx, convertString2Date(value, mask));
1775      }
1776      catch (ParseException JavaDoc pex)
1777      {
1778        throw new PropertyFormatException(Messages.getString("DjObject.FormatError", pex.getMessage(), mask), this,
1779            getPropertyName(propIdx));
1780      }
1781    }
1782    else if (propType == DjDomain.INT_TYPE)
1783    {
1784      setInt(propIdx, new Integer JavaDoc(value));
1785    }
1786    else if (propType == DjDomain.LONG_TYPE)
1787    {
1788      setLong(propIdx, new Long JavaDoc(value));
1789    }
1790    else
1791    {
1792      throw new PropertyFormatException(Messages.getString("DjObject.setStringError", String.valueOf(propType)), this,
1793          getPropertyName(propIdx));
1794    }
1795  }
1796
1797  /**
1798   * Gets the string attribute of the DjObject object
1799   *
1800   * @param propertyName
1801   * Description of the Parameter
1802   * @return The string value
1803   * @exception ObjectNotDefinedException
1804   * Description of the Exception
1805   */

1806  public String JavaDoc getString(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
1807  {
1808    int idx = propertyName.lastIndexOf(".");
1809    if (idx != -1)
1810    {
1811      String JavaDoc propName = propertyName.substring(idx + 1);
1812      String JavaDoc instPath = propertyName.substring(0, idx);
1813
1814      DjObject dest = resolveInstance(instPath, false);
1815      if (dest == null) return null;
1816      return dest.getString(propName);
1817    }
1818    else return getString(_extent.getPropertyIndex(propertyName));
1819  }
1820
1821  /**
1822   * Returns the formatMask of the DjObject object
1823   *
1824   * @param propIdx
1825   * Description of the Parameter
1826   * @return The formatMask value
1827   */

1828  public String JavaDoc getFormatMask(int propIdx)
1829  {
1830    String JavaDoc mask = null;
1831    DjPropertyType tp = getProperty(propIdx).getType();
1832    if (tp instanceof DjDomain)
1833    {
1834      DjDomain dom = (DjDomain) tp;
1835      mask = dom.getFormatMask();
1836      if (mask != null && mask.length() == 0) mask = null;
1837    }
1838    return mask;
1839  }
1840
1841  /**
1842   * Gets the string attribute of the DjObject object
1843   *
1844   * @param propIdx
1845   * Description of the Parameter
1846   * @return The string value
1847   */

1848  public String JavaDoc getString(int propIdx)
1849  {
1850    if (isNull(propIdx))
1851    {
1852      return null;
1853    }
1854    Object JavaDoc val = _propertyValues[propIdx];
1855    if (val == null)
1856    {
1857      return null;
1858    }
1859
1860    try
1861    {
1862      if (getTypeCode(propIdx) == DjDomain.DATE_TYPE)
1863      {
1864        return convertDate2String(getDate(propIdx), getFormatMask(propIdx));
1865      }
1866    }
1867    catch (Exception JavaDoc x)
1868    {
1869      DjLogger.log(x);
1870    }
1871
1872    if (getTypeCode(propIdx) == DjDomain.BYTE_TYPE)
1873    {
1874      try
1875      {
1876        return new String JavaDoc(getBytes(propIdx), DjPersistenceManager.ENCODING_METHOD);
1877      }
1878      catch (UnsupportedEncodingException JavaDoc uee)
1879      {
1880        DjLogger.log(uee);
1881        // try default encoding in stead
1882
return new String JavaDoc(getBytes(propIdx));
1883      }
1884    }
1885
1886    return val.toString();
1887  }
1888
1889  public String JavaDoc getOriginalValueString(String JavaDoc propertyName) throws ObjectNotDefinedException
1890  {
1891    return getOriginalValueString(getPropertyIndex(propertyName));
1892  }
1893
1894  public String JavaDoc getOriginalValueString(int propIdx)
1895  {
1896    Object JavaDoc val = _originalPropertyValues[propIdx];
1897    if (val == null)
1898    {
1899      return null;
1900    }
1901
1902    try
1903    {
1904      if (getTypeCode(propIdx) == DjDomain.DATE_TYPE)
1905      {
1906        return convertDate2String((Date JavaDoc) _originalPropertyValues[propIdx], getFormatMask(propIdx));
1907      }
1908    }
1909    catch (Exception JavaDoc x)
1910    {
1911      DjLogger.log(x);
1912    }
1913
1914    if (getTypeCode(propIdx) == DjDomain.BYTE_TYPE)
1915    {
1916      try
1917      {
1918        return new String JavaDoc((byte[]) _originalPropertyValues[propIdx], DjPersistenceManager.ENCODING_METHOD);
1919      }
1920      catch (UnsupportedEncodingException JavaDoc uee)
1921      {
1922        DjLogger.log(uee);
1923        // try default encoding in stead
1924
return new String JavaDoc((byte[]) _originalPropertyValues[propIdx]);
1925      }
1926    }
1927
1928    return val.toString();
1929  }
1930
1931  /**
1932   * Sets the bytes of the DjObject object
1933   *
1934   * @param propertyName
1935   * The new bytes value
1936   * @param value
1937   * The new bytes value
1938   * @exception ObjectNotDefinedException
1939   * Description of the Exception
1940   * @exception PropertyFormatException
1941   * Description of the Exception
1942   */

1943  public void setBytes(String JavaDoc propertyName, byte[] value) throws PropertyFormatException, ObjectNotDefinedException,
1944      DjenericException
1945  {
1946    int idx = propertyName.lastIndexOf(".");
1947    if (idx != -1)
1948    {
1949      String JavaDoc propName = propertyName.substring(idx + 1);
1950      String JavaDoc instPath = propertyName.substring(0, idx);
1951      resolveInstance(instPath, true).setBytes(propName, value);
1952    }
1953    else setBytes(_extent.getPropertyIndex(propertyName), value);
1954  }
1955
1956  /**
1957   * Sets the bytes of the DjObject object
1958   *
1959   * @param propIdx
1960   * The new bytes value
1961   * @param value
1962   * The new bytes value
1963   * @exception PropertyFormatException
1964   * Description of the Exception
1965   */

1966  public void setBytes(int propIdx, byte[] value) throws PropertyFormatException, DjenericException
1967  {
1968    if (value == null)
1969    {
1970      setNull(propIdx);
1971      return;
1972    }
1973    int propType = getTypeCode(propIdx);
1974
1975    if (propType == DjDomain.BYTE_TYPE)
1976    {
1977      if (isNull(propIdx) || !Arrays.equals(value, (byte[]) _propertyValues[propIdx]))
1978      {
1979        checkDomainValue(propIdx, value);
1980        _propertyValues[propIdx] = value;
1981        setModified(true);
1982      }
1983    }
1984    else if (propType == DjDomain.STRING_TYPE)
1985    {
1986      setString(propIdx, new String JavaDoc(value));
1987    }
1988    else
1989    {
1990      throw new PropertyFormatException(Messages.getString("DjObject.setBytesError", String.valueOf(propType)), this,
1991          getPropertyName(propIdx));
1992    }
1993
1994  }
1995
1996  /**
1997   * Sets the bigDecimal attribute of the DjObject object
1998   *
1999   * @param propertyName
2000   * The new bigDecimal value
2001   * @param value
2002   * The new bigDecimal value
2003   * @exception ObjectNotDefinedException
2004   * Description of the Exception
2005   * @exception PropertyFormatException
2006   * Description of the Exception
2007   */

2008  public void setBigDecimal(String JavaDoc propertyName, BigDecimal JavaDoc value) throws PropertyFormatException,
2009      ObjectNotDefinedException, DjenericException
2010  {
2011    int idx = propertyName.lastIndexOf(".");
2012    if (idx != -1)
2013    {
2014      String JavaDoc propName = propertyName.substring(idx + 1);
2015      String JavaDoc instPath = propertyName.substring(0, idx);
2016      resolveInstance(instPath, true).setBigDecimal(propName, value);
2017    }
2018    else setBigDecimal(_extent.getPropertyIndex(propertyName), value);
2019  }
2020
2021  private void checkDomainValue(int propIdx, Object JavaDoc value) throws PropertyFormatException
2022  {
2023    if (_isBeingLoaded || value == null) return;
2024
2025    DjProperty theProp = getExtent().getProperty(propIdx);
2026    try
2027    {
2028      theProp.getType().validateValue(value);
2029    }
2030    catch (DomainViolationException dve)
2031    {
2032      throw new PropertyFormatException(dve.getMessage(), this, getPropertyName(propIdx));
2033    }
2034  }
2035
2036  /**
2037   * Sets the bigDecimal attribute of the DjObject object
2038   *
2039   * @param propIdx
2040   * The new bigDecimal value
2041   * @param value
2042   * The new bigDecimal value
2043   * @exception PropertyFormatException
2044   * Description of the Exception
2045   */

2046  public void setBigDecimal(int propIdx, BigDecimal JavaDoc value) throws PropertyFormatException, DjenericException
2047  {
2048    if (value == null)
2049    {
2050      setNull(propIdx);
2051      return;
2052    }
2053
2054    int propType = getTypeCode(propIdx);
2055
2056    if (propType == DjDomain.BIGDECIMAL_TYPE)
2057    {
2058      if (isNull(propIdx) || !_propertyValues[propIdx].equals(value))
2059      {
2060        checkDomainValue(propIdx, value);
2061        _propertyValues[propIdx] = value;
2062        setModified(true);
2063      }
2064    }
2065    else if (propType == DjDomain.STRING_TYPE)
2066    {
2067      setString(propIdx, value.toString());
2068    }
2069    else if (propType == DjDomain.DATE_TYPE)
2070    {
2071      setDate(propIdx, new Date JavaDoc(value.longValue()));
2072    }
2073    else if (propType == DjDomain.INT_TYPE)
2074    {
2075      setInt(propIdx, new Integer JavaDoc(value.toString()));
2076    }
2077    else if (propType == DjDomain.LONG_TYPE)
2078    {
2079      setLong(propIdx, new Long JavaDoc(value.toString()));
2080    }
2081    else
2082    {
2083      throw new PropertyFormatException(Messages.getString("DjObject.setBigDecimalError", String.valueOf(propType)),
2084          this, getPropertyName(propIdx));
2085    }
2086
2087  }
2088
2089  /**
2090   * Gets the bigDecimal attribute of the DjObject object
2091   *
2092   * @param propertyName
2093   * Description of the Parameter
2094   * @return The bigDecimal value
2095   * @exception ObjectNotDefinedException
2096   * Description of the Exception
2097   */

2098  public BigDecimal JavaDoc getBigDecimal(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
2099  {
2100    int idx = propertyName.lastIndexOf(".");
2101    if (idx != -1)
2102    {
2103      String JavaDoc propName = propertyName.substring(idx + 1);
2104      String JavaDoc instPath = propertyName.substring(0, idx);
2105      DjObject dest = resolveInstance(instPath, false);
2106      if (dest == null) return null;
2107      return dest.getBigDecimal(propName);
2108    }
2109    else return getBigDecimal(_extent.getPropertyIndex(propertyName));
2110  }
2111
2112  /**
2113   * Gets the bigDecimal attribute of the DjObject object
2114   *
2115   * @param propIdx
2116   * Description of the Parameter
2117   * @return The bigDecimal value
2118   */

2119  public BigDecimal JavaDoc getBigDecimal(int propIdx)
2120  {
2121    if (isNull(propIdx))
2122    {
2123      return null;
2124    }
2125    Object JavaDoc val = _propertyValues[propIdx];
2126    if (val == null)
2127    {
2128      return null;
2129    }
2130
2131    if (val instanceof BigDecimal JavaDoc)
2132    {
2133      return (BigDecimal JavaDoc) val;
2134    }
2135
2136    return new BigDecimal JavaDoc(val.toString());
2137  }
2138
2139  /**
2140   * Returns the bytes of the DjObject object
2141   *
2142   * @param propertyName
2143   * Description of the Parameter
2144   * @return The bytes value
2145   * @exception ObjectNotDefinedException
2146   * Description of the Exception
2147   */

2148  public byte[] getBytes(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
2149  {
2150    int idx = propertyName.lastIndexOf(".");
2151    if (idx != -1)
2152    {
2153      String JavaDoc propName = propertyName.substring(idx + 1);
2154      String JavaDoc instPath = propertyName.substring(0, idx);
2155      DjObject dest = resolveInstance(instPath, false);
2156      if (dest == null) return null;
2157      return dest.getBytes(propName);
2158    }
2159    else return getBytes(_extent.getPropertyIndex(propertyName));
2160  }
2161
2162  /**
2163   * Returns the bytes of the DjObject object
2164   *
2165   * @param propIdx
2166   * Description of the Parameter
2167   * @return The bytes value
2168   */

2169  public byte[] getBytes(int propIdx)
2170  {
2171    if (isNull(propIdx))
2172    {
2173      return null;
2174    }
2175    Object JavaDoc val = _propertyValues[propIdx];
2176    if (val == null)
2177    {
2178      return null;
2179    }
2180
2181    if (val instanceof byte[])
2182    {
2183      return (byte[]) val;
2184    }
2185
2186    try
2187    {
2188      return val.toString().getBytes(DjPersistenceManager.ENCODING_METHOD);
2189    }
2190    catch (UnsupportedEncodingException JavaDoc uee)
2191    {
2192      DjLogger.log(uee);
2193      return val.toString().getBytes();
2194    }
2195  }
2196
2197  /**
2198   * Sets the int attribute of the DjObject object
2199   *
2200   * @param propertyName
2201   * The new int value
2202   * @param value
2203   * The new int value
2204   * @exception ObjectNotDefinedException
2205   * Description of the Exception
2206   * @exception PropertyFormatException
2207   * Description of the Exception
2208   */

2209  public void setInt(String JavaDoc propertyName, int value) throws PropertyFormatException, ObjectNotDefinedException,
2210      DjenericException
2211  {
2212    int idx = propertyName.lastIndexOf(".");
2213    if (idx != -1)
2214    {
2215      String JavaDoc propName = propertyName.substring(idx + 1);
2216      String JavaDoc instPath = propertyName.substring(0, idx);
2217      resolveInstance(instPath, true).setInt(propName, value);
2218    }
2219    else setInt(_extent.getPropertyIndex(propertyName), new Integer JavaDoc(value));
2220  }
2221
2222  /**
2223   * Sets the int attribute of the DjObject object
2224   *
2225   * @param propIdx
2226   * The new int value
2227   * @param value
2228   * The new int value
2229   * @exception PropertyFormatException
2230   * Description of the Exception
2231   */

2232  public void setInt(int propIdx, Integer JavaDoc value) throws PropertyFormatException, DjenericException
2233  {
2234    int propType = getTypeCode(propIdx);
2235
2236    if (propType == DjDomain.INT_TYPE)
2237    {
2238      if (isNull(propIdx) || !_propertyValues[propIdx].equals(value))
2239      {
2240        checkDomainValue(propIdx, value);
2241        _propertyValues[propIdx] = value;
2242        setModified(true);
2243      }
2244    }
2245    else if (propType == DjDomain.BIGDECIMAL_TYPE)
2246    {
2247      setBigDecimal(propIdx, new BigDecimal JavaDoc(value.intValue()));
2248    }
2249    else if (propType == DjDomain.STRING_TYPE)
2250    {
2251      setString(propIdx, value.toString());
2252    }
2253    else if (propType == DjDomain.DATE_TYPE)
2254    {
2255      setDate(propIdx, new Date JavaDoc(value.longValue()));
2256    }
2257    else if (propType == DjDomain.LONG_TYPE)
2258    {
2259      setLong(propIdx, new Long JavaDoc(value.longValue()));
2260    }
2261    else
2262    {
2263      throw new PropertyFormatException(Messages.getString("DjObject.setIntError", String.valueOf(propType)), this,
2264          getPropertyName(propIdx));
2265    }
2266
2267  }
2268
2269  /**
2270   * Sets the int attribute of the DjObject object
2271   *
2272   * @param propertyName
2273   * The new int value
2274   * @param value
2275   * The new int value
2276   * @exception ObjectNotDefinedException
2277   * Description of the Exception
2278   * @exception PropertyFormatException
2279   * Description of the Exception
2280   */

2281  public void setInt(String JavaDoc propertyName, Integer JavaDoc value) throws PropertyFormatException, ObjectNotDefinedException,
2282      DjenericException
2283  {
2284    int idx = propertyName.lastIndexOf(".");
2285    if (idx != -1)
2286    {
2287      String JavaDoc propName = propertyName.substring(idx + 1);
2288      String JavaDoc instPath = propertyName.substring(0, idx);
2289      resolveInstance(instPath, true).setInt(propName, value);
2290    }
2291    else setInt(_extent.getPropertyIndex(propertyName), value);
2292  }
2293
2294  /**
2295   * Sets the int attribute of the DjObject object
2296   *
2297   * @param propIdx
2298   * The new int value
2299   * @param value
2300   * The new int value
2301   * @exception PropertyFormatException
2302   * Description of the Exception
2303   */

2304  public void setInt(int propIdx, int value) throws PropertyFormatException, DjenericException
2305  {
2306    setInt(propIdx, new Integer JavaDoc(value));
2307  }
2308
2309  /**
2310   * Gets the int attribute of the DjObject object
2311   *
2312   * @param propertyName
2313   * Description of the Parameter
2314   * @return The int value
2315   * @exception ObjectNotDefinedException
2316   * Description of the Exception
2317   */

2318  public int getInt(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
2319  {
2320    int idx = propertyName.lastIndexOf(".");
2321    if (idx != -1)
2322    {
2323      String JavaDoc propName = propertyName.substring(idx + 1);
2324      String JavaDoc instPath = propertyName.substring(0, idx);
2325      DjObject dest = resolveInstance(instPath, false);
2326      if (dest == null) throw new DjenericException(Messages.getString("ObjectPath.IdentifierNull", propertyName));
2327      return dest.getInt(propName);
2328    }
2329    else return getInt(_extent.getPropertyIndex(propertyName));
2330  }
2331
2332  /**
2333   * Gets the int attribute of the DjObject object
2334   *
2335   * @param propIdx
2336   * Description of the Parameter
2337   * @return The int value
2338   */

2339  public int getInt(int propIdx)
2340  {
2341    Object JavaDoc val = _propertyValues[propIdx];
2342    if (val == null)
2343    {
2344      return 0;
2345    }
2346
2347    if (val instanceof Integer JavaDoc)
2348    {
2349      return ((Integer JavaDoc) val).intValue();
2350    }
2351
2352    return Integer.parseInt(val.toString());
2353  }
2354
2355  /**
2356   * Sets the long attribute of the DjObject object
2357   *
2358   * @param propertyName
2359   * The new long value
2360   * @param value
2361   * The new long value
2362   * @exception ObjectNotDefinedException
2363   * Description of the Exception
2364   * @exception PropertyFormatException
2365   * Description of the Exception
2366   */

2367  public void setLong(String JavaDoc propertyName, long value) throws PropertyFormatException, ObjectNotDefinedException,
2368      DjenericException
2369  {
2370    int idx = propertyName.lastIndexOf(".");
2371    if (idx != -1)
2372    {
2373      String JavaDoc propName = propertyName.substring(idx + 1);
2374      String JavaDoc instPath = propertyName.substring(0, idx);
2375      resolveInstance(instPath, true).setLong(propName, value);
2376    }
2377    else setLong(_extent.getPropertyIndex(propertyName), new Long JavaDoc(value));
2378  }
2379
2380  /**
2381   * Sets the long attribute of the DjObject object
2382   *
2383   * @param propIdx
2384   * The new long value
2385   * @param value
2386   * The new long value
2387   * @exception PropertyFormatException
2388   * Description of the Exception
2389   */

2390  public void setLong(int propIdx, Long JavaDoc value) throws PropertyFormatException, DjenericException
2391  {
2392
2393    int propType = getTypeCode(propIdx);
2394
2395    if (propType == DjDomain.LONG_TYPE)
2396    {
2397      if (isNull(propIdx) || !_propertyValues[propIdx].equals(value))
2398      {
2399        checkDomainValue(propIdx, value);
2400        Long JavaDoc oldValue = (Long JavaDoc) _propertyValues[propIdx];
2401        _propertyValues[propIdx] = value;
2402        setModified(true);
2403
2404        try
2405        { // Automatically sychronize associations when updates take place.
2406
// BUT: be sure to NOT DO THIS when initial loading from the
2407
// persistent store
2408
// takes place, and ignore transient objects (QBE's and the like)
2409
if (!_isBeingLoaded && !isTransient() && getProperty(propIdx).getType() instanceof DjExtent)
2410          {
2411            if (value != null)
2412            {
2413              DjObject obj = getSession().getFromSession(value.longValue());
2414              if (obj != null) obj.synchronizeAssociations();
2415            }
2416
2417            if (oldValue != null)
2418            {
2419              DjObject obj = getSession().getFromSession(oldValue.longValue());
2420              if (obj != null) obj.synchronizeAssociations();
2421            }
2422          }
2423        }
2424        catch (DjenericException dje)
2425        {
2426          DjLogger.log(dje);
2427          throw new PropertyFormatException(dje.getMessage(), this, getProperty(propIdx).getName());
2428        }
2429      }
2430    }
2431    else if (propType == DjDomain.BIGDECIMAL_TYPE)
2432    {
2433      setBigDecimal(propIdx, new BigDecimal JavaDoc(value.longValue()));
2434    }
2435    else if (propType == DjDomain.STRING_TYPE)
2436    {
2437      setString(propIdx, value.toString());
2438    }
2439    else if (propType == DjDomain.DATE_TYPE)
2440    {
2441      setDate(propIdx, new Date JavaDoc(value.longValue()));
2442    }
2443    else if (propType == DjDomain.INT_TYPE)
2444    {
2445      setInt(propIdx, new Integer JavaDoc(value.intValue()));
2446    }
2447    else
2448    {
2449      throw new PropertyFormatException(Messages.getString("DjObject.setLongError", String.valueOf(propType)), this,
2450          getPropertyName(propIdx));
2451    }
2452  }
2453
2454  /**
2455   * Sets the long attribute of the DjObject object
2456   *
2457   * @param propertyName
2458   * The new long value
2459   * @param value
2460   * The new long value
2461   * @exception ObjectNotDefinedException
2462   * Description of the Exception
2463   * @exception PropertyFormatException
2464   * Description of the Exception
2465   */

2466  public void setLong(String JavaDoc propertyName, Long JavaDoc value) throws PropertyFormatException, ObjectNotDefinedException,
2467      DjenericException
2468  {
2469    int idx = propertyName.lastIndexOf(".");
2470    if (idx != -1)
2471    {
2472      String JavaDoc propName = propertyName.substring(idx + 1);
2473      String JavaDoc instPath = propertyName.substring(0, idx);
2474      resolveInstance(instPath, true).setLong(propName, value);
2475    }
2476    else setLong(_extent.getPropertyIndex(propertyName), value);
2477  }
2478
2479  /**
2480   * Sets the long attribute of the DjObject object
2481   *
2482   * @param propIdx
2483   * The new long value
2484   * @param value
2485   * The new long value
2486   * @exception PropertyFormatException
2487   * Description of the Exception
2488   */

2489  public void setLong(int propIdx, long value) throws PropertyFormatException, DjenericException
2490  {
2491    setLong(propIdx, new Long JavaDoc(value));
2492  }
2493
2494  /**
2495   * Gets the long attribute of the DjObject object
2496   *
2497   * @param propertyName
2498   * Description of the Parameter
2499   * @return The long value
2500   * @exception ObjectNotDefinedException
2501   * Description of the Exception
2502   */

2503  public long getLong(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
2504  {
2505    int idx = propertyName.lastIndexOf(".");
2506    if (idx != -1)
2507    {
2508      String JavaDoc propName = propertyName.substring(idx + 1);
2509      String JavaDoc instPath = propertyName.substring(0, idx);
2510      DjObject dest = resolveInstance(instPath, false);
2511      if (dest == null) throw new DjenericException(Messages.getString("ObjectPath.IdentifierNull", propertyName));
2512      return dest.getLong(propName);
2513    }
2514    else return getLong(_extent.getPropertyIndex(propertyName));
2515  }
2516
2517  /**
2518   * Gets the long attribute of the DjObject object
2519   *
2520   * @param propIdx
2521   * Description of the Parameter
2522   * @return The long value
2523   */

2524  public long getLong(int propIdx)
2525  {
2526    Object JavaDoc val = _propertyValues[propIdx];
2527    if (val == null)
2528    {
2529      return 0;
2530    }
2531
2532    if (val instanceof Long JavaDoc)
2533    {
2534      return ((Long JavaDoc) val).longValue();
2535    }
2536
2537    return Long.parseLong(val.toString());
2538  }
2539
2540  /**
2541   * Sets the date attribute of the DjObject object
2542   *
2543   * @param propertyName
2544   * The new date value
2545   * @param dt
2546   * The new date value
2547   * @exception ObjectNotDefinedException
2548   * Description of the Exception
2549   * @exception PropertyFormatException
2550   * Description of the Exception
2551   */

2552  public void setDate(String JavaDoc propertyName, java.util.Date JavaDoc dt) throws PropertyFormatException,
2553      ObjectNotDefinedException, DjenericException
2554  {
2555    int idx = propertyName.lastIndexOf(".");
2556    if (idx != -1)
2557    {
2558      String JavaDoc propName = propertyName.substring(idx + 1);
2559      String JavaDoc instPath = propertyName.substring(0, idx);
2560      resolveInstance(instPath, true).setDate(propName, dt);
2561    }
2562    else setDate(getPropertyIndex(propertyName), dt);
2563  }
2564
2565  /**
2566   * Sets the date attribute of the DjObject object
2567   *
2568   * @param propIdx
2569   * The new date value
2570   * @param dt
2571   * The new date value
2572   * @exception PropertyFormatException
2573   * Description of the Exception
2574   */

2575  public void setDate(int propIdx, java.util.Date JavaDoc dt) throws PropertyFormatException, DjenericException
2576  {
2577    if (dt == null)
2578    {
2579      setNull(propIdx);
2580      return;
2581    }
2582    int propType = getTypeCode(propIdx);
2583
2584    if (propType == DjDomain.BIGDECIMAL_TYPE)
2585    {
2586      setBigDecimal(propIdx, new BigDecimal JavaDoc(dt.getTime()));
2587
2588    }
2589    else if (propType == DjDomain.STRING_TYPE)
2590    {
2591      setString(propIdx, dt.toString());
2592    }
2593    else if (propType == DjDomain.DATE_TYPE)
2594    {
2595      if (isNull(propIdx) || !_propertyValues[propIdx].equals(dt))
2596      {
2597        checkDomainValue(propIdx, dt);
2598        _propertyValues[propIdx] = dt;
2599        setModified(true);
2600      }
2601    }
2602    else if (propType == DjDomain.LONG_TYPE)
2603    {
2604      setLong(propIdx, dt.getTime());
2605    }
2606    else
2607    {
2608      throw new PropertyFormatException(Messages.getString("DjObject.setDateError", String.valueOf(propType)), this,
2609          getPropertyName(propIdx));
2610    }
2611  }
2612
2613  /**
2614   * Gets the date attribute of the DjObject object
2615   *
2616   * @param propertyName
2617   * Description of the Parameter
2618   * @return The date value
2619   * @exception ObjectNotDefinedException
2620   * Description of the Exception
2621   */

2622  public java.util.Date JavaDoc getDate(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
2623  {
2624    if (isNull(propertyName))
2625    {
2626      return null;
2627    }
2628    return new java.util.Date JavaDoc(getLong(propertyName));
2629  }
2630
2631  /**
2632   * Gets the date attribute of the DjObject object
2633   *
2634   * @param propIdx
2635   * Description of the Parameter
2636   * @return The date value
2637   */

2638  public java.util.Date JavaDoc getDate(int propIdx)
2639  {
2640    if (isNull(propIdx))
2641    {
2642      return null;
2643    }
2644    Object JavaDoc val = _propertyValues[propIdx];
2645    if (val == null)
2646    {
2647      return null;
2648    }
2649
2650    if (val instanceof Date JavaDoc)
2651    {
2652      return (Date JavaDoc) val;
2653    }
2654
2655    return new Date JavaDoc(new Long JavaDoc(val.toString()).longValue());
2656  }
2657
2658  /**
2659   * Description of the Method
2660   *
2661   * @return Description of the Return Value
2662   */

2663  public String JavaDoc toString()
2664  {
2665    return getDescriptor();
2666  }
2667
2668  ///////////////////////////////////////////////////////////////////////////////////////////
2669
//////////////// TRANSACTIONAL STUFF
2670

2671  /**
2672   * Gets the modified attribute of the DjObject object
2673   *
2674   * @return The modified value
2675   */

2676  public boolean isModified()
2677  {
2678    return _isModified;
2679  }
2680
2681  /**
2682   * Adds a feature to the RestrictingObjects attribute of the DjObject object
2683   *
2684   * @return Description of the Return Value
2685   * @exception DjenericException
2686   * Description of the Exception
2687   */

2688  protected DjExtent restrictingObjectsExist() throws DjenericException
2689  {
2690    return restrictingObjectsExist(new HashMap JavaDoc());
2691  }
2692
2693  protected DjExtent restrictingObjectsExist(HashMap JavaDoc hitlist) throws DjenericException
2694  {
2695    if (hitlist.containsKey(this)) return null;
2696    hitlist.put(this, this);
2697
2698    DjAssociation[] assocs = getDetailAssociations();
2699
2700    for (int i = 0; i < assocs.length; i++)
2701    {
2702      if (!assocs[i].isDetailsContained())
2703      {
2704        // by reference and therefore RESTRICTED: add them
2705
if (assocs[i].detailsExist()) return assocs[i].getDetailExtent();
2706      }
2707      else
2708      {
2709        // There are details. Check them too, because they themselves can
2710
// have restricting details
2711
if (assocs[i].getRelation().getDetailExtent().getDetailRelations().length != 0)
2712        {
2713          // If the details do not have details they can be safely deleted, so
2714
// we can skip the following
2715
// But if we get here they might have details so they need to be
2716
// loaded and checked too:
2717
DjList details = assocs[i].getObjects();
2718          for (int d = 0; d < details.size(); d++)
2719          {
2720            DjObject detail = details.getDjenericObjectAt(d);
2721            DjExtent x = detail.restrictingObjectsExist(hitlist);
2722            if (x != null) return x;
2723          }
2724        }
2725      }
2726    }
2727    return null;
2728  }
2729
2730  /**
2731   * Description of the Method
2732   *
2733   * @exception CanNotDeleteException
2734   * Description of the Exception
2735   * @exception DjenericException
2736   * Description of the Exception
2737   */

2738  protected void throwIfDeleteRestricted() throws DjenericException, CanNotDeleteException
2739  {
2740    DjExtent inExtent = restrictingObjectsExist();
2741
2742    if (inExtent != null)
2743    {
2744      throw new CanNotDeleteException(Messages.getString("DjObject.CanNotDelete", inExtent.getNameSingular(),
2745                                                         getExtent().getNameSingular()), this, inExtent);
2746    }
2747  }
2748
2749  /**
2750   * Gets the new attribute of the DjObject object
2751   *
2752   * @return The new value
2753   */

2754  public boolean isNew()
2755  {
2756    return !_isPersisted && !isMarkedForDelete();
2757  }
2758
2759  /**
2760   * Returns the persisted of the DjObject object
2761   *
2762   * @return The persisted value
2763   */

2764  public boolean isPersisted()
2765  {
2766    return _isPersisted;
2767  }
2768
2769  /**
2770   * Returns the empty of the DjObject object
2771   *
2772   * @return The empty value
2773   */

2774  public boolean isEmpty()
2775  {
2776    return isNew() && !isModified();
2777  }
2778
2779  /**
2780   * Description of the Method
2781   *
2782   * @return Description of the Return Value
2783   */

2784  protected boolean hasDetailsLoaded()
2785  {
2786    if (_detailAssociations == null)
2787    {
2788      return false;
2789    }
2790    for (int i = 0; i < _detailAssociations.length; i++)
2791    {
2792      if (_detailAssociations[i].isDetailsLoaded())
2793      {
2794        return true;
2795      }
2796    }
2797    return false;
2798  }
2799
2800  /**
2801   * Description of the Method
2802   *
2803   * @exception CanNotDeleteException
2804   * Description of the Exception
2805   * @exception DjenericException
2806   * Description of the Exception
2807   */

2808  public void markForDelete() throws DjenericException, CanNotDeleteException
2809  {
2810    markForDelete(new HashMap JavaDoc());
2811  }
2812
2813  public void markForDelete(HashMap JavaDoc hitlist) throws DjenericException, CanNotDeleteException
2814  {
2815    if (hitlist.containsKey(this)) return;
2816    hitlist.put(this, this);
2817
2818    if (_isMarkedForDelete) return;
2819
2820    if (getSession().getPersistenceManager().isCheckReferentialIntegrity())
2821    {
2822      // First check for any details i.e. restricted deletes
2823
throwIfDeleteRestricted();
2824
2825      DjAssociation[] assocs = getDetailAssociations();
2826      for (int i = 0; i < assocs.length; i++)
2827      {
2828        if (assocs[i].isDetailsContained())
2829        {
2830          // by value and therefore should be deleted
2831
DjList details = assocs[i].getObjects();
2832          for (int d = 0; d < details.size(); d++)
2833          {
2834            DjObject detail = details.getDjenericObjectAt(d);
2835            detail.markForDelete(hitlist);
2836          }
2837        }
2838      }
2839    }
2840    _isMarkedForDelete = true;
2841    if (shouldTrace(DjPersistenceManager.TRACE_FLOW)) trace("Marked for delete: " + getExtent().getObjectType()
2842                                                            + "(id=" + getObjectId() + ") " + toString());
2843    setModified(true);
2844  }
2845
2846  /**
2847   * Description of the Method
2848   *
2849   * @exception DjenericException
2850   * Description of the Exception
2851   */

2852  protected void determineObjectIdIfNeeded() throws DjenericException
2853  {
2854    String JavaDoc ipn = getIdPropertyName();
2855
2856    if (isNull(ipn))
2857    {
2858      if (isTransient()) setLong(ipn, getSession().getNextTransientObjectId());
2859      else setLong(ipn, getSession().getPersistenceManager().getNextObjectId());
2860    }
2861  }
2862
2863  /**
2864   * Description of the Method
2865   *
2866   * @exception DjenericException
2867   * Description of the Exception
2868   */

2869
2870  private void applyBottomUp() throws DjenericException
2871  {
2872    applyBottomUp(new HashMap JavaDoc());
2873  }
2874
2875  private void applyBottomUp(HashMap JavaDoc hitlist) throws DjenericException
2876  {
2877    if (hitlist.containsKey(this)) return;
2878    hitlist.put(this, this);
2879
2880    determineObjectIdIfNeeded();
2881    if (_detailAssociations != null)
2882    {
2883      // there are details; process their deletes bottom up, the rest top down
2884
for (int i = 0; i < _detailAssociations.length; i++)
2885      {
2886        if (_detailAssociations[i].isDetailsLoaded())
2887        {
2888          DjList details = _detailAssociations[i].getObjects();
2889          for (int d = 0; d < details.size(); d++)
2890          {
2891            DjObject detail = details.getDjenericObjectAt(d);
2892            detail.applyBottomUp(hitlist);
2893          }
2894        }
2895      }
2896    }
2897
2898    if (!isHitDuringCurrentTransaction() && _isPersisted && isMarkedForDelete())
2899    {
2900      delete();
2901      setHitDuringCurrentTransaction(true);
2902    }
2903  }
2904
2905  /**
2906   * Description of the Method
2907   *
2908   * @exception DjenericException
2909   * Description of the Exception
2910   */

2911  protected void updateDetailFlags() throws DjenericException
2912  {
2913    updateDetailFlags(new HashMap JavaDoc());
2914  }
2915
2916  protected void updateDetailFlags(HashMap JavaDoc hitlist) throws DjenericException
2917  {
2918    if (hitlist.containsKey(this)) return;
2919    hitlist.put(this, this);
2920
2921    if (_detailAssociations != null)
2922    {
2923      for (int i = 0; i < _detailAssociations.length; i++)
2924      {
2925        if (_detailAssociations[i].isDetailsLoaded())
2926        {
2927          DjList details = _detailAssociations[i].getObjects();
2928          for (int d = 0; d < details.size(); d++)
2929          {
2930            DjObject detail = details.getDjenericObjectAt(d);
2931            detail.setIsDetail(true);
2932            detail.updateDetailFlags(hitlist);
2933            if (shouldTrace(DjPersistenceManager.TRACE_FLOW)) trace("Marked as a detail: "
2934                                                                    + detail.getExtent().getObjectType() + "(id="
2935                                                                    + detail.getObjectId() + ") " + detail.toString());
2936          }
2937        }
2938      }
2939    }
2940  }
2941
2942  /**
2943   * Description of the Method
2944   *
2945   * @exception DjenericException
2946   * Description of the Exception
2947   */

2948  protected void updateDetailOfnewMasterFlags() throws DjenericException
2949  {
2950    updateDetailOfnewMasterFlags(new HashMap JavaDoc());
2951  }
2952
2953  protected void updateDetailOfnewMasterFlags(HashMap JavaDoc hitlist) throws DjenericException
2954  {
2955    if (hitlist.containsKey(this)) return;
2956    hitlist.put(this, this);
2957
2958    if (!isNew() || isHitDuringCurrentTransaction()) return;
2959
2960    if (_detailAssociations != null)
2961    {
2962      for (int i = 0; i < _detailAssociations.length; i++)
2963      {
2964        if (_detailAssociations[i].isDetailsLoaded())
2965        {
2966          DjList details = _detailAssociations[i].getObjects();
2967          for (int d = 0; d < details.size(); d++)
2968          {
2969            DjObject detail = details.getDjenericObjectAt(d);
2970            detail.setDetailOfNewMaster(true);
2971            detail.updateDetailOfnewMasterFlags(hitlist);
2972            if (shouldTrace(DjPersistenceManager.TRACE_FLOW)) trace("Marked as a detail of a new Object: "
2973                                                                    + detail.getExtent().getObjectType() + "(id="
2974                                                                    + detail.getObjectId() + ") " + detail.toString());
2975          }
2976        }
2977      }
2978    }
2979  }
2980
2981  /**
2982   * Description of the Method
2983   *
2984   * @exception DjenericException
2985   * Description of the Exception
2986   */

2987  public void updateDetailObjectLinks() throws DjenericException
2988  {
2989    updateDetailObjectLinks(new HashMap JavaDoc());
2990  }
2991
2992  protected void updateDetailObjectLinks(HashMap JavaDoc hitlist) throws DjenericException
2993  {
2994    if (hitlist.containsKey(this)) return;
2995    hitlist.put(this, this);
2996
2997    determineObjectIdIfNeeded();
2998    if (_detailAssociations != null)
2999    {
3000      // there are details; make sure their links to 'this' are set
3001
for (int i = 0; i < _detailAssociations.length; i++)
3002      {
3003        if (_detailAssociations[i].isDetailsLoaded())
3004        {
3005          DjList details = _detailAssociations[i].getObjects();
3006          for (int d = 0; d < details.size(); d++)
3007          {
3008            DjObject detail = details.getDjenericObjectAt(d);
3009            // Make sure the link to the master is set correctly; but only do
3010
// this
3011
// for new / updated objects to avoid unnecessary updates
3012
if (detail.isModified() || detail.isNew())
3013            {
3014              DjRelation rel = _detailAssociations[i].getRelation();
3015              // Now set the foreign key column (in the detail) to this parent:
3016
detail.setLong(rel.getDetailProperty().getName(), getObjectId());
3017              // "this" has an id by now cause it's already inserted
3018
}
3019            detail.updateDetailObjectLinks(hitlist);
3020          }
3021        }
3022      }
3023    }
3024  }
3025
3026  /**
3027   * Description of the Method
3028   *
3029   * @exception DjenericException
3030   * Description of the Exception
3031   */

3032  private void applyTopDown() throws DjenericException
3033  {
3034    applyTopDown(new HashMap JavaDoc());
3035  }
3036
3037  private void applyTopDown(HashMap JavaDoc hitlist) throws DjenericException
3038  {
3039
3040    if (hitlist.containsKey(this)) return;
3041    hitlist.put(this, this);
3042
3043    determineObjectIdIfNeeded();
3044
3045    if (isModified() && !isMarkedForDelete())
3046    {
3047      if (_isPersisted)
3048      {
3049        if (!isHitDuringCurrentTransaction())
3050        {
3051          update();
3052          setHitDuringCurrentTransaction(true);
3053        }
3054      }
3055      else
3056      {
3057        if (!isHitDuringCurrentTransaction())
3058        {
3059          insert();
3060          setHitDuringCurrentTransaction(true);
3061        }
3062      }
3063    }
3064    if (_detailAssociations != null)
3065    {
3066      // there are details; process their ins/upd top down
3067
for (int i = 0; i < _detailAssociations.length; i++)
3068      {
3069        if (_detailAssociations[i].isDetailsLoaded())
3070        {
3071          DjList details = _detailAssociations[i].getObjects();
3072          for (int d = 0; d < details.size(); d++)
3073          {
3074            DjObject detail = details.getDjenericObjectAt(d);
3075            // Make sure the link to the master is set correctly; but only do
3076
// this for new / updated objects to avoid unnecessary updates
3077
if (detail.isModified() || detail.isNew())
3078            {
3079              DjRelation rel = _detailAssociations[i].getRelation();
3080              // Now set the foreign key column (in the detail) to this parent:
3081
// "this" has an id by now cause it's already inserted
3082
detail.setLong(rel.getDetailProperty().getName(), getObjectId());
3083            }
3084            detail.applyTopDown(hitlist);
3085          }
3086        }
3087      }
3088    }
3089  }
3090
3091  // This is delegated so the extent is able to cache the statement for a
3092
// particular object type.
3093
// Within this object we can only be generic
3094
/**
3095   * Description of the Method
3096   *
3097   * @exception DjenericException
3098   * Description of the Exception
3099   */

3100  protected void applyDeletes() throws DjenericException
3101  {
3102    // Do not apply transient or 'empty' objects
3103
if (isTransient() || (isEmpty() && !hasDetailsLoaded()))
3104    {
3105      return;
3106    }
3107
3108    applyBottomUp();
3109  }
3110
3111  // This is delegated so the extent is able to cache the statement for a
3112
// particular object type.
3113
// Within this object we can only be generic
3114
/**
3115   * Description of the Method
3116   *
3117   * @exception DjenericException
3118   * Description of the Exception
3119   */

3120  protected void applyUpdates() throws DjenericException
3121  {
3122    // Do not apply transient or 'empty' objects
3123
if (isTransient() || (isEmpty() && !hasDetailsLoaded()))
3124    {
3125      return;
3126    }
3127
3128    applyTopDown();
3129  }
3130
3131  /**
3132   * Notify the object that a new transaction is about to start
3133   */

3134  protected void notifyStartTransaction()
3135  {
3136    setHitDuringCurrentTransaction(false);
3137  }
3138
3139  /**
3140   * Call this if this object is persisted and committed ok.
3141   *
3142   * @exception DjenericException
3143   * Description of the Exception
3144   */

3145  protected void notifyApplySuccesfull() throws DjenericException
3146  {
3147    notifyApplySuccesfull(new HashMap JavaDoc());
3148  }
3149
3150  protected void notifyApplySuccesfull(HashMap JavaDoc hitlist) throws DjenericException
3151  {
3152    if (hitlist.containsKey(this)) return;
3153    hitlist.put(this, this);
3154
3155    if (isMarkedForDelete())
3156    {
3157      // Object is gone now. Make sure it is also removed from the cache..
3158
_session.unregisterDjenericObject(this);
3159      _isPersisted = false;
3160      // make sure this object does not participate in transactions anymore;
3161
// make it transient
3162
setTransient(true);
3163    }
3164    else
3165    {
3166      _isPersisted = true;
3167    }
3168    // ins/upd done = persisted
3169
setModified(false);
3170    // reset the flag set by the setters
3171
_isMarkedForDelete = false;
3172
3173    // a shallow copy is sufficient here since peoprties are replaced and not
3174
// manipulated
3175
_originalPropertyValues = (Object JavaDoc[]) _propertyValues.clone();
3176
3177    if (_detailAssociations != null)
3178    {
3179      // there are details; process their ins/upd top down
3180
for (int i = 0; i < _detailAssociations.length; i++)
3181      {
3182        if (_detailAssociations[i].isDetailsLoaded())
3183        {
3184          DjList details = _detailAssociations[i].getObjects();
3185          for (int d = 0; d < details.size(); d++)
3186          {
3187            DjObject detail = details.getDjenericObjectAt(d);
3188            detail.notifyApplySuccesfull(hitlist);
3189          }
3190        }
3191      }
3192    }
3193  }
3194
3195  /**
3196   * Description of the Method
3197   *
3198   * @param dateString
3199   * Description of the Parameter
3200   * @param mask
3201   * Description of the Parameter
3202   * @return Description of the Return Value
3203   * @exception ParseException
3204   * Description of the Exception
3205   */

3206  protected Date JavaDoc convertString2Date(String JavaDoc dateString, String JavaDoc mask) throws ParseException JavaDoc
3207  {
3208    if (mask == null) return sf.parse(dateString);
3209
3210    SimpleDateFormat JavaDoc m = new SimpleDateFormat JavaDoc(mask);
3211    return m.parse(dateString);
3212  }
3213
3214  /**
3215   * Description of the Method
3216   *
3217   * @param date
3218   * Description of the Parameter
3219   * @param mask
3220   * Description of the Parameter
3221   * @return Description of the Return Value
3222   */

3223  protected String JavaDoc convertDate2String(Date JavaDoc date, String JavaDoc mask)
3224  {
3225    if (mask == null) return sf.format(date);
3226
3227    SimpleDateFormat JavaDoc m = new SimpleDateFormat JavaDoc(mask);
3228    return m.format(date);
3229  }
3230
3231  // Implement DjValueObject
3232
// An object always exists
3233
public boolean exists()
3234  {
3235    return true;
3236  }
3237
3238  public void setDetailOfNewMaster(boolean b)
3239  {
3240    _isDetailOfNewMaster = b;
3241
3242  }
3243
3244  public boolean isDetailOfNewMaster()
3245  {
3246    return _isDetailOfNewMaster;
3247  }
3248
3249  protected boolean isTemporary()
3250  {
3251    return _isTemporary;
3252  }
3253
3254  protected void setTemporary(boolean isTemporary)
3255  {
3256    _isTemporary = isTemporary;
3257  }
3258
3259  public DjUid getUID() throws DjenericException
3260  {
3261    DjUid uid = new DjUid(getExtent());
3262
3263    for (int i = 0; i < getPropertyCount(); i++)
3264    {
3265      DjProperty prop = getProperty(i);
3266      if (prop.isPartOfUID())
3267      {
3268        if (prop.getType() instanceof DjDomain)
3269        {
3270          String JavaDoc value = getString(prop.getName());
3271          if (value != null) uid.setProperty(prop.getName(), value);
3272        }
3273        else
3274        {
3275          DjObject master = (DjObject) get(prop.getName());
3276          if (master != null) uid.setProperty(prop.getName(), master.getUID());
3277        }
3278      }
3279    }
3280    uid.setAssociatedObjectid(getObjectId());
3281    uid.setDescriptor(toString());
3282    return uid;
3283  }
3284}
Popular Tags