001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.oldboss.domain.visualmodelling.impl;
016:
017: import java.awt.Point;
018: import java.util.Properties;
019:
020: import com.metaboss.enterprise.bo.BOException;
021: import com.metaboss.enterprise.bo.BOInvalidOperationForReadOnlyObjectException;
022: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
023: import com.metaboss.enterprise.ps.PSException;
024: import com.metaboss.sdlctools.domains.enterprisemodel.BODomain;
025: import com.oldboss.domain.visualmodelling.BOEntityRelationshipDiagramLayout;
026: import com.oldboss.framework.bo.impl.BOObjectImpl;
027:
028: public class BOEntityRelationshipDiagramLayoutImpl extends BOObjectImpl
029: implements BOEntityRelationshipDiagramLayout {
030: private BOVisualModellingHomeImpl mDomainHome = null;
031: private BODomain mDomain = null;
032: private Properties mLayoutProperties = null;
033: private String mLayoutPropertiesFileName = null;
034:
035: /* Instance creator */
036: public static BOEntityRelationshipDiagramLayout createInstanceForExisting(
037: BOVisualModellingHomeImpl pDomainHome, BODomain pDomain)
038: throws BOException {
039: BOEntityRelationshipDiagramLayoutImpl lImpl = new BOEntityRelationshipDiagramLayoutImpl();
040: lImpl.mDomainHome = pDomainHome;
041: lImpl.mDomain = pDomain;
042: // lImpl.mLayoutPropertiesFileName = com.oldboss.ps.impl.Storage.getDomainDirectory(pDomain.getRef()) + java.io.File.separator + "EntityRelationshipDiagramLayout.properties";
043: lImpl.mLayoutPropertiesFileName = "C:" + java.io.File.separator
044: + "EntityRelationshipDiagramLayout.properties";
045: lImpl.setupForExisting();
046: return lImpl;
047: }
048:
049: /* Private constructor restricts instance creation from outside */
050: private BOEntityRelationshipDiagramLayoutImpl() throws BOException {
051: }
052:
053: /** Simplified get position method. */
054: public Point getPosition(String pObjectType, String pObjectRef)
055: throws BOException {
056: loadDetailsIfNecessary();
057: String lPropertyValue = mLayoutProperties
058: .getProperty(getPositionKey(pObjectType, pObjectRef));
059: if (lPropertyValue == null)
060: return null;
061: java.util.StringTokenizer lTokenizer = new java.util.StringTokenizer(
062: lPropertyValue, ",", false);
063: return new Point(Integer.parseInt(lTokenizer.nextToken()),
064: Integer.parseInt(lTokenizer.nextToken()));
065: }
066:
067: /** Simplified set position method. */
068: public void setPosition(String pObjectType, String pObjectRef,
069: Point pPosition) throws BOException {
070: if (!isBeingEdited())
071: throw new BOInvalidOperationForReadOnlyObjectException();
072: mLayoutProperties.setProperty(getPositionKey(pObjectType,
073: pObjectRef), ((int) pPosition.getX()) + ","
074: + ((int) pPosition.getY()));
075: }
076:
077: /* Clears particular position. */
078: public void clearPosition(String pObjectType, String pObjectRef)
079: throws BOException {
080: if (!isBeingEdited())
081: throw new BOInvalidOperationForReadOnlyObjectException();
082: mLayoutProperties
083: .remove(getPositionKey(pObjectType, pObjectRef));
084: }
085:
086: /* Clears all stored positions. */
087: public void clearAllPositions() throws BOException {
088: if (!isBeingEdited())
089: throw new BOInvalidOperationForReadOnlyObjectException();
090: mLayoutProperties.clear();
091: }
092:
093: protected void onBeginEdit() throws BOException {
094: // Fully load the object
095: loadDetailsIfNecessary();
096: }
097:
098: protected void onCommitUpdate() throws BOException {
099: try {
100: try {
101: mLayoutProperties.store(new java.io.FileOutputStream(
102: mLayoutPropertiesFileName),
103: "The Entity Relationship Diagram Properties");
104: } catch (java.io.IOException e) {
105: throw new PSException(e);
106: }
107: } catch (PSException e) {
108: throw new BOPersistenceServiceInvocationException("", e);
109: }
110: }
111:
112: // For now - just a hack to get it working
113: private void loadDetailsIfNecessary() throws BOException {
114: if (mLayoutProperties == null) {
115: try {
116: try {
117: mLayoutProperties = new Properties();
118: // Do the direct call to get the properties file
119: java.io.File lLayoutPropertiesFile = new java.io.File(
120: mLayoutPropertiesFileName);
121: if (lLayoutPropertiesFile.exists())
122: mLayoutProperties
123: .load(new java.io.FileInputStream(
124: lLayoutPropertiesFile));
125: } catch (java.io.IOException e) {
126: throw new PSException(e);
127: }
128: } catch (PSException e) {
129: throw new BOPersistenceServiceInvocationException("", e);
130: }
131: }
132: }
133:
134: // helper. Retrieves key of the property containing position
135: private static String getPositionKey(String pObjectType,
136: String pObjectRef) {
137: return new String("position." + pObjectType + "." + pObjectRef)
138: .toLowerCase();
139: }
140: }
|