KickJava   Java API By Example, From Geeks To Geeks.

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


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

30 package com.genimen.djeneric.repository;
31
32 import java.io.ByteArrayInputStream JavaDoc;
33 import java.io.ByteArrayOutputStream JavaDoc;
34 import java.io.InputStream JavaDoc;
35 import java.io.UnsupportedEncodingException JavaDoc;
36 import java.security.MessageDigest JavaDoc;
37 import java.security.NoSuchAlgorithmException JavaDoc;
38 import java.text.SimpleDateFormat JavaDoc;
39 import java.util.ArrayList JavaDoc;
40 import java.util.Arrays JavaDoc;
41 import java.util.Collections JavaDoc;
42 import java.util.Date JavaDoc;
43 import java.util.HashMap JavaDoc;
44 import java.util.Iterator JavaDoc;
45
46 import javax.xml.parsers.DocumentBuilder JavaDoc;
47 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
48 import javax.xml.transform.OutputKeys JavaDoc;
49 import javax.xml.transform.Transformer JavaDoc;
50 import javax.xml.transform.TransformerException JavaDoc;
51 import javax.xml.transform.TransformerFactory JavaDoc;
52 import javax.xml.transform.dom.DOMSource JavaDoc;
53 import javax.xml.transform.stream.StreamResult JavaDoc;
54
55 import org.apache.xpath.XPathAPI;
56 import org.w3c.dom.CDATASection JavaDoc;
57 import org.w3c.dom.Document JavaDoc;
58 import org.w3c.dom.Element JavaDoc;
59 import org.w3c.dom.NodeList JavaDoc;
60 import org.w3c.dom.traversal.NodeIterator;
61
62 import com.genimen.djeneric.language.Messages;
63 import com.genimen.djeneric.repository.exceptions.CatalogException;
64 import com.genimen.djeneric.repository.exceptions.DjenericException;
65 import com.genimen.djeneric.repository.exceptions.LogonException;
66 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException;
67 import com.genimen.djeneric.util.DjExtentComparator;
68 import com.genimen.djeneric.util.DjLogger;
69 import com.genimen.djeneric.util.DjProgressDisplayer;
70 import com.genimen.djeneric.util.DjStringComparator;
71 import com.genimen.djeneric.util.DjVersion;
72
73 /**
74  * @author Wido Riezebos @created 25 november 2001
75  */

