diff options
Diffstat (limited to 'plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal')
22 files changed, 0 insertions, 2964 deletions
diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/core/JEMPlugin.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/core/JEMPlugin.java deleted file mode 100644 index 05ce6cfbf..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/core/JEMPlugin.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - - - */ -package org.eclipse.jem.internal.core; - -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.Platform; -import org.osgi.framework.BundleContext; - -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jem.util.logger.proxyrender.EclipseLogger; - - -/** - * org.eclipse.jem plugin - */ -public class JEMPlugin extends Plugin { - - private static JEMPlugin PLUGIN; - private Logger logger; - private static final String PLUGIN_ID = "org.eclipse.jem"; //$NON-NLS-1$ - - public JEMPlugin() { - PLUGIN = this; - } - - public static JEMPlugin getPlugin() { - return PLUGIN; - } - - - /* (non-Javadoc) - * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - logger = EclipseLogger.getEclipseLogger(this); - } - - public Logger getLogger() { - return logger; - } - - public String getPluginID() { - return PLUGIN_ID; - } - - public static IStatus createStatus(int severity, String message, Throwable exception) { - return new Status(severity, PLUGIN_ID, severity, message, exception); - } - - public static void logWarning(String message, Throwable exception) { - Platform.getLog(Platform.getBundle(PLUGIN_ID)).log( createStatus(IStatus.WARNING, message , exception)); - } - - public static void logError(String message, Throwable exception) { - Platform.getLog(Platform.getBundle(PLUGIN_ID)).log( createStatus(IStatus.ERROR, message , exception)); - } - - -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/IJavaClassAdaptor.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/IJavaClassAdaptor.java deleted file mode 100644 index 54066782b..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/IJavaClassAdaptor.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters; -/* - - - */ -/** - * Insert the type's description here. - * Creation date: (8/27/2001 1:17:46 PM) - * @author: Administrator - */ -public interface IJavaClassAdaptor { -/** - * Return true if the sourceType is null or if - * it is a binary type. - */ -boolean isSourceTypeFromBinary() ; -/** - * Return true if the sourceType can be found. - */ -boolean sourceTypeExists() ; - -/** - * Reflect the fields - * @return <code>true</code> if reflection occurred. - * - * @since 1.0.0 - */ -boolean reflectFieldsIfNecessary(); - -/** - * Reflect the methods. - * @return <code>true</code> if reflection occurred. - * - * @since 1.0.0 - */ -boolean reflectMethodsIfNecessary(); -} - - - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/IJavaMethodAdapter.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/IJavaMethodAdapter.java deleted file mode 100644 index 68db0038f..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/IJavaMethodAdapter.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - - - */ -package org.eclipse.jem.internal.java.adapters; - - -/** - * Used to reflect methods - * @since 1.0.0 - */ -public interface IJavaMethodAdapter { - - /** - * Reflect the generated if necessary. - * @return <code>true</code> if reflection occurred. - * - * @since 1.0.0 - */ - public boolean reflectGeneratedIfNecessary(); - - /** - * Reflect the names of the method parameters if necessary. - * @return <code>true</code> if reflection occurred. - * - * @since 1.0.0 - */ - public boolean reflectParamNamesIfNecessary(); -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/InternalReadAdaptable.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/InternalReadAdaptable.java deleted file mode 100644 index f7c474de8..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/InternalReadAdaptable.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters; -/* - - - */ - -public interface InternalReadAdaptable extends org.eclipse.emf.common.notify.Notifier { -/** - * Implementers of this interface need to contain the following method - * implementations: - * public Object primRefValue(EObject a) { - * return super.getValue(a); - * } - * public Object getValue(EObject a) { - * return ReflectionAdaptor.getValue(this, a); - * } - */ -//public Object primRefValue(EObject a); -void setReflected(boolean aBoolean); -} - - - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaArrayTypeReflectionAdapter.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaArrayTypeReflectionAdapter.java deleted file mode 100644 index d8e1a6638..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaArrayTypeReflectionAdapter.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - - - */ -package org.eclipse.jem.internal.java.adapters; - -import java.util.List; - -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.jem.java.ArrayType; -import org.eclipse.jem.java.InheritanceCycleException; -import org.eclipse.jem.java.JavaClass; -import org.eclipse.jem.java.JavaHelpers; -import org.eclipse.jem.java.JavaRefFactory; -import org.eclipse.jem.java.internal.impl.ArrayTypeImpl; - -/** - * Array type reflection adapter. Since arrays are very constant we don't need any fancy reflection to the source type (class object). It really - * doesn't do anything. It is just here so that it exists. Everything is constant or depends on the final component type. - * - * @since 1.0.0 - */ -public class JavaArrayTypeReflectionAdapter extends JavaReflectionAdaptor implements IJavaClassAdaptor { - - public JavaArrayTypeReflectionAdapter(Notifier target) { - super(target); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#getReflectionSource() - */ - public Object getReflectionSource() { - return null; // There isn't any for arrays. - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#hasReflectionSource() - */ - public boolean hasReflectionSource() { - // This method is used to determine if valid, so we pass on to use the final component. - ArrayType jh = (ArrayType) getTarget(); - JavaHelpers fc = jh.getFinalComponentType(); - return (fc.isPrimitive() || ((JavaClass) fc).isExistingType()); - } - - public boolean hasCachedReflectionSource() { - ArrayType jh = (ArrayType) getTarget(); - JavaHelpers fc = jh.getFinalComponentType(); - if(fc.isPrimitive()) - return true; - else { - JavaReflectionAdaptor reflectionAdaptor = (JavaReflectionAdaptor) EcoreUtil.getExistingAdapter(fc, ReflectionAdaptor.TYPE_KEY); - return (reflectionAdaptor != null) ? reflectionAdaptor.hasCachedReflectionSource() : false; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.internal.java.adapters.ReflectionAdaptor#reflectValues() - */ - public boolean reflectValues() { - ArrayTypeImpl at = (ArrayTypeImpl) getTarget(); - - // Arrays are always: - // final - // Supertype of java.lang.Object - // implements java.lang.Cloneable, java.io.Serializable - at.setFinal(true); - try { - at.setSupertype((JavaClass) JavaRefFactory.eINSTANCE.reflectType("java.lang.Object", (EObject) getTarget())); //$NON-NLS-1$ - } catch (InheritanceCycleException e) { - } - List list = at.getImplementsInterfacesGen(); - list.add(JavaRefFactory.eINSTANCE.createClassRef("java.lang.Cloneable")); //$NON-NLS-1$ - list.add(JavaRefFactory.eINSTANCE.createClassRef("java.io.Serializable")); //$NON-NLS-1$ - return super.reflectValues(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#flushReflectedValues(boolean) - */ - protected boolean flushReflectedValues(boolean clearCachedModelObject) { - ArrayTypeImpl at = (ArrayTypeImpl) getTarget(); - at.getImplementsInterfacesGen().clear(); - return true; - } - - /* - * (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaClassAdaptor#isSourceTypeFromBinary() - */ - public boolean isSourceTypeFromBinary() { - return false; - } - - /* - * (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaClassAdaptor#reflectFieldsIfNecessary() - */ - public synchronized boolean reflectFieldsIfNecessary() { - return reflectValuesIfNecessary(); - } - - /* - * (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaClassAdaptor#reflectMethodsIfNecessary() - */ - public synchronized boolean reflectMethodsIfNecessary() { - return reflectValuesIfNecessary(); - } - - /* - * (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaClassAdaptor#sourceTypeExists() - */ - public boolean sourceTypeExists() { - return hasReflectionSource(); - } -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaReflectionAdapterFactory.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaReflectionAdapterFactory.java deleted file mode 100644 index 381376bdb..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaReflectionAdapterFactory.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters; -/* - - - */ -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EPackage; - -import org.eclipse.jem.java.JavaRefPackage; -public abstract class JavaReflectionAdapterFactory extends AdapterFactoryImpl { - // Maintain a mapping of the source objects to the adaptors which have - // relfected from them. This allows a flush operation to force those - // adapters to re-reflect. - protected HashMap reflected = new HashMap(); - /** - * Key for the type of adapters that this factory creates. (Used in isFactoryForType()). - */ - public static final String TYPE_KEY = ReadAdaptor.TYPE_KEY; - protected boolean isBusyIteratingReflected = false; - protected Map registerQueue; - protected List unregisterQueue; -/** - * JavaReflectionAdapterFactory constructor comment. - */ -public JavaReflectionAdapterFactory() { - super(); -} -public Adapter createAdapter(Notifier target) { - ReflectionAdaptor adapter = null; - EObject object = (EObject) target; - JavaRefPackage pack = getJavaRefPackage(); - if (object.eClass() == pack.getJavaClass()) - adapter = createJavaClassAdaptor(target); - else - if (object.eClass() == pack.getArrayType()) - adapter = createArrayTypeAdaptor(target); - else - if (object.eClass() == pack.getMethod()) - adapter = createJavaMethodAdaptor(target); - else - if (object.eClass() == pack.getField()) - adapter = createJavaFieldAdaptor(target); - return adapter; -} - -protected ReflectionAdaptor createArrayTypeAdaptor(Notifier target) { - return new JavaArrayTypeReflectionAdapter(target); -} - -protected abstract ReflectionAdaptor createJavaClassAdaptor(Notifier target) ; -protected abstract ReflectionAdaptor createJavaFieldAdaptor(Notifier target) ; -protected abstract ReflectionAdaptor createJavaMethodAdaptor(Notifier target) ; -// Flush the adapter for a source object -public Notification disAssociateSource(String source) { - return disAssociateSource(source, true); -} - -public Notification disAssociateSource(String source, boolean doNotify) { - JavaReflectionAdaptor a = (JavaReflectionAdaptor) reflected.get(source); - Notification notification = null; - if (a != null) { - if (doNotify) - a.releaseSourceType(); - else - notification = a.releaseSourceTypeNoNotification(); - } - return notification; -} -public void flushAll() {} -// Flush the adapter for a source object -public void flushReflection(String source) {} -protected JavaRefPackage getJavaRefPackage() { - return (JavaRefPackage) EPackage.Registry.INSTANCE.getEPackage(JavaRefPackage.eNS_URI); -} -public void registerReflection(String source, ReflectionAdaptor adapter) { - if (isBusyIteratingReflected) { - if (registerQueue == null) - registerQueue = new HashMap(); - registerQueue.put(source, adapter); - } else - reflected.put(source, adapter); -} -public void unregisterReflection(String source) { - if (isBusyIteratingReflected) { - if (unregisterQueue == null) - unregisterQueue = new ArrayList(); - unregisterQueue.add(source); - } else - reflected.remove(source); -} -public void disAssociateSourcePlusInner(String source) { - disAssociateSourcePlusInner(source, true); -} - -public Notification disAssociateSourcePlusInner(String source, boolean doNotify) { - isBusyIteratingReflected = true; - Notification notification = null; - try { - String innerName = source + '$'; - Iterator it = reflected.entrySet().iterator(); - Map.Entry entry; - String key; - JavaReflectionAdaptor adaptor; - while (it.hasNext()) { - entry = (Map.Entry) it.next(); - key = (String) entry.getKey(); - if (key.equals(source) || key.startsWith(innerName)) { - adaptor = (JavaReflectionAdaptor) reflected.get(key); - if (adaptor != null) { - if (doNotify) - adaptor.releaseSourceType(); - else - notification = adaptor.releaseSourceTypeNoNotification(); - } - } - } - } finally { - finishedIteratingReflected(); - } - return notification; -} - -protected void finishedIteratingReflected() { - isBusyIteratingReflected = false; - if (unregisterQueue != null && !unregisterQueue.isEmpty()) { - for (int i = 0; i < unregisterQueue.size(); i++) { - reflected.remove(unregisterQueue.get(i)); - } - unregisterQueue.clear(); - } - if (registerQueue != null && !registerQueue.isEmpty()) { - Iterator it = registerQueue.entrySet().iterator(); - Map.Entry entry; - while (it.hasNext()) { - entry = (Map.Entry) it.next(); - reflected.put(entry.getKey(), entry.getValue()); - } - registerQueue.clear(); - } -} -public boolean isFactoryForType(Object type) { - return TYPE_KEY.equals(type); -} -} - - - - - - - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaReflectionAdaptor.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaReflectionAdaptor.java deleted file mode 100644 index 1a1f7cda7..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaReflectionAdaptor.java +++ /dev/null @@ -1,274 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters; -/* - - - */ -import java.util.List; - -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.*; -import org.eclipse.emf.ecore.impl.ENotificationImpl; - -import org.eclipse.jem.java.*; -import org.eclipse.jem.util.logger.proxy.Logger; - -/** - * - */ -public abstract class JavaReflectionAdaptor extends ReflectionAdaptor { - private static final String C_METHOD_DEFAULT_CTOR = String.valueOf(C_METHOD_PARM_DELIMITER) + S_CONSTRUCTOR_TOKEN; - protected static final String LEFT_BRACKET = "[";//$NON-NLS-1$ - - /** - * Special notification event type. This is sent against a JavaClass (as the target) whenever flush of the reflection occurs. It will be - * sent under the notification event type of REFLECTION_EVENT. - * @since 1.1.0 - */ - public static final EAttribute FLUSH_REFLECTION_EVENT = EcorePackage.eINSTANCE.getEcoreFactory().createEAttribute(); - - /** - * Special notification event type. This is sent against a JavaClass (as the target) whenever flush of a new class (i.e. - * no source was found) of the reflection occurs. It will be - * sent under the notification event type of REFLECTION_EVENT. - * @since 1.1.0 - */ - public static final EAttribute FLUSH_NEW_REFLECTION_EVENT = EcorePackage.eINSTANCE.getEcoreFactory().createEAttribute(); - - /* - * Fill in the name. Not really needed but it would be nice. - */ - static { - FLUSH_REFLECTION_EVENT.setName("flushReflectedValues"); //$NON-NLS-1$ - FLUSH_NEW_REFLECTION_EVENT.setName("flushNewReflectedValues"); //$NON-NLS-1$ - } - protected boolean hasFlushed = false; - protected boolean isFlushing = false; -/** - * JavaReflectionAdapter constructor comment. - */ -public JavaReflectionAdaptor() { - super(); -} -/** - * JavaReflectionAdapter constructor comment. - * @param target org.eclipse.emf.common.notify.Notifier - */ -public JavaReflectionAdaptor(org.eclipse.emf.common.notify.Notifier target) { - super(target); -} -/** - * createBlock - instantiate a Block containing the passed source - */ -public Block createBlock(String name, String sourceString) { - Block newBlock = getJavaFactory().createBlock(); - newBlock.setName(name + "_" + "block");//$NON-NLS-2$//$NON-NLS-1$ - newBlock.setSource(sourceString); - return newBlock; -} -/** - * setSuper - set our supertype here, implemented interface are handled separately - */ -public JavaClass createJavaClassRef(String targetName) { - return JavaRefFactory.eINSTANCE.createClassRef(targetName); -} -/** - * createJavaParameter - instantiate a Java Parameter based on the passed name and type name (a simple name, NOT A SIGNATURE!!!) - * The id for a parameter has to be complex in order to be parsable into class, method, and parm. - * It is created by appending the parm name to the method id, with a known separator. - * It will look something like "Foo.doSomething(java.lang.Integer-arg0" - */ -public JavaParameter createJavaParameter(Method parentMethod, String parmName, String parmTypeName) { - JavaParameter newParm = getJavaFactory().createJavaParameter(); - if (parmName!=null) - newParm.setName(parmName); -// ((InternalEObject)newParm).eSetID(parentMethod.eID() + C_METHODID_PARMID_DELIMITER + parmName); - String classRefString = parmTypeName; - newParm.setEType(createJavaClassRef(classRefString)); - return newParm; -} -/** - * This method will return a List of dimensions for a typeName. - * For example "foo[][]" would return a List of Integers - * 1, 1. At some point we may want to actually capture the size - * for Fields but we would need the initializer source to determine that. - */ -public List getArrayDimensions(String typeName) { - List dimensions = new java.util.ArrayList(); - if (typeName != null) { - int begin = 0; - int index = -1; - while (begin < typeName.length()) { - index = typeName.indexOf(LEFT_BRACKET, begin); - if (index > -1) { - dimensions.add(new Integer(1)); - begin = index + 1; - } else { - begin = typeName.length(); - } - } - } - return dimensions; -} -/* Get the Java Factory - */ -protected static JavaRefFactory getJavaFactory() { - return ((org.eclipse.jem.java.JavaRefPackage)EPackage.Registry.INSTANCE.getEPackage(org.eclipse.jem.java.JavaRefPackage.eNS_URI)).getJavaRefFactory(); -} -public abstract Object getReflectionSource(); -/** - * getTypeNamesFromMethodUUID - Pull the parm type names out of a method ID - * It will be in the form: "simpleclass.methodName(com.fronk.Parm1_type,parm2type" - */ -protected static String[] getTypeNamesFromMethodID(String methodID) { - if (methodID.charAt(methodID.length()-1) == C_METHOD_PARM_DELIMITER || methodID.endsWith(C_METHOD_DEFAULT_CTOR)) - return emptyStringArray; - - // Count the parms first. The number of parms is the number of occurrences of ',' + 1 - int numParms = 1; - int pos = -1; - // Skip the '.' after classname - pos = methodID.indexOf(C_CLASS_MEMBER_DELIMITER, ++pos); - // Look for the start of the parms - int parmPos = methodID.indexOf(C_METHOD_PARM_DELIMITER, ++pos); - pos = parmPos; - while ((pos = methodID.indexOf(C_PARM_PARM_DELIMITER, ++pos)) != -1) - numParms++; - String[] parmTypeNames = new String[numParms]; - // now collect the parm names - // skip the method name - pos = parmPos; - int i = 0, end; - do { - end = methodID.indexOf(C_PARM_PARM_DELIMITER, pos + 1); - // This is the last parameter, we may need to strip a trailing &V for a constructor - if (end == -1) - end = methodID.indexOf(S_CONSTRUCTOR_TOKEN, pos + 1); - // otherwise take the rest of the ID - if (end == -1) - end = methodID.length(); - parmTypeNames[i++] = methodID.substring(pos + 1, end); - } while ((pos = methodID.indexOf(C_PARM_PARM_DELIMITER, ++pos)) != -1); - return parmTypeNames; -} -public abstract boolean hasCachedReflectionSource(); - -public boolean hasReflectionSource() { - return getReflectionSource() != null; -} - -/** - * Subclasses should override. - * - */ -public void releaseSourceType(){ -} - -/** - * Subclasses should override. - * @return - */ -public Notification releaseSourceTypeNoNotification() { - return null; -} - -public static void releaseSourceType(JavaClass javaClass) { - if (javaClass == null) - return; - - JavaReflectionAdaptor existing = (JavaReflectionAdaptor) retrieveAdaptorFrom(javaClass); - if (existing != null) - existing.releaseSourceType(); -} -/* - * This method is called by a Field Adaptor to set the type of aField - * to be aTypeName. aTypeName may contain array brackets which need - * to be detected in order to set the array dimensions on aField. - */ -protected void setFieldType(Field aField, String aTypeName) { - if (aField != null && aTypeName != null) { - String classRefString = aTypeName; - aField.setEType(createJavaClassRef(classRefString)); - } -} -public final boolean flushReflectedValuesIfNecessary() { - return flushReflectedValuesIfNecessary(false); -} -public final boolean flushReflectedValuesIfNecessary(boolean clearCachedModelObject) { - Notification not = flushReflectedValuesIfNecessaryNoNotification(clearCachedModelObject); - if (not != null) - getTarget().eNotify(not); - return hasFlushed; -} - -public synchronized Notification flushReflectedValuesIfNecessaryNoNotification(boolean clearCachedModelObject) { - if (!hasFlushed && !isFlushing) { - boolean isExisting = hasCachedReflectionSource(); - try { - isFlushing = true; - hasReflected = false; - hasFlushed = flushReflectedValues(clearCachedModelObject); - } catch (Throwable e) { - hasFlushed = false; - Logger.getLogger().log(e); - if (e instanceof RuntimeException) - throw (RuntimeException) e; - else if (e instanceof Error) - throw (Error) e; - else - throw new RuntimeException(e.getMessage()); - } finally { - isFlushing = false; - postFlushReflectedValuesIfNecessary(isExisting); - } - return createFlushNotification(isExisting); - } - return null; -} - -/** - * @param isExisting - * @return - */ -protected Notification createFlushNotification(boolean isExisting) { - EStructuralFeature feature = isExisting ? FLUSH_REFLECTION_EVENT : FLUSH_NEW_REFLECTION_EVENT; - return new ENotificationImpl((InternalEObject)getTarget(),EVENT, feature, null, null); -} -protected void postFlushReflectedValuesIfNecessary(boolean isExisting) { -} -/** - * Subclasses should override to perform the actual clearing of the values. - */ -protected boolean flushReflectedValues(boolean clearCachedModelObject) { - return true; -} -/** - * Return a boolean indicating whether reflection had occurred. - */ -public boolean reflectValuesIfNecessary() { - if (isFlushing) - return false; - return super.reflectValuesIfNecessary(); -} - -/** - * reflectValues - template method, subclasses override to pump values into target - */ -public boolean reflectValues() { - hasFlushed = false; - return true; -} -} - - - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaReflectionKey.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaReflectionKey.java deleted file mode 100644 index 25c482ee7..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaReflectionKey.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters; -/* - - - */ -import java.util.*; - -import org.eclipse.emf.ecore.*; -import org.eclipse.emf.ecore.util.EcoreUtil; - -import org.eclipse.jem.java.*; -import org.eclipse.jem.java.adapters.IJavaReflectionKey; -import org.eclipse.jem.java.adapters.IJavaReflectionKeyExtension; -import org.eclipse.jem.util.CharacterUtil; -import org.eclipse.jem.util.CharacterUtil.StringIterator; - -/** - * This key handles Java Reflection. It creates the appropriate type of entries if - * they are not already in the resource. There is an extension mechanism for other - * types of ids that are not recognized by this key. They are registered with the - * JavaXMIFactory that is used to create these keys, and the factory will pass in - * a List of these registered extension processers (IJavaReflectionKeyExtension). - * - * Creation date: (10/4/2000 8:24:36 AM) - * @author: Administrator - */ -public class JavaReflectionKey implements IJavaReflectionKey { - private static final Collection PRIMITIVES = new ArrayList(8); - - static { initializePrimitivesCollection(); } - - protected JavaXMIFactoryImpl.JavaXMIResource resource; //FB - protected List extensions; - -public JavaReflectionKey(List extensions, JavaXMIFactoryImpl.JavaXMIResource resource) { - this.extensions = extensions; - this.resource = resource; -} -//FB END - -/* - * Create an ArrayType instance in the current document - * Handles the push and pop of the current document. - */ -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#createArrayType() - */ -public ArrayType createArrayType() { - return getJavaFactory().createArrayType(); -} -/* - * Create a JavaClass instance in the current document - * Handles the push and pop of the current document. - */ -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#createJavaClass() - */ -public JavaClass createJavaClass() { - return getJavaFactory().createJavaClass(); -} -/** - * Create a data type and put it in the primitives resource - */ -protected EClassifier getJavaDataType(String typeName) { - JavaDataType result = getJavaFactory().createJavaDataType(); - result.setName(typeName); - // ((InternalEObject)result).eSetID(typeName); - //result.eSetUUID((UUID) null); - //result.setEPackage(getPackage()); - getPackage().getEClassifiers().add(result); - resource.setID(result, typeName); - return result; -} -/* - * Create a Field instance in the current document - * Handles the push and pop of the current document. - */ -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#createJavaField() - */ -public Field createJavaField() { - return getJavaFactory().createField(); -} -/* - * Create a Method instance in the current document - * Handles the push and pop of the current document. - */ -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#createJavaMethod() - */ -public Method createJavaMethod() { - return getJavaFactory().createMethod(); -} -/* - * Create a JavaParameter instance in the current document - */ -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#createJavaParameter() - */ -public JavaParameter createJavaParameter() { - return getJavaFactory().createJavaParameter(); -} -//FB/** -//FB * Override to try to introspect objects -//FB * that aren't found using the default mechanism. -//FB */ -//FBpublic Object get(Object key) { -//FB Object javaObject = super.get(key); -//FB if (javaObject == null) { -//FB javaObject = getObjectFromExtensions((String) key); -//FB if (javaObject == null) -//FB javaObject = getJavaObject((String) key); -//FB } -//FB return javaObject; -//FB} - -//FB ADDED -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#get(java.lang.String) - */ -public Object get(String key) { - Object javaObject = getObjectFromExtensions(key); - if (javaObject == null) - javaObject = getJavaObject(key); - return javaObject; -} -//FB END - -/* - * Instantiate the named class. - * If we make it to this point, the class has not yet been instantiated or reflected. - */ -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#getArrayType(java.lang.String) - */ -public EClassifier getArrayType(String typeName) { - ArrayType arrayType = this.createArrayType(); - arrayType.setName(typeName); - // ((InternalEObject)arrayType).eSetID(typeName); - //arrayType.eSetUUID((UUID) null); - int pos = -1, braces = 0; - do { - pos = typeName.indexOf("[", pos+1);//$NON-NLS-1$ - if (pos != -1) - braces++; - } while (pos != -1); - arrayType.setArrayDimensions(braces); - //arrayType.setEPackage(getPackage()); - getPackage().getEClassifiers().add(arrayType); - resource.setID(arrayType, typeName); - return arrayType; -} -/* - * Instantiate the named class. - * If we make it to this point, teh class has not yet been instantiated or reflected. - */ -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#getJavaClass(java.lang.String) - */ -public EClassifier getJavaClass(String typeName) { - JavaClass javaClass = this.createJavaClass(); - javaClass.setName(typeName); - // ((InternalEObject)javaClass).eSetID(javaClass.getName()); - //javaClass.eSetUUID((UUID) null); - // javaClass.setEPackage(getPackage()); - getPackage().getEClassifiers().add(javaClass); - resource.setID(javaClass, typeName); - return javaClass; -} -/* Get the Java Factory - */ -protected static JavaRefFactory getJavaFactory() { - return JavaRefFactory.eINSTANCE; -} -/** - * This allows for the direct retrieval of fields with the following notation: - * field: java:/com.ibm.foo#Test.foo - * - */ -protected Field getJavaField(String keyValue) { - Field result = null; - String className, memberName; - int memberDelimiter = keyValue.indexOf(ReflectionAdaptor.C_CLASS_MEMBER_DELIMITER); - className = keyValue.substring(0, memberDelimiter); - memberName = keyValue.substring(memberDelimiter + 1); - EClassifier javaClass = (EClassifier) primGet(className); - // if we haven't already instantiated the containing class, then go do it. - if (javaClass == null) - javaClass = getJavaType(className); - if ((javaClass != null) && !((JavaHelpers) javaClass).isPrimitive()) { - // We have a class. Now we need to force reflection, this will cause - // the JavaReflectionKey to be updated and have the member added to the - // list. - ((JavaClass) javaClass).getFields(); - //FB result = (Field) super.get(keyValue); // It should now be registered. - result = (Field) primGet(keyValue); // It should now be registered. - - if (result == null) { - Field tempField = createJavaField(); - tempField.setName(memberName); - // ((InternalEObject)tempField).eSetID(keyValue); - //tempField.eSetUUID((UUID) null); - ((JavaClass) javaClass).getFields().add(tempField); - result = tempField; - } - } - return result; -} -/** - * This allows for the retrieval of methods with the following notation: - * method: java:/com.ibm.foo#Test.foofoo( - * - */ -protected Method getJavaMethod(String keyValue) { - Method result = null; - String className, memberName; - int memberDelimiter = keyValue.indexOf(ReflectionAdaptor.C_CLASS_MEMBER_DELIMITER); - className = keyValue.substring(0, memberDelimiter); - int parmDelimiter = keyValue.indexOf(ReflectionAdaptor.C_METHOD_PARM_DELIMITER, memberDelimiter); - memberName = keyValue.substring(memberDelimiter + 1, parmDelimiter); - EClassifier javaClass = (EClassifier) primGet(className); - // if we haven't already instantiated the containing class, then go do it. - if (javaClass == null) - javaClass = getJavaType(className); - if ((javaClass != null) && !((JavaHelpers) javaClass).isPrimitive()) { - // We have a class. Now we need to force reflection, this will cause - // the JavaReflectionKey to be updated and have the member added to the - // list. - ((JavaClass) javaClass).getMethods(); - result = (Method) primGet(keyValue); // It should now be registered. - - if (result == null) { - Method tempMethod = createJavaMethod(); - tempMethod.setName(memberName); - resource.setID(tempMethod, keyValue); - ((JavaClass) javaClass).getMethods().add(tempMethod); - result = tempMethod; - } - } - return result; -} -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#getJavaObject(java.lang.String) - */ -public EObject getJavaObject(String keyValue) { - EObject result = null; - int index = keyValue.indexOf(ReflectionAdaptor.C_CLASS_MEMBER_DELIMITER); - if (index > 0) { - // The reference is to a member: field, method, or parameter. - // Take the most specific case first, a parameter. - // Only a parameter should contain the methodID to parmID delimiter. - boolean isParameter = (keyValue.indexOf(ReflectionAdaptor.C_METHODID_PARMID_DELIMITER, index) != -1); - if (isParameter) { - result = getJavaParameter(keyValue); - } else { - // The target is a field or method. If it has a "(", then it is a method. - // If it is not found, then we will create a temporary object. - int parmStart = keyValue.indexOf(ReflectionAdaptor.C_METHOD_PARM_DELIMITER, index); - boolean isField = parmStart == -1; - if (isField) { - result = getJavaField(keyValue); - } else { - result = getJavaMethod(keyValue); - } - } - } else { - result = getJavaType(keyValue); - } - return result; -} - -/** - * See if the extensions can resolve this first. - */ -protected Object getObjectFromExtensions(String keyValue) { - if (extensions != null) { - for (Iterator iter = extensions.iterator(); iter.hasNext();) { - IJavaReflectionKeyExtension extension = (IJavaReflectionKeyExtension) iter.next(); - Object obj = extension.getObject(keyValue, this); - if (obj != null) - return obj; - } - } - - return null; -} -/** - * This allows for the retrieval of parameters with the following notation: - * parameter: java:/com.ibm.foo#Test.foofoo(-arg0 - * - */ -protected JavaParameter getJavaParameter(String keyValue) { - JavaParameter result = null; - String parmName; - int memberDelimiter = keyValue.indexOf(ReflectionAdaptor.C_CLASS_MEMBER_DELIMITER); - int parmDelimiter = keyValue.indexOf(ReflectionAdaptor.C_METHODID_PARMID_DELIMITER, memberDelimiter); - parmName = keyValue.substring(parmDelimiter + 1); - // getMethod() will find or create a method - Method method = this.getJavaMethod(keyValue.substring(parmDelimiter)); - if (method != null) { - result = method.getParameter(parmName); - if (result == null) { - JavaParameter tempParameter = createJavaParameter(); - tempParameter.setName(parmName); - // ((InternalEObject)tempParameter).eSetID(keyValue); - // tempParameter.eSetUUID((UUID) null); - method.getParameters().add(tempParameter); - result = tempParameter; - } - } - return result; -} -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#getJavaType(java.lang.String) - */ -public EClassifier getJavaType(String typeName) { - if (isPrimitive(typeName)) - return getJavaDataType(typeName); - else if (isArray(typeName)) - return getArrayType(typeName); - else if (isValidJavaIdentifier(typeName)) - return getJavaClass(typeName); - return null; -} - -protected boolean isValidJavaIdentifier(String typeName) { - if (typeName.length() > 0) { - StringIterator charIter = new StringIterator(typeName); - if (CharacterUtil.isJavaIdentifierStart(charIter.next())) { - // Starts with a valid java identifier character. - // Now see if the rest are valid. - while (charIter.hasNext()) { - if (!CharacterUtil.isJavaIdentifierPart(charIter.next())) - return false; // Not valid - } - return true; - } - } - return false; -} - -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#primGet(java.lang.String) - */ -public Object primGet(String key) { - return resource.primGetEObject(key); -} -protected EPackage getPackage() { - //FB return (EPackage) super.get(JavaPackage.PACKAGE_ID); - // return (EPackage) resource.getEObject(JavaPackage.PACKAGE_ID); //FB - //return (EPackage) resource.getEObject(JavaPackage.PACKAGE_ID); //FB - return (EPackage)EcoreUtil.getObjectByType(resource.getContents(), EcorePackage.eINSTANCE.getEPackage()); -} -/** - * Insert the method's description here. - * Creation date: (10/4/2000 9:56:53 AM) - */ -private static void initializePrimitivesCollection() { - PRIMITIVES.add(N_VOID); - PRIMITIVES.add(N_BOOLEAN); - PRIMITIVES.add(N_BYTE); - PRIMITIVES.add(N_CHAR); - PRIMITIVES.add(N_DOUBLE); - PRIMITIVES.add(N_FLOAT); - PRIMITIVES.add(N_INT); - PRIMITIVES.add(N_LONG); - PRIMITIVES.add(N_SHORT); -} -/* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaReflectionKey#isArray(java.lang.String) - */ -public boolean isArray(String typeName) { - return typeName.endsWith("[]");//$NON-NLS-1$ -} -/** - * Insert the method's description here. - * Creation date: (10/4/2000 9:54:23 AM) - * @return boolean - * @param typeName java.lang.String - */ -private boolean isPrimitive(String typeName) { - return PRIMITIVES.contains(typeName); -} -} - - - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaXMIFactoryImpl.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaXMIFactoryImpl.java deleted file mode 100644 index b06e9a716..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/JavaXMIFactoryImpl.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters; -/* - - - */ -import java.io.IOException; -import java.util.*; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.xmi.XMIResource; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; -import org.eclipse.jem.java.JavaPackage; -import org.eclipse.jem.java.JavaRefFactory; -import org.eclipse.jem.java.adapters.*; -import org.eclipse.jem.java.internal.impl.JavaFactoryImpl; - -/** - * Factory to create the Resource for the Java protocol. - * - * It allows extensions to the reflection key to be registered with it. - * - * Creation date: (10/4/2000 8:22:23 AM) - * @author: Administrator - */ -public class JavaXMIFactoryImpl extends XMIResourceFactoryImpl implements JavaXMIFactory { - private static final String SCHEMA_SEPERATOR = ":/"; //$NON-NLS-1$ - protected List extensions = new ArrayList(); - - /** - * JavaXMIFactoryImpl constructor comment. - */ - public JavaXMIFactoryImpl() { - super(); - } - - - public void registerReflectionKeyExtension(IJavaReflectionKeyExtension extension) { - extensions.add(extension); - } - - - public void deregisterReflectionKeyExtension(IJavaReflectionKeyExtension extension) { - extensions.remove(extension); - } - - protected void createJavaPackage(String packageName, String xmiuri, Resource resource) { - // changed to allow a zero-length package name - // for the special case of "java:/#int", etc. - JavaRefFactory jfac = JavaRefFactory.eINSTANCE; - JavaPackage pack = jfac.createJavaPackage(); - // Need to create and add special JavaFactory for instantiation to work. - JavaFactoryImpl fact = new JavaFactoryImpl(); - pack.setEFactoryInstance(fact); - if (packageName.length() > 0) { - // Standard Java package - pack.setNsPrefix(packageName); - pack.setName(packageName); - } else { - // Primitive package - pack.setNsPrefix(JavaPackage.PRIMITIVE_PACKAGE_NAME); - pack.setName(JavaPackage.PRIMITIVE_PACKAGE_NAME); - } - - pack.setNsURI(xmiuri); - resource.getContents().add(pack); - ((XMIResource) pack.eResource()).setID(pack, JavaPackage.PACKAGE_ID); - } - public static class JavaXMIResource extends XMIResourceImpl { - protected IJavaReflectionKey reflectionKey; - - public JavaXMIResource(URI uri) { - super(uri); - } - - public void setReflectionKey(IJavaReflectionKey key) { - reflectionKey = key; - } - - public void load(Map options) throws IOException { - try { - super.load(options); - } catch (Exception exception) { - } - } - - public EObject getEObject(String uriFragment) { - EObject result = super.getEObject(uriFragment); - if (result == null && reflectionKey != null) { - result = (EObject) reflectionKey.get(uriFragment); - } - return result; - } - - /** - * Used by JavaReflectionKey to look directly into ID table to bypass an infinite loop. It will - * call here because it may not of first been found, but then added, so now is found. - * - * @param uriFragment - * @return - * - * @since 1.1.0 - */ - EObject primGetEObject(String uriFragment) { - return super.getEObject(uriFragment); - } - - /* (non-Javadoc) - * @see org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl#useIDAttributes() - */ - protected boolean useIDAttributes() { - return false; - } - - } - - public Resource createResource(URI uri) { - JavaXMIResource resource = new JavaXMIResource(uri); - resource.setReflectionKey(new JavaReflectionKey(extensions, resource)); - - String uriString = uri.toString(); - createJavaPackage(stripScheme(uriString), uriString, resource); - - return resource; - } - - public static void register() { - Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap().put(JavaXMIFactory.SCHEME, JavaXMIFactory.INSTANCE); - } - - /** - * Strip the trailing identifier, if any, from the uri. An identifier - * begins with # or |. - */ - private String stripScheme(String uri) { - int index = uri.indexOf(SCHEMA_SEPERATOR); - if (index != -1) - return uri.substring(index + SCHEMA_SEPERATOR.length(), uri.length()); - else - return uri; - } - -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/ReadAdaptor.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/ReadAdaptor.java deleted file mode 100644 index d73dafc33..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/ReadAdaptor.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters; -/* - - - */ - -import org.eclipse.emf.ecore.EObject; -/** - * Extended Adaptor interface which adds support for an adapter - * providing default values for attributes. - * Creation date: (6/6/2000 4:41:19 PM) - * @author: Scott Rich - */ -public interface ReadAdaptor extends org.eclipse.emf.common.notify.Adapter { - public static final String TYPE_KEY = "JavaReflection"; //$NON-NLS-1$ - public Object getValueIn(EObject object, EObject attribute); - public boolean reflectValuesIfNecessary(); //FB -} - - - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/ReflectionAdaptor.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/ReflectionAdaptor.java deleted file mode 100644 index 6c89ca344..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/ReflectionAdaptor.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters; -/* - - - */ -import java.util.logging.Level; - -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.ecore.*; -import org.eclipse.emf.ecore.impl.ENotificationImpl; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.util.EcoreUtil; - -import org.eclipse.jem.internal.core.JEMPlugin; -import org.eclipse.jem.internal.java.adapters.nls.ResourceHandler; -import org.eclipse.jem.util.logger.proxy.Logger; -/** - * ReflectionAdaptor - a read adaptor base implementation which does a bulk - * load of relflected values on the first request. - * Subclasses can optimize to defer some properties. - * Properties may also be deferred by setting their values with proxy references, - * for example, for supertype and other referenced types. - * Creation date: (6/6/2000 4:42:50 PM) - * @author: Administrator - */ -public abstract class ReflectionAdaptor extends org.eclipse.emf.common.notify.impl.AdapterImpl implements ReadAdaptor { - public static final char C_CLASS_MEMBER_DELIMITER = '.'; - public static final char C_METHOD_PARM_DELIMITER = '('; - public static final char C_METHODID_PARMID_DELIMITER = '-'; - public static final char C_PARM_PARM_DELIMITER = ','; - public static final char PATH_DELIMITER = '/'; - // SW id contains & in xml file casues exception throw during load - // public static final String S_CONSTRUCTOR_TOKEN = "&V";//$NON-NLS-1$ - public static final String S_CONSTRUCTOR_TOKEN = "_V";//$NON-NLS-1$ // SW - // cache a static empty String[] for no parm methods - protected static String[] emptyStringArray = new String[0]; - - - /** - * Notification event type for special Reflection notifications. This will be the event type for the special ones, like REFLECTION_EVENT. - * The listener should listen for this event type, and then check the feature for the type of special event (like REFLECTION_EVENT). - * @since 1.1.0 - */ - public static final int EVENT = -3456; // Using a funny number to try to eliminate confliction with any other specials that may of occur from other code on the JavaClass. - - /** - * Special notification event type. This is sent against a JavaClass (as the target) whenever reflection occurs. It will be - * sent under the notification event type of REFLECTION_EVENT. - * @since 1.1.0 - */ - public static final EAttribute REFLECTION_EVENT = EcoreFactory.eINSTANCE.createEAttribute(); - - /* - * Fill in the name. Not really needed but it would be nice. - */ - static {REFLECTION_EVENT.setName("reflectValues");} //$NON-NLS-1$ - - protected boolean hasReflected = false; - protected boolean isReflecting = false; -public ReflectionAdaptor() { - super(); -} -public ReflectionAdaptor(Notifier target) { - super(); - setTarget(target); -} -/** - * Helper method to ensure full initialization of the target. Required - * for serialization. - */ -public static void forceDeferredReadFor(EObject target) { - ReflectionAdaptor adaptor = retrieveAdaptorFrom(target); - if (adaptor != null) { - adaptor.reflectValuesIfNecessary(); - } -} -protected Resource getTargetResource() { - if (getTarget() != null) - return ((org.eclipse.emf.ecore.EObject) getTarget()).eResource(); - return null; -} -/** - * Helper method to fetch the adaptor from the object, and if it exists, get the adapted - * value for the attribute. Overloaded for many-sided attributes where the return value would - * otherwise be an enumeration; in this case will return an Array instead. - */ -public static Object getValue(EObject object, EReference attribute) { -//FB ReflectionAdaptor adaptor = retrieveAdaptorFrom(object); -//FB if (adaptor != null) -//FB return adaptor.getValueIn(object, attribute); -//FB return ((IReadAdaptable) object).primRefValue(attribute); - return object.eGet(attribute); //FB - -} -/*Helper method to fetch the adaptor from the object, and if it exists, get the adapted - *value for the attribute. - */ -public static Object getValue(EObject object, EObject attribute) { -//FB ReflectionAdaptor adaptor = retrieveAdaptorFrom(object); -//FB if (adaptor != null) -//FB return adaptor.getValueIn(object, attribute); -//FB return ((IReadAdaptable) object).primRefValue(attribute); - return object.eGet((EStructuralFeature)attribute); //FB -} -/** - * getValueIn method comment. - */ -public Object getValueIn(EObject object, EObject attribute) { -//FB reflectValuesIfNecessary(); -//FB return ((IReadAdaptable) object).primRefValue(attribute); - return object.eGet((EStructuralFeature)attribute); //FB -} -/** - * isAdaptorForType method comment. - */ -public boolean isAdapterForType(Object type) { - return (type == ReadAdaptor.TYPE_KEY); -} -/** - * reflectValues - template method, subclasses override to pump values into target - */ -public abstract boolean reflectValues(); -/** - * Return a boolean indicating whether reflection had occurred. - */ -public synchronized boolean reflectValuesIfNecessary() { - if (!hasReflected && !isReflecting) { - try { - isReflecting = true; - EObject etarget = (EObject)getTarget(); - if (!etarget.eIsProxy() && etarget.eResource() != null && etarget.eResource().getResourceSet() != null) - hasReflected = reflectValues(); - else - hasReflected = false; // AS long we are a proxy or is not in a valid resource or set, we won't reflect. - } catch (Exception e) { - hasReflected = false; - Logger logger = Logger.getLogger(); - if (logger.isLoggingLevel(Level.WARNING)) { - logger.log(ResourceHandler.getString("Failed_reflecting_values_ERROR_"), Level.WARNING); //$NON-NLS-1$ = "Failed reflecting values!!!" - logger.logWarning(e); - JEMPlugin.logWarning(ResourceHandler.getString("Failed_reflecting_values_ERROR_"), e); - } - } finally { - isReflecting = false; - getTarget().eNotify(new ENotificationImpl((InternalEObject)getTarget(), EVENT, REFLECTION_EVENT, null, null, Notification.NO_INDEX)); - } - } - return hasReflected; -} -public static ReflectionAdaptor retrieveAdaptorFrom(EObject object) { - synchronized (object) { - return (ReflectionAdaptor)EcoreUtil.getRegisteredAdapter(object, ReadAdaptor.TYPE_KEY); - } -} -} - - - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JDKAdaptor.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JDKAdaptor.java deleted file mode 100644 index cfc16e669..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JDKAdaptor.java +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters.jdk; -/* - - - */ - -import java.lang.reflect.Array; - -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.ecore.xmi.XMIResource; -import org.eclipse.jem.java.*; -import org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor; -/** - * Insert the type's description here. - * Creation date: (6/6/2000 4:42:50 PM) - * @author: Administrator - */ -public abstract class JDKAdaptor extends JavaReflectionAdaptor { - public JavaJDKAdapterFactory adapterFactory; - public JDKAdaptor(Notifier target, JavaJDKAdapterFactory anAdapterFactory) { - super(target); - setAdapterFactory(anAdapterFactory); - } - /** - * computeMethodID - generate the unique ID to be used to identify a constructor. - * Similar to a Signature, but hopefully more readable. - * The name format will be: - * simpleClassName.simpleClassName(com.fronk.ParmType1_parmType2&V - * Note: This implementation is tightly coupled with ReflectionAdapter.getTypeNamesFromMethodID(). - * - * It has to be done separately for JDK because Constructors and Methods are different classes. - * However, in the Java Model they are both just Methods with a flag indicating Constructor. - */ - public static String computeMethodID(java.lang.reflect.Constructor jdkConstructor) { - StringBuffer out = new StringBuffer(); - String className = getSimpleName(jdkConstructor.getDeclaringClass().getName()); - out.append(className); - out.append(C_CLASS_MEMBER_DELIMITER); - out.append(computeMethodName(jdkConstructor)); - out.append(C_METHOD_PARM_DELIMITER); - Class[] parmTypes = jdkConstructor.getParameterTypes(); - for (int i = 0; i < parmTypes.length; i++) { - out.append(parmTypes[i].getName()); - if (i < parmTypes.length - 1) - out.append(C_PARM_PARM_DELIMITER); - } - out.append(S_CONSTRUCTOR_TOKEN); //It's a constructor - return out.toString(); - } - /** - * computeMethodID - generate the unique ID to be used to identify a method. - * Similar to a Signature, but hopefully more readable. - * If there are no parms, it will end with a "(" so that it can be distictive from a field. - * The name format will be: - * simpleClassName.methodName(com.fronk.ParmType1_parmType2 - * Note: This implementation is tightly coupled with ReflectionAdapter.getTypeNamesFromMethodID(). - */ - public static String computeMethodID(java.lang.reflect.Method jdkMethod) { - StringBuffer out = new StringBuffer(); - String className = getSimpleName(jdkMethod.getDeclaringClass().getName()); - out.append(className); - out.append(C_CLASS_MEMBER_DELIMITER); - out.append(computeMethodName(jdkMethod)); - out.append(C_METHOD_PARM_DELIMITER); - Class[] parmTypes = jdkMethod.getParameterTypes(); - for (int i = 0; i < parmTypes.length; i++) { - out.append(parmTypes[i].getName()); - if (i < parmTypes.length - 1) - out.append(C_PARM_PARM_DELIMITER); - } - if (jdkMethod.getDeclaringClass().getName().equals(jdkMethod.getName())) - out.append(S_CONSTRUCTOR_TOKEN); //It's a constructor - return out.toString(); - } - /** - * computeMethodName - generate the name to be used to identify a constructor. - * For the moment, names are simple, and UUID's are complex. - * - * It has to be done separately for JDK because Constructors and Methods are different classes. - * However, in the Java Model they are both just Methods with a flag indicating Constructor. - */ - public static String computeMethodName(java.lang.reflect.Constructor jdkConstructor) { - return getSimpleName(jdkConstructor.getName()); // CTOR names come back fully-qualified with package. - } - /** - * computeMethodName - generate the name to be used to identify a method. - * For the moment, names are simple, and UUID's are complex. - */ - public static String computeMethodName(java.lang.reflect.Method jdkMethod) { - return jdkMethod.getName(); - } - /** - * 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; - } - /** - * createJavaMethod - instantiate a Java Method based on the passed Java Reflection Constructor - * We are deferring method contents assuming that its adaptor will reflect its details. - * We need to store enough info in the empty Method to find its Java source. - * The ID will eventually hold enough info to identify the source, so we use it. - */ - public Method createJavaMethod(java.lang.reflect.Constructor jdkConstructor, XMIResource resource) { - Method newMethod = getJavaFactory().createMethod(); - // We use a simple name, but a complex ID - newMethod.setName(computeMethodName(jdkConstructor)); - resource.setID(newMethod, computeMethodID(jdkConstructor)); - return newMethod; - } - /** - * createJavaMethod - instantiate a Java Method based on the passed Java Reflection Method - * We are deferring method contents assuming that its adaptor will reflect its details. - * We need to store enough info in the empty Method to find its Java source. - * The ID will eventually hold enough info to identify the source, so we use it. - */ - public Method createJavaMethod(java.lang.reflect.Method jdkMethod, XMIResource resource) { - Method newMethod = getJavaFactory().createMethod(); - // We use a simple name, but a complex ID - newMethod.setName(computeMethodName(jdkMethod)); - resource.setID(newMethod, computeMethodID(jdkMethod)); - return newMethod; - } - /** - * Insert the method's description here. - * Creation date: (11/07/00 3:43:55 PM) - * @return org.eclipse.jem.java.adapters.JavaJDKAdapterFactory - */ - public JavaJDKAdapterFactory getAdapterFactory() { - return adapterFactory; - } - public ClassLoader getAlternateClassLoader() { - return getAdapterFactory().getContextClassLoader(); - } - /***************************************************************************** - * Method to convert the textual form of a primitive type into its Class object - * - * @param type The primitive type's textual representation - */ - public static Class getPrimitiveType(String type) { - Class c = null; - - if (type.equals(byte.class.getName())) { - c = byte.class; - } else if (type.equals(short.class.getName())) { - c = short.class; - } else if (type.equals(int.class.getName())) { - c = int.class; - } else if (type.equals(long.class.getName())) { - c = long.class; - } else if (type.equals(float.class.getName())) { - c = float.class; - } else if (type.equals(double.class.getName())) { - c = double.class; - } else if (type.equals(boolean.class.getName())) { - c = boolean.class; - } else if (type.equals(char.class.getName())) { - c = char.class; - } else if (type.equals(void.class.getName())) { - c = void.class; - } - - return c; - } - /** - * Returns the last segment of a '.'-separated qualified name. - * Returns the given name if it is not qualified. - * For example: - * <pre> - * getSimpleName("java.lang.Object") -> "Object" - * </pre> - */ - public static String getSimpleName(String name) { - int lastDot = name.lastIndexOf('.'); - if (lastDot == -1) - return name; - return name.substring(lastDot + 1); - } - public Class getType(JavaHelpers modelClass) { - Class result = null; - if (modelClass.isArray()) { - ArrayType arrayType = (ArrayType) modelClass; - Class componentClass = getType(arrayType.getFinalComponentType()); - result = (Array.newInstance(componentClass, new int[arrayType.getArrayDimensions()])).getClass(); - } else if (modelClass.isPrimitive()) { - result = getType(modelClass.getQualifiedName()); - } else { - result = getType(((JavaClass) modelClass).getQualifiedNameForReflection()); - } - return result; - } - public Class getType(String qualifiedName) { - // Try for a primitive type ("int","char",etc.) first - Class primType = getPrimitiveType(qualifiedName); - if (primType == null) { - // Changed for defect #212147 botp@ausaix19.austin.ibm.com@7630 system. - // - // Search only one of the following classloaders (the first one that exists) in this order. If not found - // in a classloader, it will not roll-over to another class loader. This is to avoid problems where a - // class may exist in more than one classloader. You get errors when this happens due to one class that - // was found in only one classloader that refers to another class that was found in both classloaders. - // They don't match when trying to reflect later. - // 1) Alternate classloader (if exists) - // 2) Thread context classloader (if exists) - // 3) System classloader (if exists) - // 4) Class.forName(). - if (getAlternateClassLoader() != null) { - try { - return getAlternateClassLoader().loadClass(qualifiedName); - } catch (ClassNotFoundException cnf2) { - return null; - } - } - - ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - if (contextClassLoader != null) { - try { - return contextClassLoader.loadClass(qualifiedName); - } catch (ClassNotFoundException e) { - return null; - } - } - - ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); - if (systemClassLoader != null) { - try { - return systemClassLoader.loadClass(qualifiedName); - } catch (ClassNotFoundException e) { - return null; - } - } - - try { - return Class.forName(qualifiedName); - } catch (ClassNotFoundException e) { - return null; - } - } else - return primType; - } - /* - * Utility routine to paper over array type names - * Borrowed from a package-visibility helper on java.lang.reflect.Field - */ - static String getTypeName(Class type) { - if (type.isArray()) { - try { - Class cl = type; - int dimensions = 0; - while (cl.isArray()) { - dimensions++; - cl = cl.getComponentType(); - } - StringBuffer sb = new StringBuffer(); - sb.append(cl.getName()); - for (int i = 0; i < dimensions; i++) { - sb.append("[]"); //$NON-NLS-1$ - } - return sb.toString(); - } catch (Exception e) { /*FALLTHRU*/ - } - } - return type.getName(); - } - - /***************************************************************************** - * Method to convert the textual form of a primitive type into its Class object - * - * @param type The primitive type's textual representation - */ - public static Class primitiveForName(String type) { - Class c = null; - - if (type.equals(byte.class.getName())) { - c = byte.class; - } else if (type.equals(short.class.getName())) { - c = short.class; - } else if (type.equals(int.class.getName())) { - c = int.class; - } else if (type.equals(long.class.getName())) { - c = long.class; - } else if (type.equals(float.class.getName())) { - c = float.class; - } else if (type.equals(double.class.getName())) { - c = double.class; - } else if (type.equals(boolean.class.getName())) { - c = boolean.class; - } else if (type.equals(char.class.getName())) { - c = char.class; - } else if (type.equals(void.class.getName())) { - c = void.class; - } - - return c; - } - - /** - * Insert the method's description here. - * Creation date: (11/07/00 3:43:55 PM) - * @param newAdapterFactory org.eclipse.jem.java.adapters.JavaJDKAdapterFactory - */ - public void setAdapterFactory(JavaJDKAdapterFactory newAdapterFactory) { - adapterFactory = newAdapterFactory; - } -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaClassJDKAdaptor.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaClassJDKAdaptor.java deleted file mode 100644 index 6d6f99104..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaClassJDKAdaptor.java +++ /dev/null @@ -1,354 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - - - */ - -package org.eclipse.jem.internal.java.adapters.jdk; - -import java.util.List; -import java.util.logging.Level; - -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.xmi.XMIResource; - -import org.eclipse.jem.internal.java.adapters.IJavaClassAdaptor; -import org.eclipse.jem.internal.java.adapters.nls.ResourceHandler; -import org.eclipse.jem.java.*; -import org.eclipse.jem.java.internal.impl.JavaClassImpl; -import org.eclipse.jem.util.logger.proxy.Logger; - -/** - * Reflect the class using standard java.reflect methods. - * Creation date: (6/6/2000 4:42:50 PM) - * @author: Administrator - */ -public class JavaClassJDKAdaptor extends JDKAdaptor implements IJavaClassAdaptor { - - protected Class sourceType = null; - - public JavaClassJDKAdaptor(Notifier target, JavaJDKAdapterFactory anAdapterFactory) { - super(target, anAdapterFactory); - } - - /** - * addFields - reflect our fields - */ - protected void addFields() { - XMIResource resource = (XMIResource) getJavaClassTarget().eResource(); - List targetFields = getJavaClassTarget().getFieldsGen(); - targetFields.clear(); - java.lang.reflect.Field[] fields = {}; - try { - fields = getSourceType().getDeclaredFields(); - } catch (NoClassDefFoundError error) { - System.out.println(ResourceHandler.getString( - "Could_Not_Reflect_Fields_ERROR_", new Object[] { getJavaClassTarget().getQualifiedName(), error.getMessage()})); //$NON-NLS-1$ - } - for (int i = 0; i < fields.length; i++) { - targetFields.add(createJavaField(fields[i], resource)); - } - } - - /** - * addMethods - reflect our methods - */ - protected void addMethods() { - // We need to first do methods and then do constructors because the JDK treats them as two - // different objects, which the Java Model treats them as both Method's. - XMIResource resource = (XMIResource) getJavaClassTarget().eResource(); - List targetMethods = getJavaClassTarget().getMethodsGen(); - targetMethods.clear(); - java.lang.reflect.Method[] methods = {}; - try { - methods = getSourceType().getDeclaredMethods(); - } catch (NoClassDefFoundError error) { - Logger logger = Logger.getLogger(); - if (logger.isLoggingLevel(Level.WARNING)) { - logger - .log( - ResourceHandler - .getString( - "Could_Not_Reflect_Methods_ERROR_", new Object[] { getJavaClassTarget().getQualifiedName(), error.toString()}), Level.WARNING); //$NON-NLS-1$ - } - } - for (int i = 0; i < methods.length; i++) { - targetMethods.add(createJavaMethod(methods[i], resource)); - } - - // Now do the constructors - java.lang.reflect.Constructor[] ctors = {}; - try { - ctors = getSourceType().getDeclaredConstructors(); - } catch (NoClassDefFoundError error) { - Logger logger = Logger.getLogger(); - if (logger.isLoggingLevel(Level.WARNING)) { - logger - .log( - ResourceHandler - .getString( - "Could_Not_Reflect_Constructors_ERROR_", new Object[] { getJavaClassTarget().getQualifiedName(), error.getMessage()}), Level.WARNING); //$NON-NLS-1$ - } - } - for (int i = 0; i < ctors.length; i++) { - targetMethods.add(createJavaMethod(ctors[i], resource)); - } - - } - - /** - * Clear the reflected fields list. - */ - protected boolean flushFields() { - getJavaClassTarget().getFieldsGen().clear(); - return true; - } - - /** - * Clear the implements list. - */ - protected boolean flushImplements() { - getJavaClassTarget().getImplementsInterfacesGen().clear(); - return true; - } - - /** - * Clear the reflected methods list. - */ - protected boolean flushMethods() { - getJavaClassTarget().getMethodsGen().clear(); - return true; - } - - protected boolean flushInnerClasses() { - getJavaClassTarget().getDeclaredClassesGen().clear(); - return true; - } - - protected boolean flushModifiers() { - JavaClass javaClassTarget = (JavaClass) getTarget(); - javaClassTarget.setAbstract(false); - javaClassTarget.setFinal(false); - javaClassTarget.setPublic(false); - javaClassTarget.setKind(TypeKind.UNDEFINED_LITERAL); - return true; - } - - /** - * @see org.eclipse.jem.java.adapters.JavaReflectionAdaptor#flushReflectedValues(boolean) - */ - protected boolean flushReflectedValues(boolean clearCachedModelObject) { - boolean result = flushModifiers(); - result &= flushSuper(); - result &= flushImplements(); - result &= flushMethods(); - result &= flushFields(); - result &= flushInnerClasses(); - return result; - } - - /** - * @see org.eclipse.jem.java.adapters.JavaReflectionAdaptor#postFlushReflectedValuesIfNecessary() - */ - protected void postFlushReflectedValuesIfNecessary(boolean isExisting) { - getJavaClassTarget().setReflected(false); - super.postFlushReflectedValuesIfNecessary(isExisting); - } - - /** - * Set the supertype to be null. - */ - protected boolean flushSuper() { - List targetSupers = getJavaClassTarget().primGetESuperTypes(); - targetSupers.clear(); - return true; - } - - /** - * Return the target typed to a JavaClass. - */ - protected JavaClassImpl getJavaClassTarget() { - return (JavaClassImpl) getTarget(); - } - - public Object getReflectionSource() { - return getSourceType(); - } - /* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#hasReflectionSource() - */ - public boolean hasCachedReflectionSource() { - return sourceType != null; - } - - /** - * getSourceType - return the java.lang.Class which describes our existing Java class - */ - protected Class getSourceType() { - if (sourceType == null) { - sourceType = getType((JavaClass) getTarget()); - } - return sourceType; - } - - /** - * getValueIn method comment. - */ - public Object getValueIn(EObject object, EObject attribute) { - // At this point, this adapter does not dynamically compute any values, - // all values are pushed back into the target on the initial call. - return super.getValueIn(object, attribute); - } - - /** - * Return true if the sourceType is null or if it is a binary type. Reflection from the JDK is always from binary. - */ - public boolean isSourceTypeFromBinary() { - return true; - } - - /** - * reflectValues - template method, subclasses override to pump values into target. on entry: name, containing package (and qualified name), and - * document must be set. Return true if successful JavaClass adaptor: - set modifiers - set name - set reference to super - create methods - - * create fields - add imports - */ - public boolean reflectValues() { - super.reflectValues(); - try { - if (getSourceType() != null) { - setModifiers(); - setNaming(); - try { - setSuper(); - } catch (InheritanceCycleException e) { - Logger.getLogger().log(e); - } - setImplements(); - addMethods(); - addFields(); - reflectInnerClasses(); - setDeclaringClass(); - getAdapterFactory().registerReflection(getSourceType().getName(), this); - // addImports(); - return true; - } - return false; - } finally { - //Don't cache the class beyond the operation of reflect values; - //this enables dynamic swapping of the alternate class loader - //for java reflection, as well as avoids potential memory leakage - sourceType = null; - } - } - - protected void setDeclaringClass() { - Class declaringType = getSourceType().getDeclaringClass(); - if (declaringType != null) { - // Need to get it and reflect it so that the declared type of this target is set correctly. We can just - // set it ourselves directly because ECore would try to add it to the list of inner classes of the declaring type. This - // would cause it to be added twice, once from the reflection caused by the inverse setting, and once from our doing - // the inverse setting itself. - ResourceSet set = getTargetResource().getResourceSet(); - JavaClassImpl declaringClass = (JavaClassImpl) JavaRefFactory.eINSTANCE.reflectType(declaringType.getName(), set); - declaringClass.getDeclaredClasses(); // This will cause it to put us into its list and also set our declaring class to this declaring type. - } - } - - /** - * - */ - protected void reflectInnerClasses() { - Class[] innerClasses = getSourceType().getClasses(); - if (innerClasses.length != 0) { - List declaredClasses = getJavaClassTarget().getDeclaredClassesGen(); - JavaClass inner; - ResourceSet set = getTargetResource().getResourceSet(); - for (int i = 0; i < innerClasses.length; i++) { - inner = (JavaClass) JavaRefFactory.eINSTANCE.reflectType(innerClasses[i].getName(), set); - declaredClasses.add(inner); - } - } - - } - - /** - * setImplements - set our implemented/super interfaces here For an interface, these are superclasses. For a class, these are implemented - * interfaces. - */ - protected void setImplements() { - Class[] interfaces = getSourceType().getInterfaces(); - // needs work, the names above will be simple names if we are relfecting from a source file - JavaClassImpl javaClassTarget = (JavaClassImpl) getTarget(); - JavaClass ref; - List intList = javaClassTarget.getImplementsInterfacesGen(); - intList.clear(); - for (int i = 0; i < interfaces.length; i++) { - ref = createJavaClassRef(interfaces[i].getName()); - intList.add(ref); - } - } - - /** - * setModifiers - set the attribute values related to modifiers here - */ - protected void setModifiers() { - JavaClass javaClassTarget = (JavaClass) getTarget(); - javaClassTarget.setAbstract(java.lang.reflect.Modifier.isAbstract(getSourceType().getModifiers())); - javaClassTarget.setFinal(java.lang.reflect.Modifier.isFinal(getSourceType().getModifiers())); - javaClassTarget.setPublic(java.lang.reflect.Modifier.isPublic(getSourceType().getModifiers())); - // Set type to class or interface, not yet handling EXCEPTION - if (getSourceType().isInterface()) - javaClassTarget.setKind(TypeKind.INTERFACE_LITERAL); - else - javaClassTarget.setKind(TypeKind.CLASS_LITERAL); - } - - /** - * setNaming - set the naming values here - qualified name (package name + name) must be set first, that is the path to the real Java class - ID - - * simple name, identity within a package document - NO UUID!!! - */ - protected void setNaming() { - // JavaClass javaClassTarget = (JavaClass) getTarget(); - // javaClassTarget.refSetUUID((String) null); - // ((XMIResource)javaClassTarget.eResource()).setID(javaClassTarget,getSimpleName(getSourceType().getName())); - } - - /** - * setSuper - set our supertype here, implemented interface are handled separately - */ - protected void setSuper() throws InheritanceCycleException { - Class superClass = null; - superClass = getSourceType().getSuperclass(); - if (superClass != null) { - JavaClass javaClassTarget = (JavaClass) getTarget(); - javaClassTarget.setSupertype(createJavaClassRef(superClass.getName())); - } - } - - /** - * Return true if the sourceType can be found. - */ - public boolean sourceTypeExists() { - return getSourceType() != null; - } - - public boolean reflectFieldsIfNecessary() { - return reflectValuesIfNecessary(); - } - - public boolean reflectMethodsIfNecessary() { - return reflectValuesIfNecessary(); - } -} - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaFieldJDKAdaptor.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaFieldJDKAdaptor.java deleted file mode 100644 index 7846917b7..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaFieldJDKAdaptor.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters.jdk; -/* - - - */ -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.jem.java.*; -import org.eclipse.jem.internal.java.adapters.ReadAdaptor; -/** - * Insert the type's description here. - * Creation date: (6/6/2000 4:42:50 PM) - * @author: Administrator - */ -public class JavaFieldJDKAdaptor extends JDKAdaptor { - protected java.lang.reflect.Field sourceField = null; - protected Class parentType = null; - public JavaFieldJDKAdaptor(Notifier target, JavaJDKAdapterFactory anAdapterFactory) { - super(target, anAdapterFactory); - } - /** - * getParentType - return the Class which corresponds to our parent JavaClass - * we're going to do this a lot, so cache it. - */ - protected Class getParentType() { - if (parentType == null) { - Field targetField = (Field) getTarget(); - JavaClass parentJavaClass = targetField.getJavaClass(); - JavaClassJDKAdaptor pa = (JavaClassJDKAdaptor) EcoreUtil.getAdapter(parentJavaClass.eAdapters(), ReadAdaptor.TYPE_KEY); - if (pa != null) - parentType = pa.getSourceType(); - } - return parentType; - } - public Object getReflectionSource() { - return getSourceField(); - } - - /* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#hasReflectionSource() - */ - public boolean hasCachedReflectionSource() { - return sourceField != null; - } - /** - * getSourceField - return the java.lang.reflect.Field which describes our implementing field - */ - protected java.lang.reflect.Field getSourceField() { - if (sourceField == null) { - Class parent = this.getParentType(); - if (parent != null) { - try { - sourceField = parent.getDeclaredField(((Field) getTarget()).getName()); - } catch (NoSuchFieldException e) { - // OK, carry on - } - } - } - return sourceField; - } - public Field getTargetField() { - return (Field) getTarget(); - } - /** - * getValueIn method comment. - */ - public Object getValueIn(EObject object, EObject attribute) { - // At this point, this adapter does not dynamically compute any values, - // all values are pushed back into the target on the initial call. - return super.getValueIn(object, attribute); - } - /** - * reflectValues - template method, subclasses override to pump values into target. - * on entry: name, containing package (and qualified name), and document must be set. - * JavaClass adaptor: - * - set modifiers - * - set name - * - set type - */ - public boolean reflectValues() { - if (getSourceField() != null) { - setModifiers(); - setType(); - setInitializerIfPossible(); - 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); - } - /** - * setModifiers - set the attribute values related to modifiers here - */ - protected void setModifiers() { - Field javaFieldTarget = (Field) getTarget(); - // For JDK reflection, I don't think we can set the initializer - int modifiers = getSourceField().getModifiers(); - javaFieldTarget.setStatic(java.lang.reflect.Modifier.isStatic(modifiers)); - javaFieldTarget.setTransient(java.lang.reflect.Modifier.isTransient(modifiers)); - javaFieldTarget.setVolatile(java.lang.reflect.Modifier.isVolatile(modifiers)); - javaFieldTarget.setFinal(java.lang.reflect.Modifier.isFinal(modifiers)); - // Set visibility - if (java.lang.reflect.Modifier.isPublic(modifiers)) - javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PUBLIC_LITERAL); - else if (java.lang.reflect.Modifier.isPrivate(modifiers)) - javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PRIVATE_LITERAL); - else if (java.lang.reflect.Modifier.isProtected(modifiers)) - javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PROTECTED_LITERAL); - else - javaFieldTarget.setJavaVisibility(JavaVisibilityKind.PACKAGE_LITERAL); - } - /** - * setType - set our type here - */ - protected void setType() { - String typeName = getTypeName(getSourceField().getType()); - setFieldType(getTargetField(), typeName); - } -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaJDKAdapterFactory.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaJDKAdapterFactory.java deleted file mode 100644 index f494eb6dd..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaJDKAdapterFactory.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters.jdk; -/* - - - */ -import java.util.Iterator; - -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.jem.internal.java.adapters.JavaReflectionAdapterFactory; -import org.eclipse.jem.internal.java.adapters.ReflectionAdaptor; -/** - * Insert the type's description here. - * Creation date: (6/13/2000 1:20:31 PM) - * @author: Administrator - */ -public class JavaJDKAdapterFactory extends JavaReflectionAdapterFactory { - protected ClassLoader contextClassLoader; - /** - * JavaJDOMAdapterFactory constructor comment. - */ - public JavaJDKAdapterFactory() { - super(); - //adapterKey = TYPE_NAME; - } - /** - * JavaJDOMAdapterFactory constructor comment. - */ - public JavaJDKAdapterFactory(ClassLoader aClassLoader) { - this(); - setContextClassLoader(aClassLoader); - } - protected ReflectionAdaptor createJavaClassAdaptor(Notifier target) { - return new JavaClassJDKAdaptor(target, this); - } - protected ReflectionAdaptor createJavaFieldAdaptor(Notifier target) { - return new JavaFieldJDKAdaptor(target, this); - } - protected ReflectionAdaptor createJavaMethodAdaptor(Notifier target) { - return new JavaMethodJDKAdaptor(target, this); - } - // Flush ALL adapters, worst case - public void flushAll() { - isBusyIteratingReflected = true; - try { - Iterator i = reflected.values().iterator(); - while (i.hasNext()) - ((JavaClassJDKAdaptor) i.next()).flushReflectedValuesIfNecessary(); - } finally { - finishedIteratingReflected(); - } - } - // Flush the adapter for a source object - public void flushReflection(String source) { - JavaClassJDKAdaptor a = (JavaClassJDKAdaptor) reflected.get(source); - if (a != null) - a.flushReflectedValuesIfNecessary(); - } - /** - * Insert the method's description here. - * Creation date: (11/07/00 3:38:12 PM) - * @return java.lang.ClassLoader - */ - public java.lang.ClassLoader getContextClassLoader() { - return contextClassLoader; - } - /** - * Insert the method's description here. - * Creation date: (11/07/00 3:38:12 PM) - * @param newContextClassLoader java.lang.ClassLoader - */ - public void setContextClassLoader(java.lang.ClassLoader newContextClassLoader) { - contextClassLoader = newContextClassLoader; - } -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaMethodJDKAdaptor.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaMethodJDKAdaptor.java deleted file mode 100644 index 0e735cd4c..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/jdk/JavaMethodJDKAdaptor.java +++ /dev/null @@ -1,245 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters.jdk; -/* - - - */ - -import java.util.List; - -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.xmi.XMIResource; -import org.eclipse.jem.java.*; -import org.eclipse.jem.internal.java.adapters.IJavaMethodAdapter; -import org.eclipse.jem.internal.java.adapters.ReadAdaptor; -import org.eclipse.jem.java.internal.impl.MethodImpl; -/** - * Insert the type's description here. - * Creation date: (6/6/2000 4:42:50 PM) - * @author: Administrator - */ -public class JavaMethodJDKAdaptor extends JDKAdaptor implements IJavaMethodAdapter { - protected java.lang.reflect.AccessibleObject sourceAccessible = null; // Could be method or ctor. - protected Class parentType = null; - // cache a static empty Class[] for no parm methods - protected static Class[] emptyClassArray = new Class[0]; - // cache a static empty String[], too - protected static String[] emptyStringArray = new String[0]; - public JavaMethodJDKAdaptor(Notifier target, JavaJDKAdapterFactory anAdapterFactory) { - super(target, anAdapterFactory); - } - /** - * addExceptions - reflect our exception list - */ - protected void addExceptions() { - Class[] exceptions = - (getSourceAccessible() instanceof java.lang.reflect.Method) - ? ((java.lang.reflect.Method) getSourceAccessible()).getExceptionTypes() - : ((java.lang.reflect.Constructor) getSourceAccessible()).getExceptionTypes(); - // EList exList = (EList) javaMethodTarget.primRefValue(JavaRefPackage.eINSTANCE.getMethod_JavaExceptions()); - List exList = getMethodTarget().getJavaExceptionsGen(); - for (int i = 0; i < exceptions.length; i++) { - exList.add(createJavaClassRef(exceptions[i].getName())); - } - } - - protected MethodImpl getMethodTarget() { - return (MethodImpl) getTarget(); - } - /** - * addParameters - reflect our parms - */ - protected void addParameters() { - Class[] parmTypes = - (getSourceAccessible() instanceof java.lang.reflect.Method) - ? ((java.lang.reflect.Method) getSourceAccessible()).getParameterTypes() - : ((java.lang.reflect.Constructor) getSourceAccessible()).getParameterTypes(); - MethodImpl javaMethodTarget = getMethodTarget(); - // List pList = (List) javaMethodTarget.primRefValue(JavaRefPackage.eINSTANCE.getMethod_Parameters()); - List pList = javaMethodTarget.getParametersGen(); - for (int i = 0; i < parmTypes.length; i++) { - pList.add(createJavaParameter(javaMethodTarget, "arg" + i, getTypeName(parmTypes[i]))); //$NON-NLS-1$ - } - } - protected JavaClass getContainingJavaClass() { - return ((Method) getTarget()).getContainingJavaClass(); - } - /** - * getParentType - return the Class which corresponds to our parent JavaClass - * we're going to do this a lot, so cache it. - */ - protected Class getParentType() { - if (parentType == null) { - Method targetMethod = (Method) getTarget(); - JavaClass parentJavaClass = targetMethod.getContainingJavaClass(); - JavaClassJDKAdaptor pa = (JavaClassJDKAdaptor) EcoreUtil.getAdapter(parentJavaClass.eAdapters(), ReadAdaptor.TYPE_KEY); - if (pa != null) - parentType = pa.getSourceType(); - } - return parentType; - } - /** - * getParmTypeSignatures - return an array of Classes for our parameter types - * For reflection purposes, we can only rely on our ID, since our parms may - * not yet be known. - */ - protected Class[] getParmTypes() { - Method javaMethodTarget = (Method) getTarget(); - String id = ((XMIResource) javaMethodTarget.eResource()).getID(javaMethodTarget); - String[] typeNames = getTypeNamesFromMethodID(id); - if (typeNames == null) - return emptyClassArray; - int n = typeNames.length; - if (n == 0) - return emptyClassArray; - Class[] types = new Class[n]; - for (int i = 0; i < n; ++i) { - types[i] = getType(typeNames[i]); - } - return types; - } - public Object getReflectionSource() { - return getSourceAccessible(); - } - - /* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor#hasReflectionSource() - */ - public boolean hasCachedReflectionSource() { - return sourceAccessible != null; - } - /** - * getsourceMethod - return the java.lang.reflect.Method which describes our implementing method - */ - protected java.lang.reflect.AccessibleObject getSourceAccessible() { - if (sourceAccessible == null) { - Class parent = this.getParentType(); - if (parent != null) { - Class[] parmTypes = this.getParmTypes(); - try { - sourceAccessible = parent.getDeclaredMethod(((Method) getTarget()).getName(), parmTypes); - } catch (NoSuchMethodException e) { - // OK, can't reflect it - } - - if (sourceAccessible == null) { - // It wasn't a method, try for constructor. - try { - sourceAccessible = parent.getDeclaredConstructor(parmTypes); - } catch (NoSuchMethodException e) { - // OK, can't reflect it - } - } - } - } - return sourceAccessible; - } - /** - * getValueIn method comment. - */ - public Object getValueIn(EObject object, EObject attribute) { - // At this point, this adapter does not dynamically compute any values, - // all values are pushed back into the target on the initial call. - return super.getValueIn(object, attribute); - } - /** - * reflectValues - template method, subclasses override to pump values into target. - * on entry: UUID, name, containing package (and qualified name), and document must be set. - * Method adaptor: - * - set modifiers - * - set name - * - set return type - * - add parameters - * - add exceptions - */ - public boolean reflectValues() { - if (getSourceAccessible() != null) { - ((Method) getTarget()).setIsGenerated(false); - setModifiers(); - setNaming(); - setReturnType(); - addParameters(); - addExceptions(); - return true; - } - return false; - } - - - /* (non-Javadoc) - * @see org.eclipse.jem.internal.java.adapters.IJavaMethodAdapter#reflectGeneratedIfNecessary() - */ - public boolean reflectGeneratedIfNecessary() { - return reflectValuesIfNecessary(); - } - - public boolean reflectParamNamesIfNecessary() { - return reflectValuesIfNecessary(); - } - - /** - * setModifiers - set the attribute values related to modifiers here - */ - protected void setModifiers() { - Method methodTarget = (Method) getTarget(); - int modifiers = - (getSourceAccessible() instanceof java.lang.reflect.Method) - ? ((java.lang.reflect.Method) getSourceAccessible()).getModifiers() - : ((java.lang.reflect.Constructor) getSourceAccessible()).getModifiers(); - methodTarget.setAbstract(java.lang.reflect.Modifier.isAbstract(modifiers)); - methodTarget.setFinal(java.lang.reflect.Modifier.isFinal(modifiers)); - methodTarget.setNative(java.lang.reflect.Modifier.isNative(modifiers)); - methodTarget.setStatic(java.lang.reflect.Modifier.isStatic(modifiers)); - methodTarget.setSynchronized(java.lang.reflect.Modifier.isSynchronized(modifiers)); - methodTarget.setConstructor(getSourceAccessible() instanceof java.lang.reflect.Constructor); - // Set visibility - JavaClass javaClass = getContainingJavaClass(); - if ((javaClass.getKind() == TypeKind.INTERFACE_LITERAL) || (java.lang.reflect.Modifier.isPublic(modifiers))) - methodTarget.setJavaVisibility(JavaVisibilityKind.PUBLIC_LITERAL); - else if (java.lang.reflect.Modifier.isPrivate(modifiers)) - methodTarget.setJavaVisibility(JavaVisibilityKind.PRIVATE_LITERAL); - else if (java.lang.reflect.Modifier.isProtected(modifiers)) - methodTarget.setJavaVisibility(JavaVisibilityKind.PROTECTED_LITERAL); - else - //Visibility must be package - methodTarget.setJavaVisibility(JavaVisibilityKind.PACKAGE_LITERAL); - } - /** - * setNaming - set the naming values here - * - qualified name must be set first, that is the path to the real Java class - * - ID - * - name-based UUID - */ - protected void setNaming() { - // - // naming is currently a no-op since the name and UUID must be set prior to reflection - // ...and ID is redundant with UUID. - // javaFieldTarget.setID(parent.getQualifiedName() + "_" + javaFieldTarget.getName()); - } - /** - * setType - set our return type here - */ - protected void setReturnType() { - if (getSourceAccessible() instanceof java.lang.reflect.Method) { - Class type = ((java.lang.reflect.Method) getSourceAccessible()).getReturnType(); - Method javaMethodTarget = (Method) getTarget(); - /* - JavaParameter newParameter = createJavaParameter(javaMethodTarget, "result", getTypeName(type));//$NON-NLS-1$ - newParameter.setParameterKind(MetaJavaParameterKind.RETURN); - javaMethodTarget.getParameters().add(newParameter); - */ - javaMethodTarget.setEType(createJavaClassRef(getTypeName(type))); - } - } -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/nls/ResourceHandler.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/nls/ResourceHandler.java deleted file mode 100644 index eefe29efe..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/adapters/nls/ResourceHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.adapters.nls; -/* - - - */ -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import java.text.MessageFormat; - -public class ResourceHandler { - - private static ResourceBundle fgResourceBundle; - - /** - * Returns the resource bundle used by all classes in this Project - */ - public static ResourceBundle getResourceBundle() { - try { - return ResourceBundle.getBundle("javaadapters");//$NON-NLS-1$ - } catch (MissingResourceException e) { - // does nothing - this method will return null and - // getString(String, String) will return the key - // it was called with - } - return null; - } - public static String getString(String key) { - if (fgResourceBundle == null) { - fgResourceBundle= getResourceBundle(); - } - - if (fgResourceBundle != null) { - try { - return fgResourceBundle.getString(key); - } catch (MissingResourceException e) { - return "!" + key + "!";//$NON-NLS-2$//$NON-NLS-1$ - } - } else { - return "!" + key + "!";//$NON-NLS-2$//$NON-NLS-1$ - } - } -public static String getString(String key, Object[] args) { - - try {return MessageFormat.format(getString(key), args);} - catch (IllegalArgumentException e) {return getString(key);} - -} -} - - - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/beaninfo/IIntrospectionAdapter.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/beaninfo/IIntrospectionAdapter.java deleted file mode 100644 index d42f95ae5..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/beaninfo/IIntrospectionAdapter.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.beaninfo; -/* - - - */ -import org.eclipse.emf.common.util.BasicEList; -import org.eclipse.emf.common.util.EList; - - -/** - * The interface for the Beaninfo adapter. The actual implementation - * is in a separate project so that beaninfo code will not be loaded - * unless it needs to be. - */ - -public interface IIntrospectionAdapter extends org.eclipse.emf.common.notify.Adapter { - public static final Class ADAPTER_KEY = IIntrospectionAdapter.class; - public void introspectIfNecessary(); - public boolean isStale(); - public EList getEStructuralFeatures(); - public EList getEOperations(); - public BasicEList getEAllOperations(); - public EList getEvents(); - public EList getAllEvents(); - public EList getAllProperties(); -} - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/init/JavaInit.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/init/JavaInit.java deleted file mode 100644 index 8b6f1c837..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/init/JavaInit.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.init; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; -import org.eclipse.jem.java.JavaRefPackage; -import org.eclipse.jem.internal.java.adapters.JavaXMIFactoryImpl; - -/** - * Initialize the Java Reflection mechanisms. - */ -public class JavaInit { - protected static boolean initialized = false; - protected static boolean plugin_initialized = false; - - public static void init() { - init(true); - } - - public static void init(boolean shouldPreRegisterPackages) { - if (!initialized) { - initialized = true; - if (shouldPreRegisterPackages) { - preRegisterPackages(); - setDefaultResourceFactory(); - } - //Register resource factory - JavaXMIFactoryImpl.register(); - } - } - - private static void preRegisterPackages() { - //ecore - if (!EPackage.Registry.INSTANCE.containsKey("ecore.xmi")) //$NON-NLS-1$ - EPackage.Registry.INSTANCE.put("ecore.xmi", EcorePackage.eINSTANCE); //$NON-NLS-1$ - //java - if (!EPackage.Registry.INSTANCE.containsKey("java.xmi")) //$NON-NLS-1$ - EPackage.Registry.INSTANCE.put("java.xmi", JavaRefPackage.eINSTANCE); //$NON-NLS-1$ - } - protected static void setDefaultResourceFactory() { - //This is not done outside of Eclipse - if (Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().get(Resource.Factory.Registry.DEFAULT_EXTENSION) == null) - Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( - Resource.Factory.Registry.DEFAULT_EXTENSION, - new XMIResourceFactoryImpl()); - } - - public static void setPluginInit(boolean bPluginInit) { - // Here's where the configuration file would be read. - plugin_initialized = bPluginInit; - } - -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/instantiation/IInstantiationHandler.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/instantiation/IInstantiationHandler.java deleted file mode 100644 index 0548958c5..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/instantiation/IInstantiationHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.instantiation; -/* - - - */ -import org.eclipse.emf.ecore.*; - -import org.eclipse.jem.java.JavaDataType; - -/** - * The interface for the Instantiation handler. The actual implementation - * is in a separate project so that instantiation code will not be loaded - * unless it needs to be. - */ - -public interface IInstantiationHandler { - /** - * Answers whether the adapter handles the datatype - * or whether the standard EFactory does. - */ - public boolean handlesDataType(JavaDataType type); - - /** - * Answers whether the adapter handles the EClass or the - * standard EFactory does. - */ - public boolean handlesClass(EClass type); - - /** - * If adapterHandlesInstance returns true, then - * this method will be called to create the instance. - */ - public EObject create(EClass javaClass); - -} - - diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/instantiation/IInstantiationHandlerFactoryAdapter.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/instantiation/IInstantiationHandlerFactoryAdapter.java deleted file mode 100644 index de4e5d3bd..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/instantiation/IInstantiationHandlerFactoryAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.instantiation; -/* - - - */ -import org.eclipse.emf.common.notify.Adapter; - -import org.eclipse.jem.java.internal.impl.JavaFactoryImpl; - -/** - * This adapter is a factory for IInstantiationHandler's. It is attached as - * an adapter on the ResourceSet that contains the java model. JavaXMIFactory - * will use it to retrieve its IInstantiationHandler. If the adapter is not - * found, then no instantiation handler exists. - */ -public interface IInstantiationHandlerFactoryAdapter extends Adapter { - - public final static Class ADAPTER_KEY = IInstantiationHandlerFactoryAdapter.class; - - /** - * Return an IInstantiationHandler. - */ - public IInstantiationHandler getInstantiationHandler(JavaFactoryImpl factory); - -} diff --git a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/instantiation/IInstantiationInstance.java b/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/instantiation/IInstantiationInstance.java deleted file mode 100644 index dde9562e8..000000000 --- a/plugins/org.eclipse.jem/mofjava/org/eclipse/jem/internal/java/instantiation/IInstantiationInstance.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.java.instantiation; -/* - - - */ -import org.eclipse.jem.java.JavaHelpers; - -/** - * The interface for an instance. The actual implementation - * is in a separate project so that instantiation code will not be loaded - * unless it needs to be. - */ -public interface IInstantiationInstance { - /** - * @return The JavaHelpers for the java type of the instance. - */ - public JavaHelpers getJavaType(); - -} |