/** * Erstellt ein neues KExDavObject * * @param objectSpecification Objekt-Spezifikation * @param connection Datenverteiler-Verbindung * @param manager KExDaV-Manager-Objekt, an das Benachrichtigungen gesendet werden können */ public KExDaVObject( final ObjectSpecification objectSpecification, final ClientDavInterface connection, final ManagerInterface manager) { _manager = manager; if (objectSpecification == null) throw new IllegalArgumentException("objectSpecification ist null"); if (connection == null) throw new IllegalArgumentException("connection ist null"); _objectSpecification = objectSpecification; _connection = connection; final SystemObject object = objectSpecification.getObject(_connection.getDataModel()); setWrappedObject(object); // Anmeldung auf Erstellung/Löschung des Objektes (nicht nötig bei schon vorhandenen // Konfigurationsobjekten) if (object == null || object.getType() instanceof DynamicObjectType) { /** * Direkt beim typ.dynamischesObject anmelden. Das Anmelden beim eigentlichen Typ dieses * Objektes funktioniert nicht immer zuverlässig, weil unter Umständen dieses Objekt noch gar * nicht vorhanden und deshalb kein Typ ermittelbar ist, oder weil evtl. jemand das Objekt mit * diesem Typ löschen könnte und ein anderes Objekt mit der gleichen Pid von einem anderen Typ * erstellen könnte */ final DynamicObjectType dynamicObjectType = (DynamicObjectType) connection.getDataModel().getType(Constants.Pids.TypeDynamicObject); if (dynamicObjectType == null) throw new IllegalStateException( Constants.Pids.TypeDynamicObject + " konnte nicht gefunden werden"); final Listener objectCreateDeleteListener = new Listener(); dynamicObjectType.addInvalidationListener(objectCreateDeleteListener); dynamicObjectType.addObjectCreationListener(objectCreateDeleteListener); } }
/** * Anmeldung als Empfänger/Senke * * @param atg Attributgruppe * @param asp Aspekt * @param simulationVariant Simulationsvariante * @param receiverRole (Empfänger oder Senke) * @param receiveOptions (Delta oder Nachgeliefert oder Normal) * @param receiver Objekt an das Empfangene Daten gesendet werden. Jedes Objekt ist einer * Datenidentifikation fest zugeordnet und kann nur einmal angemeldet werden. * @throws MissingObjectException Falls Attributgruppe oder Aspekt nicht vorhanden sind */ public boolean registerReceiver( final String atg, final String asp, final short simulationVariant, final ReceiverRole receiverRole, final ReceiveOptions receiveOptions, final KExDaVReceiver receiver) throws MissingObjectException { if (atg == null) throw new IllegalArgumentException("atg ist null"); if (asp == null) throw new IllegalArgumentException("asp ist null"); if (receiverRole == null) throw new IllegalArgumentException("receiverRole ist null"); if (receiver == null) throw new IllegalArgumentException("receiver ist null"); if (_receivers.containsKey(receiver)) throw new IllegalArgumentException("Der Empfänger " + receiver + " ist bereits angemeldet."); final DataDescription dataDescription = makeDataDescription(atg, asp, simulationVariant); final InnerReceiver innerReceiver = new InnerReceiver(receiver, receiverRole, dataDescription, receiveOptions); final SystemObject systemObject = getWrappedObject(); if (systemObject == null) return true; if (!checkType(systemObject.getType(), dataDescription.getAttributeGroup())) return false; registerReceiver(innerReceiver, systemObject); return true; }
/** * Anmeldung als Sender oder Quelle * * @param atg Attributgruppe * @param asp Aspekt * @param simulationVariant Simulationsvariante * @param senderRole Sender oder Quelle * @param senderObject Beliebiges Objekt das zu diesem Sender gespeichert wird. Jedes Objekt ist * einer Datenidentifikation fest zugeordnet und kann nur einmal angemeldet werden. * @throws MissingObjectException Falls Attributgruppe oder Aspekt nicht vorhanden sind * @return true wenn das Objekt angemeldet wurde, sonst false. */ public boolean registerSender( final String atg, final String asp, final short simulationVariant, final SenderRole senderRole, final KExDaVSender senderObject) throws MissingObjectException { if (atg == null) throw new IllegalArgumentException("atg ist null"); if (asp == null) throw new IllegalArgumentException("asp ist null"); if (senderRole == null) throw new IllegalArgumentException("senderRole ist null"); if (senderObject == null) throw new IllegalArgumentException("senderObject ist null"); if (_senders.containsKey(senderObject)) throw new IllegalArgumentException("Der Sender " + senderObject + " ist bereits angemeldet."); final DataDescription dataDescription = makeDataDescription(atg, asp, simulationVariant); final InnerSender innerSender = new InnerSender(senderObject, dataDescription, senderRole); final SystemObject systemObject = getWrappedObject(); if (systemObject == null) return true; if (!checkType(systemObject.getType(), dataDescription.getAttributeGroup())) return false; registerSender(innerSender, systemObject); return true; }
public static ExchangeProperties getExchangeProperties(final SystemObject wrappedObject) throws MissingKExDaVAttributeGroupException { final AttributeGroup attributeGroup = wrappedObject .getDataModel() .getAttributeGroup(Constants.Pids.AttributeGroupKExDaVConfigData); if (attributeGroup == null) throw new MissingKExDaVAttributeGroupException(); Data data = wrappedObject.getConfigurationData(attributeGroup); if (data == null) return null; return new ExchangeProperties(data); }
private void recurse(File file) { if (file.isDirectory()) { File files[] = file.listFiles(); for (File afile : files) { if (afile.isDirectory()) recurse(afile); else if (afile.getName().toLowerCase().endsWith(".class")) { so.addClass(parseBytecode(afile)); } } } else if (file.getName().toLowerCase().endsWith(".class")) so.addClass(parseBytecode(file)); // Natasha Khan System.out.print("Recursing file and finding Pattern in Classes. "); System.out.print(so); }
/** * Löscht dieses Objekt * * @param force Soll das Objekt auch gelöscht werden, wenn es nicht von KExDaV kopiert wurde? * @return true wenn das Objekt nicht mehr existiert, sonst false * @throws ConfigurationChangeException Falls das Ändern der Konfiguration fehlschlägt (z.B. keine * Berechtigung) */ public boolean invalidate(final boolean force) throws ConfigurationChangeException, MissingKExDaVAttributeGroupException { final SystemObject wrappedObject = getWrappedObject(); if (wrappedObject == null || !wrappedObject.isValid()) { return true; // Objekt existiert nicht mehr, es braucht nicht nochmal gelöscht zu werden. // Daher ist auch eine Warnung unnötig. } if (wrappedObject instanceof ConfigurationObject) { throw new IllegalArgumentException("Versuch, ein Konfigurationsobjekt zu löschen."); } if (!force && !isCopy()) return false; _manager.addMessage(Message.newInfo("Lösche Objekt: " + _objectSpecification)); wrappedObject.invalidate(); setWrappedObject(null); return true; }
public ASTReader(IJavaProject iJavaProject, IProgressMonitor monitor) { if (monitor != null) monitor.beginTask("Parsing selected Java Project", getNumberOfCompilationUnits(iJavaProject)); systemObject = new SystemObject(); examinedProject = iJavaProject; try { IPackageFragmentRoot[] iPackageFragmentRoots = iJavaProject.getPackageFragmentRoots(); for (IPackageFragmentRoot iPackageFragmentRoot : iPackageFragmentRoots) { IJavaElement[] children = iPackageFragmentRoot.getChildren(); for (IJavaElement child : children) { if (child.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { IPackageFragment iPackageFragment = (IPackageFragment) child; ICompilationUnit[] iCompilationUnits = iPackageFragment.getCompilationUnits(); for (ICompilationUnit iCompilationUnit : iCompilationUnits) { if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException(); systemObject.addClasses(parseAST(iCompilationUnit)); if (monitor != null) monitor.worked(1); } } } } } catch (JavaModelException e) { e.printStackTrace(); } if (monitor != null) monitor.done(); }
public ASTReader( IJavaProject iJavaProject, SystemObject existingSystemObject, IProgressMonitor monitor) { Set<ICompilationUnit> changedCompilationUnits = new LinkedHashSet<ICompilationUnit>(); Set<ICompilationUnit> addedCompilationUnits = new LinkedHashSet<ICompilationUnit>(); Set<ICompilationUnit> removedCompilationUnits = new LinkedHashSet<ICompilationUnit>(); CompilationUnitCache instance = CompilationUnitCache.getInstance(); for (ICompilationUnit changedCompilationUnit : instance.getChangedCompilationUnits()) { if (changedCompilationUnit.getJavaProject().equals(iJavaProject)) changedCompilationUnits.add(changedCompilationUnit); } for (ICompilationUnit addedCompilationUnit : instance.getAddedCompilationUnits()) { if (addedCompilationUnit.getJavaProject().equals(iJavaProject)) addedCompilationUnits.add(addedCompilationUnit); } for (ICompilationUnit removedCompilationUnit : instance.getRemovedCompilationUnits()) { if (removedCompilationUnit.getJavaProject().equals(iJavaProject)) removedCompilationUnits.add(removedCompilationUnit); } if (monitor != null) monitor.beginTask( "Parsing changed/added Compilation Units", changedCompilationUnits.size() + addedCompilationUnits.size()); systemObject = existingSystemObject; examinedProject = iJavaProject; for (ICompilationUnit removedCompilationUnit : removedCompilationUnits) { IFile removedCompilationUnitFile = (IFile) removedCompilationUnit.getResource(); systemObject.removeClasses(removedCompilationUnitFile); } for (ICompilationUnit changedCompilationUnit : changedCompilationUnits) { List<ClassObject> changedClassObjects = parseAST(changedCompilationUnit); for (ClassObject changedClassObject : changedClassObjects) { systemObject.replaceClass(changedClassObject); } if (monitor != null) monitor.worked(1); } for (ICompilationUnit addedCompilationUnit : addedCompilationUnits) { List<ClassObject> addedClassObjects = parseAST(addedCompilationUnit); for (ClassObject addedClassObject : addedClassObjects) { systemObject.addClass(addedClassObject); } if (monitor != null) monitor.worked(1); } instance.clearAffectedCompilationUnits(); if (monitor != null) monitor.done(); }
public boolean isValid(final SystemObject object) { if (object == null) return false; if (object instanceof ConfigurationObject) { ConfigurationObject configurationObject = (ConfigurationObject) object; short viewingVersion = getVersion(configurationObject); final short validSince = configurationObject.getValidSince(); final short notValidSince = configurationObject.getNotValidSince(); return validSince <= viewingVersion && (notValidSince == 0 || viewingVersion < notValidSince); } else return object.isValid(); }
/** * Bestimmt die betrachtete Version des Konfigurationsbereichs in dem das angegebene Objekt * enthalten ist. * * @param object Systemobjekt zu dem die Version ermittelt werden soll. * @return Version des Konfigurationsbereichs des angegebenen Systemobjekts */ public short getVersion(final SystemObject object) { final ConfigurationArea configurationArea = object.getConfigurationArea(); Short version = _configurationAreaVersions.get(configurationArea); if (version != null) return version.shortValue(); // throw new IllegalStateException("Version des Konfigurationsbereichs " + // object.getConfigurationArea().getPidOrNameOrId() + " nicht definiert"); // Falls in der Map ein Konfigurationsbereich nicht enthalten ist, dann wird die aktive Version // des Bereichs zurückgegeben. return configurationArea.getActiveVersion(); }
/** * Liest alle Konfigurationsdaten dieses Objekts * * @return Konfigurationsdaten * @throws MissingObjectException Falls ein Objekt fehlt (entweder das Systemobjekt, oder die * Attributgruppe oder der Aspekt) */ public Map<PidAttributeGroupUsage, KExDaVAttributeGroupData> getAllConfigurationData() throws MissingObjectException { final SystemObject wrappedObject = getWrappedObjectOrThrowException(); final Map<PidAttributeGroupUsage, KExDaVAttributeGroupData> result = new HashMap<PidAttributeGroupUsage, KExDaVAttributeGroupData>(); final List<AttributeGroup> attributeGroups = wrappedObject.getType().getAttributeGroups(); for (final AttributeGroup attributeGroup : attributeGroups) { final Collection<Aspect> aspects = attributeGroup.getAspects(); for (final Aspect aspect : aspects) { final Data data = wrappedObject.getConfigurationData(attributeGroup, aspect); if (data != null) { result.put( new PidAttributeGroupUsage(attributeGroup.getPid(), aspect.getPid()), new KExDaVAttributeGroupData(data, _manager)); } } } return result; }
/** * Liefert das System-Objekt mit der angegebenen PID zurück. * * @param pid Die permanente ID des System-Objekts * @return Das gewünschte System-Objekt oder <code>null</code>, wenn es kein Objekt mit der * angegebenen PID gibt. * @see de.bsvrz.dav.daf.main.config.DataModel */ public SystemObject getObject(String pid) { if (pid == null || pid.equals("") || pid.equals("null")) return null; SystemObject object = _dataModel.getObject(pid); if (isValid(object)) return object; synchronized (this) { // Sans, STS, KonfigAss: Korrektur _newlyActiveObjects if (_newlyActiveObjects == null) { _newlyActiveObjects = new HashMap<String, SystemObject>(); long startTime = System.currentTimeMillis(); final Map<String, ConfigurationArea> areas = ((ConfigDataModel) _dataModel).getAllConfigurationAreas(); for (ConfigurationArea configurationArea : areas.values()) { final Collection<SystemObject> newObjects = configurationArea.getNewObjects(); for (SystemObject newObject : newObjects) { final String newObjectPid = newObject.getPid(); if (newObjectPid != null && newObjectPid.length() > 0 && isValid(newObject)) { _newlyActiveObjects.put(newObjectPid, newObject); } } _debug.fine( "Zwischenspeicherung von neuerdings aktiven Objekten dauerte in Millisekunden", System.currentTimeMillis() - startTime); } } return _newlyActiveObjects.get(pid); } // final Set<ConfigurationArea> configurationAreas = _configurationAreaVersions.keySet(); // for(ConfigurationArea configurationArea : configurationAreas) { // final Collection<SystemObject> newObjects = configurationArea.getNewObjects(); // for(SystemObject systemObject : newObjects) { // if(systemObject.getPid().equals(pid) && isValid(systemObject)) return systemObject; // } // } // return null; }
private synchronized void setWrappedObject(final SystemObject wrappedObject) { if (_wrappedObject == wrappedObject) return; _wrappedObject = wrappedObject; if (wrappedObject != null) { for (final InnerReceiver receiver : _receivers.values()) { if (checkType(wrappedObject.getType(), receiver.getDataDescription().getAttributeGroup())) { registerReceiver(receiver, wrappedObject); } } for (final InnerSender sender : _senders.values()) { if (checkType(wrappedObject.getType(), sender.getDataDescription().getAttributeGroup())) { registerSender(sender, wrappedObject); } } for (final ExistenceListener listener : _existenceListeners) { listener.objectCreated(this); } } else { for (final ExistenceListener listener : _existenceListeners) { listener.objectInvalidated(this); } } }
private List<ClassObject> parseAST(CompilationUnit compilationUnit, IFile iFile) { List<ClassObject> classObjects = new ArrayList<ClassObject>(); List<AbstractTypeDeclaration> topLevelTypeDeclarations = compilationUnit.types(); for (AbstractTypeDeclaration abstractTypeDeclaration : topLevelTypeDeclarations) { if (abstractTypeDeclaration instanceof TypeDeclaration) { TypeDeclaration topLevelTypeDeclaration = (TypeDeclaration) abstractTypeDeclaration; List<TypeDeclaration> typeDeclarations = new ArrayList<TypeDeclaration>(); typeDeclarations.add(topLevelTypeDeclaration); typeDeclarations.addAll(getRecursivelyInnerTypes(topLevelTypeDeclaration)); for (TypeDeclaration typeDeclaration : typeDeclarations) { final ClassObject classObject = new ClassObject(); classObject.setIFile(iFile); classObject.setName(typeDeclaration.resolveBinding().getQualifiedName()); classObject.setTypeDeclaration(typeDeclaration); if (typeDeclaration.isInterface()) { classObject.setInterface(true); } int modifiers = typeDeclaration.getModifiers(); if ((modifiers & Modifier.ABSTRACT) != 0) classObject.setAbstract(true); if ((modifiers & Modifier.PUBLIC) != 0) classObject.setAccess(Access.PUBLIC); else if ((modifiers & Modifier.PROTECTED) != 0) classObject.setAccess(Access.PROTECTED); else if ((modifiers & Modifier.PRIVATE) != 0) classObject.setAccess(Access.PRIVATE); else classObject.setAccess(Access.NONE); if ((modifiers & Modifier.STATIC) != 0) classObject.setStatic(true); Type superclassType = typeDeclaration.getSuperclassType(); if (superclassType != null) { ITypeBinding binding = superclassType.resolveBinding(); String qualifiedName = binding.getQualifiedName(); TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName); classObject.setSuperclass(typeObject); } List<Type> superInterfaceTypes = typeDeclaration.superInterfaceTypes(); for (Type interfaceType : superInterfaceTypes) { ITypeBinding binding = interfaceType.resolveBinding(); String qualifiedName = binding.getQualifiedName(); TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName); classObject.addInterface(typeObject); } FieldDeclaration[] fieldDeclarations = typeDeclaration.getFields(); for (FieldDeclaration fieldDeclaration : fieldDeclarations) { Type fieldType = fieldDeclaration.getType(); ITypeBinding binding = fieldType.resolveBinding(); List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments(); for (VariableDeclarationFragment fragment : fragments) { String qualifiedName = binding.getQualifiedName(); TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName); typeObject.setArrayDimension( typeObject.getArrayDimension() + fragment.getExtraDimensions()); FieldObject fieldObject = new FieldObject(typeObject, fragment.getName().getIdentifier()); fieldObject.setClassName(classObject.getName()); fieldObject.setVariableDeclarationFragment(fragment); int fieldModifiers = fieldDeclaration.getModifiers(); if ((fieldModifiers & Modifier.PUBLIC) != 0) fieldObject.setAccess(Access.PUBLIC); else if ((fieldModifiers & Modifier.PROTECTED) != 0) fieldObject.setAccess(Access.PROTECTED); else if ((fieldModifiers & Modifier.PRIVATE) != 0) fieldObject.setAccess(Access.PRIVATE); else fieldObject.setAccess(Access.NONE); if ((fieldModifiers & Modifier.STATIC) != 0) fieldObject.setStatic(true); classObject.addField(fieldObject); } } MethodDeclaration[] methodDeclarations = typeDeclaration.getMethods(); for (MethodDeclaration methodDeclaration : methodDeclarations) { String methodName = methodDeclaration.getName().getIdentifier(); final ConstructorObject constructorObject = new ConstructorObject(); constructorObject.setMethodDeclaration(methodDeclaration); constructorObject.setName(methodName); constructorObject.setClassName(classObject.getName()); int methodModifiers = methodDeclaration.getModifiers(); if ((methodModifiers & Modifier.PUBLIC) != 0) constructorObject.setAccess(Access.PUBLIC); else if ((methodModifiers & Modifier.PROTECTED) != 0) constructorObject.setAccess(Access.PROTECTED); else if ((methodModifiers & Modifier.PRIVATE) != 0) constructorObject.setAccess(Access.PRIVATE); else constructorObject.setAccess(Access.NONE); List<SingleVariableDeclaration> parameters = methodDeclaration.parameters(); for (SingleVariableDeclaration parameter : parameters) { Type parameterType = parameter.getType(); ITypeBinding binding = parameterType.resolveBinding(); String qualifiedName = binding.getQualifiedName(); TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName); typeObject.setArrayDimension( typeObject.getArrayDimension() + parameter.getExtraDimensions()); if (parameter.isVarargs()) { typeObject.setArrayDimension(1); } ParameterObject parameterObject = new ParameterObject(typeObject, parameter.getName().getIdentifier()); parameterObject.setSingleVariableDeclaration(parameter); constructorObject.addParameter(parameterObject); } Block methodBody = methodDeclaration.getBody(); if (methodBody != null) { MethodBodyObject methodBodyObject = new MethodBodyObject(methodBody); constructorObject.setMethodBody(methodBodyObject); } if (methodDeclaration.isConstructor()) { classObject.addConstructor(constructorObject); } else { MethodObject methodObject = new MethodObject(constructorObject); List<IExtendedModifier> extendedModifiers = methodDeclaration.modifiers(); for (IExtendedModifier extendedModifier : extendedModifiers) { if (extendedModifier.isAnnotation()) { Annotation annotation = (Annotation) extendedModifier; if (annotation.getTypeName().getFullyQualifiedName().equals("Test")) { methodObject.setTestAnnotation(true); break; } } } Type returnType = methodDeclaration.getReturnType2(); ITypeBinding binding = returnType.resolveBinding(); String qualifiedName = binding.getQualifiedName(); TypeObject typeObject = TypeObject.extractTypeObject(qualifiedName); methodObject.setReturnType(typeObject); if ((methodModifiers & Modifier.ABSTRACT) != 0) methodObject.setAbstract(true); if ((methodModifiers & Modifier.STATIC) != 0) methodObject.setStatic(true); if ((methodModifiers & Modifier.SYNCHRONIZED) != 0) methodObject.setSynchronized(true); if ((methodModifiers & Modifier.NATIVE) != 0) methodObject.setNative(true); classObject.addMethod(methodObject); FieldInstructionObject fieldInstruction = methodObject.isGetter(); if (fieldInstruction != null) systemObject.addGetter(methodObject.generateMethodInvocation(), fieldInstruction); fieldInstruction = methodObject.isSetter(); if (fieldInstruction != null) systemObject.addSetter(methodObject.generateMethodInvocation(), fieldInstruction); fieldInstruction = methodObject.isCollectionAdder(); if (fieldInstruction != null) systemObject.addCollectionAdder( methodObject.generateMethodInvocation(), fieldInstruction); MethodInvocationObject methodInvocation = methodObject.isDelegate(); if (methodInvocation != null) systemObject.addDelegate(methodObject.generateMethodInvocation(), methodInvocation); } } classObjects.add(classObject); } } } return classObjects; }
/** * Bestimmt, ob das angegebene System-Objekt ein Element des angegebenen Typs ist. Ein * System-Objekt ist Element des Typs, wenn der Typ des Objekts mit dem angegebenen Typ * übereinstimmt oder diesen erweitert. * * @param object Zu prüfendes Objekt. * @param ancestorType Zu prüfender Typ. * @return <code>true</code>, wenn der übergebene Typ mit dem Typ des Objekts oder mit einem der * direkten oder indirekten Vorgänger in der Vererbungshierarchie übereinstimmt; sonst <code> * false</code>. */ public boolean isOfType(SystemObject object, SystemObjectType ancestorType) { final SystemObjectType objectType = object.getType(); if (ancestorType == objectType) return true; return inheritsFrom(objectType, ancestorType); }
/** * Prüft ob das Objekt existiert * * @return True wenn es existiert */ public boolean exists() { final SystemObject wrappedObject = getWrappedObject(); return wrappedObject != null && wrappedObject.isValid(); }
@Override public String toString() { final SystemObject wrappedObject = getWrappedObject(); if (wrappedObject != null) return wrappedObject.getPidOrNameOrId(); return _objectSpecification.toString(); }