Пример #1
0
  @Override
  public void setParameterValues(Properties parameters) {
    final ParameterType reader = (ParameterType) parameters.get(PARAMETER_TYPE);

    // IMPL NOTE : be protective about not setting enumValueMapper (i.e. calling
    // treatAsNamed/treatAsOrdinal)
    // in cases where we do not have enough information.  In such cases we do additional checks
    // as part of nullSafeGet/nullSafeSet to query against the JDBC metadata to make the
    // determination.

    if (reader != null) {
      enumClass = reader.getReturnedClass().asSubclass(Enum.class);

      final boolean isOrdinal;
      final javax.persistence.EnumType enumType = getEnumType(reader);
      if (enumType == null) {
        isOrdinal = true;
      } else if (javax.persistence.EnumType.ORDINAL.equals(enumType)) {
        isOrdinal = true;
      } else if (javax.persistence.EnumType.STRING.equals(enumType)) {
        isOrdinal = false;
      } else {
        throw new AssertionFailure("Unknown EnumType: " + enumType);
      }

      if (isOrdinal) {
        treatAsOrdinal();
      } else {
        treatAsNamed();
      }
      sqlType = enumValueMapper.getSqlType();
    } else {
      String enumClassName = (String) parameters.get(ENUM);
      try {
        enumClass =
            ReflectHelper.classForName(enumClassName, this.getClass()).asSubclass(Enum.class);
      } catch (ClassNotFoundException exception) {
        throw new HibernateException("Enum class not found", exception);
      }

      final Object useNamedSetting = parameters.get(NAMED);
      if (useNamedSetting != null) {
        final boolean useNamed = ConfigurationHelper.getBoolean(NAMED, parameters);
        if (useNamed) {
          treatAsNamed();
        } else {
          treatAsOrdinal();
        }
        sqlType = enumValueMapper.getSqlType();
      }
    }

    final String type = (String) parameters.get(TYPE);
    if (type != null) {
      sqlType = Integer.decode(type);
    }
  }
