You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by pm...@apache.org on 2007/07/05 19:21:49 UTC
svn commit: r553566 - in /geronimo/sandbox/j2g:
plugins/org.apache.geronimo.j2g.common/src/org/apache/geronimo/j2g/common/
plugins/org.apache.geronimo.j2g.descriptors/
plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/...
Author: pmcmahan
Date: Thu Jul 5 10:21:48 2007
New Revision: 553566
URL: http://svn.apache.org/viewvc?view=rev&rev=553566
Log:
GERONIMO-3299 EJB annotation support for J2G. Patch submitted by Viet Nguyen
Added:
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationConverter.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationInstance.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java
geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb.annotation/
geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb.annotation/annotation_differences.properties
Modified:
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.common/src/org/apache/geronimo/j2g/common/XMLMigrationTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/plugin.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml
Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.common/src/org/apache/geronimo/j2g/common/XMLMigrationTool.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.common/src/org/apache/geronimo/j2g/common/XMLMigrationTool.java?view=diff&rev=553566&r1=553565&r2=553566
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.common/src/org/apache/geronimo/j2g/common/XMLMigrationTool.java (original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.common/src/org/apache/geronimo/j2g/common/XMLMigrationTool.java Thu Jul 5 10:21:48 2007
@@ -34,145 +34,150 @@
* Base class for descriptors and resources migration tool.
*/
public abstract class XMLMigrationTool extends Tool {
-
- /** XML suffix */
- public final static String XML_SUFFIX = ".xml";
-
- /** .xml files filter */
- private final FileFilter XML_FILTER = new XMLFilter();
-
- /**
- * @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
- */
- public Object run(Object a) throws Exception {
- String[] args = (String[]) a;
-
- IFileMigration[] plugs = loadPlugins();
- if(plugs.length == 0) {
- getOutput().warn("No plugins were found - skipping migration");
- return new Integer(0);
- }
-
- if(args.length == 0) {
- usage();
- return new Integer(0);
- }
-
- // Restore backed up files
- List files = new ArrayList();
- RollbackManager rollbackManager = new RollbackManager(XML_FILTER);
- try {
- for (int i = 0; i < args.length; ++i) {
- File file = new File(args[i]);
- if(file.exists()) {
- files.add(file);
- rollbackManager.restore(file);
- } else {
- getOutput().error("Given file or directory (" + args[i] + ") does not exist, skipping!");
- }
- }
- } catch(FatalToolException ex) {
- getOutput().fatal(ex.getMessage());
- return new Integer(1);
- }
-
- // Migrate descriptors
- Iterator it = files.iterator();
- while(it.hasNext()) {
- File file = (File)it.next();
- migrate(plugs, file);
- }
- return new Integer(0);
- }
-
- /**
- * Print tool usage text.
- */
- protected void usage() {
- getOutput().fatal("Usage: " + getToolName() + " file_or_dir_name ...");
- }
-
-
- /**
- * Migrate given file or directory.
- *
- * @param plugs available migration plug-ins
- * @param file file or directory to migrate
- */
- protected void migrate(IFileMigration[] plugs, File file) {
- if (file.isDirectory()) {
- File[] children = file.listFiles(XML_FILTER);
- for (int i = 0; i < children.length; ++i) {
- migrate(plugs, children[i]);
- }
- } else {
- for (int i = 0; i < plugs.length; ++i) {
- if(plugs[i].migrate(file)) {
- break;
- }
- }
- }
- }
-
- /**
- * Load migration plug-ins from the extension registry
- * @return
- */
- protected IFileMigration[] loadPlugins() {
- List plugins = new ArrayList();
-
- IExtensionPoint point = Platform.getExtensionRegistry()
- .getExtensionPoint(getExtensionPointId());
- IExtension[] exts = point.getExtensions();
- for (int i = 0; i < exts.length; ++i) {
- IConfigurationElement[] els = exts[i].getConfigurationElements();
- for (int j = 0; j < els.length; ++j) {
- try {
- plugins.add(els[j].createExecutableExtension(ToolConstants.CLASS_PROPERTY));
- } catch (CoreException ex) {
- ILog log = Platform.getLog(Platform.getBundle(getPluginId()));
- log
- .log(new Status(
- Status.WARNING,
- getPluginId(),
- Status.OK,
- "Failed to instantiate migration plug-in.",
- ex));
- }
- }
- }
- return (IFileMigration[]) plugins.toArray(new IFileMigration[plugins
- .size()]);
- }
-
- /**
- * Get id of the extension point with the migration plug-ins.
- *
- * @return id of the extension point with the migration plug-ins.
- */
- protected abstract String getExtensionPointId();
-
- /**
- * Get id of the tool plug-in.
- * @return id of the tool plug-in.
- */
- protected abstract String getPluginId();
-
- /**
- * Name of the tool to show in the usage text.
- * @return name of the tool to show in the usage text.
- */
- protected abstract String getToolName();
-
- /**
- * Filter for .xml descriptors.
- */
- protected static class XMLFilter implements FileFilter {
- /**
- * @see java.io.FileFilter#accept(java.io.File)
- */
- public boolean accept(File file) {
- return file.isDirectory() || file.getName().endsWith(XML_SUFFIX);
- }
- }
+
+ /** XML suffix */
+ public final static String XML_SUFFIX = ".xml";
+
+ /** JAVA suffix */
+ public final static String JAVA_SUFFIX = ".java";
+
+ /** .xml files filter */
+ private final FileFilter XML_FILTER = new XMLFilter();
+
+ /**
+ * @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
+ */
+ public Object run(Object a) throws Exception {
+ String[] args = (String[]) a;
+
+ IFileMigration[] plugs = loadPlugins();
+ if (plugs.length == 0) {
+ getOutput().warn("No plugins were found - skipping migration");
+ return new Integer(0);
+ }
+
+ if (args.length == 0) {
+ usage();
+ return new Integer(0);
+ }
+
+ // Restore backed up files
+ List files = new ArrayList();
+ RollbackManager rollbackManager = new RollbackManager(XML_FILTER);
+ try {
+ for (int i = 0; i < args.length; ++i) {
+ File file = new File(args[i]);
+ if (file.exists()) {
+ files.add(file);
+ rollbackManager.restore(file);
+ } else {
+ getOutput().error(
+ "Given file or directory (" + args[i]
+ + ") does not exist, skipping!");
+ }
+ }
+ } catch (FatalToolException ex) {
+ getOutput().fatal(ex.getMessage());
+ return new Integer(1);
+ }
+
+ // Migrate descriptors
+ Iterator it = files.iterator();
+ while (it.hasNext()) {
+ File file = (File) it.next();
+ migrate(plugs, file);
+ }
+ return new Integer(0);
+ }
+
+ /**
+ * Print tool usage text.
+ */
+ protected void usage() {
+ getOutput().fatal("Usage: " + getToolName() + " file_or_dir_name ...");
+ }
+
+ /**
+ * Migrate given file or directory.
+ *
+ * @param plugs
+ * available migration plug-ins
+ * @param file
+ * file or directory to migrate
+ */
+ protected void migrate(IFileMigration[] plugs, File file) {
+ if (file.isDirectory()) {
+ File[] children = file.listFiles(XML_FILTER);
+ for (int i = 0; i < children.length; ++i) {
+ migrate(plugs, children[i]);
+ }
+ } else {
+ for (int i = 0; i < plugs.length; ++i) {
+ if (plugs[i].migrate(file)) {
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Load migration plug-ins from the extension registry
+ *
+ * @return
+ */
+ protected IFileMigration[] loadPlugins() {
+ List plugins = new ArrayList();
+
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(getExtensionPointId());
+ IExtension[] exts = point.getExtensions();
+ for (int i = 0; i < exts.length; ++i) {
+ IConfigurationElement[] els = exts[i].getConfigurationElements();
+ for (int j = 0; j < els.length; ++j) {
+ try {
+ plugins
+ .add(els[j]
+ .createExecutableExtension(ToolConstants.CLASS_PROPERTY));
+ } catch (CoreException ex) {
+ ILog log = Platform.getLog(Platform.getBundle(getPluginId()));
+ log.log(new Status(Status.WARNING, getPluginId(), Status.OK,
+ "Failed to instantiate migration plug-in.", ex));
+ }
+ }
+ }
+ return (IFileMigration[]) plugins.toArray(new IFileMigration[plugins.size()]);
+ }
+
+ /**
+ * Get id of the extension point with the migration plug-ins.
+ *
+ * @return id of the extension point with the migration plug-ins.
+ */
+ protected abstract String getExtensionPointId();
+
+ /**
+ * Get id of the tool plug-in.
+ *
+ * @return id of the tool plug-in.
+ */
+ protected abstract String getPluginId();
+
+ /**
+ * Name of the tool to show in the usage text.
+ *
+ * @return name of the tool to show in the usage text.
+ */
+ protected abstract String getToolName();
+
+ /**
+ * Filter for .xml descriptors.
+ */
+ protected static class XMLFilter implements FileFilter {
+/**
+ * @see java.io.FileFilter#accept(java.io.File)
+ */
+ public boolean accept(File file) {
+ return file.isDirectory() || file.getName().endsWith(XML_SUFFIX)
+ || file.getName().endsWith(JAVA_SUFFIX);
+ }
+ }
}
Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/plugin.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/plugin.xml?view=diff&rev=553566&r1=553565&r2=553566
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/plugin.xml (original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/plugin.xml Thu Jul 5 10:21:48 2007
@@ -50,5 +50,10 @@
class="org.apache.geronimo.j2g.descriptors.web.WebDescriptorTool">
</migration>
</extension>
-
+ <extension
+ point="org.apache.geronimo.j2g.descriptors.migrations">
+ <migration
+ class="org.apache.geronimo.j2g.descriptors.ejb.annotation.AnnotationTool">
+ </migration>
+ </extension>
</plugin>
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationConverter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationConverter.java?view=auto&rev=553566
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationConverter.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationConverter.java Thu Jul 5 10:21:48 2007
@@ -0,0 +1,210 @@
+/**
+ * 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.j2g.descriptors.ejb.annotation;
+
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.j2g.common.ConsoleOutput;
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.Tool;
+
+//
+// Provides the functionality to convert a JBoss-supported annotation
+// to a Geronimo-supported annotation.
+//
+public class AnnotationConverter {
+ // key - annotation keyword
+ // value - mappings from JBoss-supported attributes associated with the keyword
+ // to Geronimo-supported attributes associated with the keyword (may be different)
+ private HashMap<String, HashMap<String, String>> j2gAnnotationDifferences;
+ // location of the properties file used to extract the differences
+ private final String PROP_ANNOTATION_FILE = "../properties/org.apache.geronimo.j2g.descriptors.ejb.annotation/annotation_differences.properties";
+
+ private final IOutput out;
+
+ private Log log = LogFactory.getLog(AnnotationConverter.class);
+
+ public AnnotationConverter() {
+ Tool currentTool = Tool.getCurrent();
+ if (currentTool != null) {
+ out = currentTool.getOutput();
+ } else {
+ out = new ConsoleOutput();
+ }
+ // populate the hashmap with the annotation info supported by
+ // JBoss and Geronimo.
+ j2gAnnotationDifferences = new HashMap<String, HashMap<String, String>>();
+ populateJ2GAnnotations();
+ }
+
+ // ArrayList<String> getAnnotations(String fileStr)
+ //
+ // Takes in a file as a string and returns all of the annotations
+ // present in the file.
+ //
+ // When there are annotations within annotations, the outter annotation
+ // will appear in the list before the inner annotations.
+ public ArrayList<String> getAnnotations(String fileStr) {
+ // list of annotations found from fileStr
+ ArrayList<String> listOfAnnotations = new ArrayList<String>();
+ // true when the part we are examining is a string defined in double quotes
+ boolean isStringMode = false;
+ // stores the last character that was examined
+ char lastChar = ' ';
+ // process the entire filestring and parse annotations
+ for(int i = 0; i < fileStr.length(); i++) {
+ char currChar = fileStr.charAt(i);
+ // determine if we are in stringMode
+ if(isStringMode) {
+ // ignore all occurrences of any letter except for an ending quote
+ if(currChar == '"' && lastChar != '\\') {
+ isStringMode = false;
+ }
+ } else { // not in String mode
+ // beginning of an annotation
+ if(currChar == '@') {
+ // find a matching annotation from the list
+ Set annotationSet = j2gAnnotationDifferences.keySet();
+ boolean notFound = true;
+ String currAnnotation = null;
+ for(Iterator it = annotationSet.iterator(); it.hasNext() && notFound; ) {
+ String annotation = (String)it.next();
+ // check for a match
+ // ignore annotations without attributes
+ if(fileStr.substring(i+1, i+1+annotation.length()).equals(annotation) &&
+ isNextChar(fileStr, i+annotation.length()+1, '(')) {
+ // get the position of the closing parentheses
+ int toPos = getClosingParenthesesPos(fileStr, fileStr.indexOf('(', i));
+ // grab everything from i --> toPos (inclusive) as our new annotation
+ currAnnotation = fileStr.substring(i, toPos+1);
+ // set found flag
+ notFound = false;
+ }
+ }
+ // add this newly found annotation to the list
+ if( !notFound ) {
+ listOfAnnotations.add(currAnnotation);
+ }
+ } else if(currChar == '"') {
+ isStringMode = true;
+ }
+ }
+ // set up for next iteration
+ lastChar = currChar;
+ }
+ return listOfAnnotations;
+ }
+
+ // Returns a boolean value specifying whether or not the next non-white
+ // space character (starting from 'start') is the same as 'target'
+ private boolean isNextChar(String fileStr, int start, char target) {
+ for(int i = start; i < fileStr.length(); i++) {
+ if(fileStr.charAt(i) != ' ') {
+ return (fileStr.charAt(i) == target);
+ }
+ }
+ return false;
+ }
+
+ // Returns the position in the 'fileStr' that has the matching closing parenthesis
+ // given the position of the opening parenthesis
+ private int getClosingParenthesesPos(String fileStr, int start) {
+ int unClosedParentheses = 1;
+ for(int i = start+1; i < fileStr.length(); i++) {
+ if(fileStr.charAt(i) == '(') {
+ unClosedParentheses++;
+ } else if(fileStr.charAt(i) == ')') {
+ unClosedParentheses--;
+ }
+ // stop when we found the match
+ if(unClosedParentheses == 0) {
+ return i;
+ }
+ }
+ // not even syntactically correct
+ return -1;
+ }
+
+ // String j2gAnnotation(String jbossAnnotation)
+ //
+ // Takes a JBoss annotation and returns the Geronimo representation of it
+ public String j2gAnnotation(String jbossStr) {
+ AnnotationInstance annotation = new AnnotationInstance(jbossStr);
+ ArrayList<String> attrKeys = annotation.getAttributeKeys();
+ ArrayList<String> attrVals = annotation.getAttributeValues();
+ // store the differences between jboss and geronimo for this annotation
+ HashMap<String, String> mappings = j2gAnnotationDifferences.get(annotation.getKeyword());
+ // list of attribute keys from the annotation
+ ArrayList<String> attributeKeys = annotation.getAttributeKeys();
+ // for each attribute key, replace any difference with the conversion
+ for(int i = 0; i < attributeKeys.size(); i++) {
+ String from = attributeKeys.get(i);
+ String to = mappings.get(from);
+ // replace this attribute if there is a difference between jboss and geronimo
+ if(from != null) {
+ if(to == null) {
+ log.error("There is not an attribute mapping for '" + from + "'");
+ } else {
+ annotation.replaceAttributeKey(from, to);
+ }
+ }
+ }
+ return annotation.toString();
+ }
+
+ private void populateJ2GAnnotations() {
+ // populate the hashmap with info from the properties file
+ Properties mappingProps = new Properties();
+ try {
+ mappingProps.load(new FileInputStream( PROP_ANNOTATION_FILE ));
+ // fetch all keys from the properties file
+ Enumeration keys = mappingProps.propertyNames();
+ // for each key (which is an annotation), store the differences into the hashmap
+ while(keys.hasMoreElements()) {
+ // initialize hashmap for each annotation with the differences in attributes
+ HashMap<String, String> diffs = new HashMap<String, String>();
+ // key is an annotation
+ String key = (String)keys.nextElement();
+ // value is the list of different attributes
+ String value = mappingProps.getProperty(key);
+ // break by attribute
+ String[] attributes = value.split(",");
+ // for each attribute, we are going to store them into the hashmap
+ for(int i = 0; i < attributes.length; i++) {
+ // break attribute into jboss-supported-attr and geronimo-supported-attr
+ String[] attrPair = attributes[i].split("-->");
+ // save this difference
+ diffs.put(attrPair[0], attrPair[1]);
+ }
+ // save all differences as the value to the annotation
+ j2gAnnotationDifferences.put(key, diffs);
+ }
+ } catch(Exception e) {
+ log.error("Cannot find properties file: " + PROP_ANNOTATION_FILE);
+ System.out.println("Cannot find properties file: " + PROP_ANNOTATION_FILE);
+ }
+ }
+}
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationInstance.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationInstance.java?view=auto&rev=553566
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationInstance.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationInstance.java Thu Jul 5 10:21:48 2007
@@ -0,0 +1,157 @@
+/**
+ * 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.j2g.descriptors.ejb.annotation;
+
+import java.util.ArrayList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class AnnotationInstance {
+
+ private Log log = LogFactory.getLog(AnnotationInstance.class);
+ private String keyword;
+ private ArrayList<String> attributeKeys = new ArrayList<String>();
+ private ArrayList<String> attributeValues = new ArrayList<String>();
+
+
+ public AnnotationInstance(String fullAnnotation) {
+ // replace all whitespace characters that are outside of a string with a no-space
+ fullAnnotation = removeWhiteSpace(fullAnnotation);
+ // parse the annotation into keyword, attributeKeys, and attributeValues and store it
+ keyword = fullAnnotation.substring(fullAnnotation.indexOf("@")+1, fullAnnotation.indexOf("("));
+ String attributeString = fullAnnotation.substring(fullAnnotation.indexOf("(")+1, fullAnnotation.length()-1).trim();
+ // break into individual attributes
+ boolean foundKey = false;
+ String key = "", value = "";
+ // a turing machine that parses the highest level by using
+ for(int i = 0 ; i < attributeString.length(); i++) {
+ if(foundKey == false && attributeString.charAt(i) != ' ' && attributeString.charAt(i) != ',') {
+ int equalPosition = attributeString.indexOf('=', i);
+ key = attributeString.substring(i, equalPosition).trim();
+ foundKey = true;
+ // jump over key
+ i += key.length()-1;
+ } else if(foundKey) {
+ int closingPosition = -1;
+ if(attributeString.charAt(i) == '{') {
+ closingPosition = getMatchingPosition(attributeString, i, '{', '}');
+ } else if(attributeString.charAt(i) == '"') {
+ closingPosition = getMatchingPosition(attributeString, i, '"', '"');
+ } else {
+ continue;
+ }
+ // the value will include " or { in the front and back
+ value = attributeString.substring(i, closingPosition+1).trim();
+ foundKey = false;
+ // add key and attribute to the lists
+ attributeKeys.add(key);
+ attributeValues.add(value);
+ // jump over value
+ i += value.length()-1;
+ }
+ }
+ }
+
+ public AnnotationInstance(String key, ArrayList<String> attrKeys, ArrayList<String> attrValues) {
+ keyword = key;
+ attributeKeys = attrKeys;
+ attributeValues = attrValues;
+ }
+
+ private String removeWhiteSpace(String s) {
+ String retval = "";
+ // for each white space character
+ for(int i = 0; i < s.length(); i++) {
+ // everything but whitespaces
+ if(s.charAt(i) != ' ') {
+ retval += s.charAt(i);
+ // the next part of this annotation will be part of a hard coded string
+ if(s.charAt(i) == '"') {
+ // skip this chunk
+ String stringChunk = s.substring(i+1, getMatchingPosition(s, i, '"', '"') + 1);
+ retval += stringChunk;
+ i = getMatchingPosition(s, i, '"', '"');
+ }
+ }
+ }
+ return retval;
+ }
+
+ private int getMatchingPosition(String str, int start, char open, char close) {
+ int unclosed = 1;
+ for(int i = start+1; i < str.length(); i++) {
+ if(close == str.charAt(i)) {
+ unclosed--;
+ } else if(open == str.charAt(i)) {
+ unclosed++;
+ }
+ // found matching
+ if(unclosed == 0) {
+ return i;
+ }
+ }
+ // not syntactically correct
+ return -1;
+ }
+
+ public String getKeyword() {
+ return keyword;
+ }
+
+ public ArrayList<String> getAttributeKeys() {
+ return attributeKeys;
+ }
+
+ public ArrayList<String> getAttributeValues() {
+ return attributeValues;
+ }
+
+ public void replaceAttributeKey(String from, String to) {
+ // for each attributeKey that needs to be replaced, replace it
+ for(int i = 0; i < attributeKeys.size(); i++) {
+ if(from.equals(attributeKeys.get(i))) {
+ attributeKeys.set(i, to); // replacing
+ }
+ }
+ }
+
+ public String toString() {
+ // preparing the keyword
+ String key = "@" + keyword;
+ // preparing the attributes
+ String attributes = "";
+ for(int i = 0; i < attributeKeys.size(); i++) {
+ attributes += attributeKeys.get(i) + "=";
+ attributes += attributeValues.get(i);
+ // add a comma after each attribute, except for the last attribute
+ if(i != attributeKeys.size()-1) {
+ attributes += ",";
+ }
+ }
+ // build and return the annotation in string form
+ return (key + "(" + attributes + ")");
+ }
+
+ private String[] trimAll(String[] list) {
+ for(int i = 0; i < list.length; i++) {
+ list[i] = list[i].trim();
+ }
+ return list;
+ }
+}
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java?view=auto&rev=553566
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/annotation/AnnotationTool.java Thu Jul 5 10:21:48 2007
@@ -0,0 +1,130 @@
+/**
+ * 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.j2g.descriptors.ejb.annotation;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.j2g.common.ConsoleOutput;
+import org.apache.geronimo.j2g.common.IFileMigration;
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.XMLMigrationTool;
+import org.apache.geronimo.j2g.common.Tool;
+import org.apache.geronimo.j2g.descriptors.app.ApplicationDescriptorTool;
+
+public class AnnotationTool implements IFileMigration {
+ private IOutput out;
+ private Log logger = LogFactory.getLog(AnnotationTool.class);
+
+ private AnnotationConverter converter;
+
+ public AnnotationTool() {
+ Tool currentTool = Tool.getCurrent();
+ if (currentTool != null) {
+ out = currentTool.getOutput();
+ } else {
+ out = new ConsoleOutput();
+ }
+ converter = new AnnotationConverter();
+ }
+
+ public boolean migrate(File source) {
+ boolean migrated = false;
+ try {
+ if (source.getCanonicalPath().endsWith(XMLMigrationTool.JAVA_SUFFIX)) {
+ out.info("Processing annotations for " + source.getCanonicalPath());
+ // get the contents of the file
+ String fileStr = getFileContents(source);
+ // retrive all annotations
+ ArrayList<String> jbossAnnotations = converter.getAnnotations(fileStr);
+ // The list given by getAnnotations() is ordered such that the
+ // outter annotations will
+ // appear before the inner annotations. Therefore, if we replace
+ // the outside one first,
+ // then the inside one nothing will be damaged.
+ for (int i = 0; i < jbossAnnotations.size(); i++) {
+ String geronimoAnnotation = converter.j2gAnnotation(jbossAnnotations.get(i));
+ out.info("JBoss annotation: " + jbossAnnotations.get(i));
+ out.info("Geronimo annotation: " + geronimoAnnotation);
+ // swap in the geronimo stuff.
+ fileStr = fileStr.replace(jbossAnnotations.get(i), geronimoAnnotation);
+ if (fileStr.contains(geronimoAnnotation)) {
+ out.info("Swapping successful.");
+ }
+ }
+ // write what is in the altered string to source file
+ writeContents(source, fileStr);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return migrated;
+ }
+
+ private void writeContents(File source, String fileStr) {
+ Writer output = null;
+ try {
+ output = new BufferedWriter(new FileWriter(source));
+ output.write(fileStr);
+ } catch (IOException e) {
+ out.error("Cannot write to file");
+ } finally {
+ try {
+ if (output != null)
+ output.close();
+ } catch (IOException e) {
+ out.error("Cannot close file");
+ }
+ }
+ }
+
+ private String getFileContents(File source) {
+ // read and save file in a string buffer
+ StringBuffer fileStrBuffer = new StringBuffer();
+ BufferedReader in = null;
+ try {
+ in = new BufferedReader(new FileReader(source));
+ String line = null;
+ while ((line = in.readLine()) != null) {
+ fileStrBuffer.append(line);
+ fileStrBuffer.append(System.getProperty("line.separator"));
+ }
+ } catch (FileNotFoundException e) {
+ out.error("Cannot find file");
+ } catch (IOException e) {
+ out.error("Cannot read file");
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } catch (IOException e) {
+ out.error("Cannot close file");
+ }
+ }
+ return fileStrBuffer.toString();
+ }
+}
Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml?view=diff&rev=553566&r1=553565&r2=553566
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml (original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml Thu Jul 5 10:21:48 2007
@@ -28,7 +28,7 @@
<log:login-module control-flag="REQUIRED" server-side="true" wrap-principals="false">
<log:login-domain-name>jbossmq</log:login-domain-name>
<log:login-module-class>org.apache.geronimo.security.realm.providers.SQLLoginModule</log:login-module-class>
- <log:option name="dataSourceName">DefaultDS/Test</log:option>
+ <log:option name="dataSourceName">java:/DefaultDS/Test</log:option>
<log:option name="userSelect">SELECT PASSWD FROM JMS_USERS WHERE USERID=?</log:option>
<log:option name="groupSelect">SELECT ROLEID, 'Roles' FROM JMS_ROLES WHERE USERID=?</log:option>
</log:login-module>
Added: geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb.annotation/annotation_differences.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb.annotation/annotation_differences.properties?view=auto&rev=553566
==============================================================================
--- geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb.annotation/annotation_differences.properties (added)
+++ geronimo/sandbox/j2g/src/main/resources/properties/org.apache.geronimo.j2g.descriptors.ejb.annotation/annotation_differences.properties Thu Jul 5 10:21:48 2007
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+###########################################################################
+# Jboss classes and it's analogies.
+###########################################################################
+Resource = mappedName-->name
+EJB = mappedName-->name
+MessageDriven = mappedName-->name
+Stateful = mappedName-->name
+Stateless = mappedName-->name