Search in sources :

Example 1 with QualifiedName

use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.

the class NamedAssociationModel method bind.

@Override
public void bind(Resolution resolution) throws BindingException {
    builderInfo = new AssociationInfo() {

        @Override
        public boolean isImmutable() {
            return false;
        }

        @Override
        public QualifiedName qualifiedName() {
            return qualifiedName;
        }

        @Override
        public Type type() {
            return type;
        }

        @Override
        public void checkConstraints(Object value) throws ConstraintViolationException {
            NamedAssociationModel.this.checkConstraints(value);
        }
    };
    if (type instanceof TypeVariable) {
        Class mainType = first(resolution.model().types());
        type = Classes.resolveTypeVariable((TypeVariable) type, ((Member) accessor).getDeclaringClass(), mainType);
    }
}
Also used : Type(java.lang.reflect.Type) GenericAssociationInfo(org.qi4j.api.association.GenericAssociationInfo) TypeVariable(java.lang.reflect.TypeVariable) QualifiedName(org.qi4j.api.common.QualifiedName) ConstraintViolationException(org.qi4j.api.constraint.ConstraintViolationException) AccessibleObject(java.lang.reflect.AccessibleObject) Member(java.lang.reflect.Member)

Example 2 with QualifiedName

use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.

the class Triples method addTripleManyAssociation.

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);
}
Also used : QualifiedName(org.qi4j.api.common.QualifiedName)

Example 3 with QualifiedName

use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.

the class GaeEntityState method initializeValueTypes.

private HashMap<QualifiedName, ValueType> initializeValueTypes(EntityDescriptor descriptor) {
    HashMap<QualifiedName, ValueType> result = new HashMap<QualifiedName, ValueType>();
    for (PropertyDescriptor persistent : descriptor.state().properties()) {
        if (persistent.valueType() instanceof ValueCompositeType) {
            QualifiedName name = persistent.qualifiedName();
            result.put(name, persistent.valueType());
        }
    }
    return result;
}
Also used : PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) ValueType(org.qi4j.api.type.ValueType) HashMap(java.util.HashMap) QualifiedName(org.qi4j.api.common.QualifiedName) ValueCompositeType(org.qi4j.api.type.ValueCompositeType)

Example 4 with QualifiedName

use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.

the class ValueCompositeCxfType method readObject.

@Override
public Object readObject(final MessageReader reader, final Context context) throws DatabindingException {
    QName qname = getSchemaType();
    final String className = (qname.getNamespaceURI() + "." + qname.getLocalPart()).substring(20);
    // Read attributes
    ValueDescriptor descriptor = module.valueDescriptor(className);
    StateDescriptor stateDescriptor = descriptor.state();
    final Map<QualifiedName, Object> values = new HashMap<QualifiedName, Object>();
    while (reader.hasMoreElementReaders()) {
        MessageReader childReader = reader.getNextElementReader();
        QName childName = childReader.getName();
        QualifiedName childQualifiedName = QualifiedName.fromClass((Class) typeClass, childName.getLocalPart());
        PropertyDescriptor propertyDescriptor = stateDescriptor.findPropertyModelByQualifiedName(childQualifiedName);
        Type propertyType = propertyDescriptor.type();
        AegisType type = getTypeMapping().getType(propertyType);
        Object value = type.readObject(childReader, context);
        values.put(childQualifiedName, value);
    }
    ValueBuilder<?> builder = module.newValueBuilderWithState((Class<?>) typeClass, new Function<PropertyDescriptor, Object>() {

        @Override
        public Object map(PropertyDescriptor descriptor1) {
            return values.get(descriptor1.qualifiedName());
        }
    }, new Function<AssociationDescriptor, EntityReference>() {

        @Override
        public EntityReference map(AssociationDescriptor descriptor) {
            Object value = values.get(descriptor.qualifiedName());
            if (value == null)
                return null;
            else
                return EntityReference.parseEntityReference(value.toString());
        }
    }, new Function<AssociationDescriptor, Iterable<EntityReference>>() {

        @Override
        public Iterable<EntityReference> map(AssociationDescriptor descriptor) {
            Object value = values.get(descriptor.qualifiedName());
            if (value == null)
                return Iterables.empty();
            else {
                String[] ids = value.toString().split(",");
                List<EntityReference> references = new ArrayList<EntityReference>();
                for (int i = 0; i < ids.length; i++) {
                    String id = ids[i];
                    references.add(EntityReference.parseEntityReference(id));
                }
                return references;
            }
        }
    });
    return builder.newInstance();
}
Also used : PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) QualifiedName(org.qi4j.api.common.QualifiedName) MessageReader(org.apache.cxf.aegis.xml.MessageReader) AssociationDescriptor(org.qi4j.api.association.AssociationDescriptor) CollectionType(org.apache.cxf.aegis.type.collection.CollectionType) MapType(org.apache.cxf.aegis.type.collection.MapType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) AegisType(org.apache.cxf.aegis.type.AegisType) StateDescriptor(org.qi4j.api.composite.StateDescriptor) EntityReference(org.qi4j.api.entity.EntityReference)

Example 5 with QualifiedName

use of org.qi4j.api.common.QualifiedName in project qi4j-sdk by Qi4j.

the class AbstractSQLStartup method extractManyAssociationQNames.

private void extractManyAssociationQNames(EntityDescriptor entityDesc, Map<QualifiedName, QNameInfo> extractedQNames, Set<QualifiedName> newQNames, Boolean setQNameTableNameToNull) {
    for (AssociationDescriptor mAssoDesc : entityDesc.state().manyAssociations()) {
        QualifiedName qName = mAssoDesc.qualifiedName();
        if (SQLSkeletonUtil.isQueryable(mAssoDesc.accessor())) {
            if (!extractedQNames.containsKey(qName)) {
                // 
                extractedQNames.put(// 
                qName, // 
                QNameInfo.fromManyAssociation(// 
                qName, setQNameTableNameToNull ? null : (QNAME_TABLE_NAME_PREFIX + extractedQNames.size()), // 
                mAssoDesc));
                newQNames.add(qName);
            }
        }
    }
}
Also used : QualifiedName(org.qi4j.api.common.QualifiedName) AssociationDescriptor(org.qi4j.api.association.AssociationDescriptor)

Aggregations

QualifiedName (org.qi4j.api.common.QualifiedName)30 HashMap (java.util.HashMap)10 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)10 EntityReference (org.qi4j.api.entity.EntityReference)9 ArrayList (java.util.ArrayList)7 AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)7 List (java.util.List)6 Map (java.util.Map)6 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)6 QNameInfo (org.qi4j.index.sql.support.common.QNameInfo)6 EntityStoreException (org.qi4j.spi.entitystore.EntityStoreException)6 Type (java.lang.reflect.Type)5 Member (java.lang.reflect.Member)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 AccessibleObject (java.lang.reflect.AccessibleObject)3 TypeVariable (java.lang.reflect.TypeVariable)3 HashSet (java.util.HashSet)3 GenericAssociationInfo (org.qi4j.api.association.GenericAssociationInfo)3