You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/07/01 00:37:29 UTC
svn commit: r418401 [21/32] - in /incubator/openjpa/trunk: openjpa-lib/
openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/
openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/
openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/ openjpa-lib/src/...
Modified: incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Attributes.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Attributes.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Attributes.java (original)
+++ incubator/openjpa/trunk/serp/src/main/java/serp/bytecode/Attributes.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -15,114 +12,97 @@
*/
package serp.bytecode;
-import serp.bytecode.lowlevel.*;
-
-import serp.bytecode.visitor.*;
-
import java.io.*;
-
import java.util.*;
-
+import serp.bytecode.lowlevel.*;
+import serp.bytecode.visitor.*;
/**
- * <p>Abstract superclass for all bytecode entities that hold attributes.</p>
- *
- * @author Abe White
+ * Abstract superclass for all bytecode entities that hold attributes.
+ *
+ * @author Abe White
*/
public abstract class Attributes implements BCEntity {
/**
- * Return all the attributes owned by this entity.
- *
- * @return all owned attributes, or empty array if none
+ * Return all the attributes owned by this entity.
+ *
+ * @return all owned attributes, or empty array if none
*/
public Attribute[] getAttributes() {
Collection attrs = getAttributesHolder();
-
- return (Attribute[]) attrs.toArray(new Attribute[attrs.size()]);
+ return(Attribute[]) attrs.toArray(new Attribute[attrs.size()]);
}
/**
- * Return the attribute with the given name. If multiple attributes
- * share the name, which is returned is undefined.
+ * Return the attribute with the given name. If multiple attributes
+ * share the name, which is returned is undefined.
*/
public Attribute getAttribute(String name) {
Collection attrs = getAttributesHolder();
Attribute attr;
-
for (Iterator itr = attrs.iterator(); itr.hasNext();) {
attr = (Attribute) itr.next();
-
- if (attr.getName().equals(name)) {
+ if (attr.getName().equals(name))
return attr;
- }
}
return null;
}
/**
- * Return all attributes with the given name.
- *
- * @return the matching attributes, or empty array if none
+ * Return all attributes with the given name.
+ *
+ * @return the matching attributes, or empty array if none
*/
public Attribute[] getAttributes(String name) {
List matches = new LinkedList();
Collection attrs = getAttributesHolder();
Attribute attr;
-
for (Iterator itr = attrs.iterator(); itr.hasNext();) {
attr = (Attribute) itr.next();
-
- if (attr.getName().equals(name)) {
+ if (attr.getName().equals(name))
matches.add(attr);
- }
}
-
- return (Attribute[]) matches.toArray(new Attribute[matches.size()]);
+ return(Attribute[]) matches.toArray(new Attribute[matches.size()]);
}
/**
- * Set the attributes for this entity; this method is useful for importing
- * all attributes from another entity. Set to null or empty array if none.
+ * Set the attributes for this entity; this method is useful for importing
+ * all attributes from another entity. Set to null or empty array if none.
*/
public void setAttributes(Attribute[] attrs) {
clearAttributes();
-
- if (attrs != null) {
+ if (attrs != null)
for (int i = 0; i < attrs.length; i++)
addAttribute(attrs[i]);
- }
}
/**
- * Import an attribute from another entity, or make a copy of one
- * on this entity.
+ * Import an attribute from another entity, or make a copy of one
+ * on this entity.
*/
public Attribute addAttribute(Attribute attr) {
Attribute newAttr = addAttribute(attr.getName());
newAttr.read(attr);
-
return newAttr;
}
/**
- * Add an attribute of the given type.
+ * Add an attribute of the given type.
*/
public Attribute addAttribute(String name) {
Attribute attr = Attribute.create(name, this);
getAttributesHolder().add(attr);
-
return attr;
}
/**
- * Clear all attributes from this entity.
+ * Clear all attributes from this entity.
*/
public void clearAttributes() {
Collection attrs = getAttributesHolder();
Attribute attr;
-
for (Iterator itr = attrs.iterator(); itr.hasNext();) {
attr = (Attribute) itr.next();
itr.remove();
@@ -131,38 +111,34 @@
}
/**
- * Remove all attributes with the given name from this entity.
- *
- * @return true if an attribute was removed, false otherwise
+ * Remove all attributes with the given name from this entity.
+ *
+ * @return true if an attribute was removed, false otherwise
*/
public boolean removeAttribute(String name) {
return removeAttribute(getAttribute(name));
}
/**
- * Remove the given attribute. After being removed, the attribute
- * is invalid, and the result of any operations on it are undefined.
- *
- * @return true if the attribute was removed, false otherwise
+ * Remove the given attribute. After being removed, the attribute
+ * is invalid, and the result of any operations on it are undefined.
+ *
+ * @return true if the attribute was removed, false otherwise
*/
public boolean removeAttribute(Attribute attribute) {
- if ((attribute == null) || !getAttributesHolder().remove(attribute)) {
+ if (attribute == null || !getAttributesHolder().remove(attribute))
return false;
- }
-
attribute.invalidate();
-
return true;
}
/**
- * Convenience method to be called by BCEntities when being visited
- * by a {@link BCVisitor}; this method will allow the visitor to visit all
- * attributes of this entity.
+ * Convenience method to be called by BCEntities when being visited
+ * by a {@link BCVisitor}; this method will allow the visitor to visit all
+ * attributes of this entity.
*/
void visitAttributes(BCVisitor visit) {
Attribute attr;
-
for (Iterator itr = getAttributesHolder().iterator(); itr.hasNext();) {
attr = (Attribute) itr.next();
visit.enterAttribute(attr);
@@ -172,9 +148,9 @@
}
/**
- * Build the attribute list from the given stream.
- * Relies on the ability of attributes to read themselves, and
- * requires access to the constant pool, which must already by read.
+ * Build the attribute list from the given stream.
+ * Relies on the ability of attributes to read themselves, and
+ * requires access to the constant pool, which must already by read.
*/
void readAttributes(DataInput in) throws IOException {
Collection attrs = getAttributesHolder();
@@ -182,17 +158,17 @@
Attribute attribute;
String name;
-
for (int i = in.readUnsignedShort(); i > 0; i--) {
- name = ((UTF8Entry) getPool().getEntry(in.readUnsignedShort())).getValue();
+ name = ((UTF8Entry) getPool().getEntry(in.readUnsignedShort())).
+ getValue();
attribute = addAttribute(name);
attribute.read(in, in.readInt());
}
}
/**
- * Writes all the owned attributes to the given stream.
- * Relies on the ability of attributes to write themselves.
+ * Writes all the owned attributes to the given stream.
+ * Relies on the ability of attributes to write themselves.
*/
void writeAttributes(DataOutput out) throws IOException {
Collection attrs = getAttributesHolder();
@@ -200,7 +176,6 @@
Attribute attribute;
int length;
-
for (Iterator itr = attrs.iterator(); itr.hasNext();) {
attribute = (Attribute) itr.next();
out.writeShort(attribute.getNameIndex());
@@ -211,7 +186,7 @@
}
/**
- * Return the collection used to hold the attributes of this entity.
+ * Return the collection used to hold the attributes of this entity.
*/
abstract Collection getAttributesHolder();
}