| 1 | |
package com.aurea.maven.plugins.sonic.sdm.util; |
| 2 | |
|
| 3 | |
import java.io.ByteArrayInputStream; |
| 4 | |
import java.io.File; |
| 5 | |
import java.util.ArrayList; |
| 6 | |
import java.util.List; |
| 7 | |
|
| 8 | |
import com.aurea.maven.plugins.util.JAXBHelper; |
| 9 | |
import com.progress.sonic.utilities.esb.admin.XarAnalyzer; |
| 10 | |
import com.sonicsw.deploy.IArtifact; |
| 11 | |
|
| 12 | |
public abstract class AbstractModelContribution implements ESBModelContribution { |
| 13 | |
|
| 14 | 0 | private ESBDeploymentModelBuilder builder = null; |
| 15 | 0 | private String contributionName = null; |
| 16 | |
|
| 17 | |
public AbstractModelContribution( |
| 18 | |
String contributionName, ESBDeploymentModelBuilder builder |
| 19 | 0 | ) { |
| 20 | 0 | this.builder = builder; |
| 21 | 0 | this.contributionName = contributionName; |
| 22 | 0 | } |
| 23 | |
|
| 24 | |
public String getContributionName() { |
| 25 | 0 | return contributionName; |
| 26 | |
} |
| 27 | |
|
| 28 | |
protected ESBDeploymentModelBuilder getBuilder() { |
| 29 | 0 | return builder; |
| 30 | |
} |
| 31 | |
|
| 32 | |
@SuppressWarnings("unchecked") |
| 33 | |
protected List<Object> getArtifactList(IArtifact type, Class<?> javaType) throws Exception { |
| 34 | |
|
| 35 | 0 | List<Object> result = new ArrayList<Object>(); |
| 36 | |
|
| 37 | 0 | ESBDeploymentModel model = getBuilder().getModel(); |
| 38 | |
|
| 39 | 0 | for (String xarFileName: (List<String>) model.getModelObject(ESBDeploymentModel.CONTRIB_XAR_FILES)) { |
| 40 | 0 | File xarFile = new File(getBuilder().getSDMDir() + "/xars", xarFileName); |
| 41 | 0 | getBuilder().getLog().debug("Analyzing [" + xarFile.getAbsolutePath() + "] for " + type.getDisplayType()); |
| 42 | 0 | XarAnalyzer analyzer = new XarAnalyzer(xarFile); |
| 43 | 0 | List<IArtifact> artifacts = analyzer.getArtifacts(type); |
| 44 | 0 | getBuilder().getLog().debug("Found [" + artifacts.size() + "] artifacs."); |
| 45 | |
|
| 46 | 0 | for(IArtifact artifact : artifacts) { |
| 47 | 0 | byte [] rawXml = analyzer.getContent(artifact); |
| 48 | 0 | Object obj = JAXBHelper.unmarshal(javaType, new ByteArrayInputStream(rawXml)); |
| 49 | 0 | getBuilder().getLog().debug("Analyzed Artifact []: " + artifact.getName()); |
| 50 | 0 | result.add(obj); |
| 51 | 0 | } |
| 52 | 0 | } |
| 53 | |
|
| 54 | 0 | return result; |
| 55 | |
} |
| 56 | |
} |