|
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-2001 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.lib.jmi.xmi;
import java.util.*;
import org.netbeans.lib.jmi.util.*;
import javax.jmi.reflect.*;
import javax.jmi.model.*;
public class ElementsCache extends Object {
// variables ................................................................
// cache storing structures' fields
private HashMap structureFields_cache = new HashMap ();
// caches storing instance-scoped and class-scoped attributes and references
private HashMap instanceAttributes_cache = new HashMap ();
private HashMap classAttributes_cache = new HashMap ();
private HashMap references_cache = new HashMap ();
private HashMap subtypes_cache = null;
private RefPackage extent;
// storage of all outermost packages
private HashMap outermostPackages = null;
// global cache used by @link #findOutermostPackages method
private HashMap trackedPackages = null;
// cache for resolved proxies enabling Enum and Struct creation and Association proxies
private HashMap proxies_cache = new HashMap ();
// init .....................................................................
public ElementsCache (RefPackage extent) {
this.extent = extent;
}
// methods ..................................................................
/**
* Detects all outermost packages related to the input extents and stores them.
* Stores all related namespaces as well.
*/
private void findOutermostPackages (RefPackage pkg) {
if (trackedPackages.get (pkg) != null)
return;
String name;
MofPackage metaObj = (MofPackage) pkg.refMetaObject ();
if (metaObj.getContainer() == null) {
Iterator iter = metaObj.getQualifiedName ().iterator ();
String fqName = (String) iter.next ();
while (iter.hasNext ())
fqName = fqName.concat (".").concat ((String) iter.next ());
outermostPackages.put (fqName, pkg);
}
trackedPackages.put (pkg, pkg);
Iterator iter = pkg.refAllPackages ().iterator ();
while (iter.hasNext ()) {
findOutermostPackages ((RefPackage) iter.next ());
}
}
/**
* Finds all attributes and references belonging to a mof class and caches them.
*/
private void cacheContainedElements (MofClass mofClass) {
List temp = new LinkedList ();
List superClasses = mofClass.allSupertypes ();
Namespace namespace = null;
Iterator it = superClasses.iterator ();
while (it.hasNext ()) {
namespace = (Namespace) it.next ();
temp.addAll (namespace.getContents ());
}
temp.addAll (mofClass.getContents ());
List instanceAttributes = new LinkedList ();
List classAttributes = new LinkedList ();
List references = new LinkedList ();
it = temp.iterator ();
while (it.hasNext ()) {
RefObject refObject = (RefObject) it.next ();
if (refObject instanceof Feature) {
boolean instanceLevel = ((Feature) refObject).getScope ().equals (ScopeKindEnum.INSTANCE_LEVEL);
if ((refObject instanceof Attribute) && (!((Attribute) refObject).isDerived ())) {
if (instanceLevel) {
instanceAttributes.add (refObject);
} else {
classAttributes.add (refObject);
}
} else if (refObject instanceof Reference) {
Association assoc = (Association) ((Reference) refObject).
getReferencedEnd ().getContainer ();
if (!assoc.isDerived ())
references.add (refObject);
} // else
} // if (refObject instanceof Feature)
} // while
instanceAttributes_cache.put (mofClass, instanceAttributes);
classAttributes_cache.put (mofClass, classAttributes);
references_cache.put (mofClass, references);
}
/**
* For a given mof class, returns list of all instance-scoped attributes
* (references are not included).
*
* @param mofClass
* @return list of all non-derived instance-scoped attributes (including inherited ones)
*/
public List instanceAttributes (MofClass mofClass) {
List list = (List) instanceAttributes_cache.get (mofClass);
if (list == null) {
cacheContainedElements (mofClass);
list = (List) instanceAttributes_cache.get (mofClass);
}
return list;
}
/**
* Returns attributes defined in the class (inhretited attributes are not included).
*/
public List localInstanceAttributes (MofClass mofClass) {
Iterator it = mofClass.getContents ().iterator ();
List result = new LinkedList ();
while (it.hasNext ()) {
Object refObject = it.next ();
if (refObject instanceof Feature) {
boolean instanceLevel = ((Feature) refObject).getScope ().equals (ScopeKindEnum.INSTANCE_LEVEL);
if (instanceLevel && (refObject instanceof Attribute) && (!((Attribute) refObject).isDerived ())) {
result.add (refObject);
} // if
} // if
} // while
return result;
}
/**
* For a given mof class, returns list of all class-scoped attributes.
*
* @param mofClass
* @return list of all non-derived class-scoped attributes (including inherited ones)
*/
public List classAttributes (MofClass mofClass) {
List list = (List) classAttributes_cache.get (mofClass);
if (list == null) {
cacheContainedElements (mofClass);
list = (List) classAttributes_cache.get (mofClass);
}
return list;
}
/**
* For a given mof class, returns list of all references.
*
* @param mofClass
* @return list of all non-derived references (including inherited ones)
*/
public List references (MofClass mofClass) {
List list = (List) references_cache.get (mofClass);
if (list == null) {
cacheContainedElements (mofClass);
list = (List) references_cache.get (mofClass);
}
return list;
}
/**
* Returns references defined in the class (inhretited references are not included).
*/
public List localReferences (MofClass mofClass) {
Iterator it = mofClass.getContents ().iterator ();
List result = new LinkedList ();
while (it.hasNext ()) {
Object refObject = it.next ();
if (refObject instanceof Feature) {
boolean instanceLevel = ((Feature) refObject).getScope ().equals (ScopeKindEnum.INSTANCE_LEVEL);
if (instanceLevel && (refObject instanceof Reference)) {
Association assoc = (Association) ((Reference) refObject).
getReferencedEnd ().getContainer ();
if (!assoc.isDerived ())
result.add (refObject);
} // if
} // if
} // while
return result;
}
/**
* Returns list of all fields belonging to the given StructureType.
*/
public List structureFields (StructureType type) {
List fields = (List) structureFields_cache.get (type);
if (fields != null)
return fields;
// find fields and cache them
fields = new LinkedList ();
Iterator content = type.getContents ().iterator ();
while (content.hasNext ()) {
Object element = content.next ();
if (element instanceof StructureField)
fields.add (element);
} // while
structureFields_cache.put (type, fields);
return fields;
}
/**
* Finds proxy object related to the container of a given meta model element.
*
* @param element meta model element
* @return related proxy object or
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.