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 package org.ogf.graap.wsag.samples;
36
37 import java.util.Map;
38
39 import org.apache.log4j.Logger;
40 import org.apache.xmlbeans.XmlObject;
41 import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType;
42 import org.ogf.graap.wsag.api.Agreement;
43 import org.ogf.graap.wsag.api.AgreementFactory;
44 import org.ogf.graap.wsag.api.AgreementOffer;
45 import org.ogf.graap.wsag.api.Negotiation;
46 import org.ogf.graap.wsag.api.exceptions.AgreementFactoryException;
47 import org.ogf.graap.wsag.api.exceptions.NegotiationFactoryException;
48 import org.ogf.graap.wsag.api.types.AbstractAgreementFactoryType;
49 import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
50 import org.ogf.schemas.graap.wsAgreement.ServiceDescriptionTermType;
51 import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationContextType;
52 import org.w3c.dom.Node;
53
54
55
56
57
58
59
60
61 @Deprecated
62 public class SampleAgreementFactory extends AbstractAgreementFactoryType
63 implements AgreementFactory
64 {
65
66 private static Logger log = Logger.getLogger( SampleAgreementFactory.class );
67
68
69
70
71 public SampleAgreementFactory()
72 {
73 super();
74 }
75
76
77
78
79 @Override
80 public AgreementTemplateType[] getTemplates()
81 {
82
83
84 AgreementTemplateType template1 = AgreementTemplateType.Factory.newInstance();
85 template1.setTemplateId( "SampleComputeResources" );
86 template1.setAgreementId( "SampleAgreementId_1" );
87 template1.addNewContext();
88 template1.addNewCreationConstraints();
89 ServiceDescriptionTermType sdt = template1.addNewTerms().addNewAll().addNewServiceDescriptionTerm();
90
91
92 sdt.setName( "sample_service_description_term" );
93 sdt.setServiceName( "sample_service" );
94
95
96 JobDefinitionType jdef = JobDefinitionType.Factory.newInstance();
97 jdef.addNewJobDescription().addNewResources().addNewCandidateHosts().addHostName( "some_host" );
98
99 Node sdtDoc = sdt.getDomNode();
100 Node imported = sdtDoc.getOwnerDocument().importNode( jdef.getDomNode(), true );
101 sdtDoc.appendChild( imported );
102
103 AgreementTemplateType template2 = AgreementTemplateType.Factory.newInstance();
104 template2.setTemplateId( "SampleOtherResources" );
105 template2.setAgreementId( "SampleAgreementId_2" );
106 template2.addNewContext();
107 template2.addNewCreationConstraints();
108 sdt = template2.addNewTerms().addNewAll().addNewServiceDescriptionTerm();
109
110
111 sdtDoc = sdt.getDomNode();
112 imported = sdtDoc.getOwnerDocument().importNode( jdef.getDomNode(), true );
113 sdtDoc.appendChild( imported );
114
115 return new AgreementTemplateType[] { template1, template2 };
116 }
117
118
119
120
121 public Agreement createAgreement( AgreementOffer offer ) throws AgreementFactoryException
122 {
123
124 SampleAgreement agreement = new SampleAgreement( offer );
125
126
127 if ( ( offer.getTerms() != null ) && ( offer.getTerms().getAll() != null ) )
128 {
129
130 agreement.setTerms( offer.getTerms() );
131
132
133 ServiceDescriptionTermType[] sdts = offer.getTerms().getAll().getServiceDescriptionTermArray();
134 if ( ( sdts != null ) && ( sdts.length == 1 ) && ( sdts[0].getName().equals( "TEST_EXCEPTION" ) ) )
135 {
136 String message = "No ServiceDescriptionTerms defined.";
137 log.error( message );
138
139
140 throw new AgreementFactoryException( message );
141 }
142
143 }
144
145 if ( offer.getContext() != null )
146 {
147 agreement.setContext( offer.getContext() );
148 }
149
150 return agreement;
151 }
152
153
154
155
156 public Negotiation
157 initiateNegotiation( NegotiationContextType context, XmlObject[] criticalExtensions,
158 XmlObject[] nonCriticalExtensions, Map<String, Object> environment )
159 throws NegotiationFactoryException
160 {
161
162
163
164
165
166 throw new UnsupportedOperationException();
167 }
168
169 }