Author: jsdelfino
Date: Fri Apr  7 08:28:54 2006
New Revision: 392319

URL: http://svn.apache.org/viewcvs?rev=392319&view=rev
Log:
prototype of a code generator that generates SDO implementation classes from 
Java interfaces

Added:
    incubator/tuscany/sandbox/sebastien/java/sdo/
    incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/
      - copied from r392086, incubator/tuscany/java/samples/bigbank/account/
    
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/Operation.java
   (with props)
    
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClientTestCase.java
   (with props)
    incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/
      - copied from r392086, incubator/tuscany/java/sdo/plugin/
    
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/
    
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/
    
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/generate/
    
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/generate/JavaGenerator.java
   (with props)
    
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/plugin/
    
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/plugin/JavaInterface2SDOGeneratorMojo.java
   (with props)
Modified:
    incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/pom.xml
    
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java
    
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java
    
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/CheckingAccount.java
    
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/SavingsAccount.java
    
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/StockAccount.java
    
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClient.java
    incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/pom.xml

Modified: incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/pom.xml
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/pom.xml?rev=392319&r1=392086&r2=392319&view=diff
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/pom.xml 
(original)
+++ incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/pom.xml Fri 
Apr  7 08:28:54 2006
@@ -34,10 +34,60 @@
             <version>${pom.version}</version>
             <scope>provided</scope> <!-- use provided so tuscany infrastructue 
is not inc. in the war-->
         </dependency>
