private EntityType introspectEntityType(Class type, EntityType parentType) throws SQLException {
    getInternalEntityConfig(type, _annotationCfg);

    Entity entityAnn = (Entity) _annotationCfg.getAnnotation();
    EntityConfig entityConfig = _annotationCfg.getEntityConfig();

    boolean isEntity = !_annotationCfg.isNull();

    if (!isEntity) return null;

    EntityType entityType;
    String typeName;

    if (entityConfig != null) typeName = entityConfig.getClassName();
    else typeName = entityAnn.name();

    // Validates the type
    String entityName;
    Inheritance inheritanceAnn = null;
    InheritanceConfig inheritanceConfig = null;
    Class rootClass = type;
    Entity rootEntityAnn = null;
    EntityConfig rootEntityConfig = null;

    validateType(type, true);

    // jpa/0ge2
    // if (hasInheritance) {

    if (entityConfig == null) entityName = entityAnn.name();
    else {
      entityName = entityConfig.getClassName();

      int p = entityName.lastIndexOf('.');

      if (p > 0) entityName = entityName.substring(p + 1);
    }

    if ((entityName == null) || "".equals(entityName)) {
      entityName = type.getSimpleName();
    }

    entityType = _persistenceUnit.createEntity(entityName, type);

    _configManager.addType(type, new EntityConfig(type.getName(), this, entityType));

    boolean isField = isField(type, entityConfig, false);

    if (isField) entityType.setFieldAccess(true);

    return entityType;
  }
Exemplo n.º 2
0
 SqlLoadPath(Element element) throws GenericEntityConfException {
   String lineNumberText = EntityConfig.createConfigFileLineNumberText(element);
   String path = element.getAttribute("path").intern();
   if (path.isEmpty()) {
     throw new GenericEntityConfException(
         "<sql-load-path> element path attribute is empty" + lineNumberText);
   }
   this.path = path;
   this.prependEnv = element.getAttribute("prepend-env").intern();
 }
  @Override
  public void receiveMessage(String message) {
    // Gdx.app.debug(TAG, "Got message " + message);
    String[] string = message.split(MESSAGE_TOKEN);

    if (string.length == 0) return;

    // Specifically for messages with 1 object payload
    if (string.length == 2) {
      if (string[0].equalsIgnoreCase(MESSAGE.CURRENT_POSITION.toString())) {
        currentPosition = json.fromJson(Vector2.class, string[1]);
      } else if (string[0].equalsIgnoreCase(MESSAGE.INIT_START_POSITION.toString())) {
        currentPosition = json.fromJson(Vector2.class, string[1]);
      } else if (string[0].equalsIgnoreCase(MESSAGE.CURRENT_STATE.toString())) {
        currentState = json.fromJson(Entity.State.class, string[1]);
      } else if (string[0].equalsIgnoreCase(MESSAGE.CURRENT_DIRECTION.toString())) {
        currentDirection = json.fromJson(Entity.Direction.class, string[1]);
      } else if (string[0].equalsIgnoreCase(MESSAGE.LOAD_ANIMATIONS.toString())) {
        EntityConfig entityConfig = json.fromJson(EntityConfig.class, string[1]);
        Array<EntityConfig.AnimationConfig> animationConfigs = entityConfig.getAnimationConfig();

        for (EntityConfig.AnimationConfig animationConfig : animationConfigs) {
          Array<String> textureNames = animationConfig.getTexturePaths();
          Array<GridPoint2> points = animationConfig.getGridPoints();
          Entity.AnimationType animationType = animationConfig.getAnimationType();
          float frameDuration = animationConfig.getFrameDuration();
          Animation animation = null;

          if (textureNames.size == 1) {
            animation = loadAnimation(textureNames.get(0), points, frameDuration);
          } else if (textureNames.size == 2) {
            animation =
                loadAnimation(textureNames.get(0), textureNames.get(1), points, frameDuration);
          }

          animations.put(animationType, animation);
        }
      }
    }
  }
  private void introspectAttributeOverrides(EntityType entityType, Class type) {
    EntityType parent = entityType.getParentType();

    if (parent == null) return;

    boolean isAbstract = Modifier.isAbstract(parent.getBeanClass().getModifiers());

    if (parent.isEntity() && !isAbstract) return;

    HashMap<String, ColumnConfig> overrideMap = new HashMap<String, ColumnConfig>();

    getInternalAttributeOverrideConfig(type, _annotationCfg);
    AttributeOverride attributeOverrideAnn = (AttributeOverride) _annotationCfg.getAnnotation();

    boolean hasAttributeOverride = (attributeOverrideAnn != null);

    AttributeOverrides attributeOverridesAnn =
        (AttributeOverrides) type.getAnnotation(AttributeOverrides.class);

    ArrayList<AttributeOverrideConfig> attributeOverrideList = null;

    EntityConfig entityConfig = getEntityConfig(type.getName());

    if (entityConfig != null) attributeOverrideList = entityConfig.getAttributeOverrideList();

    boolean hasAttributeOverrides = false;

    if ((attributeOverrideList != null) && (attributeOverrideList.size() > 0)) {
      hasAttributeOverrides = true;
    } else if (attributeOverridesAnn != null) hasAttributeOverrides = true;

    if (hasAttributeOverride && hasAttributeOverrides)
      throw new ConfigException(
          L.l("{0} may not have both @AttributeOverride and @AttributeOverrides", type));

    if (attributeOverrideList == null)
      attributeOverrideList = new ArrayList<AttributeOverrideConfig>();

    if (hasAttributeOverride) {
      // Convert annotation to configuration.

      AttributeOverrideConfig attOverrideConfig =
          convertAttributeOverrideAnnotationToConfig(attributeOverrideAnn);

      attributeOverrideList.add(attOverrideConfig);
    } else if (hasAttributeOverrides) {
      if (attributeOverrideList.size() > 0) {
        // OK: attributeOverrideList came from orm.xml
      } else {
        // Convert annotations to configurations.

        AttributeOverride attOverridesAnn[] = attributeOverridesAnn.value();

        AttributeOverrideConfig attOverrideConfig;

        /* XXX:
        for (int i = 0; i < attOverridesAnn.length; i++) {
          attOverrideConfig
            = convertAttributeOverrideAnnotationToConfig((JAnnotation) attOverridesAnn[i]);

          attributeOverrideList.add(attOverrideConfig);
        }
                * */
      }
    }

    for (AttributeOverrideConfig override : attributeOverrideList) {
      overrideMap.put(override.getName(), override.getColumn());
    }

    _depCompletions.add(new AttributeOverrideCompletion(this, entityType, type, overrideMap));
  }