1 56 package org.opencrx.demo.kernel; 57 58 import java.math.BigDecimal ; 59 import java.util.Collection ; 60 import java.util.Date ; 61 import java.util.Iterator ; 62 63 import javax.jmi.reflect.RefException; 64 import javax.naming.Context ; 65 import javax.naming.InitialContext ; 66 import javax.naming.NamingException ; 67 68 import org.opencrx.kernel.account1.cci.Account; 69 import org.opencrx.kernel.account1.cci.AccountAddress; 70 import org.opencrx.kernel.account1.cci.AccountFilter; 71 import org.opencrx.kernel.address1.cci.EMailAddressable; 72 import org.opencrx.kernel.address1.cci.PhoneNumberAddressable; 73 import org.opencrx.kernel.address1.cci.PostalAddressable; 74 import org.opencrx.kernel.address1.cci.WebAddressable; 75 import org.opencrx.kernel.base.cci.ExportResult; 76 import org.opencrx.kernel.client.ClientHelper; 77 import org.opencrx.kernel.product1.cci.Product; 78 import org.openmdx.base.accessor.generic.cci.ObjectFactory_1_0; 79 import org.openmdx.base.accessor.jmi.cci.JmiServiceException; 80 import org.openmdx.base.accessor.jmi.cci.RefPackage_1_0; 81 import org.openmdx.base.accessor.jmi.spi.RefRootPackage_1; 82 import org.openmdx.base.exception.ServiceException; 83 import org.openmdx.compatibility.base.query.FilterOperators; 84 85 public class SimpleClient { 86 87 public static void main( 89 String [] args 90 ) { 91 try { 92 Context componentEnvironment = (Context )new InitialContext ().lookup("java:comp/env"); 93 94 ObjectFactory_1_0 of = ClientHelper.createObjectFactory( 96 componentEnvironment, 97 "openmdx/data" 98 ); 99 100 RefPackage_1_0 rootPkg = new RefRootPackage_1( 104 of, 105 null, null, "cci", 108 false ); 110 111 ClientHelper.loadModels( 113 componentEnvironment, 114 rootPkg 115 ); 116 117 org.opencrx.kernel.account1.cci.account1Package account1Pkg = 119 (org.opencrx.kernel.account1.cci.account1Package)rootPkg.refPackage( 120 org.opencrx.kernel.account1.cci.account1Package.class.getName() 121 ); 122 org.opencrx.kernel.product1.cci.product1Package product1Pkg = 123 (org.opencrx.kernel.product1.cci.product1Package)rootPkg.refPackage( 124 org.opencrx.kernel.product1.cci.product1Package.class.getName() 125 ); 126 org.opencrx.kernel.contract1.cci.contract1Package contract1Pkg = 127 (org.opencrx.kernel.contract1.cci.contract1Package)rootPkg.refPackage( 128 org.opencrx.kernel.contract1.cci.contract1Package.class.getName() 129 ); 130 131 String providerName = (String )componentEnvironment.lookup("providerName"); 133 String segmentName = (String )componentEnvironment.lookup("segmentName"); 134 135 org.opencrx.kernel.account1.cci.Segment accountSegment = 137 (org.opencrx.kernel.account1.cci.Segment)rootPkg.refObject( 138 "xri:@openmdx:org.opencrx.kernel.account1/provider/" + providerName + "/segment/" + segmentName 139 ); 140 org.opencrx.kernel.product1.cci.Segment productSegment = 142 (org.opencrx.kernel.product1.cci.Segment)rootPkg.refObject( 143 "xri:@openmdx:org.opencrx.kernel.product1/provider/" + providerName + "/segment/" + segmentName 144 ); 145 org.opencrx.kernel.contract1.cci.Segment contractSegment = 147 (org.opencrx.kernel.contract1.cci.Segment)rootPkg.refObject( 148 "xri:@openmdx:org.opencrx.kernel.contract1/provider/" + providerName + "/segment/" + segmentName 149 ); 150 151 String name = (String )componentEnvironment.lookup("name"); 153 Boolean xmlExport = (Boolean )componentEnvironment.lookup("xmlExport"); 154 155 System.out.println("openCRX SimpleClient: Find accounts with name LIKE " + name); 157 158 AccountFilter filter = account1Pkg.createAccountFilter(); 160 filter.thereExistsFullName( 161 FilterOperators.IS_LIKE, 162 new String []{name + "%"} 163 ); 164 Collection accounts = accountSegment.getAccount(filter); 165 166 for( 168 Iterator i = accounts.iterator(); 169 i.hasNext(); 170 ) { 171 Account account = (Account)i.next(); 172 System.out.println(); 174 System.out.println("account=" + account.refMofId()); 175 System.out.println(" full name=" + account.getFullName()); 176 if(xmlExport.booleanValue()) { 177 ExportResult result = account.exportXml("", ""); 178 System.out.println(" xml export size=" + result.getItem().length + "; mimeType=" + result.getItemMimeType()); 179 } 180 181 Collection addresses = account.getAddress(); 183 for( 184 Iterator j = addresses.iterator(); 185 j.hasNext(); 186 ) { 187 AccountAddress address = (AccountAddress)j.next(); 188 System.out.println(" address=" + address.refMofId()); 189 if(address instanceof PostalAddressable) { 190 PostalAddressable postal = (PostalAddressable)address; 191 System.out.println(" address lines=" + postal.getPostalAddressLine() + "; " + postal.getPostalStreet() + "; " + postal.getPostalCode() + "; " + postal.getPostalCity()); 192 } 193 else if(address instanceof EMailAddressable) { 194 System.out.println(" email=" + ((EMailAddressable)address).getEmailAddress()); 195 } 196 else if(address instanceof WebAddressable) { 197 System.out.println(" web url=" + ((WebAddressable)address).getWebUrl()); 198 } 199 else if(address instanceof PhoneNumberAddressable) { 200 System.out.println(" phone number=" + ((PhoneNumberAddressable)address).getPhoneLocalNumber()); 201 } 202 } 203 } 204 205 Account customer = (Account)accountSegment.getAccount().iterator().next(); 207 Product product = (Product)productSegment.getProduct().iterator().next(); 209 210 org.opencrx.kernel.contract1.cci.Invoice invoice = contract1Pkg.getInvoiceClass().createInvoice(); 212 invoice.setName("Invoice created by SimpleClient"); 213 invoice.setCustomer(customer); 214 contract1Pkg.refBegin(); 215 contractSegment.addInvoice(invoice); 216 contract1Pkg.refCommit(); 217 System.out.println("Invoice 'Invoice created by SimpleClient'.refMofId()=" + invoice.refMofId()); 218 219 BigDecimal quantity = new BigDecimal (11.5); 221 org.opencrx.kernel.contract1.cci.CreatePositionParams params = contract1Pkg.createCreatePositionParams( 222 "position name", 223 null, 224 null, 225 null, 226 product, 227 quantity, 228 null 229 ); 230 contract1Pkg.refBegin(); 231 org.opencrx.kernel.contract1.cci.CreatePositionResult result = invoice.createPosition(params); 232 contract1Pkg.refCommit(); 233 System.out.println("position=" + result.getPosition().refMofId()); 234 235 org.opencrx.kernel.contract1.cci.InvoicePosition invoicePosition = 237 (org.opencrx.kernel.contract1.cci.InvoicePosition)rootPkg.refObject(result.getPosition().refMofId()); 238 org.opencrx.kernel.contract1.cci.DeliveryInformation deliveryInformation = 239 contract1Pkg.getDeliveryInformationClass().createDeliveryInformation(); 240 deliveryInformation.setActualDeliveryOn(new Date ()); 241 deliveryInformation.setQuantityShipped(new BigDecimal (5.0)); 242 contract1Pkg.refBegin(); 243 invoicePosition.addDeliveryInformation(deliveryInformation); 244 contract1Pkg.refCommit(); 245 246 } 247 catch (NamingException e) { 248 e.printStackTrace(); 249 } 250 catch (ServiceException e) { 251 e.printStackTrace(); 252 } 253 catch (JmiServiceException e) { 254 e.printStackTrace(); 255 } 256 catch (RefException e) { 257 e.printStackTrace(); 258 } 259 } 260 261 } 262 263 | Popular Tags |