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.metaboss.sdlctools.domains.enterprisemodel.testing;
016:
017: import javax.naming.Context;
018: import javax.naming.InitialContext;
019:
020: import com.metaboss.sdlctools.domains.enterprisemodel.BOAssociationRole;
021: import com.metaboss.sdlctools.domains.enterprisemodel.BOAttribute;
022: import com.metaboss.sdlctools.domains.enterprisemodel.BODatatype;
023: import com.metaboss.sdlctools.domains.enterprisemodel.BODomain;
024: import com.metaboss.sdlctools.domains.enterprisemodel.BOEntity;
025: import com.metaboss.sdlctools.domains.enterprisemodel.BOMetaBossDomain;
026: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
027: import com.oldboss.framework.bo.BOTransaction;
028:
029: public class TestHarness {
030: public static void main(String[] args) {
031: try {
032:
033: // listAllElements();
034:
035: // Test replacing og the entity in the role
036: testReplacingOfTheEntityInTheAssociationRole();
037:
038: } catch (Exception e) {
039: e.printStackTrace();
040: }
041: }
042:
043: private static void listAllElements() throws Exception {
044: // Get the instance of the enterprise ps home via jndi
045: Context ctx = new InitialContext();
046: BOMetaBossDomain lDomain = (BOMetaBossDomain) ctx
047: .lookup(BOMetaBossDomain.COMPONENT_URL);
048: BOSystem[] lSystems = lDomain.getEnterprises().getEnterprise(
049: "HatMaker").getSystems().getAllSystems();
050: for (int lSystemIndex = 0; lSystemIndex < lSystems.length; lSystemIndex++) {
051: BOSystem lSystem = lSystems[lSystemIndex];
052: // Get list of datatypes and print them out
053: {
054: BODatatype[] lDatatypes = lSystem.getDatatypes()
055: .getAllDatatypes();
056: System.out.println("Datatypes (" + lDatatypes.length
057: + ")");
058: for (int i = 0; i < lDatatypes.length; i++) {
059: System.out.println(" Datatype : "
060: + lDatatypes[i].getRef());
061: }
062: }
063: // Get list of domains and print them out
064: {
065: BODomain[] lDomains = lSystem.getDomains()
066: .getAllDomains();
067: System.out.println("Domains (" + lDomains.length + ")");
068: for (int i = 0; i < lDomains.length; i++) {
069: System.out.println(" Domain : "
070: + lDomains[i].getRef());
071: BOEntity[] lEntities = lDomains[i].getEntities()
072: .getAllEntities();
073: System.out.println(" Entities ("
074: + lEntities.length + ")");
075: for (int j = 0; j < lEntities.length; j++) {
076: System.out
077: .println(" Entity : "
078: + lEntities[j].getRef());
079: System.out
080: .println(" : "
081: + lEntities[j].getDescription());
082: BOAttribute[] lAttributes = lEntities[j]
083: .getAttributes().getAllAttributes();
084: for (int k = 0; k < lAttributes.length; k++) {
085: System.out
086: .println(" Contained Attribute : "
087: + lAttributes[k].getName());
088: }
089: }
090: }
091: }
092: }
093: }
094:
095: private static void testReplacingOfTheEntityInTheAssociationRole()
096: throws Exception {
097: // Get the instance of the enterprise ps home via jndi
098: Context ctx = new InitialContext();
099: BOMetaBossDomain lDomain = (BOMetaBossDomain) ctx
100: .lookup(BOMetaBossDomain.COMPONENT_URL);
101: BOTransaction lTx = (BOTransaction) ctx
102: .lookup(BOTransaction.COMPONENT_URL);
103: try {
104: BOAssociationRole lAssociationRole = lDomain
105: .getAssociationRole("HatMaker.Crm.Core.ActionsPerformedInSession.Session");
106: BOEntity lEntity = lDomain
107: .getEntity("HatMaker.Crm.Core.FunctionalModule");
108: lAssociationRole.beginEdit(lTx);
109: lAssociationRole.setEntity(lEntity);
110: lTx.doCommit();
111: lTx = null;
112: } finally {
113: if (lTx != null)
114: lTx.doRollback();
115: }
116: }
117: }
|