geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From de...@apache.org
Subject svn commit: r817996 [17/23] - in /geronimo/devtools/eclipse-plugin/trunk: assembly/ assembly/src/main/assembly/ features/ features/org.apache.geronimo.v22.feature/ plugins/ plugins/org.apache.geronimo.j2ee.v11.jaxbmodel/ plugins/org.apache.geronimo.j2e...
Date Wed, 23 Sep 2009 08:04:34 GMT
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerInfo.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerInfo.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerInfo.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoServerInfo.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,446 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.management.MBeanServerConnection;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.NoSuchAttributeException;
+import org.apache.geronimo.kernel.NoSuchOperationException;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate;
+import org.apache.geronimo.st.v21.core.internal.Trace;
+import org.apache.geronimo.system.jmx.KernelDelegate;
+import org.apache.geronimo.xml.ns.deployment_1.DependencyType;
+import org.apache.geronimo.xml.ns.naming_1.PatternType;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
+
+/**
+ * @version $Rev: 688452 $ $Date: 2008-08-24 13:56:20 +0800 (Sun, 24 Aug 2008) $
+ */
+public class GeronimoServerInfo {
+    static final long serialVersionUID = 1L;
+
+    private ArrayList<Kernel> kernels;
+
+    private ArrayList<PatternType> deployedEJBs;
+    private ArrayList<String> securityRealms;
+    private ArrayList<PatternType> jmsConnectionFactories;
+    private ArrayList<PatternType> jmsDestinations;
+    private ArrayList<PatternType> jdbcConnectionPools;
+    private ArrayList<PatternType> javaMailResources;
+    private ArrayList<org.apache.geronimo.xml.ns.deployment_1.PatternType> credentialStores;
+    private ArrayList<DependencyType> commonLibs;
+
+    // singleton class
+    private GeronimoServerInfo() {
+    }
+
+    private static GeronimoServerInfo instance = new GeronimoServerInfo();
+
+    public static GeronimoServerInfo getInstance() {
+        return instance;
+    }
+
+    public ArrayList<PatternType> getDeployedEjbs() {
+        return deployedEJBs;
+    }
+
+    public ArrayList<String> getSecurityRealms() {
+        return securityRealms;
+    }
+
+    public ArrayList<PatternType> getJmsConnectionFactories() {
+        return jmsConnectionFactories;
+    }
+
+    public ArrayList<PatternType> getJmsDestinations() {
+        return jmsDestinations;
+    }
+
+    public ArrayList<PatternType> getJdbcConnectionPools() {
+        return jdbcConnectionPools;
+    }
+
+    public ArrayList<PatternType> getJavaMailSessions() {
+        return javaMailResources;
+    }
+
+    public ArrayList<org.apache.geronimo.xml.ns.deployment_1.PatternType> getDeployedCredentialStores() {
+        return credentialStores;
+    }
+
+    public ArrayList<DependencyType> getCommonLibs() {
+        return commonLibs;
+    }
+
+    public void updateInfo() {
+        Job job = new Job("Getting Dynamic Information from Server"){
+            protected IStatus run(IProgressMonitor arg0) {
+                updateKernels();
+                updateDeployedEJBs();
+                updateSecurityRealms();
+                updateJmsConnectionFactories();
+                updateJmsDestinations();
+                updateJdbcConnectionPools();
+                updateJavaMailSessions();
+                updateDeployedCredentialStores();
+                updateCommonLibs();
+                return Status.OK_STATUS;
+            }
+        };
+        job.setPriority(Job.SHORT);
+        job.schedule();
+    }
+
+    private void updateKernels() {
+        kernels = new ArrayList<Kernel>();
+        IServer[] servers = ServerCore.getServers();
+        for (int i = 0; i < servers.length; i++) {
+            if (servers[i].getServerState() == IServer.STATE_STARTED) {
+                try {
+                    GeronimoServerBehaviourDelegate delegate = (GeronimoServerBehaviourDelegate) servers[i]
+                            .getAdapter(GeronimoServerBehaviourDelegate.class);
+                    if (delegate != null) {
+                        MBeanServerConnection connection = delegate
+                                .getServerConnection();
+                        if (connection != null) {
+                            kernels.add(new KernelDelegate(connection));
+                        }
+                    }
+                } catch (SecurityException e) {
+                } catch (Exception e) {
+                    Trace.trace(Trace.WARNING, "Kernel connection failed. "
+                            + e.getMessage());
+                }
+            }
+        }
+    }
+
+    private void updateDeployedEJBs() {
+        deployedEJBs = new ArrayList<PatternType>();
+        ArrayList<PatternType> statelessSessionBeans = getByType("StatelessSessionBean");
+        ArrayList<PatternType> statefulSessionBeans = getByType("StatefulSessionBean");
+        ArrayList<PatternType> messageDrivenBeans = getByType("MessageDrivenBean");
+        ArrayList<PatternType> entityBeans = getByType("EntityBean");
+        deployedEJBs.addAll(statelessSessionBeans);
+        deployedEJBs.addAll(statefulSessionBeans);
+        deployedEJBs.addAll(messageDrivenBeans);
+        deployedEJBs.addAll(entityBeans);
+    }
+
+    private void updateSecurityRealms() {
+        securityRealms = new ArrayList<String>();
+        Map map = Collections.singletonMap("j2eeType", "SecurityRealm");
+        AbstractNameQuery query = new AbstractNameQuery(null, map,
+                Collections.EMPTY_SET);
+        for (int i = 0; i < kernels.size(); i++) {
+            Set beans = kernels.get(i).listGBeans(query);
+            for (Iterator it = beans.iterator(); it.hasNext();) {
+                AbstractName abstractName = (AbstractName) it.next();
+                String name = (String) abstractName.getName().get("name");
+                if (!securityRealms.contains(name)) {
+                    securityRealms.add(name);
+                }
+            }
+        }
+    }
+
+    private void updateJmsConnectionFactories() {
+        String[] requiredInterfaces = new String[] {
+                "javax.jms.ConnectionFactory",
+                "javax.jms.QueueConnectionFactory",
+                "javax.jms.TopicConnectionFactory", };
+        String attribute = "implementedInterfaces";
+        jmsConnectionFactories = getByTypeAttributeValues(
+                "JCAManagedConnectionFactory", attribute, requiredInterfaces);
+    }
+
+    private void updateJmsDestinations() {
+        String[] requiredInterfaces = new String[] { "javax.jms.Queue",
+                "javax.jms.Topic" };
+        String attribute = "adminObjectInterface";
+        jmsDestinations = getByTypeAttributeValues("JCAAdminObject", attribute,
+                requiredInterfaces);
+    }
+
+    private void updateJdbcConnectionPools() {
+        String[] acceptedValues = new String[] { "javax.sql.DataSource" };
+        String attribute = "connectionFactoryInterface";
+        jdbcConnectionPools = getByTypeAttributeValues(
+                "JCAManagedConnectionFactory", attribute, acceptedValues);
+
+    }
+
+    private void updateJavaMailSessions() {
+        javaMailResources = getByType("JavaMailResource");
+    }
+
+    private void updateDeployedCredentialStores() {
+        credentialStores = new ArrayList<org.apache.geronimo.xml.ns.deployment_1.PatternType>();
+        Map map = Collections.singletonMap("j2eeType", "GBean");
+        AbstractNameQuery query = new AbstractNameQuery(null, map,
+                Collections.EMPTY_SET);
+        for (int i = 0; i < kernels.size(); i++) {
+            Set beans = kernels.get(i).listGBeans(query);
+            for (Iterator it = beans.iterator(); it.hasNext();) {
+                AbstractName abstractName = (AbstractName) it.next();
+                try {
+                    GBeanInfo info = kernels.get(i).getGBeanInfo(abstractName);
+                    GAttributeInfo attribInfo = info
+                            .getAttribute("credentialStore");
+                    if (attribInfo != null) {
+                        Artifact artifact = abstractName.getArtifact();
+                        Object name = abstractName.getName().get("name");
+                        org.apache.geronimo.xml.ns.deployment_1.PatternType pattern = new org.apache.geronimo.xml.ns.deployment_1.PatternType();
+                        pattern.setArtifactId(artifact.getArtifactId());
+                        pattern.setGroupId(artifact.getGroupId());
+                        pattern.setType(artifact.getType());
+                        pattern.setVersion(artifact.getVersion().toString());
+                        pattern.setCustomFoo((String) name);
+                        if (!credentialStores.contains(pattern)) {
+                            credentialStores.add(pattern);
+                        }
+                    }
+                } catch (GBeanNotFoundException e) {
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    private void updateCommonLibs() {
+        List<Object> artifacts = null;
+        commonLibs = new ArrayList<DependencyType>();
+        Map map = Collections.singletonMap("j2eeType", "Repository");
+        AbstractNameQuery query = new AbstractNameQuery(null, map,
+                Collections.EMPTY_SET);
+        for (int i = 0; i < kernels.size(); i++) {
+            Set beans = kernels.get(i).listGBeans(query);
+            for (Iterator it = beans.iterator(); it.hasNext();) {
+                AbstractName abstractName = (AbstractName) it.next();
+                try {
+                    GBeanInfo info = kernels.get(i).getGBeanInfo(abstractName);
+                    Object value = kernels.get(i).invoke(abstractName, "list");
+                    if (value instanceof TreeSet) {
+                        artifacts = Arrays.asList(((TreeSet) value).toArray());
+                    }
+                } catch (GBeanNotFoundException e) {
+                    Trace.trace(Trace.WARNING, "GBean Not Found. "
+                            + e.getMessage());
+                } catch (NoSuchOperationException e) {
+                    Trace.trace(Trace.WARNING, "The operation cant invoked. "
+                            + e.getMessage());
+                } catch (InternalKernelException e) {
+                    throw e;
+                } catch (Exception e) {
+                    Trace.trace(Trace.WARNING, "Kernel connection failed.  "
+                            + e.getMessage());
+                }
+
+            }
+        }
+        if (artifacts != null) {
+            for (int i = 0; i < artifacts.size(); i++) {
+                DependencyType dependency = new DependencyType();
+                dependency.setArtifactId(((Artifact) artifacts.get(i))
+                        .getArtifactId());
+                dependency.setGroupId(((Artifact) artifacts.get(i))
+                        .getGroupId());
+                dependency.setVersion(((Artifact) artifacts.get(i))
+                        .getVersion().toString());
+                dependency.setType(((Artifact) artifacts.get(i)).getType());
+                if (!commonLibs.contains(dependency)) {
+                    commonLibs.add(dependency);
+                }
+            }
+        }
+    }
+
+    private ArrayList<PatternType> getByTypeAttributeValues(String type,
+            String attribute, String[] acceptedValues) {
+        ArrayList<PatternType> result = new ArrayList<PatternType>();
+        Map map = Collections.singletonMap("j2eeType", type);
+        AbstractNameQuery query = new AbstractNameQuery(null, map,
+                Collections.EMPTY_SET);
+        for (int i = 0; i < kernels.size(); i++) {
+            Set beans = kernels.get(i).listGBeans(query);
+            for (Iterator it = beans.iterator(); it.hasNext();) {
+                AbstractName abstractName = (AbstractName) it.next();
+                try {
+                    Object value = kernels.get(i).getAttribute(abstractName,
+                            attribute);
+                    if (value != null) {
+                        if (value instanceof String[]) {
+                            List<String> interfaces = Arrays
+                                    .asList((String[]) value);
+                            for (int j = 0; j < acceptedValues.length; j++) {
+                                if (interfaces.contains(acceptedValues[j])) {
+                                	PatternType pattern = new PatternType();
+                                    Artifact artifact = abstractName
+                                            .getArtifact();
+                                    pattern.setArtifactId(artifact
+                                            .getArtifactId());
+                                    pattern.setGroupId(artifact.getGroupId());
+                                    pattern.setVersion(artifact.getVersion()
+                                            .toString());
+                                    pattern.setName((String) abstractName
+                                            .getName().get("name"));
+                                    if (!result.contains(pattern)) {
+                                        result.add(pattern);
+                                    }
+                                    break;
+                                }
+                            }
+                        }
+                        if (value instanceof String) {
+                            String interfaces = (String) value;
+                            for (int j = 0; j < acceptedValues.length; j++) {
+                                if (interfaces.contains(acceptedValues[j])) {
+                                	PatternType pattern = new PatternType();
+                                    Artifact artifact = abstractName
+                                            .getArtifact();
+                                    pattern.setArtifactId(artifact
+                                            .getArtifactId());
+                                    pattern.setGroupId(artifact.getGroupId());
+                                    pattern.setVersion(artifact.getVersion()
+                                            .toString());
+                                    pattern.setName((String) abstractName
+                                            .getName().get("name"));
+                                    if (!result.contains(pattern)) {
+                                        result.add(pattern);
+                                    }
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                } catch (GBeanNotFoundException e) {
+                } catch (NoSuchAttributeException e) {
+                } catch (Exception e) {
+                    Trace.trace(Trace.WARNING, "Kernel connection failed. "
+                            + e.getMessage());
+                }
+            }
+        }
+        return result;
+    }
+
+    private ArrayList<PatternType> getByType(String type) {
+        ArrayList<PatternType> result = new ArrayList<PatternType>();
+        Map map = Collections.singletonMap("j2eeType", type);
+        AbstractNameQuery query = new AbstractNameQuery(null, map,
+                Collections.EMPTY_SET);
+        for (int i = 0; i < kernels.size(); i++) {
+            Set beans = kernels.get(i).listGBeans(query);
+            for (Iterator it = beans.iterator(); it.hasNext();) {
+                AbstractName abstractName = (AbstractName) it.next();
+                PatternType pattern = new PatternType();
+                Artifact artifact = abstractName.getArtifact();
+                pattern.setArtifactId(artifact.getArtifactId());
+                pattern.setGroupId(artifact.getGroupId());
+                pattern.setVersion(artifact.getVersion().toString());
+                pattern.setName((String) abstractName.getName().get("name"));
+                if (!result.contains(pattern)) {
+                    result.add(pattern);
+                }
+            }
+        }
+        return result;
+    }
+
+    protected void printNamingPatternList(List<PatternType> patternList) {
+        for (int i = 0; i < patternList.size(); i++) {
+        	PatternType pattern = patternList.get(i);
+            System.out.println("ArtifactID:" + pattern.getArtifactId()
+                    + " GroupID:" + pattern.getGroupId() + " Module:"
+                    + pattern.getModule() + " Version:" + pattern.getVersion()
+                    + " Name:" + pattern.getName());
+        }
+    }
+
+    protected void printDeploymentPatternList(
+            List<org.apache.geronimo.xml.ns.deployment_1.PatternType> patternList) {
+        for (int i = 0; i < patternList.size(); i++) {
+        	org.apache.geronimo.xml.ns.deployment_1.PatternType pattern = patternList
+                    .get(i);
+            System.out.println("ArtifactID:" + pattern.getArtifactId()
+                    + " GroupID:" + pattern.getGroupId() + " Module:"
+                    + pattern.getVersion() + " Version:" + pattern.getType()
+                    + " Name:" + pattern.getCustomFoo());
+        }
+    }
+
+    protected void printDependencies(List<DependencyType> dependencyList) {
+        for (int i = 0; i < dependencyList.size(); i++) {
+        	DependencyType dependency = dependencyList.get(i);
+            System.out.println("ArtifactID:" + dependency.getArtifactId()
+                    + " GroupID:" + dependency.getGroupId() + " Type:"
+                    + dependency.getType() + " Version:"
+                    + dependency.getVersion());
+        }
+    }
+
+    public void printServerInfo() {
+        System.out.println("EJB Modules: \n");
+        List<PatternType> ejbModules = getDeployedEjbs();
+        printNamingPatternList(ejbModules);
+        System.out.println("\n\nSecurity Realms: \n");
+        List<String> securityRealms = getSecurityRealms();
+        System.out.println(securityRealms.toString());
+        System.out.println("\n\nJMS Connection Factories: \n");
+        List<PatternType> jmsConnectionFactories = getJmsConnectionFactories();
+        printNamingPatternList(jmsConnectionFactories);
+        System.out.println("\n\nJMS Destinations: \n");
+        List<PatternType> jmsDestinations = getJmsDestinations();
+        printNamingPatternList(jmsDestinations);
+        System.out.println("\n\nJDBC Connection Pools: \n");
+        List<PatternType> jdbcConnectionPools = getJdbcConnectionPools();
+        printNamingPatternList(jdbcConnectionPools);
+        System.out.println("\n\nJava Mail Resources: \n");
+        List<PatternType> javaMailResources = getJavaMailSessions();
+        printNamingPatternList(javaMailResources);
+        System.out.println("\n\nCredential Stores: \n");
+        List<org.apache.geronimo.xml.ns.deployment_1.PatternType> credentialStores = getDeployedCredentialStores();
+        printDeploymentPatternList(credentialStores);
+        System.out.println("\n\nCommon Libs: \n");
+        List<DependencyType> dependencies = getCommonLibs();
+        printDependencies(dependencies);
+    }
+
+}

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoV11Utils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoV11Utils.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoV11Utils.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoV11Utils.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core;
+
+import javax.xml.bind.JAXBElement;
+
+import org.apache.geronimo.st.core.GeronimoUtils;
+import org.apache.geronimo.st.core.internal.Trace;
+import org.apache.geronimo.st.v11.core.jaxb.JAXBUtils;
+import org.apache.geronimo.xml.ns.deployment_1.ArtifactType;
+import org.apache.geronimo.xml.ns.deployment_1.EnvironmentType;
+import org.apache.geronimo.xml.ns.j2ee.application_1.ApplicationType;
+import org.apache.geronimo.xml.ns.j2ee.connector_1.ConnectorType;
+import org.apache.geronimo.xml.ns.j2ee.web_1.WebAppType;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.server.core.IModule;
+import org.openejb.xml.ns.openejb_jar_2.OpenejbJarType;
+
+/**
+ * @version $Rev: 471551 $ $Date: 2006-11-05 17:47:11 -0500 (Sun, 05 Nov 2006) $
+ */
+public class GeronimoV11Utils extends GeronimoUtils {
+
+	public static JAXBElement getDeploymentPlan(IFile file) throws Exception {
+		Trace.tracePoint("ENTRY", "GeronimoV11Utils.getDeploymentPlan", file);
+
+		if (!file.exists()) {
+			return null;
+		}
+
+		if (file.getName().equals(GeronimoUtils.APP_PLAN_NAME))
+			return getApplicationDeploymentPlan(file);
+		else if (file.getName().equals(GeronimoUtils.OPENEJB_PLAN_NAME))
+			return getOpenEjbDeploymentPlan(file);
+		else if (file.getName().equals(GeronimoUtils.WEB_PLAN_NAME))
+			return getWebDeploymentPlan(file);
+		else if (file.getName().equals(GeronimoUtils.CONNECTOR_PLAN_NAME))
+			return getConnectorDeploymentPlan(file);
+		else if (file.getName().equals(GeronimoUtils.APP_CLIENT_PLAN_NAME))
+			return getApplicationClientDeploymentPlan(file);
+
+		Trace.tracePoint("EXIT", "GeronimoV11Utils.getDeploymentPlan", null);
+		return null;
+	}
+
+	// public static String getConfigId2(IModule module) {
+	//		
+	// IFile planFile = null;
+	// IVirtualComponent comp =
+	// ComponentCore.createComponent(module.getProject());
+	// if (isWebModule(module)) {
+	// planFile = GeronimoUtils.getWebDeploymentPlanFile(comp);
+	// } else if (isEjbJarModule(module)) {
+	// planFile = GeronimoUtils.getOpenEjbDeploymentPlanFile(comp);
+	// } else if (isEarModule(module)) {
+	// planFile = GeronimoUtils.getApplicationDeploymentPlanFile(comp);
+	// } else if (isRARModule(module)) {
+	// planFile = GeronimoUtils.getConnectorDeploymentPlanFile(comp);
+	// }
+	//		
+	// if(planFile != null) {
+	// try {
+	// XmlObject xmlObject =
+	// XmlBeansUtil.parse(planFile.getLocation().toFile());
+	// XmlCursor cursor = xmlObject.newCursor();
+	// cursor.toFirstChild();
+	// xmlObject = cursor.getObject();
+	// XmlObject result[] =
+	// xmlObject.selectChildren(QNameSet.singleton(EnvironmentDocument.type.getDocumentElementName()));
+	// if(result != null && result.length > 0) {
+	// org.apache.geronimo.deployment.xbeans.EnvironmentType env =
+	// (org.apache.geronimo.deployment.xbeans.EnvironmentType)
+	// result[0].changeType(org.apache.geronimo.deployment.xbeans.EnvironmentType.type);
+	// org.apache.geronimo.deployment.xbeans.ArtifactType moduleId =
+	// env.getModuleId();
+	// return getQualifiedConfigID(moduleId);
+	// }
+	// } catch (IOException e) {
+	// e.printStackTrace();
+	// } catch (XmlException e) {
+	// e.printStackTrace();
+	// }
+	// }
+	//		
+	// return null;
+	// }
+
+	public static String getConfigId(IModule module) throws Exception {
+
+		EnvironmentType environment = null;
+		if (isWebModule(module)) {
+			JAXBElement<WebAppType> webapptype=getWebDeploymentPlan(module);
+			WebAppType plan = webapptype.getValue();
+			if (plan != null)
+				environment = plan.getEnvironment();
+		} else if (isEjbJarModule(module)) {
+			OpenejbJarType plan = getOpenEjbDeploymentPlan(module).getValue();
+			// if (plan != null)
+			// environment = plan.getEnvironment();
+		} else if (isEarModule(module)) {
+			ApplicationType plan = getApplicationDeploymentPlan(module).getValue();
+			if (plan != null)
+				environment = plan.getEnvironment();
+		} else if (isRARModule(module)) {
+			ConnectorType plan = getConnectorDeploymentPlan(module).getValue();
+			if (plan != null)
+				environment = plan.getEnvironment();
+		}
+		if (environment != null
+	            && environment.getModuleId() != null) {
+	            Trace.tracePoint("EXIT", "GeronimoV11Utils.getConfigId", getQualifiedConfigID(environment.getModuleId()));
+	            return getQualifiedConfigID(environment.getModuleId());
+	        }
+
+		return getId(module);
+	}
+
+//	public static String getQualifiedConfigID(ArtifactType artifact) {
+//		return getQualifiedConfigID(artifact.getGroupId(), artifact
+//				.getArtifactId(), artifact.getVersion(), artifact.getType());
+//	}
+
+	public static String getQualifiedConfigID(
+			ArtifactType artifact) {
+		return getQualifiedConfigID(artifact.getGroupId(), artifact
+				.getArtifactId(), artifact.getVersion(), artifact.getType());
+	}
+
+	public static String getQualifiedConfigID(String groupId,
+			String artifactId, String version, String type) {
+		return groupId + "/" + artifactId + "/" + version + "/" + type;
+	}
+
+	public static String getContextRoot(IModule module) throws Exception {
+		String contextRoot = null;
+
+		WebAppType deploymentPlan = getWebDeploymentPlan(module).getValue();
+		if (deploymentPlan != null)
+			contextRoot = deploymentPlan.getContextRoot();
+
+		if (contextRoot == null)
+			contextRoot = GeronimoUtils.getContextRoot(module);
+
+		return contextRoot;
+	}
+
+	public static JAXBElement<WebAppType> getWebDeploymentPlan(IModule module)
+			throws Exception {
+		return getWebDeploymentPlan(getVirtualComponent(module));
+	}
+
+	public static JAXBElement<ApplicationType> getApplicationDeploymentPlan(
+			IModule module) throws Exception {
+		return getApplicationDeploymentPlan(getVirtualComponent(module));
+	}
+
+	public static JAXBElement<OpenejbJarType> getOpenEjbDeploymentPlan(
+			IModule module) throws Exception {
+		return getOpenEjbDeploymentPlan(getVirtualComponent(module));
+	}
+
+	public static JAXBElement<ConnectorType> getConnectorDeploymentPlan(
+			IModule module) throws Exception {
+		return getConnectorDeploymentPlan(getVirtualComponent(module));
+	}
+
+	public static JAXBElement getApplicationDeploymentPlan(
+			IVirtualComponent comp) throws Exception {
+		return getApplicationDeploymentPlan(getApplicationDeploymentPlanFile(comp));
+	}
+
+	public static JAXBElement getApplicationClientDeploymentPlan(IFile file)
+			throws Exception {
+		Trace.tracePoint("ENTRY",
+				"GeronimoV11Utils.getApplicationClientDeploymentPlan", file);
+
+		if (file.getName().equals(APP_CLIENT_PLAN_NAME) && file.exists()) {
+			return JAXBUtils.unmarshalFilterDeploymentPlan(file);
+		}
+
+		Trace.tracePoint("EXIT",
+				"GeronimoV11Utils.getApplicationClientDeploymentPlan", null);
+		return null;
+	}
+
+	public static JAXBElement getWebDeploymentPlan(IVirtualComponent comp)
+			throws Exception {
+		return getWebDeploymentPlan(getWebDeploymentPlanFile(comp));
+	}
+
+	public static JAXBElement getOpenEjbDeploymentPlan(IVirtualComponent comp)
+			throws Exception {
+		return getOpenEjbDeploymentPlan(getOpenEjbDeploymentPlanFile(comp));
+	}
+
+	public static JAXBElement getConnectorDeploymentPlan(IVirtualComponent comp)
+			throws Exception {
+		return getConnectorDeploymentPlan(getConnectorDeploymentPlanFile(comp));
+	}
+
+	public static JAXBElement getApplicationDeploymentPlan(IFile file) throws Exception {
+		Trace.tracePoint("ENTRY",
+				"GeronimoV11Utils.getApplicationClientDeploymentPlan", file);
+
+		if (file.getName().equals(APP_PLAN_NAME) && file.exists()) {
+			return JAXBUtils.unmarshalFilterDeploymentPlan(file);
+		}
+
+		Trace.tracePoint("EXIT",
+				"GeronimoV11Utils.getApplicationClientDeploymentPlan", null);
+		return null;
+	}
+
+	public static JAXBElement getWebDeploymentPlan(IFile file) throws Exception {
+		Trace
+				.tracePoint("ENTRY", "GeronimoV11Utils.getWebDeploymentPlan",
+						file);
+
+		if (file.getName().equals(WEB_PLAN_NAME) && file.exists()) {
+			return JAXBUtils.unmarshalFilterDeploymentPlan(file);
+		}
+
+		Trace.tracePoint("EXIT", "GeronimoV11Utils.getWebDeploymentPlan", null);
+		return null;
+	}
+
+	public static JAXBElement getOpenEjbDeploymentPlan(IFile file)
+			throws Exception {
+		Trace.tracePoint("ENTRY", "GeronimoV11Utils.getOpenEjbDeploymentPlan",
+				file);
+
+		if (file.getName().equals(OPENEJB_PLAN_NAME) && file.exists()) {
+			return JAXBUtils.unmarshalFilterDeploymentPlan(file);
+		}
+
+		Trace.tracePoint("EXIT", "GeronimoV11Utils.getOpenEjbDeploymentPlan",
+				null);
+		return null;
+	}
+
+	public static JAXBElement getConnectorDeploymentPlan(IFile file)
+			throws Exception {
+		Trace.tracePoint("ENTRY",
+				"GeronimoV11Utils.getConnectorDeploymentPlan", file);
+
+		if (file.getName().equals(CONNECTOR_PLAN_NAME) && file.exists()) {
+			return JAXBUtils.unmarshalFilterDeploymentPlan(file);
+		}
+
+		Trace.tracePoint("EXIT", "GeronimoV11Utils.getConnectorDeploymentPlan",
+				null);
+		return null;
+	}
+
+}

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoV11VersionHandler.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoV11VersionHandler.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoV11VersionHandler.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/GeronimoV11VersionHandler.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core;
+
+import javax.enterprise.deploy.spi.TargetModuleID;
+
+import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
+import org.apache.geronimo.st.core.IGeronimoVersionHandler;
+import org.apache.geronimo.st.v21.core.GeronimoV21Utils;
+import org.eclipse.wst.server.core.IModule;
+
+/**
+ * @version $Rev: 471551 $ $Date: 2006-11-05 17:47:11 -0500 (Sun, 05 Nov 2006) $
+ */
+public class GeronimoV11VersionHandler implements IGeronimoVersionHandler {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.geronimo.st.core.IGeronimoVersionHandler#getConfigID(org.eclipse.wst.server.core.IModule)
+	 */
+	public String getConfigID(IModule module) throws Exception {
+		return GeronimoV11Utils.getConfigId(module);
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.geronimo.st.core.IGeronimoVersionHandler#createTargetModuleId(java.lang.String)
+	 */
+	public TargetModuleID createTargetModuleId(String configId) {
+		return new TargetModuleIDImpl(null, configId);
+	}
+}

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/internal/Trace.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/internal/Trace.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/internal/Trace.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/internal/Trace.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core.internal;
+
+import org.apache.geronimo.st.v11.core.Activator;
+
+/**
+ * Helper class to route trace output.
+ *
+ * @version $Rev: 471551 $ $Date: 2006-11-05 17:47:11 -0500 (Sun, 05 Nov 2006) $
+ */
+public class Trace {
+
+	/**
+	 * Finest trace event.
+	 */
+	public static byte INFO = 0;
+
+	/**
+	 * Warning trace event.
+	 */
+	public static byte WARNING = 1;
+
+	/**
+	 * Severe trace event.
+	 */
+	public static byte SEVERE = 2;
+
+	/**
+	 * Trace constructor comment.
+	 */
+	private Trace() {
+		super();
+	}
+
+	/**
+	 * Trace the given text.
+	 * 
+	 * @param level
+	 *            the trace level
+	 * @param s
+	 *            a message
+	 */
+	public static void trace(byte level, String s) {
+		trace(level, s, null);
+	}
+
+	/**
+	 * Trace the given message and exception.
+	 * 
+	 * @param level
+	 *            the trace level
+	 * @param s
+	 *            a message
+	 * @param t
+	 *            a throwable
+	 */
+	public static void trace(byte level, String s, Throwable t) {
+		if (!Activator.getDefault().isDebugging())
+			return;
+
+		System.out.println(Activator.PLUGIN_ID + ":  " + s);
+		if (t != null)
+			t.printStackTrace();
+	}
+	
+	 /**
+     * Trace the given message 
+     * 
+     * @param tracePoint
+     *            The trace point (e.g., "Exit", "Entry", "Constructor", etc....
+     *            
+     * @param classDotMethod
+     *            The class name + method name (e.g., "Class.method()")
+     *            
+     * @param parms
+     *            Method parameter(s) if the trace point is an "Entry"
+     *            or
+     *            Return value if the trace point is an "Exit"
+     */
+    public static void tracePoint(String tracePoint, String classDotMethod) {
+        trace(Trace.INFO, tracePoint + ": " + classDotMethod + "()" );
+    }   
+    public static void tracePoint(String tracePoint, String classDotMethod, Object... parms) {
+        if ( parms == null ) {
+            trace(Trace.INFO, tracePoint + ": " + classDotMethod + "( null )" );
+        }
+        else {
+            trace(Trace.INFO, tracePoint + ": " + classDotMethod + "(" );
+            for ( int ii=0; ii<parms.length; ii++) {
+                Object parm = parms[ii];
+                trace(Trace.INFO, "    parm" + (ii+1) + "=[" + (parm == null ? null : parm.toString()) + "]" );
+            }
+            trace(Trace.INFO, ")" );
+        }
+    }  
+}
\ No newline at end of file

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBModelUtils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBModelUtils.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBModelUtils.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBModelUtils.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core.jaxb;
+
+import java.util.List;
+
+import javax.xml.bind.JAXBElement;
+
+import org.apache.geronimo.xml.ns.deployment_1.EnvironmentType;
+import org.apache.geronimo.xml.ns.j2ee.application_1.ApplicationType;
+import org.apache.geronimo.xml.ns.j2ee.application_client_1.ApplicationClientType;
+import org.apache.geronimo.xml.ns.j2ee.connector_1.ConnectorType;
+import org.apache.geronimo.xml.ns.j2ee.web_1.WebAppType;
+import org.apache.geronimo.xml.ns.security_1.SecurityType;
+import org.openejb.xml.ns.openejb_jar_2.OpenejbJarType;
+import org.openejb.xml.ns.openejb_jar_2.RelationshipsType;
+
+/**
+ * @version $Rev: 705268 $ $Date: 2008-10-16 23:54:29 +0800 (Thu, 16 Oct 2008) $
+ */
+public class JAXBModelUtils {
+	
+    
+    public static SecurityType getSecurity (JAXBElement element) {
+        Object plan = element;
+        if (WebAppType.class.isInstance (plan)) {
+            if (((WebAppType)plan).getSecurity() == null) {
+                setSecurity (element, new org.apache.geronimo.xml.ns.security_1.ObjectFactory().createSecurityType());
+            }
+            SecurityType security = (SecurityType)((WebAppType)plan).getSecurity();
+            if (security.getRoleMappings() == null) {
+                security.setRoleMappings (new org.apache.geronimo.xml.ns.security_1.ObjectFactory().createRoleMappingsType());
+            }
+            return security;
+        } else if (ApplicationType.class.isInstance (plan)) {
+            if (((ApplicationType)plan).getSecurity() == null) {
+                setSecurity (element, new org.apache.geronimo.xml.ns.security_1.ObjectFactory().createSecurityType());
+            }
+            SecurityType security = (SecurityType)((ApplicationType)plan).getSecurity();
+            if (security.getRoleMappings() == null) {
+                security.setRoleMappings (new org.apache.geronimo.xml.ns.security_1.ObjectFactory().createRoleMappingsType());
+            }
+            return security;
+        } else if (OpenejbJarType.class.isInstance (plan)) {
+            if (((OpenejbJarType)plan).getSecurity() == null) {
+                setSecurity (element, new org.apache.geronimo.xml.ns.security_1.ObjectFactory().createSecurityType());
+            }
+            SecurityType security = (SecurityType)((OpenejbJarType)plan).getSecurity();
+            if (security.getRoleMappings() == null) {
+                security.setRoleMappings (new org.apache.geronimo.xml.ns.security_1.ObjectFactory().createRoleMappingsType());
+            }
+            return security;
+        }
+        return null;
+    }
+    
+    public static void setSecurity (JAXBElement element, SecurityType security) {
+        Object plan = element;
+        if (WebAppType.class.isInstance (plan)) {
+            ((WebAppType)plan).setSecurity((new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createSecurity( security ).getValue() );
+        } else if (ApplicationType.class.isInstance(plan)) {
+            ((ApplicationType)plan).setSecurity((new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createSecurity( security ).getValue() );
+        } else if (OpenejbJarType.class.isInstance(plan)) {
+            ((OpenejbJarType)plan).setSecurity((new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createSecurity( security ).getValue() );
+        }
+    }
+
+    public static EnvironmentType getEnvironment(JAXBElement element) {
+        return getEnvironment (element, true);
+    }
+
+    public static EnvironmentType getEnvironment(JAXBElement element, boolean serverEnvironment) {
+        Object plan = element;
+        if (serverEnvironment == true) {
+            if (WebAppType.class.isInstance (plan)) {
+                return ((WebAppType)plan).getEnvironment();
+            } else if (ApplicationType.class.isInstance (plan)) {
+                return ((ApplicationType)plan).getEnvironment();
+            } else if (OpenejbJarType.class.isInstance (plan)) {
+                return ((OpenejbJarType)plan).getEnvironment();
+            } else if (ConnectorType.class.isInstance (plan)) {
+                return ((ConnectorType)plan).getEnvironment();
+            } else if (ApplicationClientType.class.isInstance (plan)) {
+                return ((ApplicationClientType)plan).getServerEnvironment();
+            }
+        } else {
+            if (ApplicationClientType.class.isInstance (plan)) {
+                return ((ApplicationClientType)plan).getClientEnvironment();
+            }
+        }
+        return null;
+    }
+
+    public static void setEnvironment (JAXBElement element, EnvironmentType environment) {
+        setEnvironment (element, environment, true);
+    }
+
+    public static void setEnvironment (JAXBElement element, EnvironmentType environment, boolean serverEnvironment) {
+        Object plan = element;
+        if (serverEnvironment == true) {
+            if (WebAppType.class.isInstance (plan)) {
+                ((WebAppType)plan).setEnvironment (environment);
+            } else if (ApplicationType.class.isInstance (plan)) {
+                ((ApplicationType)plan).setEnvironment (environment);
+            } else if (OpenejbJarType.class.isInstance (plan)) {
+                ((OpenejbJarType)plan).setEnvironment (environment);
+            } else if (ConnectorType.class.isInstance (plan)) {
+                ((ConnectorType)plan).setEnvironment (environment);
+            } else if (ApplicationClientType.class.isInstance (plan)) {
+                ((ApplicationClientType)plan).setServerEnvironment (environment);
+            }
+        } else {
+            if (ApplicationClientType.class.isInstance (plan)) {
+                ((ApplicationClientType)plan).setClientEnvironment (environment);
+            }
+        }
+    }
+
+    public static List getGbeans (JAXBElement element) {
+        Object plan = element;
+        if (WebAppType.class.isInstance (plan)) {
+            return ((WebAppType)plan).getGbean();
+        } else if (ApplicationType.class.isInstance (plan)) {
+            return ((ApplicationType)plan).getGbean();
+        } else if (OpenejbJarType.class.isInstance (plan)) {
+            return ((OpenejbJarType)plan).getGbean();
+        } else if (ConnectorType.class.isInstance (plan)) {
+            return ((ConnectorType)plan).getGbean();
+        } else if (ApplicationClientType.class.isInstance (plan)) {
+            return ((ApplicationClientType)plan).getGbean();
+        }
+        return null;
+    }
+
+    public static List getGbeanRefs (JAXBElement element) {
+        Object plan = element;
+        if (ApplicationClientType.class.isInstance (plan)) {
+            return ((ApplicationClientType)plan).getGbeanRef();
+        } else if (WebAppType.class.isInstance (plan)) {
+            return ((WebAppType)plan).getGbeanRef();
+        }
+        return null;
+    }
+
+    public static List getServiceRefs (JAXBElement element) {
+        Object plan = element;
+        if (WebAppType.class.isInstance (plan)) {
+            return ((WebAppType)plan).getServiceRef();
+        }
+        return null;
+    }
+
+    public static List getEjbRelationships (JAXBElement element) {
+        Object plan = element;
+        if (OpenejbJarType.class.isInstance (plan)) {
+            return ((OpenejbJarType)plan).getRelationships() == null ? null : ((OpenejbJarType)plan).getRelationships().getEjbRelation();
+        }
+        return null;
+    }
+    
+    public static void setEjbRelationships (JAXBElement element, RelationshipsType relationships ) {
+        Object plan = element;
+        if (OpenejbJarType.class.isInstance (plan)) {
+            ((OpenejbJarType)plan).setRelationships(relationships);
+        }
+    }
+    
+    public static List getMessageDestinations (JAXBElement element) {
+        Object plan = element;
+        if (WebAppType.class.isInstance (plan)) {
+            return ((WebAppType)plan).getMessageDestination();
+        } else if (OpenejbJarType.class.isInstance (plan)) {
+            return ((OpenejbJarType)plan).getMessageDestination();
+        } else if (ApplicationClientType.class.isInstance (plan)) {
+            return ((ApplicationClientType)plan).getMessageDestination();
+        }
+        return null;
+    }
+}

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBObjectFactory.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBObjectFactory.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBObjectFactory.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBObjectFactory.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core.jaxb;
+
+/**
+ * @version $Rev: 636723 $ $Date: 2008-03-13 19:36:06 +0800 (Thu, 13 Mar 2008) $
+ */
+public interface JAXBObjectFactory {
+
+	public Object create(Class type);
+}

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBObjectFactoryImpl.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBObjectFactoryImpl.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBObjectFactoryImpl.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core.jaxb;
+
+import org.apache.geronimo.st.core.jaxb.JAXBObjectFactory;
+import org.apache.geronimo.xml.ns.deployment.javabean_1.PropertyType;
+import org.apache.geronimo.xml.ns.deployment_1.ArtifactType;
+import org.apache.geronimo.xml.ns.deployment_1.AttributeType;
+import org.apache.geronimo.xml.ns.deployment_1.ClassFilterType;
+import org.apache.geronimo.xml.ns.deployment_1.DependenciesType;
+import org.apache.geronimo.xml.ns.deployment_1.DependencyType;
+import org.apache.geronimo.xml.ns.deployment_1.EnvironmentType;
+import org.apache.geronimo.xml.ns.deployment_1.GbeanType;
+import org.apache.geronimo.xml.ns.deployment_1.ReferenceType;
+import org.apache.geronimo.xml.ns.j2ee.application_1.ExtModuleType;
+import org.apache.geronimo.xml.ns.j2ee.application_1.ModuleType;
+import org.apache.geronimo.xml.ns.j2ee.application_1.PathType;
+import org.apache.geronimo.xml.ns.j2ee.connector_1.AdminobjectInstanceType;
+import org.apache.geronimo.xml.ns.j2ee.connector_1.AdminobjectType;
+import org.apache.geronimo.xml.ns.j2ee.connector_1.ConfigPropertySettingType;
+import org.apache.geronimo.xml.ns.naming_1.EjbLocalRefType;
+import org.apache.geronimo.xml.ns.naming_1.EjbRefType;
+import org.apache.geronimo.xml.ns.naming_1.GbeanRefType;
+import org.apache.geronimo.xml.ns.naming_1.MessageDestinationType;
+import org.apache.geronimo.xml.ns.naming_1.PatternType;
+import org.apache.geronimo.xml.ns.naming_1.PortCompletionType;
+import org.apache.geronimo.xml.ns.naming_1.PortType;
+import org.apache.geronimo.xml.ns.naming_1.ResourceEnvRefType;
+import org.apache.geronimo.xml.ns.naming_1.ResourceRefType;
+import org.apache.geronimo.xml.ns.naming_1.ServiceCompletionType;
+import org.apache.geronimo.xml.ns.naming_1.ServiceRefType;
+import org.apache.geronimo.xml.ns.security_1.DescriptionType;
+import org.apache.geronimo.xml.ns.security_1.DistinguishedNameType;
+import org.apache.geronimo.xml.ns.security_1.LoginDomainPrincipalType;
+import org.apache.geronimo.xml.ns.security_1.PrincipalType;
+import org.apache.geronimo.xml.ns.security_1.RealmPrincipalType;
+import org.apache.geronimo.xml.ns.security_1.RoleMappingsType;
+import org.apache.geronimo.xml.ns.security_1.RoleType;
+import org.apache.geronimo.xml.ns.security_1.SecurityType;
+import org.openejb.xml.ns.openejb_jar_2.EjbRelationType;
+import org.openejb.xml.ns.openejb_jar_2.EjbRelationshipRoleType;
+import org.openejb.xml.ns.openejb_jar_2.RelationshipsType;
+
+
+/**
+ * @version $Rev: 705268 $ $Date: 2008-10-16 23:54:29 +0800 (Thu, 16 Oct 2008) $
+ */
+public class JAXBObjectFactoryImpl implements JAXBObjectFactory {
+
+    private static JAXBObjectFactoryImpl instance = new JAXBObjectFactoryImpl();
+    
+    private JAXBObjectFactoryImpl() {
+        
+    }
+    
+    public static JAXBObjectFactoryImpl getInstance() {
+        return instance;
+    }
+    
+    public Object create(Class type) {
+        if ( type.equals( ResourceRefType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createResourceRefType();
+        } else if ( type.equals( ResourceEnvRefType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createResourceEnvRefType();
+        } else if ( type.equals( EjbRefType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createEjbRefType();
+        } else if ( type.equals( GbeanRefType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createGbeanRefType();
+        } else if ( type.equals( MessageDestinationType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createMessageDestinationType();
+        } else if ( type.equals( PatternType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createPatternType();
+        } else if ( type.equals( PortType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createPortType();
+        } else if ( type.equals( PortCompletionType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createPortCompletionType();
+        } else if ( type.equals( PropertyType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment.javabean_1.ObjectFactory()).createPropertyType();
+        } else if ( type.equals( ServiceCompletionType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createServiceCompletionType();
+        } else if ( type.equals( ServiceRefType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createServiceRefType();
+        } else if ( type.equals( EjbLocalRefType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.naming_1.ObjectFactory()).createEjbLocalRefType();
+        } else if ( type.equals( SecurityType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createSecurityType();
+        } else if ( type.equals( RoleMappingsType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createRoleMappingsType();
+        } else if ( type.equals( DescriptionType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createDescriptionType();
+        } else if ( type.equals( RoleType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createRoleType();
+        } else if ( type.equals( DistinguishedNameType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createDistinguishedNameType();
+        } else if ( type.equals( PrincipalType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createPrincipalType();
+        } else if ( type.equals( LoginDomainPrincipalType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createLoginDomainPrincipalType();
+        } else if ( type.equals( RealmPrincipalType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.security_1.ObjectFactory()).createRealmPrincipalType();
+        } else if ( type.equals( GbeanType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment_1.ObjectFactory()).createGbeanType();
+        } else if ( type.equals( ArtifactType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment_1.ObjectFactory()).createArtifactType();
+        } else if ( type.equals( ClassFilterType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment_1.ObjectFactory()).createClassFilterType();
+        } else if ( type.equals( DependenciesType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment_1.ObjectFactory()).createDependenciesType();
+        } else if ( type.equals( DependencyType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment_1.ObjectFactory()).createDependencyType();
+        } else if ( type.equals( EnvironmentType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment_1.ObjectFactory()).createEnvironmentType();
+        } else if ( type.equals( org.apache.geronimo.xml.ns.deployment_1.PatternType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment_1.ObjectFactory()).createPatternType();
+        } else if ( type.equals( AttributeType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment_1.ObjectFactory()).createAttributeType();
+        } else if ( type.equals( ReferenceType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.deployment_1.ObjectFactory()).createReferenceType();
+        } else if ( type.equals( ExtModuleType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.j2ee.application_1.ObjectFactory()).createExtModuleType();
+        } else if ( type.equals( ModuleType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.j2ee.application_1.ObjectFactory()).createModuleType();
+        } else if ( type.equals( PathType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.j2ee.application_1.ObjectFactory()).createPathType();
+        } else if ( type.equals( EjbRelationType.class ) ) {
+            return (new org.openejb.xml.ns.openejb_jar_2.ObjectFactory()).createEjbRelationType();
+        } else if ( type.equals( EjbRelationshipRoleType.class ) ) {
+            return (new org.openejb.xml.ns.openejb_jar_2.ObjectFactory()).createEjbRelationshipRoleType();
+        } else if ( type.equals( EjbRelationshipRoleType.RelationshipRoleSource.class ) ) {
+            return (new org.openejb.xml.ns.openejb_jar_2.ObjectFactory()).createEjbRelationshipRoleTypeRelationshipRoleSource();
+        } else if ( type.equals( EjbRelationshipRoleType.CmrField.class ) ) {
+            return (new org.openejb.xml.ns.openejb_jar_2.ObjectFactory()).createEjbRelationshipRoleTypeCmrField();
+        } else if ( type.equals( EjbRelationshipRoleType.RoleMapping.CmrFieldMapping.class ) ) {
+            return (new org.openejb.xml.ns.openejb_jar_2.ObjectFactory()).createEjbRelationshipRoleTypeRoleMappingCmrFieldMapping();
+        } else if ( type.equals( EjbRelationshipRoleType.RoleMapping.class ) ) {
+            return (new org.openejb.xml.ns.openejb_jar_2.ObjectFactory()).createEjbRelationshipRoleTypeRoleMapping();
+        } else if ( type.equals( RelationshipsType.class ) ) {
+            return (new org.openejb.xml.ns.openejb_jar_2.ObjectFactory()).createRelationshipsType();
+        } else if ( type.equals( AdminobjectType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.j2ee.connector_1.ObjectFactory()).createAdminobjectType();
+        } else if ( type.equals( AdminobjectInstanceType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.j2ee.connector_1.ObjectFactory()).createAdminobjectInstanceType();
+        } else if ( type.equals( ConfigPropertySettingType.class ) ) {
+            return (new org.apache.geronimo.xml.ns.j2ee.connector_1.ObjectFactory()).createConfigPropertySettingType();
+        }
+        
+        return null;
+    }
+
+}

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBUtils.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBUtils.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/JAXBUtils.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core.jaxb;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Method;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.geronimo.st.core.Activator;
+import org.apache.geronimo.st.core.internal.Trace;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * @version $Rev: 726047 $ $Date: 2008-12-12 23:35:00 +0800 (Fri, 12 Dec 2008) $
+ */
+public class JAXBUtils {
+
+    // JAXBContext instantiation is costly - must be done only once!
+    private static final JAXBContext jaxbContext = newJAXBContext();
+    private static final JAXBContext jaxbPluginContext = newJAXBPluginContext();
+    private static final MarshallerListener marshallerListener = new MarshallerListener();
+
+    private static JAXBContext newJAXBContext() {
+        try {
+            return JAXBContext.newInstance( 
+                    "org.apache.geronimo.xml.ns.deployment_1:" +
+                    "org.apache.geronimo.xml.ns.j2ee.application_1:" +
+                    "org.apache.geronimo.xml.ns.j2ee.application_client_1:" +
+                    "org.apache.geronimo.xml.ns.j2ee.connector_1:" +
+                    "org.apache.geronimo.xml.ns.j2ee.web_1:" +
+                    "org.apache.geronimo.xml.ns.naming_1:" +
+                    "org.apache.geronimo.xml.ns.security_1:" +
+                    "org.openejb.xml.ns.openejb_jar_2:"+
+                    "org.openejb.xml.ns.pkgen_2:"+
+                    "org.openejb.xml.ns.corba_css_config_2:"+
+                    "org.openejb.xml.ns.corba_tss_config_2:", Activator.class.getClassLoader() );
+        } catch (JAXBException e) {
+            Trace.tracePoint("JAXBException", "JAXBContext.newInstance");
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private static JAXBContext newJAXBPluginContext() {
+        try {
+            return JAXBContext.newInstance( 
+                    "org.apache.geronimo.system.plugin.model", Activator.class.getClassLoader() );
+        } catch (JAXBException e) {
+            Trace.tracePoint("JAXBException", "JAXBContext.newInstance");
+            e.printStackTrace();
+        }
+        return null;
+    }
+    
+    public static void marshalDeploymentPlan(JAXBElement jaxbElement, IFile file) throws Exception {
+        try {
+            Marshaller marshaller = jaxbContext.createMarshaller();
+            marshaller.setListener(marshallerListener);
+
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            dbf.setNamespaceAware(true);
+            DocumentBuilder db = dbf.newDocumentBuilder();
+            Document doc = db.newDocument(); 
+
+            marshaller.marshal(jaxbElement, doc);
+
+            TransformerFactory xf = TransformerFactory.newInstance();
+            try {
+            	xf.setAttribute("indent-number", new Integer(4));
+            } catch (IllegalArgumentException iae) {
+                //ignore this. http://forums.sun.com/thread.jspa?threadID=562510&messageID=2841867
+            }
+            Transformer xformer = xf.newTransformer();
+            xformer.setOutputProperty(OutputKeys.METHOD, "xml");
+            xformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            xformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+            xformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "4"); 
+
+            ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
+            Result out = new StreamResult(new OutputStreamWriter(outBuffer,"UTF-8"));
+            NamespacePrefix.processPrefix(doc);
+
+            xformer.transform(new DOMSource(doc), out);
+            ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
+            if(file.exists()) {
+                file.setContents(inBuffer, true, false, null);
+            } else {
+                prepareFolder(file.getParent());
+                file.create(inBuffer, true, null);
+            }
+        } catch (JAXBException jaxbException) {
+            Trace.tracePoint("JAXBException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+            throw jaxbException;
+        } catch (CoreException coreException) {
+            Trace.tracePoint("CoreException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+            throw coreException;
+        } catch (ParserConfigurationException e) {
+        	Trace.tracePoint("ParserConfigurationException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+        	throw e;
+		} catch (TransformerConfigurationException e) {
+			Trace.tracePoint("TransformerConfigurationException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+			throw e;
+		} catch (UnsupportedEncodingException e) {
+			Trace.tracePoint("UnsupportedEncodingException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+			throw e;
+		} catch (TransformerException e) {
+			Trace.tracePoint("TransformerException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+			throw e;
+		}
+    }
+
+    public static JAXBElement unmarshalFilterDeploymentPlan(IFile file) throws Exception {
+        try {
+            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            factory.setNamespaceAware(true);
+            factory.setValidating(false);
+            SAXParser parser = factory.newSAXParser();
+            SAXSource source = new SAXSource(null, new InputSource(file.getContents()));
+            JAXBElement plan = (JAXBElement) unmarshaller.unmarshal(source);
+            return plan;
+        } catch (JAXBException e) {
+            Trace.tracePoint("JAXBException", "JAXBUtils.unmarshalFilterDeploymentPlan()", file.getFullPath());
+            throw e;
+        } catch (CoreException e) {
+            Trace.tracePoint("CoreException", "JAXBUtils.unmarshalFilterDeploymentPlan()", file.getFullPath());
+            throw e;
+        } catch (ParserConfigurationException e) {
+            Trace.tracePoint("ParserConfigurationException", "JAXBUtils.unmarshalFilterDeploymentPlan()", file.getFullPath());
+            throw e;
+        } catch (SAXException e) {
+            Trace.tracePoint("SAXException", "JAXBUtils.unmarshalFilterDeploymentPlan()", file.getFullPath());
+            throw e;
+        }
+    }
+
+    public static void marshalPlugin(JAXBElement jaxbElement, OutputStream outputStream) throws Exception {
+        try {
+            Marshaller marshaller = jaxbPluginContext.createMarshaller();
+            marshaller.setListener(marshallerListener);
+
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            DocumentBuilder db = dbf.newDocumentBuilder();
+            Document doc = db.newDocument(); 
+
+            marshaller.marshal(jaxbElement, doc);
+
+            TransformerFactory xf = TransformerFactory.newInstance();
+            try {
+                xf.setAttribute("indent-number", new Integer(4));
+            } catch (IllegalArgumentException iae) {
+                //ignore this. http://forums.sun.com/thread.jspa?threadID=562510&messageID=2841867
+            }
+            Transformer xformer = xf.newTransformer();
+            xformer.setOutputProperty(OutputKeys.METHOD, "xml");
+            xformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            xformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+            xformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "4"); 
+
+            ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
+            Result out = new StreamResult(new OutputStreamWriter(outBuffer,"UTF-8"));
+
+            xformer.transform(new DOMSource(doc), out);
+            ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
+            outputStream.write(outBuffer.toByteArray());
+        } catch (JAXBException jaxbException) {
+            Trace.tracePoint("JAXBException", "JAXBUtils.marshalDeploymentPlan()");
+            throw jaxbException;
+        } catch (IOException coreException) {
+            Trace.tracePoint("IOException", "JAXBUtils.marshalDeploymentPlan()");
+            throw coreException;
+        } catch (ParserConfigurationException e) {
+            Trace.tracePoint("ParserConfigurationException", "JAXBUtils.marshalDeploymentPlan()");
+            throw e;
+        } catch (TransformerConfigurationException e) {
+            Trace.tracePoint("TransformerConfigurationException", "JAXBUtils.marshalDeploymentPlan()");
+            throw e;
+        } catch (TransformerException e) {
+            Trace.tracePoint("TransformerException", "JAXBUtils.marshalDeploymentPlan()");
+            throw e;
+        }
+    }
+
+    public static JAXBElement unmarshalPlugin(InputStream inputStream) {
+        try {
+            Unmarshaller unmarshaller = jaxbPluginContext.createUnmarshaller();
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            factory.setNamespaceAware(true);
+            factory.setValidating(false);
+            SAXParser parser = factory.newSAXParser();
+            SAXSource source = new SAXSource(null, new InputSource(inputStream));
+            JAXBElement plan = (JAXBElement) unmarshaller.unmarshal(source);
+            return plan;
+        } catch (JAXBException e) {
+            Trace.tracePoint("JAXBException", "JAXBUtils.unmarshalFilterDeploymentPlan()");
+            e.printStackTrace();
+        } catch (ParserConfigurationException e) {
+            Trace.tracePoint("ParserConfigurationException", "JAXBUtils.unmarshalFilterDeploymentPlan()");
+            e.printStackTrace();
+        } catch (SAXException e) {
+            Trace.tracePoint("SAXException", "JAXBUtils.unmarshalFilterDeploymentPlan()");
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private static void prepareFolder(IContainer folder) throws CoreException {
+        if (folder.exists() || !(folder instanceof IFolder)) {
+            return;
+        }
+        // prepare the upper level folders recursively
+        prepareFolder(folder.getParent());
+        ((IFolder) folder).create(true, true, null);
+    }
+
+    public static Object getValue( Object element, String name ) throws Exception {
+        try {
+            if (String.class.isInstance(element))
+                return (String)element;
+            Method method = element.getClass().getMethod( "get" + name, null);
+            return method.invoke(element, null);
+        } catch ( Exception e ) {
+            throw e;
+        }
+    }
+    
+    public static void setValue( Object element, String name, Object value ) throws Exception {
+        try {
+            Method[] methods = element.getClass().getMethods();
+            for ( Method method: methods) {
+                if ( method.getName().equals( "set" + name ) ) {
+                    method.invoke( element, value );
+                    return;
+                }
+            }
+        } catch (Exception e) {
+            throw e;
+        }
+        System.out.println( "============== No such method set" + name + " in class " + element.getClass().getName() );
+    }
+}

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/MarshallerListener.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/MarshallerListener.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/MarshallerListener.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/MarshallerListener.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core.jaxb;
+
+import javax.xml.bind.Marshaller;
+
+import org.apache.geronimo.xml.ns.j2ee.web_1.WebAppType;
+import org.apache.geronimo.xml.ns.naming_1.GbeanLocatorType;
+import org.apache.geronimo.xml.ns.naming_1.PatternType;
+import org.apache.geronimo.xml.ns.naming_1.ResourceLocatorType;
+import org.apache.geronimo.xml.ns.security_1.SecurityType;
+import org.openejb.xml.ns.openejb_jar_2.EjbRelationshipRoleType;
+import org.openejb.xml.ns.openejb_jar_2.OpenejbJarType;
+import org.openejb.xml.ns.openejb_jar_2.RelationshipsType;
+
+public class MarshallerListener extends Marshaller.Listener{
+
+    @Override
+    public void beforeMarshal(Object source) {
+        if (source instanceof SecurityType) {
+            SecurityType security = (SecurityType)source;
+            if (security.getRoleMappings() != null && security.getRoleMappings().getRole().size() == 0) {
+                security.setRoleMappings(null);
+            } 
+        } else if (source instanceof WebAppType) {
+            WebAppType webapp = (WebAppType)source;
+            GbeanLocatorType gbeanlocator = webapp.getWebContainer();
+            if (gbeanlocator != null && isEmpty(gbeanlocator.getGbeanLink()) && isEmpty(gbeanlocator.getPattern())) {
+                webapp.setWebContainer(null);
+            }
+        } else if (source instanceof OpenejbJarType) {
+        	OpenejbJarType openejb = (OpenejbJarType)source;
+            ResourceLocatorType locator = openejb.getCmpConnectionFactory();
+            if (locator != null && isEmpty(locator.getResourceLink()) && isEmpty(locator.getUrl()) && isEmpty(locator.getPattern())) {
+                openejb.setCmpConnectionFactory(null);
+            }
+            RelationshipsType relationships = openejb.getRelationships();
+            if (relationships != null && relationships.getEjbRelation().size() == 0) {
+                openejb.setRelationships(null);
+            }
+        }else if (source instanceof EjbRelationshipRoleType) {
+        	EjbRelationshipRoleType role = (EjbRelationshipRoleType)source;
+            if (role.getRoleMapping() != null && role.getRoleMapping().getCmrFieldMapping().size() == 0) {
+                role.setRoleMapping(null);
+            }
+        }
+    }
+        
+    private boolean isEmpty(PatternType pattern) {
+        if ( pattern == null ) {
+            return true;
+        }
+        if ( isEmpty(pattern.getGroupId()) && isEmpty(pattern.getArtifactId()) &&
+                isEmpty(pattern.getModule()) && isEmpty(pattern.getName()) &&
+                isEmpty(pattern.getVersion()) ) {
+            return true;
+        }
+        return false;
+    }
+    
+    private boolean isEmpty(String value) {
+        
+        return (value == null || value.trim().equals(""));
+    }
+
+}

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/NamespacePrefix.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/NamespacePrefix.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/NamespacePrefix.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/jaxb/NamespacePrefix.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.st.v11.core.jaxb;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @version $Rev: 685643 $ $Date: 2008-08-14 03:24:11 +0800 (Thu, 14 Aug 2008) $ 
+ */
+public class NamespacePrefix {
+
+    private static Map<String, String> prefixMap = new HashMap<String, String>();
+
+    static {
+        prefixMap.put("http://geronimo.apache.org/xml/ns/deployment-1.1", "dep");
+        prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/application-1.1", "app");
+        prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/application-client-1.1", "client");
+        prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/connector-1.1", "conn");
+        prefixMap.put("http://openejb.apache.org/xml/ns/openejb-jar-2.1", "ejb");
+        prefixMap.put("http://openejb.apache.org/xml/ns/pkgen-2.0", "pkgen");
+        prefixMap.put("http://geronimo.apache.org/xml/ns/naming-1.1", "name");
+        prefixMap.put("http://geronimo.apache.org/xml/ns/security-1.1", "sec");
+        prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/web-1.1", "web");
+    }
+	
+	public static void processPrefix( Node parent ) {
+		NodeList nl = parent.getChildNodes();
+		
+		if ( parent instanceof Element ) {
+			updatePrefix( (Element)parent );
+		}
+		
+		for ( int i = 0; i <= nl.getLength(); i ++ ) {
+			Node node = nl.item(i);
+			if ( node instanceof Element ) {
+				processPrefix( node );
+			}
+		}
+
+	}
+	
+	private static void updatePrefix( Element element ) {
+		NamedNodeMap mnm = element.getAttributes();
+		
+		ArrayList<Attr> attributes = new ArrayList<Attr>();
+		for ( int j = 0; j <= mnm.getLength(); j ++ ) { 
+			Attr attr = (Attr)mnm.item(j);
+			if ( attr != null && attr.getOwnerElement() != null && getPrefix( attr.getNodeValue() ) != null ) {
+				attributes.add((Attr)attr.cloneNode(false));
+			}
+		}
+		for ( int j = 0; j < attributes.size(); j ++ ) {
+			Attr tempAttr = attributes.get(j);
+			Attr attr = element.getAttributeNode(tempAttr.getName());
+			Element owner = (Element)attr.getOwnerElement();
+			owner.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + getPrefix( attr.getNodeValue() ), attr.getNodeValue());
+			owner.removeAttributeNode(attr);
+		}
+		String prefix = getPrefix( element.getNamespaceURI() );
+		if ( prefix != null ) {
+		    element.setPrefix( prefix );
+		}
+	}
+
+	private static String getPrefix(String namespaceURI) {
+        if (prefixMap.containsKey(namespaceURI))
+            return prefixMap.get(namespaceURI);
+		return null;
+	}
+
+}

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/operations/GeronimoV11FacetInstallDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/operations/GeronimoV11FacetInstallDelegate.java?rev=817996&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/operations/GeronimoV11FacetInstallDelegate.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v11.core/src/org/apache/geronimo/st/v11/core/operations/GeronimoV11FacetInstallDelegate.java Wed Sep 23 08:04:12 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v11.core.operations;
+
+import org.apache.geronimo.st.core.GeronimoFacetInstallDelegate;
+import org.apache.geronimo.st.v21.core.internal.Trace;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jst.common.project.facet.JavaProjectFacetCreationDataModelProvider;
+import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
+
+/**
+ * @version $Rev: 471551 $ $Date: 2006-11-05 17:47:11 -0500 (Sun, 05 Nov 2006) $
+ */
+public class GeronimoV11FacetInstallDelegate extends GeronimoFacetInstallDelegate {
+
+	public IDataModelOperation createDeploymentPlanCreationOp(IProject project, Object config) {
+		Trace.tracePoint("Entry", "GeronimoV11FacetInstallDelegate.createDeploymentPlanCreationOp", project, config);
+		
+		IDataModel model = DataModelFactory.createDataModel(new JavaProjectFacetCreationDataModelProvider());
+		model.setStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME, project.getName());
+		
+		Trace.tracePoint("Exit ", "GeronimoV11FacetInstallDelegate.createDeploymentPlanCreationOp");
+		return new V11DeploymentPlanCreationOperation(model, config);
+	}
+}



Mime
View raw message