|
Lines 13-27
Link Here
|
| 13 |
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional; |
13 |
package org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional; |
| 14 |
|
14 |
|
| 15 |
import java.io.ByteArrayInputStream; |
15 |
import java.io.ByteArrayInputStream; |
| 16 |
import java.io.IOException; |
|
|
| 17 |
import java.io.InputStream; |
16 |
import java.io.InputStream; |
| 18 |
import java.net.URL; |
|
|
| 19 |
import java.util.ArrayList; |
17 |
import java.util.ArrayList; |
| 20 |
import java.util.HashMap; |
18 |
import java.util.HashMap; |
| 21 |
import java.util.Iterator; |
|
|
| 22 |
import java.util.List; |
19 |
import java.util.List; |
| 23 |
|
20 |
|
| 24 |
import org.apache.muse.tools.Activator; |
21 |
import javax.xml.namespace.QName; |
|
|
22 |
|
| 23 |
import org.apache.muse.util.xml.XmlUtils; |
| 24 |
import org.apache.muse.ws.addressing.soap.SoapFault; |
| 25 |
import org.apache.muse.ws.resource.sg.WssgConstants; |
| 25 |
import org.apache.ws.muse.descriptor.CapabilityType; |
26 |
import org.apache.ws.muse.descriptor.CapabilityType; |
| 26 |
import org.apache.ws.muse.descriptor.DescriptorFactory; |
27 |
import org.apache.ws.muse.descriptor.DescriptorFactory; |
| 27 |
import org.apache.ws.muse.descriptor.DocumentRoot; |
28 |
import org.apache.ws.muse.descriptor.DocumentRoot; |
|
Lines 31-66
Link Here
|
| 31 |
import org.apache.ws.muse.descriptor.ResourceTypeType; |
32 |
import org.apache.ws.muse.descriptor.ResourceTypeType; |
| 32 |
import org.apache.ws.muse.descriptor.WsdlType; |
33 |
import org.apache.ws.muse.descriptor.WsdlType; |
| 33 |
import org.eclipse.core.resources.IFile; |
34 |
import org.eclipse.core.resources.IFile; |
| 34 |
import org.eclipse.core.runtime.CoreException; |
|
|
| 35 |
import org.eclipse.core.runtime.NullProgressMonitor; |
35 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 36 |
import org.eclipse.emf.common.util.URI; |
36 |
import org.eclipse.emf.common.util.URI; |
| 37 |
import org.eclipse.emf.ecore.EStructuralFeature; |
|
|
| 38 |
import org.eclipse.emf.ecore.resource.Resource; |
37 |
import org.eclipse.emf.ecore.resource.Resource; |
| 39 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
38 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
| 40 |
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
39 |
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| 41 |
import org.eclipse.emf.ecore.util.BasicExtendedMetaData; |
|
|
| 42 |
import org.eclipse.emf.ecore.util.ExtendedMetaData; |
| 43 |
import org.eclipse.emf.ecore.util.FeatureMap; |
| 44 |
import org.eclipse.emf.ecore.xml.type.AnyType; |
| 45 |
import org.eclipse.emf.ecore.xml.type.XMLTypeFactory; |
| 46 |
import org.eclipse.tptp.wsdm.model.MetadataDescriptor; |
| 47 |
import org.eclipse.tptp.wsdm.tooling.editor.capability.util.internal.MetaDataUtils; |
| 48 |
import org.eclipse.tptp.wsdm.tooling.editor.mrt.servicegroup.utils.internal.ServiceGroupUtils; |
| 49 |
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.NewNameGenerator; |
40 |
import org.eclipse.tptp.wsdm.tooling.editor.ui.internal.NewNameGenerator; |
| 50 |
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability; |
41 |
import org.eclipse.tptp.wsdm.tooling.model.capabilities.Capability; |
| 51 |
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType; |
42 |
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceType; |
| 52 |
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceTypeFactory; |
43 |
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.ManageableResourceTypeFactory; |
| 53 |
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.MembershipContentRuleType; |
44 |
import org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.MembershipContentRuleType; |
| 54 |
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.InitialValuesType; |
45 |
import org.eclipse.tptp.wsdm.tooling.util.internal.CustomMrtResourceFactoryImpl; |
| 55 |
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.MetadataDescriptorFactory; |
|
|
| 56 |
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.PropertyType; |
| 57 |
import org.eclipse.tptp.wsdm.tooling.model.metadataDescriptor.impl.MetadataDescriptorFactoryImpl; |
| 58 |
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils; |
46 |
import org.eclipse.tptp.wsdm.tooling.util.internal.EclipseUtils; |
| 59 |
import org.eclipse.tptp.wsdm.tooling.util.internal.IFile2Capability; |
|
|
| 60 |
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils; |
47 |
import org.eclipse.tptp.wsdm.tooling.util.internal.MrtUtils; |
| 61 |
import org.eclipse.tptp.wsdm.tooling.util.internal.RmdUtils; |
|
|
| 62 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants; |
48 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmConstants; |
| 63 |
import org.eclipse.tptp.wsdm.tooling.util.internal.CustomMrtResourceFactoryImpl; |
49 |
import org.eclipse.tptp.wsdm.tooling.util.internal.WsdmToolingLog; |
|
|
50 |
import org.w3c.dom.Document; |
| 51 |
import org.w3c.dom.Element; |
| 64 |
/** |
52 |
/** |
| 65 |
* This class analyzes the given manageable resource type and provide an extra |
53 |
* This class analyzes the given manageable resource type and provide an extra |
| 66 |
* resource type for muse descriptor (ServiceGroupEntry), if manageable |
54 |
* resource type for muse descriptor (ServiceGroupEntry), if manageable |
|
Lines 76-89
Link Here
|
| 76 |
|
64 |
|
| 77 |
private ResourceTypeType _serviceGroupEntryResorceType; |
65 |
private ResourceTypeType _serviceGroupEntryResorceType; |
| 78 |
|
66 |
|
| 79 |
private ManageableResourceType _mrt; |
|
|
| 80 |
|
| 81 |
private ExtendedMetaData _extendedMetaData; |
| 82 |
|
| 83 |
private ManageableResourceType _serviceGroupEntrymrt; |
67 |
private ManageableResourceType _serviceGroupEntrymrt; |
| 84 |
|
68 |
|
| 85 |
private List _fileLocation ; |
|
|
| 86 |
|
| 87 |
private HashMap _prefixNamespaceMap; |
69 |
private HashMap _prefixNamespaceMap; |
| 88 |
|
70 |
|
| 89 |
/** |
71 |
/** |
|
Lines 95-102
Link Here
|
| 95 |
public ServiceGroupInspector(ManageableResourceType mrt,DocumentRoot root) |
77 |
public ServiceGroupInspector(ManageableResourceType mrt,DocumentRoot root) |
| 96 |
{ |
78 |
{ |
| 97 |
_root = root; |
79 |
_root = root; |
| 98 |
_mrt = mrt; |
|
|
| 99 |
_extendedMetaData = createExtendedMetaData(); |
| 100 |
} |
80 |
} |
| 101 |
|
81 |
|
| 102 |
/** |
82 |
/** |
|
Lines 107-152
Link Here
|
| 107 |
public ResourceTypeType inspect(Capability[] mrtCapabilities) |
87 |
public ResourceTypeType inspect(Capability[] mrtCapabilities) |
| 108 |
{ |
88 |
{ |
| 109 |
|
89 |
|
| 110 |
for(int i =0;i<mrtCapabilities.length;i++) |
90 |
if(hasServiceGroupCapabilities(mrtCapabilities)) |
| 111 |
{ |
91 |
return createServiceGroupEntryResourceType(); |
| 112 |
if(hasServiceGroupCapabilities(mrtCapabilities)) |
|
|
| 113 |
{ |
| 114 |
addMandatoryFiles(); |
| 115 |
return createServiceGroupEntryResourceType(); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
return null; |
92 |
return null; |
| 120 |
} |
93 |
} |
| 121 |
|
94 |
|
| 122 |
private void addMandatoryFiles() |
|
|
| 123 |
{ |
| 124 |
_fileLocation = new ArrayList(); |
| 125 |
boolean hasSGCapability = workspaceHasServiceGroupCapability(); |
| 126 |
boolean hasSGRmd = workspaceHasServiceGroupRMD(); |
| 127 |
try |
| 128 |
{ |
| 129 |
if(hasSGCapability && hasSGRmd) |
| 130 |
{ |
| 131 |
copyMemberRulesToRMD(); |
| 132 |
|
| 133 |
}else if(hasSGCapability && !hasSGRmd) |
| 134 |
{ |
| 135 |
createRMDFile(); |
| 136 |
copyMemberRulesToRMD(); |
| 137 |
} |
| 138 |
else |
| 139 |
{ |
| 140 |
createServiceGroupCapability(); |
| 141 |
createRMDFile(); |
| 142 |
copyMemberRulesToRMD(); |
| 143 |
} |
| 144 |
}catch (Exception ex) |
| 145 |
{ |
| 146 |
ex.printStackTrace(); |
| 147 |
} |
| 148 |
|
| 149 |
} |
| 150 |
private boolean hasServiceGroupCapabilities(Capability[] mrtCapabilities) |
95 |
private boolean hasServiceGroupCapabilities(Capability[] mrtCapabilities) |
| 151 |
{ |
96 |
{ |
| 152 |
boolean hasServiceGroupCapability = false; |
97 |
boolean hasServiceGroupCapability = false; |
|
Lines 163-217
Link Here
|
| 163 |
return hasServiceGroupCapability && hasServiceGroupRegistration; |
108 |
return hasServiceGroupCapability && hasServiceGroupRegistration; |
| 164 |
} |
109 |
} |
| 165 |
|
110 |
|
| 166 |
private void createRMDFile() |
|
|
| 167 |
{ |
| 168 |
URL serviceGroupRMDURL = Activator.getDefault().getBundle().getEntry("artifacts/resourceTypes/ServiceGroupCapability.rmd"); |
| 169 |
try { |
| 170 |
InputStream is = serviceGroupRMDURL.openStream(); |
| 171 |
IFile serviceGroupRMDIFile = EclipseUtils.getIFile(_mrtParentDirName+"/ServiceGroupCapability.rmd"); |
| 172 |
|
| 173 |
if(!serviceGroupRMDIFile.exists()) |
| 174 |
{ |
| 175 |
serviceGroupRMDIFile.create(is, true, new NullProgressMonitor()); |
| 176 |
} |
| 177 |
else |
| 178 |
{ |
| 179 |
serviceGroupRMDIFile.setContents(is, IFile.FORCE, new NullProgressMonitor()); |
| 180 |
} |
| 181 |
|
| 182 |
_fileLocation.add(serviceGroupRMDIFile); |
| 183 |
} catch (Exception e) { |
| 184 |
// TODO Auto-generated catch block |
| 185 |
e.printStackTrace(); |
| 186 |
} |
| 187 |
|
| 188 |
} |
| 189 |
|
| 190 |
private IFile createServiceGroupCapability() |
| 191 |
{ |
| 192 |
try { |
| 193 |
URL sgCapabilityURL = Activator.getDefault().getBundle().getEntry("artifacts/resourceTypes/ServiceGroupCapability.wsdl"); |
| 194 |
InputStream is = sgCapabilityURL.openStream(); |
| 195 |
IFile sgCapabilityIFile = EclipseUtils.getIFile(_mrtParentDirName+"/ServiceGroupCapability.mcap"); |
| 196 |
if(!sgCapabilityIFile.exists()) |
| 197 |
{ |
| 198 |
sgCapabilityIFile.create(is, true, new NullProgressMonitor()); |
| 199 |
} |
| 200 |
else |
| 201 |
{ |
| 202 |
sgCapabilityIFile.setContents(is, IFile.FORCE, new NullProgressMonitor()); |
| 203 |
} |
| 204 |
|
| 205 |
_fileLocation.add(sgCapabilityIFile); |
| 206 |
|
| 207 |
return sgCapabilityIFile; |
| 208 |
} catch (Exception e) { |
| 209 |
// TODO Auto-generated catch block |
| 210 |
e.printStackTrace(); |
| 211 |
} |
| 212 |
return null; |
| 213 |
} |
| 214 |
|
| 215 |
/** |
111 |
/** |
| 216 |
* Returns the initial instances |
112 |
* Returns the initial instances |
| 217 |
* @return InitialInstancesType[] |
113 |
* @return InitialInstancesType[] |
|
Lines 242-256
Link Here
|
| 242 |
{ |
138 |
{ |
| 243 |
createServiceGroupEntryMrt(); |
139 |
createServiceGroupEntryMrt(); |
| 244 |
_serviceGroupEntryResorceType = createServiceGroupEntryMuseResourceType(); |
140 |
_serviceGroupEntryResorceType = createServiceGroupEntryMuseResourceType(); |
| 245 |
_mrt.getImplements().remove(WsdmConstants.SERVICE_GROUP_CAPABILITY_LOCATION); |
|
|
| 246 |
_mrt.getImplements().add("platform:/resource"+_mrtParentDirName+"/ServiceGroupCapability.mcap"); |
| 247 |
saveMRTFile(_mrt); |
| 248 |
return _serviceGroupEntryResorceType; |
141 |
return _serviceGroupEntryResorceType; |
| 249 |
} |
142 |
} |
| 250 |
|
143 |
|
| 251 |
private void createServiceGroupEntryMrt() |
144 |
private void createServiceGroupEntryMrt() |
| 252 |
{ |
145 |
{ |
| 253 |
//_serviceGroupEntrymrt = ManageableResourceTypeFactory.eINSTANCE.createManageableResourceType(); |
|
|
| 254 |
org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.DocumentRoot documentRoot = ManageableResourceTypeFactory.eINSTANCE.createDocumentRoot(); |
146 |
org.eclipse.tptp.wsdm.tooling.model.manageableResourceType.DocumentRoot documentRoot = ManageableResourceTypeFactory.eINSTANCE.createDocumentRoot(); |
| 255 |
_serviceGroupEntrymrt = ManageableResourceTypeFactory.eINSTANCE.createManageableResourceType(); |
147 |
_serviceGroupEntrymrt = ManageableResourceTypeFactory.eINSTANCE.createManageableResourceType(); |
| 256 |
documentRoot.setManageableResource(_serviceGroupEntrymrt); |
148 |
documentRoot.setManageableResource(_serviceGroupEntrymrt); |
|
Lines 322-434
Link Here
|
| 322 |
return resourceType; |
214 |
return resourceType; |
| 323 |
} |
215 |
} |
| 324 |
|
216 |
|
| 325 |
private boolean workspaceHasServiceGroupCapability() |
|
|
| 326 |
{ |
| 327 |
List fileList = ServiceGroupUtils.getFilesFromDirectory(_mrtParentDirName); |
| 328 |
for(Iterator iter = fileList.iterator();iter.hasNext();) |
| 329 |
{ |
| 330 |
IFile file = (IFile) iter.next(); |
| 331 |
if(file.getFileExtension() == "mcap") |
| 332 |
{ |
| 333 |
try |
| 334 |
{ |
| 335 |
IFile2Capability file2Capability = new IFile2Capability(file); |
| 336 |
Capability capability = file2Capability.getCapability(); |
| 337 |
if(capability.getNamespace().equals(WsdmConstants.SERVICE_GROUP_NS)) |
| 338 |
{ |
| 339 |
return true; |
| 340 |
} |
| 341 |
}catch(Exception e) |
| 342 |
{ |
| 343 |
continue; |
| 344 |
} |
| 345 |
} |
| 346 |
} |
| 347 |
return false; |
| 348 |
} |
| 349 |
|
| 350 |
private boolean workspaceHasServiceGroupRMD() |
| 351 |
{ |
| 352 |
List fileList = ServiceGroupUtils.getFilesFromDirectory(_mrtParentDirName); |
| 353 |
for(Iterator iter = fileList.iterator();iter.hasNext();) |
| 354 |
{ |
| 355 |
IFile file = (IFile) iter.next(); |
| 356 |
if(file.getFileExtension() == "rmd") |
| 357 |
{ |
| 358 |
try |
| 359 |
{ |
| 360 |
if(RmdUtils.getDocumentRoot(file).getDefinitions().getTargetNamespace().equals(WsdmConstants.SERVICE_GROUP_NS)) |
| 361 |
return true; |
| 362 |
}catch(Exception e) |
| 363 |
{ |
| 364 |
continue; |
| 365 |
} |
| 366 |
} |
| 367 |
} |
| 368 |
return false; |
| 369 |
} |
| 370 |
|
| 371 |
private void copyMemberRulesToRMD() throws CoreException |
| 372 |
{ |
| 373 |
|
| 374 |
try { |
| 375 |
|
| 376 |
IFile file = EclipseUtils.getIFile(_mrtParentDirName+"/ServiceGroupCapability.mcap"); |
| 377 |
IFile2Capability file2Capability = new IFile2Capability(file); |
| 378 |
Capability sgCapability = file2Capability.getCapability(); |
| 379 |
MetadataDescriptor descriptor = sgCapability.getMetadata(); |
| 380 |
MetadataDescriptorFactory _rmdFactory = new MetadataDescriptorFactoryImpl(); |
| 381 |
|
| 382 |
|
| 383 |
List memberShipContentRuleList = _mrt.getMembershipContentRule(); |
| 384 |
InitialValuesType initialValuesType = _rmdFactory.createInitialValuesType(); |
| 385 |
|
| 386 |
for(int i = 0; i<memberShipContentRuleList.size();i++) |
| 387 |
{ |
| 388 |
FeatureMap fm = initialValuesType.getAny(); |
| 389 |
String namespace = WsdmConstants.SERVICE_GROUP_NS; |
| 390 |
String name = "MembershipContentRule"; |
| 391 |
_prefixNamespaceMap = new HashMap(); |
| 392 |
AnyType anyType = XMLTypeFactory.eINSTANCE.createAnyType(); |
| 393 |
String xmlAttribute=""; |
| 394 |
String xmlNamespace = ""; |
| 395 |
String tns=""; |
| 396 |
MembershipContentRuleType rule = (MembershipContentRuleType) memberShipContentRuleList.get(i); |
| 397 |
for(Iterator iter = rule.getContentElements().iterator();iter.hasNext();) |
| 398 |
{ |
| 399 |
String contentElements = (String)iter.next(); |
| 400 |
tns = getNamespace(contentElements); |
| 401 |
String localName = getLocalName(contentElements); |
| 402 |
preparePrfixNamespaceMap(tns); |
| 403 |
if(xmlAttribute.length() !=0) |
| 404 |
xmlAttribute = xmlAttribute + " " + (String)_prefixNamespaceMap.get(tns)+":"+ localName; |
| 405 |
else |
| 406 |
xmlAttribute =(String)_prefixNamespaceMap.get(tns)+":"+ localName; |
| 407 |
String xmlns = "xmlns:" + _prefixNamespaceMap.get(tns); |
| 408 |
EStructuralFeature pfx1Attribute = _extendedMetaData.demandFeature(null, xmlns, false); |
| 409 |
anyType.eSet(pfx1Attribute, tns); |
| 410 |
} |
| 411 |
EStructuralFeature memberShipContentRule = _extendedMetaData.demandFeature(namespace,name, true); |
| 412 |
fm.add(memberShipContentRule, anyType); |
| 413 |
EStructuralFeature contentElementsAttribute = _extendedMetaData.demandFeature(null, "ContentElements", false); |
| 414 |
anyType.eSet(contentElementsAttribute, xmlAttribute); |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
PropertyType propertyType = descriptor.getPropertyMetadata("MembershipContentRule", WsdmConstants.SERVICE_GROUP_NS); |
| 419 |
propertyType.setInitialValues(initialValuesType); |
| 420 |
MetaDataUtils.save(descriptor, new NullProgressMonitor()); |
| 421 |
|
| 422 |
} catch (Exception e){ |
| 423 |
e.printStackTrace(); |
| 424 |
} |
| 425 |
|
| 426 |
} |
| 427 |
|
| 428 |
private String getNamespace(String contentElement) |
217 |
private String getNamespace(String contentElement) |
| 429 |
{ |
218 |
{ |
| 430 |
return contentElement.substring(1,contentElement.lastIndexOf('}')); |
219 |
return contentElement.substring(1,contentElement.lastIndexOf('}')); |
| 431 |
} |
220 |
} |
|
|
221 |
|
| 432 |
private void preparePrfixNamespaceMap(String contentElement) |
222 |
private void preparePrfixNamespaceMap(String contentElement) |
| 433 |
{ |
223 |
{ |
| 434 |
if(!_prefixNamespaceMap.containsKey(contentElement)) |
224 |
if(!_prefixNamespaceMap.containsKey(contentElement)) |
|
Lines 455-467
Link Here
|
| 455 |
{ |
245 |
{ |
| 456 |
return namespace.substring(namespace.lastIndexOf('}')+1); |
246 |
return namespace.substring(namespace.lastIndexOf('}')+1); |
| 457 |
} |
247 |
} |
| 458 |
private ExtendedMetaData createExtendedMetaData() |
248 |
|
| 459 |
{ |
|
|
| 460 |
ResourceSet resourceSet = new ResourceSetImpl(); |
| 461 |
ExtendedMetaData extendedMetaData = new BasicExtendedMetaData( |
| 462 |
resourceSet.getPackageRegistry()); |
| 463 |
return extendedMetaData; |
| 464 |
} |
| 465 |
/** |
249 |
/** |
| 466 |
* This method will returns the extra generated ManageableResourceType object equivalent to ServiceGroupEntry. |
250 |
* This method will returns the extra generated ManageableResourceType object equivalent to ServiceGroupEntry. |
| 467 |
*/ |
251 |
*/ |
|
Lines 482-572
Link Here
|
| 482 |
*/ |
266 |
*/ |
| 483 |
public void persistArtifacts() |
267 |
public void persistArtifacts() |
| 484 |
{ |
268 |
{ |
| 485 |
ResourceSet rs = new ResourceSetImpl(); |
269 |
try{ |
| 486 |
byte[] rawNewMRT = MrtUtils.serializeMRT(_serviceGroupEntrymrt, rs, URI |
270 |
ResourceSet rs = new ResourceSetImpl(); |
| 487 |
.createURI("dummy.xml"), true); |
271 |
rs.getResourceFactoryRegistry().getExtensionToFactoryMap() |
| 488 |
InputStream stream = new ByteArrayInputStream(rawNewMRT); |
272 |
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new CustomMrtResourceFactoryImpl()); |
| 489 |
|
273 |
String serviceGroupMrt = _mrtParentDirName + "/"+ "ServiceGroupEntry.mrt"; |
| 490 |
try |
274 |
URI uri = URI.createPlatformResourceURI(serviceGroupMrt); |
| 491 |
{ |
275 |
byte[] rawNewMRT = MrtUtils.serializeMRT(_serviceGroupEntrymrt, rs, uri, true); |
| 492 |
String serviceGroupMrt = _mrtParentDirName + "/" |
276 |
InputStream stream = new ByteArrayInputStream(rawNewMRT); |
| 493 |
+ "ServiceGroupEntry.mrt"; |
277 |
IFile subManagerMrtFile = EclipseUtils.getIFile(serviceGroupMrt); |
| 494 |
IFile serviceGroupMrtFile = EclipseUtils.getIFile(serviceGroupMrt); |
278 |
if (subManagerMrtFile.exists()) |
| 495 |
if (serviceGroupMrtFile.exists()) |
|
|
| 496 |
{ |
279 |
{ |
| 497 |
serviceGroupMrtFile.setContents(stream, true, true, |
280 |
subManagerMrtFile.setContents(stream, true, true, |
| 498 |
new NullProgressMonitor()); |
281 |
new NullProgressMonitor()); |
| 499 |
} |
282 |
} |
| 500 |
else |
283 |
else |
| 501 |
{ |
284 |
{ |
| 502 |
serviceGroupMrtFile.create(stream, true, |
285 |
subManagerMrtFile.create(stream, true, |
| 503 |
new NullProgressMonitor()); |
286 |
new NullProgressMonitor()); |
| 504 |
} |
|
|
| 505 |
try |
| 506 |
{ |
| 507 |
stream.close(); |
| 508 |
} |
| 509 |
catch (IOException e) |
| 510 |
{ |
| 511 |
// TODO Log |
| 512 |
e.printStackTrace(); |
| 513 |
} |
287 |
} |
|
|
288 |
stream.close(); |
| 514 |
} |
289 |
} |
| 515 |
catch (CoreException e) |
290 |
catch(Exception e) |
| 516 |
{ |
291 |
{ |
| 517 |
// TODO Log |
|
|
| 518 |
e.printStackTrace(); |
292 |
e.printStackTrace(); |
| 519 |
} |
293 |
} |
| 520 |
|
|
|
| 521 |
|
| 522 |
} |
| 523 |
/** |
| 524 |
* This method will remove the artifacts which are generated during the code generation time and should not be persisted |
| 525 |
* in the workspace even though user checks the Persisit Artifatcs Button. |
| 526 |
*/ |
| 527 |
public void removeArtifacts() |
| 528 |
{ |
| 529 |
if(_mrt.getImplements().contains("platform:/resource"+_mrtParentDirName+"/ServiceGroupCapability.mcap")) |
| 530 |
{ |
| 531 |
_mrt.getImplements().remove("platform:/resource"+_mrtParentDirName+"/ServiceGroupCapability.mcap"); |
| 532 |
_mrt.getImplements().add(WsdmConstants.SERVICE_GROUP_CAPABILITY_LOCATION); |
| 533 |
saveMRTFile(_mrt); |
| 534 |
removeFiles(_fileLocation); |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
private void saveMRTFile(ManageableResourceType mrt) |
| 539 |
{ |
| 540 |
ResourceSet rs = new ResourceSetImpl(); |
| 541 |
rs.getResourceFactoryRegistry().getExtensionToFactoryMap() |
| 542 |
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new CustomMrtResourceFactoryImpl()); |
| 543 |
URI uri = _mrt.eResource().getURI(); |
| 544 |
byte[] bytes = MrtUtils.serializeMRT(_mrt, rs, uri, false); |
| 545 |
try { |
| 546 |
IFile mrtFile = EclipseUtils.getIFile(uri.toString()); |
| 547 |
mrtFile.setContents(new ByteArrayInputStream(bytes), IFile.FORCE, null); |
| 548 |
} catch (Exception e) { |
| 549 |
e.printStackTrace(); |
| 550 |
} |
| 551 |
} |
294 |
} |
| 552 |
|
295 |
|
| 553 |
private void removeFiles(List fileLocations) |
|
|
| 554 |
{ |
| 555 |
if(fileLocations != null) |
| 556 |
{ |
| 557 |
for(int i =0;i<fileLocations.size();i++) |
| 558 |
{ |
| 559 |
IFile file = (IFile)fileLocations.get(i); |
| 560 |
try { |
| 561 |
file.delete(IFile.FORCE, new NullProgressMonitor()); |
| 562 |
} catch (CoreException e) |
| 563 |
{ |
| 564 |
e.printStackTrace(); |
| 565 |
} |
| 566 |
} |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
/** |
296 |
/** |
| 571 |
* Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given |
297 |
* Inspects the given manageable resource type for servicegroup/relationship kind of resource type and update the given |
| 572 |
* merged RMD document for it by having the rules/relationships in it. |
298 |
* merged RMD document for it by having the rules/relationships in it. |
|
Lines 574-578
Link Here
|
| 574 |
public void inspectMetadata(ManageableResourceType mrt, |
300 |
public void inspectMetadata(ManageableResourceType mrt, |
| 575 |
org.apache.muse.ws.resource.metadata.MetadataDescriptor rmd) |
301 |
org.apache.muse.ws.resource.metadata.MetadataDescriptor rmd) |
| 576 |
{ |
302 |
{ |
|
|
303 |
|
| 304 |
_prefixNamespaceMap = new HashMap(); |
| 305 |
Capability[] mrtCapabilities = new Capability[0]; |
| 306 |
try |
| 307 |
{ |
| 308 |
mrtCapabilities = MrtUtils.getCapabilities(mrt); |
| 309 |
} |
| 310 |
catch (Exception e) |
| 311 |
{ |
| 312 |
WsdmToolingLog.logError(e.getMessage(), e); |
| 313 |
} |
| 314 |
|
| 315 |
if(hasServiceGroupCapabilities(mrtCapabilities)) |
| 316 |
{ |
| 317 |
List membershipContentRule = mrt.getMembershipContentRule(); |
| 318 |
List initialValues = new ArrayList(); |
| 319 |
for(int i=0;i<membershipContentRule.size();i++) |
| 320 |
{ |
| 321 |
MembershipContentRuleType rule = (MembershipContentRuleType) membershipContentRule.get(i); |
| 322 |
Element value = createMembershipContentRuleElement(rule); |
| 323 |
|
| 324 |
initialValues.add(value); |
| 325 |
} |
| 326 |
if(!initialValues.isEmpty()); |
| 327 |
try |
| 328 |
{ |
| 329 |
rmd.setInitialValues(new QName(WssgConstants.NAMESPACE_URI,"MembershipContentRule"), initialValues); |
| 330 |
} |
| 331 |
catch (SoapFault e) |
| 332 |
{ |
| 333 |
WsdmToolingLog.logError(e.getMessage(), e); |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
private Element createMembershipContentRuleElement(MembershipContentRuleType rule) |
| 339 |
{ |
| 340 |
Document document = XmlUtils.createDocument(); |
| 341 |
Element membershipContentRuleElement = XmlUtils.createElement(document, new QName(WssgConstants.NAMESPACE_URI,"MembershipContentRule")); |
| 342 |
List contentElements = rule.getContentElements(); |
| 343 |
String contentElementAttribute=""; |
| 344 |
|
| 345 |
for(int i =0 ;i<contentElements.size();i++) |
| 346 |
{ |
| 347 |
String contentElement = (String)contentElements.get(i); |
| 348 |
String tns = getNamespace(contentElement); |
| 349 |
String localName = getLocalName(contentElement); |
| 350 |
preparePrfixNamespaceMap(tns); |
| 351 |
|
| 352 |
if(contentElementAttribute.length() !=0) |
| 353 |
contentElementAttribute = contentElementAttribute + " " + (String)_prefixNamespaceMap.get(tns)+":"+ localName; |
| 354 |
else |
| 355 |
contentElementAttribute =(String)_prefixNamespaceMap.get(tns)+":"+ localName; |
| 356 |
String xmlns = "xmlns:" + _prefixNamespaceMap.get(tns); |
| 357 |
membershipContentRuleElement.setAttribute(xmlns,tns ); |
| 358 |
|
| 359 |
} |
| 360 |
membershipContentRuleElement.setAttribute("ContentElements",contentElementAttribute ); |
| 361 |
|
| 362 |
return membershipContentRuleElement; |
| 363 |
|
| 364 |
|
| 577 |
} |
365 |
} |
| 578 |
} |
366 |
} |