User: dsundstrom
Date: 01/07/09 16:59:58
Modified: src/main/org/jboss/ejb/plugins/cmp/bridge
CMPFieldBridge.java CMRFieldBridge.java
EntityBridgeInvocationHandler.java
Log:
Added container managed relationships.
Revision Changes Path
1.2 +4 -1
jboss/src/main/org/jboss/ejb/plugins/cmp/bridge/CMPFieldBridge.java
Index: CMPFieldBridge.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/bridge/CMPFieldBridge.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CMPFieldBridge.java 2001/06/24 03:23:14 1.1
+++ CMPFieldBridge.java 2001/07/09 23:59:58 1.2
@@ -19,7 +19,7 @@
* One for each entity bean cmp field.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface CMPFieldBridge {
public String getFieldName();
@@ -33,6 +33,9 @@
public Object getPrimaryKeyValue(Object primaryKey) throws
IllegalArgumentException;
public Object setPrimaryKeyValue(Object primaryKey, Object value) throws
IllegalArgumentException;
+ /**
+ * Set CMPFieldValue to Java default value (i.e., 0 or null).
+ */
public void initInstance(EntityEnterpriseContext ctx);
/**
1.2 +2 -2
jboss/src/main/org/jboss/ejb/plugins/cmp/bridge/CMRFieldBridge.java
Index: CMRFieldBridge.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/bridge/CMRFieldBridge.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CMRFieldBridge.java 2001/06/24 03:23:14 1.1
+++ CMRFieldBridge.java 2001/07/09 23:59:58 1.2
@@ -20,11 +20,11 @@
* one per relationship (shared between two beans).
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface CMRFieldBridge {
public String getFieldName();
- public Class getFieldType();
+// public Class getFieldType();
public Object getValue(EntityEnterpriseContext ctx);
public void setValue(EntityEnterpriseContext ctx, Object value);
1.2 +65 -15
jboss/src/main/org/jboss/ejb/plugins/cmp/bridge/EntityBridgeInvocationHandler.java
Index: EntityBridgeInvocationHandler.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/bridge/EntityBridgeInvocationHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EntityBridgeInvocationHandler.java 2001/06/24 03:23:14 1.1
+++ EntityBridgeInvocationHandler.java 2001/07/09 23:59:58 1.2
@@ -32,18 +32,26 @@
* One per cmp entity bean instance, including beans in pool.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class EntityBridgeInvocationHandler implements InvocationHandler {
protected EntityBridge entityBridge;
protected Class beanClass;
protected EntityEnterpriseContext ctx;
protected Map cmpFieldMap;
+ protected Map cmrFieldMap;
public EntityBridgeInvocationHandler(EntityBridge entityBridge, Class
beanClass) throws Exception {
this.entityBridge = entityBridge;
this.beanClass = beanClass;
- setupCMPFieldMap(getAbstractAccessors());
+ Map abstractAccessors = getAbstractAccessors();
+ setupCMPFieldMap(abstractAccessors);
+ try {
+ setupCMRFieldMap(abstractAccessors);
+ } catch(Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
}
public void setContext(EntityEnterpriseContext ctx) {
@@ -68,9 +76,25 @@
cmpField.setInstanceValue(ctx, args[0]);
return null;
}
- throw new IllegalArgumentException("Unknown cmp field method:
" + methodName);
+ Exception e = new EJBException("Unknown cmp field method: " +
methodName);
+ e.printStackTrace();
+ throw e;
}
- throw new IllegalArgumentException("Unknown method type: " +
methodName);
+
+ CMRFieldBridge cmrField = (CMRFieldBridge) cmrFieldMap.get(method);
+ if(cmrField != null) {
+ if(methodName.startsWith("get")) {
+ return cmrField.getValue(ctx);
+ } else if(methodName.startsWith("set")) {
+ cmrField.setValue(ctx, args[0]);
+ return null;
+ }
+ throw new EJBException("Unknown cmr field method: " +
methodName);
+ }
+
+ Exception e = new EJBException("Unknown method type: " + methodName);
+ e.printStackTrace();
+ throw e;
}
protected Map getAbstractAccessors() {
@@ -88,7 +112,7 @@
return abstractAccessors;
}
- protected void setupCMPFieldMap(Map abstractAccessors) {
+ protected void setupCMPFieldMap(Map abstractAccessors) throws
DeploymentException {
CMPFieldBridge[] cmpFields = entityBridge.getCMPFields();
cmpFieldMap = new HashMap(cmpFields.length * 2);
@@ -98,39 +122,65 @@
}
}
- protected void setupCMPFieldGetter(Map abstractAccessors, CMPFieldBridge
cmpField) {
+ protected void setupCMPFieldGetter(Map abstractAccessors, CMPFieldBridge
cmpField) throws DeploymentException {
String fieldName = cmpField.getFieldName();
String getterName = "get" + Character.toUpperCase(fieldName.charAt(0))
+ fieldName.substring(1);
Method getterMethod = (Method)abstractAccessors.get(getterName);
if(getterMethod != null) {
- verifyGetter(getterMethod, cmpField);
cmpFieldMap.put(getterMethod, cmpField);
abstractAccessors.remove(getterName);
} else {
- // not clear that a getter is required for each cmp field
- // throw new DeploymentException("No getter found for cmp
field: " + fieldName);
+ throw new DeploymentException("No getter found for cmp field:
" + fieldName);
}
}
- protected void setupCMPFieldSetter(Map abstractAccessors, CMPFieldBridge
cmpField) {
+ protected void setupCMPFieldSetter(Map abstractAccessors, CMPFieldBridge
cmpField) throws DeploymentException {
String fieldName = cmpField.getFieldName();
String setterName = "set" + Character.toUpperCase(fieldName.charAt(0))
+ fieldName.substring(1);
Method setterMethod = (Method)abstractAccessors.get(setterName);
if(setterMethod != null) {
- verifySetter(setterMethod, cmpField);
cmpFieldMap.put(setterMethod, cmpField);
abstractAccessors.remove(setterName);
} else {
- // not clear that a setter is required for each cmp field
- // throw new DeploymentException("No setter found for cmp
field: " + fieldName);
+ throw new DeploymentException("No setter found for cmp field:
" + fieldName);
}
}
+
+ protected void setupCMRFieldMap(Map abstractAccessors) throws
DeploymentException {
+ CMRFieldBridge[] cmrFields = entityBridge.getCMRFields();
+ cmrFieldMap = new HashMap(cmrFields.length * 2);
- protected void verifyGetter(Method getterMethod, CMPFieldBridge cmpField) {
+ for(int i=0; i<cmrFields.length; i++) {
+ // in unidirectional relationships only one side has
+ // a field name
+ if(cmrFields[i].getFieldName() != null) {
+ setupCMRFieldGetter(abstractAccessors, cmrFields[i]);
+ setupCMRFieldSetter(abstractAccessors, cmrFields[i]);
+ }
+ }
}
- protected void verifySetter(Method setterMethod, CMPFieldBridge cmpField) {
+ protected void setupCMRFieldGetter(Map abstractAccessors, CMRFieldBridge
cmrField) throws DeploymentException {
+ String fieldName = cmrField.getFieldName();
+ String getterName = "get" + Character.toUpperCase(fieldName.charAt(0))
+ fieldName.substring(1);
+
+ Method getterMethod = (Method)abstractAccessors.get(getterName);
+ if(getterMethod != null) {
+ cmrFieldMap.put(getterMethod, cmrField);
+ abstractAccessors.remove(getterName);
+ }
+ }
+
+ protected void setupCMRFieldSetter(Map abstractAccessors, CMRFieldBridge
cmrField) throws DeploymentException {
+ String fieldName = cmrField.getFieldName();
+ String setterName = "set" + Character.toUpperCase(fieldName.charAt(0))
+ fieldName.substring(1);
+
+ Method setterMethod = (Method)abstractAccessors.get(setterName);
+ if(setterMethod != null) {
+ cmrFieldMap.put(setterMethod, cmrField);
+ abstractAccessors.remove(setterName);
+ }
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development