You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ke...@apache.org on 2007/05/29 18:53:22 UTC

svn commit: r542588 [2/2] - in /incubator/tuscany/java/sdo: impl/src/main/java/org/apache/tuscany/sdo/impl/ tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/ tools/src/test/java/com/example/customer/ tools/src/test/java/com/example/c...

Added: incubator/tuscany/java/sdo/tools/src/test/java/com/example/customer/impl/CustomerImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/src/test/java/com/example/customer/impl/CustomerImpl.java?view=auto&rev=542588
==============================================================================
--- incubator/tuscany/java/sdo/tools/src/test/java/com/example/customer/impl/CustomerImpl.java (added)
+++ incubator/tuscany/java/sdo/tools/src/test/java/com/example/customer/impl/CustomerImpl.java Tue May 29 09:53:20 2007
@@ -0,0 +1,419 @@
+/**
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package com.example.customer.impl;
+
+import com.example.customer.Account;
+import com.example.customer.Customer;
+import com.example.customer.CustomerFactory;
+
+import commonj.sdo.Type;
+
+import org.apache.tuscany.sdo.impl.DataObjectBase;
+
+/**
+ * <!-- begin-user-doc -->
+ * An implementation of the model object '<em><b>Customer</b></em>'.
+ * <!-- end-user-doc -->
+ * <p>
+ * The following features are implemented:
+ * <ul>
+ *   <li>{@link com.example.customer.impl.CustomerImpl#getAccount <em>Account</em>}</li>
+ *   <li>{@link com.example.customer.impl.CustomerImpl#getFirstName <em>First Name</em>}</li>
+ * </ul>
+ * </p>
+ *
+ * @generated
+ */
+public class CustomerImpl extends DataObjectBase implements Customer
+{
+
+  public final static int ACCOUNT = 0;
+
+  public final static int FIRST_NAME = 1;
+
+  public final static int SDO_PROPERTY_COUNT = 2;
+
+  public final static int EXTENDED_PROPERTY_COUNT = 0;
+
+
+  /**
+   * The internal feature id for the '<em><b>Account</b></em>' containment reference.
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   * @ordered
+   */ 
+  public final static int INTERNAL_ACCOUNT = 0;
+
+  /**
+   * The internal feature id for the '<em><b>First Name</b></em>' attribute.
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   * @ordered
+   */ 
+  public final static int INTERNAL_FIRST_NAME = 1;
+
+  /**
+   * The number of properties for this type.
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   * @ordered
+   */
+  public final static int INTERNAL_PROPERTY_COUNT = 2;
+
+  protected int internalConvertIndex(int internalIndex)
+  {
+    switch (internalIndex)
+    {
+      case INTERNAL_ACCOUNT: return ACCOUNT;
+      case INTERNAL_FIRST_NAME: return FIRST_NAME;
+    }
+    return super.internalConvertIndex(internalIndex);
+  }
+
+
+  /**
+   * The cached value of the '{@link #getAccount() <em>Account</em>}' containment reference.
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @see #getAccount()
+   * @generated
+   * @ordered
+   */
+  
+  protected Account account = null;
+  
+  /**
+   * This is true if the Account containment reference has been set.
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   * @ordered
+   */
+  protected boolean account_set_ = false;
+
+  /**
+   * The default value of the '{@link #getFirstName() <em>First Name</em>}' attribute.
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @see #getFirstName()
+   * @generated
+   * @ordered
+   */
+  protected static final String FIRST_NAME_DEFAULT_ = null;
+
+  /**
+   * The cached value of the '{@link #getFirstName() <em>First Name</em>}' attribute.
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @see #getFirstName()
+   * @generated
+   * @ordered
+   */
+  protected String firstName = FIRST_NAME_DEFAULT_;
+
+  /**
+   * This is true if the First Name attribute has been set.
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   * @ordered
+   */
+  protected boolean firstName_set_ = false;
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public CustomerImpl()
+  {
+    super();
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public Type getType()
+  {
+    return ((CustomerFactoryImpl)CustomerFactory.INSTANCE).getCustomer();
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public Account getAccount()
+  {
+    return account;
+  }
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public ChangeContext basicSetAccount(Account newAccount, ChangeContext changeContext)
+  {
+    Account oldAccount = account;
+    account = newAccount;
+    boolean oldAccount_set_ = account_set_;
+    account_set_ = true;
+    if (isNotifying())
+    {
+      addNotification(this, ChangeKind.SET, ACCOUNT, oldAccount, newAccount, !oldAccount_set_, changeContext);
+    }
+    return changeContext;
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public void setAccount(Account newAccount)
+  {
+    if (newAccount != account)
+    {
+      ChangeContext changeContext = null;
+      if (account != null)
+        changeContext = inverseRemove(account, this, OPPOSITE_FEATURE_BASE - ACCOUNT, null, changeContext);
+      if (newAccount != null)
+        changeContext = inverseAdd(newAccount, this, OPPOSITE_FEATURE_BASE - ACCOUNT, null, changeContext);
+      changeContext = basicSetAccount(newAccount, changeContext);
+      if (changeContext != null) dispatch(changeContext);
+    }
+    else
+    	{
+      boolean oldAccount_set_ = account_set_;
+      account_set_ = true;
+      if (isNotifying())
+        notify(ChangeKind.SET, ACCOUNT, newAccount, newAccount, !oldAccount_set_);
+    	}
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public ChangeContext basicUnsetAccount(ChangeContext changeContext)
+  {
+    Account oldAccount = account;
+    account = null;
+    boolean oldAccount_set_ = account_set_;
+    account_set_ = false;
+    if (isNotifying())
+    {
+      addNotification(this, ChangeKind.UNSET, ACCOUNT, oldAccount, null, !oldAccount_set_, changeContext);
+    }
+    return changeContext;
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public void unsetAccount()
+  {
+    if (account != null)
+    {
+      ChangeContext changeContext = null;
+      changeContext = inverseRemove(account, this, EOPPOSITE_FEATURE_BASE - ACCOUNT, null, changeContext);
+      changeContext = basicUnsetAccount(changeContext);
+      if (changeContext != null) dispatch(changeContext);
+    }
+    else
+    	{
+      boolean oldAccount_set_ = account_set_;
+      account_set_ = false;
+      if (isNotifying())
+        notify(ChangeKind.UNSET, ACCOUNT, null, null, oldAccount_set_);
+    	}
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public boolean isSetAccount()
+  {
+    return account_set_;
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public String getFirstName()
+  {
+    return firstName;
+  }
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public void setFirstName(String newFirstName)
+  {
+    String oldFirstName = firstName;
+    firstName = newFirstName;
+    boolean oldFirstName_set_ = firstName_set_;
+    firstName_set_ = true;
+    if (isNotifying())
+      notify(ChangeKind.SET, FIRST_NAME, oldFirstName, firstName, !oldFirstName_set_);
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public void unsetFirstName()
+  {
+    String oldFirstName = firstName;
+    boolean oldFirstName_set_ = firstName_set_;
+    firstName = FIRST_NAME_DEFAULT_;
+    firstName_set_ = false;
+    if (isNotifying())
+      notify(ChangeKind.UNSET, FIRST_NAME, oldFirstName, FIRST_NAME_DEFAULT_, oldFirstName_set_);
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public boolean isSetFirstName()
+  {
+    return firstName_set_;
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public ChangeContext inverseRemove(Object otherEnd, int propertyIndex, ChangeContext changeContext)
+  {
+    switch (propertyIndex)
+    {
+      case ACCOUNT:
+        return basicUnsetAccount(changeContext);
+    }
+    return super.inverseRemove(otherEnd, propertyIndex, changeContext);
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public Object get(int propertyIndex, boolean resolve)
+  {
+    switch (propertyIndex)
+    {
+      case ACCOUNT:
+        return getAccount();
+      case FIRST_NAME:
+        return getFirstName();
+    }
+    return super.get(propertyIndex, resolve);
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public void set(int propertyIndex, Object newValue)
+  {
+    switch (propertyIndex)
+    {
+      case ACCOUNT:
+        setAccount((Account)newValue);
+        return;
+      case FIRST_NAME:
+        setFirstName((String)newValue);
+        return;
+    }
+    super.set(propertyIndex, newValue);
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public void unset(int propertyIndex)
+  {
+    switch (propertyIndex)
+    {
+      case ACCOUNT:
+        unsetAccount();
+        return;
+      case FIRST_NAME:
+        unsetFirstName();
+        return;
+    }
+    super.unset(propertyIndex);
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public boolean isSet(int propertyIndex)
+  {
+    switch (propertyIndex)
+    {
+      case ACCOUNT:
+        return isSetAccount();
+      case FIRST_NAME:
+        return isSetFirstName();
+    }
+    return super.isSet(propertyIndex);
+  }
+
+  /**
+   * <!-- begin-user-doc -->
+   * <!-- end-user-doc -->
+   * @generated
+   */
+  public String toString()
+  {
+    if (isProxy(this)) return super.toString();
+
+    StringBuffer result = new StringBuffer(super.toString());
+    result.append(" (firstName: ");
+    if (firstName_set_) result.append(firstName); else result.append("<unset>");
+    result.append(')');
+    return result.toString();
+  }
+
+} //CustomerImpl

Modified: incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java?view=diff&rev=542588&r1=542587&r2=542588
==============================================================================
--- incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java (original)
+++ incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryGenTestCase.java Tue May 29 09:53:20 2007
@@ -1,33 +1,47 @@
 /**
  *
- *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
  *
- *  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
  *
- *     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.
+ *  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.sdo.test;
 
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.List;
 
+import org.apache.tuscany.sdo.api.SDOUtil;
+
 import junit.framework.TestCase;
 
+import com.example.customer.Account;
+import com.example.customer.Customer;
+import com.example.customer.CustomerFactory;
 import com.example.simple.cs.CSFactory;
 import com.example.simple.cs.Quote;
 import com.example.simple.cs.QuoteBase;
 import commonj.sdo.ChangeSummary;
+import commonj.sdo.DataGraph;
 import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.impl.HelperProvider;
 
 
 public class ChangeSummaryGenTestCase extends TestCase {
@@ -68,4 +82,33 @@
         //XMLHelper.INSTANCE.save(dQuote, "http://www.example.com/simpleCS", "quoteBase", System.out);
     }
 
+    public void testChangeSummaryOnDatagraphWithContainmentStatic() throws Exception {
+      
+      HelperContext hc = HelperProvider.getDefaultContext();
+      CustomerFactory.INSTANCE.register(hc);    
+      
+      Type customerType = hc.getTypeHelper().getType(Customer.class);   
+      DataGraph dataGraph = SDOUtil.createDataGraph();
+      Customer customer = (Customer) dataGraph.createRootObject(customerType);
+    
+      Account account = CustomerFactory.INSTANCE.createAccount();
+      customer.setAccount(account);
+      customer.setFirstName("John");
+      customer.getAccount().setAccountNum(1234);
+        
+      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+      SDOUtil.saveDataGraph(dataGraph, outputStream, null);
+      DataGraph loadDataGraph = SDOUtil.loadDataGraph(new ByteArrayInputStream(outputStream.toByteArray()), null);
+      
+      loadDataGraph.getChangeSummary().beginLogging();
+      
+      customer = (Customer) loadDataGraph.getRootObject();
+      customer.getAccount().setAccountNum(987);   
+      
+      loadDataGraph.getChangeSummary().endLogging();
+      
+      List changedDataObjects = loadDataGraph.getChangeSummary().getChangedDataObjects();   
+        assertEquals("in fact 1 Object was changed in the code", 1, changedDataObjects.size());     
+    }
+    
 }

Modified: incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet?view=diff&rev=542588&r1=542587&r2=542588
==============================================================================
--- incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet (original)
+++ incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet Tue May 29 09:53:20 2007
@@ -22,7 +22,7 @@
 %>
 <%GenPackage genPackage = (GenPackage)((Object[])argument)[0]; GenModel genModel=genPackage.getGenModel();%>
 <%boolean isInterface = Boolean.TRUE.equals(((Object[])argument)[1]); boolean isImplementation = Boolean.TRUE.equals(((Object[])argument)[2]);%>
-<%String factoryPatternVersion = "1.1";%>
+<%String factoryPatternVersion = "1.2";%>
 <%String publicStaticFinalFlag = isImplementation ? "public static final " : "";%>
 <%@ include file="../Header.javajetinc"%>
 <%if (isInterface || genModel.isSuppressInterfaces()) {%>
@@ -340,7 +340,7 @@
           <%}%>
           <%for (Iterator j=genClass.getGenFeatures().iterator(); j.hasNext();) {GenFeature genFeature = (GenFeature)j.next();%>
             <%String type = genFeature.getType().equals("commonj.sdo.Sequence") ? "getSequence()" : genPackage.getPackageInstanceVariable(genFeature.getTypeGenPackage()) + ".get" + genFeature.getTypeClassifierAccessorName() + "()";%>
-		property = getProperty(<%=genClass.getSafeUncapName()%>Type, <%=genClass.getClassName()%>.INTERNAL_<%=genFeature.getUpperName()%>);
+		property = getLocalProperty(<%=genClass.getSafeUncapName()%>Type, <%=genClass.getLocalFeatureIndex(genFeature)%>);
             <%if (genFeature.isReferenceType()) { GenFeature reverseGenFeature = genFeature.getReverse();%>
               <%String reverse = reverseGenFeature == null ? "null" : genPackage.getPackageInstanceVariable(reverseGenFeature.getGenPackage()) + ".get" + reverseGenFeature.getFeatureAccessorName() + "()";%>
 		initializeProperty(property, <%=type%>, "<%=genFeature.getName()%>", <%=genFeature.getDefaultValue()%>, <%=genFeature.getLowerBound()%>, <%=genFeature.getUpperBound()%>, <%=genFeature.getContainerClass()%>, <%=genFeature.getChangeableFlag().equals("IS_CHANGEABLE") ? "false" : "true"%>, <%=genFeature.getUnsettableFlag().equals("IS_UNSETTABLE") ? "true": "false"%>, <%=genFeature.getDerivedFlag().equals("IS_DERIVED") ? "true" : "false"%>, <%=genFeature.getContainmentFlag().equals("IS_COMPOSITE")? "true": "false"%> , <%=reverse%>);



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