You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by mc...@apache.org on 2010/04/29 02:45:15 UTC
svn commit: r939145 [6/7] - in
/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core:
./ META-INF/ src/main/java/org/apache/geronimo/st/v30/core/
src/main/java/org/apache/geronimo/st/v30/core/commands/
src/main/java/org/apache...
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyHelper.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyHelper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyManager.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyManager.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyManager.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyManager.java Thu Apr 29 00:45:13 2010
@@ -0,0 +1,213 @@
+/*
+ * 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.v30.core.internal;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.jee.deployment.Artifact;
+
+/**
+ * <b>DependencyManager</b> is very closely-based on the similar class in the Geronimo server.
+ * DependencyManager is the record keeper of the dependencies in the Geronimo Eclipse Plugin. The
+ * DependencyManager does not enforce any dependencies, it is simply a place where components can
+ * register their intent to be dependent on another component, and where other components can query
+ * those dependencies.
+ *
+ * <p>Like the DependencyManager in the Geronimo server, it uses the nomenclature of parent-child
+ * where a child is dependent on a parent. The names parent and child have no other meaning are just
+ * a convenience to make the code readable.
+ *
+ * <p>The initial usage of this DependencyManager in the GEP is somewhat limited but other usages
+ * are possible<p>
+ *
+ * @version $Rev$ $Date$
+ */
+public class DependencyManager {
+
+ //
+ // Map from child to a list of parents
+ //
+ private final Map childToParentMap = new HashMap();
+
+ //
+ // Map from parent back to a list of its children
+ //
+ private final Map parentToChildMap = new HashMap();
+
+
+ /**
+ *
+ */
+ public void close() {
+ childToParentMap.clear();
+ parentToChildMap.clear();
+ }
+
+
+ /**
+ * Declares a dependency from a child to a parent.
+ *
+ * @param child the dependent component
+ * @param parent the component the child is depending on
+ */
+ public void addDependency(Artifact child, Artifact parent) {
+ Trace.tracePoint("Entry", "DependencyManager.addDependency", child, parent);
+
+ Set parents = (Set) childToParentMap.get(child);
+ if (parents == null) {
+ parents = new LinkedHashSet();
+ childToParentMap.put(child, parents);
+ }
+ parents.add(parent);
+
+ Set children = (Set) parentToChildMap.get(parent);
+ if (children == null) {
+ children = new LinkedHashSet();
+ parentToChildMap.put(parent, children);
+ }
+ children.add(child);
+
+ Trace.tracePoint("Exit ", "DependencyManager.addDependency", childToParentMap.size() );
+ Trace.tracePoint("Exit ", "DependencyManager.addDependency", parentToChildMap.size() );
+ }
+
+
+ /**
+ * Removes a dependency from a child to a parent
+ *
+ * @param child the dependnet component
+ * @param parent the component that the child wil no longer depend on
+ */
+ public void removeDependency(Artifact child, Artifact parent) {
+ Trace.tracePoint("Entry", "DependencyManager.removeDependency", child, parent);
+
+ Set parents = (Set) childToParentMap.get(child);
+ if (parents != null) {
+ parents.remove(parent);
+ }
+
+ Set children = (Set) parentToChildMap.get(parent);
+ if (children != null) {
+ children.remove(child);
+ }
+
+ Trace.tracePoint("Exit ", "DependencyManager.addDependency");
+ }
+
+
+ /**
+ * Removes all dependencies for a child
+ *
+ * @param child the component that will no longer depend on anything
+ */
+ public void removeAllDependencies(Artifact child) {
+ Trace.tracePoint("Entry", "DependencyManager.removeAllDependencies", child);
+
+ Set parents = (Set) childToParentMap.remove(child);
+ if (parents == null) {
+ return;
+ }
+
+ for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
+ Artifact parent = (Artifact) iterator.next();
+ Set children = (Set) parentToChildMap.get(parent);
+ if (children != null) {
+ children.remove(child);
+ }
+ }
+
+ Trace.tracePoint("Exit ", "DependencyManager.removeAllDependencies");
+ }
+
+
+ /**
+ * Adds dependencies from the child to every parent in the parents set
+ *
+ * @param child the dependent component
+ * @param parents the set of components the child is depending on
+ */
+ public void addDependencies(Artifact child, Set parents) {
+ Trace.tracePoint("Entry", "DependencyManager.addDependencies", child, parents);
+
+ Set existingParents = (Set) childToParentMap.get(child);
+ if (existingParents == null) {
+ existingParents = new LinkedHashSet(parents);
+ childToParentMap.put(child, existingParents);
+ }
+ else {
+ existingParents.addAll(parents);
+ }
+
+ for (Iterator i = parents.iterator(); i.hasNext();) {
+ Object startParent = i.next();
+ Set children = (Set) parentToChildMap.get(startParent);
+ if (children == null) {
+ children = new LinkedHashSet();
+ parentToChildMap.put(startParent, children);
+ }
+ children.add(child);
+ }
+
+ Trace.tracePoint("Exit ", "DependencyManager.addDependencies");
+ }
+
+
+ /**
+ * Gets the set of parents that the child is depending on
+ *
+ * @param child the dependent component
+ * @return a collection containing all of the components the child depends on; will never be null
+ */
+ public Set getParents(Artifact child) {
+ Trace.tracePoint("Entry", "DependencyManager.getParents", child);
+
+ Set parents = (Set) childToParentMap.get(child);
+ if (parents == null) {
+ Trace.tracePoint("Exit", "DependencyManager.getParents", 0);
+ return Collections.EMPTY_SET;
+ }
+
+ Trace.tracePoint("Exit", "DependencyManager.getParents", parents.size() );
+ return new LinkedHashSet(parents);
+ }
+
+
+ /**
+ * Gets all of the children that have a dependency on the specified parent.
+ *
+ * @param parent the component the returned childen set depend on
+ * @return a collection containing all of the components that depend on the parent; will never be null
+ */
+ public Set getChildren(Artifact parent) {
+ Trace.tracePoint("Entry", "DependencyManager.getChildren", parent);
+
+ Set children = (Set) parentToChildMap.get(parent);
+ if (children == null) {
+ Trace.tracePoint("Exit ", "DependencyManager.getChildren", 0);
+ return Collections.EMPTY_SET;
+ }
+
+ Trace.tracePoint("Exit ", "DependencyManager.getChildren", children.size() );
+ return new LinkedHashSet(children);
+ }
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyManager.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/DependencyManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java Thu Apr 29 00:45:13 2010
@@ -0,0 +1,66 @@
+/*
+ * 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.v30.core.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Translated messages.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Messages extends NLS {
+
+ static {
+ NLS.initializeMessages("org.apache.geronimo.st.v30.core.internal.Messages", Messages.class);
+ }
+
+ public static String DISTRIBUTE_FAIL;
+ public static String START_FAIL;
+ public static String STOP_FAIL;
+ public static String UNDEPLOY_FAIL;
+ public static String REDEPLOY_FAIL;
+ public static String DM_CONNECTION_FAIL;
+
+ public static String errorJRE;
+
+ public static String targetRuntime;
+
+ public static String incorrectVersion;
+ public static String noVersion;
+ public static String missingContent;
+ public static String errorPortInUse;
+ public static String missingServer;
+
+ public static String errorNoProfiler;
+
+ // errors for GeronimoServerPluginManager
+ public static String badConfigId;
+ public static String errorDeletePlugin;
+ public static String errorMovePlugin;
+ public static String badPlugin;
+ public static String errorCreateMetadata;
+ public static String errorUpdateMetadata;
+ public static String errorReadConfig;
+ public static String errorReadSerFile;
+ public static String errorNoSerFile;
+ public static String errorLoadClass;
+ public static String requires;
+ public static String installed;
+ public static String configSizeMismatch;
+ public static String noDefaultServer;
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties Thu Apr 29 00:45:13 2010
@@ -0,0 +1,51 @@
+#
+# 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.
+#
+# $Rev$ $Date$
+#
+DISTRIBUTE_FAIL=Distribution of module failed. See log for details.
+START_FAIL=Starting of module failed. See log for details.
+STOP_FAIL=Stopping of module failed. See log for details.
+UNDEPLOY_FAIL=Undeploy of module failed. See log for details.
+REDEPLOY_FAIL=Redeploy of module failed. See log for details.
+DM_CONNECTION_FAIL=Connection to deployment manager failed. See log for details.
+
+targetRuntime=Geronimo v3.0 Runtime
+
+incorrectVersion=An incorrect version of {0} was detected. Version {1} was expected, but version {2} was found.
+noVersion=A {0} installation was detected, however the version could not be verified.
+missingContent=A {0} installation was detected, however parts of the server seem to be missing.
+errorJRE=The JRE could not be found. Edit the server and change the JRE location.
+errorPortInUse=Port {0} required by {1} is already in use. The server may already be running in another process, or a system process may be using the port. \
+To start this server you will need to stop the other process or change the port number(s).
+missingServer=Server does not exist
+
+errorNoProfiler=Could not launch in profiling mode because no profilers are configured.
+
+badConfigId=Bad configID; should never happen.
+errorDeletePlugin=Unable to delete old plugin at {0}.
+errorMovePlugin=Unable to move new plugin {0} to {1}.
+badadPlugin={0} is not a plugin.
+errorCreateMetadata=Cannot create plugin metadata file for {0}.
+errorUpdateMetadata=Unable to update plugin metadata.
+errorReadConfig=Cannot read configuration {0}.
+errorReadSerFile=Can not read configuration META-INF/config.ser file: {0}.
+errorNoSerFile=Configuration does not contain a META-INF/config.ser file: {0}.
+errorLoadClass=Unable to load class from config: {0}.
+requires= requires
+installed= to be installed.
+configSizeMismatch=A plugin configuration must include one plugin artifact, not {0}.
+noDefaultServer=Invalid setup, no default server instance registered.
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/ConversionHelper.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/ConversionHelper.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/ConversionHelper.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/ConversionHelper.java Thu Apr 29 00:45:13 2010
@@ -0,0 +1,143 @@
+/*
+ * 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.v30.core.jaxb;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+
+import org.apache.geronimo.st.v30.core.internal.Trace;
+import org.eclipse.core.resources.IFile;
+
+/**
+ * <strong>ConversionHelper</strong> is a helper class with numerous static
+ * methods to aid in the conversion of Geronimo-specific deployment plans from
+ * one JAXB version to another (e.g., v1.1 to v2.1)<p>
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversionHelper {
+
+ /**
+ * Convert a geronimo-web.xml deployment plan file (if necessary)
+ * and return the JAXB representation
+ *
+ * @param plan Geronimo deployment plan
+ * @throws Exception
+ */
+ public static void convertGeronimoWebFile( IFile plan ) throws Exception {
+ Trace.tracePoint("Entry", "ConversionHelper.convertGeronimoWebFile", plan);
+
+ convertNamespace( plan );
+
+ Trace.tracePoint("Exit ", "ConversionHelper.convertGeronimoWebFile");
+ }
+
+
+ /**
+ * Convert an openejb-jar.xml deployment plan file (if necessary) and return the
+ * JAXB representation
+ *
+ * @param plan OpenEJB deployment plan
+ * @throws Exception
+ */
+ public static void convertOpenEjbJarFile( IFile plan ) throws Exception {
+ Trace.tracePoint("Entry", "ConversionHelper.convertGeronimoOpenEjbFile", plan);
+
+ convertNamespace( plan );
+
+ Trace.tracePoint("Exit ", "ConversionHelper.convertGeronimoOpenEjbFile");
+ }
+
+
+ /**
+ * Convert a geronimo-application.xml deployment plan file (if necessary)
+ * and return the JAXB representation
+ *
+ * @param plan Geronimo deployment plan
+ *
+ * @exception JAXBException if JAXB error
+ */
+ public static void convertGeronimoApplicationFile( IFile plan ) throws Exception {
+ Trace.tracePoint("Entry", "ConversionHelper.convertGeronimoApplicationFile", plan);
+
+ convertNamespace( plan );
+
+ Trace.tracePoint("Exit ", "ConversionHelper.convertGeronimoApplicationFile");
+ }
+
+
+ /**
+ * Convert a geronimo-ra.xml deployment plan file (if necessary)
+ * and return the JAXB representation
+ *
+ * @param plan Geronimo deployment plan
+ *
+ * @exception JAXBException if JAXB error
+ */
+ public static void convertGeronimoRaFile( IFile plan ) throws Exception {
+ Trace.tracePoint("Entry", "ConversionHelper.convertGeronimoRaFile", plan);
+
+ convertNamespace( plan );
+
+ Trace.tracePoint("Exit ", "ConversionHelper.convertGeronimoRaFile");
+ }
+
+
+ /**
+ * Convert a geronimo-application-client.xml deployment plan file
+ * and return the JAXB representation
+ *
+ * @param plan Geronimo deployment plan
+ *
+ * @exception JAXBException if JAXB error
+ */
+ public static void convertGeronimoApplicationClientFile( IFile plan ) throws Exception {
+ Trace.tracePoint("Entry", "ConversionHelper.convertGeronimoApplicationClientFile", plan);
+
+ convertNamespace( plan );
+
+ Trace.tracePoint("Exit ", "ConversionHelper.convertGeronimoApplicationClientFile");
+ }
+
+
+ /*------------------------------------------------------------------------*\
+ | |
+ | Private method(s) |
+ | |
+ \*------------------------------------------------------------------------*/
+
+
+ /**
+ * Convert the namespace of the Geronimo deployment plan and then save the
+ * deployment plan
+ *
+ * @param plan Geronimo deployment plan
+ */
+ private static void convertNamespace( IFile plan ) throws Exception{
+
+ //
+ // Unmarshall and filter the deployment plan
+ //
+ JAXBElement jaxbElement = JAXBUtils.unmarshalFilterDeploymentPlan(plan);
+
+ //
+ // Marshall and save the deployment plan from the jaxbElement
+ //
+ JAXBUtils.marshalDeploymentPlan( jaxbElement, plan );
+ }
+}
\ No newline at end of file
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/ConversionHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/ConversionHelper.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/ConversionHelper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/IJAXBUtilsProvider.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/IJAXBUtilsProvider.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/IJAXBUtilsProvider.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/IJAXBUtilsProvider.java Thu Apr 29 00:45:13 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.v30.core.jaxb;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+
+import org.eclipse.core.resources.IFile;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface IJAXBUtilsProvider {
+ public JAXBContext getJAXBContext();
+ public void marshalDeploymentPlan(JAXBElement jaxbElement, IFile file) throws Exception;
+ public void marshalPlugin(JAXBElement jaxbElement, OutputStream outputStream) throws Exception;
+ public JAXBElement unmarshalFilterDeploymentPlan(IFile file) throws Exception;
+ public JAXBElement unmarshalPlugin(InputStream inputStream);
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/IJAXBUtilsProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/IJAXBUtilsProvider.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/IJAXBUtilsProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXB21Utils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXB21Utils.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXB21Utils.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXB21Utils.java Thu Apr 29 00:45:13 2010
@@ -0,0 +1,298 @@
+/*
+ * 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.v30.core.jaxb;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+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.v30.core.Activator;
+import org.apache.geronimo.st.v30.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$ $Date$
+ */
+public class JAXB21Utils implements IJAXBUtilsProvider{
+
+ // 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 JAXB21Utils _instance = new JAXB21Utils();
+
+ private static JAXBContext newJAXBContext() {
+ try {
+ return JAXBContext.newInstance(
+ "org.apache.geronimo.jee.connector:" +
+ "org.apache.geronimo.jee.loginconfig:" +
+ "org.apache.geronimo.jee.openejb:" +
+ "org.apache.geronimo.jee.web:" +
+ "org.apache.geronimo.jee.application:" +
+ "org.apache.geronimo.jee.applicationclient:" +
+ "org.apache.geronimo.jee.deployment:" +
+ "org.apache.geronimo.jee.naming:" +
+ "org.apache.geronimo.jee.security:", Activator.class.getClassLoader() );
+ } catch (JAXBException e) {
+ Trace.tracePoint("JAXBException", "JAXBContext.newInstance");
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /*private JAXB21Utils(){
+ }
+
+ public static JAXB21Utils getInstance(){
+ return _instance;
+ }*/
+
+ public JAXBContext getJAXBContext(){
+ return jaxbContext;
+ }
+
+ 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 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 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();
+ NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
+ SAXSource source = new SAXSource(xmlFilter, 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 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 JAXBElement unmarshalPlugin(InputStream inputStream) {
+ try {
+ Unmarshaller unmarshaller = jaxbPluginContext.createUnmarshaller();
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setValidating(false);
+ SAXParser parser = factory.newSAXParser();
+ NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
+ SAXSource source = new SAXSource(xmlFilter, 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 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 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 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() );
+ }
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXB21Utils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXB21Utils.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXB21Utils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBModelUtils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBModelUtils.java?rev=939145&r1=939144&r2=939145&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBModelUtils.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBModelUtils.java Thu Apr 29 00:45:13 2010
@@ -33,7 +33,7 @@ import org.apache.geronimo.jee.web.WebAp
* @version $Rev$ $Date$
*/
public class JAXBModelUtils {
-
+
public static Security getSecurity (JAXBElement element) {
Object plan = element.getValue();
@@ -45,13 +45,13 @@ public class JAXBModelUtils {
return security;
} else if (Application.class.isInstance (plan)) {
if (((Application)plan).getSecurity() == null) {
- return null;
+ return null;
}
Security security = (Security)((Application)plan).getSecurity().getValue();
return security;
} else if (OpenejbJar.class.isInstance (plan)) {
if (((OpenejbJar)plan).getSecurity() == null) {
- return null;
+ return null;
}
Security security = (Security)((OpenejbJar)plan).getSecurity().getValue();
return security;
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactory.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactory.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactory.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactory.java Thu Apr 29 00:45:13 2010
@@ -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.v30.core.jaxb;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface JAXBObjectFactory {
+
+ public Object create(Class type);
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactoryImpl.java?rev=939145&r1=939144&r2=939145&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactoryImpl.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBObjectFactoryImpl.java Thu Apr 29 00:45:13 2010
@@ -16,7 +16,6 @@
*/
package org.apache.geronimo.st.v30.core.jaxb;
-import org.apache.geronimo.st.core.jaxb.JAXBObjectFactory;
import org.apache.geronimo.jee.application.ExtModule;
import org.apache.geronimo.jee.application.Module;
import org.apache.geronimo.jee.application.Path;
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBUtils.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBUtils.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBUtils.java Thu Apr 29 00:45:13 2010
@@ -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 anguage governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.st.v30.core.jaxb;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+
+import org.apache.geronimo.st.v30.core.Activator;
+import org.apache.geronimo.st.v30.core.internal.Trace;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jst.server.core.FacetUtil;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.server.core.IRuntime;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JAXBUtils {
+
+ private static Map<String,IJAXBUtilsProvider> providers = new HashMap<String,IJAXBUtilsProvider>();
+
+ static {
+ loadExtensionPoints();
+ }
+
+ private static synchronized void loadExtensionPoints() {
+ Trace.tracePoint("ENTRY", "JAXBUtils.loadExtensionPoints");
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] cf = registry.getConfigurationElementsFor(Activator.PLUGIN_ID, "JAXBUtilsProvider");
+ for (int i = 0; i < cf.length; i++) {
+ IConfigurationElement element = cf[i];
+ if ("provider".equals(element.getName())) {
+ try {
+ IJAXBUtilsProvider provider = (IJAXBUtilsProvider) element.createExecutableExtension("class");
+ String versions = element.getAttribute("version");
+ String[] versionArray = versions.split(",");
+ for (int j=0;j<versionArray.length;j++) {
+ providers.put(versionArray[j], provider);
+ }
+ } catch (CoreException e) {
+ Trace.tracePoint("CoreException", "JAXBUtils.loadExtensionPoints");
+ e.printStackTrace();
+ }
+ }
+ }
+
+ Trace.tracePoint("EXIT", "JAXBUtils.loadExtensionPoints");
+ }
+
+ public static List<JAXBContext> getJAXBContext(){
+ List<JAXBContext> contextList = new ArrayList<JAXBContext>();
+
+ Collection<IJAXBUtilsProvider> jaxbutils = providers.values();
+ Iterator<IJAXBUtilsProvider> iterator = jaxbutils.iterator();
+ while (iterator.hasNext()){
+ IJAXBUtilsProvider provider = iterator.next();
+ contextList.add(provider.getJAXBContext());
+ }
+ return contextList;
+ }
+
+ private static IJAXBUtilsProvider getProvider(IFile plan) {
+ Trace.tracePoint("ENTRY", "JAXBUtils.getProvider");
+
+ IJAXBUtilsProvider provider = null;
+ if (plan != null) {
+ IProject project = plan.getProject();
+ try {
+ IFacetedProject fp = ProjectFacetsManager.create(project);
+ if (fp == null) return null;
+ IRuntime runtime = FacetUtil.getRuntime(fp.getPrimaryRuntime());
+ if (runtime == null) return null;
+ String version = runtime.getRuntimeType().getVersion();
+ provider = (IJAXBUtilsProvider) providers.get(version);
+ } catch (CoreException e) {
+ Trace.tracePoint("CoreException", "JAXBUtils.getProvider");
+ e.printStackTrace();
+ } catch (IllegalArgumentException ie) {
+ Trace.tracePoint("IllegalArgumentException", "JAXBUtils.getProvider");
+ throw new IllegalArgumentException("The project [" + project.getName() + "] does not have a Targeted Runtime specified.");
+ }
+ }
+
+ Trace.tracePoint("EXIT", "JAXBUtils.getProvider", provider);
+ return provider;
+ }
+
+ public static void marshalDeploymentPlan(JAXBElement jaxbElement, IFile file) throws Exception {
+ IJAXBUtilsProvider provider = getProvider(file);
+ provider.marshalDeploymentPlan(jaxbElement, file);
+ }
+
+ public static JAXBElement unmarshalFilterDeploymentPlan(IFile file) throws Exception {
+ IJAXBUtilsProvider provider = getProvider(file);
+ return provider.unmarshalFilterDeploymentPlan(file);
+ }
+
+ public static void marshalPlugin(JAXBElement jaxbElement, OutputStream outputStream) throws Exception {
+ //currently only JAXB21Utils provide this method,so invoke it directly
+ providers.get("2.1").marshalPlugin(jaxbElement, outputStream);
+ }
+
+ public static JAXBElement unmarshalPlugin(InputStream inputStream) {
+ //currently only JAXB21Utils provide this method,so invoke it directly
+ return providers.get("2.1").unmarshalPlugin(inputStream);
+ }
+
+ 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() );
+ }
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/JAXBUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/MarshallerListener.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/MarshallerListener.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/MarshallerListener.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/MarshallerListener.java Thu Apr 29 00:45:13 2010
@@ -0,0 +1,86 @@
+/*
+ * 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.v30.core.jaxb;
+
+import javax.xml.bind.Marshaller;
+
+import org.apache.geronimo.jee.naming.GbeanLocator;
+import org.apache.geronimo.jee.naming.Pattern;
+import org.apache.geronimo.jee.naming.PersistenceContextRef;
+import org.apache.geronimo.jee.naming.ResourceLocator;
+import org.apache.geronimo.jee.openejb.EjbRelationshipRole;
+import org.apache.geronimo.jee.openejb.OpenejbJar;
+import org.apache.geronimo.jee.openejb.Relationships;
+import org.apache.geronimo.jee.security.Security;
+import org.apache.geronimo.jee.web.WebApp;
+
+public class MarshallerListener extends Marshaller.Listener{
+
+ @Override
+ public void beforeMarshal(Object source) {
+ if (source instanceof Security) {
+ Security security = (Security)source;
+ if (security.getRoleMappings() != null && security.getRoleMappings().getRole().size() == 0) {
+ security.setRoleMappings(null);
+ }
+ } else if (source instanceof WebApp) {
+ WebApp webapp = (WebApp)source;
+ GbeanLocator gbeanlocator = webapp.getWebContainer();
+ if (gbeanlocator != null && isEmpty(gbeanlocator.getGbeanLink()) && isEmpty(gbeanlocator.getPattern())) {
+ webapp.setWebContainer(null);
+ }
+ } else if (source instanceof OpenejbJar) {
+ OpenejbJar openejb = (OpenejbJar)source;
+ ResourceLocator locator = openejb.getCmpConnectionFactory();
+ if (locator != null && isEmpty(locator.getResourceLink()) && isEmpty(locator.getUrl()) && isEmpty(locator.getPattern())) {
+ openejb.setCmpConnectionFactory(null);
+ }
+ Relationships relationships = openejb.getRelationships();
+ if (relationships != null && relationships.getEjbRelation().size() == 0) {
+ openejb.setRelationships(null);
+ }
+ } else if (source instanceof PersistenceContextRef) {
+ PersistenceContextRef contextRef = (PersistenceContextRef)source;
+ if (contextRef.getPattern() != null && isEmpty(contextRef.getPattern())) {
+ contextRef.setPattern(null);
+ }
+ } else if (source instanceof EjbRelationshipRole) {
+ EjbRelationshipRole role = (EjbRelationshipRole)source;
+ if (role.getRoleMapping() != null && role.getRoleMapping().getCmrFieldMapping().size() == 0) {
+ role.setRoleMapping(null);
+ }
+ }
+ }
+
+ private boolean isEmpty(Pattern 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(""));
+ }
+
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/MarshallerListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/MarshallerListener.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/MarshallerListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespaceFilter.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespaceFilter.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespaceFilter.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespaceFilter.java Thu Apr 29 00:45:13 2010
@@ -0,0 +1,150 @@
+/**
+ * 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.v30.core.jaxb;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.geronimo.st.v30.core.internal.Trace;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+/**
+ * <strong>NamespaceFilter</strong> is used to filter out older versions (e.g.,
+ * v1.1) of Geronimo namespaces and replace them with the more current versions
+ * (e.g., v2.1)<p>
+ *
+ * If this class changes, then the test version in org.apache.geronimo.jee.common
+ * need to be updated to be kept in sync
+ *
+ * @version $Rev$ $Date$
+ */
+public class NamespaceFilter extends XMLFilterImpl {
+
+ private static Map<String, String> namespace = new HashMap<String, String>();
+
+ static {
+ //
+ // Convert old deployment namespaces
+ //
+ namespace.put("http://geronimo.apache.org/xml/ns/deployment",
+ "http://geronimo.apache.org/xml/ns/deployment-1.2");
+ namespace.put("http://geronimo.apache.org/xml/ns/deployment-1.0",
+ "http://geronimo.apache.org/xml/ns/deployment-1.2");
+ namespace.put("http://geronimo.apache.org/xml/ns/deployment-1.1",
+ "http://geronimo.apache.org/xml/ns/deployment-1.2");
+
+ //
+ // Convert old application namespaces
+ //
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/application",
+ "http://geronimo.apache.org/xml/ns/j2ee/application-2.0");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/application-1.1",
+ "http://geronimo.apache.org/xml/ns/j2ee/application-2.0");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/application-1.2",
+ "http://geronimo.apache.org/xml/ns/j2ee/application-2.0");
+
+ //
+ // Convert old application-client namespaces
+ //
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/application-client",
+ "http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/application-client-1.2",
+ "http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/application-client-1.1",
+ "http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0");
+
+ //
+ // Convert old connector namespaces
+ //
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/connector",
+ "http://geronimo.apache.org/xml/ns/j2ee/connector-1.2");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/connector-1.0",
+ "http://geronimo.apache.org/xml/ns/j2ee/connector-1.2");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/connector-1.1",
+ "http://geronimo.apache.org/xml/ns/j2ee/connector-1.2");
+
+ //
+ // Convert old web namespaces
+ //
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/web",
+ "http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/web-1.0",
+ "http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/web-1.1",
+ "http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/web-1.2",
+ "http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1");
+ namespace.put("http://geronimo.apache.org/xml/ns/j2ee/web-2.0",
+ "http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1");
+
+ //
+ // Convert old naming namespaces
+ //
+ namespace.put("http://geronimo.apache.org/xml/ns/naming",
+ "http://geronimo.apache.org/xml/ns/naming-1.2");
+ namespace.put("http://geronimo.apache.org/xml/ns/naming-1.0",
+ "http://geronimo.apache.org/xml/ns/naming-1.2");
+ namespace.put("http://geronimo.apache.org/xml/ns/naming-1.1",
+ "http://geronimo.apache.org/xml/ns/naming-1.2");
+
+ //
+ // Convert old security namespaces
+ //
+ namespace.put("http://geronimo.apache.org/xml/ns/security",
+ "http://geronimo.apache.org/xml/ns/security-2.0");
+ namespace.put("http://geronimo.apache.org/xml/ns/security-1.1",
+ "http://geronimo.apache.org/xml/ns/security-2.0");
+ namespace.put("http://geronimo.apache.org/xml/ns/security-1.2",
+ "http://geronimo.apache.org/xml/ns/security-2.0");
+
+ //
+ // Convert old openejb-jar namespaces
+ //
+ namespace.put("http://www.openejb.org/xml/ns/openejb-jar",
+ "http://openejb.apache.org/xml/ns/openejb-jar-2.2");
+ namespace.put("http://www.openejb.org/xml/ns/openejb-jar-2.1",
+ "http://openejb.apache.org/xml/ns/openejb-jar-2.2");
+ namespace.put("http://www.openejb.org/xml/ns/openejb-jar-2.2",
+ "http://openejb.apache.org/xml/ns/openejb-jar-2.2");
+ namespace.put("http://www.openejb.org/xml/ns/openejb-jar-2.3",
+ "http://openejb.apache.org/xml/ns/openejb-jar-2.2");
+ namespace.put("http://www.openejb.org/xml/ns/pkgen",
+ "http://openejb.apache.org/xml/ns/pkgen-2.1");
+ namespace.put("http://www.openejb.org/xml/ns/pkgen-2.0",
+ "http://openejb.apache.org/xml/ns/pkgen-2.1");
+ }
+
+ public NamespaceFilter(XMLReader xmlReader) {
+ super(xmlReader);
+ Trace.tracePoint("Constructor", "NamespaceFilter", xmlReader);
+ }
+
+ public void startElement(String uri, String localName, String qname, Attributes atts) throws SAXException {
+ Trace.tracePoint("Entry", "NamespaceFilter.startElement", uri, localName, qname, atts);
+
+ if (namespace.containsKey( uri )) {
+ uri = namespace.get( uri );
+ }
+
+ Trace.tracePoint("Exit ", "NamespaceFilter.startElement", uri, localName, qname, atts);
+ super.startElement(uri, localName, qname, atts);
+ }
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespaceFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespaceFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespaceFilter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespacePrefix.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespacePrefix.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespacePrefix.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespacePrefix.java Thu Apr 29 00:45:13 2010
@@ -0,0 +1,107 @@
+/**
+ * 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.v30.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;
+
+import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NamespacePrefix extends NamespacePrefixMapper{
+
+ private static Map<String, String> prefixMap = new HashMap<String, String>();
+
+ static {
+ prefixMap.put("http://geronimo.apache.org/xml/ns/deployment-1.2", "dep");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/application-2.0", "app");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0", "client");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/connector-1.2", "conn");
+ prefixMap.put("http://openejb.apache.org/xml/ns/openejb-jar-2.2", "ejb");
+ prefixMap.put("http://java.sun.com/xml/ns/persistence", "pers");
+ prefixMap.put("http://openejb.apache.org/xml/ns/pkgen-2.1", "pkgen");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/naming-1.2", "name");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/security-2.0", "sec");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1", "web");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/loginconfig-2.0", "log");
+ }
+
+ 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;
+ }
+
+ @Override
+ public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
+
+ if (prefixMap.containsKey(namespaceUri))
+ return prefixMap.get(namespaceUri);
+
+ return suggestion;
+ }
+
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespacePrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespacePrefix.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/jaxb/NamespacePrefix.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/operations/AbstractGeronimoJ2EEComponentOperation.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/operations/AbstractGeronimoJ2EEComponentOperation.java?rev=939145&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/operations/AbstractGeronimoJ2EEComponentOperation.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/operations/AbstractGeronimoJ2EEComponentOperation.java Thu Apr 29 00:45:13 2010
@@ -0,0 +1,92 @@
+/*
+ * 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.v30.core.operations;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jst.server.core.FacetUtil;
+import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
+import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractGeronimoJ2EEComponentOperation extends AbstractDataModelOperation {
+
+ public AbstractGeronimoJ2EEComponentOperation() {
+ super();
+ }
+
+ /**
+ * @param model
+ */
+ public AbstractGeronimoJ2EEComponentOperation(IDataModel model) {
+ super(model);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.core.runtime.IAdaptable)
+ */
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.core.runtime.IAdaptable)
+ */
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ return null;
+ }
+
+ public boolean isGeronimoRuntimeTarget() {
+ org.eclipse.wst.server.core.IRuntime runtime = getRuntime();
+ if (runtime != null) {
+ return runtime.getRuntimeType().getId().startsWith("org.apache.geronimo");
+ }
+ return false;
+ }
+
+ public org.eclipse.wst.server.core.IRuntime getRuntime() {
+ IRuntime runtime = (IRuntime) model.getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME);
+ if (runtime != null) {
+ return FacetUtil.getRuntime(runtime);
+ }
+ return null;
+ }
+
+ public IProject getProject() {
+ String projectName = model.getProperty(IFacetDataModelProperties.FACET_PROJECT_NAME).toString();
+ if (projectName != null) {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ }
+ return null;
+ }
+
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/operations/AbstractGeronimoJ2EEComponentOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/operations/AbstractGeronimoJ2EEComponentOperation.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/operations/AbstractGeronimoJ2EEComponentOperation.java
------------------------------------------------------------------------------
svn:mime-type = text/plain