/** * Returns the firsts Association from fromAssociations that matches with association type and * have the ManagedElement element as "from" element * * @param clazz specific Association.class * @param element that represents the "from" * @return Association of type clazz that have I as a "to" and the element as "from" */ public Association getFirstFromAssociationByTypeAndElement( Class<? extends Association> clazz, ManagedElement element) { for (Association assoc : fromAssociations) if (clazz.isInstance(assoc)) if (assoc.getFrom().equals(element)) return assoc; return null; }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!Association.class.isInstance(obj)) { return false; } try { @SuppressWarnings("unchecked") Association<K, L, A, M, D> other = (Association<K, L, A, M, D>) obj; A other_a = other.getAntecendent(); A this_a = this.getAntecendent(); if (this_a == other_a || (this_a != null && this_a.equals(other_a))) { D other_d = other.getDependent(); D this_d = this.getDependent(); if (this_d == other_d || (this_d != null && this_d.equals(other_d))) { return true; } } } catch (ClassCastException ex) { return false; } return false; }
@Override public SctpChannel accept() throws IOException, SctpException, InvalidKeyException, NoSuchAlgorithmException { logger.setLevel(Level.INFO); DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length); SctpPacket packet = null; while (true) { serverSocket.receive(receivePacket); try { packet = new SctpPacket(buffer, 0, receivePacket.getLength()); } catch (SctpException e) { logger.log(Level.WARNING, e.getMessage()); continue; } logger.log(Level.INFO, "receive new packet"); InetSocketAddress address = new InetSocketAddress(receivePacket.getAddress(), receivePacket.getPort()); packet.apply(address, this); Association association = pendingAssociations.get(address); if (association != null && association.getState() == State.ESTABLISHED) { return new SctpChannel(association); } } }
/** * Constructor for class BackupAssociation * * @param assoc the given Association (not null). * @param regLevel the given registeration level. */ protected BackupAssociation(Association assoc, int regLevel) { curMimeType = assoc.getMimeType(); Iterator<String> iter = null; List<String> temFileExtList = assoc.getFileExtList(); if (temFileExtList != null) { iter = temFileExtList.iterator(); } if (iter != null) { if (iter.hasNext()) { curFileExt = (String) iter.next(); } } if (curMimeType != null) { curMimeTypeExisted = WinRegistryUtil.isMimeTypeExist(curMimeType, regLevel); } else { curMimeTypeExisted = false; } if (curFileExt != null) { curFileExtExisted = WinRegistryUtil.isFileExtExist(curFileExt, regLevel); } else { curFileExtExisted = false; } if (curMimeTypeExisted) { backupFileExt = WinRegistryUtil.getFileExtByMimeType(curMimeType, regLevel); } if (curFileExtExisted) { backupClassID = WinRegistryUtil.getClassIDByFileExt(curFileExt, regLevel); backupMimeType = WinRegistryUtil.getMimeTypeByFileExt(curFileExt, regLevel); } }
/** * remove the specific association from the vector fromAssociation that * * <p>have the ManagedElement element as a "from" * * @param the ManagedElement that represents the "from" into the Association * @return true if association is removed from the vector, false otherwise */ public boolean removeFromAssociationByElement(ManagedElement element) { for (Association assoc : fromAssociations) if (assoc.getFrom().equals(element)) { return removeFromAssociation(assoc); } return false; }
/** * Returns the firsts ManagedElement that represents the "to" of the toAssociations that match * with association type * * @param specific Association.class * @return ManagedElement that represents the "to" of the toAssociations */ public ManagedElement getFisrtsToAssociatedElementByType(Class<? extends Association> clazz) { ManagedElement element = null; for (Association assoc : toAssociations) { if (clazz.isInstance(assoc)) return assoc.getTo(); } return element; }
/** * Returns the list of ManagedElement that represents the "to" of the toAssociations, that match * with association type * * @param specific Association.class * @return list of ManagedElement that represents the "to" of the toAssociations */ public List<? extends ManagedElement> getToAssociatedElementsByType( Class<? extends Association> clazz) { List<ManagedElement> elements = new LinkedList<ManagedElement>(); for (Association assoc : toAssociations) { if (clazz.isInstance(assoc)) elements.add(assoc.getTo()); } return elements; }
@Override protected void deleteEntities( PersistentEntity pe, @SuppressWarnings("rawtypes") Iterable objects) { List<EntityAccess> entityAccesses = new ArrayList<EntityAccess>(); List<Object> ids = new ArrayList<Object>(); Map<PersistentEntity, Collection<Object>> cascades = new HashMap<PersistentEntity, Collection<Object>>(); for (Object obj : objects) { EntityAccess entityAccess = createEntityAccess(pe, obj); if (cancelDelete(pe, entityAccess)) { return; } entityAccesses.add(entityAccess); ids.add(entityAccess.getIdentifier()); // populate cascades for (Association association : pe.getAssociations()) { Object property = entityAccess.getProperty(association.getName()); if (association.isOwningSide() && association.doesCascade(CascadeType.REMOVE) && (property != null)) { PersistentEntity associatedEntity = association.getAssociatedEntity(); Collection<Object> cascadesForPersistentEntity = cascades.get(associatedEntity); if (cascadesForPersistentEntity == null) { cascadesForPersistentEntity = new ArrayList<Object>(); cascades.put(associatedEntity, cascadesForPersistentEntity); } if (association instanceof ToOne) { cascadesForPersistentEntity.add(property); } else { cascadesForPersistentEntity.addAll((Collection<?>) property); } } } } for (Map.Entry<PersistentEntity, Collection<Object>> entry : cascades.entrySet()) { deleteEntities(entry.getKey(), entry.getValue()); } getCypherEngine() .execute( String.format( "MATCH (n:%s) WHERE n.__id__ in {ids} OPTIONAL MATCH (n)-[r]-() DELETE r,n", ((GraphPersistentEntity) pe).getLabel()), Collections.singletonMap("ids", ids)); for (EntityAccess entityAccess : entityAccesses) { firePostDeleteEvent(pe, entityAccess); } }
/** PUBLIC: Set a collection of the source to target query key/field associations. */ public void setSourceToTargetQueryKeyFieldAssociations( Vector sourceToTargetQueryKeyFieldAssociations) { setSourceToTargetQueryKeyFields( new HashMap(sourceToTargetQueryKeyFieldAssociations.size() + 1)); for (Enumeration associationsEnum = sourceToTargetQueryKeyFieldAssociations.elements(); associationsEnum.hasMoreElements(); ) { Association association = (Association) associationsEnum.nextElement(); Object sourceField = new DatabaseField((String) association.getKey()); String targetQueryKey = (String) association.getValue(); getSourceToTargetQueryKeyNames().put(sourceField, targetQueryKey); } }
/** * Checks whether the given assocation is valid for unregistration. If both the mimeType and * fileExtensionList field is null, throw exception. * * @param assoc a given Association object. * @throws IllegalArgumentException if the given association is not valid for unregistration. */ public void checkAssociationValidForUnregistration(Association assoc) throws IllegalArgumentException { boolean isFileExtListEmpty = true; if (assoc.getFileExtList() != null) { isFileExtListEmpty = assoc.getFileExtList().isEmpty(); } if ((assoc.getMimeType() == null) && isFileExtListEmpty) { throw new IllegalArgumentException( "The given association is invalid. It should " + "specify both the mimeType and fileExtensionList fields to perform this " + "operation."); } }
private void configureAssociation( GrailsDomainClassProperty grailsDomainClassProperty, final Association association) { association.setAssociatedEntity( getMappingContext() .addPersistentEntity(grailsDomainClassProperty.getReferencedPropertyType())); association.setOwningSide(grailsDomainClassProperty.isOwningSide()); String referencedPropertyName = grailsDomainClassProperty.getReferencedPropertyName(); if (referencedPropertyName != null) { association.setReferencedPropertyName(referencedPropertyName); } else { GrailsDomainClassProperty otherSide = grailsDomainClassProperty.getOtherSide(); if (otherSide != null) { association.setReferencedPropertyName(otherSide.getName()); } } }
/** * Checks whether the given assocation is valid for registration. * * <PRE> * 1. The file extension list and mime type can't all be null * 2. If any of the fileds: description, iconFile, actionList is not null, * then fileExtensionList should not be empty * </PRE> * * @param assoc a given Association object. * @throws IllegalArgumentException if the given association is not valid for registration. */ public void checkAssociationValidForRegistration(Association assoc) throws IllegalArgumentException { boolean isActionListEmpty = true; boolean isFileExtensionEmpty = true; boolean isValid = false; // Check if actionlist is empty if (assoc.getActionList() != null) { isActionListEmpty = assoc.getActionList().isEmpty(); } // Check if file extension list is empty if (assoc.getFileExtList() != null) { isFileExtensionEmpty = assoc.getFileExtList().isEmpty(); } if (isFileExtensionEmpty && (assoc.getMimeType() == null)) { isValid = false; } else if ((assoc.getDescription() != null) || (assoc.getIconFileName() != null) || (!isActionListEmpty)) { isValid = !isFileExtensionEmpty; } else { isValid = true; } if (!isValid) { throw new IllegalArgumentException( "The given association is invalid. It should " + "specify both the mimeType and fileExtensionList fields to perform this operation."); } }
public static PolicyGroupInSystem link(System antecedent, PolicyGroup dependent, int priority) { PolicyGroupInSystem assoc = (PolicyGroupInSystem) Association.link(PolicyGroupInSystem.class, antecedent, dependent); assoc.setAntecedent(antecedent); assoc.setDependent(dependent); assoc.setPriority(priority); return assoc; }
/** * @param association * @param affectedSOPClass * @param affectedSOPInstance * @param inputTransferSyntaxUID * @param din * @param presentationContextID * @param outputTransferSyntaxUID * @exception IOException * @exception DicomException * @exception DicomNetworkException * @exception AReleaseException */ protected boolean sendOneSOPInstance( Association association, String affectedSOPClass, String affectedSOPInstance, String inputTransferSyntaxUID, DicomInputStream din, byte presentationContextID, String outputTransferSyntaxUID) throws AReleaseException, DicomNetworkException, DicomException, IOException { CStoreResponseHandler receivedDataHandler = new CStoreResponseHandler(debugLevel); association.setReceivedDataHandler(receivedDataHandler); if (inputTransferSyntaxUID.equals(outputTransferSyntaxUID)) { // din will already be positioned after meta-header and set for reading data set byte[] data = null; byte[] b = new byte[32768]; while (true) { int bytesReceived = din.read(b, 0, 32768); if (bytesReceived == -1) { break; } else if (bytesReceived > 0) { if (data == null) { data = new byte[bytesReceived]; System.arraycopy(b, 0, data, 0, bytesReceived); } else { data = ByteArray.concatenate(data, 0, data.length, b, 0, bytesReceived); } } } byte cStoreRequestCommandMessage[] = new CStoreRequestCommandMessage(affectedSOPClass, affectedSOPInstance).getBytes(); association.send(presentationContextID, cStoreRequestCommandMessage, data); } else { throw new DicomException("Must be the same transfer syntax"); } if (debugLevel > 1) System.err.println( new java.util.Date().toString() + ": TestSendingCommandAndDataInOnePDU.sendOneSOPInstance(): about to wait for PDUs"); association.waitForCommandPDataPDUs(); return receivedDataHandler.wasSuccessful(); }
@Override protected void deleteEntity(PersistentEntity pe, Object obj) { EntityAccess entityAccess = createEntityAccess(pe, obj); if (cancelDelete(pe, entityAccess)) { return; } for (Association association : pe.getAssociations()) { if (association.isOwningSide() && association.doesCascade(CascadeType.REMOVE)) { log.debug("cascading delete for property " + association.getName()); GraphPersistentEntity otherPersistentEntity = (GraphPersistentEntity) association.getAssociatedEntity(); Object otherSideValue = entityAccess.getProperty(association.getName()); if (association instanceof ToOne) { deleteEntity(otherPersistentEntity, otherSideValue); } else { deleteEntities(otherPersistentEntity, (Iterable) otherSideValue); } } } getCypherEngine() .execute( String.format( "MATCH (n:%s) WHERE n.__id__={id} OPTIONAL MATCH (n)-[r]-() DELETE r,n", ((GraphPersistentEntity) pe).getLabel()), Collections.singletonMap("id", entityAccess.getIdentifier())); firePostDeleteEvent(pe, entityAccess); }
/** * Checks whether the given assocation already existed in Windows registry. * * <PRE> * The evaluation will based on the following rule: * 1. mimetype == null && fileExt == null * return false * 2. mimetype == null && fileExt != null * return !(fileExt existed in the reg table) * 3. mimetype != null && fileExt == null * return !(mimetype existed in the reg table) * 4. mimetype != null && fileExt != null * return ( (mimetype existed in the reg table) && * (fileExt existed in the reg table) && * (getFileExtByMimeType(mimetype) == fileExt) && * (getMimeTypeByFileExt(fileExt) == mimetype) ) * </PRE> * * @param assoc given association (not null) * @param regLevel given registry level * @return true if the given association existed */ public boolean isAssociationExist(Association assoc, int regLevel) { String temFileExt = null; String temMimeType = assoc.getMimeType(); Iterator<String> temFileExtIter; if (assoc.getFileExtList() != null) { temFileExtIter = assoc.getFileExtList().iterator(); } else { temFileExtIter = null; } if (temFileExtIter != null) { if (temFileExtIter.hasNext()) { temFileExt = (String) temFileExtIter.next(); } } // Check if there is the same file extension define in Win2k // HKEY_CURRENT_USER\\software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts if (WinRegistryUtil.isWin2kUserDefinedFileExtExist(temFileExt)) { return true; } if ((temMimeType == null) && (temFileExt == null)) { return false; } else if ((temMimeType == null) && (temFileExt != null)) { return WinRegistryUtil.isFileExtExist(temFileExt, regLevel); } else if ((temMimeType != null) && (temFileExt == null)) { return WinRegistryUtil.isMimeTypeExist(temMimeType, regLevel); } else { String regMimeType = WinRegistryUtil.getMimeTypeByFileExt(temFileExt, regLevel); String regFileExt = WinRegistryUtil.getFileExtByMimeType(temMimeType, regLevel); return ((WinRegistryUtil.isMimeTypeExist(temMimeType, regLevel)) && (WinRegistryUtil.isFileExtExist(temFileExt, regLevel)) && (temFileExt == null ? regFileExt == null : temFileExt.equals(regFileExt)) && (temMimeType == null ? regMimeType == null : temMimeType.equals(regMimeType))); } }
R_result(AbstractCollection c, int items, boolean rules) { Iterator it; this.rules = rules; if (rules) { // split rules into two collections Vector lhsVec = new Vector(c.size()); Vector rhsVec = new Vector(c.size()); Rule rule; it = c.iterator(); while (it.hasNext()) { rule = (Rule) it.next(); lhsVec.add(rule.getLhs()); rhsVec.add(rule.getRhs()); } lhs = new SparseSetOfItemsets(lhsVec, items); rhs = new SparseSetOfItemsets(rhsVec, items); } else { this.items = new SparseSetOfItemsets(c, items); } // get precision precision = new double[c.size()]; Association set; it = c.iterator(); int ps = 0; while (it.hasNext()) { // I hope the iterator uses the same order set = (Association) it.next(); precision[ps] = set.getPrecision(); ps++; } }
/** PUBLIC: Set the class indicator associations. */ public void setClassIndicatorAssociations(Vector classIndicatorAssociations) { setTypeIndicatorNameTranslation(new HashMap(classIndicatorAssociations.size() + 1)); setTypeIndicatorTranslation(new HashMap((classIndicatorAssociations.size() * 2) + 1)); for (Enumeration associationsEnum = classIndicatorAssociations.elements(); associationsEnum.hasMoreElements(); ) { Association association = (Association) associationsEnum.nextElement(); Object classValue = association.getKey(); if (classValue instanceof Class) { // 904 projects will be a class type. addClassIndicator((Class) association.getKey(), association.getValue()); } else { addClassNameIndicator((String) association.getKey(), association.getValue()); } } }
public Association connect(Connection local, Connection remote, AAssociateRQ rq) throws IOException, InterruptedException, IncompatibleConnectionException, GeneralSecurityException { checkDevice(); checkInstalled(); if (rq.getCallingAET() == null) rq.setCallingAET(AETitle); rq.setMaxOpsInvoked(local.getMaxOpsInvoked()); rq.setMaxOpsPerformed(local.getMaxOpsPerformed()); rq.setMaxPDULength(local.getReceivePDULength()); final Socket sock = local.connect(remote); // automatically closes the socket in case an exception is thrown Association as; try { as = new Association(this, local, sock); } catch (final IOException e) { LOG.warn("Failed to open new association, will close underlying socket"); local.close(sock); throw e; } try { as.write(rq); as.waitForLeaving(State.Sta5); } catch (final IOException e) { LOG.warn("{}: Failed to write A-ASSOCIATE-RQ, will abort association", as.toString()); as.abort(); throw e; } catch (final InterruptedException e) { LOG.warn( "{}: Interrupted while waiting to leave state Sta 5, will abort association", as.toString()); as.abort(); throw e; } return as; }
private static void parseConfiguration(String stringUrl, Product product) { try { URL url = new URL(stringUrl); URLConnection connection = url.openConnection(); int fileLength = connection.getContentLength(); if (fileLength == -1) { System.out.println("Invalide URL or file."); return; } CommandClass currentCC = null; Parameter currentParameter = null; Association currentAssociation = null; XMLInputFactory inputFactory = XMLInputFactory.newInstance(); InputStream input = connection.getInputStream(); final XMLEventReader eventReader = inputFactory.createXMLEventReader(input); while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); if (event.isStartElement()) { StartElement startElt = event.asStartElement(); if (startElt.getName().getLocalPart().equals("CommandClass")) { CommandClass cc = product.view().createCommandClass(); Iterator<Attribute> attributes = startElt.getAttributes(); while (attributes.hasNext()) { Attribute next = attributes.next(); String attrName = next.getName().toString(); if (attrName.equals("id")) { cc.setId(Integer.parseInt(next.getValue(), 16)); } } product.addCommandClasses(cc); currentCC = cc; } else if (startElt.getName().getLocalPart().equals("Value")) { Parameter param = product.view().createParameter(); Iterator<Attribute> attributes = startElt.getAttributes(); while (attributes.hasNext()) { Attribute next = attributes.next(); String attrName = next.getName().toString(); if (!next.getValue().equals("")) { if (attrName.equals("type")) { param.setType(ParameterType.valueOf(next.getValue().toUpperCase())); } else if (attrName.equals("genre")) { param.setGenre(next.getValue()); } else if (attrName.equals("instance")) { param.setInstance(Integer.valueOf(next.getValue())); } else if (attrName.equals("index")) { param.setIndex(Integer.valueOf(next.getValue())); } else if (attrName.equals("label")) { param.setLabel(next.getValue()); } else if (attrName.equals("value")) { param.setValue(next.getValue()); } else if (attrName.equals("min")) { param.setMin(Integer.valueOf(next.getValue())); } else if (attrName.equals("max")) { param.setMax(Integer.valueOf(next.getValue())); } else if (attrName.equals("size")) { param.setSize(Integer.valueOf(next.getValue())); } } } currentCC.addParameters(param); currentParameter = param; } else if (startElt.getName().getLocalPart().equals("Help")) { // help } else if (startElt.getName().getLocalPart().equals("Item")) { ParameterItem item = product.view().createParameterItem(); Iterator<Attribute> attributes = startElt.getAttributes(); while (attributes.hasNext()) { Attribute next = attributes.next(); String attrName = next.getName().toString(); if (attrName.equals("label")) { item.setLabel(next.getValue()); } else if (attrName.equals("value")) { item.setValue(Integer.valueOf(next.getValue())); } } currentParameter.addItems(item); } else if (startElt.getName().getLocalPart().equals("Associations")) { Association assoc = product.view().createAssociation(); Iterator<Attribute> attributes = startElt.getAttributes(); while (attributes.hasNext()) { Attribute next = attributes.next(); String attrName = next.getName().toString(); if (attrName.equals("num_groups")) { assoc.setNumGroups(Integer.valueOf(next.getValue())); } } currentCC.addAssociations(assoc); currentAssociation = assoc; } else if (startElt.getName().getLocalPart().equals("Group")) { AssociationGroup group = product.view().createAssociationGroup(); Iterator<Attribute> attributes = startElt.getAttributes(); while (attributes.hasNext()) { Attribute next = attributes.next(); String attrName = next.getName().toString(); if (attrName.equals("label")) { group.setLabel(next.getValue()); } else if (attrName.equals("index")) { group.setIndex(Integer.valueOf(next.getValue())); } else if (attrName.equals("max_associations")) { group.setMaxAssociations(Integer.valueOf(next.getValue())); } else if (attrName.equals("auto")) { group.setAuto(Boolean.valueOf(next.getValue())); } currentAssociation.addGroups(group); } } } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public void clearInit(final Payment.Association... associations) { if (associations == null) throw new IllegalArgumentException(); for (Association association : associations) initAssociations.remove(association.name()); }
/** * This method create an Association of the type LogicalIdentity between one ManagedElement object * and ManagedElement object */ public static LogicalIdentity link(ManagedElement systemElement, ManagedElement sameElement) { return (LogicalIdentity) Association.link(LogicalIdentity.class, systemElement, sameElement); } // link
private void persistAssociationsOfEntity( PersistentEntity pe, EntityAccess entityAccess, boolean isUpdate) { Object obj = entityAccess.getEntity(); DirtyCheckable dirtyCheckable = null; if (obj instanceof DirtyCheckable) { dirtyCheckable = (DirtyCheckable) obj; } for (PersistentProperty pp : pe.getAssociations()) { if ((!isUpdate) || ((dirtyCheckable != null) && dirtyCheckable.hasChanged(pp.getName()))) { Object propertyValue = entityAccess.getProperty(pp.getName()); if ((pp instanceof OneToMany) || (pp instanceof ManyToMany)) { Association association = (Association) pp; if (propertyValue != null) { if (association.isBidirectional()) { // Populate other side of bidi for (Object associatedObject : (Iterable) propertyValue) { EntityAccess assocEntityAccess = createEntityAccess(association.getAssociatedEntity(), associatedObject); assocEntityAccess.setProperty(association.getReferencedPropertyName(), obj); } } Iterable targets = (Iterable) propertyValue; persistEntities(association.getAssociatedEntity(), targets); boolean reversed = RelationshipUtils.useReversedMappingFor(association); if (!reversed) { if (!(propertyValue instanceof LazyEnititySet)) { LazyEnititySet les = new LazyEnititySet( entityAccess, association, getMappingContext().getProxyFactory(), getSession()); les.addAll(targets); entityAccess.setProperty(association.getName(), les); } } } } else if (pp instanceof ToOne) { if (propertyValue != null) { ToOne to = (ToOne) pp; if (to.isBidirectional()) { // Populate other side of bidi EntityAccess assocEntityAccess = createEntityAccess(to.getAssociatedEntity(), propertyValue); if (to instanceof OneToOne) { assocEntityAccess.setProperty(to.getReferencedPropertyName(), obj); } else { Collection collection = (Collection) assocEntityAccess.getProperty(to.getReferencedPropertyName()); if (collection == null) { collection = new ArrayList(); assocEntityAccess.setProperty(to.getReferencedPropertyName(), collection); } if (!collection.contains(obj)) { collection.add(obj); } } } persistEntity(to.getAssociatedEntity(), propertyValue); boolean reversed = RelationshipUtils.useReversedMappingFor(to); String relType = RelationshipUtils.relationshipTypeUsedFor(to); if (!reversed) { getSession() .addPendingInsert( new RelationshipPendingInsert( entityAccess, relType, new EntityAccess(to.getAssociatedEntity(), propertyValue), getCypherEngine())); } } } else { throw new IllegalArgumentException( "wtf don't know how to handle " + pp + "(" + pp.getClass() + ")"); } } } }
/** * This method create an Association of the type FilterListInSystem between one ComputerSystem * object and FilterList object */ @Deprecated public static FilterListInSystem link(ComputerSystem groupComponent, FilterList partComponent) { return (FilterListInSystem) Association.link(FilterListInSystem.class, groupComponent, partComponent); } // link
public void cancel(Association as) throws IOException { as.cancel(pc, msgId); }
/** * This method create an Association of the type BindsTo between one ProtocolEndpoint object and * ServiceAccessPoint object */ public static BindsTo link(ProtocolEndpoint antecedent, ServiceAccessPoint dependent) { return (BindsTo) Association.link(BindsTo.class, antecedent, dependent); } // link
/** * Registers the given association info in the specified level. * * <PRE> * * The register process will following the rules below * 1. mimetype == null && fileExt != null * Since fileExt does not exist in this case * 1.1 adds the fileExt * 1.2 adds description, icon file and action list for this fileExt * 2. mimetype != null && fileExt == null * Since mimetype does not exist in this case * just adds the mimetype in the reg table * 3. mimetype != null && fileExt != null * 3.1 Adds the mime type into the reg table if necessary * 3.2 Adds the file extension into the reg table if necessary * 3.3 Adds the description, icon file and action list for the fileExt * 3.4 Sets the mutual reference of the mime type and file extension * </PRE> * * @param assoc given association (not null) * @param regLevel given registry level * @throws RegisterFailedException if the operation fails. */ public void registerAssociation(Association assoc, int regLevel) throws RegisterFailedException { // LOCAL_MACHINE. Association, in this case, should only be written into LOCAL_MACHINE rather // than the CURRENT_USER. boolean isOldWindows = false; String osName = System.getProperty("os.name").toLowerCase(); if ((osName.indexOf("98") != -1) || (osName.indexOf("me") != -1) || (osName.indexOf("nt") != -1)) { isOldWindows = true; } if (isOldWindows) { regLevel = AppConstants.SYSTEM_LEVEL; } BackupAssociation backupAssoc = new BackupAssociation(assoc, regLevel); String curMimeType = backupAssoc.getCurMimeType(); String curFileExt = backupAssoc.getCurFileExt(); String curDescription = assoc.getDescription(); String curIconFileName = assoc.getIconFileName(); List<Action> curActionList = assoc.getActionList(); boolean curMimeTypeExisted = backupAssoc.getCurMimeTypeExisted(); boolean curFileExtExisted = backupAssoc.getCurFileExtExisted(); try { if ((curMimeType == null) && (curFileExt != null)) { WinRegistryUtil.addFileExt(curFileExt, regLevel); if (curDescription != null) { WinRegistryUtil.setDescriptionByFileExt(curDescription, curFileExt, regLevel); } if (curIconFileName != null) { WinRegistryUtil.setIconFileNameByFileExt(curIconFileName, curFileExt, regLevel); } if (curActionList != null) { WinRegistryUtil.setActionListByFileExt(curActionList, curFileExt, regLevel); } // Mark the classID generator field WinRegistryUtil.markGeneratorByFileExt(curFileExt, regLevel); } else if ((curMimeType != null) && (curFileExt == null)) { WinRegistryUtil.addMimeType(curMimeType, regLevel); } else if ((curMimeType != null) && (curFileExt != null)) { if (!curMimeTypeExisted) { WinRegistryUtil.addMimeType(curMimeType, regLevel); } if (!curFileExtExisted) { WinRegistryUtil.addFileExt(curFileExt, regLevel); } if (curDescription != null) { WinRegistryUtil.setDescriptionByFileExt(curDescription, curFileExt, regLevel); } if (curIconFileName != null) { WinRegistryUtil.setIconFileNameByFileExt(curIconFileName, curFileExt, regLevel); } if (curActionList != null) { WinRegistryUtil.setActionListByFileExt(curActionList, curFileExt, regLevel); } // Mark the classID generator field. WinRegistryUtil.markGeneratorByFileExt(curFileExt, regLevel); WinRegistryUtil.setMutualRef(curFileExt, curMimeType, regLevel); } } catch (RegisterFailedException e) { restoreAssociationRegistration(backupAssoc, regLevel); throw e; } }
/** * Returns the firsts Association from fromAssociations that have the ManagedElement element as * "from" element * * @param element that represents the "from" * @return Association that have I as a "to" and the element as "from" */ public Association getFromAssociationByElement(ManagedElement element) { for (Association assoc : fromAssociations) if (assoc.getFrom().equals(element)) return assoc; return null; }
/** * This method create an Association of the type ReflectorService between one BGPCluster object * and BGPService object */ public static ReflectorService link(BGPCluster antecedent, BGPService dependent) { return (ReflectorService) Association.link(ReflectorService.class, antecedent, dependent); } // link
/** * This method create an Association of the type PortImplementsEndpoint between one LogicalPort * object and ProtocolEndpoint object */ public static PortImplementsEndpoint link(LogicalPort antecedent, ProtocolEndpoint dependent) { return (PortImplementsEndpoint) Association.link(PortImplementsEndpoint.class, antecedent, dependent); } // link