ISO-10303-21;This is about the smallest possible AP203 example. It does not fit to several global rules of AP203 but it is valid according to the EXPRESS structural definitions.
HEADER;
FILE_DESCRIPTION(('Examp1e program to generate a very basic AP203 p21 file'),'2;1');
FILE_NAME('&repository1','2000-02-09 T10:58:28',('Lothar Klein'),('LKSoftWare GmbH'),
'NO VERSION','J-SDAI MULTIPLE level: Version 2.0 (Build 173, 2000-02-07)','Lothar Klein');
FILE_SCHEMA(('CONFIG_CONTROL_DESIGN'));
ENDSEC;
DATA;
#1=APPLICATION_CONTEXT('CONFIGURATION MANAGEMENT');
#2=APPLICATION_PROTOCOL_DEFINITION('INTERNATIONAL STANDARD','CONFIG_CONTROL_DESIGN',
1994,#1);
#3=MECHANICAL_CONTEXT('CONFIGURATION CONTROL DESIGN',#1,'MECHANICAL');
#4=PRODUCT('TestId','TestName','TestDescription',(#3));
ENDSEC;
END-ISO-10303-21;
public static final void main(String argv[]) throws SdaiException {SdaiSession.setLogWriter(new PrintWriter(System.out, true));}
SdaiSession session = SdaiSession.openSession();
SdaiTransaction transaction = session.startTransactionReadWriteAccess();
...
transaction.endTransactionAccessAbort();
...
session.closeSession();
A new part21 file is created with exportClearTextEncoding. The whole contents and all the header information of the repository is written out. The only one parameter specifies where to place the part21 file. In this case the first command line argument is used. At the end the repository is closed and deleted. Because the repository is created as a temporarily, this is not really needed - it is only given here for completeness.
SdaiRepository repo = session.createRepository("", null);Please note that creation and deletion of repositories is not covered by the transaction mechanism.
repo.openRepository();
...
repo.exportClearTextEncoding(argv[0]);
...
repo.closeRepository();
repo.deleteRepository();
A_string descriptions = repo.getDescription();
descriptions.addByIndex(1, "Examp1e program to generate a very basic AP203 p21 file");
A_string authors = repo.getAuthor();
authors.addByIndex(1, "Lothar Klein");
A_string organizations = repo.getOrganization();
organizations.addByIndex(1, "LKSoftWare GmbH");
repo.setOriginatingSystem(session.getSdaiImplementation().getName() + " " +
session.getSdaiImplementation().getLevel() );
repo.setAuthorization("Lothar Klein");
Usually the read-write access on the model is ended when no longer needed. But after some changes these changes first need to be either accepted or rejected through the transaction operation commit and abort. Here we abort and end the transaction in one operation. Ending the transaction results also in ending all read-only or read-write access to models.
SdaiModel model = repo.createSdaiModel("Model1", jsdai.SConfig_control_design.SConfig_control_design.class);
model.startReadWriteAccess();
...
transaction.endTransactionAccessAbort();
EXxx instance = (EXxx) model.createEntityInstance(CXxx.class);In this example application we need instances of the types application_context, application_protocol_definition, mechanical_context and product. Here they are:
EApplication_context app_context = (EApplication_context)
model.createEntityInstance(CApplication_context.class);
EApplication_protocol_definition app_protocol = (EApplication_protocol_definition)
model.createEntityInstance(CApplication_protocol_definition.class);
EMechanical_context mechanical = (EMechanical_context)
model.createEntityInstance(CMechanical_context.class);
EProduct product = (EProduct) model.createEntityInstance(CProduct.class);
app_context.setApplication(null, "CONFIGURATION MANAGEMENT");Attributes of an aggregate type can't be set. The aggregate instance can only be created in place. For early binding the method name is a combination of the prefix "create" with the attribute name. After the aggregate is created members can be added to it.
app_protocol.setApplication_protocol_year(null, 1994);
mechanical.setFrame_of_reference(null, app_context);
AProduct_context contexts = product.createFrame_of_reference(null);It is also possible to create a instance of e.g. AProduct_context with the new operator. But this would create only a non-persistent list. Such an aggregate instance can't be set to an attribute of an entity-instance - or in the case of nested aggregates to a member of the enclosing aggregate.
contexts.addUnordered(mechanical);
// Example11.java
// Copyright (c) LKSoft
// Inc. All Rights Reserved.
//
// This software is provided "AS IS," without
a warranty of any kind.
// Simple SDAI application program.
// Generates a very basic ap203 population
and
// writes it out into a p21 file.
import java.io.*;
import jsdai.lang.*;
import jsdai.SConfig_control_design.*;
import jsdai.SApplication_context_schema.*;
import jsdai.SProduct_definition_schema.*;
public class Example11 {
public static final void main(String
argv[]) throws SdaiException {
if (argv == null || argv.length != 1) {}System.out.println("usage:");}
System.out.println(" Example11 output_file");
return;// redirect the J-SDAI system log to System.out
SdaiSession.setLogWriter(new PrintWriter(System.out, true));// first open a session and specify the desired AP
SdaiSession session = SdaiSession.openSession();// start a read/write transaction to allow importClearTextEncoding
SdaiTransaction transaction = session.startTransactionReadWriteAccess();SdaiRepository repo = session.createRepository("", null);
repo.openRepository();
A_string descriptions = repo.getDescription();
descriptions.addByIndex(1, "Examp1e program to generate a very basic AP203 p21 file");
A_string authors = repo.getAuthor();
authors.addByIndex(1, "Lothar Klein");
A_string organizations = repo.getOrganization();
organizations.addByIndex(1, "LKSoftWare GmbH");
repo.setOriginatingSystem(session.getSdaiImplementation().getName() + " " +
session.getSdaiImplementation().getLevel() );
repo.setAuthorization("Lothar Klein");SdaiModel model = repo.createSdaiModel("Model1", jsdai.SConfig_control_design.SConfig_control_design.class);
model.startReadWriteAccess();EApplication_context app_context = (EApplication_context) model.createEntityInstance(CApplication_context.class);
app_context.setApplication(null, "CONFIGURATION MANAGEMENT");EApplication_protocol_definition app_protocol = (EApplication_protocol_definition) model.createEntityInstance(CApplication_protocol_definition.class);
app_protocol.setStatus(null, "INTERNATIONAL STANDARD");
app_protocol.setApplication_interpreted_model_schema_name(null, "CONFIG_CONTROL_DESIGN");
app_protocol.setApplication_protocol_year(null, 1994);
app_protocol.setApplication(null, app_context);EMechanical_context mechanical = (EMechanical_context)
model.createEntityInstance(CMechanical_context.class);
mechanical.setName(null, "CONFIGURATION CONTROL DESIGN");
mechanical.setFrame_of_reference(null, app_context);
mechanical.setDiscipline_type(null, "MECHANICAL");EProduct product = (EProduct) model.createEntityInstance(CProduct.class);
product.setId(null, "TestId");
product.setName(null, "TestName");
product.setDescription(null, "TestDescription");
AProduct_context contexts = product.createFrame_of_reference(null);
contexts.addUnordered(mechanical);repo.exportClearTextEncoding(argv[0]);
transaction.endTransactionAccessAbort();
repo.closeRepository();
repo.deleteRepository();System.out.println();
System.out.println("Done");
session.closeSession();
C:\examples>javac Example11.javaThe resulting file "t.stp" is given above.
C:\examples>java Example11 t.stp
--- time for getting values=0sec
--- Writing time=0secDone
Download Example11.java