use of org.apache.synapse.libraries.model.SynapseLibrary in project wso2-synapse by wso2.
the class LibDeployerUtils method createSynapseLibraryWithDeps.
/**
* Builds the Artifact object when an artifact element is given
*
* @param artifactEle - artifact OMElement
* @return created Artifact object
*/
private static SynapseLibrary createSynapseLibraryWithDeps(OMElement artifactEle) {
if (artifactEle == null) {
return null;
}
SynapseLibrary synLib = new SynapseLibrary(readAttribute(artifactEle, LibDeployerConstants.NAME), readAttribute(artifactEle, LibDeployerConstants.PACKAGE_ATTR));
synLib.setDescription(readChildText(artifactEle, LibDeployerConstants.DESCRIPTION_ELEMENT));
// read the dependencies
Iterator itr = artifactEle.getChildrenWithLocalName(LibDeployerConstants.DEPENDENCY);
while (itr.hasNext()) {
OMElement depElement = (OMElement) itr.next();
// create a synLib for each dependency and add to the root synLib
LibraryArtifact.Dependency dep = new LibraryArtifact.Dependency(readAttribute(depElement, LibDeployerConstants.ARTIFACT));
synLib.addDependency(dep);
}
return synLib;
}
use of org.apache.synapse.libraries.model.SynapseLibrary in project wso2-synapse by wso2.
the class LibDeployerUtils method populateDependencies.
/**
* populate Dependencies using main root artifacts.xml.. Schema for artifacts.xml is follwing
*
*<artifacts>
* <artifact name="SampleLib" package="synapse.sample" >
* <dependency artifact="templates1" /> +
* <description>sample synapse library</description> ?
* </artifact>
* </artifacts>
*
* @param libXmlPath
* @return
*/
private static SynapseLibrary populateDependencies(String libXmlPath) {
File f = new File(libXmlPath);
if (!f.exists()) {
throw new SynapseException("artifacts.xml file not found at : " + libXmlPath);
}
InputStream xmlInputStream = null;
try {
xmlInputStream = new FileInputStream(f);
OMElement documentElement = new StAXOMBuilder(xmlInputStream).getDocumentElement();
if (documentElement == null) {
throw new SynapseArtifactDeploymentException("Document element for artifacts.xml is " + "null. Can't build " + "the synapse library configuration");
}
Iterator artifactItr = documentElement.getChildrenWithLocalName(LibDeployerConstants.ARTIFACT);
SynapseLibrary mainSynLibArtifact = null;
mainSynLibArtifact = createSynapseLibraryWithDeps(((OMElement) artifactItr.next()));
if (mainSynLibArtifact == null) {
throw new SynapseArtifactDeploymentException("artifacts.xml is invalid. <artifact> element" + " Not Found ");
}
return mainSynLibArtifact;
} catch (FileNotFoundException e) {
throw new SynapseArtifactDeploymentException("artifacts.xml File cannot be loaded from " + libXmlPath, e);
} catch (XMLStreamException e) {
throw new SynapseArtifactDeploymentException("Error while parsing the artifacts.xml file ", e);
} finally {
if (xmlInputStream != null) {
try {
xmlInputStream.close();
} catch (IOException e) {
log.error("Error while closing input stream.", e);
}
}
}
}
use of org.apache.synapse.libraries.model.SynapseLibrary in project wso2-synapse by wso2.
the class LibDeployerUtils method createSynapseLibrary.
public static Library createSynapseLibrary(String libPath) {
String libFilePath = LibDeployerUtils.formatPath(libPath);
// extract
String extractPath = LibDeployerUtils.extractSynapseLib(libFilePath);
// create synapse lib metadata
SynapseLibrary synapseLib = LibDeployerUtils.populateDependencies(extractPath + LibDeployerConstants.ARTIFACTS_XML);
// create a ClassLoader for loading this synapse lib classes/resources
try {
ClassLoader libLoader = Utils.getClassLoader(LibDeployerUtils.class.getClassLoader(), extractPath, false);
synapseLib.setLibClassLoader(libLoader);
} catch (DeploymentException e) {
throw new SynapseArtifactDeploymentException("Error setting up lib classpath for Synapse" + " Library : " + libFilePath, e);
}
// resolve synapse lib artifacts
LibDeployerUtils.searchAndResolveDependencies(extractPath, synapseLib);
// TODO:reslove local-entry references
LibDeployerUtils.populateLocalEnties(synapseLib, extractPath + LibDeployerConstants.LOCAL_ENTRIES);
synapseLib.setFileName(libFilePath);
return synapseLib;
}
Aggregations