public boolean isFieldType(EnterpriseBean bean, JavaClass clazz, Field field) { if(field == null) { return false; } if(field.getName().equals(IMethodAndFieldConstants.FIELDNAME_SERIALVERSIONUID)) { return true; } return false; }
/** * Return true if the JavaClass passed in has the Field defined * on it. Return false if the Field is defined on a supertype or * is not defined on the class at all. */ public static final boolean onClass(JavaClass clazz, Field field) { if((clazz == null) || (field == null)) { return false; } return clazz.equals(field.getJavaClass()); }
/** * Return true if the field is defined on java.lang.Object. */ public static boolean isJavaLangObjectField(EnterpriseBean bean, Field field) { return isSameType(bean, field.getContainingJavaClass(), ITypeConstants.CLASSNAME_JAVA_LANG_OBJECT); }
/** * Is the cmp attribute also a field in the key class? */ protected boolean isAttributeKeyClassField(String attributeName) { // ensure key class is not null JavaClass keyClass = cmp.getPrimaryKey(); if (keyClass == null) return false; // see if the attribute name matchs any of the reflected key class public field names List keyFields = keyClass.getFieldsExtended(); for (int i = 0; i < keyFields.size(); i++) { Field field = (Field) keyFields.get(i); if (field.getJavaVisibility() == JavaVisibilityKind.PUBLIC_LITERAL) { if (field.getName().equals(attributeName)) return true; } } return false; }
/** * Used for the very narrow case of final static Strings */ protected void setInitializerIfPossible() { if (!(getTargetField().isStatic() && getTargetField().isFinal() && "java.lang.String".equals(((JavaHelpers) getTargetField().getEType()).getQualifiedName()))) //$NON-NLS-1$ return; String value = null; try { value = (String) getSourceField().get(null); } catch (IllegalAccessException ex) { return; } if (value == null) return; else value = "\"".concat(value).concat("\""); //$NON-NLS-2$//$NON-NLS-1$ Block aBlock = createBlock(getTargetField().getName(), value); getTargetField().setInitializer(aBlock); } /**
/** * For CMP 1.1 beans, the list is simply the fields, extended, * on the bean class * * @return java.util.List of {@link CMPFieldDescriptor} */ public static List getAvailableCMP11FieldDescriptors(JavaClass beanClass, CMPHelper.CMPFieldExistTester fieldTester) { if (beanClass == null) return Collections.EMPTY_LIST; List fields = beanClass.getFieldsExtended(); List result = new ArrayList(); for (int i = 0; i < fields.size(); i++) { Field aField = (Field) fields.get(i); if (!isPublic(aField) || aField.isStatic() || aField.isTransient() || (fieldTester != null && !fieldTester.isExisting(aField))) continue; String name = aField.getName(); String typeName = getTypeName(aField); if (typeName != null && name != null) result.add(createFieldDescriptor(name, typeName)); } return result; }
field = findExistingField(); if (field != null && getEType() != null && field.getEType() == null) field.setEType(getEType()); break; case J2EEVersionConstants.EJB_2_0_ID: case J2EEVersionConstants.EJB_2_1_ID: default: field = ((JavaRefPackage)EPackage.Registry.INSTANCE.getEPackage(JavaRefPackage.eNS_URI)).getJavaRefFactory().createField(); field.setName(getName()); field.setEType(getAccessorType()); break;
} else if (object instanceof Field) { Field field = (Field) object; JavaClass clazz = field.getContainingJavaClass(); return ResourceHandler.getExternalizedMessage(EJBHelperConstants.LOC_FIELD, new String[]{field.getName(), clazz.getQualifiedName()}); } else if (object instanceof EnterpriseBean) { return ResourceHandler.getExternalizedMessage(EJBHelperConstants.LOC_BEAN, new String[]{((EnterpriseBean) object).getName()});
/** * 18.1.2 Programming restrictions *... * - An enterprise Bean must not use read/write static fields. Using read-only static fields is * allowed. Therefore, it is recommended that all static fields in the enterprise bean class be * declared as final. *... */ protected void validateStaticField(IEJBValidationContext vc, EnterpriseBean bean, JavaClass clazz, Field field) throws InvalidInputException { if (field == null) { return; } // An enterprise Bean must not use read/write static fields. Using read-only static fields is // allowed. Therefore, it is recommended that all static fields in the enterprise bean class be // declared as final. if (field.isStatic() && !field.isFinal()) { IMessage message = MessageUtility.getUtility().getMessage(vc, IMessagePrefixEjb11Constants.CHKJ2200, IEJBValidationContext.WARNING, bean, clazz, field, this); vc.addMessage(message); } }
public static final JavaHelpers getType(Field field) { if(field == null) { return null; } return (JavaHelpers)field.getEType(); }
public static final boolean isPublic(Field field) { if ( field == null ) return false; return (JavaVisibilityKind.PUBLIC_LITERAL == field.getJavaVisibility()); }
/** * createJavaField - instantiate a Java Field based on the passed Field * We are deferring field contents assuming that its adaptor will reflect its details. */ public Field createJavaField(java.lang.reflect.Field reflectedField, XMIResource resource) { Field newField = getJavaFactory().createField(); newField.setName(reflectedField.getName()); String className = getSimpleName(reflectedField.getDeclaringClass().getName()); resource.setID(newField, className + C_CLASS_MEMBER_DELIMITER + reflectedField.getName()); return newField; } /**
protected void setFieldType(Field aField, String aTypeName) { if (aField != null && aTypeName != null) { String classRefString = aTypeName; aField.setEType(createJavaClassRef(classRefString)); } } public final boolean flushReflectedValuesIfNecessary() {
protected void initializeForCompoundKey() { List keys = getKeyAttributes(); // clear key list keys.clear(); //ensure the key class is not null JavaClass keyClass = cmp.getPrimaryKey(); if (keyClass == null) return; keyClass.eAdapters().add(this); // reflect key fields into key attributes list List keyFields = keyClass.getFieldsExtended(); for (int i = 0; i < keyFields.size(); i++) { Field field = (Field) keyFields.get(i); if (field.getJavaVisibility() == JavaVisibilityKind.PUBLIC_LITERAL) { //only public fields CMPAttribute keyAttribute = cmp.getPersistentAttribute(field.getName()); if (keyAttribute != null) keys.add(keyAttribute); } } }
protected static String getTypeName(Field aField) { if (aField == null) return null; JavaHelpers type = (JavaHelpers)aField.getEType(); return getTypeName(type); }
protected static boolean isPublic(Field field) { if (field == null) return false; return (JavaVisibilityKind.PUBLIC_LITERAL.getValue() == field.getJavaVisibility().getValue()); }
tempField.setName(memberName);
public long getFieldType(EnterpriseBean bean, JavaClass clazz, Field field) { if(field == null) { return EXCLUDED_FIELD; } else if(field.getName().equals(IMethodAndFieldConstants.FIELDNAME_SERIALVERSIONUID)) { return SERIALVERSIONUID; } else { return OTHER_FIELD; } }
/** * Sort the list of the key attributes to match the order of the key class */ private void sortKeyAttributeList() { List result = new ArrayList(); JavaClass keyClass = cmp.getPrimaryKey(); if (keyClass == null) return; List keyFields = keyClass.getFieldsExtended(); List currentKeys = getKeyAttributes(); // create a new list of the attributes in order of key class fields. for (int i = 0; i < keyFields.size(); i++) { Field field = (Field) keyFields.get(i); if (field.getJavaVisibility() == JavaVisibilityKind.PUBLIC_LITERAL) { //only public fields for (int j=0; j<currentKeys.size(); j++) { CMPAttribute attribute = (CMPAttribute) currentKeys.get(j); if (field.getName().equals(attribute.getName())) result.add(attribute); } } } //clear list and set the new key attribute order on the cmp getKeyAttributes().clear(); getKeyAttributes().addAll(result); }