org.qi4j.api.common.QualifiedName类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(14.9k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中org.qi4j.api.common.QualifiedName类的一些代码示例,展示了QualifiedName类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QualifiedName类的具体详情如下:
包路径:org.qi4j.api.common.QualifiedName
类名称:QualifiedName

QualifiedName介绍

[英]QualifiedName is a representation of Property names to their full declaration.

A QualifiedName is created by combining the name of a method and the name of the type that declares the method. This class also contains many static utility methods to manage QualifiedName instances.

NOTE: Unless you do very generic libraries, entity stores and other extensions that is deeply coupled into the Zest runtime, it is very unlikely you will need to use this class directly.

It is also important to notice that the QualifiedName needs to be long-term stable, as the names are written to persistent storage. So any changes in the formatting must be made in a backward-compatible manner .

The QualifiedName has two intrinsic parts, one being the type and the other the name. The type comes from the class where the QualifiedName originates from and internally kept as a TypeNameinstance. The name is the name from the method name. When the QualifiedName instance is converted to an external string representation, via the offical and formal #toString() method, the type is normalized, i.e. any dollar characters ($) in the name are replaced by dashes (-), to make them URI friendly.

QualifiedName instances are immutable, implements #hashCode() and #equals(Object) as a value object and can safely be used as keys in java.util.Map.
[中]QualifiedName是财产名称的完整声明。
QualifiedName是通过组合方法的名称和声明该方法的类型的名称来创建的。此类还包含许多用于管理QualifiedName实例的静态实用程序方法。
注意:除非您使用非常通用的库、实体存储和其他深度耦合到Zest运行时的扩展,否则您不太可能需要直接使用这个类。
还需要注意的是,QualifiedName需要长期稳定,因为名称会写入持久存储。因此,格式的任何更改都必须以向后兼容的方式进行。
QualifiedName有两个固有部分,一个是类型,另一个是名称。该类型来自QualifiedName来源的类,并在内部作为TypeNameinstance保存。名称是方法名称中的名称。当QualifiedName实例通过正式的#toString()方法转换为外部字符串表示形式时,该类型将被规范化,即名称中的任何美元字符($)都将替换为破折号(-),以使其对URI友好。
QualifiedName实例是不可变的,将#hashCode()和#equals(Object)实现为值对象,可以安全地用作java中的键。util。地图

代码示例

代码示例来源:origin: org.qi4j.library/org.qi4j.library.rest-server

@Override
  public String map( PropertyDescriptor propertyDescriptor )
  {
    return propertyDescriptor.qualifiedName().name();
  }
}, descriptor.state().properties() ).iterator() );

代码示例来源:origin: org.qi4j.extension/org.qi4j.extension.indexing-rdf

public void addDefaultTriples( String resultType )
{
  triples.add(
    new Triple(
      "?entityType",
      "rdfs:subClassOf",
      "<" + Classes.toURI( resultType ) + ">",
      false )
  );
  triples.add(
    new Triple(
      "?entity",
      "rdf:type",
      "?entityType",
      false )
  );
  triples.add(
    new Triple(
      "?entity",
      addNamespace( QualifiedName.fromClass( Identity.class, "identity" ).toNamespace() ) + ":identity",
      "?identity",
      false
    )
  );
}

代码示例来源:origin: org.qi4j.core/org.qi4j.core.api

/**
 * Creates a QualifiedName instance from the Class and a given name.
 * <p>
 * This factory method converts the {@code type} to a {@link TypeName} and appends the given {@code name}.
 *
 * @param type The Class that is the base of the QualifiedName.
 * @param name The qualifier name which will be appended to the base name derived from the {@code type} argument.
 *
 * @return A QualifiedName instance representing the {@code type} and {@code name} arguments.
 *
 * @throws NullArgumentException if any of the two arguments are {@code null}, or if the name string is empty.
 */
public static QualifiedName fromClass( Class type, String name )
{
  return new QualifiedName( TypeName.nameOf( type ), name );
}

代码示例来源:origin: org.qi4j.extension/org.qi4j.extension.indexing-rdf

