Package org.dom4j

Examples of org.dom4j.Attribute


      final Mappings mappings) throws MappingException {

    Table table = simpleValue.getTable();

    // COLUMN(S)
    Attribute columnAttribute = node.attribute( "column" );
    if ( columnAttribute == null ) {
      Iterator iter = node.elementIterator();
      int count = 0;
      while ( iter.hasNext() ) {
        Element columnElement = (Element) iter.next();
        if ( columnElement.getName().equals( "column" ) ) {
          Column column = new Column();
          column.setValue( simpleValue );
          column.setTypeIndex( count++ );
          bindColumn( columnElement, column, isNullable );
          String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
              columnElement.attributeValue( "name" ), propertyPath
          );
          column.setName( mappings.getNamingStrategy().columnName(
            logicalColumnName ) );
          if ( table != null ) {
            table.addColumn( column ); // table=null -> an association
                                       // - fill it in later
            //TODO fill in the mappings for table == null
            mappings.addColumnBinding( logicalColumnName, column, table );
          }


          simpleValue.addColumn( column );
          // column index
          bindIndex( columnElement.attribute( "index" ), table, column, mappings );
          bindIndex( node.attribute( "index" ), table, column, mappings );
          //column unique-key
          bindUniqueKey( columnElement.attribute( "unique-key" ), table, column, mappings );
          bindUniqueKey( node.attribute( "unique-key" ), table, column, mappings );
        }
        else if ( columnElement.getName().equals( "formula" ) ) {
          Formula formula = new Formula();
          formula.setFormula( columnElement.getText() );
          simpleValue.addFormula( formula );
        }
      }
    }
    else {
      if ( node.elementIterator( "column" ).hasNext() ) {
        throw new MappingException(
          "column attribute may not be used together with <column> subelement" );
      }
      if ( node.elementIterator( "formula" ).hasNext() ) {
        throw new MappingException(
          "column attribute may not be used together with <formula> subelement" );
      }

      Column column = new Column();
      column.setValue( simpleValue );
      bindColumn( node, column, isNullable );
      String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
          columnAttribute.getValue(), propertyPath
      );
      column.setName( mappings.getNamingStrategy().columnName( logicalColumnName ) );
      if ( table != null ) {
        table.addColumn( column ); // table=null -> an association - fill
                                   // it in later
View Full Code Here


      String path, Mappings mappings) throws MappingException {
    bindSimpleValueType( node, simpleValue, mappings );

    bindColumnsOrFormula( node, simpleValue, path, isNullable, mappings );

    Attribute fkNode = node.attribute( "foreign-key" );
    if ( fkNode != null ) simpleValue.setForeignKeyName( fkNode.getValue() );
  }
