You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2005/10/21 14:40:08 UTC

svn commit: r327163 - in /webservices/jaxme/branches/MAVEN/projects/pm: src/main/java/org/apache/ws/jaxme/generator/ino/api4j/ src/main/java/org/apache/ws/jaxme/pm/ino/api4j/ xdocs/

Author: jochen
Date: Fri Oct 21 05:39:56 2005
New Revision: 327163

URL: http://svn.apache.org/viewcvs?rev=327163&view=rev
Log:
Added support for the TaminoAPI4J without the resource adapter.
In other words, this is usable in the absence of an EJB container.

Added:
    webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JDbPm.java
    webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JRaPm.java
Modified:
    webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSG.java
    webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSchemaSG.java
    webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/DocumentDefaultHandler.java
    webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/ElementDefaultHandler.java
    webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TJMElement.java
    webservices/jaxme/branches/MAVEN/projects/pm/xdocs/ino.xml

Modified: webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSG.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSG.java?rev=327163&r1=327162&r2=327163&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSG.java (original)
+++ webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSG.java Fri Oct 21 05:39:56 2005
@@ -72,9 +72,9 @@
     private static final JavaQName INO_OBJECT_TYPE = JavaQNameImpl.getInstance(InoObject.class);
     private static final JavaQName JMELEMENT_TYPE = JavaQNameImpl.getInstance(JMElement.class);
 