+        <dependency>
+            <groupId>org.apache.tuscany.sca.containers</groupId>
+            <artifactId>tuscany-container-java</artifactId>
+            <version>${pom.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tuscany.sca.bindings</groupId>
+            <artifactId>tuscany-binding-axis2</artifactId>
+            <version>${pom.version}</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.tuscany</groupId>
+                <artifactId>tuscany-java2sdo-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <configuration>
+                            <javaInterfaces>
+                                
<javaInterface>org.apache.tuscany.samples.bigbank.account.services.accountdata.CheckingAccount</javaInterface>
+                                
<javaInterface>org.apache.tuscany.samples.bigbank.account.services.accountdata.Operation</javaInterface>
+                                
<javaInterface>org.apache.tuscany.samples.bigbank.account.services.accountdata.SavingsAccount</javaInterface>
+                                
<javaInterface>org.apache.tuscany.samples.bigbank.account.services.accountdata.StockAccount</javaInterface>
+                            </javaInterfaces>
+                            
<javaPackage>org.apache.tuscany.samples.bigbank.account.services.accountdata</javaPackage>
+                            <noNotification>true</noNotification>
+                            <noContainer>true</noContainer>
+                            <noUnsettable>true</noUnsettable>
+                        </configuration>
+                        <goals>
+                            <goal>generate</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.apache.tuscany</groupId>
                 <artifactId>tuscany-sdo-plugin</artifactId>

Modified: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java?rev=392319&r1=392086&r2=392319&view=diff
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java
 (original)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/account/AccountServiceImpl.java
 Fri Apr  7 08:28:54 2006
@@ -31,6 +31,8 @@
 import org.osoa.sca.annotations.Reference;
 import org.osoa.sca.annotations.Service;
 
+import commonj.sdo.helper.DataFactory;
+
 @Service(interfaces=AccountService.class)
 public class AccountServiceImpl implements AccountService {
 
@@ -38,6 +40,8 @@
         SDOUtil.registerStaticTypes(AccountFactory.class);
     }
 
+    private static final DataFactory dataFactory=DataFactory.INSTANCE;
+
     @Property
     private String currency = "USD";
 
@@ -51,27 +55,25 @@
 
     public AccountReport getAccountReport(String customerID) {
         
-        AccountFactory accountFactory=new AccountFactory();
-
-        AccountReport accountReport = accountFactory.createAccountReport();
+        AccountReport accountReport = 
(AccountReport)dataFactory.create(AccountReport.class);
         List accountSummaries = accountReport.getAccountSummaries();
 
         CheckingAccount checkingAccount = 
accountDataService.getCheckingAccount(customerID);
-        AccountSummary checkingAccountSummary = 
accountFactory.createAccountSummary();
+        AccountSummary checkingAccountSummary = 
(AccountSummary)dataFactory.create(AccountSummary.class);
         
checkingAccountSummary.setAccountNumber(checkingAccount.getAccountNumber());
         checkingAccountSummary.setAccountType("checking");
         
checkingAccountSummary.setBalance(fromUSDollarToCurrency(checkingAccount.getBalance()));
         accountSummaries.add(checkingAccountSummary);
 
         SavingsAccount savingsAccount = 
accountDataService.getSavingsAccount(customerID);
-        AccountSummary savingsAccountSummary = 
accountFactory.createAccountSummary();
+        AccountSummary savingsAccountSummary = 
(AccountSummary)dataFactory.create(AccountSummary.class);
         
savingsAccountSummary.setAccountNumber(savingsAccount.getAccountNumber());
         savingsAccountSummary.setAccountType("savings");
         
savingsAccountSummary.setBalance(fromUSDollarToCurrency(savingsAccount.getBalance()));
         accountSummaries.add(savingsAccountSummary);
 
         StockAccount stockAccount = 
accountDataService.getStockAccount(customerID);
-        AccountSummary stockAccountSummary = 
accountFactory.createAccountSummary();
+        AccountSummary stockAccountSummary = 
(AccountSummary)dataFactory.create(AccountSummary.class);
         stockAccountSummary.setAccountNumber(stockAccount.getAccountNumber());
         stockAccountSummary.setAccountType("stock");
         float balance = (stockQuoteService.getQuote(stockAccount.getSymbol())) 
* stockAccount.getQuantity();

Modified: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java?rev=392319&r1=392086&r2=392319&view=diff
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java
 (original)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/AccountDataServiceImpl.java
 Fri Apr  7 08:28:54 2006
@@ -16,23 +16,44 @@
  */
 package org.apache.tuscany.samples.bigbank.account.services.accountdata;
 
+import java.util.Date;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
 import org.osoa.sca.annotations.Service;
 
+import commonj.sdo.helper.DataFactory;
+
 @Service(AccountDataService.class)
 public class AccountDataServiceImpl implements AccountDataService {
+    
+    static {
+        SDOUtil.registerStaticTypes(AccountdataFactory.class);
+    }
+    
+    private static final DataFactory dataFactory=DataFactory.INSTANCE;
 
     public CheckingAccount getCheckingAccount(String customerID) {
 
-        CheckingAccount checkingAccount = new CheckingAccount();
+        CheckingAccount checkingAccount = 
(CheckingAccount)dataFactory.create(CheckingAccount.class);
         checkingAccount.setAccountNumber(customerID + "_" + "CHA12345");
         checkingAccount.setBalance(1500.0f);
+        
+        Operation operation1=(Operation)dataFactory.create(Operation.class);
+        operation1.setAmount(1000);
+        operation1.setDate(new Date(System.currentTimeMillis()));
+        checkingAccount.getOperations().add(operation1);
+
+        Operation operation2=(Operation)dataFactory.create(Operation.class);
+        operation2.setAmount(1000);
+        operation2.setDate(new Date(System.currentTimeMillis()));
+        checkingAccount.getOperations().add(operation2);
 
         return checkingAccount;
     }
 
     public SavingsAccount getSavingsAccount(String customerID) {
 
-        SavingsAccount savingsAccount = new SavingsAccount();
+        SavingsAccount savingsAccount = 
(SavingsAccount)dataFactory.create(SavingsAccount.class);
         savingsAccount.setAccountNumber(customerID + "_" + "SAA12345");
         savingsAccount.setBalance(1500.0f);
 
@@ -41,7 +62,7 @@
 
     public StockAccount getStockAccount(String customerID) {
 
-        StockAccount stockAccount = new StockAccount();
+        StockAccount stockAccount = 
(StockAccount)dataFactory.create(StockAccount.class);
         stockAccount.setAccountNumber(customerID + "_" + "STA12345");
         stockAccount.setSymbol("IBM");
         stockAccount.setQuantity(100);

Modified: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/CheckingAccount.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/CheckingAccount.java?rev=392319&r1=392086&r2=392319&view=diff
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/CheckingAccount.java
 (original)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/CheckingAccount.java
 Fri Apr  7 08:28:54 2006
@@ -16,24 +16,18 @@
  */
 package org.apache.tuscany.samples.bigbank.account.services.accountdata;
 
-public class CheckingAccount {
+import java.util.List;
 
-    private String accountNumber;
-    private float balance;
+public interface CheckingAccount {
 
-    public String getAccountNumber() {
-        return accountNumber;
-    }
+    public String getAccountNumber();
 
-    public void setAccountNumber(String accountNumber) {
-        this.accountNumber = accountNumber;
-    }
+    public void setAccountNumber(String accountNumber);
 
-    public float getBalance() {
-        return balance;
-    }
+    public float getBalance();
 
-    public void setBalance(float balance) {
-        this.balance = balance;
-    }
+    public void setBalance(float balance);
+    
+    public List<Operation> getOperations();
+    
 }

Added: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/Operation.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/Operation.java?rev=392319&view=auto
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/Operation.java
 (added)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/Operation.java
 Fri Apr  7 08:28:54 2006
@@ -0,0 +1,31 @@
+/**
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as 
applicable.
+ *
+ *  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.tuscany.samples.bigbank.account.services.accountdata;
+
+import java.util.Date;
+
+public interface Operation {
+
+    public Date getDate();
+
+    public void setDate(Date date);
+
+    public float getAmount();
+
+    public void setAmount(float amount);
+
+}

Propchange: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/Operation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/Operation.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Modified: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/SavingsAccount.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/SavingsAccount.java?rev=392319&r1=392086&r2=392319&view=diff
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/SavingsAccount.java
 (original)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/SavingsAccount.java
 Fri Apr  7 08:28:54 2006
@@ -16,24 +16,14 @@
  */
 package org.apache.tuscany.samples.bigbank.account.services.accountdata;
 
-public class SavingsAccount {
+public interface SavingsAccount {
 
-    private String accountNumber;
-    private float balance;
+    public String getAccountNumber();
 
-    public String getAccountNumber() {
-        return accountNumber;
-    }
+    public void setAccountNumber(String accountNumber);
 
-    public void setAccountNumber(String accountNumber) {
-        this.accountNumber = accountNumber;
-    }
+    public float getBalance();
 
-    public float getBalance() {
-        return balance;
-    }
+    public void setBalance(float balance);
 
-    public void setBalance(float balance) {
-        this.balance = balance;
-    }
 }

Modified: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/StockAccount.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/StockAccount.java?rev=392319&r1=392086&r2=392319&view=diff
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/StockAccount.java
 (original)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/main/java/org/apache/tuscany/samples/bigbank/account/services/accountdata/StockAccount.java
 Fri Apr  7 08:28:54 2006
@@ -16,33 +16,18 @@
  */
 package org.apache.tuscany.samples.bigbank.account.services.accountdata;
 
-public class StockAccount {
+public interface StockAccount {
+
+    public String getAccountNumber();
+
+    public void setAccountNumber(String accountNumber);
+
+    public int getQuantity();
+
+    public void setQuantity(int quantity);
+
+    public String getSymbol();
+
+    public void setSymbol(String symbol);
 
-    private String accountNumber;
-    private String symbol;
-    private int quantity;
-
-    public String getAccountNumber() {
-        return accountNumber;
-    }
-
-    public void setAccountNumber(String accountNumber) {
-        this.accountNumber = accountNumber;
-    }
-
-    public int getQuantity() {
-        return quantity;
-    }
-
-    public void setQuantity(int quantity) {
-        this.quantity = quantity;
-    }
-
-    public String getSymbol() {
-        return symbol;
-    }
-
-    public void setSymbol(String symbol) {
-        this.symbol = symbol;
-    }
 }

Modified: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClient.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClient.java?rev=392319&r1=392086&r2=392319&view=diff
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClient.java
 (original)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClient.java
 Fri Apr  7 08:28:54 2006
@@ -24,15 +24,8 @@
 import 
org.apache.tuscany.samples.bigbank.account.services.account.AccountService;
 import org.osoa.sca.CurrentModuleContext;
 import org.osoa.sca.ModuleContext;
-import org.osoa.sca.SCA;
 
-public class AccountClient extends SCA {
-
-    public void start() {
-    }
-
-    public void stop() {
-    }
+public class AccountClient {
 
     public static void main(String[] args) throws Exception {
         TuscanyRuntime tuscany = new 
TuscanyRuntime("bigbank.account.testclient", null);
@@ -50,7 +43,6 @@
             System.out.println(accountSummary.getAccountType());
             System.out.println(accountSummary.getBalance());
         }
-
     }
 
 }

Added: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClientTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClientTestCase.java?rev=392319&view=auto
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClientTestCase.java
 (added)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClientTestCase.java
 Fri Apr  7 08:28:54 2006
@@ -0,0 +1,74 @@
+/**
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as 
applicable.
+ *
+ *  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.tuscany.samples.bigbank.account.client;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.client.TuscanyRuntime;
+import org.apache.tuscany.samples.bigbank.account.AccountReport;
+import org.apache.tuscany.samples.bigbank.account.AccountSummary;
+import 
org.apache.tuscany.samples.bigbank.account.services.account.AccountService;
+import org.osoa.sca.CurrentModuleContext;
+import org.osoa.sca.ModuleContext;
+
+public class AccountClientTestCase extends TestCase {
+
+    private boolean verbose = false;
+    
+    public void testAccount() throws Exception {
+
+        TuscanyRuntime tuscany = new 
TuscanyRuntime("bigbank.account.testclient", null);
+        tuscany.start();
+        ModuleContext moduleContext = CurrentModuleContext.getContext();
+        assertNotNull(moduleContext);
+
+        AccountService accountService = (AccountService) 
moduleContext.locateService("AccountServiceComponent");
+        assertNotNull(accountService);
+
+        AccountReport accountReport = accountService.getAccountReport("12345");
+        assertNotNull(accountReport);
+
+        for (Iterator i = accountReport.getAccountSummaries().iterator(); 
i.hasNext();) {
+            AccountSummary accountSummary = (AccountSummary) i.next();
+            assertNotNull(accountSummary);
+
+            if (verbose) {
+                System.out.println(accountSummary.getAccountNumber());
+                System.out.println(accountSummary.getAccountType());
+                System.out.println(accountSummary.getBalance());
+            }
+        }
+    }
+
+    public boolean isVerbose() {
+        return verbose;
+    }
+
+    public void setVerbose(boolean verbose) {
+        this.verbose = verbose;
+    }
+
+    public final static void main(String[] args) throws Exception {
+        AccountClientTestCase tc = new AccountClientTestCase();
+        tc.setVerbose(true);
+        tc.testAccount();
+
+    }
+
+}

Propchange: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClientTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/sebastien/java/sdo/account-java2sdo/src/test/java/org/apache/tuscany/samples/bigbank/account/client/AccountClientTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Modified: incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/pom.xml
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/pom.xml?rev=392319&r1=392086&r2=392319&view=diff
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/pom.xml 
(original)
+++ incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/pom.xml Fri 
Apr  7 08:28:54 2006
@@ -21,10 +21,10 @@
         <version>SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <artifactId>tuscany-sdo-plugin</artifactId>
+    <artifactId>tuscany-java2sdo-plugin</artifactId>
     <packaging>maven-plugin</packaging>
     <version>SNAPSHOT</version>
-    <name>Tuscany SDO Maven Plugin</name>
+    <name>Tuscany Java2SDO Maven Plugin</name>
 
     <dependencies>
         <dependency>
@@ -39,4 +39,16 @@
             <scope>compile</scope>
         </dependency>
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

Added: 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/generate/JavaGenerator.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/generate/JavaGenerator.java?rev=392319&view=auto
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/generate/JavaGenerator.java
 (added)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/generate/JavaGenerator.java
 Fri Apr  7 08:28:54 2006
@@ -0,0 +1,300 @@
+/**
+ *
+ *  Copyright 2005 BEA Systems Inc.
+ *  Copyright 2005 International Business Machines Corporation
+ *
+ *  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.tuscany.java2sdo.generate;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sdo.impl.SDOPackageImpl;
+import org.apache.tuscany.sdo.model.impl.ModelPackageImpl;
+import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.codegen.util.CodeGenUtil;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+import commonj.sdo.helper.TypeHelper;
+
+public class JavaGenerator extends 
org.apache.tuscany.sdo.generate.JavaGenerator
+{
+
+    /**
+   * Generate static SDOs from Java interfaces
+   * 
+   *   Usage arguments: see JavaGenerator
+   *   
+   *     [ -targetDirectory <target-root-directory> ]
+   *     [ -javaPackage <java-package-name> ]
+   *     [ -namespace <xsd-namespace> ]
+   *     interface-names
+   *
+   *   For example:
+   *   
+   *     generate somepackage.InterfaceA somepackage.InterfaceB
+   *     
+   *   See the original SDO JavaGenerator for details and the other options.
+   *   
+   */
+  public static void main(String args[])
+  {
+    if (args.length == 0)
+    {
+      printUsage();
+      return;
+    }
+
+    //TODO The processing of the options is very similar to the original SDO 
JavaGenerator and should be factored out
+    String targetDirectory = null;
+    String javaPackage = null;
+    String namespace = null;
+    String prefix = null;
+    
+    int genOptions = 0;
+
+    int index = 0;
+    for (; index < args.length && args[index].startsWith("-"); ++index)
+    {
+      if (args[index].equalsIgnoreCase("-targetDirectory"))
+      {
+        targetDirectory = args[++index];
+      }
+      else if (args[index].equalsIgnoreCase("-javaPackage"))
+      {
+        javaPackage = args[++index];
+      }
+      else if (args[index].equalsIgnoreCase("-namespace"))
+      {
+        namespace = args[++index];
+      }
+      else if (args[index].equalsIgnoreCase("-prefix"))
+      {
+        prefix = args[++index];
+      }
+      else if (args[index].equalsIgnoreCase("-noInterfaces"))
+      {
+        genOptions |= OPTION_NO_INTERFACES;
+      }
+      else if (args[index].equalsIgnoreCase("-sparsePattern"))
+      {
+        genOptions |= OPTION_SPARSE_PATTERN;
+      }
+      else if (args[index].equalsIgnoreCase("-storePattern"))
+      {
+        genOptions |= OPTION_STORE_PATTERN;
+      }
+      else if (args[index].equalsIgnoreCase("-noContainment"))
+      {
+        genOptions |= OPTION_NO_CONTAINMENT;
+      }
+      else if (args[index].equalsIgnoreCase("-noNotification"))
+      {
+        genOptions |= OPTION_NO_NOTIFICATION;
+      }
+      else if (args[index].equalsIgnoreCase("-arrayAccessors"))
+      {
+        genOptions |= OPTION_ARRAY_ACCESSORS;
+      }
+      else if (args[index].equalsIgnoreCase("-generateLoader"))
+      {
+        genOptions |= OPTION_GENERATE_LOADER;
+      }
+      else if (args[index].equalsIgnoreCase("-noUnsettable"))
+      {
+        genOptions |= OPTION_NO_UNSETTABLE;
+      }
+      //else if (...)
+      else
+      {
+        printUsage();
+        return;
+      }
+    }
+
+    List<String> javaInterfaces=new ArrayList<String>();
+    for (; index < args.length; ++index)
+    {
+        javaInterfaces.add(args[index]);
+    }
+    
+    ClassLoader classLoader=JavaGenerator.class.getClassLoader();
+    
+    generateFromJavaInterfaces(classLoader, javaInterfaces, namespace, 
targetDirectory, javaPackage, prefix, genOptions);
+  }
+  
+  public static void generateFromJavaInterfaces(ClassLoader classLoader, 
List<String> javaInterfaces, String packageURI, String targetDirectory, String 
javaPackage, String prefix, int genOptions)
+  {
+    try
+    {
+        // Initialize the SDO runtime
+        DataObjectUtil.initRuntime();
+        EPackage.Registry packageRegistry = new 
EPackageRegistryImpl(EPackage.Registry.INSTANCE);
+
+        // Create an EPackage for the generated SDO
+        if (packageURI==null)
+            packageURI="http://"+javaPackage;
+        EPackage implEPackage = EcoreFactory.eINSTANCE.createEPackage();
+        implEPackage.setNsURI(packageURI);
+        String shortName=shortName(packageURI);
+        implEPackage.setName(shortName);
+        implEPackage.setNsPrefix(shortName.toLowerCase());
+        packageRegistry.put(packageURI, implEPackage);
+        
+        // Create EClasses for all the given Java interfaces 
+        Map<Class, EClass> eClasses=new HashMap<Class, EClass>();
+        for (String interfaceName : javaInterfaces) {
+            Class instanceClass=Class.forName(interfaceName, true, 
classLoader);
+            
+            EClass implEClass=EcoreFactory.eINSTANCE.createEClass();
+            String className=shortName(instanceClass.getName());
+            implEClass.setName(className);
+            implEClass.setInstanceClass(instanceClass);
+            
+            eClasses.put(instanceClass, implEClass);
+            implEPackage.getEClassifiers().add(implEClass);
+        }
+        
+        // Populate the EClasses with EAttributes and EReferences for their 
properties
+        for (EClass implEClass : (List<EClass>)implEPackage.getEClassifiers()) 
{
+            Class instanceClass=implEClass.getInstanceClass();
+            Method[] methods=instanceClass.getMethods();
+            for (int m=0; m<methods.length; m++) {
+                Method method=methods[m];
+                String propertyName=null;
+                if (method.getName().startsWith("get"))
+                    propertyName=method.getName().substring(3);
+                else if (method.getName().startsWith("is"))
+                    propertyName=method.getName().substring(2);
+                
+                if (propertyName!=null) {
+                    if (propertyName.length()>1)
+                        
propertyName=propertyName.substring(0,1).toLowerCase()+propertyName.substring(1);
+                
+                    Class propertyClass=method.getReturnType();
+                    EClass propertyEClass=eClasses.get(propertyClass);
+
+                    if (propertyEClass!=null) {
+                        
+                        // The property is another SDO, create an EReference 
to represent the property
+                        EReference 
reference=EcoreFactory.eINSTANCE.createEReference();
+                        reference.setName(propertyName);
+                        reference.setContainment(true);
+                        reference.setEType(propertyEClass);
+                        implEClass.getEStructuralFeatures().add(reference);
+                        
+                    } else {
+
+                        // The property is a List<T> and T is an SDO, created 
a 0..many EReference to represent the property 
+                        if (propertyClass==List.class) {
+                            Type genericType=method.getGenericReturnType();
+                            if (genericType instanceof ParameterizedType) {
+                                ParameterizedType parameterizedType = 
(ParameterizedType) genericType;
+                                Type[] targs = 
parameterizedType.getActualTypeArguments();
+                                if (targs.length!=0 && 
eClasses.containsKey(targs[0])) {
+                                    propertyEClass=eClasses.get(targs[0]);
+                                    if (propertyEClass!=null) {
+                                        EReference 
reference=EcoreFactory.eINSTANCE.createEReference();
+                                        reference.setName(propertyName);
+                                        reference.setContainment(true);
+                                        reference.setEType(propertyEClass);
+                                        reference.setUpperBound(-1);
+                                        
implEClass.getEStructuralFeatures().add(reference);
+                                    }
+                                }
+                            }
+                            continue;
+                        }
+                        
+                        // The property is a regular Java type / not an SDO, 
create an EAttribute to represent it
+                        EAttribute 
attribute=EcoreFactory.eINSTANCE.createEAttribute();
+                        attribute.setName(propertyName);
+                        EDataType 
dataType=(EDataType)TypeHelper.INSTANCE.getType(propertyClass);
+                        attribute.setEType(dataType);
+                        implEClass.getEStructuralFeatures().add(attribute);
+                    }
+                }
+            }
+            
+        }
+        
+        // TODO This code is very similar to the original SDO JavaGenerator 
and should be factored out
+        ResourceSet resourceSet = DataObjectUtil.createResourceSet();
+        List usedGenPackages = new ArrayList();
+        GenModel genModel = null;
+        for (Iterator iter = packageRegistry.values().iterator(); 
iter.hasNext();)
+        {
+          EPackage currentEPackage = (EPackage)iter.next();
+          String currentBasePackage = extractBasePackageName(currentEPackage, 
javaPackage);
+          String currentPrefix = prefix == null ? 
CodeGenUtil.capName(shortName) : prefix;
+          GenPackage currentGenPackage = createGenPackage(currentEPackage, 
currentBasePackage, currentPrefix, genOptions, resourceSet);
+          if (currentEPackage.getNsURI().equals(packageURI))
+          {
+            genModel = currentGenPackage.getGenModel();
+          }
+          else
+          {
+            usedGenPackages.add(currentGenPackage);
+          }
+        }
+        
+        usedGenPackages.add(createGenPackage(SDOPackageImpl.eINSTANCE, 
"org.apache.tuscany", "SDO", 0, resourceSet));
+        usedGenPackages.add(createGenPackage(ModelPackageImpl.eINSTANCE, 
"org.apache.tuscany.sdo", "Model", 0, resourceSet));
+        genModel.getUsedGenPackages().addAll(usedGenPackages);
+        
+        // Invoke the SDO JavaGenerator to generate the SDO classes
+        generateFromGenModel(genModel, new 
File(targetDirectory).getCanonicalPath());
+        
+    }
+    catch (IOException e)
+    {
+      e.printStackTrace();
+    }
+    catch (ClassNotFoundException e)
+    {
+      e.printStackTrace();
+    }
+  }
+  
+  protected static void printUsage()
+  {
+    System.out.println("Usage arguments:");
+    System.out.println("  [ -targetDirectory <target-root-directory> ]");
+    System.out.println("  [ -javaPackage <java-package-name> ]");
+    System.out.println("  [ -namespace <xsd-namespace> ]");
+    System.out.println("  interface-names");
+    System.out.println("");
+    System.out.println("For example:");
+    System.out.println("");
+    System.out.println("  generate somepackage.InterfaceA 
somepackage.InterfaceB");
+  }
+
+}

Propchange: 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/generate/JavaGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/generate/JavaGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/plugin/JavaInterface2SDOGeneratorMojo.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/plugin/JavaInterface2SDOGeneratorMojo.java?rev=392319&view=auto
==============================================================================
--- 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/plugin/JavaInterface2SDOGeneratorMojo.java
 (added)
+++ 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/plugin/JavaInterface2SDOGeneratorMojo.java
 Fri Apr  7 08:28:54 2006
@@ -0,0 +1,192 @@
+/**
+ *
+ *  Copyright 2005 BEA Systems Inc.
+ *  Copyright 2005 International Business Machines Corporation
+ *
+ *  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.tuscany.java2sdo.plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.tuscany.java2sdo.generate.JavaGenerator;
+
+/**
+ * @version $Rev$ $Date$
+ * @goal generate
+ * @phase generate-sources
+ * @execute phase=compile
+ * @requiresDependencyResolution compile
+ * @description Generate SDO classes from Java interfaces
+ */
+public class JavaInterface2SDOGeneratorMojo extends AbstractMojo {
+
+    /**
+     * The directory containing java files; defaults to 
${basedir}/src/main/java
+     * @parameter expression="${basedir}/src/main/java"
+     */
+    private String sourceDir;
+
+    /**
+     * List of java interface names.
+     * @parameter
+     */
+    private List javaInterfaces;
+
+    /**
+     * The Java package to generate into. By default the value is derived from 
the schema URI.
+     *
+     * @parameter
+     */
+    private String javaPackage;
+
+    /**
+     * The directory to generate into; defaults to 
${project.build.directory}/sdo-source
+     *
+     * @parameter expression="${project.build.directory}/sdo-source"
+     */
+    private String targetDirectory;
+
+    /**
+     * Specifies the namespace URI to use in the generated SDO package. 
+     * @parameter
+     */
+    private String namespace;
+
+    /**
+     * Specifies the prefix string to use for naming the generated factory. 
+     * @parameter
+     */
+    private String prefix;
+
+    /**
+     * This option can be used to eliminate the generated interface and to 
generate only an implementation class. 
+     * @parameter
+     */
+    private boolean noInterfaces;
+
+    /**
+     * Turns off container management for containment properties.  
+     * @parameter
+     */
+    private boolean noContainment;
+
+    /**
+     * This option eliminates all change notification overhead in the 
generated classes.   
+     * @parameter
+     */
+    private boolean noNotification;
+
+    /**
+     * With this option, all generated properties will not record their unset 
state. 
+     * @parameter
+     */
+    private boolean noUnsettable;
+
+    /**
+     * Generate a fast XML parser/loader for instances of the model.   
+     * @parameter
+     */
+    private boolean generateLoader;
+
+    /**
+     * Generate a Switch class for the model.   
+     * @parameter
+     */
+    private boolean generateSwitch;
+
+    /**
+     * @parameter expression="${project.compileSourceRoots}"
+     * @readonly
+     */
+    private List compilerSourceRoots;
+
+    /**
+     * @parameter expression="${project.compileClasspathElements}"
+     * @readonly
+     */
+    private List classpathElements;
+    
+    public void execute() throws MojoExecutionException {
+        
+        int genOptions = 0;
+        if (noInterfaces) {
+          genOptions |= JavaGenerator.OPTION_NO_INTERFACES;
+        }
+        if (noContainment) {
+          genOptions |= JavaGenerator.OPTION_NO_CONTAINMENT;
+        }
+        if (noNotification) {
+          genOptions |= JavaGenerator.OPTION_NO_NOTIFICATION;
+        }
+        if (generateLoader) {
+          genOptions |= JavaGenerator.OPTION_GENERATE_LOADER;
+        }
+        if (noUnsettable) {
+          genOptions |= JavaGenerator.OPTION_NO_UNSETTABLE;
+        }
+        if (generateSwitch) {
+            genOptions |= JavaGenerator.OPTION_GENERATE_SWITCH;
+          }
+
+        URL[] urls=new URL[classpathElements.size()];
+        for (int i=0, n=classpathElements.size(); i<n; i++) {
+            String path=(String)classpathElements.get(i);
+            if (new File(path).isDirectory())
+                path+='/';
+           try {
+            urls[i]=new URL("file", null, path);
+           } catch (MalformedURLException e) {
+               throw new MojoExecutionException(e.getMessage(), e);
+           } 
+        }
+        ClassLoader classLoader=new URLClassLoader(urls, 
getClass().getClassLoader());
+        
+        long lastModified=0;
+        for (String javaInterface : (List<String>)javaInterfaces) {
+            URL url=classLoader.getResource(javaInterface.replace('.', 
'/')+".class");
+            if (url!=null) {
+                File file=new File(url.getPath());
+                if (file.exists() && file.lastModified()>lastModified)
+                    lastModified=file.lastModified();
+            }
+        }
+        File marker = new File(targetDirectory, ".gen#" + javaPackage);
+        if (lastModified==0 || lastModified > marker.lastModified()) {
+
+            for (String javaInterface : (List<String>)javaInterfaces) {
+                getLog().info("Generating SDO classes from " + javaInterface);
+            }
+            JavaGenerator.generateFromJavaInterfaces(classLoader, 
javaInterfaces, namespace, targetDirectory, javaPackage, prefix, genOptions);
+
+        }
+        try {
+            marker.createNewFile();
+        } catch (IOException e) {
+            throw new MojoExecutionException(e.getMessage(), e);
+        }
+        marker.setLastModified(System.currentTimeMillis());
+        
+        compilerSourceRoots.add(targetDirectory);
+    }
+
+}
\ No newline at end of file

Propchange: 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/plugin/JavaInterface2SDOGeneratorMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/sebastien/java/sdo/plugin-java2sdo/src/main/java/org/apache/tuscany/java2sdo/plugin/JavaInterface2SDOGeneratorMojo.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date


Reply via email to