Exemple #1
0
 @SuppressWarnings("unchecked")
 @Override
 public void registerMeasures(NameResolver resolver) {
   System.out.printf("Resolver %s!\n", id.getValue());
   key = (Key<PropType>) resolver.resolve(id.getValue());
   key.registerValue(inner.getValue());
 }
 public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
   return Arrays.asList(
       new PropertyDescriptor(
           PROP_TEXT,
           MidpTypes.TYPEID_JAVA_LANG_STRING,
           PropertyValue.createNull(),
           true,
           true,
           MidpVersionable.MIDP),
       new PropertyDescriptor(
           PROP_MAX_SIZE,
           MidpTypes.TYPEID_INT,
           PropertyValue.createNull(),
           false,
           true,
           MidpVersionable.MIDP),
       new PropertyDescriptor(
           PROP_CONSTRAINTS,
           MidpTypes.TYPEID_INT,
           PropertyValue.createNull(),
           false,
           true,
           MidpVersionable.MIDP),
       new PropertyDescriptor(
           PROP_INITIAL_INPUT_MODE,
           MidpTypes.TYPEID_JAVA_LANG_STRING,
           PropertyValue.createNull(),
           true,
           true,
           MidpVersionable.MIDP_2));
 }
Exemple #3
0
 public void deletePropertyValue(URI property) {
   for (PropertyValue pv : this.properties) {
     if (pv.getUri().equals(property)) {
       this.properties.remove(pv);
     }
   }
 }
 /**
  * The color with which the background will be drawn.
  *
  * @return int representation of a rgba string color
  * @throws RuntimeException thrown if property isn't a value
  */
 @ColorInt
 public int getBackgroundColorAsInt() {
   PropertyValue<String> value = getBackgroundColor();
   if (value.isValue()) {
     return rgbaToColor(value.getValue());
   } else {
     throw new RuntimeException("background-color was set as a Function");
   }
 }
  public CGlassEclipseButtonTitle(Dockable dockable, DockTitleVersion origin) {
    super(dockable, origin);
    setTransparency(Transparency.DEFAULT);

    if (origin != null) {
      propValueSmall.setProperties(origin.getController());
      propValueFactory.setProperties(origin.getController());
    }
    bSmallTitle = propValueSmall.getValue();
  }
 /**
  * Add a PropertyValue object, replacing any existing one for the respective property.
  *
  * @param pv PropertyValue object to add
  */
 public void addPropertyValue(PropertyValue pv) {
   for (int i = 0; i < this.propertyValueList.size(); i++) {
     PropertyValue currentPv = (PropertyValue) this.propertyValueList.get(i);
     if (currentPv.getName().equals(pv.getName())) {
       setPropertyValueAt(pv, i);
       return;
     }
   }
   this.propertyValueList.add(pv);
   recache();
 }
 public Object build(DeserializationContext ctxt, PropertyValueBuffer buffer) throws IOException {
   Object bean =
       buffer.handleIdValue(
           ctxt,
           this._valueInstantiator.createFromObjectWith(
               ctxt, buffer.getParameters(this._defaultValues)));
   for (PropertyValue pv = buffer.buffered(); pv != null; pv = pv.next) {
     pv.assign(bean);
   }
   return bean;
 }
 @Override
 public void generateParameterCode(
     DesignComponent component, MultiGuardedSection section, int index) {
   PropertyValue value = component.readProperty(PROP_CONSTRAINTS);
   if (value.getKind() == PropertyValue.Kind.VALUE) {
     int constraint = MidpTypes.getInteger(value);
     int core = constraint & TextFieldCD.VALUE_CONSTRAINT_MASK;
     CodeWriter writer = section.getWriter();
     switch (core) {
       case TextFieldCD.VALUE_ANY:
         writer.write("TextField.ANY"); // NOI18N
         break;
       case TextFieldCD.VALUE_EMAILADDR:
         writer.write("TextField.EMAILADDR"); // NOI18N
         break;
       case TextFieldCD.VALUE_NUMERIC:
         writer.write("TextField.NUMERIC"); // NOI18N
         break;
       case TextFieldCD.VALUE_PHONENUMBER:
         writer.write("TextField.PHONENUMBER"); // NOI18N
         break;
       case TextFieldCD.VALUE_URL:
         writer.write("TextField.URL"); // NOI18N
         break;
       case TextFieldCD.VALUE_DECIMAL:
         writer.write("TextField.DECIMAL"); // NOI18N
         break;
       default:
         writer.write(Integer.toString(core));
     }
     if ((constraint & TextFieldCD.VALUE_PASSWORD) != 0) {
       writer.write(" | TextField.PASSWORD"); // NOI18N
     }
     if ((constraint & TextFieldCD.VALUE_UNEDITABLE) != 0) {
       writer.write(" | TextField.UNEDITABLE"); // NOI18N
     }
     if ((constraint & TextFieldCD.VALUE_SENSITIVE) != 0) {
       writer.write(" | TextField.SENSITIVE"); // NOI18N
     }
     if ((constraint & TextFieldCD.VALUE_NON_PREDICTIVE) != 0) {
       writer.write(" | TextField.NON_PREDICTIVE"); // NOI18N
     }
     if ((constraint & TextFieldCD.VALUE_INITIAL_CAPS_WORD) != 0) {
       writer.write(" | TextField.INITIAL_CAPS_WORD"); // NOI18N
     }
     if ((constraint & TextFieldCD.VALUE_INITIAL_CAPS_SENTENCE) != 0) {
       writer.write(" | TextField.INITIAL_CAPS_SENTENCE"); // NOI18N
     }
     return;
   }
   super.generateParameterCode(component, section, index);
 }
