1 56 package org.opencrx.demo.kernel; 57 58 import java.util.Collection ; 59 import java.util.Iterator ; 60 61 import javax.naming.Context ; 62 import javax.naming.InitialContext ; 63 import javax.naming.NamingException ; 64 65 import org.opencrx.kernel.client.ClientHelper; 66 import org.opencrx.kernel.code1.cci.CodeValueContainer; 67 import org.opencrx.kernel.code1.cci.CodeValueContainerFilter; 68 import org.opencrx.kernel.code1.cci.CodeValueEntry; 69 import org.openmdx.base.accessor.generic.cci.ObjectFactory_1_0; 70 import org.openmdx.base.accessor.jmi.cci.JmiServiceException; 71 import org.openmdx.base.accessor.jmi.cci.RefPackage_1_0; 72 import org.openmdx.base.accessor.jmi.spi.RefRootPackage_1; 73 import org.openmdx.base.exception.ServiceException; 74 import org.openmdx.compatibility.base.naming.Path; 75 import org.openmdx.compatibility.base.query.FilterOperators; 76 77 public class CodeClient { 78 79 public static void main( 81 String [] args 82 ) { 83 try { 84 Context componentEnvironment = (Context )new InitialContext ().lookup("java:comp/env"); 85 86 ObjectFactory_1_0 of = ClientHelper.createObjectFactory( 88 componentEnvironment, 89 "openmdx/data" 90 ); 91 92 RefPackage_1_0 rootPkg = new RefRootPackage_1( 96 of, 97 null, null, "cci", 100 false ); 102 103 ClientHelper.loadModels( 105 componentEnvironment, 106 rootPkg 107 ); 108 109 org.opencrx.kernel.code1.cci.code1Package code1Pkg = 111 (org.opencrx.kernel.code1.cci.code1Package)rootPkg.refPackage( 112 org.opencrx.kernel.code1.cci.code1Package.class.getName() 113 ); 114 115 String providerName = (String )componentEnvironment.lookup("providerName"); 117 118 org.opencrx.kernel.code1.cci.Segment codeSegment = 120 (org.opencrx.kernel.code1.cci.Segment)rootPkg.refObject( 121 "xri:@openmdx:org.opencrx.kernel.code1/provider/" + providerName + "/segment/Root" 122 ); 123 124 String name = (String )componentEnvironment.lookup("name"); 126 127 System.out.println("openCRX CodeAccessor: Find codes of field " + name); 129 130 CodeValueContainerFilter filter = code1Pkg.createCodeValueContainerFilter(); 132 filter.thereExistsName( 133 FilterOperators.IS_IN, 134 new String []{name} 135 ); 136 Collection codeValueContainers = codeSegment.getValueContainer(filter); 137 if(codeValueContainers.size() == 0) { 138 System.out.println("no code value container found matching name " + name); 139 } 140 else { 141 for( 142 Iterator i = codeValueContainers.iterator(); 143 i.hasNext(); 144 ) { 145 CodeValueContainer codeValueContainer = (CodeValueContainer)i.next(); 146 System.out.println("code value container=" + codeValueContainer.getName()); 147 for( 148 Iterator j = codeValueContainer.getEntry().iterator(); 149 j.hasNext(); 150 ) { 151 CodeValueEntry entry = (CodeValueEntry)j.next(); 152 System.out.println("code=" + new Path(entry.refMofId()).getBase()); 153 System.out.println(" shortText"); 155 int kk = 0; 156 for( 157 Iterator k = entry.getShortText().iterator(); 158 k.hasNext(); 159 kk++ 160 ) { 161 System.out.println(" shortText[" + kk + "]=" + k.next()); 162 } 163 System.out.println(" longText"); 165 kk = 0; 166 for( 167 Iterator k = entry.getLongText().iterator(); 168 k.hasNext(); 169 kk++ 170 ) { 171 System.out.println(" longText[" + kk + "]=" + k.next()); 172 } 173 } 174 } 175 } 176 } 177 catch (NamingException e) { 178 e.printStackTrace(); 179 } 180 catch (ServiceException e) { 181 e.printStackTrace(); 182 } 183 catch (JmiServiceException e) { 184 e.printStackTrace(); 185 } 186 } 187 188 } 189 190 | Popular Tags |