View Full Code Here

      throws MappingException {
    String typeName = null;

    Properties parameters = new Properties();

    Attribute typeNode = node.attribute( "type" );
    if ( typeNode == null ) typeNode = node.attribute( "id-type" ); // for an any
    if ( typeNode != null ) typeName = typeNode.getValue();

    Element typeChild = node.element( "type" );
    if ( typeName == null && typeChild != null ) {
      typeName = typeChild.attribute( "name" ).getValue();
      Iterator typeParameters = typeChild.elementIterator( "param" );
View Full Code Here

    // TODO:
    //Type type = model.getValue().getType();
    //if (type==null) throw new MappingException(
    //"Could not determine a property type for: " + model.getName() );

    Attribute accessNode = node.attribute( "access" );
    if ( accessNode != null ) {
      property.setPropertyAccessorName( accessNode.getValue() );
    }
    else if ( node.getName().equals( "properties" ) ) {
      property.setPropertyAccessorName( "embedded" );
    }
    else {
      property.setPropertyAccessorName( mappings.getDefaultAccess() );
    }

    Attribute cascadeNode = node.attribute( "cascade" );
    property.setCascade( cascadeNode == null ? mappings.getDefaultCascade() : cascadeNode
      .getValue() );

    Attribute updateNode = node.attribute( "update" );
    property.setUpdateable( updateNode == null || "true".equals( updateNode.getValue() ) );

    Attribute insertNode = node.attribute( "insert" );
    property.setInsertable( insertNode == null || "true".equals( insertNode.getValue() ) );

    Attribute lockNode = node.attribute( "optimistic-lock" );
    property.setOptimisticLocked( lockNode == null || "true".equals( lockNode.getValue() ) );

    Attribute generatedNode = node.attribute( "generated" );
        String generationName = generatedNode == null ? null : generatedNode.getValue();
        PropertyGeneration generation = PropertyGeneration.parse( generationName );
    property.setGeneration( generation );

        if ( generation == PropertyGeneration.ALWAYS || generation == PropertyGeneration.INSERT ) {
          // generated properties can *never* be insertable...
          if ( property.isInsertable() ) {
            if ( insertNode == null ) {
              // insertable simply because that is the user did not specify
              // anything; just override it
          property.setInsertable( false );
            }
            else {
              // the user specifically supplied insert="true",
              // which constitutes an illegal combo
          throw new MappingException(
              "cannot specify both insert=\"true\" and generated=\"" + generation.getName() +
              "\" for property: " +
              propName
          );
            }
          }

          // properties generated on update can never be updateable...
          if ( property.isUpdateable() && generation == PropertyGeneration.ALWAYS ) {
            if ( updateNode == null ) {
              // updateable only because the user did not specify
              // anything; just override it
              property.setUpdateable( false );
            }
            else {
              // the user specifically supplied update="true",
              // which constitutes an illegal combo
          throw new MappingException(
              "cannot specify both update=\"true\" and generated=\"" + generation.getName() +
              "\" for property: " +
              propName
          );
            }
          }
        }

    boolean isLazyable = "property".equals( node.getName() ) ||
        "component".equals( node.getName() ) ||
        "many-to-one".equals( node.getName() ) ||
        "one-to-one".equals( node.getName() ) ||
        "any".equals( node.getName() );
    if ( isLazyable ) {
      Attribute lazyNode = node.attribute( "lazy" );
      property.setLazy( lazyNode != null && "true".equals( lazyNode.getValue() ) );
    }

    if ( log.isDebugEnabled() ) {
      String msg = "Mapped property: " + property.getName();
      String columns = columns( property.getValue() );
View Full Code Here

      String path, Mappings mappings, java.util.Map inheritedMetas) throws MappingException {

    // ROLENAME
    collection.setRole(path);

    Attribute inverseNode = node.attribute( "inverse" );
    if ( inverseNode != null ) {
      collection.setInverse( "true".equals( inverseNode.getValue() ) );
    }

    Attribute mutableNode = node.attribute( "mutable" );
    if ( mutableNode != null ) {
      collection.setMutable( !"false".equals( mutableNode.getValue() ) );
    }

    Attribute olNode = node.attribute( "optimistic-lock" );
    collection.setOptimisticLocked( olNode == null || "true".equals( olNode.getValue() ) );

    Attribute orderNode = node.attribute( "order-by" );
    if ( orderNode != null ) {
      if ( Environment.jvmSupportsLinkedHashCollections() || ( collection instanceof Bag ) ) {
        collection.setOrderBy( orderNode.getValue() );
      }
      else {
        log.warn( "Attribute \"order-by\" ignored in JDK1.3 or less" );
      }
    }
    Attribute whereNode = node.attribute( "where" );
    if ( whereNode != null ) {
      collection.setWhere( whereNode.getValue() );
    }
    Attribute batchNode = node.attribute( "batch-size" );
    if ( batchNode != null ) {
      collection.setBatchSize( Integer.parseInt( batchNode.getValue() ) );
    }

    String nodeName = node.attributeValue( "node" );
    if ( nodeName == null ) nodeName = node.attributeValue( "name" );
    collection.setNodeName( nodeName );
    String embed = node.attributeValue( "embed-xml" );
    collection.setEmbedded( embed==null || "true".equals(embed) );


    // PERSISTER
    Attribute persisterNode = node.attribute( "persister" );
    if ( persisterNode != null ) {
      try {
        collection.setCollectionPersisterClass( ReflectHelper.classForName( persisterNode
          .getValue() ) );
      }
      catch (ClassNotFoundException cnfe) {
        throw new MappingException( "Could not find collection persister class: "
          + persisterNode.getValue() );
      }
    }

    Attribute typeNode = node.attribute( "collection-type" );
    if ( typeNode != null ) {
      String typeName = typeNode.getValue();
      TypeDef typeDef = mappings.getTypeDef( typeName );
      if ( typeDef != null ) {
        collection.setTypeName( typeDef.getTypeClass() );
        collection.setTypeParameters( typeDef.getParameters() );
      }
      else {
        collection.setTypeName( typeName );
      }
    }

    // FETCH STRATEGY

    initOuterJoinFetchSetting( node, collection );

    if ( "subselect".equals( node.attributeValue("fetch") ) ) {
      collection.setSubselectLoadable(true);
      collection.getOwner().setSubselectLoadableCollections(true);
    }

    initLaziness( node, collection, mappings, "true", mappings.isDefaultLazy() );
    //TODO: suck this into initLaziness!
    if ( "extra".equals( node.attributeValue("lazy") ) ) {
      collection.setLazy(true);
      collection.setExtraLazy(true);
    }

    Element oneToManyNode = node.element( "one-to-many" );
    if ( oneToManyNode != null ) {
      OneToMany oneToMany = new OneToMany( collection.getOwner() );
      collection.setElement( oneToMany );
      bindOneToMany( oneToManyNode, oneToMany, mappings );
      // we have to set up the table later!! yuck
    }
    else {
      // TABLE
      Attribute tableNode = node.attribute( "table" );
      String tableName;
      if ( tableNode != null ) {
        tableName = mappings.getNamingStrategy().tableName( tableNode.getValue() );
      }
      else {
        //tableName = mappings.getNamingStrategy().propertyToTableName( className, path );
        Table ownerTable = collection.getOwner().getTable();
        //TODO mappings.getLogicalTableName(ownerTable)
        String logicalOwnerTableName = ownerTable.getName();
        //FIXME we don't have the associated entity table name here, has to be done in a second pass
        tableName = mappings.getNamingStrategy().collectionTableName(
            collection.getOwner().getEntityName(),
            logicalOwnerTableName ,
            null,
            null,
            path
        );
      }
      Attribute schemaNode = node.attribute( "schema" );
      String schema = schemaNode == null ?
          mappings.getSchemaName() : schemaNode.getValue();

      Attribute catalogNode = node.attribute( "catalog" );
      String catalog = catalogNode == null ?
          mappings.getCatalogName() : catalogNode.getValue();

      Table table = mappings.addTable(
          schema,
          catalog,
          tableName,
          getSubselect( node ),
          false
        );
      collection.setCollectionTable( table );
      bindComment(table, node);

      log.info(
          "Mapping collection: " + collection.getRole() +
          " -> " + collection.getCollectionTable().getName()
        );
    }

    // SORT
    Attribute sortedAtt = node.attribute( "sort" );
    // unsorted, natural, comparator.class.name
    if ( sortedAtt == null || sortedAtt.getValue().equals( "unsorted" ) ) {
      collection.setSorted( false );
    }
    else {
      collection.setSorted( true );
      String comparatorClassName = sortedAtt.getValue();
      if ( !comparatorClassName.equals( "natural" ) ) {
        collection.setComparatorClassName(comparatorClassName);
      }
    }

    // ORPHAN DELETE (used for programmer error detection)
    Attribute cascadeAtt = node.attribute( "cascade" );
    if ( cascadeAtt != null && cascadeAtt.getValue().indexOf( "delete-orphan" ) >= 0 ) {
      collection.setOrphanDelete( true );
    }

    // CUSTOM SQL
    handleCustomSQL( node, collection );
View Full Code Here

      Fetchable fetchable,
      Mappings mappings,
      String proxyVal,
      boolean defaultLazy
  ) {
    Attribute lazyNode = node.attribute( "lazy" );
    boolean isLazyTrue = lazyNode == null ?
        defaultLazy && fetchable.isLazy() : //fetch="join" overrides default laziness
        lazyNode.getValue().equals(proxyVal); //fetch="join" overrides default laziness
    fetchable.setLazy( isLazyTrue );
  }
View Full Code Here

    }
  }

  private static void bindColumnsOrFormula(Element node, SimpleValue simpleValue, String path,
      boolean isNullable, Mappings mappings) {
    Attribute formulaNode = node.attribute( "formula" );
    if ( formulaNode != null ) {
      Formula f = new Formula();
      f.setFormula( formulaNode.getText() );
      simpleValue.addFormula( f );
    }
    else {
      bindColumns( node, simpleValue, isNullable, true, path, mappings );
    }
View Full Code Here

    bindColumnsOrFormula( node, manyToOne, path, isNullable, mappings );
    initOuterJoinFetchSetting( node, manyToOne );
    initLaziness( node, manyToOne, mappings, true );

    Attribute ukName = node.attribute( "property-ref" );
    if ( ukName != null ) {
      manyToOne.setReferencedPropertyName( ukName.getValue() );
    }

    manyToOne.setReferencedEntityName( getEntityName( node, mappings ) );

    String embed = node.attributeValue( "embed-xml" );
    manyToOne.setEmbedded( embed == null || "true".equals( embed ) );

    String notFound = node.attributeValue( "not-found" );
    manyToOne.setIgnoreNotFound( "ignore".equals( notFound ) );

    if( ukName != null && !manyToOne.isIgnoreNotFound() ) {
      if ( !node.getName().equals("many-to-many") ) { //TODO: really bad, evil hack to fix!!!
        mappings.addSecondPass( new ManyToOneSecondPass(manyToOne) );
      }
    }

    Attribute fkNode = node.attribute( "foreign-key" );
    if ( fkNode != null ) manyToOne.setForeignKeyName( fkNode.getValue() );

    validateCascade( node, path );
  }
