/** * Create serializer instance with inband type information. * * @param includeClass always true to include class name before serialized value. * @throws IllegalArgumentException if <code>includeClass</code> is not true. */ public Serializer(boolean includeClass) throws IllegalArgumentException { Params.isTrue(includeClass, "Include class flag should always be true."); this.includeClass = includeClass; }
@Override public Element setAttrs(String... nameValuePairs) { Params.isTrue(nameValuePairs.length % 2 == 0, "Missing value for last attribute."); for (int i = 0, l = nameValuePairs.length - 1; i < l; i += 2) { Params.notNull(nameValuePairs[i + 1], "Attribute value"); node.setAttribute(nameValuePairs[i], nameValuePairs[i + 1]); } return this; }
@Override public Element createElement(String tagName, String... attrNameValues) { Params.notNullOrEmpty(tagName, "Tag name"); Params.isTrue(attrNameValues.length % 2 == 0, "Missing value for last attribute."); Element el = getElement(doc.createElement(tagName)); if (attrNameValues.length > 0) { el.setAttrs(attrNameValues); } return el; }
@Override public Element importElement(Element el) { Params.notNull(el, "Element"); Params.isTrue(el.getDocument() != this, "Element already belongs to this document."); return getElement(doc.importNode(((ElementImpl) el).getNode(), true)); }
@Override public <T> T getRemoteInstance(String implementationURL, Class<? super T> interfaceClass) { Params.notNull(implementationURL, "Implementation URL"); Params.notNull(interfaceClass, "Interface class"); Params.isTrue(interfaceClass.isInterface(), "Interface class argument is not actually an interface."); InstanceFactory instanceFactory = instanceFactories.get(InstanceType.REMOTE); if (instanceFactory == null) { throw new BugError("No REMOTE instance factory registered."); } if (!(instanceFactory instanceof RemoteFactory)) { throw new BugError("Invalid REMOTE instance factory provider. Does not implement %s interface.", RemoteFactory.class); } return ((RemoteFactory) instanceFactory).getRemoteInstance(implementationURL, interfaceClass); }
/** * Construct transactional proxy invocation handler for given managed instance. * * @param transactionalResource transactional resource, * @param managedClass managed class, * @param managedInstance instance of managed class. * @throws IllegalArgumentException if <code>managedClass</code> is null or not transactional or * <code>managedInstance</code> is null. */ public ManagedProxyHandler(TransactionalResource transactionalResource, ManagedClassSPI managedClass, Object managedInstance) { Params.notNull(managedClass, "Managed class"); if (transactionalResource != null) { Params.isTrue(managedClass.isTransactional(), "Managed class is not transactional"); } Params.notNull(managedInstance, "Managed instance"); this.transactionalResource = transactionalResource; this.managedClass = managedClass; this.managedInstance = managedInstance; }