/** * Adds an parent class to this resource class. * * @param parentClass a parent class. * @throws SchemaIntegrityException if parentClass contains conflicting attributes. * @throws CircularDependencyException if parentClass is a descendant of this class. */ public void addParentClass(ResourceClass parentClass) throws SchemaIntegrityException, CircularDependencyException { List<String> conflicting = new ArrayList<String>(); List<Attribute> newAttributes = parentClass.getAllAttributes(); SortedMap<String, Attribute> existingAttributes = attributeMap(getAllAttributes()); for (Iterator<Attribute> i = newAttributes.iterator(); i.hasNext(); ) { Attribute attr = i.next(); Attribute existing = existingAttributes.get(attr.getName()); if (existing != null && !attr.getDeclaringClass().equals(existing.getDeclaringClass())) { conflicting.add(attr.getName()); } } if (!conflicting.isEmpty()) { throw new SchemaIntegrityException( "class " + parentClass.getName() + " contains attributes with conficting names " + conflicting.toString()); } if (parentClass.getAllParentClasses().contains(this)) { throw new CircularDependencyException( parentClass.getName() + " is a descendant of " + getName()); } parentClasses.put(parentClass.getName(), parentClass); }
/** * Adds new attribute to the entity. If attribute has no name, IllegalArgumentException is thrown. * * <p>Also sets <code>attr</code>'s entity to be this entity. */ public void addAttribute(Attribute attr) { if (attr.getName() == null) { throw new IllegalArgumentException("Attempt to insert unnamed attribute."); } attributes.put(attr.getName(), attr); }
@Test public void testAtt() { String nsUri = "nsUri"; String prefix = "prefix"; String localName = "localName"; String value = "value"; Attribute att = new Attribute(nsUri, localName, value); Assert.assertEquals(nsUri, att.getNamespace()); Assert.assertEquals(localName, att.getName()); Assert.assertEquals(value, att.getValue()); String nsUri2 = "nsUri2"; String prefix2 = "prefix2"; String localName2 = "localName2"; String value2 = "value2"; att.setNsURI(nsUri2); att.setName(localName2); att.setValue(value2); Assert.assertEquals(nsUri2, att.getNamespace()); Assert.assertEquals(localName2, att.getName()); Assert.assertEquals(value2, att.getValue()); }
/** * Add an attribute to the section * * @param attribute the attribute to be added. * @return the value of the attribute if it is a name attribute - null other wise * @throws ManifestException if the attribute already exists in this section. */ public String addAttributeAndCheck(Attribute attribute) throws ManifestException { if (attribute.getName() == null || attribute.getValue() == null) { throw new ManifestException("Attributes must have name and value"); } if (attribute.getKey().equalsIgnoreCase(ATTRIBUTE_NAME)) { warnings.addElement( "\"" + ATTRIBUTE_NAME + "\" attributes " + "should not occur in the main section and must be the " + "first element in all other sections: \"" + attribute.getName() + ": " + attribute.getValue() + "\""); return attribute.getValue(); } if (attribute.getKey().startsWith(ATTRIBUTE_FROM.toLowerCase())) { warnings.addElement( "Manifest attributes should not start " + "with \"" + ATTRIBUTE_FROM + "\" in \"" + attribute.getName() + ": " + attribute.getValue() + "\""); } else { // classpath attributes go into a vector String attributeKey = attribute.getKey(); if (attributeKey.equalsIgnoreCase(ATTRIBUTE_CLASSPATH)) { Attribute classpathAttribute = (Attribute) attributes.get(attributeKey); if (classpathAttribute == null) { storeAttribute(attribute); } else { warnings.addElement( "Multiple Class-Path attributes " + "are supported but violate the Jar " + "specification and may not be correctly " + "processed in all environments"); Enumeration e = attribute.getValues(); while (e.hasMoreElements()) { String value = (String) e.nextElement(); classpathAttribute.addValue(value); } } } else if (attributes.containsKey(attributeKey)) { throw new ManifestException( "The attribute \"" + attribute.getName() + "\" may not occur more " + "than once in the same section"); } else { storeAttribute(attribute); } } return null; }
protected void testCopy(Element element) throws Exception { assertTrue("Not null", element != null); int attributeCount = element.attributeCount(); int nodeCount = element.nodeCount(); Element copy = element.createCopy(); assertEquals("Node size not equal after copy", element.nodeCount(), nodeCount); assertTrue("Same attribute size after copy", element.attributeCount() == attributeCount); assertTrue("Copy has same node size", copy.nodeCount() == nodeCount); assertTrue("Copy has same attribute size", copy.attributeCount() == attributeCount); for (int i = 0; i < attributeCount; i++) { Attribute attr1 = element.attribute(i); Attribute attr2 = copy.attribute(i); assertTrue("Attribute: " + i + " name is equal", attr1.getName().equals(attr2.getName())); assertTrue("Attribute: " + i + " value is equal", attr1.getValue().equals(attr2.getValue())); } for (int i = 0; i < nodeCount; i++) { Node node1 = element.node(i); Node node2 = copy.node(i); assertTrue("Node: " + i + " type is equal", node1.getNodeType() == node2.getNodeType()); assertTrue("Node: " + i + " value is equal", node1.getText().equals(node2.getText())); } }
@Override public boolean onHttpRequestSend(HttpMessage message) { if (isActive() && SAMLUtils.hasSAMLMessage(message)) { try { SAMLMessage samlMessage = new SAMLMessage(message); // change the params for (Attribute attribute : configuration.getAutoChangeAttributes()) { String value = attribute.getValue().toString(); boolean changed = samlMessage.changeAttributeValueTo(attribute.getName(), value); if (changed) { log.debug(attribute.getName() + ": value changed to " + value); } } // change the original message HttpMessage changedMessege = samlMessage.getChangedMessage(); if (changedMessege != message) { // check for reference, if they are same the message is already changed, // else the header and body are changed message.setRequestBody(changedMessege.getRequestBody()); message.setRequestHeader(changedMessege.getRequestHeader()); } } catch (SAMLException ignored) { } } return true; }
/** * Removes an attribute from this resource class. * * @param attr an attribute. * @throws EntityDoesNotExistException if the class does not declare the attribute. */ public void deleteAttribute(Attribute attr) throws EntityDoesNotExistException { if (!attributes.containsKey(attr.getName())) { throw new EntityDoesNotExistException( "class " + getName() + " does not declare attribute " + "named " + attr.getName()); } attributes.remove(attr.getName()); attr.setDeclaringClass(null); }
@Override public void attributeChanged(Attribute attribute) { calculateDerivedAttributes(); updateMustDrop(); if (attribute.getName().equals("DEX") || attribute.getName().equals("EDU")) { calculateDynamicSkills(attribute, true); } }
/** * Gets the styles. * * @return the styles */ public ArrayList<Attribute> getStyles() { ArrayList<Attribute> result = new ArrayList<Attribute>(); for (Attribute attr : this) { if (attr.getName().indexOf("tyle") != -1 || attr.getName().indexOf("lass") != -1) { result.add(attr); } } return result; }
/** * Sets the value of the specified attribute of the DynamicMBean. * * @param attribute The attribute to set */ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { if (attribute.getName().equals("Name")) { // TODO set value of Name attribute } else throw new AttributeNotFoundException("Unknown Attribute " + attribute.getName()); }
/** * Returns the value of an attribute on the outline or null. * * @param name name of the attribute. */ public String getAttributeValue(final String name) { final List<Attribute> attributes = Collections.synchronizedList(getAttributes()); for (int i = 0; i < attributes.size(); i++) { final Attribute a = attributes.get(i); if (a.getName() != null && a.getName().equals(name)) { return a.getValue(); } } return null; }
String constructDN(final T o, final String parentDN, final Map<String, Attribute> attrMap) throws LDAPPersistException { final String existingDN = getEntryDN(o); if (existingDN != null) { return existingDN; } final ArrayList<String> rdnNameList = new ArrayList<String>(1); final ArrayList<byte[]> rdnValueList = new ArrayList<byte[]>(1); for (final FieldInfo i : rdnFields) { final Attribute a = attrMap.get(toLowerCase(i.getAttributeName())); if (a == null) { throw new LDAPPersistException( ERR_OBJECT_HANDLER_RDN_FIELD_MISSING_VALUE.get(type.getName(), i.getField().getName())); } rdnNameList.add(a.getName()); rdnValueList.add(a.getValueByteArray()); } for (final GetterInfo i : rdnGetters) { final Attribute a = attrMap.get(toLowerCase(i.getAttributeName())); if (a == null) { throw new LDAPPersistException( ERR_OBJECT_HANDLER_RDN_GETTER_MISSING_VALUE.get( type.getName(), i.getMethod().getName())); } rdnNameList.add(a.getName()); rdnValueList.add(a.getValueByteArray()); } final String[] rdnNames = new String[rdnNameList.size()]; rdnNameList.toArray(rdnNames); final byte[][] rdnValues = new byte[rdnNames.length][]; rdnValueList.toArray(rdnValues); final RDN rdn = new RDN(rdnNames, rdnValues); if (parentDN == null) { return new DN(rdn, defaultParentDN).toString(); } else { try { final DN parsedParentDN = new DN(parentDN); return new DN(rdn, parsedParentDN).toString(); } catch (LDAPException le) { debugException(le); throw new LDAPPersistException( ERR_OBJECT_HANDLER_INVALID_PARENT_DN.get(type.getName(), parentDN, le.getMessage()), le); } } }
/** * Gets the common attributes. * * @return the common attributes */ public ArrayList<Attribute> getCommonAttributes() { ArrayList<Attribute> result = new ArrayList<Attribute>(); for (Attribute attr : this) { if (!(attr.getName().startsWith("on") || (attr.getName().indexOf("tyle") != -1) || (attr.getName().indexOf("lass") != -1))) { result.add(attr); } } return result; }
/** * Adds an attribute to this resource class. * * @param attr an attribute. * @throws EntityExistsException if the class already delcares an attribute by that name. */ public void addAttribute(Attribute attr) throws EntityExistsException { if (attributes.containsKey(attr.getName())) { throw new EntityExistsException( "class " + getName() + " already declares attribute named " + attr.getName()); } if (getAllAttributes().contains(attr)) { throw new EntityExistsException( "class " + getName() + " already inherits attribute named " + attr.getName()); } attributes.put(attr.getName(), attr); attr.setDeclaringClass(this); }
// This sucks but it's pretty straightforward for now private void calculateDynamicSkills(Attribute attribute, boolean updateEditor) { ISkill sk = null; if (attribute.getName().equals("DEX")) { sk = investigator.getSkills().get("Dodge"); if (sk != null) sk.setBaseValue(attribute.getTotal() * 2); } else if (attribute.getName().equals("EDU")) { sk = investigator.getSkills().get("Own Language"); if (sk != null) sk.setBaseValue(Math.min(99, attribute.getTotal() * 5)); } if (updateEditor && sk != null) { BaseSkillEditor editor = findSkillEditor(sk); editor.updateBaseValue(); } }
@Test public void testAttWithoutPrefix() { String nsUri = "nsUri"; String localName = "localName"; String value = "value"; Attribute att = new Attribute(nsUri, localName, value); Assert.assertEquals(nsUri, att.getNamespace()); Assert.assertEquals(localName, att.getName()); att = new Attribute(nsUri, localName, value); Assert.assertEquals(nsUri, att.getNamespace()); Assert.assertEquals(localName, att.getName()); }
public static List<List<String>> attributeValuesInSets( List<String> urlList, List<String> attributeNames) throws MalformedURLException { List<List<String>> allAttributes = new ArrayList<List<String>>(); Attribute p = null; String key = null; int index = -1; for (int j = 0; j < attributeNames.size(); j++) { allAttributes.add(new ArrayList<String>()); // Add empty value to each list allAttributes.get(j).add(""); } for (int i = 0; i < urlList.size(); i++) { // System.out.println(urlList.get(i)); // allAttributes.add(new ArrayList<String>()); List<Attribute> attributeList = getQueryAttributes(urlList.get(i)); for (int j = 0; j < attributeList.size(); j++) { p = attributeList.get(j); key = p.getName(); index = attributeNames.indexOf(key); if (p.getValue() != null && p.getValue().trim().length() > 0) if (index != -1) if (allAttributes.get(index).indexOf(p.getValue().trim()) == -1) allAttributes.get(index).add(p.getValue().trim()); } } return allAttributes; }
private static void renderPassThruAttributesUnoptimized( FacesContext context, ResponseWriter writer, UIComponent component, Attribute[] knownAttributes, Map<String, List<ClientBehavior>> behaviors) throws IOException { boolean isXhtml = XHTML_CONTENT_TYPE.equals(writer.getContentType()); Map<String, Object> attrMap = component.getAttributes(); for (Attribute attribute : knownAttributes) { String attrName = attribute.getName(); String[] events = attribute.getEvents(); boolean hasBehavior = ((events != null) && (events.length > 0) && (behaviors.containsKey(events[0]))); Object value = attrMap.get(attrName); if (value != null && shouldRenderAttribute(value) && !hasBehavior) { writer.writeAttribute(prefixAttribute(attrName, isXhtml), value, attrName); } else if (hasBehavior) { renderHandler(context, component, null, attrName, value, events[0]); } } }
/* ------------------------------------------------------------ */ public AttributeList setAttributes(AttributeList attrs) { log.debug("setAttributes"); AttributeList results = new AttributeList(attrs.size()); Iterator iter = attrs.iterator(); while (iter.hasNext()) { try { Attribute attr = (Attribute) iter.next(); setAttribute(attr); results.add(new Attribute(attr.getName(), getAttribute(attr.getName()))); } catch (Exception e) { log.warn(LogSupport.EXCEPTION, e); } } return results; }
public String getPrintInfo() { String s = ""; s += "Table data: \n"; for (Attribute p : headers) { s += p.getIOType() + ","; } s += "\n"; for (Attribute p : headers) { s += p.getName() + ","; } s += "\n"; // for (Attribute p: headers) { // s += p.getId() + ","; // } // s += "\n"; for (List<String> value : values) { for (String v : value) { s += v + ","; } s += "\n"; } return s; }
/** * Gets the names array. * * @return the names array */ public ArrayList<String> getNamesArray() { ArrayList<String> result = new ArrayList<String>(); for (Attribute attr : this) { result.add(attr.getName()); } return result; }
/** * Constructor for class Attributes. * * @param componentClass class object of a JSF component whose attributes will be stored * @param beanClass class object of a managed bean */ private Attributes(Class<?> componentClass, Class<?> beanClass, boolean loadFromClass) { this.beanClass = beanClass; logger.debug("creating attributes map for " + componentClass); if (!loadFromClass && richfacesAttributes == null) { loadRichFacesComponents(); } if (!loadFromClass && richfacesAttributes.containsKey(componentClass)) { logger.debug( "retrieving attributes of " + componentClass.getName() + " from faces-config.xml"); if (attributes == null) { attributes = new TreeMap<String, Attribute>(); } for (Attribute a : richfacesAttributes.get(componentClass)) { Attribute newAttr = new Attribute(a); attributes.put(newAttr.getName(), newAttr); } } else if (!loadFromClass && !richfacesAttributes.containsKey(componentClass)) { throw new FacesException( "Componnent " + componentClass.getName() + " is not included in faces-config.xml."); } else { logger.debug( "retrieving attributes of " + componentClass.getName() + " from class descriptor"); loadAttributesFromClass(componentClass); } logger.debug(attributes.keySet().toString()); loadHelp(); loadSelectOptions(); }
/** * This will invoke the <code>startElement</code> callback in the <code>ContentHandler</code>. * * @param element <code>Element</code> used in callbacks. * @param nsAtts <code>List</code> of namespaces to declare with the element or <code>null</code>. */ private void startElement(Element element, Attributes nsAtts) throws JDOMException { String namespaceURI = element.getNamespaceURI(); String localName = element.getName(); String rawName = element.getQualifiedName(); // Allocate attribute list. AttributesImpl atts = (nsAtts != null) ? new AttributesImpl(nsAtts) : new AttributesImpl(); List attributes = element.getAttributes(); Iterator i = attributes.iterator(); while (i.hasNext()) { Attribute a = (Attribute) i.next(); atts.addAttribute( a.getNamespaceURI(), a.getName(), a.getQualifiedName(), getAttributeTypeName(a.getAttributeType()), a.getValue()); } try { contentHandler.startElement(namespaceURI, localName, rawName, atts); } catch (SAXException se) { throw new JDOMException("Exception in startElement", se); } }
/** Return index of attribute with same name and Namespace, or -1 if one doesn't exist */ private int indexOfDuplicate(Attribute attribute) { int duplicate = -1; String name = attribute.getName(); Namespace namespace = attribute.getNamespace(); duplicate = indexOf(name, namespace); return duplicate; }
@Override protected void doParseEventAttributes(XMLEventParserContext ctx, XMLEvent event, Object... args) { Iterator iter = event.asStartElement().getAttributes(); if (iter == null) return; while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); if (attr.getName().getLocalPart().equals("name") && attr.getValue() != null) this.setName(attr.getValue()); else if (attr.getName().getLocalPart().equals("default") && attr.getValue() != null) this.setDefaultValue(attr.getValue()); else if (attr.getName().getLocalPart().equals("nearestValue") && attr.getValue() != null) { Boolean d = WWUtil.convertStringToBoolean(attr.getValue()); if (d != null) this.setNearestValue(d); } } }
@Override public boolean equals(Object o) { if (!(o instanceof Attribute)) { return false; } Attribute attribute = (Attribute) o; return getName().equalsIgnoreCase(attribute.getName()); }
public boolean addAttribute(String name) { for (Attribute attribute : attributes) { if (attribute.getName().equalsIgnoreCase(name)) { return false; } } return addAttribute(new Attribute(name)); }
private String getAttributeValue(List<Attribute> attributes, String name) { for (Attribute attribute : attributes) { if (attribute.getName().equals(name)) { return attribute.getValue(); } } return null; }
private SortedMap<String, Attribute> attributeMap(Collection<Attribute> attributes) { SortedMap<String, Attribute> result = new TreeMap<String, Attribute>(); for (Iterator<Attribute> i = attributes.iterator(); i.hasNext(); ) { Attribute attr = i.next(); result.put(attr.getName(), attr); } return result; }
/** * Returns a Attribute of the given name * * @param name the name of the attribute to look for * @return the attribute with the given name */ public Attribute getAttributeByName(String name) { for (Attribute attr : attributes) { if (attr.getName().equals(name)) { return attr; } } return null; }