public ConfigModel.Property getProperty(String xmlName) { return bean.model.findIgnoreCase(xmlName); }
/* package */ void ensureConstraints(List<Child> children) { Set<String> nullElements = new HashSet<String>(model.getElementNames()); for (Child child : children) { nullElements.remove(child.name); } for (String s : nullElements) { ConfigModel.Property p = model.getElement(s); for (String annotation : p.getAnnotations()) { if (annotation.equals(NotNull.class.getName())) { if (p instanceof ConfigModel.Node) { ConfigModel childModel = ((ConfigModel.Node) p).model; Dom child = document.make(getHabitat(), null, this, childModel); child.register(); children.add(new Dom.NodeChild(s, child)); // recursive call to ensure the children constraints are also respected List<Child> grandChildren = new ArrayList<Child>(); child.ensureConstraints(grandChildren); if (!grandChildren.isEmpty()) { child.setChildren(grandChildren); } child.initializationCompleted(); } } } } }
ConfigModel.Property property = bean.model.toProperty(method);
name = camelCaseToXML(name); prop = findIgnoreCase(name); methodCache.put(method, prop); return prop;
String dv = getMetadataFieldKeyedAs(e.getValue(), "default:"); //default value String dt = getMetadataFieldKeyedAs(e.getValue(), "datatype:"); //type AttributeLeaf leaf = null; if (dv == null) { if (e.getValue().size()>0) { String elementName = name.substring(1, name.length() - 1); elements.put(elementName,parseValue(elementName,document,e.getValue())); this.keyedAs = indexTypeName; this.key = key; this.contracts = getMetadataFromDescription(description, ConfigMetadata.TARGET_CONTRACTS); this.symbolSpaces = new HashSet<String>(getMetadataFromDescription(description, "symbolSpaces")); for (String v : getMetadataFromDescription(description, INDEX_KEY)) { if(v.startsWith(ELEMENT_NAME_PREFIX)) tagName = v.substring(ELEMENT_NAME_PREFIX.length());
private List<ColumnInfo> getColumnInfo(Class<? extends ConfigBeanProxy> clazz) { List<ColumnInfo> cols = new ArrayList<ColumnInfo>(); for (String aname : targetModel.getAttributeNames()) { ColumnInfo ci = new ColumnInfo(); ci.cprop = targetModel.findIgnoreCase(aname); ci.order = targetModel.key.equals("@" + aname) ? ColumnInfo.KEY_ORDER : ColumnInfo.NONKEY_ORDER; ci.xmlName = aname; ListingColumn lc = m.getAnnotation(ListingColumn.class); if (lc != null) { String cname = targetModel.camelCaseToXML(targetModel.trimPrefix(m.getName())); ColumnInfo mci = null; for (ColumnInfo ci : cols) { mci.heading = cname.toUpperCase(Locale.ENGLISH); try { mci.duckGetter = targetModel.getDuckMethod(m); } catch (ClassNotFoundException ex) { // @todo Java SE 7 multicatch ConfigApiLoggerInfo.getLogger().log(Level.SEVERE,
for (String elementName : cm.getElementNames()) { ConfigModel.Property prop = cm.getElement(elementName); if (prop instanceof ConfigModel.Node) { ConfigModel childCM = ((ConfigModel.Node) prop).getModel(); String childTypeName = childCM.targetTypeName; if (childTypeName.equals(child.getName())) { return childCM.getTagName(); for (ConfigModel subChildModel : subChildrenModels) { if (subChildModel.targetTypeName.equals(child.getName())) { return subChildModel.getTagName();
? getServiceLocator().getService(ConfigExtensionHandler.class, cem.value()) : getServiceLocator().getService(ConfigExtensionHandler.class)); return invokeConfigExtensionMethod(handler, this, model.getProxyType(), args); ConfigModel.Property p = model.toProperty(method); if(p==null) throw new IllegalArgumentException("No corresponding property found for method: "+method);
private boolean isDeprecatedAttr(Dom dom, String name) { if (dom == null || dom.model == null || name == null) return false; Class t = dom.getProxyType(); if (t == null) return false; for (Method m : t.getDeclaredMethods()) { ConfigModel.Property p = dom.model.toProperty(m); if (p != null && name.equals(p.xmlName())) { return m.isAnnotationPresent(Deprecated.class); } } for (Field f : t.getDeclaredFields()) { if (name.equals(dom.model.camelCaseToXML(f.getName()))) { return f.isAnnotationPresent(Deprecated.class); } } return false; }
if (parent.model.findIgnoreCase(childName)!=null) { if (parent.model.getElement(childName).isLeaf()) continue; collection = parent.model.getElement(childName).isCollection();
public Map<String, String> getNodeAttributes(Dom node, String prefix) { Map<String, String> result = new HashMap<String, String>(); for (String attrName : node.model.getAttributeNames()) { String value = (String) node.model.findIgnoreCase(attrName).get(node, String.class); if (value!=null) { result.put(attrName, value); } } for (String leafName : node.model.getLeafElementNames()) { List values = node.leafElements(leafName); Iterator i = values.iterator(); StringBuffer value = new StringBuffer(); while (i.hasNext()) { String nextValue = (String) i.next(); if (nextValue!=null) { value.append(nextValue); if(i.hasNext()) { value.append(","); } } } result.put(leafName, value.toString()); } return result; }
/** * Returns the proxy type for this configuration object * @param <T> the proxy type * @return the class object for the proxy type */ public <T extends ConfigBeanProxy> Class<T> getProxyType() { return model.getProxyType(); }
String dv = getMetadataFieldKeyedAs(e.getValue(), "default:"); //default value String dt = getMetadataFieldKeyedAs(e.getValue(), "datatype:"); //type AttributeLeaf leaf = null; if (dv == null) { if (e.getValue().size()>0) { String elementName = name.substring(1, name.length() - 1); elements.put(elementName,parseValue(elementName,document,e.getValue()));
/** * Invoke the user defined static method in the nested "Duck" class so that * the user can define convenience methods on the config beans. */ Object invokeDuckMethod(Method method, Object proxy, Object[] args) throws Exception { Method duckMethod = model.getDuckMethod(method); Object[] duckArgs; if(args==null) { duckArgs = new Object[]{proxy}; } else { duckArgs = new Object[args.length+1]; duckArgs[0] = proxy; System.arraycopy(args,0,duckArgs,1,args.length); } try { return duckMethod.invoke(null,duckArgs); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof Exception) throw (Exception) t; if (t instanceof Error) throw (Error) t; throw e; } } /**
return null; ConfigModel.Property property = parentDom.model.getElement(elementName); if (property.isCollection()) { Collection<Dom> collection = parentDom.nodeElements(elementName);
/** * Creates {@link ConfigModel} for the given {@link ConfigInjector} if we haven't done so. */ /*package*/ ConfigModel buildModel(ActiveDescriptor<? extends ConfigInjector> i) { ConfigModel m = models.get(i); if(m==null) m = new ConfigModel(this, i, i.getMetadata(), habitat); return m; }
/** * Finds the {@link Property} from either {@link #elements} or {@link #attributes}. * @param xmlName * XML name to be searched. * @return null * if none is found. */ public Property findIgnoreCase(String xmlName) { // first try the exact match to take our chance Property a = attributes.get(xmlName); if(a!=null) return a; a = elements.get(xmlName); if(a!=null) return a; // exhaustive search a = _findIgnoreCase(xmlName, attributes); if(a!=null) return a; return _findIgnoreCase(xmlName, elements); }
name = camelCaseToXML(name); return findIgnoreCase(name);
? getServiceLocator().getService(ConfigExtensionHandler.class, cem.value()) : getServiceLocator().getService(ConfigExtensionHandler.class)); return invokeConfigExtensionMethod(handler, this, model.getProxyType(), args); ConfigModel.Property p = model.toProperty(method); if(p==null) throw new IllegalArgumentException("No corresponding property found for method: "+method);
String dv = getMetadataFieldKeyedAs(e.getValue(), "default:"); //default value String dt = getMetadataFieldKeyedAs(e.getValue(), "datatype:"); //type AttributeLeaf leaf = null; if (dv == null) { if (e.getValue().size()>0) { String elementName = name.substring(1, name.length() - 1); elements.put(elementName,parseValue(elementName,document,e.getValue())); this.keyedAs = indexTypeName; this.key = key; this.contracts = getMetadataFromDescription(description, ConfigMetadata.TARGET_CONTRACTS); this.symbolSpaces = new HashSet<String>(getMetadataFromDescription(description, "symbolSpaces")); for (String v : getMetadataFromDescription(description, INDEX_KEY)) { if(v.startsWith(ELEMENT_NAME_PREFIX)) tagName = v.substring(ELEMENT_NAME_PREFIX.length());