summaryrefslogtreecommitdiffstats
path: root/tags/java/sca/1.5.1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
blob: f34adbc581ced73ea728ba8694898c190b734fc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */

package org.apache.tuscany.sca.assembly.xml;

import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.Callback;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.ComponentReference;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.CompositeReference;
import org.apache.tuscany.sca.assembly.CompositeService;
import org.apache.tuscany.sca.assembly.ConfiguredOperation;
import org.apache.tuscany.sca.assembly.ConstrainingType;
import org.apache.tuscany.sca.assembly.Contract;
import org.apache.tuscany.sca.assembly.ExtensionFactory;
import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.assembly.OperationsConfigurator;
import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.assembly.Wire;
import org.apache.tuscany.sca.assembly.impl.CompositeImpl;
import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ResolverExtension;
import org.apache.tuscany.sca.contribution.service.ContributionReadException;
import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.policy.Intent;
import org.apache.tuscany.sca.policy.IntentAttachPointType;
import org.apache.tuscany.sca.policy.PolicyFactory;
import org.apache.tuscany.sca.policy.PolicySet;
import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
import org.apache.tuscany.sca.policy.util.PolicyComputationUtils;
import org.apache.tuscany.sca.policy.util.PolicyValidationException;
import org.apache.tuscany.sca.policy.util.PolicyValidationUtils;
import org.w3c.dom.Document;

/**
 * A composite processor. 
 * 
 * @version $Rev$ $Date$
 */