public Triple addTripleAssociation( AssociationFunction<?> associationReference, boolean optional )
{
  String subject = "?entity";
  if( associationReference.traversedAssociation() != null )
  {
    subject = addTripleAssociation( associationReference.traversedAssociation(), false ).value;
  }
  QualifiedName qualifiedName = QualifiedName.fromAccessor( associationReference.accessor() );
  String prefix = addNamespace( qualifiedName.toNamespace() );
  return addTriple( subject, prefix + ":" + qualifiedName.name(), optional );
}

代码示例来源:origin: org.qi4j.library/org.qi4j.library.conversion

if( IDENTITY_STATE_NAME.equals( ePropDesc.qualifiedName() ) )
  PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( ePropDesc.qualifiedName().name() );
  eState.propertyFor( ePropDesc.accessor() ).set( vState.propertyFor( vPropDesc.accessor() ).get() );
try
  AssociationDescriptor vAssocDesc = vStateDesc.getAssociationByName( eAssocDesc.qualifiedName().name() );
  eAssoc.set( vState.associationFor( vAssocDesc.accessor() ).get() );
      = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
    if( STRING_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) )
    = vStateDesc.getManyAssociationByName( eAssocDesc.qualifiedName().name() );
  ManyAssociation<Object> vManyAss = vState.manyAssociationFor( vAssDesc.accessor() );
  for( Object ass : eManyAssoc.toList() )
      = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
    if( STRING_COLLECTION_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) )
    = vStateDesc.getNamedAssociationByName( eAssocDesc.qualifiedName().name() );
  NamedAssociation<Object> vNamedAssoc = vState.namedAssociationFor( vAssocDesc.accessor() );
  for( String assocName : Iterables.toList( eNamedAssoc ) )
      = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
    if( STRING_MAP_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) )

代码示例来源:origin: org.qi4j.core/org.qi4j.core.api

/**
 * Returns the URI of the QualifiedName.
 *
 * <p>
 * The URI is the {@link #toNamespace()} followed by the {@code name} component.
 * <p>
 *
 * @return the URI of the QualifiedName.
 *
 * @see #toNamespace()
 */
public String toURI()
{
  return toNamespace() + name;
}

代码示例来源:origin: org.qi4j.core/org.qi4j.core.api

/**
 * Creates a QualifiedName from a method.
 * <p>
 * This factory method will create a QualifiedName from the Method itself.
 *
 * </p>
 *
 * @param method Type method that returns a Property, for which the QualifiedName will be representing.
 *
 * @return A QualifiedName representing this method.
 *
 * @throws NullArgumentException If the {@code method} argument passed is null.
 */
public static QualifiedName fromAccessor( AccessibleObject method )
{
  NullArgumentException.validateNotNull( "method", method );
  return fromClass( ( (Member) method ).getDeclaringClass(), ( (Member) method ).getName() );
}

代码示例来源:origin: org.qi4j.extension/org.qi4j.extension.indexing-rdf

public Triple addTripleManyAssociation( final ManyAssociationFunction<?> manyAssociationReference,
                    final boolean optional
)
{
  AssociationFunction<?> traversedAssociation = manyAssociationReference.traversedAssociation();
  String subject = "?entity";
  if( traversedAssociation != null )
  {
    subject = addTripleAssociation( traversedAssociation, false ).value;
  }
  QualifiedName qualifiedName = QualifiedName.fromAccessor( manyAssociationReference.accessor() );
  String predicatePrefix = addNamespace( qualifiedName.toNamespace() );
  String predicate = predicatePrefix + ":" + qualifiedName.name();
  Triple collectionTriple = addTriple( subject, predicate, optional );
  String liSubject = collectionTriple.value;
  return addTriple( liSubject, "rdf:li", false );
}

代码示例来源:origin: org.qi4j.library/org.qi4j.library.conversion

if( IDENTITY_STATE_NAME.equals( ePropDesc.qualifiedName() ) )
      = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
    if( STRING_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) )
      = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
    if( STRING_COLLECTION_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) )
      = vStateDesc.findPropertyModelByName( eAssocDesc.qualifiedName().name() );
    if( STRING_MAP_TYPE_SPEC.satisfiedBy( vPropDesc.valueType() ) )

代码示例来源:origin: org.qi4j.library/org.qi4j.library.sql

