1 package org.openprovenance.model;
2 import java.util.Collection;
3 import java.util.Arrays;
4 import java.util.LinkedList;
5 import java.util.List;
6 import java.util.Date;
7 import javax.xml.bind.JAXBElement;
8 import java.util.GregorianCalendar;
9 import javax.xml.datatype.XMLGregorianCalendar;
10 import javax.xml.datatype.DatatypeFactory;
11 import javax.xml.datatype.DatatypeConfigurationException;
12
13 import org.w3c.dom.Document;
14 import org.w3c.dom.Element;
15 import javax.xml.parsers.DocumentBuilder;
16 import javax.xml.parsers.DocumentBuilderFactory;
17 import javax.xml.parsers.ParserConfigurationException;
18
19
20 /*** A stateless factory of OPM objects. */
21
22 public class OPMFactory implements CommonURIs {
23
24 public static String roleIdPrefix="r_";
25 public static String usedIdPrefix="u_";
26 public static String wasGenerateByIdPrefix="g_";
27 public static String wasDerivedFromIdPrefix="d_";
28 public static String wasTriggeredByIdPrefix="t_";
29 public static String wasControlledByIdPrefix="c_";
30 public static String opmGraphIdPrefix="gr_";
31
32 public static final String packageList=
33 "org.openprovenance.model";
34
35 public String getPackageList() {
36 return packageList;
37 }
38
39 private final static OPMFactory oFactory=new OPMFactory();
40
41 public static OPMFactory getFactory() {
42 return oFactory;
43 }
44
45 protected ObjectFactory of;
46
47 protected DatatypeFactory dataFactory;
48
49 void init() {
50 try {
51 dataFactory= DatatypeFactory.newInstance ();
52 } catch (DatatypeConfigurationException ex) {
53 throw new RuntimeException (ex);
54 }
55 }
56
57
58
59 public OPMFactory() {
60 of=new ObjectFactory();
61 init();
62 }
63
64 public OPMFactory(ObjectFactory of) {
65 this.of=of;
66 init();
67 }
68
69 public ObjectFactory getObjectFactory() {
70 return of;
71 }
72
73 public ProcessRef newProcessRef(Process p) {
74 ProcessRef res=of.createProcessRef();
75 res.setRef(p);
76 return res;
77 }
78
79 public RoleRef newRoleRef(Role p) {
80 RoleRef res=of.createRoleRef();
81 res.setRef(p);
82 return res;
83 }
84
85 public AnnotationRef newAnnotationRef(Annotation a) {
86 AnnotationRef res=of.createAnnotationRef();
87 res.setRef(a);
88 return res;
89 }
90
91 public ArtifactRef newArtifactRef(Artifact a) {
92 ArtifactRef res=of.createArtifactRef();
93 res.setRef(a);
94 return res;
95 }
96 public AgentRef newAgentRef(Agent a) {
97 AgentRef res=of.createAgentRef();
98 res.setRef(a);
99 return res;
100 }
101
102 public AccountRef newAccountRef(Account acc) {
103 AccountRef res=of.createAccountRef();
104 res.setRef(acc);
105 return res;
106 }
107
108
109
110
111
112 public CausalDependencyRef newCausalDependencyRef(WasGeneratedBy edge) {
113 CausalDependencyRef res=of.createCausalDependencyRef();
114 res.setRef(edge);
115 return res;
116 }
117
118 public CausalDependencyRef newCausalDependencyRef(Used edge) {
119 CausalDependencyRef res=of.createCausalDependencyRef();
120 res.setRef(edge);
121 return res;
122 }
123 public CausalDependencyRef newCausalDependencyRef(WasDerivedFrom edge) {
124 CausalDependencyRef res=of.createCausalDependencyRef();
125 res.setRef(edge);
126 return res;
127 }
128
129 public CausalDependencyRef newCausalDependencyRef(WasControlledBy edge) {
130 CausalDependencyRef res=of.createCausalDependencyRef();
131 res.setRef(edge);
132 return res;
133 }
134 public CausalDependencyRef newCausalDependencyRef(WasTriggeredBy edge) {
135 CausalDependencyRef res=of.createCausalDependencyRef();
136 res.setRef(edge);
137 return res;
138 }
139
140
141
142 public Process newProcess(String pr,
143 Collection<Account> accounts) {
144 return newProcess(pr,accounts,null);
145 }
146
147 public Process newProcess(String pr,
148 Collection<Account> accounts,
149 String label) {
150 Process res=of.createProcess();
151 res.setId(pr);
152 addAccounts(res,accounts,null);
153 if (label!=null) addAnnotation(res,newLabel(label));
154 return res;
155 }
156
157 public Agent newAgent(String ag,
158 Collection<Account> accounts) {
159 return newAgent(ag,accounts,null);
160 }
161
162 public Agent newAgent(String ag,
163 Collection<Account> accounts,
164 String label) {
165 Agent res=of.createAgent();
166 res.setId(ag);
167 addAccounts(res,accounts,null);
168 if (label!=null) addAnnotation(res,newLabel(label));
169 return res;
170 }
171
172 public Account newAccount(String id) {
173 Account res=of.createAccount();
174 res.setId(id);
175 return res;
176 }
177 public Account newAccount(String id, String label) {
178 Account res=of.createAccount();
179 res.setId(id);
180 res.getAnnotation().add(of.createLabel(newLabel(label)));
181 return res;
182 }
183
184 public Label newLabel(String label) {
185 Label res=of.createLabel();
186 res.setValue(label);
187 return res;
188 }
189
190 public Value newValue(Object value, String encoding) {
191 Value res=of.createValue();
192 res.setContent(value);
193 res.setEncoding(encoding);
194 return res;
195 }
196
197
198 public Profile newProfile(String profile) {
199 Profile res=of.createProfile();
200 res.setValue(profile);
201 return res;
202 }
203
204
205 public PName newPName(String profile) {
206 PName res=of.createPName();
207 res.setValue(profile);
208 return res;
209 }
210
211
212 public Role getRole(Edge e) {
213 if (e instanceof Used) {
214 return ((Used) e).getRole();
215 }
216 if (e instanceof WasGeneratedBy) {
217 return ((WasGeneratedBy) e).getRole();
218 }
219 if (e instanceof WasControlledBy) {
220 return ((WasControlledBy) e).getRole();
221 }
222 return null;
223 }
224
225 public String getLabel(EmbeddedAnnotation annotation) {
226 if (annotation instanceof Label) {
227 Label label=(Label) annotation;
228 return label.getValue();
229 } else {
230 for (Property prop: annotation.getProperty()) {
231 if (prop.getUri().equals(LABEL_PROPERTY)) {
232 return (String) prop.getValue();
233 }
234 }
235 return null;
236 }
237 }
238
239
240 public String getType(EmbeddedAnnotation annotation) {
241 if (annotation instanceof Type) {
242 Type type=(Type) annotation;
243 return type.getValue();
244 } else {
245 for (Property prop: annotation.getProperty()) {
246 if (prop.getUri().equals(TYPE_PROPERTY)) {
247 return (String) prop.getValue();
248 }
249 }
250 return null;
251 }
252 }
253
254 public Object getValue(EmbeddedAnnotation annotation) {
255 if (annotation instanceof Value) {
256 Value value=(Value) annotation;
257 return value.getContent();
258 } else {
259 for (Property prop: annotation.getProperty()) {
260 if (prop.getUri().equals(VALUE_PROPERTY)) {
261 return prop.getValue();
262 }
263 }
264 return null;
265 }
266 }
267
268 public String getEncoding(EmbeddedAnnotation annotation) {
269 if (annotation instanceof Value) {
270 Value value=(Value) annotation;
271 return value.getEncoding();
272 } else {
273 for (Property prop: annotation.getProperty()) {
274 if (prop.getUri().equals(ENCODING_PROPERTY)) {
275 return (String) prop.getValue();
276 }
277 }
278 return null;
279 }
280 }
281
282 public String getProfile(EmbeddedAnnotation annotation) {
283 if (annotation instanceof Profile) {
284 Profile profile=(Profile) annotation;
285 return profile.getValue();
286 } else {
287 for (Property prop: annotation.getProperty()) {
288 if (prop.getUri().equals(PROFILE_PROPERTY)) {
289 return (String) prop.getValue();
290 }
291 }
292 return null;
293 }
294 }
295
296 public String getPname(EmbeddedAnnotation annotation) {
297 if (annotation instanceof PName) {
298 PName pname=(PName) annotation;
299 return pname.getValue();
300 } else {
301 for (Property prop: annotation.getProperty()) {
302 if (prop.getUri().equals(PNAME_PROPERTY)) {
303 return (String) prop.getValue();
304 }
305 }
306 return null;
307 }
308 }
309
310
311
312 /*** Return the value of the value property in the first annotation. */
313
314 public Object getValue(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
315 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
316 EmbeddedAnnotation ann=jann.getValue();
317 Object value=getValue(ann);
318 if (value!=null) return value;
319 }
320 return null;
321 }
322
323
324
325 /*** Return the value of the label property in the first annotation. */
326 public String getLabel(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
327 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
328 EmbeddedAnnotation ann=jann.getValue();
329 String label=getLabel(ann);
330 if (label!=null) return label;
331 }
332 return null;
333 }
334
335
336 /*** Return the value of the type property in the first annotation. */
337
338 public String getType(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
339 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
340 EmbeddedAnnotation ann=jann.getValue();
341 String type=getType(ann);
342 if (type!=null) return type;
343 }
344 return null;
345 }
346
347
348 /*** Return the value of the profile property in the first annotation. */
349 public String getProfile(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
350 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
351 EmbeddedAnnotation ann=jann.getValue();
352 String profile=getProfile(ann);
353 if (profile!=null) return profile;
354 }
355 return null;
356 }
357
358 /*** Return the value of the pname property in the first annotation. */
359 public String getPname(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
360 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
361 EmbeddedAnnotation ann=jann.getValue();
362 String pname=getPname(ann);
363 if (pname!=null) return pname;
364 }
365 return null;
366 }
367
368
369 /*** Return the value of the value property. */
370
371 public List<Object> getValues(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
372 List<Object> res=new LinkedList();
373 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
374 EmbeddedAnnotation ann=jann.getValue();
375 Object value=getValue(ann);
376 if (value!=null) res.add(value);
377 }
378 return res;
379 }
380
381
382
383 /*** Return the value of the label property. */
384 public List<String> getLabels(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
385 List<String> res=new LinkedList();
386 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
387 EmbeddedAnnotation ann=jann.getValue();
388 String label=getLabel(ann);
389 if (label!=null) res.add(label);
390 }
391 return res;
392 }
393
394
395 /*** Return the value of the type property. */
396
397 public List<String> getTypes(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
398 List<String> res=new LinkedList();
399 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
400 EmbeddedAnnotation ann=jann.getValue();
401 String type=getType(ann);
402 if (type!=null) res.add(type);
403 }
404 return res;
405 }
406
407
408 /*** Return the value of the profile property. */
409 public List<String> getProfiles(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
410 List<String> res=new LinkedList();
411 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
412 EmbeddedAnnotation ann=jann.getValue();
413 String profile=getProfile(ann);
414 if (profile!=null) res.add(profile);
415 }
416 return res;
417 }
418
419 /*** Return the value of the pname property. */
420 public List<String> getPnames(List<JAXBElement<? extends EmbeddedAnnotation>> annotations) {
421 List<String> res=new LinkedList();
422 for (JAXBElement<? extends EmbeddedAnnotation> jann: annotations) {
423 EmbeddedAnnotation ann=jann.getValue();
424 String pname=getPname(ann);
425 if (pname!=null) res.add(pname);
426 }
427 return res;
428 }
429
430 /*** Generic accessor for annotable entities. */
431 public String getLabel(Annotable annotable) {
432 return getLabel(annotable.getAnnotation());
433 }
434
435 /*** Generic accessor for annotable entities. */
436 public String getType(Annotable annotable) {
437 return getType(annotable.getAnnotation());
438 }
439
440 /*** Generic accessor for annotable entities. */
441 public String getProfile(Annotable annotable) {
442 return getProfile(annotable.getAnnotation());
443 }
444
445 /*** Generic accessor for annotable entities. */
446 public String getPname(Annotable annotable) {
447 return getPname(annotable.getAnnotation());
448 }
449
450
451 public Type newType(String type) {
452 Type res=of.createType();
453 res.setValue(type);
454 return res;
455 }
456
457 public void addValue(Artifact annotable, Object value, String encoding) {
458 addAnnotation(annotable,newValue(value,encoding));
459 }
460
461 public void addAnnotation(Annotable annotable, Label ann) {
462 if (ann!=null) {
463 annotable.getAnnotation().add(of.createLabel(ann));
464 }
465 }
466
467 public void addAnnotation(Annotable annotable, Value ann) {
468 annotable.getAnnotation().add(of.createValue(ann));
469 }
470
471 public void addAnnotation(Annotable annotable, Profile ann) {
472 annotable.getAnnotation().add(of.createProfile(ann));
473 }
474
475 public void addAnnotation(Annotable annotable, PName ann) {
476 annotable.getAnnotation().add(of.createPname(ann));
477 }
478
479 public void addAnnotation(Annotable annotable, EmbeddedAnnotation ann) {
480 annotable.getAnnotation().add(of.createAnnotation(ann));
481 }
482
483 public void addAnnotation(Annotable annotable, JAXBElement<? extends EmbeddedAnnotation> ann) {
484 annotable.getAnnotation().add(ann);
485 }
486 public void addAnnotations(Annotable annotable, List<JAXBElement<? extends EmbeddedAnnotation>> anns) {
487 annotable.getAnnotation().addAll(anns);
488 }
489
490 public void expandAnnotation(EmbeddedAnnotation ann) {
491 if (ann instanceof Label) {
492 Label label=(Label) ann;
493 String labelValue=label.getValue();
494 ann.getProperty().add(newProperty(LABEL_PROPERTY,labelValue));
495 }
496 if (ann instanceof Type) {
497 Type type=(Type) ann;
498 String typeValue=type.getValue();
499 ann.getProperty().add(newProperty(TYPE_PROPERTY,typeValue));
500 }
501 }
502
503
504 public JAXBElement<? extends EmbeddedAnnotation> compactAnnotation(EmbeddedAnnotation ann) {
505 if (ann instanceof Label) {
506 Label label=(Label) ann;
507 return of.createLabel(label);
508 }
509 if (ann instanceof Type) {
510 Type type=(Type) ann;
511 return of.createType(type);
512 }
513 if (ann instanceof Profile) {
514 Profile profile=(Profile) ann;
515 return of.createProfile(profile);
516 }
517 if (ann instanceof Value) {
518 Value value=(Value) ann;
519 return of.createValue(value);
520 }
521 if (ann instanceof PName) {
522 PName pname=(PName) ann;
523 return of.createPname(pname);
524 }
525 List<Property> properties=ann.getProperty();
526 if (properties.size()==1) {
527 Property prop=properties.get(0);
528 if (prop.getUri().equals(LABEL_PROPERTY)) {
529 Label label=newLabel((String)prop.getValue());
530 setIdForCompactAnnotation(label,ann.getId());
531 return of.createLabel(label);
532 }
533 if (prop.getUri().equals(TYPE_PROPERTY)) {
534 Type type=newType((String)prop.getValue());
535 setIdForCompactAnnotation(type,ann.getId());
536 return of.createType(type);
537 }
538 if (prop.getUri().equals(PROFILE_PROPERTY)) {
539 Profile profile=newProfile((String)prop.getValue());
540 setIdForCompactAnnotation(profile,ann.getId());
541 return of.createProfile(profile);
542 }
543 if (prop.getUri().equals(PNAME_PROPERTY)) {
544 PName pname=newPName((String)prop.getValue());
545 setIdForCompactAnnotation(pname,ann.getId());
546 return of.createPname(pname);
547 }
548 }
549 else if (properties.size()==2) {
550 if ((properties.get(0).getUri().equals(VALUE_PROPERTY))
551 &&
552 (properties.get(1).getUri().equals(ENCODING_PROPERTY))) {
553 Value value=newValue(properties.get(0).getValue(),
554 (String)properties.get(1).getValue());
555 setIdForCompactAnnotation(value,ann.getId());
556 return of.createValue(value);
557 } else if ((properties.get(1).getUri().equals(VALUE_PROPERTY))
558 &&
559 (properties.get(0).getUri().equals(ENCODING_PROPERTY))) {
560 Value value=newValue(properties.get(1).getValue(),
561 (String)properties.get(0).getValue());
562 setIdForCompactAnnotation(value,ann.getId());
563 return of.createValue(value);
564 }
565 }
566
567 return of.createAnnotation(ann);
568 }
569
570 public XMLGregorianCalendar
571 newXMLGregorianCalendar(GregorianCalendar gc) {
572 return dataFactory.newXMLGregorianCalendar(gc);
573 }
574
575
576 public OTime newOTime (OTime time) {
577 return newOTime(time.getNoEarlierThan(),
578 time.getNoLaterThan(),
579 time.getExactlyAt());
580 }
581
582
583 public OTime newOTime (XMLGregorianCalendar point1,
584 XMLGregorianCalendar point2,
585 XMLGregorianCalendar point3) {
586 OTime time = of.createOTime();
587 time.setNoEarlierThan (point1);
588 time.setNoLaterThan (point2);
589 time.setExactlyAt (point3);
590 return time;
591 }
592
593 public OTime newOTime (XMLGregorianCalendar point1,
594 XMLGregorianCalendar point2) {
595 OTime time = of.createOTime();
596 time.setNoEarlierThan (point1);
597 time.setNoLaterThan (point2);
598 return time;
599 }
600
601 public OTime newOTime (XMLGregorianCalendar point) {
602 OTime time = of.createOTime();
603 time.setExactlyAt (point);
604 return time;
605 }
606
607 public OTime newOTime (String value1, String value2) {
608 XMLGregorianCalendar point1 = dataFactory.newXMLGregorianCalendar (value1);
609 XMLGregorianCalendar point2 = dataFactory.newXMLGregorianCalendar (value2);
610 return newOTime(point1,point2);
611 }
612
613 public OTime newOTime (Date date1,
614 Date date2) {
615 GregorianCalendar gc1=new GregorianCalendar();
616 gc1.setTime(date1);
617 GregorianCalendar gc2=new GregorianCalendar();
618 gc2.setTime(date2);
619 return newOTime(newXMLGregorianCalendar(gc1),
620 newXMLGregorianCalendar(gc2));
621 }
622
623 public OTime newOTime (Date date) {
624 GregorianCalendar gc=new GregorianCalendar();
625 gc.setTime(date);
626 return newOTime(newXMLGregorianCalendar(gc));
627 }
628
629 public OTime newInstantaneousTime (XMLGregorianCalendar point) {
630 return newOTime(point);
631 }
632
633 public OTime newInstantaneousTime (String value) {
634 XMLGregorianCalendar point = dataFactory.newXMLGregorianCalendar (value);
635 return newOTime(point);
636 }
637
638
639 public OTime newInstantaneousTime (Date date) {
640 GregorianCalendar gc=new GregorianCalendar();
641 gc.setTime(date);
642 XMLGregorianCalendar xgc=newXMLGregorianCalendar(gc);
643 return newOTime(xgc);
644 }
645
646 public OTime newInstantaneousTimeNow () {
647 return newInstantaneousTime(new Date());
648 }
649
650
651 public boolean compactId=false;
652
653 public void setIdForCompactAnnotation(EmbeddedAnnotation ann, String id) {
654 if (compactId) ann.setId(id);
655 }
656
657
658 public void addAnnotation(Annotable annotable, List<EmbeddedAnnotation> anns) {
659 List<JAXBElement<? extends EmbeddedAnnotation>> annotations=annotable.getAnnotation();
660 for (EmbeddedAnnotation ann: anns) {
661 annotations.add(of.createAnnotation(ann));
662 }
663 }
664
665
666
667 public void addCompactAnnotation(Annotable annotable, List<EmbeddedAnnotation> anns) {
668 List<JAXBElement<? extends EmbeddedAnnotation>> annotations=annotable.getAnnotation();
669 for (EmbeddedAnnotation ann: anns) {
670 annotations.add(compactAnnotation(ann));
671 }
672 }
673
674
675
676 public Overlaps newOverlaps(Collection<Account> accounts) {
677 Overlaps res=of.createOverlaps();
678 LinkedList ll=new LinkedList();
679 int i=0;
680 for (Account acc: accounts) {
681 if (i==2) break;
682 ll.add(newAccountRef(acc));
683 i++;
684 }
685 res.getAccount().addAll(ll);
686 return res;
687 }
688
689 public Overlaps newOverlaps(AccountRef aid1,AccountRef aid2) {
690 Overlaps res=of.createOverlaps();
691 res.getAccount().add(aid1);
692 res.getAccount().add(aid2);
693 return res;
694 }
695
696 /*** By default, no auto generation of Id. Override this behaviour if required. */
697 public String autoGenerateId(String prefix) {
698 return null;
699 }
700
701 /*** Conditional autogeneration of Id. By default, no auto
702 * generation of Id. Override this behaviour if required. */
703 public String autoGenerateId(String prefix, String id) {
704 return id;
705 }
706
707 public Role newRole(String value) {
708 return newRole(autoGenerateId(roleIdPrefix),value);
709 }
710
711 public Role newRole(Role role) {
712 return newRole(autoGenerateId(roleIdPrefix,role.getId()),role.getValue());
713 }
714
715 public Role newRole(String id, String value) {
716 Role res=of.createRole();
717 res.setId(id);
718 res.setValue(value);
719 return res;
720 }
721
722 public Artifact newArtifact(Artifact a) {
723 LinkedList<Account> ll=new LinkedList();
724 for (AccountRef acc: a.getAccount()) {
725 ll.add(newAccount((Account)acc.getRef()));
726 }
727 Artifact res=newArtifact(a.getId(),ll);
728 addNewAnnotations(res,a.getAnnotation());
729 return res;
730 }
731 public Process newProcess(Process a) {
732 LinkedList<Account> ll=new LinkedList();
733 for (AccountRef acc: a.getAccount()) {
734 ll.add(newAccount((Account)acc.getRef()));
735 }
736 Process res=newProcess(a.getId(),ll);
737 addNewAnnotations(res,a.getAnnotation());
738 return res;
739 }
740 public Agent newAgent(Agent a) {
741 LinkedList<Account> ll=new LinkedList();
742 for (AccountRef acc: a.getAccount()) {
743 ll.add(newAccount((Account)acc.getRef()));
744 }
745 Agent res=newAgent(a.getId(),ll);
746 addNewAnnotations(res,a.getAnnotation());
747 return res;
748 }
749
750 public Account newAccount(Account acc) {
751 Account res=newAccount(acc.getId());
752 addNewAnnotations(res,acc.getAnnotation());
753 return res;
754 }
755
756 public void addNewAnnotations(Annotable res,
757 List<JAXBElement<? extends org.openprovenance.model.EmbeddedAnnotation>> anns) {
758 for (JAXBElement<? extends org.openprovenance.model.EmbeddedAnnotation> ann: anns) {
759 EmbeddedAnnotation ea=ann.getValue();
760 if (ea.getId()!=null)
761 addAnnotation(res,newEmbeddedAnnotation(ea.getId(),
762 ea.getProperty(),
763 ea.getAccount(),
764 null));
765 }
766 }
767
768
769
770
771 public Artifact newArtifact(String id,
772 Collection<Account> accounts) {
773 return newArtifact(id,accounts,null);
774 }
775
776 public Artifact newArtifact(String id,
777 Collection<Account> accounts,
778 String label) {
779 Artifact res=of.createArtifact();
780 res.setId(id);
781 addAccounts(res,accounts,null);
782 if (label!=null) addAnnotation(res,newLabel(label));
783 return res;
784 }
785
786 public void addAccounts(HasAccounts element, Collection<Account> accounts, Object ignoreForErasure) {
787 if ((accounts !=null) && (accounts.size()!=0)) {
788 LinkedList ll=new LinkedList();
789 for (Account acc: accounts) {
790 ll.add(newAccountRef(acc));
791 }
792 addAccounts(element,ll);
793 }
794 }
795 public void addAccounts(HasAccounts element, Collection<AccountRef> accounts) {
796 if ((accounts !=null) && (accounts.size()!=0)) {
797 element.getAccount().addAll(accounts);
798 }
799 }
800
801
802 public Used newUsed(String id,
803 ProcessRef pid,
804 Role role,
805 ArtifactRef aid,
806 Collection<AccountRef> accounts) {
807 Used res=of.createUsed();
808 res.setId(autoGenerateId(usedIdPrefix,id));
809 res.setEffect(pid);
810 res.setRole(role);
811 res.setCause(aid);
812 addAccounts(res,accounts);
813 return res;
814 }
815
816
817
818 public UsedStar newUsedStar(ProcessRef pid,
819 ArtifactRef aid,
820 Collection<AccountRef> accounts) {
821 UsedStar res=of.createUsedStar();
822 res.setEffect(pid);
823 res.setCause(aid);
824 addAccounts(res,accounts);
825 return res;
826 }
827
828 public Used newUsed(Process p,
829 Role role,
830 Artifact a,
831 Collection<Account> accounts) {
832 Used res=newUsed(null,p,role,a,accounts);
833 return res;
834 }
835
836 public Used newUsed(String id,
837 Process p,
838 Role role,
839 Artifact a,
840 Collection<Account> accounts) {
841 ProcessRef pid=newProcessRef(p);
842 ArtifactRef aid=newArtifactRef(a);
843 LinkedList ll=new LinkedList();
844 if (accounts!=null) {
845 for (Account acc: accounts) {
846 ll.add(newAccountRef(acc));
847 }
848 }
849 return newUsed(id,pid,role,aid,ll);
850 }
851 public UsedStar newUsedStar(Process p,
852 Artifact a,
853 Collection<Account> accounts) {
854 ProcessRef pid=newProcessRef(p);
855 ArtifactRef aid=newArtifactRef(a);
856 LinkedList ll=new LinkedList();
857 if (accounts!=null) {
858 for (Account acc: accounts) {
859 ll.add(newAccountRef(acc));
860 }
861 }
862 return newUsedStar(pid,aid,ll);
863 }
864
865
866 public Used newUsed(String id,
867 Process p,
868 Role role,
869 Artifact a,
870 String type,
871 Collection<Account> accounts) {
872 Used res=newUsed(id,p,role,a,accounts);
873 addAnnotation(res,of.createType(newType(type)));
874 return res;
875 }
876
877 public Used newUsed(Used u) {
878 Used u1=newUsed(u.getId(),
879 u.getEffect(),
880 u.getRole(),
881 u.getCause(),
882 u.getAccount());
883 u1.getAnnotation().addAll(u.getAnnotation());
884 return u1;
885 }
886
887 public WasControlledBy newWasControlledBy(WasControlledBy c) {
888 WasControlledBy wcb=newWasControlledBy(c.getEffect(),
889 c.getRole(),
890 c.getCause(),
891 c.getAccount());
892 wcb.setId(c.getId());
893 wcb.getAnnotation().addAll(c.getAnnotation());
894 return wcb;
895 }
896
897 public WasGeneratedBy newWasGeneratedBy(WasGeneratedBy g) {
898 WasGeneratedBy wgb=newWasGeneratedBy(g.getId(),
899 g.getEffect(),
900 g.getRole(),
901 g.getCause(),
902 g.getAccount());
903 wgb.setId(g.getId());
904 wgb.getAnnotation().addAll(g.getAnnotation());
905 return wgb;
906 }
907
908 public WasDerivedFrom newWasDerivedFrom(WasDerivedFrom d) {
909 WasDerivedFrom wdf=newWasDerivedFrom(d.getId(),
910 d.getEffect(),
911 d.getCause(),
912 d.getAccount());
913 wdf.getAnnotation().addAll(d.getAnnotation());
914 return wdf;
915 }
916
917 public WasTriggeredBy newWasTriggeredBy(WasTriggeredBy d) {
918 WasTriggeredBy wtb=newWasTriggeredBy(d.getId(),
919 d.getEffect(),
920 d.getCause(),
921 d.getAccount());
922 wtb.setId(d.getId());
923 wtb.getAnnotation().addAll(d.getAnnotation());
924 return wtb;
925 }
926
927
928
929 public WasGeneratedBy newWasGeneratedBy(String id,
930 ArtifactRef aid,
931 Role role,
932 ProcessRef pid,
933 Collection<AccountRef> accounts) {
934 WasGeneratedBy res=of.createWasGeneratedBy();
935 res.setId(autoGenerateId(wasGenerateByIdPrefix,id));
936 res.setCause(pid);
937 res.setRole(role);
938 res.setEffect(aid);
939 addAccounts(res,accounts);
940 return res;
941 }
942
943 public WasGeneratedByStar newWasGeneratedByStar(ArtifactRef aid,
944 ProcessRef pid,
945 Collection<AccountRef> accounts) {
946 WasGeneratedByStar res=of.createWasGeneratedByStar();
947 res.setCause(pid);
948 res.setEffect(aid);
949 addAccounts(res,accounts);
950 return res;
951 }
952 public WasGeneratedBy newWasGeneratedBy(Artifact a,
953 Role role,
954 Process p,
955 Collection<Account> accounts) {
956 return newWasGeneratedBy(null,a,role,p,accounts);
957 }
958
959 public WasGeneratedBy newWasGeneratedBy(String id,
960 Artifact a,
961 Role role,
962 Process p,
963 Collection<Account> accounts) {
964 ArtifactRef aid=newArtifactRef(a);
965 ProcessRef pid=newProcessRef(p);
966 LinkedList ll=new LinkedList();
967 for (Account acc: accounts) {
968 ll.add(newAccountRef(acc));
969 }
970 return newWasGeneratedBy(id,aid,role,pid,ll);
971 }
972
973
974 public WasGeneratedByStar newWasGeneratedByStar(Artifact a,
975 Process p,
976 Collection<Account> accounts) {
977 ArtifactRef aid=newArtifactRef(a);
978 ProcessRef pid=newProcessRef(p);
979 LinkedList ll=new LinkedList();
980 for (Account acc: accounts) {
981 ll.add(newAccountRef(acc));
982 }
983 return newWasGeneratedByStar(aid,pid,ll);
984 }
985
986
987
988 public WasGeneratedBy newWasGeneratedBy(String id,
989 Artifact a,
990 Role role,
991 Process p,
992 String type,
993 Collection<Account> accounts) {
994 WasGeneratedBy wgb=newWasGeneratedBy(id,a,role,p,accounts);
995 addAnnotation(wgb,of.createType(newType(type)));
996 return wgb;
997 }
998
999 public WasControlledBy newWasControlledBy(ProcessRef pid,
1000 Role role,
1001 AgentRef agid,
1002 Collection<AccountRef> accounts) {
1003 return newWasControlledBy(null,pid,role,agid,accounts);
1004 }
1005
1006 public WasControlledBy newWasControlledBy(String id,
1007 ProcessRef pid,
1008 Role role,
1009 AgentRef agid,
1010 Collection<AccountRef> accounts) {
1011 WasControlledBy res=of.createWasControlledBy();
1012 res.setId(autoGenerateId(wasControlledByIdPrefix,id));
1013 res.setEffect(pid);
1014 res.setRole(role);
1015 res.setCause(agid);
1016 addAccounts(res,accounts);
1017 return res;
1018 }
1019
1020
1021 public WasControlledBy newWasControlledBy(Process p,
1022 Role role,
1023 Agent ag,
1024 Collection<Account> accounts) {
1025 return newWasControlledBy(null,p,role,ag,accounts);
1026 }
1027
1028 public WasControlledBy newWasControlledBy(String id,
1029 Process p,
1030 Role role,
1031 Agent ag,
1032 Collection<Account> accounts) {
1033 AgentRef agid=newAgentRef(ag);
1034 ProcessRef pid=newProcessRef(p);
1035 LinkedList ll=new LinkedList();
1036 for (Account acc: accounts) {
1037 ll.add(newAccountRef(acc));
1038 }
1039 return newWasControlledBy(id,pid,role,agid,ll);
1040 }
1041
1042 public WasControlledBy newWasControlledBy(String id,
1043 Process p,
1044 Role role,
1045 Agent ag,
1046 String type,
1047 Collection<Account> accounts) {
1048 WasControlledBy wcb=newWasControlledBy(id,p,role,ag,accounts);
1049 addAnnotation(wcb,of.createType(newType(type)));
1050 return wcb;
1051 }
1052
1053
1054 public WasDerivedFrom newWasDerivedFrom(String id,
1055 ArtifactRef aid1,
1056 ArtifactRef aid2,
1057 Collection<AccountRef> accounts) {
1058 WasDerivedFrom res=of.createWasDerivedFrom();
1059 res.setId(autoGenerateId(wasDerivedFromIdPrefix,id));
1060 res.setCause(aid2);
1061 res.setEffect(aid1);
1062 addAccounts(res,accounts);
1063 return res;
1064 }
1065
1066 public WasDerivedFromStar newWasDerivedFromStar(ArtifactRef aid1,
1067 ArtifactRef aid2,
1068 Collection<AccountRef> accounts) {
1069 WasDerivedFromStar res=of.createWasDerivedFromStar();
1070 res.setCause(aid2);
1071 res.setEffect(aid1);
1072 addAccounts(res,accounts);
1073 return res;
1074 }
1075
1076 public WasDerivedFrom newWasDerivedFrom(Artifact a1,
1077 Artifact a2,
1078 Collection<Account> accounts) {
1079 return newWasDerivedFrom(null,a1,a2,accounts);
1080 }
1081
1082 public WasDerivedFrom newWasDerivedFrom(String id,
1083 Artifact a1,
1084 Artifact a2,
1085 Collection<Account> accounts) {
1086 ArtifactRef aid1=newArtifactRef(a1);
1087 ArtifactRef aid2=newArtifactRef(a2);
1088 LinkedList ll=new LinkedList();
1089 for (Account acc: accounts) {
1090 ll.add(newAccountRef(acc));
1091 }
1092 return newWasDerivedFrom(id,aid1,aid2,ll);
1093 }
1094
1095 public WasDerivedFromStar newWasDerivedFromStar(Artifact a1,
1096 Artifact a2,
1097 Collection<Account> accounts) {
1098 ArtifactRef aid1=newArtifactRef(a1);
1099 ArtifactRef aid2=newArtifactRef(a2);
1100 LinkedList ll=new LinkedList();
1101 for (Account acc: accounts) {
1102 ll.add(newAccountRef(acc));
1103 }
1104 return newWasDerivedFromStar(aid1,aid2,ll);
1105 }
1106
1107
1108 public WasDerivedFrom newWasDerivedFrom(String id,
1109 Artifact a1,
1110 Artifact a2,
1111 String type,
1112 Collection<Account> accounts) {
1113 WasDerivedFrom wdf=newWasDerivedFrom(id,a1,a2,accounts);
1114 addAnnotation(wdf,of.createType(newType(type)));
1115 return wdf;
1116 }
1117
1118
1119
1120 public WasTriggeredBy newWasTriggeredBy(String id,
1121 ProcessRef pid1,
1122 ProcessRef pid2,
1123 Collection<AccountRef> accounts) {
1124 WasTriggeredBy res=of.createWasTriggeredBy();
1125 res.setId(autoGenerateId(wasTriggeredByIdPrefix,id));
1126 res.setEffect(pid1);
1127 res.setCause(pid2);
1128 addAccounts(res,accounts);
1129 return res;
1130 }
1131
1132 public WasTriggeredByStar newWasTriggeredByStar(ProcessRef pid1,
1133 ProcessRef pid2,
1134 Collection<AccountRef> accounts) {
1135 WasTriggeredByStar res=of.createWasTriggeredByStar();
1136 res.setEffect(pid1);
1137 res.setCause(pid2);
1138 addAccounts(res,accounts);
1139 return res;
1140 }
1141
1142 public WasTriggeredBy newWasTriggeredBy(Process p1,
1143 Process p2,
1144 Collection<Account> accounts) {
1145 return newWasTriggeredBy(null,p1,p2,accounts);
1146 }
1147
1148 public WasTriggeredBy newWasTriggeredBy(String id,
1149 Process p1,
1150 Process p2,
1151 Collection<Account> accounts) {
1152 ProcessRef pid1=newProcessRef(p1);
1153 ProcessRef pid2=newProcessRef(p2);
1154 LinkedList<AccountRef> ll=new LinkedList();
1155 for (Account acc: accounts) {
1156 ll.add(newAccountRef(acc));
1157 }
1158 return newWasTriggeredBy(id,pid1,pid2,ll);
1159 }
1160
1161 public WasTriggeredByStar newWasTriggeredByStar(Process p1,
1162 Process p2,
1163 Collection<Account> accounts) {
1164 ProcessRef pid1=newProcessRef(p1);
1165 ProcessRef pid2=newProcessRef(p2);
1166 LinkedList<AccountRef> ll=new LinkedList();
1167 for (Account acc: accounts) {
1168 ll.add(newAccountRef(acc));
1169 }
1170 return newWasTriggeredByStar(pid1,pid2,ll);
1171 }
1172
1173 public WasTriggeredBy newWasTriggeredBy(String id,
1174 Process p1,
1175 Process p2,
1176 String type,
1177 Collection<Account> accounts) {
1178 WasTriggeredBy wtb=newWasTriggeredBy(p1,p2,accounts);
1179 wtb.setId(id);
1180 addAnnotation(wtb,of.createType(newType(type)));
1181 return wtb;
1182 }
1183
1184
1185 public EmbeddedAnnotation newEmbeddedAnnotation(String id,
1186 String property,
1187 Object value,
1188 Collection<Account> accs) {
1189 LinkedList<AccountRef> ll=new LinkedList();
1190 if (accs!=null) {
1191 for (Account acc: accs) {
1192 ll.add(newAccountRef(acc));
1193 }
1194 }
1195 return newEmbeddedAnnotation(id,property,value,ll,null);
1196 }
1197
1198 public Annotation newAnnotation(String id,
1199 Artifact a,
1200 String property,
1201 Object value,
1202 Collection<Account> accs) {
1203 ArtifactRef aid=newArtifactRef(a);
1204 LinkedList<AccountRef> ll=new LinkedList();
1205 if (accs!=null) {
1206 for (Account acc: accs) {
1207 ll.add(newAccountRef(acc));
1208 }
1209 }
1210 return newAnnotation(id,aid,property,value,ll);
1211 }
1212 public Annotation newAnnotation(String id,
1213 Process p,
1214 String property,
1215 Object value,
1216 Collection<Account> accs) {
1217 ProcessRef pid=newProcessRef(p);
1218 LinkedList<AccountRef> ll=new LinkedList();
1219 if (accs!=null) {
1220 for (Account acc: accs) {
1221 ll.add(newAccountRef(acc));
1222 }
1223 }
1224 return newAnnotation(id,pid,property,value,ll);
1225 }
1226
1227 public Annotation newAnnotation(String id,
1228 Annotation a,
1229 String property,
1230 Object value,
1231 Collection<Account> accs) {
1232 AnnotationRef aid=newAnnotationRef(a);
1233 LinkedList<AccountRef> ll=new LinkedList();
1234 if (accs!=null) {
1235 for (Account acc: accs) {
1236 ll.add(newAccountRef(acc));
1237 }
1238 }
1239 return newAnnotation(id,aid,property,value,ll);
1240 }
1241
1242 public Annotation newAnnotation(String id,
1243 WasDerivedFrom edge,
1244 String property,
1245 Object value,
1246 Collection<Account> accs) {
1247 CausalDependencyRef cid=newCausalDependencyRef(edge);
1248 LinkedList<AccountRef> ll=new LinkedList();
1249 if (accs!=null) {
1250 for (Account acc: accs) {
1251 ll.add(newAccountRef(acc));
1252 }
1253 }
1254 return newAnnotation(id,cid,property,value,ll);
1255 }
1256 public Annotation newAnnotation(String id,
1257 Used edge,
1258 String property,
1259 Object value,
1260 Collection<Account> accs) {
1261 CausalDependencyRef cid=newCausalDependencyRef(edge);
1262 LinkedList<AccountRef> ll=new LinkedList();
1263 if (accs!=null) {
1264 for (Account acc: accs) {
1265 ll.add(newAccountRef(acc));
1266 }
1267 }
1268 return newAnnotation(id,cid,property,value,ll);
1269 }
1270 public Annotation newAnnotation(String id,
1271 WasGeneratedBy edge,
1272 String property,
1273 Object value,
1274 Collection<Account> accs) {
1275 CausalDependencyRef cid=newCausalDependencyRef(edge);
1276 LinkedList<AccountRef> ll=new LinkedList();
1277 if (accs!=null) {
1278 for (Account acc: accs) {
1279 ll.add(newAccountRef(acc));
1280 }
1281 }
1282 return newAnnotation(id,cid,property,value,ll);
1283 }
1284 public Annotation newAnnotation(String id,
1285 WasControlledBy edge,
1286 String property,
1287 Object value,
1288 Collection<Account> accs) {
1289 CausalDependencyRef cid=newCausalDependencyRef(edge);
1290 LinkedList<AccountRef> ll=new LinkedList();
1291 if (accs!=null) {
1292 for (Account acc: accs) {
1293 ll.add(newAccountRef(acc));
1294 }
1295 }
1296 return newAnnotation(id,cid,property,value,ll);
1297 }
1298 public Annotation newAnnotation(String id,
1299 WasTriggeredBy edge,
1300 String property,
1301 Object value,
1302 Collection<Account> accs) {
1303 CausalDependencyRef cid=newCausalDependencyRef(edge);
1304 LinkedList<AccountRef> ll=new LinkedList();
1305 if (accs!=null) {
1306 for (Account acc: accs) {
1307 ll.add(newAccountRef(acc));
1308 }
1309 }
1310 return newAnnotation(id,cid,property,value,ll);
1311 }
1312
1313 public Annotation newAnnotation(String id,
1314 Role role,
1315 String property,
1316 Object value,
1317 Collection<Account> accs) {
1318 RoleRef rid=newRoleRef(role);
1319 LinkedList<AccountRef> ll=new LinkedList();
1320 if (accs!=null) {
1321 for (Account acc: accs) {
1322 ll.add(newAccountRef(acc));
1323 }
1324 }
1325 return newAnnotation(id,rid,property,value,ll);
1326 }
1327
1328 public Property newProperty(String property,
1329 Object value) {
1330 Property res=of.createProperty();
1331 res.setUri(property);
1332 res.setValue(value);
1333 return res;
1334 }
1335
1336 public Property newProperty(Property property) {
1337 return newProperty(property.getUri(),property.getValue());
1338 }
1339
1340
1341 public void addProperty(Annotation ann, Property p) {
1342 ann.getProperty().add(p);
1343 }
1344
1345 public void addProperty(Annotation ann, List<Property> p) {
1346 ann.getProperty().addAll(p);
1347 }
1348
1349 public void addProperty(EmbeddedAnnotation ann, Property p) {
1350 ann.getProperty().add(p);
1351 }
1352
1353 public void addProperty(EmbeddedAnnotation ann, List<Property> p) {
1354 ann.getProperty().addAll(p);
1355 }
1356
1357 public Annotation newAnnotation(String id,
1358 Ref ref,
1359 String property,
1360 Object value,
1361 Collection<AccountRef> accs) {
1362 Annotation res=of.createAnnotation();
1363 res.setId(id);
1364 res.setLocalSubject(ref.getRef());
1365 addProperty(res,newProperty(property,value));
1366 addAccounts(res,accs);
1367 return res;
1368 }
1369
1370 public Annotation newAnnotation(String id,
1371 Object o,
1372 List<Property> properties,
1373 Collection<AccountRef> accs) {
1374 Annotation res=of.createAnnotation();
1375 res.setId(id);
1376 res.setLocalSubject(o);
1377 for (Property property: properties) {
1378 addProperty(res,property);
1379 }
1380 addAccounts(res,accs);
1381 return res;
1382 }
1383
1384 public Annotation newAnnotation(Annotation ann) {
1385 Annotation res=newAnnotation(ann.getId(),
1386 ann.getLocalSubject(),
1387 ann.getProperty(),
1388 ann.getAccount());
1389 return res;
1390 }
1391
1392 public EmbeddedAnnotation newEmbeddedAnnotation(String id,
1393 String property,
1394 Object value,
1395 Collection<AccountRef> accs,
1396 Object dummyParameterForAvoidingSameErasure) {
1397 EmbeddedAnnotation res=of.createEmbeddedAnnotation();
1398 res.setId(id);
1399 addProperty(res,newProperty(property,value));
1400 addAccounts(res,accs);
1401 return res;
1402 }
1403 public EmbeddedAnnotation newEmbeddedAnnotation(String id,
1404 List<Property> properties,
1405 Collection<AccountRef> accs,
1406 Object dummyParameterForAvoidingSameErasure) {
1407 EmbeddedAnnotation res=of.createEmbeddedAnnotation();
1408 res.setId(id);
1409 if (properties!=null) {
1410 addProperty(res,properties);
1411 }
1412 addAccounts(res,accs);
1413 return res;
1414 }
1415
1416
1417 public OPMGraph newOPMGraph(Collection<Account> accs,
1418 Collection<Overlaps> ops,
1419 Collection<Process> ps,
1420 Collection<Artifact> as,
1421 Collection<Agent> ags,
1422 Collection<Object> lks) {
1423 return newOPMGraph(null,accs,ops,ps,as,ags,lks,null);
1424 }
1425
1426 public OPMGraph newOPMGraph(Collection<Account> accs,
1427 Collection<Overlaps> ops,
1428 Collection<Process> ps,
1429 Collection<Artifact> as,
1430 Collection<Agent> ags,
1431 Collection<Object> lks,
1432 Collection<Annotation> anns) {
1433 return newOPMGraph(null,accs,ops,ps,as,ags,lks,anns);
1434 }
1435
1436 public OPMGraph newOPMGraph(String id,
1437 Collection<Account> accs,
1438 Collection<Overlaps> ops,
1439 Collection<Process> ps,
1440 Collection<Artifact> as,
1441 Collection<Agent> ags,
1442 Collection<Object> lks,
1443 Collection<Annotation> anns)
1444 {
1445 OPMGraph res=of.createOPMGraph();
1446 res.setId(autoGenerateId(opmGraphIdPrefix,id));
1447 if (accs!=null) {
1448 Accounts aaccs=of.createAccounts();
1449 aaccs.getAccount().addAll(accs);
1450 if (ops!=null)
1451 aaccs.getOverlaps().addAll(ops);
1452 res.setAccounts(aaccs);
1453
1454 }
1455 if (ps!=null) {
1456 Processes pps=of.createProcesses();
1457 pps.getProcess().addAll(ps);
1458 res.setProcesses(pps);
1459 }
1460 if (as!=null) {
1461 Artifacts aas=of.createArtifacts();
1462 aas.getArtifact().addAll(as);
1463 res.setArtifacts(aas);
1464 }
1465 if (ags!=null) {
1466 Agents aags=of.createAgents();
1467 aags.getAgent().addAll(ags);
1468 res.setAgents(aags);
1469 }
1470 if (lks!=null) {
1471 CausalDependencies ccls=of.createCausalDependencies();
1472 ccls.getUsedOrWasGeneratedByOrWasTriggeredBy().addAll(lks);
1473 res.setCausalDependencies(ccls);
1474 }
1475
1476 if (anns!=null) {
1477 Annotations l=of.createAnnotations();
1478 l.getAnnotation().addAll(anns);
1479 res.setAnnotations(l);
1480 }
1481 return res;
1482 }
1483
1484 public OPMGraph newOPMGraph(Collection<Account> accs,
1485 Overlaps [] ovs,
1486 Process [] ps,
1487 Artifact [] as,
1488 Agent [] ags,
1489 Object [] lks)
1490 {
1491
1492 return newOPMGraph(accs,
1493 ((ovs==null) ? null : Arrays.asList(ovs)),
1494 ((ps==null) ? null : Arrays.asList(ps)),
1495 ((as==null) ? null : Arrays.asList(as)),
1496 ((ags==null) ? null : Arrays.asList(ags)),
1497 ((lks==null) ? null : Arrays.asList(lks)));
1498 }
1499 public OPMGraph newOPMGraph(Collection<Account> accs,
1500 Overlaps [] ovs,
1501 Process [] ps,
1502 Artifact [] as,
1503 Agent [] ags,
1504 Object [] lks,
1505 Annotation [] anns) {
1506 return newOPMGraph(null,accs,ovs,ps,as,ags,lks,anns);
1507 }
1508
1509 public OPMGraph newOPMGraph(String id,
1510 Collection<Account> accs,
1511 Overlaps [] ovs,
1512 Process [] ps,
1513 Artifact [] as,
1514 Agent [] ags,
1515 Object [] lks,
1516 Annotation [] anns)
1517 {
1518
1519 return newOPMGraph(id,
1520 accs,
1521 ((ovs==null) ? null : Arrays.asList(ovs)),
1522 ((ps==null) ? null : Arrays.asList(ps)),
1523 ((as==null) ? null : Arrays.asList(as)),
1524 ((ags==null) ? null : Arrays.asList(ags)),
1525 ((lks==null) ? null : Arrays.asList(lks)),
1526 ((anns==null) ? null : Arrays.asList(anns)));
1527 }
1528
1529 public OPMGraph newOPMGraph(Accounts accs,
1530 Processes ps,
1531 Artifacts as,
1532 Agents ags,
1533 CausalDependencies lks)
1534 {
1535 OPMGraph res=of.createOPMGraph();
1536
1537 res.setAccounts(accs);
1538 res.setProcesses(ps);
1539 res.setArtifacts(as);
1540 res.setAgents(ags);
1541 res.setCausalDependencies(lks);
1542 return res;
1543 }
1544
1545 public OPMGraph newOPMGraph(Accounts accs,
1546 Processes ps,
1547 Artifacts as,
1548 Agents ags,
1549 CausalDependencies lks,
1550 Annotations anns)
1551 {
1552 OPMGraph res=of.createOPMGraph();
1553
1554 res.setAccounts(accs);
1555 res.setProcesses(ps);
1556 res.setArtifacts(as);
1557 res.setAgents(ags);
1558 res.setCausalDependencies(lks);
1559 res.setAnnotations(anns);
1560 return res;
1561 }
1562
1563 public OPMGraph newOPMGraph(OPMGraph graph) {
1564 return newOPMGraph(graph.getAccounts(),
1565 graph.getProcesses(),
1566 graph.getArtifacts(),
1567 graph.getAgents(),
1568 graph.getCausalDependencies(),
1569 graph.getAnnotations());
1570 }
1571
1572
1573 public Accounts newAccounts(Collection<Account> accs,
1574 Collection<Overlaps> ovlps) {
1575 Accounts res=of.createAccounts();
1576 if (accs!=null) {
1577 res.getAccount().addAll(accs);
1578 }
1579 if (ovlps!=null) {
1580 res.getOverlaps().addAll(ovlps);
1581 }
1582 return res;
1583 }
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604 static {
1605 initBuilder();
1606 }
1607 static public DocumentBuilder builder;
1608
1609 static void initBuilder() {
1610 try {
1611 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
1612 docBuilderFactory.setNamespaceAware(true);
1613 builder = docBuilderFactory.newDocumentBuilder();
1614 } catch (ParserConfigurationException ex) {
1615 throw new RuntimeException(ex);
1616 }
1617 }
1618
1619 }
1620