/* * (non-Javadoc) * * @see ca.unb.cs.pcsf.db.DBAccessService#getCreatorById(java.lang.String) */ public Creator getCreatorById(String id) { logger.debug(LOGPRE + "getCreatorById() start" + LOGPRE); Creator creator = new Creator(); String selectRequest = "select * from `" + DOMAIN_CREATOR + "`"; List<Item> items = this.getDataFromDomain(selectRequest); Item findItem = new Item(); if (!items.isEmpty()) { for (Item item : items) { if (item.getName().equals(id)) { findItem = item; break; } } } if (findItem != null) { creator.setId(findItem.getName()); for (Attribute attribute : findItem.getAttributes()) { if (attribute.getName().equals(CREATOR_ATTRIBUTE_NAME)) creator.setName(attribute.getValue()); if (attribute.getName().equals(CREATOR_ATTRIBUTE_PASSWORD)) creator.setPassword(attribute.getValue()); if (attribute.getName().equals(CREATOR_ATTRIBUTE_EMAIL)) creator.setEmail(attribute.getValue()); } } logger.debug(LOGPRE + "getCreatorById() end" + LOGPRE); return creator; }
/* * (non-Javadoc) * * @see ca.unb.cs.pcsf.db.DBAccessService#getCreatorByName(java.lang.String) */ public Creator getCreatorByName(String userName) { logger.debug(LOGPRE + "getCreatorByName() start" + LOGPRE); Creator creator = new Creator(); String selectRequest = "select * from `" + DOMAIN_CREATOR + "` where " + CREATOR_ATTRIBUTE_NAME + " = '" + userName + "'"; Item item = this.getDataFromDomain(selectRequest).get(0); creator.setId(item.getName()); for (Attribute attribute : item.getAttributes()) { if (attribute.getName().equals(CREATOR_ATTRIBUTE_NAME)) creator.setName(attribute.getValue()); if (attribute.getName().equals(CREATOR_ATTRIBUTE_PASSWORD)) creator.setPassword(attribute.getValue()); if (attribute.getName().equals(CREATOR_ATTRIBUTE_EMAIL)) creator.setEmail(attribute.getValue()); } logger.debug(LOGPRE + "getCreatorByName() end" + LOGPRE); return creator; }
private Object replace(Class<?> type, ApplicableGenerator generator, boolean alternative) { for (Creator<?> creator : creators) { ParameterizedType generic = (ParameterizedType) creator.getClass().getGenericInterfaces()[0]; Class<?> restrained = generic.getActualTypeArguments()[0] instanceof ParameterizedType ? (Class<?>) ((ParameterizedType) generic.getActualTypeArguments()[0]).getRawType() : (Class<?>) generic.getActualTypeArguments()[0]; if (type.isAssignableFrom(restrained)) { return creator.create(); } } return generator.generate(type, alternative); }
public List<I> create(M queryResult) { List<I> result = new ArrayList<I>(); while (hasNext(queryResult)) { result.add(creator.create(next(queryResult))); } return result; }
/** * This is used to ensure that final methods and fields have a constructor parameter that allows * the value to be injected in to. Validating the constructor in this manner ensures that the * class schema remains fully serializable and deserializable. * * @param label this is the variable to check in constructors * @param list this is the list of builders to validate */ private void validateConstructor(Label label, List<Creator> list) throws Exception { Iterator<Creator> iterator = list.iterator(); while (iterator.hasNext()) { Creator instantiator = iterator.next(); Signature signature = instantiator.getSignature(); Contact contact = label.getContact(); Object key = label.getKey(); if (contact.isReadOnly()) { Parameter value = signature.get(key); if (value == null) { iterator.remove(); } } } }
@SuppressWarnings({"rawtypes", "unchecked"}) public static void main(String[] args) { Creator[] creators = { new ConcreteCreatorA(), new ConcreteCreatorB(), }; for (Creator creator : creators) { Product product = creator.create(); System.out.println("Created " + product.getClass().getSimpleName()); } ParametricCreator pcreator = new ParametricCreator(); ProductId[] productIds = {ProductId.ProductA, ProductId.ProductB}; for (ProductId productId : productIds) { Product product = pcreator.create(productId); System.out.println("Created " + product.getClass().getSimpleName()); } Class[] types = {ConcreteProductA.class, ConcreteProductB.class}; for (Class type : types) { GenericCreator.type = type; Product product = GenericCreator.create(); System.out.println("Created " + product.getClass().getSimpleName()); } }
/** * Populates a list and discards the internal state of the ParceledListSlice in the process. The * instance should not be used anymore. * * @param list list to insert items from this slice. * @param creator creator that knows how to unparcel the target object type. * @return the last item inserted into the list or null if none. */ @DSGenerator( tool_name = "Doppelganger", tool_version = "2.0", generated_on = "2013-12-30 12:34:55.748 -0500", hash_original_method = "C11B1153BF8BCDA44C4073AC785F824F", hash_generated_method = "31DE1676A7D3BC3BC9911CB72FB32E4D") public T populateList(List<T> list, Creator<T> creator) { mParcel.setDataPosition(0); T item = null; for (int i = 0; i < mNumItems; i++) { item = creator.createFromParcel(mParcel); list.add(item); } mParcel.recycle(); mParcel = null; return item; }
@Override public void run() { BotAIManagement.getLogger() .debug( "Processing packet " + "({}): {}", (InetSocketAddress) mRecievedDatagramPacket.getSocketAddress(), new String(mRecievedDatagramPacket.getData(), 0, mRecievedDatagramPacket.getLength())); BotAI aCorrespondingBotAI = BotAIManagement.getInstance() .getMapOfBotAIs() .get(mRecievedDatagramPacket.getSocketAddress()); if (aCorrespondingBotAI != null) { aCorrespondingBotAI.processDatagrammPacket(mRecievedDatagramPacket); } else { Creator.putUnkownSenderDatagramInProcessingQueue( new UnkownBotAI(mBotAIConnect, mRecievedDatagramPacket)); } }
public void writeToParcel(Parcel parcel, int flags) { CREATOR.writeToParcel(this, parcel, flags); }
public static void main(String[] args) { Creator creator = new ConcreteCreatorA(); Product product = creator.factoryMethod(); product.show(); }
/* * (non-Javadoc) * * @see ca.unb.cs.pcsf.db.DBAccessService#putDataIntoDomain(java.lang.Object) */ public void putDataIntoDomain(Object object) { logger.debug(LOGPRE + "putDataIntoDomain() start" + LOGPRE); if (object instanceof Participant) { Participant participant = (Participant) object; List<ReplaceableItem> items = new ArrayList<ReplaceableItem>(); items.add( new ReplaceableItem(participant.getId()) .withAttributes( new ReplaceableAttribute(PARTICIPANT_ATTRIBUTE_NAME, participant.getName(), true), new ReplaceableAttribute( PARTICIPANT_ATTRIBUTE_EMAIL, participant.getEmail(), true), new ReplaceableAttribute( PARTICIPANT_ATTRIBUTE_COLLABORATION_ID, participant.getCollaborationId(), false), new ReplaceableAttribute( PARTICIPANT_ATTRIBUTE_IS_REG, participant.getIsReg(), true))); logger.info("Putting participant <" + participant.getName() + "> into domain..."); sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_PARTICIPANT, items)); } if (object instanceof Creator) { Creator creator = (Creator) object; if (!isCreatorExist(creator.getName())) { List<ReplaceableItem> items = new ArrayList<ReplaceableItem>(); items.add( new ReplaceableItem(creator.getId()) .withAttributes( new ReplaceableAttribute(CREATOR_ATTRIBUTE_NAME, creator.getName(), true), new ReplaceableAttribute( CREATOR_ATTRIBUTE_PASSWORD, creator.getPassword(), true), new ReplaceableAttribute(CREATOR_ATTRIBUTE_EMAIL, creator.getEmail(), true))); logger.info("Putting creator <" + creator.getName() + "> into domain..."); sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_CREATOR, items)); } } if (object instanceof Collaboration) { Collaboration collaboration = (Collaboration) object; if (!isCollaborationExist(collaboration.getName())) { List<ReplaceableItem> items = new ArrayList<ReplaceableItem>(); ReplaceableItem item = new ReplaceableItem(collaboration.getId()); item.withAttributes( new ReplaceableAttribute(COLLABORATION_ATTRIBUTE_NAME, collaboration.getName(), true), new ReplaceableAttribute( COLLABORATION_ATTRIBUTE_CREATOR_ID, collaboration.getCreatorId(), true), new ReplaceableAttribute( COLLABORATION_ATTRIBUTE_CURRENT_STATE, collaboration.getCurrentState(), true), new ReplaceableAttribute( COLLABORATION_ATTRIBUTE_WORKFLOW_MODEL, collaboration.getWorkflowModel(), true)); List<Participant> participants = collaboration.getParticipants(); for (Participant participant : participants) item.withAttributes( new ReplaceableAttribute( COLLABORATION_ATTRIBUTE_PARTICIPANT, participant.getName(), true)); items.add(item); logger.info("Putting collaboration <" + collaboration.getName() + "> into domain..."); sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_COLLABORATION, items)); } } logger.debug(LOGPRE + "putDataIntoDomain() end" + LOGPRE); }
/** * Shows a working of "factory method" pattern. * * @param args command-line arguments */ public static void main(String[] args) { Creator creator = new ConcreteCreator(); Element element = creator.create(); }