public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<Composite> {
    // FIXME: to be refactored
    private XPathFactory xPathFactory = XPathFactory.newInstance();
    
    /**
     * Construct a new composite processor
     * 
     * @param extensionPoints
     * @param extensionProcessor
     */
    public CompositeProcessor(ExtensionPointRegistry extensionPoints,
			StAXArtifactProcessor extensionProcessor,
			StAXAttributeProcessor extensionAttributeProcessor, 
			Monitor monitor) {
        
        this(modelFactories(extensionPoints), 
             extensionProcessor, 
             extensionAttributeProcessor, 
             monitor(extensionPoints));
        
    	this.extensionAttributeProcessor = extensionAttributeProcessor;
    }
    
    /**
     * Constructs a new composite processor
     * 
     * @param modelFactories
     * @param extensionProcessor
     * @param monitor
     */
    private CompositeProcessor(ModelFactoryExtensionPoint modelFactories,
             StAXArtifactProcessor extensionProcessor,
             StAXAttributeProcessor extensionAttributeProcessor,
             Monitor monitor) {
        
    	super(modelFactories.getFactory(ContributionFactory.class),
            modelFactories.getFactory(AssemblyFactory.class),
            modelFactories.getFactory(ExtensionFactory.class),
            modelFactories.getFactory(PolicyFactory.class),
            extensionProcessor, 
            extensionAttributeProcessor,
            monitor);
        
        this.extensionAttributeProcessor = extensionAttributeProcessor;
        
    }
    
    /**
     * Construct a new composite processor
     * 
     * @param contributionFactory
     * @param assemblyFactory
     * @param policyFactory
     * @param extensionProcessor
     */
    public CompositeProcessor(ContributionFactory contributionFactory,
            AssemblyFactory assemblyFactory,
            ExtensionFactory extensionFactory,
            PolicyFactory policyFactory,
            StAXArtifactProcessor extensionProcessor,
            StAXAttributeProcessor extensionAttributeProcessor,
            Monitor monitor) {
        super(contributionFactory, assemblyFactory, extensionFactory, policyFactory, extensionProcessor, extensionAttributeProcessor, monitor);
    }    

    public Composite read(XMLStreamReader reader) throws ContributionReadException {
        Composite composite = null;
        Composite include = null;
        Component component = null;
        Property property = null;
        ComponentService componentService = null;
        ComponentReference componentReference = null;
        ComponentProperty componentProperty = null;
        CompositeService compositeService = null;
        CompositeReference compositeReference = null;
        Contract contract = null;
        Wire wire = null;
        Callback callback = null;
        QName name = null;

        try {
            // Read the composite document
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        name = reader.getName();
    
                        if (COMPOSITE_QNAME.equals(name)) {
    
                            // Read a <composite>
                            composite = assemblyFactory.createComposite();
                            
                            composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
    
                            if(!isSet(reader, TARGET_NAMESPACE)){
                                // spec says that a composite must have a namespace
                                warning("NoCompositeNamespace", composite, composite.getName().toString());   
                            }
                            
                            if(isSet(reader, AUTOWIRE)) {
                                composite.setAutowire(getBoolean(reader, AUTOWIRE));
                            }
                            
                            //handle extension attributes
                            this.readExtendedAttributes(reader, composite);
    
                            composite.setLocal(getBoolean(reader, LOCAL));
                            composite.setConstrainingType(readConstrainingType(reader));
                            policyProcessor.readPolicies(composite, reader);
    
                        } else if (INCLUDE_QNAME.equals(name)) {
    
                            // Read an <include>
                            include = assemblyFactory.createComposite();
                            include.setName(getQName(reader, NAME));
                            include.setURI(getString(reader, URI));
                            include.setUnresolved(true);
                            composite.getIncludes().add(include);
    
                        } else if (SERVICE_QNAME.equals(name)) {
                            if (component != null) {
    
                                // Read a <component><service>
                                componentService = assemblyFactory.createComponentService();
                                contract = componentService;
                                componentService.setName(getString(reader, NAME));
                                
                                //handle extension attributes
                                this.readExtendedAttributes(reader, componentService);
    
                                component.getServices().add(componentService);
                                policyProcessor.readPolicies(contract, reader);
                            } else {
    
                                // Read a <composite><service>
                                compositeService = assemblyFactory.createCompositeService();
                                contract = compositeService;
                                compositeService.setName(getString(reader, NAME));
    
                                String promoted = getString(reader, PROMOTE);
                                if (promoted != null) {
                                    String promotedComponentName;
                                    String promotedServiceName;
                                    int s = promoted.indexOf('/');
                                    if (s == -1) {
                                        promotedComponentName = promoted;
                                        promotedServiceName = null;
                                    } else {
                                        promotedComponentName = promoted.substring(0, s);
                                        promotedServiceName = promoted.substring(s + 1);
                                    }
        
                                    Component promotedComponent = assemblyFactory.createComponent();
                                    promotedComponent.setUnresolved(true);
                                    promotedComponent.setName(promotedComponentName);
                                    compositeService.setPromotedComponent(promotedComponent);
        
                                    ComponentService promotedService = assemblyFactory.createComponentService();
                                    promotedService.setUnresolved(true);
                                    promotedService.setName(promotedServiceName);
                                    compositeService.setPromotedService(promotedService);
                                }
    
                                //handle extension attributes
                                this.readExtendedAttributes(reader, compositeService);
    
                                composite.getServices().add(compositeService);
                                policyProcessor.readPolicies(contract, reader);
                            }
    
                        } else if (REFERENCE_QNAME.equals(name)) {
                            if (component != null) {
                                // Read a <component><reference>
                                componentReference = assemblyFactory.createComponentReference();
                                contract = componentReference;
                                componentReference.setName(getString(reader, NAME));
                                readMultiplicity(componentReference, reader);
                                if (isSet(reader, AUTOWIRE)) {
                                    componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
                                }
                                readTargets(componentReference, reader);
                                componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                                
                                //handle extension attributes
                                this.readExtendedAttributes(reader, componentReference);
    
                                component.getReferences().add(componentReference);
                                policyProcessor.readPolicies(contract, reader);
                            } else {
                                // Read a <composite><reference>
                                compositeReference = assemblyFactory.createCompositeReference();
                                contract = compositeReference;
                                compositeReference.setName(getString(reader, NAME));
                                readMultiplicity(compositeReference, reader);
                                readTargets(compositeReference, reader);
                                String promote = reader.getAttributeValue(null, Constants.PROMOTE);
                                if (promote != null) {
                                    for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
                                        ComponentReference promotedReference =
                                            assemblyFactory.createComponentReference();
                                        promotedReference.setUnresolved(true);
                                        promotedReference.setName(tokens.nextToken());
                                        compositeReference.getPromotedReferences().add(promotedReference);
                                    }
                                }
                                compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                                
                                //handle extension attributes
                                this.readExtendedAttributes(reader, compositeReference);
    
                                composite.getReferences().add(compositeReference);                            
                                policyProcessor.readPolicies(contract, reader);
                            }
    
                        } else if (PROPERTY_QNAME.equals(name)) {
                            if (component != null) {
    
                                // Read a <component><property>
                                componentProperty = assemblyFactory.createComponentProperty();
                                property = componentProperty;
                                String source = getString(reader, SOURCE);
                                if(source!=null) {
                                    source = source.trim();
                                }
                                componentProperty.setSource(source);
                                if (source != null) {
                                    // $<name>/...
                                    if (source.charAt(0) == '$') {
                                        int index = source.indexOf('/');
                                        if (index == -1) {
                                            // Tolerating $prop
                                            source = source + "/";
                                            index = source.length() - 1;
                                        }
                                        source = source.substring(index + 1);
                                        if ("".equals(source)) {
                                            source = ".";
                                        }
                                    }
                                    XPath xpath = xPathFactory.newXPath();
                                    xpath.setNamespaceContext(reader.getNamespaceContext());
                                    try {
                                        componentProperty.setSourceXPathExpression(xpath.compile(source));
                                    } catch (XPathExpressionException e) {
                                    	ContributionReadException ce = new ContributionReadException(e);
                                    	error("ContributionReadException", xpath, ce);
                                        //throw ce;
                                    }
                                }
                                componentProperty.setFile(getString(reader, FILE));
                                
                                //handle extension attributes
                                this.readExtendedAttributes(reader, componentProperty);
    
                                policyProcessor.readPolicies(property, reader);
                                readAbstractProperty(componentProperty, reader);
                                
                                // Read the property value
                                Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                                property.setValue(value);
                                
                                component.getProperties().add(componentProperty);
                            } else {
    
                                // Read a <composite><property>
                                property = assemblyFactory.createProperty();
                                policyProcessor.readPolicies(property, reader);
                                readAbstractProperty(property, reader);
                                
                                // Read the property value
                                Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                                property.setValue(value);
                                
                                composite.getProperties().add(property);
                            }
                            
                            // TUSCANY-1949
                            // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
                            if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
                                property = null;
                                componentProperty = null;
                            }
    
                        } else if (COMPONENT_QNAME.equals(name)) {
    
                            // Read a <component>
                            component = assemblyFactory.createComponent();
                            component.setName(getString(reader, NAME));
                            if (isSet(reader, AUTOWIRE)) {
                                component.setAutowire(getBoolean(reader, AUTOWIRE));
                            }
                            if (isSet(reader, URI)) {
                                component.setURI(getString(reader, URI));
                            }
                            
                            //handle extension attributes
                           this.readExtendedAttributes(reader, component);
                            
                            component.setConstrainingType(readConstrainingType(reader));
                            composite.getComponents().add(component);
                            policyProcessor.readPolicies(component, reader);
    
                        } else if (WIRE_QNAME.equals(name)) {
    
                            // Read a <wire>
                            wire = assemblyFactory.createWire();
                            ComponentReference source = assemblyFactory.createComponentReference();
                            source.setUnresolved(true);
                            source.setName(getString(reader, SOURCE));
                            wire.setSource(source);
    
                            ComponentService target = assemblyFactory.createComponentService();
                            target.setUnresolved(true);
                            target.setName(getString(reader, TARGET));
                            wire.setTarget(target);
    
                            //handle extension attributes
                            this.readExtendedAttributes(reader, wire);
    
                            composite.getWires().add(wire);
                            policyProcessor.readPolicies(wire, reader);
    
                        } else if (CALLBACK_QNAME.equals(name)) {
    
                            // Read a <callback>
                            callback = assemblyFactory.createCallback();
                            contract.setCallback(callback);
                            
                            //handle extension attributes
                            this.readExtendedAttributes(reader, callback);
                            
                            policyProcessor.readPolicies(callback, reader);
    
                        } else if (OPERATION_QNAME.equals(name)) {
    
                            // Read an <operation>
                            ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
                            operation.setName(getString(reader, NAME));
                            operation.setUnresolved(true);
                            if (callback != null) {
                                policyProcessor.readPolicies(operation, reader);
                            } else {
                                policyProcessor.readPolicies(operation, reader);
                            }
                            
                            OperationsConfigurator opConfigurator = null;
                            if ( compositeService != null ) {
                                opConfigurator = compositeService;
                            } else if ( componentService != null ) {
                                opConfigurator = componentService;
                            } else if ( compositeReference != null ) {
                                opConfigurator = compositeReference;
                            } else if ( componentReference != null ) {
                                opConfigurator = componentReference;
                            }
                            
                            opConfigurator.getConfiguredOperations().add(operation);
                        } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
    
                            // Read an implementation.composite
                            Composite implementation = assemblyFactory.createComposite();
                            implementation.setName(getQName(reader, NAME));
                            implementation.setUnresolved(true);
                            
                            //handle extension attributes
                            this.readExtendedAttributes(reader, implementation);
    
                            component.setImplementation(implementation);
                            policyProcessor.readPolicies(implementation, reader);
                        } else {
    
                            // Read an extension element
                            Object extension = extensionProcessor.read(reader);
                            if (extension != null) {
                                if (extension instanceof InterfaceContract) {
    
                                    // <service><interface> and
                                    // <reference><interface>
                                    if (contract != null) {
                                        contract.setInterfaceContract((InterfaceContract)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA10_NS)) {
                                        	error("UnexpectedInterfaceElement", extension);
                                            //throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
                                        } else {
                                            composite.getExtensions().add(extension);
                                        }
                                    }
                                } else if (extension instanceof Binding) {
                                    if ( extension instanceof PolicySetAttachPoint ) {
                                        IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
                                        bindingType.setName(name);
                                        bindingType.setUnresolved(true);
                                        ((PolicySetAttachPoint)extension).setType(bindingType);
                                    }
                                    // <service><binding> and
                                    // <reference><binding>
                                    if (callback != null) {
                                        callback.getBindings().add((Binding)extension);
                                    } else {
                                        if (contract != null) {
                                            contract.getBindings().add((Binding)extension);
                                        } else {
                                            if (name.getNamespaceURI().equals(SCA10_NS)) {
                                            	error("UnexpectedBindingElement", extension);
                                                //throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
                                            } else {
                                                composite.getExtensions().add(extension);
                                            }
                                        }
                                    }
    
                                } else if (extension instanceof Implementation) {
                                    if ( extension instanceof PolicySetAttachPoint ) {
                                        IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
                                        implType.setName(name);
                                        implType.setUnresolved(true);
                                        ((PolicySetAttachPoint)extension).setType(implType);
                                    }
                                    // <component><implementation>
                                    if (component != null) {
                                        component.setImplementation((Implementation)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA10_NS)) {
                                        	error("UnexpectedImplementationElement", extension);
                                            //throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element");
                                        } else {
                                            composite.getExtensions().add(extension);
                                        }
                                    }
                                } else {
    
                                    // Add the extension element to the current
                                    // element
                                    if (callback != null) {
                                        callback.getExtensions().add(extension);
                                    } else if (contract != null) {
                                        contract.getExtensions().add(extension);
                                    } else if (property != null) {
                                        property.getExtensions().add(extension);
                                    } else if (component != null) {
                                        component.getExtensions().add(extension);
                                    } else {
                                        composite.getExtensions().add(extension);
                                    }
                                }
                            }
                        }
                        break;
    
                    case XMLStreamConstants.CHARACTERS:
                        break;
    
                    case END_ELEMENT:
                        name = reader.getName();
    
                        // Clear current state when reading reaching end element
                        if (SERVICE_QNAME.equals(name)) {
                            componentService = null;
                            compositeService = null;
                            contract = null;
                        } else if (INCLUDE_QNAME.equals(name)) {
                            include = null;
                        } else if (REFERENCE_QNAME.equals(name)) {
                            componentReference = null;
                            compositeReference = null;
                            contract = null;
                        } else if (PROPERTY_QNAME.equals(name)) {
                            componentProperty = null;
                            property = null;
                        } else if (COMPONENT_QNAME.equals(name)) {
                            component = null;
                        } else if (WIRE_QNAME.equals(name)) {
                            wire = null;
                        } else if (CALLBACK_QNAME.equals(name)) {
                            callback = null;
                        }
                        break;
                }
    
                // Read the next element
                if (reader.hasNext()) {
                    reader.next();
                }
            }
        }
        catch (XMLStreamException e) {
            ContributionReadException ex = new ContributionReadException(e);
            error("ContributionReadException", reader, ex);
        }
        
        return composite;
    }

    public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {

        // Write <composite> element
        writeStartDocument(writer,
                           COMPOSITE,
                           writeConstrainingType(composite),
                           new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()),
                           new XAttr(NAME, composite.getName().getLocalPart()),
                           new XAttr(LOCAL, composite.isLocal() ? Boolean.TRUE : null),
                           new XAttr(AUTOWIRE, composite.getAutowire()),
                           policyProcessor.writePolicies(composite));
        
        //write extended attributes
        this.writeExtendedAttributes(writer, composite, extensionAttributeProcessor);

        // Write <include> elements
        for (Composite include : composite.getIncludes()) {
            String uri = include.isUnresolved()? include.getURI() : null;
            writeStart(writer,
                       INCLUDE,
                       new XAttr(NAME, include.getName()),
                       new XAttr(URI, uri));

            //write extended attributes
            this.writeExtendedAttributes(writer, include, extensionAttributeProcessor);
            
            writeEnd(writer);
        }

        // Write <service> elements
        for (Service service : composite.getServices()) {
            CompositeService compositeService = (CompositeService)service;
            Component promotedComponent = compositeService.getPromotedComponent();
            ComponentService promotedService = compositeService.getPromotedService();
            String promote;
            if (promotedService != null) {
                if (promotedService.getName() != null) {
                    promote = promotedComponent.getName() + '/' + promotedService.getName();
                } else {
                    promote = promotedComponent.getName();
                }
            } else {
                promote = null;
            }
            writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote),
                       policyProcessor.writePolicies(service));
            
            //write extended attributes
            this.writeExtendedAttributes(writer, service, extensionAttributeProcessor);

            
            // Write service interface
            extensionProcessor.write(service.getInterfaceContract(), writer);

            // Write bindings
            for (Binding binding : service.getBindings()) {
                extensionProcessor.write(binding, writer);
            }

            // Write <callback> element
            if (service.getCallback() != null) {
                Callback callback = service.getCallback();
                writeStart(writer, CALLBACK,
                           policyProcessor.writePolicies(callback));
            
                //write extended attributes
                this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);

                // Write callback bindings
                for (Binding binding : callback.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }
                
                // Write extensions 
                for (Object extension : callback.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }
            
                writeEnd(writer);
            }

            // Write extensions
            for (Object extension : service.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }
            
            writeEnd(writer);
        }

        // Write <component> elements
        for (Component component : composite.getComponents()) {
            writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()),
                       new XAttr(URI, component.getURI()),
                       new XAttr(AUTOWIRE, component.getAutowire()),
                       policyProcessor.writePolicies(component));
            
            //write extended attributes
            this.writeExtendedAttributes(writer, component, extensionAttributeProcessor);
            
            // Write the component implementation
            Implementation implementation = component.getImplementation();
            // check that we really have CompositeImpl and treat this specially. Some
            // extension extend CompositeImpl and we want these to be treated by the extension 
            // processor.
            if ((implementation != null ) && (implementation.getClass().equals(CompositeImpl.class))) {
                writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, ((Composite)implementation).getName()));
                
                //write extended attributes
                this.writeExtendedAttributes(writer, (Composite)implementation, extensionAttributeProcessor);

                writeEnd(writer);
            } else {
                extensionProcessor.write(component.getImplementation(), writer);
            }
            
            for (Object extension : component.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }            
            
            // Write <service> elements
            for (ComponentService service : component.getServices()) {
            	if (service.isCallback() == false){
	                writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
	                           policyProcessor.writePolicies(service));
	
	                //write extended attributes
	                this.writeExtendedAttributes(writer, service, extensionAttributeProcessor);
	
	                // Write service interface
	                extensionProcessor.write(service.getInterfaceContract(), writer);
	                
	                // Write bindings
	                for (Binding binding : service.getBindings()) {
	                    extensionProcessor.write(binding, writer);
	                }
	                
	                // Write <callback> element
	                if (service.getCallback() != null) {
	                    Callback callback = service.getCallback();
	                    writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
	
	                    //write extended attributes
	                    this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
	
	                    // Write bindings
	                    for (Binding binding : callback.getBindings()) {
	                        extensionProcessor.write(binding, writer);
	                    }
	                    
	                    // Write extensions 
	                    for (Object extension : callback.getExtensions()) {
	                        extensionProcessor.write(extension, writer);
	                    }
	                
	                    writeEnd(writer);
	                }
	                
	                // Write extensions
	                for (Object extension : service.getExtensions()) {
	                    extensionProcessor.write(extension, writer);
	                }
	                
	                writeEnd(writer);
            	}
            }
            
            // Write <reference> elements
            for (ComponentReference reference : component.getReferences()) {
            	if (reference.isCallback() == false){
	                writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
	                           new XAttr(AUTOWIRE, reference.getAutowire()),
	                           writeMultiplicity(reference),
	                           writeTargets(reference),
	                           policyProcessor.writePolicies(reference));
	
	                //write extended attributes
	                this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor);
	
	                // Write reference interface
	                extensionProcessor.write(reference.getInterfaceContract(), writer);
	
	                // Write bindings
	                for (Binding binding : reference.getBindings()) {
	                    extensionProcessor.write(binding, writer);
	                }
	                
	                // Write callback
	                if (reference.getCallback() != null) {
	                    Callback callback = reference.getCallback();
	                    writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
	                
	                    //write extended attributes
	                    this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
	
	                    // Write callback bindings
	                    for (Binding binding : callback.getBindings()) {
	                        extensionProcessor.write(binding, writer);
	                    }
	                    
	                    // Write extensions
	                    for (Object extensions : callback.getExtensions()) {
	                        extensionProcessor.write(extensions, writer);
	                    }
	                
	                    writeEnd(writer);
	                }
	                
	                // Write extensions
	                for (Object extensions : reference.getExtensions()) {
	                    extensionProcessor.write(extensions, writer);
	                }
	                
	                writeEnd(writer);
            	}
            }
            
            // Write <property> elements
            for (ComponentProperty property : component.getProperties()) {
                writeStart(writer,
                           PROPERTY,
                           new XAttr(NAME, property.getName()),
                           new XAttr(MUST_SUPPLY, property.isMustSupply()),
                           new XAttr(MANY, property.isMany()),
                           new XAttr(TYPE, property.getXSDType()),
                           new XAttr(ELEMENT, property.getXSDElement()),
                           new XAttr(SOURCE, property.getSource()),
                           new XAttr(FILE, property.getFile()),
                           policyProcessor.writePolicies(property));

                //write extended attributes
                this.writeExtendedAttributes(writer, property, extensionAttributeProcessor);

                // Write property value
                writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);

                // Write extensions
                for (Object extension : property.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }

                writeEnd(writer);
            }
 
            writeEnd(writer);
        }

        // Write <reference> elements
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference)reference;

            // Write list of promoted references
            List<String> promote = new ArrayList<String>();
            for (ComponentReference promoted: compositeReference.getPromotedReferences()) {
                promote.add(promoted.getName());
            }
            
            // Write <reference> element
            writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
                       new XAttr(PROMOTE, promote),
                       writeMultiplicity(reference),
                       policyProcessor.writePolicies(reference));

            //write extended attributes
            this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor);

            // Write reference interface
            extensionProcessor.write(reference.getInterfaceContract(), writer);
            
            // Write bindings
            for (Binding binding : reference.getBindings()) {
                extensionProcessor.write(binding, writer);
            }
            
            // Write <callback> element
            if (reference.getCallback() != null) {
                Callback callback = reference.getCallback();
                writeStart(writer, CALLBACK);
            
                //write extended attributes
                this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);

                // Write callback bindings
                for (Binding binding : callback.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }
                
                // Write extensions
                for (Object extension : callback.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }
            
                writeEnd(writer);
            }
            
            // Write extensions
            for (Object extension : reference.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }
            
            writeEnd(writer);
        }

        // Write <property> elements
        for (Property property : composite.getProperties()) {
            writeStart(writer,
                       PROPERTY,
                       new XAttr(NAME, property.getName()),
                       new XAttr(MUST_SUPPLY, property.isMustSupply()),
                       new XAttr(MANY, property.isMany()),
                       new XAttr(TYPE, property.getXSDType()),
                       new XAttr(ELEMENT, property.getXSDElement()),
                       policyProcessor.writePolicies(property));

            //write extended attributes
            this.writeExtendedAttributes(writer, property, extensionAttributeProcessor);

            // Write property value
            writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);

            // Write extensions
            for (Object extension : property.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }

            writeEnd(writer);
        }

        // Write <wire> elements
        for (Wire wire : composite.getWires()) {
            writeStart(writer, WIRE, new XAttr(SOURCE, wire.getSource().getName()), new XAttr(TARGET, wire
                .getTarget().getName()));
            
            //write extended attributes
            this.writeExtendedAttributes(writer, wire, extensionAttributeProcessor);

            // Write extensions
            for (Object extension : wire.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }
            writeEnd(writer);
        }

        for (Object extension : composite.getExtensions()) {
        		extensionProcessor.write(extension, writer);
        }
        
        writeEndDocument(writer);
    }

    public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException {

        // Resolve constraining type
        ConstrainingType constrainingType = composite.getConstrainingType();
        if (constrainingType != null) {
            constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType);
            composite.setConstrainingType(constrainingType);
        }

        // Resolve includes in the composite
        for (int i = 0, n = composite.getIncludes().size(); i < n; i++) {
            Composite include = composite.getIncludes().get(i);
            if (include != null) {
                include = resolver.resolveModel(Composite.class, include);
                composite.getIncludes().set(i, include);
            }
        }

        // Resolve extensions
        for (Object extension : composite.getExtensions()) {
            if (extension != null) {
                extensionProcessor.resolve(extension, resolver);
            }
        }
        
        //resolve intents and policy sets
        List<Intent> compositeIntents = null;
        List<PolicySet> compositePolicySets = null;
        List<PolicySet> compositeApplicablePolicySets = null;
        resolveIntents(composite.getRequiredIntents(), resolver);
        resolvePolicySets(composite.getPolicySets(), resolver);
        resolvePolicySets(composite.getApplicablePolicySets(), resolver);
        compositeIntents = composite.getRequiredIntents();
        compositePolicySets = composite.getPolicySets();
        compositeApplicablePolicySets = composite.getApplicablePolicySets();

        //Resolve composite services and references
        resolveContracts(composite, composite.getServices(), resolver);
        resolveContracts(composite, composite.getReferences(), resolver);

        // Resolve component implementations, services and references
        for (Component component : composite.getComponents()) {
            constrainingType = component.getConstrainingType();
            if (constrainingType != null) {
                constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType);
                component.setConstrainingType(constrainingType);
            }
            
            //resolve intents and policy sets
            resolveIntents(component.getRequiredIntents(), resolver);
            resolvePolicySets(component.getPolicySets(), resolver);
            resolvePolicySets(component.getApplicablePolicySets(), resolver);
            
            //inherit composite intents and policysets
            PolicyComputationUtils.addDefaultPolicies(compositeIntents,
                                                      compositePolicySets,
                                                      component.getRequiredIntents(),
                                                      component.getPolicySets());

            addInheritedPolicySets(compositeApplicablePolicySets, component.getApplicablePolicySets());

            //resolve component services and references 
            resolveContracts(component, component.getServices(), resolver);
            resolveContracts(component, component.getReferences(), resolver);
            
            for (ComponentProperty componentProperty : component.getProperties()) {
                if (componentProperty.getFile() != null) {
                    Artifact artifact = contributionFactory.createArtifact();
                    artifact.setURI(componentProperty.getFile());
                    artifact = resolver.resolveModel(Artifact.class, artifact);
                    if (artifact.getLocation() != null) {
                        componentProperty.setFile(artifact.getLocation());
                    }
                }
            }
            
            //resolve component implementation
            Implementation implementation = component.getImplementation();
            if (implementation != null) {
                try {
                    //resolve intents and policysets specified on this implementation
                    //before copying them over to the component.  Before that, from the component
                    //copy over the applicablePolicySets alone as it might have to be
                    //used to validate the policysets specified on the implementation
                    
                    resolveImplIntentsAndPolicySets(implementation, 
                                                    component.getApplicablePolicySets(), 
                                                    resolver);

                    copyPoliciesToComponent(component, implementation, resolver, true);
                    
                    //now resolve the implementation so that even if there is a shared instance
                    //for this that is resolved, the specified intents and policysets are safe in the
                    //component and not lost
                    implementation = resolveImplementation(implementation, resolver);
                    
                    //resolved implementation may contain intents and policysets specified at 
                    //componentType (either in the componentType side file or in annotations if its a 
                    //java implementation).  This has to be consolidated in to the component.
                    copyPoliciesToComponent(component, implementation, resolver, false);
                    
                    component.setImplementation(implementation);
                } catch ( PolicyValidationException e ) {
                	error("PolicyImplValidationException", resolver, component.getName(), e.getMessage());
                    //throw new ContributionResolveException("PolicyValidation exception when processing implementation of component '" 
                                                           //+ component.getName() + "' due to " + e.getMessage(), e);
                }
            
            }

            //add model resolver to component
            if (component instanceof ResolverExtension) {
                ((ResolverExtension)component).setModelResolver(resolver);
            }
        }

        // Add model resolver to promoted components
        for (Service service : composite.getServices()) {
            CompositeService compositeService = (CompositeService)service;
            Component promotedComponent = compositeService.getPromotedComponent();
            if (promotedComponent instanceof ResolverExtension) {
                ((ResolverExtension)promotedComponent).setModelResolver(resolver);
            }
        }
    }
    
    private void resolveImplIntentsAndPolicySets(Implementation implementation,
                                                 List<PolicySet> inheritedApplicablePolicySets,
                                                 ModelResolver resolver) throws ContributionResolveException,
                                                                                 PolicyValidationException
                                                        {
        if ( implementation instanceof PolicySetAttachPoint ) {
            PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation;
            
            policiedImpl.getApplicablePolicySets().addAll(inheritedApplicablePolicySets);
            
            resolveIntents(policiedImpl.getRequiredIntents(), resolver);
            PolicyValidationUtils.validateIntents(policiedImpl, policiedImpl.getType());
            
            resolvePolicySets(policiedImpl.getPolicySets(), resolver);
            resolvePolicySets(policiedImpl.getApplicablePolicySets(), resolver);
            
            PolicyValidationUtils.validatePolicySets(policiedImpl);
            
            if ( implementation instanceof OperationsConfigurator ) {
                for ( ConfiguredOperation implConfOp : ((OperationsConfigurator)implementation).getConfiguredOperations() ) {
                    resolveIntents(implConfOp.getRequiredIntents(), resolver);
                    PolicyValidationUtils.validateIntents(implConfOp, policiedImpl.getType());
                    
                    resolvePolicySets(implConfOp.getPolicySets(), resolver);
                    resolvePolicySets(implConfOp.getApplicablePolicySets(), resolver);
                    //add the inherited applicablePolicysets
                    addInheritedPolicySets(policiedImpl.getApplicablePolicySets(), implConfOp.getApplicablePolicySets());
                    
                    PolicyValidationUtils.validatePolicySets(implConfOp, policiedImpl.getType());
                    
                    PolicyComputationUtils.addDefaultPolicies(
                                            ((PolicySetAttachPoint)implementation).getRequiredIntents(),
                                            ((PolicySetAttachPoint)implementation).getPolicySets(),
                                            implConfOp.getRequiredIntents(),
                                            implConfOp.getPolicySets());
                }
            }
        }
    }
    
    private void copyPoliciesToComponent(Component component, 
                                         Implementation implementation, 
                                         ModelResolver resolver,
                                         boolean clearImplSettings) throws ContributionResolveException {
        if (implementation instanceof PolicySetAttachPoint) {
            // Add implementation policies into component, since implementation instances are 
            // reused and it's likely that this implementation instance will not hold after its resolution.
            // On the first call to this method (clearImplSettings=true), we are moving policies from the
            // implementation XML element up to the component.  In this case if there are mutually exclusive
            // policies we must clear the component policy so that the implementation policy "wins".
            // On the second call to this method (clearImplSettings=false), we are moving policies from the
            // componentType implementation up to the component.  In this case if there are mutually
            // exclusive policies it is an error.  This error will be detected later in the PolicyComputer.
            if (clearImplSettings) {
                for (Intent intent : ((PolicySetAttachPoint)implementation).getRequiredIntents()) {
                    for (Intent excluded : intent.getExcludedIntents()) {
                        if (component.getRequiredIntents().contains(excluded)) {
                            component.getRequiredIntents().remove(excluded);
                        }
                        for (Iterator i = component.getPolicySets().iterator(); i.hasNext(); ) {
                            PolicySet cmpPolicySet = (PolicySet) i.next();
                            if (cmpPolicySet.getProvidedIntents().contains(excluded)) {
                                i.remove();
                            }
                        }
                    }
                }
                for (PolicySet policySet : ((PolicySetAttachPoint)implementation).getPolicySets()) {
                    for (Intent intent : policySet.getProvidedIntents()) {
                        for (Intent excluded : intent.getExcludedIntents()) {
                            if (component.getRequiredIntents().contains(excluded)) {
                                component.getRequiredIntents().remove(excluded);
                            }
                            for (Iterator i = component.getPolicySets().iterator(); i.hasNext(); ) {
                                PolicySet cmpPolicySet = (PolicySet) i.next();
                                if (cmpPolicySet.getProvidedIntents().contains(excluded)) {
                                    i.remove();
                                }
                            }
                        }
                    }
                }
            }
            component.getRequiredIntents().addAll(((PolicySetAttachPoint)implementation).getRequiredIntents());
            component.getPolicySets().addAll(((PolicySetAttachPoint)implementation).getPolicySets());
            component.getApplicablePolicySets().addAll(((PolicySetAttachPoint)implementation).getApplicablePolicySets());
            
            if ( implementation instanceof OperationsConfigurator ) {
                boolean notFound;
                List<ConfiguredOperation> opsFromImplementation = new ArrayList<ConfiguredOperation>();
                List<ConfiguredOperation> implConfOperations = 
                    new ArrayList<ConfiguredOperation>(((OperationsConfigurator)implementation).getConfiguredOperations());
                for ( ConfiguredOperation implConfOp : implConfOperations ) {
                    notFound = true;
                    for ( ConfiguredOperation compConfOp : ((OperationsConfigurator)component).getConfiguredOperations() ) {
                        if ( implConfOp.getName().equals(compConfOp.getName()) ) {
                            notFound = false;

                            if (clearImplSettings) {
                                for (Intent intent : implConfOp.getRequiredIntents()) {
                                    for (Intent excluded : intent.getExcludedIntents()) {
                                        if (compConfOp.getRequiredIntents().contains(excluded)) {
                                            compConfOp.getRequiredIntents().remove(excluded);
                                        }
                                    }
                                }
                                for (PolicySet policySet : implConfOp.getPolicySets()) {
                                    for (Intent intent : policySet.getProvidedIntents()) {
                                        for (Intent excluded : intent.getExcludedIntents()) {
                                            if (compConfOp.getRequiredIntents().contains(excluded)) {
                                                compConfOp.getRequiredIntents().remove(excluded);
                                            }
                                            for (Iterator i = compConfOp.getPolicySets().iterator(); i.hasNext(); ) {
                                                PolicySet cmpPolicySet = (PolicySet) i.next();
                                                if (cmpPolicySet.getProvidedIntents().contains(excluded)) {
                                                    i.remove();
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            addInheritedIntents(implConfOp.getRequiredIntents(), compConfOp.getRequiredIntents());
                            addInheritedPolicySets(implConfOp.getPolicySets(), compConfOp.getPolicySets());
                            addInheritedPolicySets(implConfOp.getApplicablePolicySets(), compConfOp.getApplicablePolicySets());
                        }
                    }
                    
                    if ( notFound ) {
                        opsFromImplementation.add(implConfOp);
                    }
                    
                    if ( clearImplSettings ) {
                        ((OperationsConfigurator)implementation).getConfiguredOperations().remove(implConfOp);
                    }
                }
                ((OperationsConfigurator)component).getConfiguredOperations().addAll(opsFromImplementation);
            }
            
            if ( clearImplSettings ) {
                ((PolicySetAttachPoint)implementation).getRequiredIntents().clear();
                ((PolicySetAttachPoint)implementation).getPolicySets().clear();
            }
        }
    }
    
    
    public QName getArtifactType() {
        return COMPOSITE_QNAME;
    }

    public Class<Composite> getModelType() {
        return Composite.class;
    }

    /**
     * Returns the model factory extension point to use.
     * 
     * @param extensionPoints
     * @return
     */
    private static ModelFactoryExtensionPoint modelFactories(ExtensionPointRegistry extensionPoints) {
        return extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
    }
    
    /**
     * Returns the monitor to use.
     * 
     * @param extensionPoints
     * @return
     */
    private static Monitor monitor(ExtensionPointRegistry extensionPoints) {
        UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
        if (utilities != null) {
            MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
            if (monitorFactory != null) {
                return monitorFactory.createMonitor();
            }
        }
        return null;
    }
    
}