76 public abstract class DjPersistenceManager implements DjMessenger
77 {
78
79   /////////////////////////////////////////////////////////////////////
80

81   public static final String JavaDoc EMPTY_MODEL_XML_DOC = "<schema></schema>";
82   private static final String JavaDoc ORG_DJENERIC_DOMAINS = "org.djeneric.domains";
83   /**
84    * Encoding method for converting bytes
85    */

86   public final static String JavaDoc ENCODING_METHOD = "Cp1252";
87   public final static String JavaDoc LINE_SEPARATOR = System.getProperty("line.separator", "\n");
88
89   public final static String JavaDoc MAPPING_OBJECT_ID = "object_id";
90   public final static String JavaDoc MAPPING_STR = "str";
91   public final static String JavaDoc MAPPING_NUM = "num";
92   public final static String JavaDoc MAPPING_REL = "rel";
93   public final static String JavaDoc MAPPING_TXT = "txt";
94   public final static String JavaDoc MAPPING_LNG = "lng";
95   public final static String JavaDoc MAPPING_DAT = "dat";
96
97   public final static int MAPPING_COLUMN_COUNT_STR = 30;
98   public final static int MAPPING_COLUMN_COUNT_NUM = 30;
99   public final static int MAPPING_COLUMN_COUNT_REL = 20;
100   public final static int MAPPING_COLUMN_COUNT_TXT = 20;
101   public final static int MAPPING_COLUMN_COUNT_DAT = 20;
102   public final static int MAPPING_COLUMN_COUNT_LNG = 1;
103
104   public final static int MAPPING_ID_COLUMN_SIZE = 15;
105   public final static String JavaDoc INTERNAL_ID_COLUMN_TYPE = "long";
106   public final static int MAPPING_STR_MAX = 250;
107   public final static int MAPPING_NUM_MAX = 15;
108   public final static int MAPPING_TXT_MAX = 4000;
109   public final static int MAPPING_LNG_MAX = 99999999;
110
111   public final static int MAX_INTERNAL_CODE_LENGTH = 10;
112
113   public final static String JavaDoc SCHEMA = "schema";
114   public final static String JavaDoc SCHEMA_HISTORY = "history";
115   public final static String JavaDoc SCHEMA_VERSION = "version";
116   public final static String JavaDoc SCHEMA_STRUCTURE_VERSION = "structureversion";
117   public final static int SCHEMA_STRUCTURE_VERSION_NUMBER = 102;
118
119   public final static String JavaDoc EXTENT_ELEMENT = "extent";
120   public final static String JavaDoc EXTENT_OBJECT_TYPE = "objecttype";
121   public final static String JavaDoc EXTENT_NAME = "name";
122   public final static String JavaDoc EXTENT_SUPER = "super";
123   public final static String JavaDoc EXTENT_ALIAS = "alias";
124   public final static String JavaDoc EXTENT_TITLE = "title";
125   public final static String JavaDoc EXTENT_DESCRIPTOR = "descriptor";
126   public final static String JavaDoc EXTENT_NAME_SINGULAR = "namesingular";
127   public final static String JavaDoc EXTENT_NAME_PLURAL = "nameplural";
128   public final static String JavaDoc EXTENT_LARGE = "large";
129   public final static String JavaDoc EXTENT_TRANSIENT = "transient";
130   public final static String JavaDoc EXTENT_PACKAGE = "package";
131
132   public final static String JavaDoc DESCRIPTION_ELEMENT = "description";
133
134   public final static String JavaDoc PROPERTY_ELEMENT = "property";
135   public final static String JavaDoc PROPERTY_NAME = "name";
136   public final static String JavaDoc PROPERTY_ALIAS = "alias";
137   public final static String JavaDoc PROPERTY_PROMPT = "prompt";
138   public final static String JavaDoc PROPERTY_MAPPING = "mapping";
139   public final static String JavaDoc PROPERTY_TYPE = "type";
140   public final static String JavaDoc PROPERTY_REQUIRED = "required";
141   public final static String JavaDoc PROPERTY_SEQ = "seq";
142   public final static String JavaDoc PROPERTY_SORT_ORDER = "sortorder";
143   public final static String JavaDoc PROPERTY_QUERYABLE = "queryable";
144   public final static String JavaDoc PROPERTY_PART_OF_UID = "partofuid";
145   public final static String JavaDoc PROPERTY_DESCRIPTION = "description";
146   public final static String JavaDoc PROPERTY_DEFAULT_VALUE = "default";
147
148   public final static String JavaDoc RELATION_ELEMENT = "relation";
149   public final static String JavaDoc RELATION_NAME = "name";
150   public final static String JavaDoc RELATION_RESTRICTION = "restriction";
151   public final static String JavaDoc RELATION_DESCRIPTION = "description";
152   public final static String JavaDoc RELATION_MASTEREXTENT = "masterextent";
153   public final static String JavaDoc RELATION_DETAILPROPERTY = "detailproperty";
154   public final static String JavaDoc RELATION_TYPE = "type";
155   public final static String JavaDoc RELATION_UNICITY = "unicity";
156   public final static String JavaDoc RELATION_TYPE_CONTAINS = "contains";
157   public final static String JavaDoc RELATION_TYPE_REFERENCES = "references";
158
159   public final static String JavaDoc DOMAIN_ELEMENT = "domain";
160   public final static String JavaDoc DOMAIN_NAME = "name";
161   public final static String JavaDoc DOMAIN_PACKAGE = "package";
162   public final static String JavaDoc DOMAIN_SUPER = "super";
163   public final static String JavaDoc DOMAIN_LENGTH = "length";
164   public final static String JavaDoc DOMAIN_DECIMALS = "decimals";
165   public final static String JavaDoc DOMAIN_CASE_CONVERSION = "caseconversion";
166   public final static String JavaDoc DOMAIN_DESCRIPTION = "description";
167   public final static String JavaDoc DOMAIN_TYPE = "type";
168   public final static String JavaDoc DOMAIN_COMPONENT = "component";
169   public final static String JavaDoc DOMAIN_ENFORCE = "enforce";
170   public final static String JavaDoc DOMAIN_DISPLAY_WIDTH = "displaywidth";
171   public final static String JavaDoc DOMAIN_DISPLAY_HEIGHT = "displayheight";
172   public final static String JavaDoc DOMAIN_VALUE_ELEMENT = "domainvalue";
173   public final static String JavaDoc DOMAIN_VALUE_SEQ = "seq";
174   public final static String JavaDoc DOMAIN_VALUE_VALUE = "value";
175   public final static String JavaDoc DOMAIN_VALUE_HIGH = "high";
176   public final static String JavaDoc DOMAIN_FORMAT_MASK = "format";
177   public final static String JavaDoc DOMAIN_RE_MASK = "remask";
178   public final static String JavaDoc DOMAIN_RE_FAIL_MSG = "refailmsg";
179   public final static String JavaDoc DOMAIN_VALUE_DESCRIPTION = "description";
180
181   public final static String JavaDoc PACKAGE_ELEMENT = "package";
182   public final static String JavaDoc PACKAGE_NAME = "name";
183
184   public final static String JavaDoc ROLE_ELEMENT = "role";
185   public final static String JavaDoc ROLE_NAME = "name";
186
187   public final static int TRACE_NOTHING = 0;
188   public final static int TRACE_FLOW = 5;
189   public final static int TRACE_INTERNAL = 10;
190   public final static int TRACE_ALL = 100;
191
192   private DjIdProvider _idProvider = null;
193   private boolean _commitAllowed = true;
194   private boolean _useGlobalContext = false;
195   private boolean _checkReferentialIntegrity = true;
196   private String JavaDoc _originalModel = null;
197   private int _traceLevel = TRACE_NOTHING;
198   private int _schemaStructureVersion = 101;
199
200   DjMessenger _messenger;
201   HashMap JavaDoc _extentsByName;
202   HashMap JavaDoc _extentsByInternalCode;
203   HashMap JavaDoc _extentsByObjectType;
204   HashMap JavaDoc _extentsByQualifiedObjectType;
205   HashMap JavaDoc _extentsUnQualifiedClashed;
206   ArrayList JavaDoc _allExtents;
207   ArrayList JavaDoc _allRoles;
208
209   HashMap JavaDoc _domainsByName;
210   ArrayList JavaDoc _allDomains;
211   HashMap JavaDoc _packagesByName = new HashMap JavaDoc();
212   ArrayList JavaDoc _allPackages;
213
214   String JavaDoc _djenericUser = null;
215   String JavaDoc _djenericPassword = null;
216
217   String JavaDoc _repositoryUser = null;
218   String JavaDoc _repositoryPassword = null;
219
220   DjContextManager _contextManager = null;
221   DjRepositoryDescriptor _currentRepository;
222   String JavaDoc _modelLoadLog = "";
223   String JavaDoc _modelHistory = "";
224   int _modelVersion = 0;
225   SimpleDateFormat JavaDoc _traceTimestampFormatter = new SimpleDateFormat JavaDoc("yyyy.MM.dd HH:mm:ss");
226   private static boolean _bannerDisplayed = false;
227
228   static long _internalId = 0;
229
230   /////////////////////////////////////////////////////////////////////
231
/**
232    * Description of the Method
233    *
234    * @return Description of the Return Value
235    * @exception DjenericException
236    * Description of the Exception
237    */

238   protected abstract String JavaDoc retrieveModelXml() throws DjenericException;
239
240   /**
241    * Description of the Method
242    *
243    * @param xml
244    * Description of the Parameter
245    * @exception DjenericException
246    * Description of the Exception
247    */

248   protected abstract void storeModelXml(String JavaDoc xml) throws DjenericException;
249
250   /**
251    * Gets the views of the DjPersistenceManager object
252    *
253    * @return The views value
254    * @exception DjenericException
255    * Description of the Exception
256    */

257   public abstract DjModelView[] getViews() throws DjenericException;
258
259   /**
260    * Description of the Method
261    */

262   public abstract void close();
263
264   /**
265    * Description of the Method
266    *
267    * @return Description of the Return Value
268    * @exception DjenericException
269    * Description of the Exception
270    */

271   public abstract DjSession createSession() throws DjenericException;
272
273   /**
274    * Description of the Method
275    *
276    * @param mgr
277    * Description of the Parameter
278    * @return Description of the Return Value
279    */

280   public abstract DjContextManager createContextManager(DjPersistenceManager mgr);
281
282   /**
283    * Description of the Method
284    *
285    * @param objectType
286    * Description of the Parameter
287    * @param name
288    * Description of the Parameter
289    * @param alias
290    * Description of the Parameter
291    * @param internalCode
292    * Description of the Parameter
293    * @param title
294    * Description of the Parameter
295    * @param nameSingular
296    * Description of the Parameter
297    * @param namePlural
298    * Description of the Parameter
299    * @return Description of the Return Value
300    */

301   public abstract DjExtent createExtent(String JavaDoc objectType, String JavaDoc name, String JavaDoc alias, String JavaDoc internalCode,
302                                         String JavaDoc title, String JavaDoc nameSingular, String JavaDoc namePlural);
303
304   /**
305    * Description of the Method
306    *
307    * @return Description of the Return Value
308    */

309   public abstract DjIdProvider createIdProvider();
310
311   /**
312    * Description of the Method
313    *
314    * @param name
315    * Description of the Parameter
316    * @param masterExtent
317    * Description of the Parameter
318    * @param detailExtent
319    * Description of the Parameter
320    * @param detailProperty
321    * Description of the Parameter
322    * @param isContainedRelation
323    * Description of the Parameter
324    * @param description
325    * Description of the Parameter
326    * @return Description of the Return Value
327    */

328   public abstract DjRelation createRelation(String JavaDoc name, DjExtent masterExtent, DjExtent detailExtent,
329                                             DjProperty detailProperty, boolean isContainedRelation, String JavaDoc description);
330
331   /**
332    * Description of the Method
333    *
334    * @return Description of the Return Value
335    * @exception DjenericException
336    * Description of the Exception
337    */

338   public abstract DjModelView createModelView() throws DjenericException;
339
340   /**
341    * Description of the Method
342    *
343    * @exception CatalogException
344    * Description of the Exception
345    */

346   public abstract void lockModel() throws CatalogException;
347
348   /**
349    * Description of the Method
350    *
351    * @exception CatalogException
352    * Description of the Exception
353    */

354   public abstract void unlockModel() throws CatalogException;
355
356   /**
357    * Description of the Method
358    *
359    * @exception CatalogException
360    * Description of the Exception
361    */

362   public abstract void forceUnlockModel() throws CatalogException;
363
364   /**
365    * Gets the modelLocked of the DjPersistenceManager object
366    *
367    * @return The modelLocked value
368    */

369   public abstract boolean isModelLocked();
370
371   /**
372    * Gets the currentLockTag of the DjPersistenceManager object
373    *
374    * @return The currentLockTag value
375    * @exception CatalogException
376    * Description of the Exception
377    */

378   public abstract String JavaDoc getCurrentLockTag() throws CatalogException;
379
380   /**
381    * Sets the estimatedConcurrentSessions of the DjPersistenceManager object
382    *
383    * @param estimate
384    * The new estimatedConcurrentSessions value
385    */

386   public abstract void setEstimatedConcurrentSessions(int estimate);
387
388   /**
389    * Constructor for the DjPersistenceManager object
390    *
391    * @param mainFrame
392    * Description of the Parameter
393    * @param rdesc
394    * Description of the Parameter
395    * @exception DjenericException
396    * Description of the Exception
397    */

398   public DjPersistenceManager(DjMessenger messenger, DjRepositoryDescriptor rdesc)
399
400   {
401     // Display the banner only once..
402
if (!_bannerDisplayed) DjLogger.log("Running on Djeneric Persistence Manager version " + DjVersion.getVersion());
403     _bannerDisplayed = true;
404     setTraceLevel(rdesc.getTraceLevel());
405
406     if (rdesc.getTraceLevel() != TRACE_NOTHING)
407     {
408       DjLogger.log(Messages.getString("DjPersistenceManager.TraceLevel", String.valueOf(rdesc.getTraceLevel())));
409     }
410
411     if (messenger == null) _messenger = this;
412     else _messenger = messenger;
413
414     _idProvider = createIdProvider();
415     _currentRepository = rdesc;
416     _contextManager = createContextManager(this);
417
418     // All traffic through one uid/pw separate from Djeneric users?
419
if (rdesc.isSharedConnection())
420     {
421       _repositoryUser = rdesc.getSharedUser();
422       _repositoryPassword = rdesc.getSharedPassword();
423
424       // still need to ask for identity of user:
425
_djenericUser = null;
426       _djenericPassword = null;
427     }
428     else
429     {
430       _repositoryUser = rdesc.getUser();
431       // might be null
432
_repositoryPassword = rdesc.getPassword();
433       // might be null
434

435       _djenericUser = rdesc.getUser();
436       // might be null
437
_djenericPassword = rdesc.getPassword();
438       // might be null
439
}
440   }
441
442   /**
443    * Description of the Method
444    *
445    * @exception DjenericException
446    * Description of the Exception
447    */

448   public void loadModel() throws DjenericException
449   {
450     String JavaDoc src = retrieveModelXml();
451     if (src.trim().length() == 0)
452     {
453       src = EMPTY_MODEL_XML_DOC;
454     }
455
456     setOriginalModel(src);
457     rebuildModelDefinition(src);
458   }
459
460   public boolean isModelUpdatedExternally() throws DjenericException
461   {
462     String JavaDoc orgModel = getOriginalModel();
463     if (orgModel == null) orgModel = "";
464
465     String JavaDoc src = retrieveModelXml();
466     if (src == null) src = "";
467
468     return !src.equals(orgModel);
469   }
470
471   public boolean isModelModified() throws DjenericException
472   {
473     String JavaDoc orgModel = getOriginalModel();
474     if (orgModel == null) orgModel = "";
475
476     String JavaDoc src = getModel();
477     if (src == null) src = "";
478
479     return !src.equals(orgModel);
480   }
481
482   /**
483    * Sets the originalModel of the DjPersistenceManager object
484    *
485    * @param orgModel
486    * The new originalModel value
487    */

488   protected void setOriginalModel(String JavaDoc orgModel)
489   {
490     _originalModel = orgModel;
491   }
492
493   /**
494    * Gets the originalModel of the DjPersistenceManager object
495    *
496    * @return The originalModel value
497    */

498   protected String JavaDoc getOriginalModel()
499   {
500     return _originalModel;
501   }
502
503   /**
504    * Gets the modelVersion of the DjPersistenceManager object
505    *
506    * @return The modelVersion value
507    */

508   public int getModelVersion()
509   {
510     return _modelVersion;
511   }
512
513   /**
514    * Sets the modelVersion of the DjPersistenceManager object
515    *
516    * @param version
517    * The new modelVersion value
518    */

519   public void setModelVersion(int version)
520   {
521     _modelVersion = version;
522   }
523
524   /**
525    * Gets the modelHistory of the DjPersistenceManager object
526    *
527    * @return The modelHistory value
528    */

529   public String JavaDoc getModelHistory()
530   {
531     return _modelHistory;
532   }
533
534   /**
535    * Sets the modelHistory of the DjPersistenceManager object
536    *
537    * @param history
538    * The new modelHistory value
539    */

540   public void setModelHistory(String JavaDoc history)
541   {
542     _modelHistory = history;
543   }
544
545   /**
546    * Gets the schemaLoadLog of the DjPersistenceManager object
547    *
548    * @return The schemaLoadLog value
549    */

550   public String JavaDoc getSchemaLoadLog()
551   {
552     return _modelLoadLog.trim();
553   }
554
555   /**
556    * Description of the Method
557    *
558    * @exception DjenericException
559    * Description of the Exception
560    */

561   public void saveModel() throws DjenericException
562   {
563     validateModel(true);
564
565     // Check to see if the model was updated. If so we need to increase the
566
// version number and history
567
String JavaDoc model = getModel();
568     if (!getOriginalModel().equals(model))
569     {
570       setModelVersion(getModelVersion() + 1);
571
572       SimpleDateFormat JavaDoc sf = new SimpleDateFormat JavaDoc("dd-MM-yyyy HH:mm:ss");
573
574       Date JavaDoc date = new Date JavaDoc(System.currentTimeMillis());
575
576       String JavaDoc djuser = getDjenericUser();
577       if (djuser == null) djuser = getRepositoryUser();
578
579       setModelHistory(Messages.getString("DjPersistenceManager.VersionString", String.valueOf(getModelVersion()), sf
580           .format(date), djuser, getConnectionTitle())
581                       + "\n" + getModelHistory());
582       model = getModel();
583     }
584     storeModelXml(model);
585     setOriginalModel(model);
586   }
587
588   /**
589    * Sets the model of the DjPersistenceManager object
590    *
591    * @param modelXml
592    * The new model value
593    * @exception DjenericException
594    * Description of the Exception
595    */

596   public void setModel(String JavaDoc modelXml) throws DjenericException
597   {
598     rebuildModelDefinition(modelXml);
599   }
600
601   public void mergeModel(String JavaDoc modelXml, boolean overwriteExisting) throws DjenericException,
602       UnsupportedEncodingException JavaDoc
603   {
604     InputStream JavaDoc is = new ByteArrayInputStream JavaDoc(modelXml.getBytes(ENCODING_METHOD));
605     mergeModelDefinition(is, overwriteExisting);
606   }
607
608   /**
609    * Sets the model of the DjPersistenceManager object
610    *
611    * @param modelXml
612    * The new model value
613    * @exception DjenericException
614    * Description of the Exception
615    */

616   public void setModel(InputStream JavaDoc modelXml) throws DjenericException
617   {
618     rebuildModelDefinition(modelXml);
619   }
620
621   /**
622    * Sets the checkReferentialIntegrity of the DjPersistenceManager object
623    *
624    * @param b
625    * The new checkReferentialIntegrity value
626    */

627   public void setCheckReferentialIntegrity(boolean b)
628   {
629     _checkReferentialIntegrity = b;
630   }
631
632   /**
633    * Gets the checkReferentialIntegrity of the DjPersistenceManager object
634    *
635    * @return The checkReferentialIntegrity value
636    */

637   public boolean isCheckReferentialIntegrity()
638   {
639     return _checkReferentialIntegrity;
640   }
641
642   /**
643    * Sets the currentContext of the DjPersistenceManager object
644    *
645    * @param ctxt
646    * The new currentContext value
647    */

648   public void setCurrentContext(DjContext ctxt)
649   {
650     getContextManager().setCurrentContext(ctxt);
651   }
652
653   /**
654    * Sets the currentContext of the DjPersistenceManager object
655    *
656    * @param ctxt
657    * The new currentContext value
658    * @exception ObjectNotDefinedException
659    * Description of the Exception
660    * @exception DjenericException
661    * Description of the Exception
662    */

663   public void setCurrentContext(String JavaDoc ctxt) throws ObjectNotDefinedException, DjenericException
664   {
665     getContextManager().setCurrentContext(ctxt);
666   }
667
668   /**
669    * Gets the currentContext of the DjPersistenceManager object
670    *
671    * @return The currentContext value
672    */

673   public DjContext getCurrentContext()
674   {
675     return getContextManager().getCurrentContext();
676   }
677
678   private String JavaDoc nvl(String JavaDoc value)
679   {
680     if (value == null) return "";
681     return value;
682   }
683
684   public String JavaDoc getModel() throws DjenericException
685   {
686     DjExtent[] extents = getExtents();
687     DjDomain[] domains = getDomains();
688     return getModel(extents, domains);
689   }
690
691   public String JavaDoc getModel(DjExtent[] extents) throws DjenericException
692   {
693     DjDomain[] domains = getDomainsUsed(extents);
694     return getModel(extents, domains);
695   }
696
697   public DjDomain[] getDomainsUsed(DjExtent[] extents)
698   {
699     HashMap JavaDoc usedDomains = new HashMap JavaDoc();
700     for (int i = 0; i < extents.length; i++)
701     {
702       DjProperty[] props = extents[i].getPersonalProperties();
703       for (int p = 0; p < props.length; p++)
704       {
705         if (props[p].getType() instanceof DjDomain)
706         {
707           DjDomain dom = (DjDomain) props[p].getType();
708           while (dom != null)
709           {
710             usedDomains.put(dom.getName(), dom);
711             dom = dom.getSuperDomain();
712           }
713         }
714       }
715     }
716     DjDomain[] domains = new DjDomain[usedDomains.size()];
717     Iterator JavaDoc it = usedDomains.keySet().iterator();
718     int i = 0;
719     while (it.hasNext())
720       domains[i++] = (DjDomain) usedDomains.get(it.next());
721     return domains;
722   }
723
724   /**
725    * Gets the model of the DjPersistenceManager object
726    *
727    * @return The model value
728    * @exception DjenericException
729    * Description of the Exception
730    */

731   public String JavaDoc getModel(DjExtent[] extents, DjDomain[] domains) throws DjenericException
732   {
733     try
734     {
735       DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
736       DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
737       Document JavaDoc doc = builder.newDocument();
738
739       Element JavaDoc root = doc.createElement(SCHEMA);
740       root.setAttribute(SCHEMA_STRUCTURE_VERSION, String.valueOf(SCHEMA_STRUCTURE_VERSION_NUMBER));
741
742       doc.appendChild(root);
743
744       updateModelHistory(doc, root);
745
746       for (int i = 0; i < extents.length; i++)
747       {
748         Element JavaDoc extent = doc.createElement(EXTENT_ELEMENT);
749
750         extent.setAttribute(EXTENT_NAME, extents[i].getName());
751         if (extents[i].getSuper() != null) extent.setAttribute(EXTENT_SUPER, extents[i].getSuper().getName());
752         extent.setAttribute(EXTENT_ALIAS, extents[i].getInternalCode());
753         extent.setAttribute(EXTENT_OBJECT_TYPE, extents[i].getObjectType());
754         extent.setAttribute(EXTENT_DESCRIPTOR, extents[i].getPersonalDescriptorExpression());
755         extent.setAttribute(EXTENT_TITLE, extents[i].getTitle());
756         extent.setAttribute(EXTENT_NAME_SINGULAR, extents[i].getNameSingular());
757         extent.setAttribute(EXTENT_NAME_PLURAL, extents[i].getNamePlural());
758         extent.setAttribute(EXTENT_LARGE, String.valueOf(extents[i].isLarge()));
759         extent.setAttribute(EXTENT_TRANSIENT, String.valueOf(extents[i].isTransient()));
760
761         if ((extents[i].getDescription() != null) && (extents[i].getDescription().trim().length() > 0))
762         {
763           Element JavaDoc descrElem = doc.createElement(DESCRIPTION_ELEMENT);
764           CDATASection JavaDoc descr = doc.createCDATASection(extents[i].getDescription());
765           descrElem.appendChild(descr);
766           extent.appendChild(descrElem);
767         }
768
769         if (extents[i].getPackage() != null)
770         {
771           extent.setAttribute(EXTENT_PACKAGE, extents[i].getPackage().getName());
772         }
773
774         root.appendChild(extent);
775
776         DjProperty[] cols = extents[i].getPersonalProperties();
777         for (int c = 0; c < cols.length; c++)
778         {
779           Element JavaDoc property = doc.createElement(PROPERTY_ELEMENT);
780
781           property.setAttribute(PROPERTY_SEQ, "" + cols[c].getSeq());
782           property.setAttribute(PROPERTY_NAME, cols[c].getName());
783           property.setAttribute(PROPERTY_ALIAS, cols[c].getAlias());
784           property.setAttribute(PROPERTY_MAPPING, cols[c].getMapping());
785           property.setAttribute(PROPERTY_PROMPT, cols[c].getPrompt());
786           property.setAttribute(PROPERTY_TYPE, cols[c].getTypeName());
787           property.setAttribute(PROPERTY_REQUIRED, "" + cols[c].isRequired());
788           property.setAttribute(PROPERTY_QUERYABLE, "" + cols[c].isQueryable());
789           property.setAttribute(PROPERTY_PART_OF_UID, "" + cols[c].isPartOfUID());
790           property.setAttribute(PROPERTY_SORT_ORDER, "" + cols[c].getSortOrder());