@Override
public void exportDataSources()
    throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException
{
  for ( ServiceReference<DataSource> dataSource : dataSources ) {
    String name = dataSource.identity();
    Module module = ( Module ) spi.moduleOf( dataSource );
    EntityDescriptor descriptor = module.entityDescriptor( DataSourceConfiguration.class.getName() );
    List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>();
    Map<String, AccessibleObject> properties = new LinkedHashMap<String, AccessibleObject>();
    for ( PropertyDescriptor persistentProperty : descriptor.state().properties() ) {
      if ( !persistentProperty.isImmutable() ) {
        String propertyName = persistentProperty.qualifiedName().name();
        String type = persistentProperty.valueType().mainType().getName();
        attributes.add( new MBeanAttributeInfo( propertyName, type, propertyName, true, true, type.equals( "java.lang.Boolean" ) ) );
        properties.put( propertyName, persistentProperty.accessor() );
      }
    }
    List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>();
    operations.add( new MBeanOperationInfo( "restart", "Restart DataSource", new MBeanParameterInfo[ 0 ], "void", MBeanOperationInfo.ACTION_INFO ) );
    MBeanInfo mbeanInfo = new MBeanInfo( DataSourceConfiguration.class.getName(), name, attributes.toArray( new MBeanAttributeInfo[ attributes.size() ] ), null, operations.toArray( new MBeanOperationInfo[ operations.size() ] ), null );
    Object mbean = new ConfigurableDataSource( dataSourceService, mbeanInfo, name, properties );
    ObjectName configurableDataSourceName = new ObjectName( "Zest:application=" + application.name() + ",class=Datasource,name=" + name );
    server.registerMBean( mbean, configurableDataSourceName );
    configurationNames.add( configurableDataSourceName );
  }
}

代码示例来源:origin: org.qi4j.extension/org.qi4j.extension.indexing-rdf

public Triple addTriple( final PropertyFunction<?> propertyFunction, boolean optional )
{
  String subject = "?entity";
  if( propertyFunction.traversedAssociation() != null )
  {
    subject = addTripleAssociation( propertyFunction.traversedAssociation(), false ).value;
  }
  else if( propertyFunction.traversedProperty() != null )
  {
    subject = addTriple( propertyFunction.traversedProperty(), false ).value;
  }
  QualifiedName qualifiedName = QualifiedName.fromAccessor( propertyFunction.accessor() );
  String prefix = addNamespace( qualifiedName.toNamespace() );
  return addTriple( subject, prefix + ":" + qualifiedName.name(), optional );
}

代码示例来源:origin: org.qi4j.core/org.qi4j.core.api

/**
 * Creates a Qualified name from a type as string and a name qualifier.
 *
 * @param type The type name as a a string, which must be properly formatted. No checks for correctly formatted
 *             type name is performed.
 * @param name The qualifier name which will be appended to the base name derived from the {@code type} argument.
 *
 * @return A QualifiedName instance representing the {@code type} and {@code name} arguments.
 *
 * @throws NullArgumentException if any of the two arguments are {@code null} or either string is empty.
 */
public static QualifiedName fromName( String type, String name )
{
  return new QualifiedName( TypeName.nameOf( type ), name );
}

代码示例来源:origin: org.qi4j.library/org.qi4j.library.rest-server

@Override
  public EntityReference map( AssociationDescriptor associationDescriptor )
  {
    Parameter param = queryAsForm.getFirst( associationDescriptor.qualifiedName().name() );
    if( param == null )
    {
      param = entityAsForm.getFirst( associationDescriptor.qualifiedName().name() );
    }
    if( param != null )
    {
      return EntityReference.parseEntityReference( param.getValue() );
    }
    else
    {
      return null;
    }
  }
},

代码示例来源:origin: org.qi4j.core/org.qi4j.core.api

/**
 * Creates a QualifiedName from the external string format of QualifiedName.
 * <p>
 * This factory method is the reverse of {@link QualifiedName#toString() }  method, and creates a new QualifiedName
 * instance from the string representation of the QualifiedName.
 * </p>
 *
 * @param fullQualifiedName The QualifiedName external string representation to be converted back into a QualifiedName
 *                      instance.
 *
 * @return The QualifiedName instance represented by the {@code qualifiedName} argument.
 *
 * @throws IllegalArgumentException If the {@code qualifiedName} argument has wrong format.
 */
