4343import org .cristalise .kernel .common .InvalidDataException ;
4444import org .cristalise .kernel .common .ObjectAlreadyExistsException ;
4545import org .cristalise .kernel .common .ObjectNotFoundException ;
46+ import org .cristalise .kernel .graph .model .BuiltInVertexProperties ;
4647import org .cristalise .kernel .lifecycle .ActivityDef ;
4748import org .cristalise .kernel .lookup .ItemPath ;
4849import org .cristalise .kernel .process .Gateway ;
@@ -173,6 +174,30 @@ public void updateMember(ItemPath childPath, int memberID, CastorHashMap memberN
173174 public DependencyMember addMember (ItemPath itemPath )
174175 throws InvalidCollectionModification , ObjectAlreadyExistsException
175176 {
177+ DependencyMember depMember = createMember (itemPath );
178+ mMembers .list .add (depMember );
179+
180+ Logger .msg (8 , "Dependency.addMember(" + itemPath + ") added to children with slotId:" +depMember .getID ());
181+ return depMember ;
182+ }
183+
184+ /**
185+ *
186+ * @param depMember
187+ * @throws InvalidCollectionModification
188+ * @throws ObjectAlreadyExistsException
189+ */
190+ public void addMember (DependencyMember depMember ) throws InvalidCollectionModification , ObjectAlreadyExistsException {
191+ mMembers .list .add (depMember );
192+ }
193+ /**
194+ *
195+ * @param itemPath
196+ * @return
197+ * @throws InvalidCollectionModification
198+ * @throws ObjectAlreadyExistsException
199+ */
200+ public DependencyMember createMember (ItemPath itemPath ) throws InvalidCollectionModification , ObjectAlreadyExistsException {
176201 if (itemPath == null )
177202 throw new InvalidCollectionModification ("Cannot add empty slot to Dependency collection" );
178203
@@ -187,9 +212,6 @@ public DependencyMember addMember(ItemPath itemPath)
187212
188213 // assign entity
189214 depMember .assignItem (itemPath );
190- mMembers .list .add (depMember );
191-
192- Logger .msg (8 , "Dependency.addMember(" + itemPath + ") added to children with slotId:" +depMember .getID ());
193215 return depMember ;
194216 }
195217
@@ -215,11 +237,29 @@ public List<DependencyMember> compare(Dependency other) {
215237 @ Override
216238 public DependencyMember addMember (ItemPath itemPath , CastorHashMap props , String classProps )
217239 throws InvalidCollectionModification , ObjectAlreadyExistsException
240+ {
241+ DependencyMember depMember = createMember (itemPath , props );
242+ mMembers .list .add (depMember );
243+ Logger .msg (8 , "Dependency.addMember(" + itemPath + ") added to children with slotId:" +depMember .getID ());
244+ return depMember ;
245+ }
246+
247+ /**
248+ *
249+ * @param itemPath
250+ * @param props
251+ * @return
252+ * @throws InvalidCollectionModification
253+ * @throws ObjectAlreadyExistsException
254+ */
255+ public DependencyMember createMember (ItemPath itemPath , CastorHashMap props )
256+ throws InvalidCollectionModification , ObjectAlreadyExistsException
218257 {
219258 if (itemPath == null )
220259 throw new InvalidCollectionModification ("Cannot add empty slot to Dependency collection" );
221260
222261 boolean checkUniqueness = Gateway .getProperties ().getBoolean ("Dependency.checkMemberUniqueness" , true );
262+
223263 if (checkUniqueness && contains (itemPath ))
224264 throw new ObjectAlreadyExistsException ("Item " +itemPath +" already exists in Dependency " +getName ());
225265
@@ -239,8 +279,6 @@ public DependencyMember addMember(ItemPath itemPath, CastorHashMap props, String
239279
240280 // assign entity
241281 depMember .assignItem (itemPath );
242- mMembers .list .add (depMember );
243- Logger .msg (8 , "Dependency.addMember(" + itemPath + ") added to children with slotId:" +depMember .getID ());
244282 return depMember ;
245283 }
246284
@@ -383,7 +421,7 @@ public void addToVertexProperties(CastorHashMap props) throws InvalidDataExcepti
383421 }
384422 catch (ObjectNotFoundException e ) {
385423 //Schema dependency could be defined in Properties
386- if (props .containsKey (SCHEMA_NAME )) {
424+ if (props .containsKey (SCHEMA_NAME . getName () )) {
387425 Logger .msg (8 , "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" +getName ()+"' is defined in Properties" );
388426 String uuid = LocalObjectLoader .getSchema (props ).getItemPath ().getUUID ().toString ();
389427 props .setBuiltInProperty (SCHEMA_NAME , uuid );
@@ -399,7 +437,7 @@ public void addToVertexProperties(CastorHashMap props) throws InvalidDataExcepti
399437 }
400438 catch (ObjectNotFoundException e ) {
401439 //Backward compability: Script dependency could be defined in Properties
402- if (props .containsKey (SCRIPT_NAME )) {
440+ if (props .containsKey (SCRIPT_NAME . getName () )) {
403441 Logger .msg (8 , "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" +getName ()+"' is defined in Properties" );
404442 String uuid = LocalObjectLoader .getScript (props ).getItemPath ().getUUID ().toString ();
405443 props .setBuiltInProperty (SCRIPT_NAME , uuid );
@@ -415,7 +453,7 @@ public void addToVertexProperties(CastorHashMap props) throws InvalidDataExcepti
415453 }
416454 catch (ObjectNotFoundException e ) {
417455 //Backward compability: Query dependency could be defined in Properties
418- if (props .containsKey (QUERY_NAME )) {
456+ if (props .containsKey (QUERY_NAME . getName () )) {
419457 Logger .msg (8 , "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" +getName ()+"' is defined in Properties" );
420458 String uuid = LocalObjectLoader .getQuery (props ).getItemPath ().getUUID ().toString ();
421459 props .setBuiltInProperty (QUERY_NAME , uuid );
@@ -430,7 +468,7 @@ public void addToVertexProperties(CastorHashMap props) throws InvalidDataExcepti
430468 props .setBuiltInProperty (STATE_MACHINE_VERSION , memberVer );
431469 }
432470 catch (ObjectNotFoundException e ) {
433- if (props .containsKey (STATE_MACHINE_NAME )) {
471+ if (props .containsKey (STATE_MACHINE_NAME . getName () )) {
434472 Logger .msg (8 , "Dependency.addToVertexProperties() - BACKWARD COMPABILITY: Dependency '" +getName ()+"' is defined in Properties" );
435473 String uuid = LocalObjectLoader .getStateMachine (props ).getItemPath ().getUUID ().toString ();
436474 props .setBuiltInProperty (STATE_MACHINE_NAME , uuid );
@@ -442,7 +480,7 @@ public void addToVertexProperties(CastorHashMap props) throws InvalidDataExcepti
442480 ActivityDef actDef = LocalObjectLoader .getActDef (memberUUID , memberVer );
443481 CastorHashMap chm = null ;
444482
445- if (props .containsKey (ACTIVITY_DEF_URN )) {
483+ if (props .containsKey (ACTIVITY_DEF_URN . getName () )) {
446484 chm = (CastorHashMap )props .getBuiltInProperty (ACTIVITY_DEF_URN );
447485 }
448486 else {
@@ -483,4 +521,24 @@ private boolean convertToVertextPropsByScript(CastorHashMap props, DependencyMem
483521 }
484522 return false ;
485523 }
524+
525+ /**
526+ * Method of convenience to get property value using BuiltInVertexProperties
527+ *
528+ * @param prop the property to read
529+ * @return the value, can be null
530+ */
531+ public Object getBuiltInProperty (BuiltInVertexProperties prop ) {
532+ return mProperties .get (prop .getName ());
533+ }
534+
535+ /**
536+ * Method of convenience to check if property exists
537+ *
538+ * @param prop the property to check
539+ * @return true if property exist, false otherwise
540+ */
541+ public boolean containsBuiltInProperty (BuiltInVertexProperties prop ) {
542+ return mProperties .containsKey (prop .getName ());
543+ }
486544}
0 commit comments