use of org.qi4j.api.entity.EntityDescriptor in project qi4j-sdk by Qi4j.
the class EntityTypeSerializerTest method testEntityTypeSerializer.
@Test
public void testEntityTypeSerializer() throws RDFHandlerException {
EntityDescriptor entityDescriptor = module.entityDescriptor(TestEntity.class.getName());
Iterable<Statement> graph = serializer.serialize(entityDescriptor);
String[] prefixes = new String[] { "rdf", "dc", " vc", "qi4j" };
String[] namespaces = new String[] { Rdfs.RDF, DcRdf.NAMESPACE, "http://www.w3.org/2001/vcard-rdf/3.0#", Qi4jEntityType.NAMESPACE };
new RdfXmlSerializer().serialize(graph, new PrintWriter(System.out), prefixes, namespaces);
}
use of org.qi4j.api.entity.EntityDescriptor in project qi4j-sdk by Qi4j.
the class EntityResource method representHtml.
private Representation representHtml(final EntityState entity) {
return new WriterRepresentation(MediaType.TEXT_HTML) {
@Override
public void write(Writer writer) throws IOException {
PrintWriter out = new PrintWriter(writer);
out.println("<html><head><title>" + entity.identity() + "</title>" + "<link rel=\"alternate\" type=\"application/rdf+xml\" " + "href=\"" + entity.identity() + ".rdf\"/></head><body>");
out.println("<h1>" + entity.identity() + "</h1>");
out.println("<form method=\"post\" action=\"" + getRequest().getResourceRef().getPath() + "\">\n");
out.println("<fieldset><legend>Properties</legend>\n<table>");
final EntityDescriptor descriptor = entity.entityDescriptor();
for (PropertyDescriptor persistentProperty : descriptor.state().properties()) {
Object value = entity.propertyValueOf(persistentProperty.qualifiedName());
out.println("<tr><td>" + "<label for=\"" + persistentProperty.qualifiedName() + "\" >" + persistentProperty.qualifiedName().name() + "</label></td>\n" + "<td><input " + "size=\"80\" " + "type=\"text\" " + (persistentProperty.isImmutable() ? "readonly=\"true\" " : "") + "name=\"" + persistentProperty.qualifiedName() + "\" " + "value=\"" + (value == null ? "" : valueSerialization.serialize(value)) + "\"/></td></tr>");
}
out.println("</table></fieldset>\n");
out.println("<fieldset><legend>Associations</legend>\n<table>");
for (AssociationDescriptor associationType : descriptor.state().associations()) {
Object value = entity.associationValueOf(associationType.qualifiedName());
if (value == null) {
value = "";
}
out.println("<tr><td>" + "<label for=\"" + associationType.qualifiedName() + "\" >" + associationType.qualifiedName().name() + "</label></td>\n" + "<td><input " + "type=\"text\" " + "size=\"80\" " + "name=\"" + associationType.qualifiedName() + "\" " + "value=\"" + value + "\"/></td></tr>");
}
out.println("</table></fieldset>\n");
out.println("<fieldset><legend>ManyAssociations</legend>\n<table>");
for (AssociationDescriptor associationType : descriptor.state().manyAssociations()) {
ManyAssociationState identities = entity.manyAssociationValueOf(associationType.qualifiedName());
String value = "";
for (EntityReference identity : identities) {
value += identity.identity() + "\n";
}
out.println("<tr><td>" + "<label for=\"" + associationType.qualifiedName() + "\" >" + associationType.qualifiedName().name() + "</label></td>\n" + "<td><textarea " + "rows=\"10\" " + "cols=\"80\" " + "name=\"" + associationType.qualifiedName() + "\" >" + value + "</textarea></td></tr>");
}
out.println("</table></fieldset>\n");
out.println("<fieldset><legend>NamedAssociations</legend>\n<table>");
for (AssociationDescriptor associationType : descriptor.state().namedAssociations()) {
NamedAssociationState identities = entity.namedAssociationValueOf(associationType.qualifiedName());
String value = "";
for (String name : identities) {
value += name + "\n" + identities.get(name).identity() + "\n";
}
out.println("<tr><td>" + "<label for=\"" + associationType.qualifiedName() + "\" >" + associationType.qualifiedName().name() + "</label></td>\n" + "<td><textarea " + "rows=\"10\" " + "cols=\"80\" " + "name=\"" + associationType.qualifiedName() + "\" >" + value + "</textarea></td></tr>");
}
out.println("</table></fieldset>\n");
out.println("<input type=\"submit\" value=\"Update\"/></form>\n");
out.println("</body></html>\n");
}
};
}
use of org.qi4j.api.entity.EntityDescriptor in project qi4j-sdk by Qi4j.
the class PropertiesPanel method createData.
/**
* Create table table or properties using the supplied query
*
* @param query the Query
*
* @return TableModel
*/
protected TableModel createData(Query query) {
DefaultTableModel model = new DefaultTableModel();
for (Object qObj : query) {
AssociationStateHolder state = qi4jspi.stateOf((EntityComposite) qObj);
EntityDescriptor descriptor = qi4jspi.entityDescriptorFor((EntityComposite) qObj);
// genereate column, first time only
if (model.getColumnCount() < 1) {
for (PropertyDescriptor persistentPropertyDescriptor : descriptor.state().properties()) {
model.addColumn(persistentPropertyDescriptor.qualifiedName().name());
}
}
Object[] rowData = new Object[model.getColumnCount()];
int i = 0;
for (PropertyDescriptor persistentPropertyDescriptor : descriptor.state().properties()) {
rowData[i++] = state.propertyFor(persistentPropertyDescriptor.accessor());
}
model.addRow(rowData);
}
return model;
}
use of org.qi4j.api.entity.EntityDescriptor in project qi4j-sdk by Qi4j.
the class PDFWriter method writeTypeGeneralPage.
private void writeTypeGeneralPage(Object objectDesciptor) {
setFont(header5Font, header5FontSize);
writeString("General: ", headerLineSpace);
setFont(normalFont, normalFontSize);
if (objectDesciptor instanceof ServiceDetailDescriptor) {
ServiceDescriptor descriptor = ((ServiceDetailDescriptor) objectDesciptor).descriptor();
writeString("- identity: " + descriptor.identity());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
writeString("- startup: " + ((ServiceDetailDescriptor) objectDesciptor).descriptor().isInstantiateOnStartup());
} else if (objectDesciptor instanceof EntityDetailDescriptor) {
EntityDescriptor descriptor = ((EntityDetailDescriptor) objectDesciptor).descriptor();
writeString("- name: " + descriptor.toString());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
} else if (objectDesciptor instanceof ValueDetailDescriptor) {
ValueDescriptor descriptor = ((ValueDetailDescriptor) objectDesciptor).descriptor();
writeString("- name: " + descriptor.toString());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
} else if (objectDesciptor instanceof ObjectDetailDescriptor) {
ObjectDescriptor descriptor = ((ObjectDetailDescriptor) objectDesciptor).descriptor();
writeString("- name: " + descriptor.toString());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
} else if (objectDesciptor instanceof CompositeDetailDescriptor) {
CompositeDescriptor descriptor = ((CompositeDetailDescriptor) objectDesciptor).descriptor();
writeString("- name: " + descriptor.toString());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
}
}
use of org.qi4j.api.entity.EntityDescriptor in project qi4j-sdk by Qi4j.
the class StateInjectionProviderFactory method newInjectionProvider.
@Override
public InjectionProvider newInjectionProvider(Resolution resolution, DependencyModel dependencyModel) throws InvalidInjectionException {
if (StateHolder.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State StateHolder properties;
return new StateInjectionProvider();
} else if (UnitOfWork.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
if (!(resolution.model() instanceof EntityDescriptor)) {
throw new InvalidInjectionException("Only EntityComposites can be injected with '@State UnitOfWork'");
}
return new UnitOfWorkInjectionProvider();
} else if (Property.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State Property<String> name;
StateDescriptor descriptor;
descriptor = ((StatefulCompositeDescriptor) resolution.model()).state();
State annotation = (State) dependencyModel.injectionAnnotation();
String name;
if (annotation.value().isEmpty()) {
name = resolution.field().getName();
} else {
name = annotation.value();
}
PropertyDescriptor propertyDescriptor = descriptor.findPropertyModelByName(name);
return new PropertyInjectionProvider(propertyDescriptor);
} else if (Association.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State Association<MyEntity> name;
AssociationStateDescriptor descriptor = ((EntityDescriptor) resolution.model()).state();
State annotation = (State) dependencyModel.injectionAnnotation();
String name;
if (annotation.value().isEmpty()) {
name = resolution.field().getName();
} else {
name = annotation.value();
}
AssociationDescriptor model = descriptor.getAssociationByName(name);
return new AssociationInjectionProvider(model);
} else if (ManyAssociation.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State ManyAssociation<MyEntity> name;
AssociationStateDescriptor descriptor = ((EntityDescriptor) resolution.model()).state();
State annotation = (State) dependencyModel.injectionAnnotation();
String name;
if (annotation.value().isEmpty()) {
name = resolution.field().getName();
} else {
name = annotation.value();
}
AssociationDescriptor model = descriptor.getManyAssociationByName(name);
return new ManyAssociationInjectionProvider(model);
} else if (NamedAssociation.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State NamedAssociation<MyEntity> name;
AssociationStateDescriptor descriptor = ((EntityDescriptor) resolution.model()).state();
State annotation = (State) dependencyModel.injectionAnnotation();
String name;
if (annotation.value().isEmpty()) {
name = resolution.field().getName();
} else {
name = annotation.value();
}
AssociationDescriptor model = descriptor.getNamedAssociationByName(name);
return new NamedAssociationInjectionProvider(model);
}
throw new InjectionProviderException("Injected value has invalid type");
}
Aggregations