private void createTarget(ArtificerRelationship artificerRelationship, Target target) throws Exception { ArtificerTarget artificerTarget = new ArtificerTarget(); artificerTarget.setTarget(relationshipFactory.createRelationship(target.getValue(), entityManager)); // Use reflection to get the 'artifact type' enum attribute found on // most (all?) targets. Unfortunately, the method and field are // redefined in each subclass of Target. // Get ^^^ changed in the spec! try { Method m = target.getClass().getMethod("getArtifactType"); Object o = m.invoke(target); // the enum itself m = o.getClass().getMethod("name"); String targetType = (String) m.invoke(o); artificerTarget.setTargetType(targetType); } catch (Exception e) { // eat it } artificerTarget.setRelationship(artificerRelationship); for (QName key : target.getOtherAttributes().keySet()) { String value = target.getOtherAttributes().get(key); artificerTarget.getOtherAttributes().put(key.toString(), value); } artificerRelationship.getTargets().add(artificerTarget); } }
Target target = new Target(); target.setValue(targetUUID); target.getOtherAttributes().putAll(targetOtherAttributes); relationship.getRelationshipTarget().add(target);
private <T> T createTarget(Class<T> targetClass, ArtificerTarget artificerTarget) throws Exception { T t = targetClass.newInstance(); Target target = (Target) t; if (artificerTarget != null) { String targetedUuid = artificerTarget.getTarget().getUuid(); target.setValue(targetedUuid); String href = String.format("%1$s/%2$s/%3$s", artificerTarget.getTarget().getModel(), artificerTarget.getTarget().getType(), targetedUuid); target.setHref(href); setOtherAttributes(artificerTarget.getOtherAttributes(), target.getOtherAttributes()); } return t; } }
Target relationshipTarget = new Target(); relationshipTarget.setValue("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa6b"); relationshipTarget.getOtherAttributes().put( new QName("xlink:href"), "http://example.org/s-ramp/xsd/XsdDocument/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa6b"); relationshipTarget2.getOtherAttributes().put( new QName("xlink:href"), "http://example.org/s-ramp/xsd/XsdDocument/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa6c");