public static QualifiedName fromFQN( String fullQualifiedName )
{
  NullArgumentException.validateNotEmpty( "qualifiedName", fullQualifiedName );
  int idx = fullQualifiedName.lastIndexOf( ":" );
  if( idx == -1 )
  {
    throw new IllegalArgumentException( "Name '" + fullQualifiedName + "' is not a qualified name" );
  }
  final String type = fullQualifiedName.substring( 0, idx );
  final String name = fullQualifiedName.substring( idx + 1 );
  return new QualifiedName( TypeName.nameOf( type ), name );
}

代码示例来源:origin: org.qi4j.library/org.qi4j.library.rest-server

@Override
public Object map( PropertyDescriptor propertyDescriptor )
{
  Parameter param = queryAsForm.getFirst( propertyDescriptor.qualifiedName().name() );
  if( param == null )
  {
    param = entityAsForm.getFirst( propertyDescriptor.qualifiedName().name() );
  }
  if( param != null )
  {
    String value = param.getValue();
    if( value != null )
    {
      try
      {
        return valueDeserializer.deserialize( propertyDescriptor.valueType(), value );
      }
      catch( ValueSerializationException e )
      {
        throw new IllegalArgumentException( "Query parameter has invalid JSON format", e );
      }
    }
  }
  return null;
}
},

代码示例来源:origin: org.qi4j.library/org.qi4j.library.conversion

@Override
  public Map<String, EntityReference> map( AssociationDescriptor descriptor )
  {
    AssociationDescriptor associationDescriptor;
    try
    {
      String associationName = descriptor.qualifiedName().name();
      AssociationStateDescriptor entityState = entityDescriptor.state();
      associationDescriptor = entityState.getNamedAssociationByName( associationName );
    }
    catch( IllegalArgumentException e )
    {
      return Collections.emptyMap();
    }
    AccessibleObject associationMethod = associationDescriptor.accessor();
    NamedAssociation<Object> assoc = associationState.namedAssociationFor( associationMethod );
    Map<String, EntityReference> refs = new LinkedHashMap<>( assoc.count() );
    for( String name : assoc )
    {
      refs.put( name, EntityReference.entityReferenceFor( assoc.get( name ) ) );
    }
    return refs;
  }
} );

代码示例来源:origin: org.qi4j.library/org.qi4j.library.conversion

@Override
  public Object map( PropertyDescriptor ePropDesc )
  {
    String propName = ePropDesc.qualifiedName().name();
    try
    {
      PropertyDescriptor vPropDesc = vStateDesc.findPropertyModelByName( propName );
      return vState.propertyFor( vPropDesc.accessor() ).get();
    }
    catch( IllegalArgumentException propNotFoundOnValue )
    {
      // Property not found on Value
      return null;
    }
  }
};

代码示例来源:origin: org.qi4j.library/org.qi4j.library.conversion

@Override
  public Iterable<EntityReference> map( final AssociationDescriptor descriptor )
  {
    AssociationDescriptor associationDescriptor;
    try
    {
      String associationName = descriptor.qualifiedName().name();
      AssociationStateDescriptor entityState = entityDescriptor.state();
      associationDescriptor = entityState.getManyAssociationByName( associationName );
    }
    catch( IllegalArgumentException e )
    {
      return Iterables.empty();
    }
    ManyAssociation<?> state = associationState.manyAssociationFor( associationDescriptor.accessor() );
    List<EntityReference> refs = new ArrayList<>( state.count() );
    for( Object entity : state )
    {
      refs.add( EntityReference.entityReferenceFor( entity ) );
    }
    return refs;
  }
},

代码示例来源:origin: org.qi4j.library/org.qi4j.library.rest-server

if( o == null )
  json.put( propertyDescriptor.qualifiedName().name(), JSONObject.NULL );
  json.put( propertyDescriptor.qualifiedName().name(), o.toString() );

代码示例来源:origin: org.qi4j.library/org.qi4j.library.conversion

@Override
  public EntityReference map( AssociationDescriptor descriptor )
  {
    AssociationDescriptor associationDescriptor;
    try
    {
      associationDescriptor = entityDescriptor.state()
        .getAssociationByName( descriptor.qualifiedName().name() );
    }
    catch( IllegalArgumentException e )
    {
      return null;
    }
    AccessibleObject associationMethod = associationDescriptor.accessor();
    Association<Object> association = associationState.associationFor( associationMethod );
    return EntityReference.entityReferenceFor( association.get() );
  }
},

相关文章

微信公众号

最新文章

更多