Beispiel #1
0
        public static List<description> mapdescription(String content, String lang)
        {
            List<description> ret = new List<description>();
            if (String.IsNullOrEmpty(content))
            {
                return ret;
            }
            if (content.Length > UDDIConstants.MAX_description_length)
            {
                int offset = 0;
                while (offset < content.Length)
                {
                    description description = new description();
                    description.lang = (lang);
                    int len =  UDDIConstants.MAX_description_length;
                    if (len > content.Length-offset)
                    {
                        len = content.Length -offset;
                    }

                    description.Value = (content.Substring(offset, len));
                    offset = offset + UDDIConstants.MAX_description_length;
                    ret.Add(description);

                }
            }
            else
            {
                ret.Add(new description(content, lang));
            }
            return ret;
        }
        public void xr_overviewDoc()
        {
            Console.Out.WriteLine("serialization xr_overviewDoc");
            overviewDoc r = new overviewDoc();
            description d = new description("v", "en");
            overviewURL ol = new overviewURL("http://url", "website");

            r.overviewURLs = new overviewURL[] { ol };
            r.descriptions = new description[] { d };
            XmlSerializer xr = new XmlSerializer(typeof(overviewDoc));
            StringWriter sw = new StringWriter();
            xr.Serialize(sw, r);
            System.Console.Out.WriteLine(sw.ToString());
        }
        public businessService readServiceAnnotations(String classWithAnnotations, Properties properties)
        {
            Type t = Type.GetType(classWithAnnotations, false, true);
            if (t != null)
            {
                businessService service = new businessService();
                object[] attrib = t.GetCustomAttributes(typeof(UDDIService), true);

                object[] ws = t.GetCustomAttributes(typeof(System.Web.Services.WebServiceBindingAttribute), true);
                WebServiceBindingAttribute webServiceAnnotation = null;
                if (ws != null && ws.Length > 0)
                {
                    webServiceAnnotation = ((WebServiceBindingAttribute[])ws)[0];
                }
                if (attrib != null && attrib.Length > 0)
                {

                    UDDIService[] bits = attrib as UDDIService[];
                    UDDIService uddiService = bits[0];
                    name n = new name();
                    n.lang = uddiService.lang;
                    service.businessKey = (TokenResolver.replaceTokens(uddiService.businessKey, properties));
                    service.serviceKey = (TokenResolver.replaceTokens(uddiService.serviceKey, properties));
                    if (!"".Equals(uddiService.serviceName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        n.Value = (TokenResolver.replaceTokens(uddiService.serviceName, properties));
                    }
                    else if (webServiceAnnotation != null && !"".Equals(webServiceAnnotation.Name))
                    {
                        n.Value = (webServiceAnnotation.Name);
                    }
                    else
                    {
                        n.Value = (classWithAnnotations);
                    }
                    service.name = new name[] { n };
                    description d = new description();
                    d.lang = (uddiService.lang);
                    d.Value = (TokenResolver.replaceTokens(uddiService.description, properties));
                    service.description = new description[] { d };

                    //categoryBag on the service
                    if (!"".Equals(uddiService.categoryBag))
                    {
                        categoryBag categoryBag = parseCategoryBag(uddiService.categoryBag);
                        service.categoryBag = (categoryBag);
                    }

                    //bindingTemplate on service
                    bindingTemplate bindingTemplate = parseServiceBinding(classWithAnnotations, uddiService.lang, webServiceAnnotation, properties);
                    if (bindingTemplate != null)
                    {
                        bindingTemplate.serviceKey = (service.serviceKey);
                        if (service.bindingTemplates == null)
                        {
                            service.bindingTemplates = new bindingTemplate[] { bindingTemplate };
                        }
                        else
                        {
                            List<bindingTemplate> l = new List<bindingTemplate>();
                            l.AddRange(service.bindingTemplates);
                            l.Add(bindingTemplate);
                            service.bindingTemplates = l.ToArray();
                        }
                    }

                    return service;
                }
                else
                {
                    log.error("Missing UDDIService annotation in class " + classWithAnnotations);
                }
            }
            log.error("Unable to load type " + classWithAnnotations);
            return null;
        }
        private bindingTemplate parseServiceBinding(string classWithAnnotations, string lang, WebServiceBindingAttribute webServiceAnnotation, Properties properties)
        {
            bindingTemplate bindingTemplate = null;
            Type t = Type.GetType(classWithAnnotations, false, false);
            UDDIServiceBinding uddiServiceBinding = null;
            object[] attrib = t.GetCustomAttributes(typeof(UDDIServiceBinding), true);
            if (attrib != null && attrib.Length > 0)
                uddiServiceBinding = attrib[0] as UDDIServiceBinding;

            //= (UDDIServiceBinding) classWithAnnotations.getAnnotation(UDDIServiceBinding.class);
            //binding
            if (uddiServiceBinding != null)
            {
                bindingTemplate = new bindingTemplate();

                bindingTemplate.bindingKey = (TokenResolver.replaceTokens(uddiServiceBinding.bindingKey, properties));

                String bindingLang = (lang);
                if (uddiServiceBinding.lang != null)
                {
                    bindingLang = TokenResolver.replaceTokens(uddiServiceBinding.lang, properties);
                }
                description bindingDescription = new description();
                bindingDescription.lang = (bindingLang);
                bindingDescription.Value = (TokenResolver.replaceTokens(uddiServiceBinding.description, properties));
                bindingTemplate.description = new description[] { (bindingDescription) };

                accessPoint accessPoint = new accessPoint();
                accessPoint.useType = (AccessPointType.wsdlDeployment.ToString());
                if (!"".Equals(uddiServiceBinding.accessPointType))
                {
                    accessPoint.useType = (uddiServiceBinding.accessPointType);
                }
                if (!"".Equals(uddiServiceBinding.accessPoint))
                {
                    String endPoint = uddiServiceBinding.accessPoint;
                    endPoint = TokenResolver.replaceTokens(endPoint, properties);
                    log.debug("AccessPoint EndPoint=" + endPoint);
                    accessPoint.Value = (endPoint);
                }
                else if (webServiceAnnotation != null && webServiceAnnotation.Location != null)
                {
                    accessPoint.Value = (webServiceAnnotation.Location);
                }
                bindingTemplate.Item = (accessPoint);

                //tModelKeys on the binding
                if (!"".Equals(uddiServiceBinding.tModelKeys))
                {
                    String[] tModelKeys = uddiServiceBinding.tModelKeys.Split(',');
                    foreach (String tModelKey in tModelKeys)
                    {
                        tModelInstanceInfo instanceInfo = new tModelInstanceInfo();
                        instanceInfo.tModelKey = (tModelKey);
                        if (bindingTemplate.tModelInstanceDetails == null)
                        {
                            bindingTemplate.tModelInstanceDetails = (new tModelInstanceInfo[] { instanceInfo });
                        }
                        List<tModelInstanceInfo> l = new List<tModelInstanceInfo>();
                        l.AddRange(bindingTemplate.tModelInstanceDetails);
                        l.Add(instanceInfo);
                        bindingTemplate.tModelInstanceDetails = l.ToArray();

                    }
                }
                //categoryBag on the binding
                if (!"".Equals(uddiServiceBinding.categoryBag))
                {
                    categoryBag categoryBag = parseCategoryBag(uddiServiceBinding.categoryBag);
                    bindingTemplate.categoryBag = (categoryBag);
                }
            }
            else
            {
                log.error("Missing UDDIServiceBinding annotation in class " + classWithAnnotations);
            }
            return bindingTemplate;
        }
Beispiel #5
0
        /**
         * Creates a UDDI Business Service.
         *
         * @param serviceQName This must be specified to identify the namespace of
         * the service, which is used to set the service uddi key
         * @param waldDefinition
         * @return
         */
        public businessService createBusinessService(QName serviceQName, application wadlDefinition)
        {
            log.debug("Constructing Service UDDI Information for " + serviceQName);
            businessService service = new businessService();
            // BusinessKey
            service.businessKey = (businessKey);
            // ServiceKey
            service.serviceKey = (UDDIKeyConvention.getServiceKey(properties, serviceQName.getLocalPart()));
            // Description
            String serviceDescription = properties.getProperty(Property.SERVICE_DESCRIPTION, Property.DEFAULT_SERVICE_DESCRIPTION);
            // Override with the service description from the WSDL if present
            bool lengthwarn = false;
            List<description> ds = new List<description>();
            if (wadlDefinition.doc != null)
            {

                for (int i = 0; i < wadlDefinition.doc.Length; i++)
                {

                    String locallang = lang;
                    description description = new description();
                    if (wadlDefinition.doc[i].lang != null)
                    {
                        locallang = (wadlDefinition.doc[i].lang);
                    }

                    if (locallang.Length > UDDIConstants.MAX_xml_lang_length)
                    {
                        lengthwarn = true;
                        locallang = (locallang.Substring(0, UDDIConstants.MAX_xml_lang_length - 1));
                    }

                    StringBuilder sb = new StringBuilder();
                    sb.Append(wadlDefinition.doc[i].title).Append(" ");
                    sb.Append(ContentToString(wadlDefinition.doc[i].Any));

                    ds.AddRange(Common2UDDI.mapdescription(sb.ToString(), locallang));

                }
            }
            else
            {
                ds.AddRange(Common2UDDI.mapdescription(serviceDescription, lang));

            }
            service.description = ds.ToArray();

            // Service name
            name sName = new name();
            sName.lang = (lang);
            if (wadlDefinition.doc != null && wadlDefinition.doc.Length > 0)
            {
                sName.Value = (wadlDefinition.doc[0].title);
            }
            if (sName.Value == null)
            {
                sName.Value = (serviceQName.getLocalPart());
            }
            service.name = new name[] { sName };

            categoryBag cb = new categoryBag();
            List<keyedReference> krs = new List<keyedReference>();
            String ns = serviceQName.getNamespaceURI();
            if (ns != null && ns != "")
            {
                keyedReference namespaceReference = new keyedReference(
                        "uddi:uddi.org:xml:namespace", "uddi-org:xml:namespace", ns);
                krs.Add(namespaceReference);
            }

            keyedReference serviceReference = new keyedReference(
                    "uddi:uddi.org:wadl:types", "uddi-org:wadl:types", "service");
            krs.Add(serviceReference);

            keyedReference localNameReference = new keyedReference(
                    "uddi:uddi.org:xml:localname", "uddi-org:xml:localName", serviceQName.getLocalPart());
            krs.Add(localNameReference);
            cb.Items = krs.ToArray();
            service.categoryBag = (cb);
            if (wadlDefinition.resources != null)
                for (int i = 0; i < wadlDefinition.resources.Length; i++)
                {
                    bindingTemplate bindingTemplate = createWADLBinding(serviceQName, getDocTitle(wadlDefinition.resources[i].doc),
                        new Uri(wadlDefinition.resources[i].@base), wadlDefinition.resources[i]);
                    service.bindingTemplates = new bindingTemplate[] { bindingTemplate };
                }

            if (lengthwarn)
            {
                log.warn("Some object descriptions are longer than the maximum allowed by UDDI and have been truncated.");
            }
            return service;
        }