public class CreateObjectFragment extends com.sodius.mdw.internal.metamodel.doors.io.commands.CreateObjectFragmentImpl implements ObjectFragment
When instantiating this command, an InsertLocation
can be used to determine the location where to insert the created object (e.g.
below another object).
This fragment is intended to be combined into an EditModuleCommand
instance.
Below is a snippet illustrating how to use this fragment (see CommandRunner
for a full snippet):
ModuleRef module = ModuleRef.qualifiedName("/MyFolder/MyModule"); EditModuleCommand command = new EditModuleCommand(module, TerminationMode.SAVE_AND_CLOSE); CreateObjectFragment fragment = new CreateObjectFragment(); command.add(fragment); myCommandRunner.run(command);
The absolute number of the object can of course not be determined before the command fragment is executed. When attribute values need to be set on
the object within the same command that creates it, the ObjectRef.created(objectFragment)
method can be used to get a reference on the
object before the command is executed, as demonstrated in the following snippet.
CreateObjectFragment fragment = new CreateObjectFragment(); myCommand.add(fragment); // obtain a reference on the object that is going to be created by the command ObjectRef object = ObjectRef.created(fragment); myCommand.add(new SetAttributeValueFragment(object, "Object Heading", "test")); myCommandRunner.run(myCommand);
Once the fragment is executed, the getAbsoluteNumber()
method gives the absolute number of the created object. This can be useful to
reference this object in other commands, later executed to edit this module. Below is a snippet illustrating the usage:
CreateObjectFragment fragment = new CreateObjectFragment(); myCommand.add(fragment); myCommandRunner.run(myCommand); String absoluteNumber = fragment.getAbsoluteNumber(); // the command has been executed, the absolute number is known ... ObjectRef object = ObjectRef.absoluteNumber(absoluteNumber); SetAttributeValueFragment fragment = new SetAttributeValueFragment(object, "Object Heading", "test"); mySecondCommand.add(fragment);
This class is not intended to be subclassed by clients but may be instantiated.
CommandRunner
,
EditModuleCommand
,
ObjectRef.created(ObjectFragment)
Constructor and Description |
---|
CreateObjectFragment()
Instantiates a fragment to create a new object in the DOORS formal module,
at top level in the module.
|
CreateObjectFragment(InsertLocation insertLocation)
Instantiates a fragment to create a new object in the DOORS formal module,
at the specified location.
|
Modifier and Type | Method and Description |
---|---|
int |
getAbsoluteNumber()
Returns the absolute number of the object created when executing the command fragment.
|
public CreateObjectFragment()
new CreateObjectFragment(InsertLocation.top())
.public CreateObjectFragment(InsertLocation insertLocation)
insertLocation
- the location in the module where to insert the created object.public int getAbsoluteNumber()
ObjectFragment
getAbsoluteNumber
in interface ObjectFragment
getAbsoluteNumber
in class com.sodius.mdw.internal.metamodel.doors.io.commands.CreateObjectFragmentImpl
0
if the fragment has not been execute (and therefore the object has not been created).