View Full Code Here

  }

  public static void bindAny(Element node, Any any, boolean isNullable, Mappings mappings)
      throws MappingException {
    any.setIdentifierType( getTypeFromXML( node ) );
    Attribute metaAttribute = node.attribute( "meta-type" );
    if ( metaAttribute != null ) {
      any.setMetaType( metaAttribute.getValue() );

      Iterator iter = node.elementIterator( "meta-value" );
      if ( iter.hasNext() ) {
        HashMap values = new HashMap();
        org.hibernate.type.Type metaType = TypeFactory.heuristicType( any.getMetaType() );
View Full Code Here

  public static void bindOneToOne(Element node, OneToOne oneToOne, String path, boolean isNullable,
      Mappings mappings) throws MappingException {

    bindColumns( node, oneToOne, isNullable, false, null, mappings );

    Attribute constrNode = node.attribute( "constrained" );
    boolean constrained = constrNode != null && constrNode.getValue().equals( "true" );
    oneToOne.setConstrained( constrained );

    oneToOne.setForeignKeyType( constrained ?
        ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :
        ForeignKeyDirection.FOREIGN_KEY_TO_PARENT );

    initOuterJoinFetchSetting( node, oneToOne );
    initLaziness( node, oneToOne, mappings, true );

    oneToOne.setEmbedded( "true".equals( node.attributeValue( "embed-xml" ) ) );

    Attribute fkNode = node.attribute( "foreign-key" );
    if ( fkNode != null ) oneToOne.setForeignKeyName( fkNode.getValue() );

    Attribute ukName = node.attribute( "property-ref" );
    if ( ukName != null ) oneToOne.setReferencedPropertyName( ukName.getValue() );

    oneToOne.setPropertyName( node.attributeValue( "name" ) );

    oneToOne.setReferencedEntityName( getEntityName( node, mappings ) );
View Full Code Here

TOP

Related Classes of org.dom4j.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.