Exemple #9
0
  /**
   * Transforms a Resource to a JSON object (key: value)
   *
   * @return a JSON object containing all info about the resource
   */
  public JSONObject toJSON() throws JSONException {
    JSONObject json = new JSONObject();

    json.put("uri", getUri() == null ? JSONObject.NULL : getUri().toString());
    json.put("type", getType() == null ? JSONObject.NULL : getType().toString());
    JSONArray jsonPropertys = new JSONArray();
    for (PropertyValue av : properties) {
      jsonPropertys.put(av.toJSON());
    }
    json.put("properties", jsonPropertys);

    return json;
  }
  public PropertyValues changesSince(PropertyValues old) {
    MutablePropertyValues changes = new MutablePropertyValues();
    if (old == this) return changes;

    // for each property value in the new set
    for (int i = 0; i < this.propertyValueArray.length; i++) {
      PropertyValue newPv = propertyValueArray[i];
      // if there wasn't an old one, add it
      PropertyValue pvOld = old.getPropertyValue(newPv.getName());
      if (pvOld == null) {
        changes.addPropertyValue(newPv);
      } else if (!pvOld.equals(newPv)) {
        // it's changed
        changes.addPropertyValue(newPv);
      }
    }
    return changes;
  }
Exemple #11
0
  public Model toRDF2GoModel() {
    Model model = RDF2Go.getModelFactory().createModel();
    model.open();

    Resource sample = this.getUri();
    model.addStatement(sample, RDF.type, this.type);
    for (PropertyValue property : properties) {
      Node object;
      if (property.getLang() != null) {
        object = model.createLanguageTagLiteral(property.getValue(), property.getLang());
      } else if (property.getDatatype() != null) {
        object = model.createDatatypeLiteral(property.getValue(), property.getDatatype());
      } else {
        object = model.createPlainLiteral(property.getValue());
      }
      model.addStatement(sample, property.getUri(), object);
    }

    return model;
  }
Exemple #12
0
 @Override
 public void setPropertyValue(PropertyValue pv) throws BeansException {
   PropertyTokenHolder tokens = (PropertyTokenHolder) pv.resolvedTokens;
   if (tokens == null) {
     String propertyName = pv.getName();
     BeanWrapperImpl nestedBw;
     try {
       nestedBw = getBeanWrapperForPropertyPath(propertyName);
     } catch (NotReadablePropertyException ex) {
       throw new NotWritablePropertyException(
           getRootClass(),
           this.nestedPath + propertyName,
           "Nested property in path '" + propertyName + "' does not exist",
           ex);
     }
     tokens = getPropertyNameTokens(getFinalPath(nestedBw, propertyName));
     if (nestedBw == this) {
       pv.getOriginalPropertyValue().resolvedTokens = tokens;
     }
     nestedBw.setPropertyValue(tokens, pv);
   } else {
     setPropertyValue(tokens, pv);
   }
 }
Exemple #13
0
 @Override
 public PropType getValue() {
   return convert.convert(key.scaleValue(inner.getValue()), pm, env);
 }
 @Override
 public void unbind() {
   super.unbind();
   propValueSmall.setProperties((DockController) null);
   propValueFactory.setProperties((DockController) null);
 }
 protected void getGlassParameters() {
   IGlassParameterFactory f = propValueFactory.getValue();
   glassStrip = f.getStripBGGlassParameters();
 }
 public void setPropertyValue(PropertyValue pv) throws BeansException {
   setPropertyValue(pv.getName(), pv.getValue());
 }
