KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.genimen.djeneric.language.Messages;
30 import com.genimen.djeneric.repository.exceptions.DjenericException;
31 import com.genimen.djeneric.structure.ExtentUsage;
32 import com.genimen.djeneric.structure.ResourceDefinition;
33 import com.genimen.djeneric.tools.io.DjenericDocumentHandler;
34
35 public abstract class DjModelView
36 {
37   final static long NOT_YET_PERSISTED = -1;
38   final static String JavaDoc UNTITLED = Messages.getString("DjModelView.Untitled");
39
40   /////////////////////////////////////////////////////////////////////
41
public abstract void delete(DjSession session) throws DjenericException;
42
43   public abstract void reload(DjSession session) throws DjenericException;
44
45   public abstract void persist(DjSession session) throws DjenericException;
46
47   public abstract void insert(DjSession session) throws DjenericException;
48
49   public abstract DjUser[] getUsers(DjSession session) throws DjenericException;
50
51   public abstract void removeUser(DjSession session, DjUser user) throws DjenericException;
52
53   public abstract boolean isModifiedExternally(DjSession session) throws DjenericException;
54
55   /////////////////////////////////////////////////////////////////////
56

57   long _id;
58   String JavaDoc _code = UNTITLED;
59   String JavaDoc _definition = "";
60   DjPersistenceManager _mgr;
61
62   protected DjModelView(DjPersistenceManager mgr)
63
64   {
65     _id = NOT_YET_PERSISTED;
66     _mgr = mgr;
67   }
68
69   protected DjModelView(DjPersistenceManager mgr, long id, String JavaDoc code, String JavaDoc definition)
70   {
71     _id = id;
72     _code = code;
73     _definition = definition;
74     _mgr = mgr;
75   }
76
77   public DjPersistenceManager getPersistenceManager()
78   {
79     return _mgr;
80   }
81
82   public boolean isUntitled()
83   {
84     return getCode() == null || getCode().equals(UNTITLED) || getCode().trim().length() == 0;
85   }
86
87   public long getId()
88   {
89     return _id;
90   }
91
92   protected void setId(long id)
93   {
94     _id = id;
95   }
96
97   public String JavaDoc getCode()
98   {
99     return _code;
100   }
101
102   public void setCode(String JavaDoc code)
103   {
104     _code = code;
105   }
106
107   public String JavaDoc getDefinition()
108   {
109     return _definition;
110   }
111
112   public void setDefinition(String JavaDoc definition)
113   {
114     _definition = definition;
115   }
116
117   public boolean equals(Object JavaDoc obj)
118   {
119     if (!(obj instanceof DjModelView)) return false;
120     DjModelView r = (DjModelView) obj;
121
122     return getId() == r.getId();
123   }
124
125   public int hashCode()
126   {
127     return (int) getId();
128   }
129
130   public String JavaDoc toString()
131   {
132     return getCode();
133   }
134
135   public ExtentUsage[] getExtentUsages() throws DjenericException
136   {
137     DjenericDocumentHandler dh = new DjenericDocumentHandler(getDefinition());
138     return dh.getTreeStructure(_mgr);
139   }
140
141   public ResourceDefinition[] getResources() throws DjenericException
142   {
143     DjenericDocumentHandler dh = new DjenericDocumentHandler(getDefinition());
144     return dh.getResources();
145   }
146
147   public DjenericDocumentHandler getDocumentHandler() throws DjenericException
148   {
149     return new DjenericDocumentHandler(getDefinition());
150   }
151
152 }
Popular Tags