if (registered.containsKey(aT.getId())) {
throw new ConfigException("Duplicate id '" + aT.getId() + "'");
}
- registered.put(aT.getId(), wrap(id.getId() + ".", aT));
+ registered.put(aT.getId(), wrap(aT));
}
/**
* Object to wrap.
* @return Wrapped object.
*/
- public abstract T wrap(String aPrefix, T aT);
+ public abstract T wrap(T aT);
/*
* (non-Javadoc)
* @param aType
* Document type to wrap.
*/
- public RobustDocumentType(String aPrefix, DocumentType aType) {
- super(aPrefix, aType);
+ public RobustDocumentType(DocumentType aType) {
+ super(aType);
type = aType;
}
/**
* Constructs the wrapper.
*
- * @param aPrefix
- * prefix to use for ids.
* @param aId
* Id.
* @param aFilter
* Filter to wrap.
*/
public RobustFilter(String aPrefix, Filter aFilter) {
- super(aPrefix, aFilter);
+ super(aFilter);
filter = aFilter;
}
private Id<T> id;
- public RobustIdentifiable(String aPrefix, Identifiable<T> aIdentifiable) {
- notNull("prefix", aPrefix);
+ public RobustIdentifiable(Identifiable<T> aIdentifiable) {
notNull("identifiable", aIdentifiable);
try {
id = aIdentifiable.getId();
if (id == null) {
throwConfigException("identifiable.getId() returned null", null);
}
- id = new Id<T>(aPrefix + id.getId());
} catch (Exception e) {
throwConfigException("identifiable.getId() threw exception", e);
}
* @param aTransformation
* Wrapped transformation.
*/
- public RobustTransformation(String aPrefix, Transformation aTransformation) {
- super(aPrefix, aTransformation);
+ public RobustTransformation(Transformation aTransformation) {
+ super(aTransformation);
transformation = aTransformation;
}
}
@Override
- public DocumentType wrap(String aPrefix, DocumentType aT) {
- return new RobustDocumentType("", aT);
+ public DocumentType wrap(DocumentType aT) {
+ return new RobustDocumentType(aT);
}
}
}
@Override
- public Transformation wrap(String aPrefix,
- Transformation aTransformation) {
- return new RobustTransformation("", aTransformation);
+ public Transformation wrap(Transformation aTransformation) {
+ return new RobustTransformation(aTransformation);
}
}
}
@Override
- public Filter wrap(String aPrefix, Filter aFilter) {
+ public Filter wrap(Filter aFilter) {
return new RobustFilter("", aFilter);
}
}
config = aConfig;
routerConfigs = new ConfigImpl<RouterConfig>(RouterConfig.class,
new Id<Config>(aApplication)) {
- public RouterConfig wrap(final String aPrefix, final RouterConfig aT) {
+ public RouterConfig wrap(final RouterConfig aT) {
return new RouterConfig() {
@Override
public Id<RouterConfig> getId() {
- return new Id<RouterConfig>(aT.getId().toString());
+ return aT.getId();
}
@Override
Config<StringClassInterface> c1 = new ConfigImpl(
StringClassInterface.class, id("c1")) {
@Override
- public Identifiable wrap(String aPrefix, Identifiable aT) {
+ public Identifiable wrap(Identifiable aT) {
return aT;
}
};
Config<StringClassInterface> c2 = new ConfigImpl(
StringClassInterface.class, id("c2")) {
@Override
- public Identifiable wrap(String aPrefix, Identifiable aT) {
+ public Identifiable wrap(Identifiable aT) {
return aT;
}
};
Config<StringClassInterface> c1 = new ConfigImpl(
StringClassInterface.class, id("c1")) {
@Override
- public Identifiable wrap(String aPrefix, Identifiable aT) {
+ public Identifiable wrap(Identifiable aT) {
return aT;
}
};
Config<StringClassInterface> c2 = new ConfigImpl(
StringClassInterface.class, id("c1")) {
@Override
- public Identifiable wrap(String aPrefix, Identifiable aT) {
+ public Identifiable wrap(Identifiable aT) {
return aT;
}
};
Config<StringClassInterface> c1 = new ConfigImpl(
StringClassInterface.class, id("c.x")) {
@Override
- public Identifiable wrap(String aPrefix, Identifiable aT) {
+ public Identifiable wrap(Identifiable aT) {
return aT;
}
};
Config<StringClassInterface> c2 = new ConfigImpl(
StringClassInterface.class, id("c")) {
@Override
- public Identifiable wrap(String aPrefix, Identifiable aT) {
+ public Identifiable wrap(Identifiable aT) {
return aT;
}
};
}
private static class MyTypeWrapper implements MyType {
- private String prefix;
private MyType type;
- public MyTypeWrapper(String aPrefix, MyType aType) {
- prefix = aPrefix;
+ public MyTypeWrapper(MyType aType) {
type = aType;
}
@Override
public Id getId() {
- return new Id(prefix + type.getId().getId());
+ return type.getId();
}
}
}
@Override
- public MyType wrap(String aPrefix, MyType aT) {
- return new MyTypeWrapper(aPrefix, aT);
+ public MyType wrap(MyType aT) {
+ return new MyTypeWrapper(aT);
}
}
assertTrue(firstValue instanceof MyTypeWrapper);
assertSame(type1, ((MyTypeWrapper) firstValue).getType());
- assertEquals(CONFIG_TYPE + "." + type1.getId().getId(), firstValue
- .getId().getId());
+ assertEquals(type1.getId().getId(), firstValue.getId().getId());
// add another one.
MyType type2 = mock(MyType.class);
public void setUp() {
documentType = mock(DocumentType.class);
when(documentType.getId()).thenReturn(new Id<DocumentType>("docid"));
- robust = new RobustDocumentType("app1", documentType);
+ robust = new RobustDocumentType(documentType);
source = mock(DOMSource.class);
}
public void testIdIsNull() {
when(ident.getId()).thenReturn(null);
RobustIdentifiable<Integer> robust = new RobustIdentifiable<Integer>(
- "prefix", ident);
+ ident);
}
@Test(expected = ConfigException.class)
public void testIdThrowsException() {
doThrow(new RuntimeException("xxx")).when(ident).getId();
RobustIdentifiable<Integer> robust = new RobustIdentifiable<Integer>(
- "prefix", ident);
+ ident);
}
@Test
public void testNormalCase() {
when(ident.getId()).thenReturn(new Id<Integer>("myid"));
RobustIdentifiable<Integer> robust = new RobustIdentifiable<Integer>(
- "prefix.", ident);
- assertEquals("prefix.myid", robust.getId().toString());
+ ident);
+ assertEquals("myid", robust.getId().toString());
// changes later do not have any effect, the id should be immutable.
when(ident.getId()).thenReturn(new Id<Integer>("myid2"));
- assertEquals("prefix.myid", robust.getId().toString());
+ assertEquals("myid", robust.getId().toString());
}
@Test
when(ident3.getId()).thenReturn(new Id<Integer>("x"));
RobustIdentifiable<Integer> robust1 = new RobustIdentifiable<Integer>(
- "prefix.", ident1);
+ ident1);
RobustIdentifiable<Integer> robust2 = new RobustIdentifiable<Integer>(
- "prefix.", ident2);
+ ident2);
RobustIdentifiable<Integer> robust3 = new RobustIdentifiable<Integer>(
- "prefix.", ident3);
+ ident3);
assertEquals(robust1, robust1);
assertEquals(robust1, robust3);
public void setUp() {
transformation = mock(Transformation.class);
when(transformation.getId()).thenReturn(new Id<Transformation>("t1"));
- robust = new RobustTransformation("transformation", transformation);
+ robust = new RobustTransformation(transformation);
source = mock(DOMSource.class);
resSource = mock(DOMSource.class);
}