GAttributeInfo attribInfo) { Map<String, String> map = new TreeMap<String, String>(); String attribName = attribInfo.getName(); map.put("name", attribName); map.put("getterName", attribInfo.getGetterName()); map.put("setterName", attribInfo.getSetterName()); map.put("type", attribInfo.getType()); map.put("manageable", String.valueOf(attribInfo.isManageable())); map.put("persistent", String.valueOf(attribInfo.isPersistent())); map.put("readable", String.valueOf(attribInfo.isReadable())); map.put("writable", String.valueOf(attribInfo.isWritable())); if (attribInfo.isReadable()) { String attribValue = ""; try {
public void setManageableAttributes(String[] manageableAttributes) { for (int i = 0; i < manageableAttributes.length; i++) { String attributeName = manageableAttributes[i]; GAttributeInfo attribute = (GAttributeInfo) attributes.get(attributeName); if (attribute != null) { attributes.put(attributeName, new GAttributeInfo(attributeName, attribute.getType(), attribute.isPersistent(), true, attribute.getGetterName(), attribute.getSetterName())); } } }
private boolean isMagicAttribute(GAttributeInfo attributeInfo) { String name = attributeInfo.getName(); String type = attributeInfo.getType(); return ("kernel".equals(name) && Kernel.class.getName().equals(type)) || ("classLoader".equals(name) && ClassLoader.class.getName().equals(type)) || ("abstractName".equals(name) && AbstractName.class.getName().equals(type)) || ("objectName".equals(name) && String.class.getName().equals(type)); }
} else if (attributes.containsKey(argumentName)) { GAttributeInfo attribute = (GAttributeInfo) attributes.get(argumentName); argumentTypes[i] = attribute.getType(); isReference[i] = false;
public void addAttribute(GAttributeInfo info) { attributes.put(info.getName(), info); }
this.attributeInfo = new GAttributeInfo(this.name, this.type.getName(), this.persistent, this.readable, this.writable, attributeInfo.getGetterName(), attributeInfo.getSetterName()); } else { this.attributeInfo = new GAttributeInfo(this.name, this.type.getName(), this.persistent,
/** * Returns a list where the elements are type GAttributeInfo */ public List getPersistentAttributes() { List attrs = new ArrayList(); for (Iterator i = attributes.iterator(); i.hasNext();) { GAttributeInfo info = (GAttributeInfo) i.next(); if (info.isPersistent()) { attrs.add(info); } } return attrs; }
/** * Returns a list where the elements are type GAttributeInfo */ public List getManageableAttributes() { List attrs = new ArrayList(); for (Iterator i = attributes.iterator(); i.hasNext();) { GAttributeInfo info = (GAttributeInfo) i.next(); if (info.isManageable()) { attrs.add(info); } } return attrs; }
public void setPersistentAttributes(String[] persistentAttributes) { for (int i = 0; i < persistentAttributes.length; i++) { String attributeName = persistentAttributes[i]; GAttributeInfo attribute = (GAttributeInfo) attributes.get(attributeName); if (attribute != null && !references.containsKey(attributeName)) { if (isMagicAttribute(attribute)) { // magic attributes can't be persistent continue; } attributes.put(attributeName, new GAttributeInfo(attributeName, attribute.getType(), true, attribute.isManageable(), attribute.getGetterName(), attribute.getSetterName())); } else { if (attributeName.equals("kernel")) { addAttribute("kernel", Kernel.class, false); } else if (attributeName.equals("classLoader")) { addAttribute("classLoader", ClassLoader.class, false); } else if (attributeName.equals("abstractName")) { addAttribute("abstractName", AbstractName.class, false); } else if (attributeName.equals("objectName")) { addAttribute("obectName", String.class, false); } } } }
private void setDynamicGBeanDataAttributes(GBeanData gbeanData, GerConfigPropertySettingType[] configProperties, Bundle bundle) throws DeploymentException { List<String> unknownNames = new ArrayList<String>(); for (GerConfigPropertySettingType configProperty : configProperties) { String name = configProperty.getName(); GAttributeInfo attributeInfo = gbeanData.getGBeanInfo().getAttribute(name); if (attributeInfo == null) { String originalName = name; name = switchCase(name); attributeInfo = gbeanData.getGBeanInfo().getAttribute(name); if (attributeInfo == null) { unknownNames.add(originalName); continue; } } String type = attributeInfo.getType(); gbeanData.setAttribute(name, getValue(type, configProperty.getStringValue().trim(), bundle)); } if (unknownNames.size() > 0) { StringBuilder buf = new StringBuilder("The plan is trying to set attributes: ").append(unknownNames).append("\n"); buf.append("Known attributes: \n"); for (GAttributeInfo attributeInfo : gbeanData.getGBeanInfo().getAttributes()) { buf.append(attributeInfo).append("\n"); } throw new DeploymentException(buf.toString()); } }
for (Iterator iterator = attributes.iterator(); iterator.hasNext();) { GAttributeInfo attribute = (GAttributeInfo) iterator.next(); map.put(attribute.getName(), attribute);
if (!attributeInfo.isReadable() && !attributeInfo.isWritable() && !attributeInfo.isPersistent() && !isConstructorArg) " name=" + attributeInfo.getName() + " targetClass=" + gbeanInstance.getType().getName()); this.name = attributeInfo.getName(); this.isConstructorArg = isConstructorArg; try { this.type = ClassLoading.loadClass(attributeInfo.getType(), gbeanInstance.getClassLoader()); } catch (ClassNotFoundException e) { throw new InvalidConfigurationException("Could not load attribute class: " + attributeInfo.getType(), e); this.persistent = attributeInfo.isPersistent(); this.manageable = attributeInfo.isManageable(); readable = attributeInfo.isReadable(); writable = attributeInfo.isWritable(); if (attributeInfo.getGetterName() != null) { try { String getterName = attributeInfo.getGetterName(); Method getterMethod = gbeanInstance.getType().getMethod(getterName, null); if (attributeInfo.getSetterName() != null) { try { String setterName = attributeInfo.getSetterName(); Method setterMethod = gbeanInstance.getType().getMethod(setterName, new Class[]{type}); if (AbstractGBeanReference.NO_PROXY) {
if (attribute == null) { attributes.put(attributeName, new GAttributeInfo(attributeName, attributeType, persistentNames.contains(attributeName), null)); } else { if (!attributeType.equals(attribute.getType())) { throw new IllegalArgumentException("Getter and setter type do not match: " + attributeName + " for gbeanType: " + gbeanType.getName()); new GAttributeInfo(attributeName, attributeType, attribute.isPersistent() || persistentNames.contains(attributeName), attribute.isManageable() || manageableNames.contains(attributeName), method.getName(), attribute.getSetterName())); if (attribute == null) { attributes.put(attributeName, new GAttributeInfo(attributeName, attributeType, persistentNames.contains(attributeName), method.getName())); } else { if (!attributeType.equals(attribute.getType())) { throw new IllegalArgumentException("Getter and setter type do not match: " + attributeName + " for gbeanType: " + gbeanType.getName());
private void setDynamicGBeanDataAttributes(GBeanData gbeanData, GerConfigPropertySettingType[] configProperties, ClassLoader cl) throws DeploymentException { List<String> unknownNames = new ArrayList<String>(); for (GerConfigPropertySettingType configProperty : configProperties) { String name = configProperty.getName(); GAttributeInfo attributeInfo = gbeanData.getGBeanInfo().getAttribute(name); if (attributeInfo == null) { String originalName = name; name = switchCase(name); attributeInfo = gbeanData.getGBeanInfo().getAttribute(name); if (attributeInfo == null) { unknownNames.add(originalName); continue; } } String type = attributeInfo.getType(); gbeanData.setAttribute(name, getValue(type, configProperty.getStringValue().trim(), cl)); } if (unknownNames.size() > 0) { StringBuffer buf = new StringBuffer("The plan is trying to set attributes: ").append(unknownNames).append("\n"); buf.append("Known attributes: \n"); for (GAttributeInfo attributeInfo: gbeanData.getGBeanInfo().getAttributes()) { buf.append(attributeInfo).append("\n"); } throw new DeploymentException(buf.toString()); } }
/** * Return MBean attributes */ @RemoteMethod public Collection<Map<String, String>> getAttributes(String abstractNameString) { Map<String, Map<String, String>> attributes = new TreeMap<String, Map<String, String>>(); try { AbstractName abstractName = new AbstractName(URI.create(abstractNameString)); GBeanInfo gBeanInfo = kernel.getGBeanInfo(abstractName); Set<GAttributeInfo> attrs = gBeanInfo.getAttributes(); for (Iterator<GAttributeInfo> i = attrs.iterator(); i.hasNext();) { GAttributeInfo gAttrInfo = i.next(); String attrName = gAttrInfo.getName(); if (!GBEANINFO_ATTRIB.equals(attrName)) { // Don't include the 'GBeanInfo' attributes Map<String, String> attrInfoMap = getAttrInfoAsMap(abstractName, gAttrInfo); attributes.put(attrName, attrInfoMap); } } } catch (GBeanNotFoundException e) { // GBean not found, just ignore } return attributes.values(); }
public void setXmlAttribute(String name, XmlObject xmlObject, XmlObject enclosing) throws DeploymentException { String namespace = xmlObject.getDomNode().getNamespaceURI(); XmlAttributeBuilder builder = (XmlAttributeBuilder) xmlAttributeBuilderMap.get(namespace); if (builder == null) { throw new DeploymentException("No attribute builder deployed for namespace: " + namespace); } GAttributeInfo attribute = gbean.getGBeanInfo().getAttribute(name); if (attribute == null) { throw new DeploymentException("Unknown attribute " + name + " on " + gbean.getAbstractName()); } String type = attribute.getType(); Object value = builder.getValue(xmlObject, enclosing, type, bundle); gbean.setAttribute(name, value); }
for (Iterator iterator = attributeInfos.iterator(); iterator.hasNext();) { GAttributeInfo attributeInfo = (GAttributeInfo) iterator.next(); attributeNames.add(attributeInfo.getName());
if (attribute != null && attribute.getType().equals("java.net.URL")) { try { Set set = configuration.getConfigurationResolver().resolve("");
private void renderDetail(RenderRequest renderRequest, RenderResponse renderResponse, String name) throws PortletException, IOException { ObjectName gbeanName; try { gbeanName = new ObjectName(name); } catch (MalformedObjectNameException e) { throw new PortletException("Malformed parameter name: " + renderRequest.getParameter("name")); } try { GBeanInfo gbeanInfo = kernel.getGBeanInfo(gbeanName); Set attributes = gbeanInfo.getAttributes(); Map values = new HashMap(attributes.size()); for (Iterator i = attributes.iterator(); i.hasNext();) { GAttributeInfo attribute = (GAttributeInfo) i.next(); String gname = attribute.getName(); if (HIDDEN_ATTRIBUTES.contains(gname)) { continue; } Object value = kernel.getAttribute(gbeanName, gname); values.put(gname, value); } renderRequest.setAttribute("attributeMap", values); } catch (Exception e) { throw new PortletException(e); } detailView.include(renderRequest, renderResponse); }
public void setAttribute(String name, String type, String text) throws DeploymentException { if (text != null) { text = text.trim(); // avoid formatting errors due to extra whitespace in XML configuration file } try { // @todo we should not need all of common just for this if (type == null) { GAttributeInfo attribute = gbean.getGBeanInfo().getAttribute(name); if (attribute == null) { throw new DeploymentException("Unknown attribute " + name + " on " + gbean.getAbstractName()); } type = attribute.getType(); } PropertyEditor editor = PropertyEditors.findEditor(type, bundle); if (editor == null) { throw new DeploymentException("Unable to find PropertyEditor for " + type); } editor.setAsText(text); Object value = editor.getValue(); gbean.setAttribute(name, value); } catch (DeploymentException e) { throw e; } catch (ClassNotFoundException e) { throw new DeploymentException("Unable to find PropertyEditor for " + type, e); } catch (Exception e) { throw new DeploymentException("Unable to set attribute " + name + " to " + text, e); } }