[jboss-cvs] JBossAS SVN: r106797 - in projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata: jbossra and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Jul 17 18:52:33 EDT 2010
Author: maeste
Date: 2010-07-17 18:52:33 -0400 (Sat, 17 Jul 2010)
New Revision: 106797
Added:
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ParserException.java
Removed:
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra10/Tag.java
Modified:
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/JbossRaParser.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra10/JbossRa10.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/JbossRa20.java
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/RaConfigProperty.java
Log:
JBJCA-385: a bit of refactoring to support enum with tag name in all metadatas classes, convenient for parsers code readability. A first parser implemented...next step is a test suite for that
Copied: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ParserException.java (from rev 106787, projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra10/Tag.java)
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ParserException.java (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/ParserException.java 2010-07-17 22:52:33 UTC (rev 106797)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.common.metadata;
+
+/**
+ *
+ * A ParserException.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class ParserException extends Exception
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Create a new ParserException.
+ *
+ */
+ public ParserException()
+ {
+ super();
+ }
+
+ /**
+ * Create a new ParserException.
+ *
+ * @param message a message
+ * @param cause a cause
+ */
+ public ParserException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ /**
+ * Create a new ParserException.
+ *
+ * @param message a message
+ */
+ public ParserException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Create a new ParserException.
+ *
+ * @param cause a cause
+ */
+ public ParserException(Throwable cause)
+ {
+ super(cause);
+ }
+
+}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/JbossRaParser.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/JbossRaParser.java 2010-07-17 20:34:34 UTC (rev 106796)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/JbossRaParser.java 2010-07-17 22:52:33 UTC (rev 106797)
@@ -22,17 +22,24 @@
package org.jboss.jca.common.metadata.jbossra;
import org.jboss.jca.common.metadata.MetadataParser;
+import org.jboss.jca.common.metadata.ParserException;
+import org.jboss.jca.common.metadata.jbossra.jbossra10.JbossRa10;
+import org.jboss.jca.common.metadata.jbossra.jbossra20.JbossRa20;
+import org.jboss.jca.common.metadata.jbossra.jbossra20.RaConfigProperty;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import static javax.xml.stream.XMLStreamConstants.*;
-import org.jboss.as.model.Domain;
-import org.jboss.as.model.Element;
-
/**
* A JbossRaParser.
*
@@ -42,7 +49,6 @@
public class JbossRaParser implements MetadataParser<JbossRa>
{
-
/**
* Parse the xml file and return the {@link JbossRa} metadata
* @param xmlFile The xml file to parse
@@ -52,35 +58,224 @@
@Override
public JbossRa parse(File xmlFile) throws Exception
{
- XMLInputFactory inputFactory=XMLInputFactory.newInstance();
- InputStream input=new FileInputStream(xmlFile);
- XMLStreamReader reader =inputFactory.createXMLStreamReader(input);
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ InputStream input = new FileInputStream(xmlFile);
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(input);
+ JbossRa jbossRa = null;
- while (reader.hasNext()) {
- switch (reader.nextTag()) {
- case END_ELEMENT: {
- // should mean we're done, so ignore it.
- break;
- }
- case START_ELEMENT: {
- if (Domain.NAMESPACES.contains(reader.getNamespaceURI())) {
- switch (Element.forName(reader.getLocalName())) {
- case SERVER_GROUPS: {
- readServerGroupsElement(reader, domain);
- break;
- }
- default: throw unexpectedElement(reader);
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case END_ELEMENT : {
+ // should mean we're done, so ignore it.
+ break;
+ }
+ case START_ELEMENT : {
+ if (JbossRa10.NAMESPACE.equals(reader.getNamespaceURI()))
+ {
+ switch (Tag.forName(reader.getLocalName()))
+ {
+ case JBOSSRA : {
+ jbossRa = parseJbossRa10(reader);
+ break;
}
- } else {
- // handle foreign root elements
- reader.handleAny(domain);
- }
- break;
- }
- default: throw new IllegalStateException();
+ default :
+ throw new ParserException("Unexpected element:" + reader.getLocalName());
+ }
+
+ }
+ else if (JbossRa20.NAMESPACE.equals(reader.getNamespaceURI()))
+ {
+ switch (Tag.forName(reader.getLocalName()))
+ {
+ case JBOSSRA : {
+ jbossRa = parseJbossRa20(reader, jbossRa);
+ break;
+ }
+ default :
+ throw new ParserException("Unexpected element:" + reader.getLocalName());
+ }
+ }
+ else
+ {
+ throw new ParserException(String.format("Namespace %s is not supported by %s parser",
+ reader.getNamespaceURI(), this.getClass().getName()));
+ }
+
+ break;
+ }
+ default :
+ throw new IllegalStateException();
}
- }
+ }
+ return jbossRa;
}
+ private JbossRa20 parseJbossRa20(XMLStreamReader reader, JbossRa jbossRa) throws XMLStreamException
+ {
+ return null;
+ }
+
+ private JbossRa10 parseJbossRa10(XMLStreamReader reader) throws XMLStreamException, ParserException
+ {
+ List<RaConfigProperty<?>> raConfigProperties = new LinkedList<RaConfigProperty<?>>();
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case END_ELEMENT : {
+ if (Tag.forName(reader.getLocalName()) == Tag.JBOSSRA)
+ {
+ return new JbossRa10(raConfigProperties);
+ }
+ else
+ {
+ if (JbossRa10.Tag.forName(reader.getLocalName()) == JbossRa10.Tag.UNKNOWN)
+ {
+ throw new ParserException("unexpected end tag" + reader.getLocalName());
+ }
+ }
+ break;
+ }
+ case START_ELEMENT : {
+ switch (JbossRa10.Tag.forName(reader.getLocalName()))
+ {
+ case RA_CONFIG_PROPERTY : {
+ raConfigProperties.add(parseConfigProperty(reader));
+ break;
+ }
+ default :
+ throw new ParserException("Unexpected element:" + reader.getLocalName());
+ }
+ break;
+ }
+ }
+ }
+ throw new ParserException("Reached end of xml document unexpectedly");
+ }
+
+ private RaConfigProperty<?> parseConfigProperty(XMLStreamReader reader) throws XMLStreamException, ParserException
+ {
+ String value = null;
+ String type = null;
+ String name = null;
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case END_ELEMENT : {
+ //maeste: to be verified
+ if (JbossRa10.Tag.forName(reader.getLocalName()) == JbossRa10.Tag.RA_CONFIG_PROPERTY
+ || JbossRa20.Tag.forName(reader.getLocalName()) == JbossRa20.Tag.RA_CONFIG_PROPERTY)
+ {
+ return RaConfigProperty.buildRaConfigProperty(name, value, type);
+ }
+ else
+ {
+ if (JbossRa10.Tag.forName(reader.getLocalName()) == JbossRa10.Tag.UNKNOWN
+ && JbossRa20.Tag.forName(reader.getLocalName()) == JbossRa20.Tag.UNKNOWN)
+ {
+ throw new ParserException("unexpected end tag" + reader.getLocalName());
+ }
+ }
+ break;
+ }
+ case START_ELEMENT : {
+ switch (RaConfigProperty.Tag.forName(reader.getLocalName()))
+ {
+ case RA_CONFIG_PROPERTY_NAME : {
+ name = reader.getElementText();
+ break;
+ }
+ case RA_CONFIG_PROPERTY_VALUE : {
+ value = reader.getElementText();
+ break;
+ }
+ case RA_CONFIG_PROPERTY_TYPE : {
+ type = reader.getElementText();
+ break;
+ }
+ default :
+ throw new ParserException("Unexpected element:" + reader.getLocalName());
+ }
+ break;
+ }
+ }
+ }
+ throw new ParserException("Reached end of xml document unexpectedly");
+ }
+
+ /**
+ *
+ * A Tag.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ public enum Tag
+ {
+ /** always first
+ *
+ */
+ UNKNOWN(null),
+
+ /** jboss-ra tag name
+ *
+ */
+ JBOSSRA("jboss-ra");
+
+ private final String name;
+
+ /**
+ *
+ * Create a new Tag.
+ *
+ * @param name a name
+ */
+ Tag(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ private static final Map<String, Tag> MAP;
+
+ static
+ {
+ final Map<String, Tag> map = new HashMap<String, Tag>();
+ for (Tag element : values())
+ {
+ final String name = element.getLocalName();
+ if (name != null)
+ map.put(name, element);
+ }
+ MAP = map;
+ }
+
+ /**
+ *
+ * Static method to get enum instance given localName string
+ *
+ * @param localName a string used as localname (typically tag name as defined in xsd)
+ * @return the enum instance
+ */
+ public static Tag forName(String localName)
+ {
+ final Tag element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+
+ }
+
}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra10/JbossRa10.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra10/JbossRa10.java 2010-07-17 20:34:34 UTC (rev 106796)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra10/JbossRa10.java 2010-07-17 22:52:33 UTC (rev 106797)
@@ -24,7 +24,9 @@
import org.jboss.jca.common.metadata.jbossra.JbossRa;
import org.jboss.jca.common.metadata.jbossra.jbossra20.RaConfigProperty;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
*
@@ -36,6 +38,11 @@
public class JbossRa10 extends JbossRa
{
+ /**
+ * NAMESPACE of xml file for which this metadata is generated
+ */
+ public static final String NAMESPACE = "http://www.jboss.org/schema/ra/1.0";
+
/** The serialVersionUID */
private static final long serialVersionUID = 1L;
@@ -54,4 +61,75 @@
return "JbossRa10 [getRaConfigProperties()=" + getRaConfigProperties() + "]";
}
+ /**
+ *
+ * A Tag.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ public enum Tag
+ {
+ /** always first
+ *
+ */
+ UNKNOWN(null),
+
+ /** ra-config-property tag name
+ *
+ */
+ RA_CONFIG_PROPERTY("ra-config-property");
+
+ private final String name;
+
+ /**
+ *
+ * Create a new Tag.
+ *
+ * @param name a name
+ */
+ Tag(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ private static final Map<String, Tag> MAP;
+
+ static
+ {
+ final Map<String, Tag> map = new HashMap<String, Tag>();
+ for (Tag element : values())
+ {
+ final String name = element.getLocalName();
+ if (name != null)
+ map.put(name, element);
+ }
+ MAP = map;
+ }
+
+ /**
+ *
+ * Static method to get enum instance given localName string
+ *
+ * @param localName a string used as localname (typically tag name as defined in xsd)
+ * @return the enum instance
+ */
+ public static Tag forName(String localName)
+ {
+ final Tag element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+
+ }
+
}
Deleted: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra10/Tag.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra10/Tag.java 2010-07-17 20:34:34 UTC (rev 106796)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra10/Tag.java 2010-07-17 22:52:33 UTC (rev 106797)
@@ -1,69 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jca.common.metadata.jbossra.jbossra10;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-public enum Tag {
-// always first
- UNKNOWN(null),
-
- // domain 1.0 attributes in alpha order
- NAME("name"),
-
-
- ;
-
- private final String name;
-
- Tag(final String name) {
- this.name = name;
- }
-
- /**
- * Get the local name of this element.
- *
- * @return the local name
- */
- public String getLocalName() {
- return name;
- }
-
- private static final Map<String, Tag> MAP;
-
- static {
- final Map<String, Tag> map = new HashMap<String, Tag>();
- for (Tag element : values()) {
- final String name = element.getLocalName();
- if (name != null) map.put(name, element);
- }
- MAP = map;
- }
-
- public static Tag forName(String localName) {
- final Tag element = MAP.get(localName);
- return element == null ? UNKNOWN : element;
- }
-
-}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/JbossRa20.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/JbossRa20.java 2010-07-17 20:34:34 UTC (rev 106796)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/JbossRa20.java 2010-07-17 22:52:33 UTC (rev 106797)
@@ -24,7 +24,9 @@
import org.jboss.jca.common.metadata.jbossra.JbossRa;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author <a href="mailto:stefano.maestri at jboss.org">Stefano Maestri</a>
@@ -33,7 +35,10 @@
{
/**
+ * NAMESPACE of xml file for which this metadata is generated
*/
+ public static final String NAMESPACE = "http://www.jboss.org/schema/ra/1.0";
+
private static final long serialVersionUID = -1494921311038998843L;
private final String bootstrapContext;
@@ -124,4 +129,75 @@
return true;
}
+ /**
+ *
+ * A Tag.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ public enum Tag
+ {
+ /**always first
+ *
+ */
+ UNKNOWN(null),
+
+ /** ra-config-property tag name
+ *
+ */
+ RA_CONFIG_PROPERTY("ra-config-property");
+
+ private final String name;
+
+ /**
+ *
+ * Create a new Tag.
+ *
+ * @param name a name
+ */
+ Tag(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ private static final Map<String, Tag> MAP;
+
+ static
+ {
+ final Map<String, Tag> map = new HashMap<String, Tag>();
+ for (Tag element : values())
+ {
+ final String name = element.getLocalName();
+ if (name != null)
+ map.put(name, element);
+ }
+ MAP = map;
+ }
+
+ /**
+ *
+ * Static method to get enum instance given localName string
+ *
+ * @param localName a string used as localname (typically tag name as defined in xsd)
+ * @return the enum instance
+ */
+ public static Tag forName(String localName)
+ {
+ final Tag element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+
+ }
+
}
Modified: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/RaConfigProperty.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/RaConfigProperty.java 2010-07-17 20:34:34 UTC (rev 106796)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/metadata/jbossra/jbossra20/RaConfigProperty.java 2010-07-17 22:52:33 UTC (rev 106797)
@@ -22,7 +22,11 @@
package org.jboss.jca.common.metadata.jbossra.jbossra20;
import org.jboss.jca.common.metadata.JCAMetadata;
+import org.jboss.jca.common.metadata.jbossra.JbossRaParser.Tag;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author <a href="mailto:stefano.maestri at jboss.org">Stefano Maestri</a>
* @param <T> generic type of this property. See {@link #buildRaConfigProperty(String, String, String)}
@@ -228,4 +232,85 @@
return "RaConfigProperty [name=" + name + ", value=" + value + "]";
}
+ /**
+ *
+ * A Tag.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+ public enum Tag
+ {
+ /** always first
+ *
+ */
+ UNKNOWN(null),
+
+ /** jboss-ra-property-name tag name
+ *
+ */
+ RA_CONFIG_PROPERTY_NAME("ra-config-property-name"),
+
+ /** jboss-ra-property-value tag name
+ *
+ */
+ RA_CONFIG_PROPERTY_VALUE("ra-config-property-value"),
+
+ /** jboss-ra-property-type tag name
+ *
+ */
+ RA_CONFIG_PROPERTY_TYPE("ra-config-property-type");
+
+ private final String name;
+
+ /**
+ *
+ * Create a new Tag.
+ *
+ * @param name a name
+ */
+ Tag(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ private static final Map<String, Tag> MAP;
+
+ static
+ {
+ final Map<String, Tag> map = new HashMap<String, Tag>();
+ for (Tag element : values())
+ {
+ final String name = element.getLocalName();
+ if (name != null)
+ map.put(name, element);
+ }
+ MAP = map;
+ }
+
+ /**
+ *
+ * Static method to get enum instance given localName string
+ *
+ * @param localName a string used as localname (typically tag name as defined in xsd)
+ * @return the enum instance
+ */
+ public static Tag forName(String localName)
+ {
+ final Tag element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+
+ }
+
}
More information about the jboss-cvs-commits
mailing list