1.1 --- a/mdr/build.xml Thu Sep 26 14:52:36 2002 +0000
1.2 +++ b/mdr/build.xml Sat Sep 28 19:48:11 2002 +0000
1.3 @@ -174,11 +174,11 @@
1.4 <locale name="ja"/>
1.5 <fileset dir="${build.mdr.classes.dir}" excludesfile="${standard-jar-excludes.txt}">
1.6 <include name="org/netbeans/mdr/"/>
1.7 - <include name="javax/"/>
1.8 + <include name="org/netbeans/jmiimpl/"/>
1.9 </fileset>
1.10 <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
1.11 <include name="org/netbeans/mdr/"/>
1.12 - <include name="javax/"/>
1.13 + <include name="org/netbeans/jmiimpl/"/>
1.14 </fileset>
1.15 <fileset dir="nbmdr-meta-inf" includes="**" />
1.16 </locjar>
1.17 @@ -245,6 +245,7 @@
1.18 <fileset dir="src" excludesfile="${standard-jar-excludes.txt}">
1.19 <include name="org/netbeans/modules/jmitoolkit/"/>
1.20 </fileset>
1.21 + <fileset dir="jmitoolkit-meta-inf" includes="**"/>
1.22 </locjar>
1.23 </target>
1.24
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/mdr/src/org/netbeans/jmiimpl/mof/model/AssociationEndImpl.java Sat Sep 28 19:48:11 2002 +0000
2.3 @@ -0,0 +1,50 @@
2.4 +/*
2.5 + * Sun Public License Notice
2.6 + *
2.7 + * The contents of this file are subject to the Sun Public License
2.8 + * Version 1.0 (the "License"). You may not use this file except in
2.9 + * compliance with the License. A copy of the License is available at
2.10 + * http://www.sun.com/
2.11 + *
2.12 + * The Original Code is NetBeans. The Initial Developer of the Original
2.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
2.14 + * Microsystems, Inc. All Rights Reserved.
2.15 + */
2.16 +package org.netbeans.jmiimpl.mof.model;
2.17 +
2.18 +import java.util.*;
2.19 +import javax.jmi.model.*;
2.20 +import javax.jmi.reflect.*;
2.21 +
2.22 +import org.netbeans.mdr.handlers.InstanceHandler;
2.23 +import org.netbeans.mdr.storagemodel.StorableObject;
2.24 +import org.netbeans.mdr.util.*;
2.25 +
2.26 +
2.27 +/**
2.28 + * Implements MOF operations
2.29 + *
2.30 + * @author mmatula
2.31 + */
2.32 +public abstract class AssociationEndImpl extends ModelElementImpl implements AssociationEnd {
2.33 + protected AssociationEndImpl(StorableObject storable) {
2.34 + super(storable);
2.35 + }
2.36 +
2.37 + public AssociationEnd otherEnd() {
2.38 + Collection elements = this.getContainer().getContents();
2.39 + Object element;
2.40 +
2.41 + for (Iterator it = elements.iterator(); it.hasNext();) {
2.42 + element = it.next();
2.43 + if (element instanceof AssociationEnd && !element.equals(this)) {
2.44 + return (AssociationEnd) element;
2.45 + }
2.46 + }
2.47 +
2.48 + return null;
2.49 + }
2.50 +
2.51 + // --- derived attributes
2.52 +
2.53 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/mdr/src/org/netbeans/jmiimpl/mof/model/DependsOnImpl.java Sat Sep 28 19:48:11 2002 +0000
3.3 @@ -0,0 +1,102 @@
3.4 +/*
3.5 + * Sun Public License Notice
3.6 + *
3.7 + * The contents of this file are subject to the Sun Public License
3.8 + * Version 1.0 (the "License"). You may not use this file except in
3.9 + * compliance with the License. A copy of the License is available at
3.10 + * http://www.sun.com/
3.11 + *
3.12 + * The Original Code is NetBeans. The Initial Developer of the Original
3.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
3.14 + * Microsystems, Inc. All Rights Reserved.
3.15 + */
3.16 +package org.netbeans.jmiimpl.mof.model;
3.17 +
3.18 +import java.util.*;
3.19 +
3.20 +import javax.jmi.model.*;
3.21 +import javax.jmi.reflect.*;
3.22 +
3.23 +import org.netbeans.mdr.handlers.BaseObjectHandler;
3.24 +import org.netbeans.mdr.handlers.AssociationHandler;
3.25 +import org.netbeans.mdr.handlers.IndexSetWrapper;
3.26 +import org.netbeans.mdr.storagemodel.AssociationLink;
3.27 +import org.netbeans.mdr.storagemodel.StorableAssociation;
3.28 +import org.netbeans.mdr.storagemodel.StorableObject;
3.29 +
3.30 +/** Implementation of DependsOn association which is derived in the MOF model.
3.31 + *
3.32 + * @author Martin Matula
3.33 + * @version
3.34 + */
3.35 +public abstract class DependsOnImpl extends AssociationHandler implements DependsOn {
3.36 +
3.37 + /** Creates new DependsOnImpl */
3.38 + protected DependsOnImpl(StorableAssociation storable) {
3.39 + super(storable);
3.40 + }
3.41 +
3.42 + // [PENDING] should be probably live
3.43 + public Collection refAllLinks() {
3.44 + ArrayList link;
3.45 + HashSet allLinks = new HashSet();
3.46 + ModelElement dependent;
3.47 +
3.48 + for (Iterator it = ((ModelPackage) refImmediatePackage()).getModelElement().refAllOfType().iterator(); it.hasNext();) {
3.49 + dependent = (ModelElement) it.next();
3.50 + for (Iterator it2 = dependent.findRequiredElements(ModelElementImpl.ALL_KINDS, true).iterator(); it2.hasNext();) {
3.51 + allLinks.add(new AssociationLink((StorableObject) ((BaseObjectHandler) dependent)._getDelegate(), (StorableObject) ((BaseObjectHandler) it2.next())._getDelegate()));
3.52 + }
3.53 + }
3.54 +
3.55 + return new IndexSetWrapper(_getMdrStorage(), allLinks);
3.56 + }
3.57 +
3.58 + public boolean exists(ModelElement dependent, ModelElement provider) {
3.59 + return dependent.isRequiredBecause(provider, new String[1]);
3.60 + }
3.61 +
3.62 + public Collection getProvider(ModelElement dependent) {
3.63 + return dependent.findRequiredElements(ModelElementImpl.ALL_KINDS, true);
3.64 + }
3.65 +
3.66 + public Collection getDependent(ModelElement provider) {
3.67 + Set result = new HashSet();
3.68 + findDependentElements(provider, result);
3.69 + return result;
3.70 + }
3.71 +
3.72 + private void findDependentElements(ModelElement provider, Set result) {
3.73 + Set temp = new HashSet();
3.74 + ModelPackage pkg = (ModelPackage) refImmediatePackage();
3.75 +
3.76 + if (provider instanceof Constraint) {
3.77 + temp.addAll(((Constraint) provider).getConstrainedElements());
3.78 + } else if (provider instanceof Namespace) {
3.79 + temp.addAll(((Namespace) provider).getContents());
3.80 + temp.addAll(pkg.getAliases().getImporter((Namespace) provider));
3.81 + if (provider instanceof GeneralizableElement) {
3.82 + temp.addAll(pkg.getGeneralizes().getSubtype((GeneralizableElement) provider));
3.83 + if (provider instanceof Classifier) {
3.84 + temp.addAll(pkg.getIsOfType().getTypedElements((Classifier) provider));
3.85 + }
3.86 + } else if (provider instanceof MofException) {
3.87 + temp.addAll(pkg.getCanRaise().getOperation((MofException) provider));
3.88 + }
3.89 + } else if (provider instanceof AssociationEnd) {
3.90 + temp.addAll(pkg.getRefersTo().getReferent((AssociationEnd) provider));
3.91 + temp.addAll(pkg.getExposes().getReferrer((AssociationEnd) provider));
3.92 + }
3.93 +
3.94 + temp.addAll(provider.getConstraints());
3.95 + temp.add(provider.getContainer());
3.96 + temp.addAll(pkg.getAttachesTo().getTag(provider));
3.97 +
3.98 + for (Iterator it = temp.iterator(); it.hasNext();) {
3.99 + ModelElement me = (ModelElement) it.next();
3.100 + if (result.add(me)) {
3.101 + findDependentElements(me, result);
3.102 + }
3.103 + }
3.104 + }
3.105 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/mdr/src/org/netbeans/jmiimpl/mof/model/ExposesImpl.java Sat Sep 28 19:48:11 2002 +0000
4.3 @@ -0,0 +1,80 @@
4.4 +/*
4.5 + * Sun Public License Notice
4.6 + *
4.7 + * The contents of this file are subject to the Sun Public License
4.8 + * Version 1.0 (the "License"). You may not use this file except in
4.9 + * compliance with the License. A copy of the License is available at
4.10 + * http://www.sun.com/
4.11 + *
4.12 + * The Original Code is NetBeans. The Initial Developer of the Original
4.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
4.14 + * Microsystems, Inc. All Rights Reserved.
4.15 + */
4.16 +package org.netbeans.jmiimpl.mof.model;
4.17 +
4.18 +import java.util.*;
4.19 +
4.20 +import javax.jmi.model.AssociationEnd;
4.21 +import javax.jmi.model.Reference;
4.22 +import javax.jmi.model.RefersTo;
4.23 +import javax.jmi.model.NameNotFoundException;
4.24 +import javax.jmi.model.Exposes;
4.25 +import javax.jmi.model.ModelPackage;
4.26 +import javax.jmi.model.ReferenceClass;
4.27 +import javax.jmi.reflect.*;
4.28 +
4.29 +import org.netbeans.mdr.handlers.*;
4.30 +import org.netbeans.mdr.storagemodel.*;
4.31 +
4.32 +/** Implementation of Exposes association, which is derived in the MOF model.
4.33 + *
4.34 + * @author Martin Matula
4.35 + * @version
4.36 + */
4.37 +public abstract class ExposesImpl extends AssociationHandler implements Exposes {
4.38 +
4.39 + /** Creates new ExposesImpl */
4.40 + protected ExposesImpl(StorableAssociation storable) {
4.41 + super(storable);
4.42 + }
4.43 +
4.44 + public Collection refAllLinks() {
4.45 + // [PENDING] live collection should be returned
4.46 + ModelPackage pkg = (ModelPackage) refImmediatePackage();
4.47 + RefersTo assoc = pkg.getRefersTo();
4.48 + Collection allLinks = assoc.refAllLinks();
4.49 + ArrayList result = new ArrayList(allLinks.size());
4.50 + RefAssociationLink link;
4.51 +
4.52 + for (Iterator it = allLinks.iterator(); it.hasNext();) {
4.53 + link = (RefAssociationLink) it.next();
4.54 + result.add(new AssociationLink((StorableObject) ((BaseObjectHandler) link.refFirstEnd())._getDelegate(), (StorableObject) ((BaseObjectHandler) link.refSecondEnd())._getDelegate()));
4.55 + }
4.56 +
4.57 + return new IndexSetWrapper(_getMdrStorage(), result);
4.58 + }
4.59 +
4.60 + public boolean exists(Reference referrer, AssociationEnd exposedEnd) {
4.61 + return exposedEnd.equals(referrer.getReferencedEnd().otherEnd());
4.62 + }
4.63 +
4.64 + public AssociationEnd getExposedEnd(Reference referrer) {
4.65 + return referrer.getReferencedEnd().otherEnd();
4.66 + }
4.67 +
4.68 + public Collection getReferrer(AssociationEnd exposedEnd) {
4.69 + return ((ModelPackage) refImmediatePackage()).getRefersTo().getReferent(exposedEnd.otherEnd());
4.70 + }
4.71 +
4.72 + public boolean add(Reference referrer, AssociationEnd exposedEnd) {
4.73 + ModelPackage pkg = (ModelPackage) refImmediatePackage();
4.74 + RefersTo assoc = (RefersTo) pkg.getRefersTo();
4.75 + return assoc.add(referrer, exposedEnd.otherEnd());
4.76 + }
4.77 +
4.78 + public boolean remove(Reference referrer, AssociationEnd exposedEnd) {
4.79 + ModelPackage pkg = (ModelPackage) refImmediatePackage();
4.80 + RefersTo assoc = (RefersTo) pkg.getRefersTo();
4.81 + return assoc.remove(referrer, exposedEnd.otherEnd());
4.82 + }
4.83 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/mdr/src/org/netbeans/jmiimpl/mof/model/GeneralizableElementImpl.java Sat Sep 28 19:48:11 2002 +0000
5.3 @@ -0,0 +1,133 @@
5.4 +/*
5.5 + * Sun Public License Notice
5.6 + *
5.7 + * The contents of this file are subject to the Sun Public License
5.8 + * Version 1.0 (the "License"). You may not use this file except in
5.9 + * compliance with the License. A copy of the License is available at
5.10 + * http://www.sun.com/
5.11 + *
5.12 + * The Original Code is NetBeans. The Initial Developer of the Original
5.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
5.14 + * Microsystems, Inc. All Rights Reserved.
5.15 + */
5.16 +package org.netbeans.jmiimpl.mof.model;
5.17 +
5.18 +import java.util.*;
5.19 +import javax.jmi.model.*;
5.20 +import javax.jmi.reflect.*;
5.21 +
5.22 +import org.netbeans.mdr.util.*;
5.23 +import org.netbeans.mdr.storagemodel.*;
5.24 +import org.netbeans.mdr.handlers.*;
5.25 +import org.netbeans.mdr.persistence.StorageException;
5.26 +
5.27 +/**
5.28 + * Implements MOF operations of GeneralizableElement class of MOF model.
5.29 + *
5.30 + * @author Martin Matula
5.31 + */
5.32 +public abstract class GeneralizableElementImpl extends NamespaceImpl implements GeneralizableElement {
5.33 +
5.34 + protected GeneralizableElementImpl(StorableObject storable) {
5.35 + super(storable);
5.36 + }
5.37 +
5.38 + private Collection/*<StorableFeatured>*/ extendedNamespace() {
5.39 + try {
5.40 + StorableFeatured storable = (StorableFeatured) _getDelegate();
5.41 + StorableAssociation assoc = resolveContains(storable);
5.42 + Collection result = new ArrayList((Collection) assoc.queryObjects(assoc.getEnd1Name(), storable.getMofId()));
5.43 +
5.44 + if (this instanceof GeneralizableElement) {
5.45 + Collection supertypes = ((GeneralizableElement) this).allSupertypes();
5.46 +
5.47 + for (Iterator it = supertypes.iterator(); it.hasNext();) {
5.48 + storable = (StorableFeatured) ((BaseObjectHandler) it.next())._getDelegate();
5.49 + result.addAll((Collection) assoc.queryObjects(assoc.getEnd1Name(), storable.getMofId()));
5.50 + }
5.51 + }
5.52 +
5.53 + if (this instanceof MofPackage) {
5.54 + ArrayList imports = new ArrayList();
5.55 + Object temp;
5.56 +
5.57 + for (Iterator it = result.iterator(); it.hasNext();) {
5.58 + temp = it.next();
5.59 + if (temp instanceof Import) {
5.60 + imports.add(((BaseObjectHandler) ((Import) temp).getImportedNamespace())._getDelegate());
5.61 + }
5.62 + }
5.63 +
5.64 + result.addAll(imports);
5.65 + }
5.66 +
5.67 + return result;
5.68 + } catch (StorageException e) {
5.69 + throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
5.70 + }
5.71 + }
5.72 +
5.73 + private void allSupertypes2(List result, Set visited) {
5.74 + List tempElements = getSupertypes();
5.75 + GeneralizableElementImpl element;
5.76 +
5.77 + for (Iterator it = tempElements.iterator(); it.hasNext();) {
5.78 + element = (GeneralizableElementImpl) it.next();
5.79 + if (visited.add(element)) {
5.80 + element.allSupertypes2(result, visited);
5.81 + result.add(element);
5.82 + }
5.83 + }
5.84 + }
5.85 +
5.86 + // --- operations
5.87 +
5.88 + public List allSupertypes() {
5.89 + List result = new ArrayList();
5.90 + allSupertypes2(result, new HashSet());
5.91 + return result;
5.92 + }
5.93 +
5.94 + public ModelElement lookupElementExtended(String name) throws NameNotFoundException {
5.95 + Collection contents = extendedNamespace();
5.96 +// StorableBaseObject storable = _getDelegate();
5.97 +// Collection items = storable.getMdrStorage().objectsFromAdditionalIndex(storable.getOutermostPackageId(), "ModelElement.name", name);
5.98 +//
5.99 +// if (items != null) {
5.100 +// Object result;
5.101 +// for (Iterator it = items.iterator(); it.hasNext();) {
5.102 +// result = it.next();
5.103 +// if (contents.contains(result)) {
5.104 +// return (ModelElement) BaseObjectHandler.getHandler((StorableBaseObject) result);
5.105 +// }
5.106 +// }
5.107 +// } else {
5.108 + for (Iterator it = contents.iterator(); it.hasNext();) {
5.109 + ModelElement el = (ModelElement) BaseObjectHandler.getHandler((StorableBaseObject) it.next());
5.110 + if (el.getName().equals(name)) {
5.111 + return el;
5.112 + }
5.113 + }
5.114 +// }
5.115 +
5.116 + throw new NameNotFoundException(name);
5.117 + }
5.118 +
5.119 + public List findElementsByTypeExtended(javax.jmi.model.MofClass ofType, boolean includeSubtypes) {
5.120 + ArrayList result = new ArrayList();
5.121 + RefObject element;
5.122 + Collection contents = extendedNamespace();
5.123 +
5.124 + for (Iterator it = contents.iterator(); it.hasNext();) {
5.125 + element = (RefObject) BaseObjectHandler.getHandler((StorableObject) it.next());
5.126 + if (element.refIsInstanceOf(ofType, includeSubtypes)) {
5.127 + result.add(element);
5.128 + }
5.129 + }
5.130 +
5.131 + return result;
5.132 + }
5.133 +
5.134 + // --- derived attributes
5.135 +
5.136 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/mdr/src/org/netbeans/jmiimpl/mof/model/ModelElementImpl.java Sat Sep 28 19:48:11 2002 +0000
6.3 @@ -0,0 +1,170 @@
6.4 +/*
6.5 + * Sun Public License Notice
6.6 + *
6.7 + * The contents of this file are subject to the Sun Public License
6.8 + * Version 1.0 (the "License"). You may not use this file except in
6.9 + * compliance with the License. A copy of the License is available at
6.10 + * http://www.sun.com/
6.11 + *
6.12 + * The Original Code is NetBeans. The Initial Developer of the Original
6.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
6.14 + * Microsystems, Inc. All Rights Reserved.
6.15 + */
6.16 +package org.netbeans.jmiimpl.mof.model;
6.17 +
6.18 +import java.util.*;
6.19 +import javax.jmi.model.*;
6.20 +import javax.jmi.reflect.*;
6.21 +
6.22 +import org.netbeans.mdr.util.*;
6.23 +import org.netbeans.mdr.handlers.*;
6.24 +import org.netbeans.mdr.storagemodel.*;
6.25 +
6.26 +/**
6.27 + * Implements MOF operations for ModelElement class
6.28 + *
6.29 + * @author Martin Matula
6.30 + */
6.31 +public abstract class ModelElementImpl extends InstanceHandler implements ModelElement {
6.32 + // correct constant names
6.33 + public static final java.lang.String CONTAINER_DEP = "container";
6.34 + public static final java.lang.String CONTENTS_DEP = "contents";
6.35 + public static final java.lang.String SIGNATURE_DEP = "signature";
6.36 + public static final java.lang.String CONSTRAINT_DEP = "constraint";
6.37 + public static final java.lang.String CONSTRAINED_ELEMENTS_DEP = "constrained elements";
6.38 + public static final java.lang.String SPECIALIZATION_DEP = "specialization";
6.39 + public static final java.lang.String IMPORT_DEP = "import";
6.40 + public static final java.lang.String TYPE_DEFINITION_DEP = "type definition";
6.41 + public static final java.lang.String REFERENCED_ENDS_DEP = "referenced ends";
6.42 + public static final java.lang.String TAGGED_ELEMENTS_DEP = "tagged elements";
6.43 + public static final java.lang.String INDIRECT_DEP = "indirect";
6.44 + public static final java.lang.String ALL_DEP = "all";
6.45 +
6.46 + static final HashSet ALL_KINDS = new HashSet();
6.47 +
6.48 + static {
6.49 + ALL_KINDS.add(CONTAINER_DEP);
6.50 + ALL_KINDS.add(CONTENTS_DEP);
6.51 + ALL_KINDS.add(SIGNATURE_DEP);
6.52 + ALL_KINDS.add(CONSTRAINT_DEP);
6.53 + ALL_KINDS.add(CONSTRAINED_ELEMENTS_DEP);
6.54 + ALL_KINDS.add(SPECIALIZATION_DEP);
6.55 + ALL_KINDS.add(IMPORT_DEP);
6.56 + ALL_KINDS.add(TYPE_DEFINITION_DEP);
6.57 + ALL_KINDS.add(REFERENCED_ENDS_DEP);
6.58 + ALL_KINDS.add(TAGGED_ELEMENTS_DEP);
6.59 + }
6.60 +
6.61 + protected ModelElementImpl(StorableObject storable) {
6.62 + super(storable);
6.63 + }
6.64 +
6.65 + private void recursiveFindDeps(Set kinds, Set result) {
6.66 + Set temp = new HashSet();
6.67 + for (Iterator m = kinds.iterator(); m.hasNext();) {
6.68 + findDepsOfKind((String) m.next(), temp);
6.69 + }
6.70 + for (Iterator it = temp.iterator(); it.hasNext();) {
6.71 + ModelElementImpl me = (ModelElementImpl) it.next();
6.72 + if (result.add(me)) {
6.73 + me.recursiveFindDeps(kinds, result);
6.74 + }
6.75 + }
6.76 + }
6.77 +
6.78 + private void findDepsOfKind(String kind, Set result) {
6.79 + if (kind.equals(CONSTRAINT_DEP)) { // constraint
6.80 + result.addAll(this.getConstraints());
6.81 + } else if (kind.equals(CONTAINER_DEP)) { //container
6.82 + result.add(this.getContainer());
6.83 + } else if (kind.equals(CONSTRAINED_ELEMENTS_DEP) && (this instanceof Constraint)) { //constrained elements
6.84 + result.addAll(((Constraint) this).getConstrainedElements());
6.85 + } else if (kind.equals(SPECIALIZATION_DEP) && (this instanceof GeneralizableElement)) { //specialization
6.86 + result.addAll(((GeneralizableElement) this).getSupertypes());
6.87 + } else if (kind.equals(IMPORT_DEP) && (this instanceof Import)) { //import
6.88 + result.add(((Import) this).getImportedNamespace());
6.89 + } else if (kind.equals(CONTENTS_DEP) && (this instanceof Namespace)) { //contents
6.90 + result.addAll(((Namespace) this).getContents());
6.91 + } else if (kind.equals(SIGNATURE_DEP) && (this instanceof Operation)) { //signature
6.92 + result.addAll(((Operation) this).getExceptions());
6.93 + } else if (kind.equals(TAGGED_ELEMENTS_DEP) && (this instanceof Tag)) { //tagged elements
6.94 + result.addAll(((Tag) this).getElements());
6.95 + } else if (kind.equals(TYPE_DEFINITION_DEP) && (this instanceof TypedElement)) { //type definition
6.96 + result.add(((TypedElement) this).getType());
6.97 + } else if (kind.equals(REFERENCED_ENDS_DEP) && (this instanceof Reference)) { //referenced ends
6.98 + result.add(((Reference) this).getReferencedEnd());
6.99 + result.add(((Reference) this).getExposedEnd());
6.100 + }
6.101 +
6.102 + result.remove(null);
6.103 + }
6.104 +
6.105 + private boolean isDepOfKind(String kind, ModelElement otherElement) {
6.106 + HashSet result = new HashSet();
6.107 + findDepsOfKind(kind, result);
6.108 + return result.contains(otherElement);
6.109 + }
6.110 +
6.111 + // --- operations
6.112 +
6.113 + public boolean isFrozen() {
6.114 + // [PENDING] has to be implemented to return true if there already exists an instance of this element
6.115 + return false;
6.116 + }
6.117 +
6.118 + public Collection findRequiredElements(Collection kinds, boolean recursive) {
6.119 + if (kinds.contains(ALL_DEP)) {
6.120 + return findRequiredElements(ALL_KINDS, recursive);
6.121 + } else {
6.122 + Set newKinds = (kinds == ALL_KINDS ? ALL_KINDS : new HashSet(kinds));
6.123 + Set result = new HashSet();
6.124 + if (recursive) {
6.125 + recursiveFindDeps(newKinds, result);
6.126 + } else {
6.127 + String kind;
6.128 + for (Iterator it = kinds.iterator(); it.hasNext();) {
6.129 + kind = (String) it.next();
6.130 + findDepsOfKind(kind, result);
6.131 + }
6.132 + }
6.133 + return result;
6.134 + }
6.135 + }
6.136 +
6.137 + public boolean isVisible(ModelElement otherElement) {
6.138 + return true;
6.139 + }
6.140 +
6.141 + public boolean isRequiredBecause(ModelElement otherElement, String[] reason) {
6.142 + for (Iterator it = ALL_KINDS.iterator(); it.hasNext();) {
6.143 + reason[0] = (String) it.next();
6.144 + if (isDepOfKind(reason[0], otherElement)) {
6.145 + return true;
6.146 + }
6.147 + }
6.148 +
6.149 + if (findRequiredElements(ALL_KINDS, true).size() > 0) {
6.150 + reason[0] = INDIRECT_DEP;
6.151 + } else {
6.152 + reason[0] = "";
6.153 + return false;
6.154 + }
6.155 +
6.156 + return true;
6.157 + }
6.158 +
6.159 + // --- derived attributes
6.160 +
6.161 + public List getQualifiedName() {
6.162 + List result;
6.163 + Namespace container = getContainer();
6.164 +
6.165 + if (container == null) {
6.166 + result = new ArrayList();
6.167 + } else {
6.168 + result = new ArrayList(container.getQualifiedName());
6.169 + }
6.170 + result.add(getName());
6.171 + return result;
6.172 + }
6.173 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/mdr/src/org/netbeans/jmiimpl/mof/model/NamespaceImpl.java Sat Sep 28 19:48:11 2002 +0000
7.3 @@ -0,0 +1,145 @@
7.4 +/*
7.5 + * Sun Public License Notice
7.6 + *
7.7 + * The contents of this file are subject to the Sun Public License
7.8 + * Version 1.0 (the "License"). You may not use this file except in
7.9 + * compliance with the License. A copy of the License is available at
7.10 + * http://www.sun.com/
7.11 + *
7.12 + * The Original Code is NetBeans. The Initial Developer of the Original
7.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
7.14 + * Microsystems, Inc. All Rights Reserved.
7.15 + */
7.16 +package org.netbeans.jmiimpl.mof.model;
7.17 +
7.18 +import java.util.*;
7.19 +import javax.jmi.model.*;
7.20 +import javax.jmi.reflect.*;
7.21 +
7.22 +import org.netbeans.mdr.util.*;
7.23 +import org.netbeans.mdr.storagemodel.*;
7.24 +import org.netbeans.mdr.persistence.*;
7.25 +import org.netbeans.mdr.handlers.*;
7.26 +
7.27 +/**
7.28 + * Implements MOF operations
7.29 + *
7.30 + * @author mmatula
7.31 + */
7.32 +public abstract class NamespaceImpl extends ModelElementImpl implements Namespace {
7.33 +
7.34 + protected NamespaceImpl(StorableObject storable) {
7.35 + super(storable);
7.36 + }
7.37 +
7.38 + private static final HashMap contains = new HashMap();
7.39 +
7.40 + protected static StorableAssociation resolveContains(StorableFeatured storable) throws StorageException {
7.41 + StorableAssociation result = (StorableAssociation) contains.get(storable.getOutermostPackageId());
7.42 +
7.43 + if (result == null) {
7.44 + result = storable.getClassProxy().getReferenceDescriptor(MOFConstants.SH_MODEL_MODEL_ELEMENT_CONTAINER).getAssociation();
7.45 + contains.put(storable.getOutermostPackageId(), result);
7.46 + }
7.47 +
7.48 + return result;
7.49 + }
7.50 +
7.51 + // --- operations
7.52 +
7.53 + public ModelElement lookupElement(String name) throws NameNotFoundException {
7.54 + Collection contents;
7.55 +
7.56 +// StorableFeatured storable = (StorableFeatured) _getDelegate();
7.57 +// Collection items = storable.getMdrStorage().objectsFromAdditionalIndex(storable.getOutermostPackageId(), "ModelElement.name", name);
7.58 +//
7.59 +// if (items != null) {
7.60 +// try {
7.61 +// StorableAssociation assoc = resolveContains(storable);
7.62 +// contents = (Collection) assoc.queryObjects(assoc.getEnd1Name(), storable.getMofId());
7.63 +// } catch (StorageException e) {
7.64 +// throw Logger.getDefault().annotate(new DebugException(), e);
7.65 +// }
7.66 +// Object result;
7.67 +// for (Iterator it = items.iterator(); it.hasNext();) {
7.68 +// result = it.next();
7.69 +// if (contents.contains(result)) {
7.70 +// return (ModelElement) BaseObjectHandler.getHandler((StorableBaseObject) result);
7.71 +// }
7.72 +// }
7.73 +// } else {
7.74 + contents = getContents();
7.75 +
7.76 + for(Iterator it = contents.iterator(); it.hasNext();) {
7.77 + ModelElement el = (ModelElement) it.next();
7.78 + if (el.getName().equals(name)) {
7.79 + return el;
7.80 + }
7.81 + }
7.82 +// }
7.83 +
7.84 + throw new NameNotFoundException(name);
7.85 + }
7.86 +
7.87 + public ModelElement resolveQualifiedName(List qualifiedName) throws NameNotResolvedException {
7.88 + if (qualifiedName.size() < 1) {
7.89 + throw new DebugException("No qualified name provided.");
7.90 + }
7.91 +
7.92 + ModelElement element;
7.93 + Iterator qnIterator = qualifiedName.iterator();
7.94 + String name = (String) qnIterator.next();
7.95 + ArrayList rest = new ArrayList();
7.96 +
7.97 + try {
7.98 + element = lookupElement(name);
7.99 + } catch (NameNotFoundException e) {
7.100 + throw new NameNotResolvedException("InvalidName", qualifiedName);
7.101 + }
7.102 +
7.103 + for (; qnIterator.hasNext();) {
7.104 + rest.add(qnIterator.next());
7.105 + }
7.106 +
7.107 + if (rest.size() >= 1) {
7.108 + if (element instanceof Namespace) {
7.109 + element = ((Namespace) element).resolveQualifiedName(rest);
7.110 + } else {
7.111 + throw new NameNotResolvedException("NotNameSpace", qualifiedName);
7.112 + }
7.113 + }
7.114 +
7.115 + return element;
7.116 + }
7.117 +
7.118 + public boolean nameIsValid(String proposedName) {
7.119 + try {
7.120 + if (this instanceof GeneralizableElement) {
7.121 + ((GeneralizableElement) this).lookupElementExtended(proposedName);
7.122 + } else {
7.123 + this.lookupElement(proposedName);
7.124 + }
7.125 + return false;
7.126 + } catch (NameNotFoundException e) {
7.127 + return true;
7.128 + }
7.129 + }
7.130 +
7.131 + public List findElementsByType(javax.jmi.model.MofClass ofType, boolean includeSubtypes ) {
7.132 + ArrayList result = new ArrayList();
7.133 + Collection contents = getContents();
7.134 + RefObject element;
7.135 +
7.136 + for (Iterator it = contents.iterator(); it.hasNext();) {
7.137 + element = (RefObject) it.next();
7.138 + if (element.refIsInstanceOf(ofType, includeSubtypes)) {
7.139 + result.add(element);
7.140 + }
7.141 + }
7.142 +
7.143 + return result;
7.144 + }
7.145 +
7.146 + // --- derived attributes
7.147 +
7.148 +}
8.1 --- a/mdr/src/org/netbeans/mdr/handlers/gen/TagSupport.java Thu Sep 26 14:52:36 2002 +0000
8.2 +++ b/mdr/src/org/netbeans/mdr/handlers/gen/TagSupport.java Sat Sep 28 19:48:11 2002 +0000
8.3 @@ -29,6 +29,7 @@
8.4 public class TagSupport extends Object {
8.5 public static final String TAGID_PACKAGE_PREFIX = "javax.jmi.packagePrefix";
8.6 public static final String TAGID_SUBSTITUTE_NAME = "javax.jmi.substituteName";
8.7 + public static final String TAGID_IMPL_PACKAGE_PREFIX = "org.netbeans.implPackagePrefix";
8.8
8.9 public static final int ASSOCIATION = 0;
8.10 public static final int INSTANCE = 1;
8.11 @@ -52,11 +53,11 @@
8.12 }
8.13
8.14 public static String getTypeFullName(StorableObject type, String substName) {
8.15 - return getTypePrefix(type) + "." + substName;
8.16 + return getTypePrefix(type, new StringBuffer(50)).append('.').append(substName).toString();
8.17 }
8.18
8.19 public static String getTypeFullName(StorableObject storable, int type) {
8.20 - return getTypeFullName(storable) + (type == CLASS ? "Class" : "") + (type == PACKAGE ? "Package" : "");
8.21 + return getTypePrefix(storable, new StringBuffer(50)).append('.').append(getSubstName(storable)).append((type == CLASS ? "Class" : (type == PACKAGE ? "Package" : ""))).toString();
8.22 }
8.23
8.24 /** Returns the full class-name of an optional implementation class
8.25 @@ -64,7 +65,7 @@
8.26 * name is available in the class-path it is used as super-class for the
8.27 * generated handler class. The returned class-name is:
8.28 *
8.29 - * <pre><i>package</i>.impl.<i>name</i>Impl</pre>
8.30 + * <pre>mdrjmiimpl.<i>package</i>.<i>name</i>Impl</pre>
8.31 * where
8.32 * <pre><i>package</i>.<i>name</i>.</pre>
8.33 * is the fully qualified name of the JMI interface.
8.34 @@ -74,7 +75,7 @@
8.35 * @return fully qualified class-name of optional implementation class
8.36 * */
8.37 public static String getImplFullName(StorableObject storable, int type) {
8.38 - return getTypePrefix(storable) + ".impl." + getSubstName(storable) + (type == CLASS ? "Class" : "") + (type == PACKAGE ? "Package" : "") + "Impl";
8.39 + return getImplPrefix(storable, new StringBuffer(50)).append('.').append(getSubstName(storable)).append(type == CLASS ? "Class" : (type == PACKAGE ? "Package" : "")).append("Impl").toString();
8.40 }
8.41
8.42 public static StorableObject getTag(StorableObject storable, String tagID) {
8.43 @@ -244,9 +245,8 @@
8.44 return mapName(name, true, false);
8.45 }
8.46
8.47 - public static String getTypePrefix(StorableObject storable) {
8.48 + private static StringBuffer getImplPrefix(StorableObject storable, StringBuffer sb) {
8.49 try {
8.50 - String result;
8.51 StorableObject pckg = storable;
8.52
8.53 while (!MOFConstants.SH_MODEL_PACKAGE.equals(pckg.getMetaObject().getAttribute(MOFConstants.SH_MODEL_MODEL_ELEMENT_NAME))) {
8.54 @@ -255,9 +255,34 @@
8.55
8.56 StorableObject container = (StorableObject) pckg.getReference(MOFConstants.SH_MODEL_MODEL_ELEMENT_CONTAINER);
8.57 if (container == null) {
8.58 - result = getTagValue(pckg, TAGID_PACKAGE_PREFIX);
8.59 + String result = getTagValue(pckg, TAGID_IMPL_PACKAGE_PREFIX);
8.60 + if (result == null) {
8.61 + result = getTagValue(pckg, TAGID_PACKAGE_PREFIX);
8.62 + if (result == null) {
8.63 + sb.append("impl");
8.64 + } else {
8.65 + result = result.toLowerCase();
8.66 + if ("javax.jmi".equals(result)) {
8.67 + sb.append("org.netbeans.jmiimpl.mof");
8.68 + } else if (result.startsWith("org.netbeans.jmi.")) {
8.69 + sb.append("org.netbeans.jmiimpl").append(result.substring(16));
8.70 + } else if (result.startsWith("org.omg")) {
8.71 + if (result.length() == 7) {
8.72 + sb.append("org.netbeans.jmiimpl.omg");
8.73 + } else if (result.charAt(7) == '.') {
8.74 + sb.append("org.netbeans.jmiimpl.omg").append(result.substring(7));
8.75 + } else {
8.76 + sb.append(result).append(".impl");
8.77 + }
8.78 + } else {
8.79 + sb.append(result).append(".impl");
8.80 + }
8.81 + }
8.82 + } else {
8.83 + sb.append(result.toLowerCase());
8.84 + }
8.85 } else {
8.86 - result = getTypePrefix(container);
8.87 + getImplPrefix(container, sb);
8.88 }
8.89
8.90 String packageName = getTagValue(pckg, TAGID_SUBSTITUTE_NAME);
8.91 @@ -265,13 +290,42 @@
8.92 packageName = mapName((String) pckg.getAttribute(MOFConstants.SH_MODEL_MODEL_ELEMENT_NAME), false, true);
8.93 }
8.94
8.95 - if (result == null) {
8.96 - result = packageName;
8.97 - } else {
8.98 - result = result + "." + packageName;
8.99 + sb.append('.').append(packageName.toLowerCase());
8.100 +
8.101 + return sb;
8.102 + } catch (Exception e) {
8.103 + throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
8.104 + }
8.105 + }
8.106 +
8.107 + public static String getTypePrefix(StorableObject storable) {
8.108 + return getTypePrefix(storable, new StringBuffer(50)).toString();
8.109 + }
8.110 +
8.111 + public static StringBuffer getTypePrefix(StorableObject storable, StringBuffer sb) {
8.112 + try {
8.113 + StorableObject pckg = storable;
8.114 +
8.115 + while (!MOFConstants.SH_MODEL_PACKAGE.equals(pckg.getMetaObject().getAttribute(MOFConstants.SH_MODEL_MODEL_ELEMENT_NAME))) {
8.116 + pckg = (StorableObject) pckg.getReference(MOFConstants.SH_MODEL_MODEL_ELEMENT_CONTAINER);
8.117 }
8.118
8.119 - return result.toLowerCase();
8.120 + StorableObject container = (StorableObject) pckg.getReference(MOFConstants.SH_MODEL_MODEL_ELEMENT_CONTAINER);
8.121 + if (container == null) {
8.122 + String result = getTagValue(pckg, TAGID_PACKAGE_PREFIX);
8.123 + if (result != null) {
8.124 + sb.append(result.toLowerCase()).append('.');
8.125 + }
8.126 + } else {
8.127 + getTypePrefix(container, sb).append('.');
8.128 + }
8.129 +
8.130 + String packageName = getTagValue(pckg, TAGID_SUBSTITUTE_NAME);
8.131 + if (packageName == null) {
8.132 + packageName = mapName((String) pckg.getAttribute(MOFConstants.SH_MODEL_MODEL_ELEMENT_NAME), false, true);
8.133 + }
8.134 +
8.135 + return sb.append(packageName.toLowerCase());
8.136 } catch (Exception e) {
8.137 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
8.138 }