Author: rareddy
Date: 2010-02-23 17:22:21 -0500 (Tue, 23 Feb 2010)
New Revision: 1870
Removed:
branches/JCA/runtime/src/main/java/org/teiid/deployers/DefParser.java
Modified:
branches/JCA/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
branches/JCA/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
branches/JCA/client/src/main/resources/vdb-deployer.xsd
branches/JCA/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
branches/JCA/runtime/src/main/java/org/teiid/deployers/DynamicVDBDeployer.java
branches/JCA/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java
Log:
TEIID-998: Replaced the DEF file parser with JAXB complient parser
Modified: branches/JCA/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
===================================================================
---
branches/JCA/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2010-02-23
20:56:05 UTC (rev 1869)
+++
branches/JCA/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2010-02-23
22:22:21 UTC (rev 1870)
@@ -68,6 +68,9 @@
})
@ManagementObject(componentType=@ManagementComponent(type="teiid",subtype="model"))
public class ModelMetaData extends AdminObjectImpl implements Model {
+
+ private static final String SUPPORTS_MULTI_SOURCE_BINDINGS_KEY =
"supports-multi-source-bindings"; //$NON-NLS-1$
+ private static final String VISIBILITY_KEY = "visibility"; //$NON-NLS-1$
private static final long serialVersionUID = 3714234763056162230L;
@@ -77,12 +80,12 @@
@XmlElement(name = "connector-ref")
protected String connectorReference;
- private String modelType = ""; //$NON-NLS-1$
+ @XmlAttribute(name = "type", required = true)
+ private String modelType; //$NON-NLS-1$
+
private String modelURI = ""; //$NON-NLS-1$
- private boolean supportsMultiSourceBindings = false;
private String path;
private String uuid;
- private Visibility visibility;
@ManagementProperty(description="Model Name", readOnly=true)
@ManagementObjectID(type="model")
@@ -123,7 +126,7 @@
@Override
@ManagementProperty(description = "Is Model Visible", readOnly=true)
public boolean isVisible() {
- return visibility == Visibility.PUBLIC;
+ return getVisibility() == Visibility.PUBLIC;
}
@Override
@@ -141,7 +144,8 @@
@Override
@ManagementProperty(description = "Does Model supports multi-source bindings",
readOnly=true)
public boolean isSupportsMultiSourceBindings() {
- return this.supportsMultiSourceBindings;
+ String supports = getPropertyValue(SUPPORTS_MULTI_SOURCE_BINDINGS_KEY);
+ return Boolean.parseBoolean(supports);
}
@Override
@@ -184,7 +188,7 @@
public void setSupportsMultiSourceBindings(boolean supports) {
- this.supportsMultiSourceBindings = supports;
+ addProperty(SUPPORTS_MULTI_SOURCE_BINDINGS_KEY, Boolean.toString(supports));
}
public void setModelType(String modelType) {
@@ -208,10 +212,15 @@
}
public Visibility getVisibility(){
- return this.visibility;
+ String visibility = getPropertyValue(VISIBILITY_KEY);
+ if (visibility != null) {
+ Visibility v = Visibility.valueOf(visibility);
+ return v;
+ }
+ return Visibility.PUBLIC;
}
public void setVisibility(Visibility visibility) {
- this.visibility = visibility;
+ addProperty(VISIBILITY_KEY, visibility.name());
}
}
Modified: branches/JCA/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
--- branches/JCA/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2010-02-23
20:56:05 UTC (rev 1869)
+++ branches/JCA/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2010-02-23
22:22:21 UTC (rev 1870)
@@ -58,6 +58,8 @@
})
@XmlRootElement(name = "vdb")
public class VDBMetaData extends AdminObjectImpl implements VDB {
+ private static final String STATUS_KEY = "status"; //$NON-NLS-1$
+
private static final long serialVersionUID = -4723595252013356436L;
@XmlElement(name = "model", required = true, type = ModelMetaData.class)
@@ -80,7 +82,6 @@
private List<String> errors;
private String fileUrl = null;
- private Status status;
public VDBMetaData() {
// auto add sytem model.
@@ -110,11 +111,15 @@
@Override
@ManagementProperty(description="VDB Status", readOnly=true)
public Status getStatus() {
- return this.status;
+ String status = getPropertyValue(STATUS_KEY);
+ if (status != null) {
+ return VDB.Status.valueOf(status);
+ }
+ return VDB.Status.ACTIVE;
}
public void setStatus(Status s) {
- this.status = s;
+ addProperty(STATUS_KEY, s.name());
}
@Override
Modified: branches/JCA/client/src/main/resources/vdb-deployer.xsd
===================================================================
--- branches/JCA/client/src/main/resources/vdb-deployer.xsd 2010-02-23 20:56:05 UTC (rev
1869)
+++ branches/JCA/client/src/main/resources/vdb-deployer.xsd 2010-02-23 22:22:21 UTC (rev
1870)
@@ -18,6 +18,7 @@
</xs:choice>
</xs:sequence>
<xs:attribute name="name" type="xs:string"
use="required"/>
+ <xs:attribute name="type" type="xs:string"
use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="connector-mapping" type="reference-mapping"
minOccurs="0" maxOccurs="unbounded"/>
Modified: branches/JCA/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
===================================================================
---
branches/JCA/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2010-02-23
20:56:05 UTC (rev 1869)
+++
branches/JCA/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2010-02-23
22:22:21 UTC (rev 1870)
@@ -58,6 +58,7 @@
ModelMetaData modelTwo = new ModelMetaData();
modelTwo.setName("model-two");
modelTwo.setConnectorReference("binding-two-ref");
+ modelTwo.setModelType("virtual");
modelTwo.addProperty("model-prop", "model-value");
vdb.addModel(modelTwo);
@@ -76,7 +77,7 @@
marshell.marshal(vdb, sw);
Unmarshaller un = jc.createUnmarshaller();
- //System.out.println(sw.toString());
+ System.out.println(sw.toString());
vdb = (VDBMetaData)un.unmarshal(new StringReader(sw.toString()));
@@ -92,7 +93,7 @@
modelOne = vdb.getModel("model-one");
assertEquals("model-one", modelOne.getName());
assertTrue(modelOne.getConnectorBindingNames().contains("java:mybinding"));
- assertEquals("", modelOne.getModelType()); // this is not persisted in the
XML
+ assertEquals("physical", modelOne.getModelType());
assertEquals("model-value",
modelOne.getPropertyValue("model-prop"));
@@ -100,7 +101,7 @@
assertEquals("model-two", modelTwo.getName());
assertTrue(modelTwo.getConnectorBindingNames().isEmpty());
assertEquals("binding-two-ref", modelTwo.getConnectorReference());
- assertEquals("", modelTwo.getModelType()); // this is not persisted in the
XML
+ assertEquals("virtual", modelTwo.getModelType()); // this is not persisted in
the XML
assertEquals("model-value",
modelTwo.getPropertyValue("model-prop"));
Deleted: branches/JCA/runtime/src/main/java/org/teiid/deployers/DefParser.java
===================================================================
--- branches/JCA/runtime/src/main/java/org/teiid/deployers/DefParser.java 2010-02-23
20:56:05 UTC (rev 1869)
+++ branches/JCA/runtime/src/main/java/org/teiid/deployers/DefParser.java 2010-02-23
22:22:21 UTC (rev 1870)
@@ -1,154 +0,0 @@
-package org.teiid.deployers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.teiid.adminapi.VDB;
-import org.teiid.adminapi.Visibility;
-import org.teiid.adminapi.impl.ModelMetaData;
-import org.teiid.adminapi.impl.VDBMetaData;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.xml.XMLReaderWriter;
-import com.metamatrix.common.xml.XMLReaderWriterImpl;
-
-public class DefParser {
-
- public static VDBMetaData load(InputStream defStream) throws IOException,
MetaMatrixComponentException {
- VDBMetaData vdb = new VDBMetaData();
- try {
- XMLReaderWriter reader = new XMLReaderWriterImpl();
- Document doc = reader.readDocument(defStream);
- Element root = doc.getRootElement();
-
- // load VDBInfo section
- loadVDBInfoSection(vdb, root);
-
- // add Models section
- loadModelsSection(vdb, root);
-
- } catch (JDOMException e) {
- throw new MetaMatrixComponentException(e);//$NON-NLS-1$
- }
- return vdb;
- }
-
- private static void loadVDBInfoSection(VDBMetaData vdb, Element root) throws
IOException {
-
- Element vdbInfoElement = root.getChild(VDBInfoFragment.ELEMENT);
- if (vdbInfoElement == null) {
- throw new IOException("VDBDefnXMLHelper.Invalid_xml_section");
//$NON-NLS-1$
- }
-
- Properties vdbProps = getElementProperties(vdbInfoElement);
- if (vdbProps == null || vdbProps.isEmpty()) {
- throw new
IOException("VDBDefnXMLHelper.No_properties_defined_to_create_defn");
//$NON-NLS-1$
- }
-
- vdb.setName((String)vdbProps.remove(VDBInfoFragment.NAME));
- String version = (String)vdbProps.remove(VDBInfoFragment.VERSION);
- vdb.setVersion(version!=null?Integer.parseInt(version):1);//$NON-NLS-1$
- vdb.setDescription((String)vdbProps.remove(VDBInfoFragment.DESCRIPTION));
- if (TRUE.equals(vdbProps.remove(VDBInfoFragment.ACTIVE))) {
- vdb.setStatus(VDB.Status.ACTIVE);
- }
- else {
- vdb.setStatus(VDB.Status.INACTIVE);
- }
- vdb.setProperties(vdbProps);
- }
-
- private static void loadModelsSection(VDBMetaData vdb, Element root) {
- Collection<Element> modelsElements = root.getChildren(ModelFragment.ELEMENT);
- for(Element modelElement:modelsElements) {
- vdb.addModel(loadModel(modelElement));
- }
- }
-
- private static ModelMetaData loadModel(Element modelElement) {
- Properties props = getElementProperties(modelElement);
-
- ModelMetaData model = new ModelMetaData();
- model.setName(props.getProperty(ModelFragment.NAME));
- props.remove(ModelFragment.NAME);
-
- String visibility = props.getProperty(ModelFragment.VISIBILITY,
Visibility.PUBLIC.toString());
- props.remove(ModelFragment.VISIBILITY);
- model.setVisibility(Visibility.valueOf(Visibility.class,
visibility.toUpperCase()));
-
-
model.setSupportsMultiSourceBindings(Boolean.parseBoolean(props.getProperty(ModelFragment.MULTI_SOURCE_ENABLED)));
- props.remove(ModelFragment.MULTI_SOURCE_ENABLED);
-
- model.setProperties(props);
-
- Element cbElement =
modelElement.getChild(ModelFragment.CONNECTOR_BINDINGS_ELEMENT);
- if (cbElement != null) {
- Collection<Element> bindingElements =
cbElement.getChildren(ModelFragment.CONNECTOR);
- for(Element bindingElement:bindingElements) {
- String connectorName =
bindingElement.getAttributeValue(ModelFragment.CONNECTOR_ATTRIBUTE_NAME);
- model.addConnectorBinding(connectorName);
- }
- }
- return model;
- }
-
- protected static Properties getElementProperties(Element rootElement) {
- Properties properties = new Properties();
- if(rootElement == null) {
- return properties;
- }
- // obtain any defaults that are defined
- List propertyElements = rootElement.getChildren(PropertyFragment.ELEMENT);
- if (propertyElements != null) {
- Iterator iterator = propertyElements.iterator();
- for (int i = 1; iterator.hasNext(); i++) {
- Element element = (Element)iterator.next();
- String name =
element.getAttributeValue(PropertyFragment.ATTRIBUTE_NAME);
- String value =
element.getAttributeValue(PropertyFragment.ATTRIBUTE_VALUE);
- if (name != null && name.length() > 0) {
- properties.setProperty(name, value);
- }
- }
- }
- return properties;
- }
-
- static final String ROOT_ELEMENT = "VDB"; //$NON-NLS-1$
- private static final String TRUE = "true"; //$NON-NLS-1$
- private static class VDBInfoFragment {
- public static final String ELEMENT = "VDBInfo"; //$NON-NLS-1$
- public static final String NAME = "Name"; //$NON-NLS-1$
- public static final String VERSION = "Version"; //$NON-NLS-1$
-
- // Optional - defaults to VDB Name
- public static final String DESCRIPTION = "Description"; //$NON-NLS-1$
- public static final String ACTIVE = "Active"; //$NON-NLS-1$
- }
-
- private static class PropertyFragment {
- public static final String ELEMENT = "Property"; //$NON-NLS-1$
- public static final String ATTRIBUTE_NAME = "Name"; //$NON-NLS-1$
- public static final String ATTRIBUTE_VALUE = "Value"; //$NON-NLS-1$
- }
-
- private static class ModelFragment {
- public static final String ELEMENT = "Model"; //$NON-NLS-1$
- public static final String NAME = "Name"; //$NON-NLS-1$
-
- // Optional - Default - physical=false, virtual=true
- public static final String VISIBILITY = "Visibility"; //$NON-NLS-1$
- public static final String MULTI_SOURCE_ENABLED = "MultiSourceEnabled";
//$NON-NLS-1$
-
- // Optional - no binding set
- public static final String CONNECTOR_BINDINGS_ELEMENT = "ConnectorBindings";
//$NON-NLS-1$
- public static final String CONNECTOR = "Connector"; //$NON-NLS-1$
- public static final String CONNECTOR_ATTRIBUTE_NAME = "Name"; //$NON-NLS-1$
- }
-}
Modified: branches/JCA/runtime/src/main/java/org/teiid/deployers/DynamicVDBDeployer.java
===================================================================
---
branches/JCA/runtime/src/main/java/org/teiid/deployers/DynamicVDBDeployer.java 2010-02-23
20:56:05 UTC (rev 1869)
+++
branches/JCA/runtime/src/main/java/org/teiid/deployers/DynamicVDBDeployer.java 2010-02-23
22:22:21 UTC (rev 1870)
@@ -25,11 +25,13 @@
import java.io.IOException;
import java.util.ArrayList;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.virtual.VirtualFile;
-import org.teiid.adminapi.Visibility;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.connector.api.ConnectorException;
@@ -39,7 +41,6 @@
import org.teiid.metadata.CompositeMetadataStore;
import com.metamatrix.core.CoreConstants;
-import com.metamatrix.core.vdb.ModelType;
public class DynamicVDBDeployer extends AbstractVFSParsingDeployer<VDBMetaData> {
private VDBRepository vdbRepository;
@@ -53,15 +54,10 @@
@Override
protected VDBMetaData parse(VFSDeploymentUnit unit, VirtualFile file, VDBMetaData root)
throws Exception {
- VDBMetaData def = DefParser.load(file.openStream());
+ JAXBContext jc = JAXBContext.newInstance(new Class<?>[] {VDBMetaData.class});
+ Unmarshaller un = jc.createUnmarshaller();
+ VDBMetaData def = (VDBMetaData)un.unmarshal(file.openStream());
- // Set the additional model properties which are traditionally on the VDB based
Models.
- for(ModelMetaData model:def.getModels()) {
- model.setModelType(ModelType.getString(ModelType.PHYSICAL));
- model.setVisibility(Visibility.PUBLIC);
- model.setSupportsMultiSourceBindings(false);
- }
-
def.setUrl(unit.getRoot().toURL().toExternalForm());
log.debug("VDB "+unit.getRoot().getName()+" has been parsed.");
Modified: branches/JCA/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java
===================================================================
---
branches/JCA/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java 2010-02-23
20:56:05 UTC (rev 1869)
+++
branches/JCA/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java 2010-02-23
22:22:21 UTC (rev 1870)
@@ -27,6 +27,9 @@
import java.util.List;
import java.util.Map;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.logging.Logger;
import org.jboss.virtual.VirtualFile;
@@ -66,7 +69,10 @@
@Override
protected <U> U parse(VFSDeploymentUnit unit, Class<U> expectedType,
VirtualFile file, Object root) throws Exception {
if (expectedType.equals(VDBMetaData.class)) {
- VDBMetaData def = DefParser.load(file.openStream());
+ JAXBContext jc = JAXBContext.newInstance(new Class<?>[] {VDBMetaData.class});
+ Unmarshaller un = jc.createUnmarshaller();
+ VDBMetaData def = (VDBMetaData)un.unmarshal(file.openStream());
+
return expectedType.cast(def);
}
else if (expectedType.equals(ManifestMetaData.class)) {