Пример #2
0
 private javax.persistence.EnumType getEnumType(ParameterType reader) {
   javax.persistence.EnumType enumType = null;
   if (reader.isPrimaryKey()) {
     MapKeyEnumerated enumAnn =
         getAnnotation(reader.getAnnotationsMethod(), MapKeyEnumerated.class);
     if (enumAnn != null) {
       enumType = enumAnn.value();
     }
   } else {
     Enumerated enumAnn = getAnnotation(reader.getAnnotationsMethod(), Enumerated.class);
     if (enumAnn != null) {
       enumType = enumAnn.value();
     }
   }
   return enumType;
 }
 public String toString() {
   return String.format(
       "%s%s[%d]",
       interp == InterpolationType.NONE ? "" : interp.name().toLowerCase() + " ",
       type.name().toLowerCase(),
       size());
 }
 private boolean isValidParameter(
     String name, ParameterType type, InterpolationType interp, int requestedSize, Parameter p) {
   if (p == null) return false;
   if (p.type != type) {
     UI.printWarning(
         Module.API,
         "Parameter %s requested as a %s - declared as %s",
         name,
         type.name().toLowerCase(),
         p.type.name().toLowerCase());
     return false;
   }
   if (p.interp != interp) {
     UI.printWarning(
         Module.API,
         "Parameter %s requested as a %s - declared as %s",
         name,
         interp.name().toLowerCase(),
         p.interp.name().toLowerCase());
     return false;
   }
   if (requestedSize > 0 && p.size() != requestedSize) {
     UI.printWarning(
         Module.API,
         "Parameter %s requires %d %s - declared with %d",
         name,
         requestedSize,
         requestedSize == 1 ? "value" : "values",
         p.size());
     return false;
   }
   p.checked = true;
   return true;
 }
 /** {@inheritDoc} */
 @SuppressWarnings("unchecked")
 public void setParameterValues(Properties parameters) {
   ParameterType reader = (ParameterType) parameters.get(PARAMETER_TYPE);
   if (reader != null) {
     setJavaTypeDescriptor(new SerializableTypeDescriptor<T>(reader.getReturnedClass()));
   } else {
     String className = parameters.getProperty(CLASS_NAME);
     if (className == null) {
       throw new MappingException(
           "No class name defined for type: " + SerializableToBlobType.class.getName());
     }
     try {
       setJavaTypeDescriptor(
           new SerializableTypeDescriptor<T>(ReflectHelper.classForName(className)));
     } catch (ClassNotFoundException e) {
       throw new MappingException("Unable to load class from " + CLASS_NAME + " parameter", e);
     }
   }
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public ParameterType createParameterTypeFromString(EDataType eDataType, String initialValue) {
   ParameterType result = ParameterType.get(initialValue);
   if (result == null)
     throw new IllegalArgumentException(
         "The value '"
             + initialValue
             + "' is not a valid enumerator of '"
             + eDataType.getName()
             + "'");
   return result;
 }
Пример #7
0
  static int parameterSize(ParameterType parameterType) {
    switch (parameterType.nativeType()) {
      case SCHAR:
      case UCHAR:
      case SSHORT:
      case USHORT:
      case SINT:
      case UINT:
      case SLONG:
      case ULONG:
      case POINTER:
      case FLOAT:
        return 4;

      case SLONG_LONG:
      case ULONG_LONG:
      case DOUBLE:
        return 8;

      default:
        throw new IllegalArgumentException("invalid parameter type" + parameterType);
    }
  }
Пример #8
0
  private static void parseConfiguration(String stringUrl, Product product) {
    try {
      URL url = new URL(stringUrl);
      URLConnection connection = url.openConnection();
      int fileLength = connection.getContentLength();

      if (fileLength == -1) {
        System.out.println("Invalide URL or file.");
        return;
      }

      CommandClass currentCC = null;
      Parameter currentParameter = null;
      Association currentAssociation = null;

      XMLInputFactory inputFactory = XMLInputFactory.newInstance();
      InputStream input = connection.getInputStream();
      final XMLEventReader eventReader = inputFactory.createXMLEventReader(input);

      while (eventReader.hasNext()) {
        XMLEvent event = eventReader.nextEvent();
        if (event.isStartElement()) {
          StartElement startElt = event.asStartElement();
          if (startElt.getName().getLocalPart().equals("CommandClass")) {
            CommandClass cc = product.view().createCommandClass();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();

              if (attrName.equals("id")) {
                cc.setId(Integer.parseInt(next.getValue(), 16));
              }
            }
            product.addCommandClasses(cc);
            currentCC = cc;

          } else if (startElt.getName().getLocalPart().equals("Value")) {

            Parameter param = product.view().createParameter();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();
              if (!next.getValue().equals("")) {
                if (attrName.equals("type")) {
                  param.setType(ParameterType.valueOf(next.getValue().toUpperCase()));
                } else if (attrName.equals("genre")) {
                  param.setGenre(next.getValue());
                } else if (attrName.equals("instance")) {
                  param.setInstance(Integer.valueOf(next.getValue()));
                } else if (attrName.equals("index")) {
                  param.setIndex(Integer.valueOf(next.getValue()));
                } else if (attrName.equals("label")) {
                  param.setLabel(next.getValue());
                } else if (attrName.equals("value")) {
                  param.setValue(next.getValue());
                } else if (attrName.equals("min")) {

                  param.setMin(Integer.valueOf(next.getValue()));
                } else if (attrName.equals("max")) {

                  param.setMax(Integer.valueOf(next.getValue()));
                } else if (attrName.equals("size")) {
                  param.setSize(Integer.valueOf(next.getValue()));
                }
              }
            }
            currentCC.addParameters(param);
            currentParameter = param;

          } else if (startElt.getName().getLocalPart().equals("Help")) {
            // help

          } else if (startElt.getName().getLocalPart().equals("Item")) {
            ParameterItem item = product.view().createParameterItem();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();
              if (attrName.equals("label")) {
                item.setLabel(next.getValue());
              } else if (attrName.equals("value")) {
                item.setValue(Integer.valueOf(next.getValue()));
              }
            }
            currentParameter.addItems(item);
          } else if (startElt.getName().getLocalPart().equals("Associations")) {
            Association assoc = product.view().createAssociation();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();
              if (attrName.equals("num_groups")) {
                assoc.setNumGroups(Integer.valueOf(next.getValue()));
              }
            }
            currentCC.addAssociations(assoc);
            currentAssociation = assoc;
          } else if (startElt.getName().getLocalPart().equals("Group")) {
            AssociationGroup group = product.view().createAssociationGroup();

            Iterator<Attribute> attributes = startElt.getAttributes();
            while (attributes.hasNext()) {
              Attribute next = attributes.next();
              String attrName = next.getName().toString();
              if (attrName.equals("label")) {
                group.setLabel(next.getValue());
              } else if (attrName.equals("index")) {
                group.setIndex(Integer.valueOf(next.getValue()));
              } else if (attrName.equals("max_associations")) {
                group.setMaxAssociations(Integer.valueOf(next.getValue()));
              } else if (attrName.equals("auto")) {
                group.setAuto(Boolean.valueOf(next.getValue()));
              }
              currentAssociation.addGroups(group);
            }
          }
        }
      }

    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (XMLStreamException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #9
0
  boolean canCompile(
      ResultType returnType, ParameterType[] parameterTypes, CallingConvention convention) {

    switch (returnType.nativeType()) {
      case VOID:
      case SCHAR:
      case UCHAR:
      case SSHORT:
      case USHORT:
      case SINT:
      case UINT:
      case SLONG:
      case ULONG:
      case SLONG_LONG:
      case ULONG_LONG:
      case FLOAT:
      case DOUBLE:
      case POINTER:
        break;

      default:
        return false;
    }

    // There is only one calling convention; SYSV, so abort if someone tries to use stdcall
    if (convention != CallingConvention.DEFAULT) {
      return false;
    }

    int fCount = 0;
    int iCount = 0;

    for (ParameterType t : parameterTypes) {
      switch (t.nativeType()) {
        case SCHAR:
        case UCHAR:
        case SSHORT:
        case USHORT:
        case SINT:
        case UINT:
        case SLONG:
        case ULONG:
        case SLONG_LONG:
        case ULONG_LONG:
        case POINTER:
          ++iCount;
          break;

        case FLOAT:
        case DOUBLE:
          ++fCount;
          break;

        default:
          // Fail on anything else
          return false;
      }
    }

    // We can only safely compile methods with up to 6 integer and 8 floating point parameters
    return true;
  }
Пример #10
0
 public String getTypeName() {
   return type.name();
 }