|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.javacore.jmiimpl.javamodel; import java.util.*; import javax.jmi.reflect.ConstraintViolationException; import javax.jmi.reflect.RefObject; import org.netbeans.jmi.javamodel.*; import org.netbeans.mdr.handlers.ClassProxyHandler; import org.netbeans.mdr.persistence.MOFID; import org.netbeans.mdr.persistence.StorageException; import org.netbeans.mdr.storagemodel.StorableBaseObject; import org.netbeans.mdr.storagemodel.StorableClass; import org.netbeans.mdr.util.DebugException; /** * * @author Dusan Balek */ public abstract class ParameterizedTypeClassImpl extends ClassProxyHandler implements ParameterizedTypeClass { private static final String MOFID_PREFIX = "parameterizedType:"; // NOI18N private static final InstanceMap allInstances = new InstanceMap(); private static int increment = 0; public ParameterizedTypeClassImpl(StorableClass s) { super(s); } public ParameterizedType createParameterizedType() { throw new ConstraintViolationException(this, refMetaObject(), "Cannot create instance of ParameterizedType directly - use resolveParameterizedType instead."); // NOI18N } public ParameterizedType createParameterizedType(String name, List annotations, int modifiers, String javadocText, JavaDoc javadoc, List contents, MultipartId superClassName, List interfaceNames, List typeParameters) { throw new ConstraintViolationException(this, refMetaObject(), "Cannot create instance of ParameterizedType directly - use resolveParameterizedType instead."); // NOI18N } public ParameterizedType resolveParameterizedType(JavaClass def, List params, ParameterizedType outerCls) { if (def == null) return null; if (def instanceof ParameterizedTypeImpl) { outerCls = ((ParameterizedTypeImpl) def).outerCls; def = ((ParameterizedTypeImpl) def).definition; } if (params == null) { params = Collections.EMPTY_LIST; } String fullName = constructKey(def, params, outerCls); ParameterizedTypeImpl result = (ParameterizedTypeImpl) allInstances.get(fullName); if (result == null) { try { StorableBaseObject s = _getDelegate(); MOFID mofId = new MOFID(increment, MOFID_PREFIX + increment++); DeferredObject o = new DeferredObject(mofId, s.getMdrStorage(), s.getImmediatePackageId(), s.getOutermostPackageId(), s.getMetaObject(), (StorableClass) s, null); result = (ParameterizedTypeImpl) _getRepository().getHandler(o); result.definition = def; result.parameters = params; result.outerCls = outerCls; allInstances.put(fullName, result); } catch (StorageException e) { throw new DebugException(); } } return result; } private String constructKey(JavaClass def, List params, ParameterizedType outerCls) { StringBuffer key = new StringBuffer(); key.append(def.refMofId()); for (Iterator it = params.iterator(); it.hasNext();) { RefObject param = (RefObject) it.next(); key.append('|'); key.append(param == null ? "null" : param.refMofId()); // NOI18N } key.append('|'); key.append(outerCls == null ? "null" : outerCls.refMofId()); // NOI18N return key.toString(); } protected Collection _allOfClass(boolean recursive) { return allInstances.values(); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.