-    public class RaDetails extends XsObjectImpl {
-        private String collection, jndiReference;
-        RaDetails(XsObject pParent) {
+    public abstract class InoDetails extends XsObjectImpl {
+        private String collection;
+        InoDetails(XsObject pParent) {
             super(pParent);
         }
         public void setCollection(String pCollection) {
@@ -84,6 +84,41 @@
             String p = "taminoapi4j.collection";
             return sgFactory.getGenerator().getProperty(p, collection);
         }
+    }
+
+    public class DbDetails extends InoDetails {
+    	private String url, user, password;
+    	DbDetails(XsObject pParent) {
+    		super(pParent);
+    	}
+        public void setUrl(String pUrl) {
+            url = pUrl;
+        }
+        public String getUrl() {
+            String p = "taminoapi4j.url";
+            return sgFactory.getGenerator().getProperty(p, url);
+        }
+        public void setUser(String pUser) {
+            user = pUser;
+        }
+        public String getUser() {
+            String p = "taminoapi4j.user";
+            return sgFactory.getGenerator().getProperty(p, user);
+        }
+        public void setPassword(String pPassword) {
+            password = pPassword;
+        }
+        public String getPassword() {
+            String p = "taminoapi4j.password";
+            return sgFactory.getGenerator().getProperty(p, password);
+        }
+    }
+
+    public class RaDetails extends InoDetails {
+        private String jndiReference;
+        RaDetails(XsObject pParent) {
+            super(pParent);
+        }
         public void setJndiReference(String pReference) {
             jndiReference = pReference;
         }
@@ -94,19 +129,27 @@
     }
 
     private RaDetails raDetails;
+    private DbDetails dbDetails;
     private SGFactory sgFactory;
 
     public TaminoAPI4JSG(SGFactoryChain o) {
         super(o);
     }
 
-    public void setRaDetails(RaDetails pDetails) {
+    public void setRaDetails(RaDetails pDetails) throws SAXException {
         raDetails = pDetails;
     }
     public RaDetails getRaDetails() {
         return raDetails;
     }
-    
+
+    public void setDbDetails(DbDetails pDetails) {
+        dbDetails = pDetails;
+    }
+    public DbDetails getDbDetails() {
+        return dbDetails;
+    }
+
     public void init(SGFactory pFactory) {
         super.init(pFactory);
         sgFactory = pFactory;
@@ -115,16 +158,32 @@
             JaxMeSchemaReader jaxmeSchemaReader = (JaxMeSchemaReader) schemaReader;
             jaxmeSchemaReader.addXsObjectCreator(new XsObjectCreator(){
                 public XsObject newBean(XsObject pParent, Locator pLocator, XsQName pQName) throws SAXException {
-                    if (pParent instanceof JAXBGlobalBindings) {
+                	if (pParent instanceof JAXBGlobalBindings) {
                         if (TAMINOAPI4J_SCHEMA_URI.equals(pQName.getNamespaceURI())) {
                             if ("raDetails".equals(pQName.getLocalName())) {
                                 if (getRaDetails() != null) {
                                     throw new LocSAXException("An element named " + pQName + " has already been specified.",
                                             				  pLocator);
                                 }
+                                if (getDbDetails() != null) {
+                                    throw new LocSAXException("The elements dbDetails and raDetails are mutually exclusive.",
+                                            				  pLocator);
+                                }
                                 RaDetails details = new RaDetails(pParent);
                                 setRaDetails(details);
                                 return details;
+                            } else if ("dbDetails".equals(pQName.getLocalName())) {
+                            	if (getDbDetails() != null) {
+                            		throw new LocSAXException("An element named " + pQName + " has already been specified.",
+                            				pLocator);
+                            	}
+                            	if (getRaDetails() != null) {
+                                    throw new LocSAXException("The elements dbDetails and raDetails are mutually exclusive.",
+                                            				  pLocator);
+                                }
+                            	DbDetails details = new DbDetails(pParent);
+                            	setDbDetails(details);
+                            	return details;
                             } else {
                                 throw new LocSAXException("Invalid element name: " + pQName, pLocator);
                             }

Modified: webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSchemaSG.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSchemaSG.java?rev=327163&r1=327162&r2=327163&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSchemaSG.java (original)
+++ webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/generator/ino/api4j/TaminoAPI4JSchemaSG.java Fri Oct 21 05:39:56 2005
@@ -16,6 +16,7 @@
 
 package org.apache.ws.jaxme.generator.ino.api4j;
 
+
 import java.util.Iterator;
 import java.util.List;
 
@@ -25,7 +26,8 @@
 import org.apache.ws.jaxme.generator.sg.TypeSG;
 import org.apache.ws.jaxme.generator.sg.impl.SchemaSGChainImpl;
 import org.apache.ws.jaxme.impl.JAXBContextImpl;
-import org.apache.ws.jaxme.pm.ino.api4j.TaminoAPI4JPm;
+import org.apache.ws.jaxme.pm.ino.api4j.TaminoAPI4JDbPm;
+import org.apache.ws.jaxme.pm.ino.api4j.TaminoAPI4JRaPm;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -37,6 +39,8 @@
 public class TaminoAPI4JSchemaSG extends SchemaSGChainImpl {
     private final TaminoAPI4JSG baseSG;
 
+    /** Creates a new instance with the given backing chains.
+     */
     public TaminoAPI4JSchemaSG(SchemaSGChain pChain, TaminoAPI4JSG pBaseSG) {
         super(pChain);
         baseSG = pBaseSG;
@@ -60,7 +64,8 @@
         final Document doc = super.getConfigFile(pController, pPackageName, pContextList);
         final Element root = doc.getDocumentElement();
         final Iterator iter = pContextList.iterator();
-        TaminoAPI4JSG.RaDetails details = baseSG.getRaDetails();
+        TaminoAPI4JSG.RaDetails raDetails = baseSG.getRaDetails();
+        TaminoAPI4JSG.DbDetails dbDetails = baseSG.getDbDetails();
         for (Node node = root.getFirstChild();  node != null;  node = node.getNextSibling()) {
             if (node.getNodeType() == Node.ELEMENT_NODE
                     &&  JAXBContextImpl.CONFIGURATION_URI.equals(node.getNamespaceURI())
@@ -68,19 +73,44 @@
                 Element manager = (Element) node;
                 final ObjectSG objectSG = (ObjectSG) iter.next();
                 final TypeSG typeSG = objectSG.getTypeSG();
-                if (typeSG.isComplex()) {
-                    manager.setAttributeNS(uri, "pmClass", TaminoAPI4JPm.class.getName());
+                if (!typeSG.isComplex()) {
+                	continue;
                 }
 
-                if (details != null) {
-                    String collection = details.getCollection();
+                final Class managerClass;
+                if (raDetails != null) {
+                    String collection = raDetails.getCollection();
                     if (collection != null  &&  collection.length() > 0) {
                         createProperty(manager, "collection", collection);
                     }
-                    String jndiRef = details.getJndiReference();
+                    String jndiRef = raDetails.getJndiReference();
                     if (jndiRef != null  &&  jndiRef.length() > 0) {
                         createProperty(manager, "jndiReference", jndiRef);
                     }
+                    managerClass = TaminoAPI4JRaPm.class;
+                } else if (dbDetails != null) {
+                	String collection = dbDetails.getCollection();
+                    if (collection != null  &&  collection.length() > 0) {
+                        createProperty(manager, "collection", collection);
+                    }
+                    String url = dbDetails.getUrl();
+                    if (url != null  &&  url.length() > 0) {
+                        createProperty(manager, "url", url);
+                    }
+                    String user = dbDetails.getUser();
+                    if (user != null  &&  user.length() > 0) {
+                        createProperty(manager, "user", user);
+                    }
+                    String password = dbDetails.getPassword();
+                    if (password != null  &&  password.length() > 0) {
+                        createProperty(manager, "password", password);
+                    }
+                    managerClass = TaminoAPI4JDbPm.class;
+                } else {
+                	managerClass = null;
+                }
+                if (managerClass != null) {
+                    manager.setAttributeNS(uri, "pmClass", managerClass.getName());
                 }
             }
         }

Modified: webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/DocumentDefaultHandler.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/DocumentDefaultHandler.java?rev=327163&r1=327162&r2=327163&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/DocumentDefaultHandler.java (original)
+++ webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/DocumentDefaultHandler.java Fri Oct 21 05:39:56 2005
@@ -43,9 +43,6 @@
     static void setUnmarshallerHandler(JMUnmarshallerHandlerImpl pHandler) {
         handler.set(pHandler);
     }
-    
-    public DocumentDefaultHandler() {
-    }
 
     public void startDocument() throws SAXException {
         getUnmarshallerHandler().startDocument();

Modified: webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/ElementDefaultHandler.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/ElementDefaultHandler.java?rev=327163&r1=327162&r2=327163&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/ElementDefaultHandler.java (original)
+++ webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/ElementDefaultHandler.java Fri Oct 21 05:39:56 2005
@@ -53,9 +53,6 @@
         return (Data) data.get();
     }
 
-    public ElementDefaultHandler() {
-    }
-
     public TSAXElement getFirstElement() {
         List result = getData().result;
         if (result.size() > 0) {

Modified: webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TJMElement.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TJMElement.java?rev=327163&r1=327162&r2=327163&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TJMElement.java (original)
+++ webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TJMElement.java Fri Oct 21 05:39:56 2005
@@ -28,16 +28,23 @@
 import com.softwareag.tamino.db.api.objectModel.sax.TSAXElement;
 
 
-/**
- * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+/** JaxMe specific implementation of
+ * {@link com.softwareag.tamino.db.api.objectModel.sax.TSAXElement},
+ * and {@link com.softwareag.tamino.db.api.objectModel.sax.TSAXDocument}.
  */
 public class TJMElement implements TSAXDocument, TSAXElement {
     private final InoObject element;
 
+    /** Creates a new instance, which reads or writes
+     * the given {@link InoObject}.
+     */
     public TJMElement(InoObject pElement) {
         element = pElement;
     }
 
+    /** Returns the {@link InoObject}, which is being
+     * read, or written.
+     */
     public InoObject getJMElement() {
         return element;
     }
@@ -48,7 +55,7 @@
 
     public void writeTo(Writer pWriter) {
         try {
-            TaminoAPI4JPm.getJAXBContext().createMarshaller().marshal(getJMElement(), pWriter);
+            TaminoAPI4JRaPm.getJAXBContext().createMarshaller().marshal(getJMElement(), pWriter);
         } catch (JAXBException e) {
             throw new UndeclaredThrowableException(e);
         }

Added: webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JDbPm.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JDbPm.java?rev=327163&view=auto
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JDbPm.java (added)
+++ webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JDbPm.java Fri Oct 21 05:39:56 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2003, 2004  The Apache Software Foundation
+ * 
+ * Licensed 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.ws.jaxme.pm.ino.api4j;
+
+import javax.xml.bind.JAXBException;
+
+import org.apache.ws.jaxme.JMManager;
+import org.apache.ws.jaxme.PMException;
+
+import com.softwareag.tamino.db.api.connection.TConnection;
+import com.softwareag.tamino.db.api.connection.TConnectionFactory;
+import com.softwareag.tamino.db.api.connection.TServerNotAvailableException;
+
+
+/** {@link org.apache.ws.jaxme.PM} implementation for accessing
+ * a Tamino database via the basic version of the TaminoAPI4J.
+ */
+public class TaminoAPI4JDbPm extends TaminoAPI4JPm {
+	private String url, user, password;
+
+	/** Sets the database URL. This includes the database name,
+	 * but not the database collection.
+	 */
+	public String getUrl() {
+		return url;
+	}
+
+	/** Returns the database URL. This includes the database name,
+	 * but not the database collection.
+	 */
+	public void setUrl(String pUrl) {
+		url = pUrl;
+	}
+
+	/** Returns the database user.
+	 */
+	public String getUser() {
+		return user;
+	}
+
+	/** Sets the database user.
+	 */
+	public void setUser(String pUser) {
+		user = pUser;
+	}
+
+	/** Returns the database users password.
+	 */
+	public String getPassword() {
+		return password;
+	}
+
+	/** Sets the database users password.
+	 */
+	public void setPassword(String pPassword) {
+		password = pPassword;
+	}
+
+    public void init(JMManager pManager) throws JAXBException {
+        super.init(pManager);
+        url = pManager.getProperty("url");
+        user = pManager.getProperty("user");
+        password = pManager.getProperty("password");
+    }
+
+	protected TConnection getTConnection() throws PMException {
+		TConnectionFactory factory = TConnectionFactory.getInstance();
+		try {
+			return factory.newConnection(url, user, password);
+		} catch (TServerNotAvailableException e) {
+			throw new PMException(e);
+		}
+	}
+}

Added: webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JRaPm.java
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JRaPm.java?rev=327163&view=auto
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JRaPm.java (added)
+++ webservices/jaxme/branches/MAVEN/projects/pm/src/main/java/org/apache/ws/jaxme/pm/ino/api4j/TaminoAPI4JRaPm.java Fri Oct 21 05:39:56 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2003, 2004  The Apache Software Foundation
+ * 
+ * Licensed 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.ws.jaxme.pm.ino.api4j;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.xml.bind.JAXBException;
+
+import org.apache.ws.jaxme.JMManager;
+import org.apache.ws.jaxme.PMException;
+
+import com.softwareag.tamino.db.api.connection.TConnection;
+import com.softwareag.tamino.db.api.connection.TServerNotAvailableException;
+import com.softwareag.tamino.db.api.connector.TaminoDataSource;
+
+
+/** {@link org.apache.ws.jaxme.PM} implementation for accessing
+ * a Tamino database via the resource adapter version of the
+ * TaminoAPI4J.
+ */
+public class TaminoAPI4JRaPm extends TaminoAPI4JPm {
+    private String jndiReference;
+
+    /** Returns the JNDI reference.
+     */
+    public String getJndiReference() {
+        return jndiReference;
+    }
+
+    /** Sets the JNDI reference.
+     */
+    public void setJndiReference(String pJndiReference) {
+        jndiReference = pJndiReference;
+    }
+
+    protected TConnection getTConnection() throws PMException {
+    	TaminoDataSource tds;
+    	try {
+    		InitialContext ic = new InitialContext();
+    		tds = (TaminoDataSource) ic.lookup(jndiReference);
+    	} catch (NamingException e) {
+    		throw new PMException(e);
+    	}
+    	try {
+			return tds.getConnection();
+		} catch (TServerNotAvailableException e) {
+			throw new PMException(e);
+		}
+    }
+
+    public void init(JMManager pManager) throws JAXBException {
+        super.init(pManager);
+        jndiReference = pManager.getProperty("jndiReference");
+        if (jndiReference == null  ||  jndiReference.length() == 0) {
+            throw new JAXBException("The property 'jndiReference' must be set.");
+        }
+    }
+}

Modified: webservices/jaxme/branches/MAVEN/projects/pm/xdocs/ino.xml
URL: http://svn.apache.org/viewcvs/webservices/jaxme/branches/MAVEN/projects/pm/xdocs/ino.xml?rev=327163&r1=327162&r2=327163&view=diff
==============================================================================
--- webservices/jaxme/branches/MAVEN/projects/pm/xdocs/ino.xml (original)
+++ webservices/jaxme/branches/MAVEN/projects/pm/xdocs/ino.xml Fri Oct 21 05:39:56 2005
@@ -76,6 +76,12 @@
 	</section>
 
 	<section name="Preparing the Tamino Resource Adapter">
+		<p>If you are not using the Tamino Resource Adapter (which
+		  is typically the case, if you are <em>not</em> using
+		  an EJB container like JBoss, WebSphere, or the like.
+		  In that case you may very well skip this section and
+		  proceed to the next section, which is about creating
+		  the schema file.</p>
 		<p>Adding the Tamino Resource Adapter is covered in the
 		  documentation of the TaminoAPI4J. However, we'll provide
 		  specific details for JBoss 3.2 here, because the docs
@@ -197,6 +203,11 @@
       <jaxb:globalBindings>
         <xjc:serializable/>
         <inoapi:raDetails collection="adr" jndiReference="java:MyTaminoLocalTxConnector"/>
+        <!-- If you are not using the Tamino Resource Adapter, then the following
+             will fit for you:
+          <inoapi:dbDetails collection="adr" url="http://127.0.0.1/tamino/adrDb"
+            user="me" password="MySecretPassword"/>
+        -->
       </jaxb:globalBindings>
       <tsd:schemaInfo name="Address">
         <tsd:collection name="adr"></tsd:collection>



---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org