Kernel kernel = PortletManager.getKernel();
DeploymentFactory factory = new DeploymentFactoryWithKernel(kernel);
DeploymentManager deploymentManager = factory.getDeploymentManager("deployer:geronimo:inVM", null, null);
DeploymentConfiguration deploymentConfiguration = deploymentManager.createConfiguration(webDeployable);
WebAppDConfigRoot configRoot = (WebAppDConfigRoot) deploymentConfiguration.getDConfigBeanRoot(ddBeanRoot);
WebAppDConfigBean webApp = (WebAppDConfigBean) configRoot.getDConfigBean(ddBean);
webApp.setContextRoot(data.getContextRoot());
EnvironmentData environment = new EnvironmentData();
webApp.setEnvironment(environment);
org.apache.geronimo.deployment.service.jsr88.Artifact configId = new org.apache.geronimo.deployment.service.jsr88.Artifact();
environment.setConfigId(configId);
configId.setGroupId(data.getGroupId());
configId.setArtifactId(data.getArtifactId());
configId.setVersion(data.getVersion());
configId.setType(data.getType());
int numDependencies = data.getDependencies().size();
if (numDependencies > 0) {
org.apache.geronimo.deployment.service.jsr88.Artifact[] dependencies = new org.apache.geronimo.deployment.service.jsr88.Artifact[numDependencies];
for (int i = 0; i < numDependencies; i++) {
dependencies[i] = new org.apache.geronimo.deployment.service.jsr88.Artifact();
}
environment.setDependencies(dependencies);
for (int i = 0; i < numDependencies; i++) {
Artifact artifact = Artifact.create(((String) data.getDependencies().get(i)).trim());
org.apache.geronimo.deployment.service.jsr88.Artifact dep = dependencies[i];
dep.setArtifactId(artifact.getArtifactId());
if (artifact.getGroupId() != null) {
dep.setGroupId(artifact.getGroupId());
}
if (artifact.getType() != null) {
dep.setType(artifact.getType());
}
if (artifact.getVersion() != null) {
dep.setVersion(artifact.getVersion().toString());
}
}
}
String hiddenClassesString = data.getHiddenClasses();
if (hiddenClassesString != null && hiddenClassesString.length() > 0) {
String[] hiddenClasses = getNonEmptyStrings(hiddenClassesString.split(";"));
if (hiddenClasses.length > 0) {
environment.setHiddenClasses(hiddenClasses);
}
}
String nonOverridableClassesString = data.getNonOverridableClasses();
if (nonOverridableClassesString != null && nonOverridableClassesString.length() > 0) {
String[] nonOverridableClasses = getNonEmptyStrings(nonOverridableClassesString.split(";"));
if (nonOverridableClasses.length > 0) {
environment.setNonOverridableClasses(nonOverridableClasses);
}
}
if (data.isInverseClassLoading()) {
environment.setInverseClassLoading(true);
}
int numEjbRefs = data.getEjbRefs().size();
if (numEjbRefs > 0) {
EjbRef[] ejbRefs = new EjbRef[numEjbRefs];
for (int i = 0; i < numEjbRefs; i++) {
ejbRefs[i] = new EjbRef();
}
webApp.setEjbRefs(ejbRefs);
for (int i = 0; i < numEjbRefs; i++) {
EjbRef ejbRef = ejbRefs[i];
ReferenceData referenceData = (ReferenceData) data.getEjbRefs().get(i);
ejbRef.setRefName(referenceData.getRefName());
ejbRef.setPattern(createPattern(referenceData.getRefLink()));
}
}
int numEjbLocalRefs = data.getEjbLocalRefs().size();
if (numEjbLocalRefs > 0) {
EjbLocalRef[] ejbLocalRefs = new EjbLocalRef[numEjbLocalRefs];
for (int i = 0; i < numEjbLocalRefs; i++) {
ejbLocalRefs[i] = new EjbLocalRef();
}
webApp.setEjbLocalRefs(ejbLocalRefs);
for (int i = 0; i < numEjbLocalRefs; i++) {
EjbLocalRef ejbLocalRef = ejbLocalRefs[i];
ReferenceData referenceData = (ReferenceData) data.getEjbLocalRefs().get(i);
ejbLocalRef.setRefName(referenceData.getRefName());
ejbLocalRef.setPattern(createPattern(referenceData.getRefLink()));
}
}
int numResourceRefs = data.getJdbcPoolRefs().size() + data.getJmsConnectionFactoryRefs().size()
+ data.getJavaMailSessionRefs().size();
if (numResourceRefs > 0) {
ResourceRef[] resourceRefs = new ResourceRef[numResourceRefs];
for (int i = 0; i < numResourceRefs; i++) {
resourceRefs[i] = new ResourceRef();
}
webApp.setResourceRefs(resourceRefs);
int i = 0;
for (int l = 0; l < data.getJdbcPoolRefs().size(); l++, i++) {
ResourceRef resourceRef = resourceRefs[i];
ReferenceData referenceData = (ReferenceData) data.getJdbcPoolRefs().get(l);
resourceRef.setRefName(referenceData.getRefName());
resourceRef.setPattern(createPattern(referenceData.getRefLink()));
}
for (int m = 0; m < data.getJmsConnectionFactoryRefs().size(); m++, i++) {
ResourceRef resourceRef = resourceRefs[i];
ReferenceData referenceData = (ReferenceData) data.getJmsConnectionFactoryRefs().get(m);
resourceRef.setRefName(referenceData.getRefName());
resourceRef.setPattern(createPattern(referenceData.getRefLink()));
}
for (int n = 0; n < data.getJavaMailSessionRefs().size(); n++, i++) {
ResourceRef resourceRef = resourceRefs[i];
ReferenceData referenceData = (ReferenceData) data.getJavaMailSessionRefs().get(n);
resourceRef.setRefName(referenceData.getRefName());
resourceRef.setPattern(createPattern(referenceData.getRefLink()));
}
}
int numMessageDestinations = data.getMessageDestinations().size();
if (numMessageDestinations > 0) {
MessageDestination[] messageDestinations = new MessageDestination[numMessageDestinations];
for (int i = 0; i < numMessageDestinations; i++) {
messageDestinations[i] = new MessageDestination();
}
webApp.setMessageDestinations(messageDestinations);
for (int i = 0; i < numMessageDestinations; i++) {
MessageDestination messageDestination = messageDestinations[i];
ReferenceData referenceData = (ReferenceData) data.getMessageDestinations().get(i);
messageDestination.setMessageDestinationName(referenceData.getRefName());
// messageDestination.setPattern(createPattern(referenceData.getRefLink()));
messageDestination.setAdminObjectLink(createPattern(referenceData.getRefLink()).getName());
}
}
int numResourceEnvRefs = data.getJmsDestinationRefs().size();
if (numResourceEnvRefs > 0) {
ResourceEnvRef[] resourceEnvRefs = new ResourceEnvRef[numResourceEnvRefs];
for (int i = 0; i < numResourceEnvRefs; i++) {
resourceEnvRefs[i] = new ResourceEnvRef();
}
webApp.setResourceEnvRefs(resourceEnvRefs);
for (int i = 0; i < numResourceEnvRefs; i++) {
ResourceEnvRef resourceEnvRef = resourceEnvRefs[i];
ReferenceData referenceData = (ReferenceData) data.getJmsDestinationRefs().get(i);
resourceEnvRef.setRefName(referenceData.getRefName());
resourceEnvRef.setPattern(createPattern(referenceData.getRefLink()));
// resourceEnvRef.setAdminObjectLink(createPattern(referenceData.getRefLink()).getName());
}
}
int numWebServiceRefs = data.getWebServiceRefs().size();
if (numWebServiceRefs > 0) {
webApp.setServiceRefs(data.getWebServiceRefs().toArray(new GerServiceRefType[numWebServiceRefs]));
}
if (data.getSecurity() != null) {
webApp.setSecurityRealmName(data.getSecurityRealmName());
webApp.setSecurity(data.getSecurity());
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
deploymentConfiguration.save(out);
out.close();