public Value aref(final int index, final Interpreter interpreter) { RecordType type = (RecordType) this.type; int size = type.fieldCount(); if (index < 0 || index >= size) { throw interpreter.runtimeException("Internal error: field index out of bounds"); } Value[] array = (Value[]) this.content; return array[index]; }
public boolean putObservation(Observation observation) { int ncStatus = 0; NativeLongByReference record_startp = new NativeLongByReference(new NativeLong(record_index)); NativeLongByReference record_countp = new NativeLongByReference(new NativeLong(1)); boolean observationPutSuccessful = false; if (!isClosed && record.isObservationValid(observation)) { ByteBuffer recordBuffer = ByteBuffer.allocateDirect(record.getCompoundSize()); recordBuffer.order(ByteOrder.nativeOrder()); recordBuffer.putInt(observation.station_index); recordBuffer.putInt(observation.time_offset); for (Object value : observation.values) { if (value instanceof String) { throw new UnsupportedOperationException("Need to implement char[] or string"); // String val = (String) value; // ncStatus = nc_put_att_text(ncId, ncVarId, key, val); // status(ncStatus); } else if (value instanceof Integer) { int val = ((Integer) value).intValue(); recordBuffer.putInt(val); } else if (value instanceof Short) { short val = ((Short) value).shortValue(); recordBuffer.putShort(val); } else if (value instanceof Float) { float val = ((Float) value).floatValue(); recordBuffer.putFloat(val); } else if (value instanceof Double) { double val = ((Double) value).doubleValue(); recordBuffer.putDouble(val); } else { throw new UnsupportedOperationException("Should implement the other types"); } } // record complete recordBuffer.rewind(); ncStatus = nc_put_vara(ncId, record.getVarId(), record_startp, record_countp, recordBuffer); status(ncStatus); record_index++; // station_indexp.setValue(station_indexp.longValue() + 1); return true; } return observationPutSuccessful; }
public RecordValue(final RecordType type) { super(type); Type[] DataTypes = type.getFieldTypes(); int size = DataTypes.length; Value[] content = new Value[size]; for (int i = 0; i < size; ++i) { content[i] = DataTypes[i].initialValue(); } this.content = content; }
public void aset(final int index, final Value val, final Interpreter interpreter) { RecordType type = (RecordType) this.type; int size = type.fieldCount(); if (index < 0 || index >= size) { throw interpreter.runtimeException("Internal error: field index out of bounds"); } Value[] array = (Value[]) this.content; if (array[index].getType().equals(val.getType())) { array[index] = val; } else if (array[index].getType().equals(DataTypes.TYPE_STRING)) { array[index] = val.toStringValue(); } else if (array[index].getType().equals(DataTypes.TYPE_INT) && val.getType().equals(DataTypes.TYPE_FLOAT)) { array[index] = val.toIntValue(); } else if (array[index].getType().equals(DataTypes.TYPE_FLOAT) && val.getType().equals(DataTypes.TYPE_INT)) { array[index] = val.toFloatValue(); } else { throw interpreter.runtimeException( "Internal error: Cannot assign " + val.getType() + " to " + array[index].getType()); } }
private void readRecordTypes() throws MojoExecutionException { if (debug) { getLog().info("generating debug code"); } typeMap = new HashMap<String, RecordType>(); for (int i = 0; i < inputFiles.length; ++i) { try { getLog().info("reading " + inputFiles[i].toString()); Reader read = new FileReader(inputFiles[i]); RecordType type = RecordType.read(read); // always add allocId to enable tracking of allocations type.addField("alloc id", RecordType.Type.SHORT, null); type.addToMap(typeMap); } catch (FileNotFoundException fnfe) { throw new MojoExecutionException( "cound not find type description file " + inputFiles[i], fnfe); } catch (JSONException jse) { throw new MojoExecutionException( "cound not parse type description file " + inputFiles[i], jse); } } }
static byte[] createHeader( RecordType type, EncryptionType encryptionType, int lastLength, int currentLength, int currentSequenceNumber) { byte[] header = new byte[IoUtils.HEADER_LENGTH]; header[0] = (byte) 0xf0; header[1] = (byte) 0xf0; header[2] = (byte) 0xf0; header[3] = (byte) 0xf0; appendInt4Bytes(header, 4, currentSequenceNumber); header[8] = type.getByteValue(); header[9] = encryptionType.getByteValue(); appendLong8Bytes(header, 10, System.currentTimeMillis()); appendInt4Bytes(header, 18, lastLength); appendInt4Bytes(header, 22, currentLength); return header; }
/** * Import the file. * * @param importFile the file to import. * @param controller the controller to use. * @param progressPanel - the progress panel to display heartbeat messages * @return if we succeded */ public boolean importFile( File importFile, DomainImportController controller, InfiniteProgressPanel progressPanel) throws ImportException { Collection<DomainObject> collection = new ArrayList<DomainObject>(); if (importFile != null) { JAXBContext context; try { LookupListUtils.initIngestReport(); context = JAXBContext.newInstance("org.archiviststoolkit.structure.accessionImport"); AccessionRecords accessionRecords = (AccessionRecords) context.createUnmarshaller().unmarshal(importFile); Accessions accession; int recordCount = 1; progressPanel.setTextLine("Importing...", 1); PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(RecordType.class); for (RecordType record : accessionRecords.getRecord()) { // check to see if the process was cancelled at this point if so just return if (progressPanel.isProcessCancelled()) { return false; } progressPanel.setTextLine("Processing record " + recordCount, 2); accession = new Accessions(); accession.setRepository(repository); for (PropertyDescriptor descriptor : descriptors) { Class propertyType = descriptor.getPropertyType(); if (propertyType == XMLGregorianCalendar.class) { ImportUtils.nullSafeDateSet( accession, descriptor.getName(), (XMLGregorianCalendar) descriptor.getReadMethod().invoke(record)); } else if (propertyType == String.class || propertyType == BigInteger.class || propertyType == BigDecimal.class) { ImportUtils.nullSafeSet( accession, descriptor.getName(), descriptor.getReadMethod().invoke(record)); } else if (propertyType == Boolean.class) { // this hack is needed because jaxb has a bug and the read method starts // with "is" instead of "get" String writeMethodName = descriptor.getWriteMethod().getName(); String readMethodName = writeMethodName.replaceFirst("set", "is"); Method readMethod = RecordType.class.getMethod(readMethodName); ImportUtils.nullSafeSet(accession, descriptor.getName(), readMethod.invoke(record)); } } parseAccessionNumber(accession, record.getAccessionNumber()); addSubjects(accession, record.getSubjectLink()); addNames(accession, record.getNameLink()); addResource( accession, record.getResourceIdentifier(), controller, accession.getAccessionNumber(), recordCount); collection.add(accession); recordCount++; } controller.domainImport(collection, ApplicationFrame.getInstance(), progressPanel); ImportExportLogDialog dialog = new ImportExportLogDialog( controller.constructFinalImportLogText() + "\n\n" + LookupListUtils.getIngestReport(), ImportExportLogDialog.DIALOG_TYPE_IMPORT); progressPanel.close(); dialog.showDialog(); } catch (JAXBException e) { progressPanel.close(); new ErrorDialog( ApplicationFrame.getInstance(), "There is a problem importing accessions.", e) .showDialog(); } catch (IllegalAccessException e) { progressPanel.close(); new ErrorDialog("", e).showDialog(); } catch (InvocationTargetException e) { progressPanel.close(); new ErrorDialog("", e).showDialog(); } catch (UnknownLookupListException e) { progressPanel.close(); new ErrorDialog("", e).showDialog(); } catch (ValidationException e) { progressPanel.close(); new ErrorDialog("", e).showDialog(); } catch (PersistenceException e) { progressPanel.close(); new ErrorDialog("", e).showDialog(); } catch (DuplicateLinkException e) { progressPanel.close(); new ErrorDialog("", e).showDialog(); } catch (NoSuchMethodException e) { progressPanel.close(); new ErrorDialog("", e).showDialog(); } catch (NoSuchAlgorithmException e) { new ErrorDialog("", e).showDialog(); } catch (UnsupportedEncodingException e) { new ErrorDialog("", e).showDialog(); } } return (true); }