Exemple #17
0
  @SuppressWarnings("unchecked")
  private void setPropertyValue(PropertyTokenHolder tokens, PropertyValue pv)
      throws BeansException {
    String propertyName = tokens.canonicalName;
    String actualName = tokens.actualName;

    if (tokens.keys != null) {
      // Apply indexes and map keys: fetch value for all keys but the last one.
      PropertyTokenHolder getterTokens = new PropertyTokenHolder();
      getterTokens.canonicalName = tokens.canonicalName;
      getterTokens.actualName = tokens.actualName;
      getterTokens.keys = new String[tokens.keys.length - 1];
      System.arraycopy(tokens.keys, 0, getterTokens.keys, 0, tokens.keys.length - 1);
      Object propValue;
      try {
        propValue = getPropertyValue(getterTokens);
      } catch (NotReadablePropertyException ex) {
        throw new NotWritablePropertyException(
            getRootClass(),
            this.nestedPath + propertyName,
            "Cannot access indexed value in property referenced "
                + "in indexed property path '"
                + propertyName
                + "'",
            ex);
      }
      // Set value for last key.
      String key = tokens.keys[tokens.keys.length - 1];
      if (propValue == null) {
        // null map value case
        if (this.autoGrowNestedPaths) {
          // TODO: cleanup, this is pretty hacky
          int lastKeyIndex = tokens.canonicalName.lastIndexOf('[');
          getterTokens.canonicalName = tokens.canonicalName.substring(0, lastKeyIndex);
          propValue = setDefaultValue(getterTokens);
        } else {
          throw new NullValueInNestedPathException(
              getRootClass(),
              this.nestedPath + propertyName,
              "Cannot access indexed value in property referenced "
                  + "in indexed property path '"
                  + propertyName
                  + "': returned null");
        }
      }
      if (propValue.getClass().isArray()) {
        PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
        Class requiredType = propValue.getClass().getComponentType();
        int arrayIndex = Integer.parseInt(key);
        Object oldValue = null;
        try {
          if (isExtractOldValueForEditor() && arrayIndex < Array.getLength(propValue)) {
            oldValue = Array.get(propValue, arrayIndex);
          }
          Object convertedValue =
              convertIfNecessary(
                  propertyName,
                  oldValue,
                  pv.getValue(),
                  requiredType,
                  TypeDescriptor.nested(property(pd), tokens.keys.length));
          Array.set(propValue, arrayIndex, convertedValue);
        } catch (IndexOutOfBoundsException ex) {
          throw new InvalidPropertyException(
              getRootClass(),
              this.nestedPath + propertyName,
              "Invalid array index in property path '" + propertyName + "'",
              ex);
        }
      } else if (propValue instanceof List) {
        PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
        Class requiredType =
            GenericCollectionTypeResolver.getCollectionReturnType(
                pd.getReadMethod(), tokens.keys.length);
        List list = (List) propValue;
        int index = Integer.parseInt(key);
        int size = list.size();
        Object oldValue = null;
        if (isExtractOldValueForEditor() && index < size) {
          oldValue = list.get(index);
        }
        Object convertedValue =
            convertIfNecessary(
                propertyName,
                oldValue,
                pv.getValue(),
                requiredType,
                TypeDescriptor.nested(property(pd), tokens.keys.length));
        if (index >= size && index < this.autoGrowCollectionLimit) {
          for (int i = size; i < index; i++) {
            try {
              list.add(null);
            } catch (NullPointerException ex) {
              throw new InvalidPropertyException(
                  getRootClass(),
                  this.nestedPath + propertyName,
                  "Cannot set element with index "
                      + index
                      + " in List of size "
                      + size
                      + ", accessed using property path '"
                      + propertyName
                      + "': List does not support filling up gaps with null elements");
            }
          }
          list.add(convertedValue);
        } else {
          try {
            list.set(index, convertedValue);
          } catch (IndexOutOfBoundsException ex) {
            throw new InvalidPropertyException(
                getRootClass(),
                this.nestedPath + propertyName,
                "Invalid list index in property path '" + propertyName + "'",
                ex);
          }
        }
      } else if (propValue instanceof Map) {
        PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
        Class mapKeyType =
            GenericCollectionTypeResolver.getMapKeyReturnType(
                pd.getReadMethod(), tokens.keys.length);
        Class mapValueType =
            GenericCollectionTypeResolver.getMapValueReturnType(
                pd.getReadMethod(), tokens.keys.length);
        Map map = (Map) propValue;
        // IMPORTANT: Do not pass full property name in here - property editors
        // must not kick in for map keys but rather only for map values.
        TypeDescriptor typeDescriptor =
            mapKeyType != null
                ? TypeDescriptor.valueOf(mapKeyType)
                : TypeDescriptor.valueOf(Object.class);
        Object convertedMapKey = convertIfNecessary(null, null, key, mapKeyType, typeDescriptor);
        Object oldValue = null;
        if (isExtractOldValueForEditor()) {
          oldValue = map.get(convertedMapKey);
        }
        // Pass full property name and old value in here, since we want full
        // conversion ability for map values.
        Object convertedMapValue =
            convertIfNecessary(
                propertyName,
                oldValue,
                pv.getValue(),
                mapValueType,
                TypeDescriptor.nested(property(pd), tokens.keys.length));
        map.put(convertedMapKey, convertedMapValue);
      } else {
        throw new InvalidPropertyException(
            getRootClass(),
            this.nestedPath + propertyName,
            "Property referenced in indexed property path '"
                + propertyName
                + "' is neither an array nor a List nor a Map; returned value was ["
                + pv.getValue()
                + "]");
      }
    } else {
      PropertyDescriptor pd = pv.resolvedDescriptor;
      if (pd == null || !pd.getWriteMethod().getDeclaringClass().isInstance(this.object)) {
        pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
        if (pd == null || pd.getWriteMethod() == null) {
          if (pv.isOptional()) {
            logger.debug(
                "Ignoring optional value for property '"
                    + actualName
                    + "' - property not found on bean class ["
                    + getRootClass().getName()
                    + "]");
            return;
          } else {
            PropertyMatches matches = PropertyMatches.forProperty(propertyName, getRootClass());
            throw new NotWritablePropertyException(
                getRootClass(),
                this.nestedPath + propertyName,
                matches.buildErrorMessage(),
                matches.getPossibleMatches());
          }
        }
        pv.getOriginalPropertyValue().resolvedDescriptor = pd;
      }

      Object oldValue = null;
      try {
        Object originalValue = pv.getValue();
        Object valueToApply = originalValue;
        if (!Boolean.FALSE.equals(pv.conversionNecessary)) {
          if (pv.isConverted()) {
            valueToApply = pv.getConvertedValue();
          } else {
            if (isExtractOldValueForEditor() && pd.getReadMethod() != null) {
              final Method readMethod = pd.getReadMethod();
              if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())
                  && !readMethod.isAccessible()) {
                if (System.getSecurityManager() != null) {
                  AccessController.doPrivileged(
                      new PrivilegedAction<Object>() {
                        public Object run() {
                          readMethod.setAccessible(true);
                          return null;
                        }
                      });
                } else {
                  readMethod.setAccessible(true);
                }
              }
              try {
                if (System.getSecurityManager() != null) {
                  oldValue =
                      AccessController.doPrivileged(
                          new PrivilegedExceptionAction<Object>() {
                            public Object run() throws Exception {
                              return readMethod.invoke(object);
                            }
                          },
                          acc);
                } else {
                  oldValue = readMethod.invoke(object);
                }
              } catch (Exception ex) {
                if (ex instanceof PrivilegedActionException) {
                  ex = ((PrivilegedActionException) ex).getException();
                }
                if (logger.isDebugEnabled()) {
                  logger.debug(
                      "Could not read previous value of property '"
                          + this.nestedPath
                          + propertyName
                          + "'",
                      ex);
                }
              }
            }
            valueToApply = convertForProperty(propertyName, oldValue, originalValue, pd);
          }
          pv.getOriginalPropertyValue().conversionNecessary = (valueToApply != originalValue);
        }
        final Method writeMethod =
            (pd instanceof GenericTypeAwarePropertyDescriptor
                ? ((GenericTypeAwarePropertyDescriptor) pd).getWriteMethodForActualAccess()
                : pd.getWriteMethod());
        if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())
            && !writeMethod.isAccessible()) {
          if (System.getSecurityManager() != null) {
            AccessController.doPrivileged(
                new PrivilegedAction<Object>() {
                  public Object run() {
                    writeMethod.setAccessible(true);
                    return null;
                  }
                });
          } else {
            writeMethod.setAccessible(true);
          }
        }
        final Object value = valueToApply;
        if (System.getSecurityManager() != null) {
          try {
            AccessController.doPrivileged(
                new PrivilegedExceptionAction<Object>() {
                  public Object run() throws Exception {
                    writeMethod.invoke(object, value);
                    return null;
                  }
                },
                acc);
          } catch (PrivilegedActionException ex) {
            throw ex.getException();
          }
        } else {
          writeMethod.invoke(this.object, value);
        }
      } catch (TypeMismatchException ex) {
        throw ex;
      } catch (InvocationTargetException ex) {
        PropertyChangeEvent propertyChangeEvent =
            new PropertyChangeEvent(
                this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue());
        if (ex.getTargetException() instanceof ClassCastException) {
          throw new TypeMismatchException(
              propertyChangeEvent, pd.getPropertyType(), ex.getTargetException());
        } else {
          throw new MethodInvocationException(propertyChangeEvent, ex.getTargetException());
        }
      } catch (Exception ex) {
        PropertyChangeEvent pce =
            new PropertyChangeEvent(
                this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue());
        throw new MethodInvocationException(pce, ex);
      }
    }
  }