private void addRowButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addRowButtonActionPerformed Object[] row; if (type.equals(PropertyType.authors) || type.equals(PropertyType.contributors)) { row = new Object[] {"", "", ""}; } else { // ontologies row = new Object[] {"", ""}; } ((DefaultTableModel) tableProperties.getModel()).addRow(row); } // GEN-LAST:event_addRowButtonActionPerformed
private static Map<String, PropertyMethod> parsePropertyAnnotations(Class<?> concreteClass) throws InstanceWrapperException { Map<String, PropertyMethod> map = new HashMap<>(); for (Method method : concreteClass.getDeclaredMethods()) { Property annotation = method.getAnnotation(Property.class); if (annotation == null) { continue; } if (!method.getReturnType().equals(Void.TYPE)) { throw new InstanceWrapperException("Property method '" + method + "' should return void."); } Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1) { throw new InstanceWrapperException( "Property method '" + method + "' must accept exactly one parameter."); } String uri = annotation.uri(); if (map.containsKey(uri)) { throw new InstanceWrapperException( "Two property methods have the same URI value: " + map.get(uri).getMethod() + ", and " + method); } try { map.put(uri, PropertyType.createPropertyMethod(method)); } catch (PropertyTypeException e) { throw new InstanceWrapperException("Failed to create the PropertyMethod", e); } } return map; }
public static boolean encode( int keyId, Object array, PropertyBlock target, int payloadSizeInBytes) { /* * If the array is huge, we don't have to check anything else. * So do the length check first. */ int arrayLength = Array.getLength(array); if (arrayLength > 63) /*because we only use 6 bits for length*/ { return false; } ShortArray type = typeOf(array); if (type == null) { return false; } int requiredBits = type.calculateRequiredBitsForArray(array, arrayLength); if (!willFit(requiredBits, arrayLength, payloadSizeInBytes)) { // Too big array return false; } final int numberOfBytes = calculateNumberOfBlocksUsed(arrayLength, requiredBits) * 8; if (Bits.requiredLongs(numberOfBytes) > PropertyType.getPayloadSizeLongs()) { return false; } Bits result = Bits.bits(numberOfBytes); // [][][ ,bbbb][bbll,llll][yyyy,tttt][kkkk,kkkk][kkkk,kkkk][kkkk,kkkk] writeHeader(keyId, type, arrayLength, requiredBits, result); type.writeAll(array, arrayLength, requiredBits, result); target.setValueBlocks(result.getLongs()); return true; }
/* * It is assumed that the argument does hold a property block - all zeros is * a valid (not in use) block, so even if the Bits object has been exhausted a * result is returned, that has inUse() return false. Also, the argument is not * touched. */ private PropertyBlock getPropertyBlock(Buffer buffer) { long header = buffer.getLong(); PropertyType type = PropertyType.getPropertyType(header, true); if (type == null) { return null; } PropertyBlock toReturn = new PropertyBlock(); // toReturn.setInUse( true ); int numBlocks = type.calculateNumberOfBlocksUsed(header); long[] blockData = new long[numBlocks]; blockData[0] = header; // we already have that for (int i = 1; i < numBlocks; i++) { blockData[i] = buffer.getLong(); } toReturn.setValueBlocks(blockData); return toReturn; }
/** * Adds a property to the building object. * * @param name the property name * @param value the property value (nullable) * @return this object (for method chain) * @throws IllegalArgumentException if the property is not defined (on {@code check = true}), or * the property value has inconsistent type, or some parameters were {@code null} * @throws IllegalStateException the property has been already added */ public Builder<T> add(PropertyName name, Object value) { if (name == null) { throw new IllegalArgumentException("name must not be null"); // $NON-NLS-1$ } if (properties.containsKey(name)) { throw new IllegalStateException( MessageFormat.format("The property \"{0}\" was already set in {1}", name, definition)); } PropertyType type = definition.getType(name); if (type != null && value != null && type.getRepresentation().isInstance(value) == false) { throw new IllegalArgumentException( MessageFormat.format( "The property \"{0}\" must be type of {1}, but was {2} ({3})", name, type, value, definition)); } properties.put(name, value); return this; }
private void updateRecord(PropertyRecord record, PersistenceWindow window) { long id = record.getId(); registerIdFromUpdateRecord(id); Buffer buffer = window.getOffsettedBuffer(id); if (record.inUse()) { // Set up the record header short prevModifier = record.getPrevProp() == Record.NO_NEXT_RELATIONSHIP.intValue() ? 0 : (short) ((record.getPrevProp() & 0xF00000000L) >> 28); short nextModifier = record.getNextProp() == Record.NO_NEXT_RELATIONSHIP.intValue() ? 0 : (short) ((record.getNextProp() & 0xF00000000L) >> 32); byte modifiers = (byte) (prevModifier | nextModifier); /* * [pppp,nnnn] previous, next high bits */ buffer.put(modifiers); buffer.putInt((int) record.getPrevProp()).putInt((int) record.getNextProp()); // Then go through the blocks int longsAppended = 0; // For marking the end of blocks for (PropertyBlock block : record.getPropertyBlocks()) { long[] propBlockValues = block.getValueBlocks(); for (long propBlockValue : propBlockValues) { buffer.putLong(propBlockValue); } longsAppended += propBlockValues.length; /* * For each block we need to update its dynamic record chain if * it is just created. Deleted dynamic records are in the property * record and dynamic records are never modified. Also, they are * assigned as a whole, so just checking the first should be enough. */ if (!block.isLight() && block.getValueRecords().get(0).isCreated()) { updateDynamicRecords(block.getValueRecords()); } } if (longsAppended < PropertyType.getPayloadSizeLongs()) { buffer.putLong(0); } } else { if (!isInRecoveryMode()) { freeId(id); } // skip over the record header, nothing useful there buffer.setOffset(buffer.getOffset() + 9); buffer.putLong(0); } updateDynamicRecords(record.getDeletedRecords()); }
private void addFedoraObjectProperties(DigitalObjectDocument.DigitalObject dobj) { ObjectPropertiesType pt = dobj.addNewObjectProperties(); { PropertyType p = pt.addNewProperty(); p.setNAME(PropertyType.NAME.INFO_FEDORA_FEDORA_SYSTEM_DEF_MODEL_STATE); p.setVALUE(state); } { PropertyType p = pt.addNewProperty(); p.setNAME(PropertyType.NAME.INFO_FEDORA_FEDORA_SYSTEM_DEF_MODEL_LABEL); p.setVALUE(label); } { PropertyType p = pt.addNewProperty(); p.setNAME(PropertyType.NAME.INFO_FEDORA_FEDORA_SYSTEM_DEF_MODEL_OWNER_ID); p.setVALUE(ownerId); } }
@Override void addWidgets() { widget("EntityTypeList", EntityTypeSet, new PortRest("entity_type_item", EntityType.name())); widget("EntityTypeItem", EntityType, new PortRest("entity_type_page", EntityType.name())); widget( "ListingTable", EntityType, new PortRest("table_head", PropertyType.name()), new PortRest("table_line", Entity.name())); widget("TableHead", PropertyType); widget("TableLine", Entity, new PortRest("line_cell", Property.name())); widget("TableCell", Property); }
public void addPropertyBlock(PropertyBlock block) { assert size() + block.getSize() <= PropertyType.getPayloadSize() : ("Exceeded capacity of property record " + this + ". My current size is reported as " + size() + "The added block was " + block + " (note that size is " + block.getSize() + ")"); blockRecords.add(block); }
public static Pair<byte[] /*header in the first record*/, byte[] /*all other bytes*/> readFullByteArray( long startRecord, Iterable<DynamicRecord> records, AbstractDynamicStore store, PropertyType propertyType) { long recordToFind = startRecord; Map<Long, DynamicRecord> recordsMap = new HashMap<Long, DynamicRecord>(); for (DynamicRecord record : records) { recordsMap.put(record.getId(), record); } byte[] header = null; List<byte[]> byteList = new LinkedList<byte[]>(); int totalSize = 0; while (recordToFind != Record.NO_NEXT_BLOCK.intValue()) { DynamicRecord record = recordsMap.get(recordToFind); if (record.isLight()) { store.makeHeavy(record); } int offset = 0; if (recordToFind == startRecord) { // This is the first one, read out the header separately header = propertyType.readDynamicRecordHeader(record.getData()); offset = header.length; } byteList.add(record.getData()); totalSize += (record.getData().length - offset); recordToFind = record.getNextBlock(); } byte[] bArray = new byte[totalSize]; int sourceOffset = header.length; int offset = 0; for (byte[] currentArray : byteList) { System.arraycopy( currentArray, sourceOffset, bArray, offset, currentArray.length - sourceOffset); offset += (currentArray.length - sourceOffset); sourceOffset = 0; } return Pair.of(header, bArray); }
@Override public String toString() { return super.toString() + "[blocksPerRecord:" + PropertyType.getPayloadSizeLongs() + "]"; }
private void setSingleBlockValue( PropertyBlock block, int keyId, PropertyType type, long longValue) { block.setSingleBlock(keyId | (((long) type.intValue()) << 24) | (longValue << 28)); }
public void encodeValue(PropertyBlock block, int keyId, Object value) { if (value instanceof String) { // Try short string first, i.e. inlined in the property block String string = (String) value; if (LongerShortString.encode(keyId, string, block, PropertyType.getPayloadSize())) return; // Fall back to dynamic string store long stringBlockId = nextStringBlockId(); setSingleBlockValue(block, keyId, PropertyType.STRING, stringBlockId); byte[] encodedString = encodeString(string); Collection<DynamicRecord> valueRecords = allocateStringRecords(stringBlockId, encodedString); for (DynamicRecord valueRecord : valueRecords) { valueRecord.setType(PropertyType.STRING.intValue()); block.addValueRecord(valueRecord); } } else if (value instanceof Integer) setSingleBlockValue(block, keyId, PropertyType.INT, ((Integer) value).longValue()); else if (value instanceof Boolean) setSingleBlockValue( block, keyId, PropertyType.BOOL, (((Boolean) value).booleanValue() ? 1L : 0L)); else if (value instanceof Float) setSingleBlockValue( block, keyId, PropertyType.FLOAT, Float.floatToRawIntBits(((Float) value).floatValue())); else if (value instanceof Long) { long keyAndType = keyId | (((long) PropertyType.LONG.intValue()) << 24); if (ShortArray.LONG.getRequiredBits((Long) value) <= 35) { // We only need one block for this value, special layout compared to, say, an // integer block.setSingleBlock(keyAndType | (1L << 28) | (((Long) value).longValue() << 29)); } else { // We need two blocks for this value block.setValueBlocks(new long[] {keyAndType, ((Long) value).longValue()}); } } else if (value instanceof Double) block.setValueBlocks( new long[] { keyId | (((long) PropertyType.DOUBLE.intValue()) << 24), Double.doubleToRawLongBits(((Double) value).doubleValue()) }); else if (value instanceof Byte) setSingleBlockValue(block, keyId, PropertyType.BYTE, ((Byte) value).longValue()); else if (value instanceof Character) setSingleBlockValue(block, keyId, PropertyType.CHAR, ((Character) value).charValue()); else if (value instanceof Short) setSingleBlockValue(block, keyId, PropertyType.SHORT, ((Short) value).longValue()); else if (value .getClass() .isArray()) { // Try short array first, i.e. inlined in the property block if (ShortArray.encode(keyId, value, block, PropertyType.getPayloadSize())) return; // Fall back to dynamic array store long arrayBlockId = nextArrayBlockId(); setSingleBlockValue(block, keyId, PropertyType.ARRAY, arrayBlockId); Collection<DynamicRecord> arrayRecords = allocateArrayRecords(arrayBlockId, value); for (DynamicRecord valueRecord : arrayRecords) { valueRecord.setType(PropertyType.ARRAY.intValue()); block.addValueRecord(valueRecord); } } else { throw new IllegalArgumentException( "Unknown property type on: " + value + ", " + value.getClass()); } }
private void assertArrayHeader(byte[] header, PropertyType type, int bitsPerItem) { assertEquals(type.byteValue(), header[0]); assertEquals(bitsPerItem, header[2]); }
private void firePropertyChange(PropertyType type, Object oldValue, Object newValue) { this.listeners.firePropertyChange(type.toString(), oldValue, newValue); }
/** * modelClassのPropertyTypeリストを取得する. PKになるkeyプロパティは必ず戻り値のリストの先頭に格納され返却されます。 * * @param modelClass slim3のモデルクラス * @return PropertyTypeリスト(先頭はプライマリキー) */ @SuppressWarnings("unchecked") public static List<PropertyType> getPropertyTypes(Class<?> modelClass) { if (modelClass == null) return null; checkSlim3Model(modelClass); // プロパティのソート順を担保するMapを生成 Map<String, PropertyType> sortedPropertyType = new LinkedHashMap<String, PropertyType>(); String pkName = null; String versionName = null; Set<String> lobNames = new HashSet<String>(); Map<String, Class> elementClassMap = new HashMap<String, Class>(); LinkedHashSet<Field> fields = getFields(modelClass); for (Field f : fields) { sortedPropertyType.put(f.getName(), null); putGenericType(f, elementClassMap); Attribute attr = f.getAnnotation(Attribute.class); if (attr == null) continue; else if (attr.primaryKey()) pkName = f.getName(); else if (attr.version()) versionName = f.getName(); else if (attr.lob()) lobNames.add(f.getName()); } BeanDesc desc = BeanUtil.getBeanDesc(modelClass); int size = desc.getPropertyDescSize(); for (int i = 0; i < size; i++) { PropertyDesc prop = desc.getPropertyDesc(i); if (prop.isReadable() && prop.isWritable()) { PropertyType pt = new PropertyType(prop.getPropertyClass(), prop.getName()); // このパラメータのメタ情報を追加 pt.setPrimaryKey(pt.getName().equals(pkName)); pt.setVersion(pt.getName().equals(versionName)); pt.setLob(lobNames.contains(pt.getName())); pt.setGenericType(elementClassMap.get(pt.getName())); // 予めソートされたMapにValueを設定 sortedPropertyType.put(pt.getName(), pt); } else if (prop.isReadable() && (ModelRef.class.isAssignableFrom(prop.getPropertyClass()) || InverseModelRef.class.isAssignableFrom(prop.getPropertyClass()) || InverseModelListRef.class.isAssignableFrom(prop.getPropertyClass()))) { PropertyType pt = new PropertyType(prop.getPropertyClass(), prop.getName()); // このパラメータのメタ情報を追加 pt.setPrimaryKey(false); pt.setVersion(false); pt.setLob(false); pt.setGenericType(elementClassMap.get(pt.getName())); // 予めソートされたMapにValueを設定 sortedPropertyType.put(pt.getName(), pt); } } List<PropertyType> lstResult = new ArrayList<PropertyType>(); for (PropertyType pt : sortedPropertyType.values()) { if (pt == null) { continue; } // プライマリキーは常に先頭へ if (pt.isPrimaryKey()) { lstResult.add(0, pt); } else { lstResult.add(pt); } } return lstResult; }
private RulesPostImportContainer mapRulesToRulesPostImportContainer( org.openclinica.ns.rules.v31.Rules rules) { RulesPostImportContainer rpic = new RulesPostImportContainer(); for (RuleAssignmentType rat : rules.getRuleAssignment()) { TargetType targetType = rat.getTarget(); ExpressionBean targetBean = new ExpressionBean(Context.OC_RULES_V1, targetType.getValue()); RunOnScheduleType scheduleType = rules.getRuleAssignment().get(0).getRunOnSchedule(); RuleSetBean ruleSetBean = new RuleSetBean(); ruleSetBean.setOriginalTarget(targetBean); if (scheduleType != null) { if (!scheduleType.getTime().equals("")) { ruleSetBean.setRunTime(scheduleType.getTime()); } } for (RuleRefType rrt : rat.getRuleRef()) { RuleSetRuleBean ruleSetRuleBean = new RuleSetRuleBean(); ruleSetRuleBean.setOid(rrt.getOID()); for (DiscrepancyNoteActionType discrepancyNoteActionType : rrt.getDiscrepancyNoteAction()) { DiscrepancyNoteActionBean action = new DiscrepancyNoteActionBean(); action.setMessage(discrepancyNoteActionType.getMessage()); action.setExpressionEvaluatesTo( Boolean.valueOf(discrepancyNoteActionType.getIfExpressionEvaluates())); action .getRuleActionRun() .setInitialDataEntry(discrepancyNoteActionType.getRun().isInitialDataEntry()); action .getRuleActionRun() .setDoubleDataEntry(discrepancyNoteActionType.getRun().isDoubleDataEntry()); action .getRuleActionRun() .setAdministrativeDataEntry( discrepancyNoteActionType.getRun().isAdministrativeDataEntry()); action .getRuleActionRun() .setImportDataEntry(discrepancyNoteActionType.getRun().isImportDataEntry()); action.getRuleActionRun().setBatch(discrepancyNoteActionType.getRun().isBatch()); ruleSetRuleBean.addAction(action); } for (EmailActionType emailActionType : rrt.getEmailAction()) { EmailActionBean action = new EmailActionBean(); action.setMessage(emailActionType.getMessage()); action.setTo(emailActionType.getTo()); action.setExpressionEvaluatesTo( Boolean.valueOf(emailActionType.getIfExpressionEvaluates())); action .getRuleActionRun() .setInitialDataEntry(emailActionType.getRun().isInitialDataEntry()); action .getRuleActionRun() .setDoubleDataEntry(emailActionType.getRun().isDoubleDataEntry()); action .getRuleActionRun() .setAdministrativeDataEntry(emailActionType.getRun().isAdministrativeDataEntry()); action .getRuleActionRun() .setImportDataEntry(emailActionType.getRun().isImportDataEntry()); action.getRuleActionRun().setBatch(emailActionType.getRun().isBatch()); ruleSetRuleBean.addAction(action); } for (ShowActionType showActionType : rrt.getShowAction()) { ShowActionBean action = new ShowActionBean(); action.setMessage(showActionType.getMessage()); action.setExpressionEvaluatesTo( Boolean.valueOf(showActionType.getIfExpressionEvaluates())); action .getRuleActionRun() .setInitialDataEntry(showActionType.getRun().isInitialDataEntry()); action.getRuleActionRun().setDoubleDataEntry(showActionType.getRun().isDoubleDataEntry()); action .getRuleActionRun() .setAdministrativeDataEntry(showActionType.getRun().isAdministrativeDataEntry()); action.getRuleActionRun().setImportDataEntry(showActionType.getRun().isImportDataEntry()); action.getRuleActionRun().setBatch(showActionType.getRun().isBatch()); for (PropertyType propertyType : showActionType.getDestinationProperty()) { PropertyBean property = new PropertyBean(); property.setOid(propertyType.getOID()); action.addProperty(property); } ruleSetRuleBean.addAction(action); } for (HideActionType hideActionType : rrt.getHideAction()) { HideActionBean action = new HideActionBean(); action.setMessage(hideActionType.getMessage()); action.setExpressionEvaluatesTo( Boolean.valueOf(hideActionType.getIfExpressionEvaluates())); action .getRuleActionRun() .setInitialDataEntry(hideActionType.getRun().isInitialDataEntry()); action.getRuleActionRun().setDoubleDataEntry(hideActionType.getRun().isDoubleDataEntry()); action .getRuleActionRun() .setAdministrativeDataEntry(hideActionType.getRun().isAdministrativeDataEntry()); action.getRuleActionRun().setImportDataEntry(hideActionType.getRun().isImportDataEntry()); action.getRuleActionRun().setBatch(hideActionType.getRun().isBatch()); for (PropertyType propertyType : hideActionType.getDestinationProperty()) { PropertyBean property = new PropertyBean(); property.setOid(propertyType.getOID()); action.addProperty(property); } ruleSetRuleBean.addAction(action); } for (InsertActionType insertActionType : rrt.getInsertAction()) { InsertActionBean action = new InsertActionBean(); action.setExpressionEvaluatesTo( Boolean.valueOf(insertActionType.getIfExpressionEvaluates())); action .getRuleActionRun() .setInitialDataEntry(insertActionType.getRun().isInitialDataEntry()); action .getRuleActionRun() .setDoubleDataEntry(insertActionType.getRun().isDoubleDataEntry()); action .getRuleActionRun() .setAdministrativeDataEntry(insertActionType.getRun().isAdministrativeDataEntry()); action .getRuleActionRun() .setImportDataEntry(insertActionType.getRun().isImportDataEntry()); action.getRuleActionRun().setBatch(insertActionType.getRun().isBatch()); ruleSetRuleBean.addAction(action); for (PropertyType propertyType : insertActionType.getDestinationProperty()) { PropertyBean property = new PropertyBean(); property.setOid(propertyType.getOID()); property.setValue(propertyType.getValue()); ExpressionBean expressionBean = new ExpressionBean( Context.OC_RULES_V1, propertyType.getValueExpression().getValue()); property.setValueExpression(expressionBean); action.addProperty(property); } ruleSetRuleBean.addAction(action); } for (EventActionType eventActionType : rrt.getEventAction()) { EventActionBean action = new EventActionBean(); action.setExpressionEvaluatesTo( Boolean.valueOf(eventActionType.getIfExpressionEvaluates())); action.setOc_oid_reference(eventActionType.getOID()); action .getRuleActionRun() .setNot_started(eventActionType.getRunOnStatus().isNotScheduled()); action.getRuleActionRun().setScheduled(eventActionType.getRunOnStatus().isScheduled()); action .getRuleActionRun() .setData_entry_started(eventActionType.getRunOnStatus().isDataEntryStarted()); action.getRuleActionRun().setComplete(eventActionType.getRunOnStatus().isCompleted()); action.getRuleActionRun().setSkipped(eventActionType.getRunOnStatus().isSkipped()); action.getRuleActionRun().setStopped(eventActionType.getRunOnStatus().isStopped()); for (EventDestinationType eventDestinationType : eventActionType.getEventDestination()) { EventPropertyBean property = new EventPropertyBean(); property.setProperty(eventDestinationType.getProperty()); ExpressionBean expressionBean = new ExpressionBean( Context.OC_RULES_V1, eventDestinationType.getValueExpression().getValue()); property.setValueExpression(expressionBean); action.addProperty(property); } ruleSetRuleBean.addAction(action); } for (NotificationActionType notificationActionType : rrt.getNotificationAction()) { NotificationActionBean action = new NotificationActionBean(); action.setExpressionEvaluatesTo( Boolean.valueOf(notificationActionType.getIfExpressionEvaluates())); action.setTo(notificationActionType.getTo()); action.setSubject(notificationActionType.getSubject()); action.setMessage(notificationActionType.getMessage()); ruleSetRuleBean.addAction(action); } ruleSetBean.addRuleSetRule(ruleSetRuleBean); } rpic.addRuleSet(ruleSetBean); } for (RuleDefType rdt : rules.getRuleDef()) { RuleBean ruleBean = new RuleBean(); ExpressionBean ruleExpressionBean = new ExpressionBean(Context.OC_RULES_V1, rdt.getExpression().getValue()); ruleBean.setExpression(ruleExpressionBean); ruleBean.setDescription(rdt.getDescription()); ruleBean.setName(rdt.getName()); ruleBean.setOid(rdt.getOID()); rpic.addRuleDef(ruleBean); } return rpic; }
public int intValue() { return type.intValue(); }